knightcrawler25 / GLSL-PathTracer

A toy physically based GPU path tracer (C++/OpenGL/GLSL)
MIT License
1.83k stars 173 forks source link

Raymarcher: Glass and shadow rays #48

Closed markusmoenig closed 3 years ago

markusmoenig commented 3 years ago

Hi,

I am working on an programmatic SDF modeler / ray marcher and I wonder how to handle light sources behind glass. Right now the shadow rays hit the glass and just produce a shadow.

What is the correct way, when hitting glass, skipping through the glass (i.e. ignoring it) for shadow rays or something more complex, i.e. refracting the shadow rays ?

Thanks!

Screen Shot 2021-09-21 at 09 03 14

?

knightcrawler25 commented 3 years ago

Hey,

With the current code, having a light source behind/inside a glass object would mean that everything would be lit 'by chance' through refracted caustics and, you'll lose the ability to directly sample the light source with shadow rays. This would lead to a lot of noise in the image.

For unidirectional path tracers, usually, what people do to avoid this problem is to ignore the glass material for shadow rays. This option would be the simplest to implement with the cost of shadows looking a bit wonky and so maybe only use it for windows etc. Some good explanations for it can be found here: http://noobody.org/is-report/advanced.html (See: forward BSDF) https://wiki.luxcorerender.org/LuxCoreRender_Materials_Glass#Architectural (This one disables refraction for primary rays as well) https://rmanwiki.pixar.com/display/REN24/Shadows#Shadows-ThinShadows

The third way (that I know of) is to actually refract through the glass using a technique called Manifold Next Event Estimation. This seems way too complex but it solves the problem: https://www.ics.uci.edu/~yug10/projects/translucent/papers/Hanika_et_al-2015-Computer_Graphics_Forum.pdf

markusmoenig commented 3 years ago

Thanks a lot, guess ignoring glass for shadow rays seems to be the best solution for now. I am modeling inside a 3D texture so actually the ray marching is! very! fast and one could try out more sophisticated ways later.

Thanks again for this great piece of code and your support!

knightcrawler25 commented 3 years ago

No problem :) Happy to help out