Spherical Light Sampling for direct lighting only

Practical and theoretical implementation discussion.
Post Reply
sajis997
Posts: 27
Joined: Thu Jul 12, 2012 11:59 pm

Spherical Light Sampling for direct lighting only

Post by sajis997 » Fri Jul 13, 2012 4:12 pm

Hello forum,

I am stuck with one of the most primitive concepts in path tracing. I am using the spherical area light . I decouple the cornell scene lighting computation to direct lighting and indirect lighting. I am following the theories based on the book "AGI".

I have started with the direct lighting only. I am sampling the spherical light. The number of primary rays is equal to the number of shadow rays i am sending per pixel. Please check the following image:

http://www.student.itn.liu.se/~sajis997 ... earea4.png

I think the spherical light is not making any effect over the sides and top wall . I think those areas should be brighter.

I need some hint from the forum to the issues to look into to debug this issue.


Regards
Sajjad

davepermen
Posts: 48
Joined: Fri Dec 02, 2011 12:21 pm

Re: Spherical Light Sampling for direct lighting only

Post by davepermen » Fri Jul 13, 2012 7:30 pm

Do you evaluate the distance of the ray, and attentuate?
Do you measure the hit angle of the ray, and attentuate?

sajis997
Posts: 27
Joined: Thu Jul 12, 2012 11:59 pm

Re: Spherical Light Sampling for direct lighting only

Post by sajis997 » Fri Jul 13, 2012 8:37 pm

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: 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

Igors
Posts: 17
Joined: Sat Jan 07, 2012 11:56 am

Re: Spherical Light Sampling for direct lighting only

Post by Igors » Sun Jul 15, 2012 4:30 pm

There is no some "spherical light", it's a general "area light", just with spherical shape you can get sampling more convenient, as a disk turned face to each point. But all calculations remain same as for area

Sample_Illum = Light_intensity * solid_angle / PI2 * dot(sample_dir, surface_normal);

At farther distances (to light) solid_angle becomes smaller so illum fades "auto". The solid_angle value can be calculated simplified (see topic "Veach thesis" here) or fully (see formulas in Wiki)

sajis997
Posts: 27
Joined: Thu Jul 12, 2012 11:59 pm

Re: Spherical Light Sampling for direct lighting only

Post by sajis997 » Fri Jul 20, 2012 6:12 am

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:

http://www.student.itn.liu.se/~sajis997 ... earea4.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

sajis997
Posts: 27
Joined: Thu Jul 12, 2012 11:59 pm

Re: Spherical Light Sampling for direct lighting only

Post by sajis997 » Mon Jul 23, 2012 5:25 pm

Hello forum,

I managed to remove those artifacts from the surface of the luminaire. But the artifacts around the luminaire still exists(side walls and top walls) and i really need some hint to remove them. Please check the following image:

http://www.student.itn.liu.se/~sajis997 ... earea5.png

I shall be eagerly looking forward to your feed-back. I am calculating the direct lighting only so far by sampling over the spherical luminaire.


Thanks
Sajjad

sajis997
Posts: 27
Joined: Thu Jul 12, 2012 11:59 pm

Re: Spherical Light Sampling for direct lighting only

Post by sajis997 » Fri Sep 07, 2012 1:57 am

Hello forum,

I have uploaded an image rendered by monte carlo ray tracing with explicit direct lighting. It is rendered with 1024 paths/pixel

But i am getting some noise probably known as "salt and peppar".

Any hint or reference to remove those noise?

I did not have those noise with 100 paths/pixel.

http://www.student.itn.liu.se/~sajis997/cornell5.png


Thanks
Sajjad

Post Reply