0
$\begingroup$

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:

enter image description here

Where 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.

One of my sample output images: enter image description here

Instead the desired output should be: enter image description here

Please ignore the size and aspect ratio differences of the two images.

$\endgroup$
4
  • 2
    $\begingroup$ seems to me like the reflection ray is self intersecting with the surface it spawned from. Add a little epsilon (0.00001 for e,g) value so that the ray starts just ahead of that surface. $\endgroup$ Sep 15, 2019 at 18:36
  • $\begingroup$ It worked!! :) Never would have thought this might be the issue even though I considered it when shadowing! what it is the best action to talk when one of the values of the RGB channels overflows 1? currently I just discard the value that produced the overflow but I wonder if there is a better or a standard way to handle this ? $\endgroup$ Sep 15, 2019 at 19:54
  • $\begingroup$ Depends on what you want. It's natural for colors to flow over the range of 1. Pretty common in HDR (High Dynamic Range) images. Tonemapping is applied to convert HDR images to LDR (0-1). For simple raytracing projects we usually clamp the colors to 0-1 $\endgroup$ Sep 15, 2019 at 20:41
  • 2
    $\begingroup$ This is a very well known issue which everybody writing their own render encounters. It's called "shadow acne" if you want to read up on it. $\endgroup$
    – beyond
    Sep 16, 2019 at 14:31

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.