After spending a few days making very little headway with a simple Raytracing program that implements Phong illumination (with shadows and no attenuation), I'm convinced I've made a logic error that I'm overlooking.
As I understand it, the pseudo-code should look like this:
ambient light
for each light source
direction of light = light point - point on the object
test for an intersection starting at the point on the object, until you hit something
if (the intersection test returned a distance > distance from point on object to light point)
(do diffuse and specular shading)
A one quick thing to mention about my implementation: the intersection test will return 9999999 if there is no intersection.
Some of the things I've tried are: inverting the direction of the shadow ray - no effect. Making the comparison intersection distance - light distance > (some small epsilon value) - no change. Manually moving the light source to the opposite side - the specular reflection moved to a new spot, but otherwise, no change.
Here's a picture of my most recent output, I'm trying to get a shadow in the bottom left corner of the light gray plane.
Any help would be greatly appreciated.
Here's the relevant part of my code:
//iterate through all lights
if (myLights.size() > 0)
{
for (int i = 0; i < myLights.size(); i++)
{
//calculate the direction of the light
glm::vec3 ldir = (myLights[i].position - surfacePoint);
//this the length of the distance between the light and the surface
float ldist= sqrt(pow(ldir.x, 2.0f) + pow(ldir.y, 2.0f) + pow(ldir.z, 2.0f));
//check if the light can see the surface point
float intersections = myObjGroup->testIntersections(surfacePoint, normalize(ldir));
if (abs(intersections-ldist) > 0.0000001f)
{
//diffuse and specular shading have been cut for brevity
}
}
}
x * x
is much faster thanpow(x, 2.0f)
. $\endgroup$