Question

I wrote a ray-tracing program and everything seems to be functioning apart from the algorithm I use to traverse the ray tree which I'm not sure is correct. At every collision point, the program stores the colour of the object, its reflectiveness index and the light intensity at that point (specular and diffuse, ambient is a constant). Can someone please help me and explain to me how exactly I'm supposed to be combining the colours of the objects and the light intensities as I'm traversing the ray tree?

Was it helpful?

Solution

From Nvidia Developer Zone:

surfaceColor = emissive + ambient + diffuse + specular

Here,

  • emissive = Ke

    where:

    • Ke is the material's emissive color.
  • ambient = Ka x globalAmbient

    where:

    • Ka is the material's ambient reflectance and
    • globalAmbient is the color of the incoming ambient light.
  • diffuse = Kd x lightColor x max(N · L, 0)

    where:

    • Kd is the material's diffuse color,
    • lightColor is the color of the incoming diffuse light,
    • N is the normalized surface normal,
    • L is the normalized vector toward the light source, and
    • P is the point being shaded.
  • specular = Ks x lightColor x facing x (max(N · H, 0))^shininess

    where:

    • Ks is the material's specular color,
    • lightColor is the color of the incoming specular light,
    • N is the normalized surface normal,
    • V is the normalized vector toward the viewpoint,
    • L is the normalized vector toward the light source,
    • H is the normalized vector that is halfway between V and L,
    • P is the point being shaded, and
    • facing is 1 if N · L is greater than 0, and 0 otherwise.

OTHER TIPS

I think that you should use some local illumination model. U have all values for computing this reflection model: Phong reflection model

At its simplest, for multiple objects, where n is the current one:

Each object receives the light that the next object emits.

incoming_light[n] = outgoing_light[n+1]

Each object's received light is filtered by its diffuse color as well as the angle of incidence (dot product of ray direction and normal, you can skip this if your outgoing ray is already cosine distributed):

outgoing_light[n] += incoming_light[n] * diffuse[n] * cosine_term[n]

And finally, the pixel color is just the light emitted by the first object you hit.

final_color = outgoing_light[0]
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top