Hi.
I am currently try to get path tracing to work, and I think I got the basic understanding of what is going on correct.
However I would like to get it to work with point lights as well - seeing as how the rays i trace would most likely never hit a point light what is the correct approch for doing this?
I have more or less followed the same approach as prestented here: http://www.iquilezles.org/www/articles/simplepathtracing/simplepathtracing.htm
So my code looks sorta like this:
(if ray hits scene:)
std::vector<PointLight*>::iterator it;
Vector3 dirLightRes = Vector3(0.0f);
for(it = m_lights.begin(); it != lights()->end() ; it++){
PointLight *light = *it;
Vector3 lightOri = light->position();
Vector3 lightDir = (lightOri-hitInfo.P).normalized();
HitInfo shadowInfo;
Ray shadowRay;
shadowRay = Ray(hitInfo.P+(epsilon*lightDir),lightDir);
if(trace(shadowInfo,shadowRay)){
}
else{
float ndl = std::max(0.0f, dot(shadowRay.d,hitInfo.N));
dirLightRes += ndl* light->color(); }
}
//indirect light:
Vector3 diffuseResult;
Ray r = Ray(hitInfo.P,getRandomNormalInHemisphere(hitInfo.N));
r.o += r.d*epsilon;
if (traceScene(r, diffuseResult, depth)){
shadeResult = (hitInfo.material->getDiffuseColor ()) + (diffuseResult*dirLightRes) ;
}
Is this the correct approch ? Not all my test scenes produce the result i would expect (one of them fails to show shadows the way i expected it too) but I am not sure if this is a problem with my path tracing, number of samples or because it is simple tea pot scene and I got a lot of misses on my traces as there isnt much geomety there.
I would have assumed that each reccursive call would need to decrease the amount of colour contributed as well, is this correct? I haven't been able to find any places where this is discussed but it seems logical... ?
Any input is very much appriciated.