I am currently building a ray tracer and I came across a problem and confusion regarding the light calculations. For lighting, I am using the following mathematical model:
Ka is the ambient color component,
Ke is the emission color component. The summation calculates the phong and lambert components using specular and diffusion. The summation is over all the lights where
Li is the light color and
Vi is a binary variable that eliminates the lambert and phong components for the sake of producing the shadowing effect. On the other hand, the
Ks is the specular component and
Ir is the reflective color that is calculated recursively by producing a new ray and tracing this ray. All the color components are represented by a 3D vector that stores the R, G, B colors and they take a value from 0 to 1.
The model sums up all the color values which can end up producing values that are greater than and in a way overflowing the maximum value for the color channel. In my ray tracer implementation this was not a problem for all the terms highlighted in white because, for all the scenes I produced, none of them actually faced the problem where the sum of the colors were greater than zero. Now my attention was brought to this problem when I added the term highlighted in green which is the reflection term. I tried different things like setting the value of the color channel to 1 when it is going to overflow and taking the modulus or even setting it to zero.
All my solutions produce reflections, but the reflections are not smooth and have a lot of noise in them which I can't seem to eliminate.
I searched online for this issue but I did not find a lot of details. What would be a good solution for handling the possibility of the final color overflowing in one or more channels?
Note: my implementation works fine without reflection which makes me believe that the color implementation is correct.
Please ignore the size and aspect ratio differences of the two images.