Cycles: what is the difference between eval() and sample()?


I was looking through the files into \blender\intern\cycles\kernel\closure\, and I noticed that each closure files contain at least two functions:
bsdf_..._eval() and

I couldn’t figure out on my own what the difference is between them. I was able to guess that sample() produces the “final” color of the pixel, but why is eval() needed? At first I thought it was a geometric term, but further analysis of the code did not confirm my theory either.

Could you explain what they do?

In general I suggest to read PBRT, since it’s difficult to understand such things in isolation.

eval() evaluates the BSDF given a light direction, used for direct lighting.

sample() samples the BSDF to generate a new ray direction, used for indirect lighting and multiple importance sampled direct lighting.