I'm trying to implement a simple physically-accurate raytracer. I have it working in grayscale (so with light intensities) but I'm struggling with colors.
How do I calculate relation between colored (non-white) light and the surface. Say the light color is rgb(1.0,0.9,0.8) and the surface is rgb(0.8,0.9,1.0)?
In a very basic manner
Let's assume you've chosen the phong shading model or you've chosen not to do any specific shading.
- You need the scene's ambient coefficient (a coefficient that describes the overall intensitiy of the colors in the scene), let's say it's 0.3; And then multiply the object's color by the coefficient.
- Then you need to calculate the phong shading model or you just need the color of the object, w/o any special shading models.
- Then you need to calculate the color of the next object if your reflection vector hit any, again starting from step 1 (recursive)
- Sum all of the results
Code:
Color3 trace(..)
{
...
Color3 ambient = object.color * 0.3;
Color3 phong = phongModel(..) or object.color;
Color3 reflection = trace(..);
return ambient + phong + reflection;
}