This is kind of a long post so thank you to anyone who reads this!
So for my own personal project I'm implementing a photon map to use with a ray tracer I built but I'm having trouble understanding the rendering equation. I've already written the code to disperse both general photons and caustic photons, store them in a KD Tree and efficiently look them up in the tree to use for rendering.
So the Rendering equation is given as: Lr(x,w) = Integral( fr(x, w', w) * Li(x, w') cos(Theta i) * dw'i )
where x is a given point in the scene, w' is the direction if incoming light, w is reflected light and Theta_i is the incoming angle(I think).
FIRST QUESTION:
This concerns the term fr(x, w', w) which is the BRDF (bidirectional reflectance distribution function). Now I'm not sure if I'm understanding this correctly or not, but basically the BRDF is basically a shading function? Namely, for the basic ray tracing functionality of my program I used the phong reflection model to do direct illumination and reflections. Is it valid to just re-appropriate my phong reflection code and use it to represent the BRDF in the integral?
SECOND QUESTION: My other question has to do with when we break down the rendering equation into its components. For example, to calculate diffuse inter-reflection we do:
Diffuse reflectance = Integral( fr,d(x, w', w), * Li,d(x,w') cos(theta_i) dw'i)
So at any given point I already have stored a bunch of diffusely reflected photons around it. From what I understand from this equation do I simply multiply the intensity of each photon times the diffuse component of the phong model times the cosine of the angle and add them all up?
The code I have for that particular segment looks like this:
Color result = Color(0,0,0) // r = g = b = 0;
for(int i = 0; i < # photons surrounding point x; i ++)
{
result += Phong_Diffuse(photon_i, x, camera_ray) * photon_i.color * photon_i.angle
}
I then add this to the color I got from Direct Illumination ( Phong_DIFF_&_SPEC(light_source, x, camera_ray) ) and to the color I got from mirror reflections. Is what I'm doing here correct?
I just don't seem to be getting the desired effect. One reason is because if I scale my photons so that each photon has the intensity of Light_source / num_Photons then even with several hundred photons per location it barely makes a noticeable difference to my scene since I have 500,000 photons total. And if I don't scale my photons or fudge the scaling the colors still seem off.
Furthermore when I do my testing on a Cornell_box, even with my diffuse reflection the ceiling is still noticeably very dark when based on pictures I've seen of other cornell boxes it should be a lot brighter.
I don't think it's an issue with how I'm storing my photons either because I've tried directly visualizing my photons (so the entire scene is just made up of colored dots where the photons would be) and they seemed to be roughly evenly distributed and in correct locations and when I test to see that I am gathering the photons closest to the given point, that seems to be working as well.
Thank you to anyone who bothered to read through this long rambling mess and thank you to anyone who takes the time to respond! =)
For your first question, the answer is yes. A BRDF is just a probability distribution that describes the probability that a photon with incident direction
i
gets reflected toward a directiono
(or gets absorbed). That's what your Phong model describes as well.For your second question, I guess your problems lies in the scaling factor. When you gather the photons in a neighborhood of radius
R
(whetherR
is constant, or varies with the k nearest neighbors), you have to divide your cumulated energy by the area of the disc of radiusR
(and as such, if this area is much less than one, this will boost your intensity). Appart from that, your calculation seems correct : you take all photons with their direction, use them in the BRDF to see the probability that they get reflected toward the camera (or said otherwise, how much energy of the photon remains when reflected toward the camera), and sum everything. I guess yourPhong_Diffuse
contains a diffuse component (hence its name), and if so, that is correct as well.Another possibility is that your diffuse reflectance is too weak to produce visible diffuse interreflections.