Thanks for your reply. That was the first thing I suspected as well, but the problem is that there is not adding up of colors. Or there is one, where I add the effects of all the lights, but as there is only one light in my scene this should not cause the effect.
// Find the color
primCol.r += (int)(dot * primColor->getDiffuse() * primColor->getR() * lightColor.r);
primCol.g += (int)(dot * primColor->getDiffuse() * primColor->getG() * lightColor.g);
primCol.b += (int)(dot * primColor->getDiffuse() * primColor->getB() * lightColor.b);
I have also tried to change the above code from “+=” to “=” but the result is the same. After what I know about raytracing(limited knowledge) it should be impossible to have transparency without shooting some secondary rays to find whats behind the original object?
The part belove here is the “core” part of the raytracer, if that in someway can help.
// This is where the raytracing is done. Here we create a ray
// and trace it through the scene to see if there is an
// intersection. Then we set the color at the corresponding pixel
// We make a loop for the hight and the width in order to trace
// all pixels
for (int y = 0; y < hight; y++)
{
for (int x = 0; x < widht; x++, arrayTracer+=3)
{
//std::cout << x << "," << y << ": We are here" << std::endl;
// Set the ray to trace through the current pixel
currentRay.setDirection(directionList[x + y * widht]);
// Variables for checking which objects that are closest to the
// camera
float closestDistance = 1000000;
int closestPrimitive = -1;
// Loop through all the primitives in the scene and return the
// the closest one
for (int currentPrimitive = 0; currentPrimitive <=totalPrimitves;
currentPrimitive++)
{
// Find the primitive we are currently testing against
Primitive* testObject = thisScene.getPrimitive(currentPrimitive);
// Check if the ray hits the current object
intersectionRes = testObject->intersectionTest(currentRay);
// If the ray hits something, check if its the closest object
if (intersectionRes.hit == 1)
{
// Find closest primitive by comparing distance
if (intersectionRes.distance < closestDistance )
{
closestDistance = intersectionRes.distance;
closestPrimitive = currentPrimitive;
}
}
}
// We now know if the ray has hit something and what the closest object is
if (closestPrimitive != -1)
{
// Store the color
Color currentColor;
// Find the intersectionPoint between the ray and the closest
// primitive
Vector3D interPoint = currentRay.getDirection();
interPoint.scale(intersectionRes.distance);
interPoint = interPoint + PointToVector3D(currentRay.getOrigin());
// Add diffuse lighting
currentColor = addDiffuse(closestPrimitive, interPoint, thisScene);
// Add the color to the colorBuffer
colBuffer[arrayTracer + 0] = currentColor.r;
colBuffer[arrayTracer + 1] = currentColor.g;
colBuffer[arrayTracer + 2] = currentColor.b;
}
}