erichlof/THREE.js-PathTracing-Renderer

Stop a caustic ray if it crosses a surface

vinkovsky opened this issue · 3 comments

Hey! Is it possible to change the behavior of the rays in this case?

image

Also sometimes i see this warn in the console

image

Hello @vinkovsky !

Yes it is possible to occlude the light and caustics rays that are passing through the volume (of gas, fog, smoke, etc.). The reason why the current demo (as your picture shows) does not block the light is simply because the 4 quads that make up the Cornell box are all single sided quads. I intentionally made them single sided (only visible if you are on the same side as the plane normal) because I kind of liked how the blue caustic light beam went all the way down into the void before tapering off. I just thought it looked kinda cool, but in reality we would never encounter such a magic wall or magic floor.

So all you have to do is find the quad intersect function and change the last boolean parameter from false to true. It should look like this on line 61 of the Volumetric_Rendering_Fragment.glsl file:

d = QuadIntersect( quads[i].v0, quads[i].v1, quads[i].v2, quads[i].v3, rOrigin, rDirection, true );

That last parameter 'true' means make the quad double-sided, as in real life. If it is 'false', then the quad is rendered single-sided and has back face culling (as in traditional rasterized 3d graphics pipelines).

A side note: I had commented out the quads for the floor and the ceiling of the Cornell box and set N_QUADS to 3 (Red left wall, White back wall, and Blue right wall. So if you want to add back the floor and/or the ceiling, you'll have to uncomment those in the 'SetupScene()' function, then make N_QUADS a higher number to match, like 4 or 5.

When I made these small changes, here's how it would look in real life:

BlockedCaustic2

BlockedCaustic

Pretty cool!

Oh, and about the occasional warning, that vec4 belongs to the RGBA Blue Noise texture. I sample that texture repeatedly very fast every animation frame, to produce low-noise random numbers between 0.0-1.0 for use with diffuse surfaces, shadow penumbras, transparency double images (refracted vs reflected), and even the blue hazy fog on this demo. This gives almost imperceptible noise patterns that are much smoother to the eye than mathematically-calculated random numbers in a GLSL shader. However, the cost is that if the RGBA Blue Noise texture is a little late in loading, the vec4 (R,G,B, and A) that needs to sample it to produce the smooth random numbers doesn't have anything to work with for a few seconds. At least, that's what I think is going on - I could be mistaken (GPUs and shaders are notoriously hard to debug).

Hope this helped!
-Erich

Thanks a lot, Erich! Works very impressive :)