1
\$\begingroup\$

I am implementing an MLT bidirectional path tracer. I have a problem integrating diffuse, specular reflection and refraction.

1) The first problem is diffuse and specular reflection. Diffuse reflection is done by sampling ray in a hemishere. But specular reflection is done by finding the ray that have an angle to the normal equal to the incident ray with the normal. However, an object can have both diffuse and specular reflection. When to use specular reflection or diffuse reflection for a ray?

2) Same as the first question but this time integrating reflection with refraction.

I've seen a few research papers and websites online where the scene have specular, diffuse reflection and refraction, but they have no tutorial on how to do this.

\$\endgroup\$
  • \$\begingroup\$ 1) You have to integrate both diffuse and specular at the same time, the result of the overall rendering equation will basically be a sum of two smaller rendering equations, one that integrates only diffuse and the other that only integrates specular. 2) Same as above, you have to handle reflection in addition as well. I'm answering in the comments section since I don't have time to formulate a good answer, but at least my comment should give you something to think about. \$\endgroup\$ – TravisG Apr 21 '15 at 9:54
  • \$\begingroup\$ How do I integrate both? Do I calculate the specular vector, then find the irradiance of both diffuse and specular? Or randomly sample the hemisphere then if there is a diffuse ray with the same as specular vector the find the irradiance of both? \$\endgroup\$ – Long Le Apr 21 '15 at 10:53
  • \$\begingroup\$ Well, imagine you have a scene where you only calculate diffuse lighting, and store that resulting image somewhere. Then imagine a scene where you only calculate lighting resulting from specular reflections. Then store that image somewhere. In the end, just add the two images together and you have your final result. Do the same thing for other lighting phenomena (refraction, emissive lighting from surfaces, etc.). \$\endgroup\$ – TravisG Apr 21 '15 at 11:36
  • \$\begingroup\$ I thought about that, but doesn't that only works if there is a light path with purely diffuse, specular and refractive rays. What happens if though you have a path with LDSDSE (using heckbert regex, L for light, D for diffuse, S for specular, E for eye). In other words, if there is an indirect light path with diffuse rays and specular rays and refractive rays. \$\endgroup\$ – Long Le Apr 21 '15 at 12:01
  • \$\begingroup\$ If you're asking if you can also separate the indirect lighting computations like that: Yes, you can! For example, in real time rendering it's not uncommon to calculate indirect diffuse and indirect specular using completely different algorithms (for performance reasons) and in the end just add the results together. \$\endgroup\$ – TravisG Apr 21 '15 at 12:17
1
\$\begingroup\$

The Phong model (diffuse + specular + ambient) is just an approximation of how light behaves. In reality, there's what's called a BRDF or bidirectional reflectance distribution function. It is a function which tell you, for a given point on the surface the probability of light bouncing in a given direction given an incident ray of light. The components (diffuse, specular) of the Phong model, (or any other model for that matter) are used to approximate the BRDF, by splitting it into roughly independent components which are easy to evaluate independently and then added together.

What does it mean? well, when you cast a ray and it hits a surface, you now have to decide where to shoot the next ray or rays. For perfectly specular surfaces, the ray is reflected with the same incident angle. How much those reflected rays will deviate from the perfect reflection vector will depend on the glossiness of the surface. For completely diffuse surfaces, the ray can be cast in any direction on the hemisphere above the point on the surface.

If you want to approximate diffuse and specular components independently, then you need to cast at least two other rays, one which will sample the diffuse contribution and another one which will sample the specular contribution. If you consider refraction as well, then you'll need a third ray.

In reality, when the reflection is not deterministic (when you don't have a perfectly reflective surface) you won't just shoot a single ray, but instead you'll shoot many rays to sample the surroundings. The more rays you shoot, the less noise you'll have in your final image, but it will become slower to compute.

How many rays to actually send and where is a very interesting and complex topic in itself. Shooting rays is not cheap, specially considering the noise in the final image decreases as the square root of the number of rays you sample. So sampling efficiently is important.

For example, for a particular material you might want to send a thousand rays, but send 90% to sample the diffuse component and 10% to sample the specular component because the diffuse part will contribute more to the final color and the surface is very smooth, and hence those 10% of the rays will all follow pretty much the same path.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.