Monday, January 31, 2022

Direct Light 2: integrating shadow rays into a path tracer

Part 1 of 3

Part 3 of 3

 

In my last post, I talked about using shadow rays to sample a light source directly.  Here is our old lovely but noisy path tracer:

vec3 ray_color(ray r)
  if (r hits an object)
       r = ray(hitpoint, generate a scattered  direction from the surface)
       return emitted(hitpoint) + reflectance*ray_color(r)
   else
        return background_color(r)

This works great provided the light emitting objects are big, but otherwise we get a lot of noise.  We also are crossing our fingers we don't get an infinite recursion.


Let's assume we have a magic function direct_light(vec3 p, reflectance_info ref).   Can we just do this to the return line above:

      return emitted(hitpoint) + direct(hitpont, ref_info) +reflectance*ray_color(r)

NOPE!  That would double count direct because that sacttered ray r might hit the light and get the emitted part.  So this is better:

     return direct(hitpont, ref_info) +reflectance*ray_color(r)

 BUT, if you see the light source in the picture, it will be black!  

And before we fix that, another problem is that if the surface is a perfect mirror, the direct lighting itself will be too noisy because only one point on the light matters.

So we need something like a "sees the light" flag on a ray.

vec3 ray_color(ray r)
   vec3 color = (0, 0, 0)
  if (r hits an object)
       if (r.should_see_lights)
            color +=  emitted(hitpoint)
            r = ray(hitpoint, generate a scattered  direction from the surface, should_r_see_lights_flag)
            if (r.should_see_light)
                    color += reflectance*ray_color(r)
            else
                    color += direct(hitpoint, ref_info) +reflectance*ray_color(r)
   else
        color += background_color(r)
  return color

Man that is pretty ugly!  But I don't know a much better way.  Be sure to set the viewing ray flags to "should_see_light = true".

 Are we done?  No.  For perfect mirrors, should_see_lights scattered rays should be set true.  For diffuse reflectors, false.  For glossy objects, it depends on the size of the light source.  Here, a lovely technique from Eric Veach is often used.   I would go with the "balance heuristic"-- it is easiest.  There is a wonderful figure from the paper that shows why this technique is needed:

 

So are we done?   No, there is one more issue.  Does the background "emit" light?  Isn't it a light source.  The answer is you can do it either way.  But if it is a light source, and you can hit it, we can get rid of the   if (r hits an object)  branch-- the background is always hit!  But if it has infinite radius where is the hitpoint?  I would say these design decisions are not obvious and I am on the fence even after trying all of them.

Next time: what goes in here: direct(hitpoint, ref_info)

 

 

 

     






11 comments:

Brian said...

Don't some path tracers get rid of the should_see_lights flag with this complexity by separating the "light emitting objects" from the other geometry. The only thing is if you have to SEE the lights then you have to double the light geometry with a simple function that returns the constant, non scattering light color on camera rays. I suppose it's a bit doing the same thing, So you'd have something like:

vec3 ray_color(ray r)
vec3 color = (0, 0, 0)
if (r hits an non_light_object)
color += emitted(hitpoint, &do_scatter) // do_scatter returns false if this is a "light geometry" and first bounce
if (do_scatter)
r = ray(hitpoint, generate a scattered direction from the surface)
color += reflectance*ray_color(r) + direct(hitpoint, ref_info) // direct lighting against light_objects
else
color += background_color(r)
return color

This is much cleaner than the sees the light flag IMO though maybe doing basically the same thing. The other nice part is that you can then completely separate the lights used for direct lighting into their own data structure from the scene geometry.

Peter Shirley said...

Thanks Brian I like it!

Version IT Ameerpet said...

Hi
Thanks for sharing the information
SAP- FICO
SAP- ABAP
SAP- MM
SAP- BASIS
SAP- HR/HCM
SAP- SD

onlineAssignmenthelp said...

If you are a Victoriana student, Canada, and your work is proving difficult to accomplish, remember that you don't need to do it by yourself. It could be a difficult subject, a deadline, or just too little time, but The Tutors Help will assist you. We're dedicated to making sure that you pass your studies with ease.
Let us take the pressure off your shoulders. Chat with The Tutors Help today and get top-quality assignment help in Victoria, Canada. We’re here to make your academic journey smoother and more successful!
https://www.thetutorshelp.com/assignment-help-in-victoria.php
Assignment Help in Victoria, Canada

Do One Thing said...

Awaken your space, soul, and sensuality with Apna Showroom’s extraordinary combo set. From the divine Brass Kalash filled with holy Ganga water to the Feng Shui tortoise, healing crystal, powerful Shaligram Shivling, and fashionable fishnet stockings—APNA SHOWROOM White Marble Shiva Lingam/Shiv Ling - Shankar Bholenath Shivji Mahadev Bhole Bhandari Idol Murti for Worship and Decoration
Apna Showroom 24k Gold Plated Yantra for Home, Office, Business, and Puja Ghar - Spiritual Energy and Prosperity Enhancement (Yantras Sidh Sampurna Vastu Dosh Nivaran, Medium, 23X23cm)
Apna Showroom 24k Gold Plated Yantra for Home, Office, Business, and Puja Ghar - Spiritual Energy and Prosperity Enhancement (Shree Sampurna Rognasak, Medium, 23x23cm)
Apna Showroom 24k Gold Plated Shree Sampurna Vastu Yantra for Home, Office, Business, and Puja Ghar - Spiritual Energy and Prosperity Enhancement
Apna Showroom Fishnet stocking for Women Sexy Black Net Pattern Medium Mesh Free Size with desent Look
this set has it all. Ideal for women who blend spirituality with style. Align your energy, upgrade your rituals, and flaunt your fierce. It’s the perfect mix of pooja, purpose, and personality. Elevate your essence—buy now and glow boldly!

Scribit Solutions said...


Really helpful information here! For anyone based around Delhi NCR, partnering with a web development company in Noida can be a smart move — they combine tech expertise with local market understanding.

Scribit Solutions said...


Thanks for the valuable tips! For businesses looking to grow locally, connecting with a digital marketing company in Delhi NCR can really make a difference. Their regional expertise helps in targeted campaigns and better ROI.

onlineAssignmenthelp said...

It is a wonderful experience to study in Belfast, but assignment work can prove to be very stressful. You don't have to do it all on your own. By availing The Tutors Help, you receive specialized guidance and high-quality help for all your scholastic needs.
We can relieve you of the pressure of studying. Chat with The Tutors Help today for the highest quality assignment assistance in Belfast and begin attaining those grades that you so rightly deserve!
https://uk.thetutorshelp.com/assignment-help-in-belfast
Assignment Help in Edinburgh

onlineAssignmenthelp said...

If you are a student in Edinburgh and struggling to maintain your assignments, don't worry. The Tutors Help is ready to assist you. Our professional writers, welcoming service, and high-quality work make us the most suitable option for assignment assistance in Edinburgh.
Chat with UKThe Tutors Help today and move one step towards academic achievement!
https://uk.thetutorshelp.com/assignment-help-in-edinburgh

Assignment Help in Edinburg

Designogram said...

Great Blog,

Designogram helps you boost your Business.

As a digital marketing agency, we strive to understand our client’s business goals first. Then all decisions are made with those goals in mind. A shiny new website is worthless if it doesn’t help you reach your goals. You talk, we listen… then we throw in lots of ideas for improvement. Not every Digital Marketing Agency is created equal. At Designogram, we know that the best results come from having the right people working on the right project. Our experienced team offers expertise in various areas of Digital Marketing Agency services, which is why each client is matched with a suitable group of experts to help them achieve their goals. With our proven strategies, your business is bound for wild success.
Social Media Marketing Agency in Ludhiana
Digital Marketing in Ludhiana
Social Media Marketing in Punjab

Skyappz Academy Training Institute said...

I’m impressed with the clarity and structure of your content. AI course in Coimbatore with placement, Affordable Fee.