Jump to content
  • Advertisement
Sign in to follow this  

Photon Mapping problems

This topic is 3389 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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;
    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
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!