(L) [2012/07/13] [ost
by sajis997] [Spherical Light Sampling for direct lighting only] Wayback!Hi
I am not sure if you i get your questions . Which rays distance to attenuate ?
I am elaborating the algorithm that i am doing to implement the direct illumination and the questions you asked will hopefully be answered through the discussion.
Code: [LINK # Select all]Color PathTracer::computeDirectIllumination(const Intersection &intersection)
{
  //declare the color to store the radiance
  //from the direct illumination
  Color outputColor;
  
  //pointer to the area light
  AreaLight *areaLight;
  
  Color incomingRadiance,BRDF;
  Vector3D lightVec;
  Vector3D lightNormal;
  float incidentAngle;
  Intersection shadowIntersection;
  Ray shadowRay;
  
  bool shadowHit = false;
  
  //get the number of area lights in the scene
  unsigned int numberOfLights = mScene->getNumberOfAreaLights();
  unsigned int samples = getNumberOfSamples();
  for(unsigned int shadowRays = 0; shadowRays < samples ; shadowRays++)
  {
     for(unsigned int i = 0; i < numberOfLights;++i)
     {
    //get the area light - i in  the scene
    areaLight = mScene->getAreaLight(i);
    
    //get the shadow ray for the area light
    //we get a new shadow ray for each sample over the light source
    shadowRay = intersection.getShadowRay(areaLight);
    
    //check if the shadow ray intersect the scene
        //we also store the shadow hit information to check the lights material
    shadowHit = mScene->intersect(shadowRay,shadowIntersection);
    
        //we calculate the outgoing radiance under two options
        //if the shadow ray do not hit any intersectables between the inersection point in the scene and light sample point
        //OR if the shadow ray hit a intersectable that happen to be the light source
    if(!shadowHit || (shadowHit && shadowIntersection.mMaterial->emissive()))
        {
       
       //calculate the light vector - the irradiance - wio
           //getWorldPosition() gets the sample point within the sphere
       lightVec = areaLight->getWorldPosition() - intersection.mPosition;
       lightVec.normalize();
       
       //the light normal is already calculated while calculating the light's
       //world position in the previous step
       lightNormal = areaLight->getSampleNormal();
       
           //get the dot product between the negated light normal and light vector
       float ndotd = std::max(-lightNormal.dot(lightVec),0.0f);
       
       //the emissive radiance from the light source
           //which does not depend over ray's incident direction
           //it is the emissive color * scaling factor
       incomingRadiance = areaLight->getRadiance();
       //length squared between the light sample point and intersection point
       float d2 = lightVec.length2();
       
       
       incidentAngle = std::max(lightVec.dot(intersection.mNormal),0.0f);
       
       //get the BRDF
       BRDF = intersection.mMaterial->evalBRDF(intersection,lightVec);
       
       
       //accumulate the color for all the lights
       outputColor += (BRDF * incomingRadiance * incidentAngle * ndotd)/(areaLight->getPDF() * d2);
        }
     }
     outputColor /= samples;
  }
  
  
  return outputColor;
}
I think i am calculating the light vector and attentuating its contribution by 1/d2.
I am also calculating the hit angle and how to attentuate the hit angle ?
If you need any more explanation please do mention .
Regards
Sajjad
(L) [2012/07/20] [ost
by sajis997] [Spherical Light Sampling for direct lighting only] Wayback!Thanks for the hints.
I think i have reached a bit closer to the solution . But i am still having some arti-facts over the luminaire and some of the areas around it.
Please check it here:
[LINK http://www.student.itn.liu.se/~sajis997/cornellscenearea4.png]
Any idea what might have caused it? I am following the Peter Shirley's book "realistic ray tracing" and some of the concepts described over there about sampling the spherical luminarie is not clear to me and this is why i think i am doing something wrong. I believe that some one in the forum have already had gone through the book .
Lets go to Chapter 13 : Explicit Direct Lighting. And then to 13.2 - Sampling a spherical luminaire
At the end of the first paragraph it is written - "We now use a coordinate system defined with x at the origin, and a right-handed orthonormal basis with"
What does it mean by x at the origin ? To me x is the first intersection point where we are calculating the radiance value , right ?
In my case i am defining the sphere center at (0,0,0) and then transforming the origin by world transformation to the scene and then calculating the w as mentioned in the book, v = w X n and u = v X w.
This is how i am defining the orthonormal basis
I shall looking forward to more suggestion over this issue.
Regards
Sajjad