|
Post by danylo on Jan 29, 2020 21:52:59 GMT
Hello there! Does anyone have any ideas on how to create caustics, using techniques we've learned from the book?
|
|
fremag
Junior Member

Posts: 73
|
Post by fremag on Feb 3, 2020 8:21:16 GMT
Hi, I've started to read this page about photon mapping but I haven't coded anything yet because I'm working on different (easier) subjects (orthographic camera, spot light with soft shadows...)
If you start working on this subject and have some information or code to share, do not hesitate to post some samples or links.
|
|
madox
New Member
Posts: 22
|
Post by madox on Mar 8, 2020 21:47:21 GMT
So I was thinking of caustics and how to do them for a while. Here is a naive approach I might try in my JS engine:
before rendering the scene: - prepare a surface the same size as the one you use for rendering the scene - cast N rays from each light in random directions (or uniform distribution, whatever) - follow each ray until it hits a surface[1] that can accept a caustic[2] - find where that hit point is from the camera's POV - record the distance from camera[3], and light colour[4], at the spot on the surface that corresponds to the point from camera's POV while rendering normally - when rendering a pixel, check the caustic map at the spot for the current pixel to see if there is any colour info there from a caustic - if the caustic is closer to the camera than the current hit[5], blend in the caustic colour
Notes: [1] if there is a semi transparent surface that splits the light and makes multiple caustics, it gets tricky... [2] do caustics appear on glossy surfaces? mirrors? semi transparencies? Need to play with it [3] record the closest caustic in case of multiple on the same spot. [4] make sure to account for multiple caustic rays ending up on the same spot and becoming super bright [5] this is like the shadow test. I expect the caustic distance to be epsilon closer than the hit surface
This will be pretty slow but will account (I think) for light coming off mirrors etc. Also you need a LOT of rays to get it looking good, I feel. To speed it up you can directly fire rays at any transparent object in view of a light so you are sure that every ray will contribute to a caustic but you lose light bounding off mirrors etc
Also the whole "record data at the spot that corresponds to the point from camera's POV" isnt possible in WebGL so I'll only be able to try it in slow JS
I'm kinda spitballing here- let me know if anyone has a better idea!
|
|
fremag
Junior Member

Posts: 73
|
Post by fremag on Mar 9, 2020 8:11:26 GMT
I agree with all this.
I read some articles and found that a Kd Tree is very useful to store the photons / caustic map so I will work on this first. This structure is useful to speed up rendering so I will practice and train on this subject before working on caustics or global illumnation.
|
|
madox
New Member
Posts: 22
|
Post by madox on Mar 14, 2020 1:44:12 GMT
I'm back after my first attempt to implement the above algorithm I posted. Here is an image from before that I posted when I was talking about better shadows for transparent objects  Here is the same rendering with caustics enabled.  Note there are 2 lights so there is 2 caustic effects, and they look pretty accurate. I have to try with more difficult objects. The strategy is: - render normal image - for each light - - for each object - - - cast a bunch of rays at the object (as above) - - - if a ray passes through a transparency and hits a surface, increase the brightness at that spot (update the rendered image) The hardest part was actually going from a world position back to a pixel on the canvas. I'm going to keep testing objects and post more later. I can go into better detail if needed
|
|
madox
New Member
Posts: 22
|
Post by madox on Mar 14, 2020 15:36:16 GMT
 An example with a cylinder. I've been trying to filter out the noisy parts and make those bright lines pop more but havn't found the right combination of settings yet. Also the caustic is at an angle from the shadow, not sure if that right or not. The bright lines do look correct if I can just get the noise down.
|
|
fremag
Junior Member

Posts: 73
|
Post by fremag on Mar 14, 2020 21:19:18 GMT
Very nice ! I have a question: what will happen if you put a reflective object (a mirror for instance), does it act like a kind of new light source ? For instance, will a "disco ball" produce a lot a light spots on the walls ?
|
|
madox
New Member
Posts: 22
|
Post by madox on Mar 14, 2020 23:28:17 GMT
Ya it should act as a new light source. I'll set up a scene like that and try it out. I also was reading that caustics only come from specular light, so I added a specular check but I dont know if the result is more right or not 
|
|
fremag
Junior Member

Posts: 73
|
Post by fremag on Mar 16, 2020 13:40:26 GMT
About the noise problem, you will have to cast a lot of rays from light to correct this I think. I've read (but not tested yet) a different way of solving this. The rendering has two steps: - first : cast a lot of rays and store their intersections (direct + reflection / refraction) This will be the "photon map".
- second: render the scene as usual but use the photon map to modify the pixel color you are drawing. With the photon map, you can have all the photons / lights close to your pixel and interpolate them so there is less noise. The best structure for the photon map is a KdTree because it allow to search for items "close" to a given point.
It's only theory to me as I have not tested anything yet.
|
|