# Integrating specular, diffuse reflection and refraction

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.

• 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. Apr 21, 2015 at 9:54
• 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? Apr 21, 2015 at 10:53
• 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.). Apr 21, 2015 at 11:36
• 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. Apr 21, 2015 at 12:01
• 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. Apr 21, 2015 at 12:17