Sign in to follow this  
IndyJones

Photon Mapping problems

Recommended Posts

I'm trying to add photon mapping to my ray tracer and got stuck with the calculation of the radiance estimate. The problem is that my estimation function always returns 0/0/0 and therefore all I see is a black image. Here is how I implemented my photon tracing/radiance estimate function: - First I calculate the photon power for a photon like this:
Color photonPower = curLight->GetColor() / numPhotons;
Where Color is a type containing 3 floats for RGB values, numPhotons is the number of photons emitted from the current light source and GetColor returns the light color/intensity. - When the photon hits an object I determine what to do next using Russian Roulette. Let's assume we are doing a diffuse reflection - then this is what I currently do in my code:
Ray reflRay = GetDiffuseReflection();
Color newPower = p_Power * DiffuseBRDF(hitPoint, hitNormal, p_Ray.m_Direction, reflRay.m_Direction, curMat);
AddPhoton(hitPoint, p_Ray.m_Direction, newPower);
PhotonTrace(p_Scene, p_Light, reflRay, newPower, p_TraceDepth + 1, p_RefrIndex);
First I calculate the diffuse reflection ray. Then I multiply the current photon power by the BRDF of the surface where the photon hit was detected (in the case of the diffuse BRDF all I do is (Normal * -reflRay.dir) * curMat->GetColor()) and store the photon (because we hit a diffuse surface). Then I recursively continue photon tracing with the new calculated photon power. - Finally my radiance estimate locates the n closest photons and performs the following calculation.
Color output(0,0,0);
for(int i = 0; i < PhotonsFound; ++i)
{
    const Photon* p = m_Photons[i];
    Vector3 dir = GetPhotonDir(p->m_Theta, p->m_Phi);
    output += (hitNormal * -dir) * p->m_Power;
} 

const float tmp = (1.0f / PI) / (MaxSqDistance);	
output = output * tmp;
The problem that I have with my photon mapping implementation is that output is always very small (0.000xxxx values) and therefore my scene is just black. I'm not sure what parts of Photon Mapping I've misunderstood that my implementation is not working correctly. I hope someone can help and enlighten me!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this