Original Post
I'm writing my first raymarcher, which at the moment is straight out of Ken Perlin's chapter in Texturing & Modeling: A Procedural Approach.
As he suggests, for lighting I'm calculating the normal at a point by using the density gradient:
However, if the density between the intersection point and the epsilon point is the same, then the normal is 0-length. If the surface is very hard, or the shape is at a constant translucency then this happens pretty much all the time.
None of the example code I've seen online seems to have to do anything to cope with this issue, nor does the book, therefore I must be doing something dumb. Can anyone tell me what it is?
As he suggests, for lighting I'm calculating the normal at a point by using the density gradient:
vec3 compute_normal(vec3 point, float density, float epsilon)
{
return normalize(vec3(density_function(vec3(point.x - epsilon, point.y, point.z)) - density,
density_function(vec3(point.x, point.y - epsilon, point.z)) - density,
density_function(vec3(point.x, point.y, point.z - epsilon)) - density));
}
However, if the density between the intersection point and the epsilon point is the same, then the normal is 0-length. If the surface is very hard, or the shape is at a constant translucency then this happens pretty much all the time.
None of the example code I've seen online seems to have to do anything to cope with this issue, nor does the book, therefore I must be doing something dumb. Can anyone tell me what it is?