Tuesday, February 1, 2022

Direct Light 3: what goes in the direct light function?

Part 1 of 3

Part 2 of 3

 

 In the previous two posts I discussed why one might want direct lighting as a separate computation.  But what goes in that function?

If we are just sampling a single light, then we need to bite the bullet and do a Monte Carlo integration with actual probability density functions.  These functions can either be defined over the area of the light, or the angles the light is seen through.  You can dive into all of that later-- it looks intimidating but is mainly like learning anything new with bad terminology and symbols-- just eat the pain :)

But for now, we can do it the easiest way possible and "just take my word for it".  After you have implemented this once, the written descriptions will make more sense.

First, pick a random point uniformly on the surface of the light.  Chapter 16 of this book will show you how to do this for various shapes.

The magic integral you need to solve, often referred to as the "rendering equation" is this:


 The key formula you evaluate is in red.  Area is the total area of the light.  The "rho" is the BRDF and for a diffuse (matte) surface that is "rho = reflectance / pi".   So pick a random point y uniformly on the light, see if x can "see" y by tracing a "shadow" ray from x to y (or vice-versa).  That's it!  It will be noisy for spherical lights (half the time, y is on the back and so will be shadowed, and the cosb will vary a lot), but it will work well for polygonal lights.  Worry about that later-- just get it to work.

What about multiple lights.  Three choices:

  1. do one of these computations for each light and add them
  2. pick one of the N lights at random, do the computation for that one light, and multiply by N
  3. implement reservoir sampling like all the cool kids do (it is a new technique and works really well)

I endorse option 2 as your first step.  

 


4 comments:

  1. For years I also discussed this in my graphics class, leading students to option 2. And then of course the question: "How would you assign probabilities to different light sources?"

    Whatever answer the students give (equal probability, proportional to intensity, distance only, ...) it is always easy to give a counterexample where that doesn't work, because it is hard to set up probabilities for the entire scene at once. And no one ever thinks to insert the visibility term into the probability of picking the light source - so that was/is usually the first homework ;-)

    ReplyDelete
  2. From the book, this is the code to sample sphere uniformly:

    1 a = 1 - 2*u[0];
    2 b = sqrt(1 - a*a);
    3 phi = 2*M_PI*u[1];
    4 x = R*b*cos(phi);
    5 y = R*b*sin(phi);
    6 z = R*a;

    -u[0] and u[1] are the x and y components of the hit point I'm sending the ray from, right?

    -And it was also specified that the z value of the sampled point ranges from -1 to 1, I just multiply that with the z value of the sphere light to make it right?

    ReplyDelete
  3. Thanks for sharing such an Amazing post with us, For Professional 3D Townhouse Rendering services in Los Angeles, Visit 3D Revolution Rendering company.

    ReplyDelete