eiffie
Guest
|
|
« on: November 09, 2013, 08:25:59 PM » |
|
Shooting montecarlo rays is great because you get DoF, AA, soft shadows and fuzzy reflections all at the same time, but it takes too long and we spend most of that time trudging through the same empty space. Over at shadertoy I was working on a script that used DE to anti-alias. Knighty pointed out that Hart had already done this 20 years ago :| Knighty and IQ thought that my script could be extended to do DoF. They are both fairly bright guys but I didn't think it would work. Distance estimates become quite bad at large distances and banding occurs. IQ said maybe taking samples whenever you are within the CoC might work. So I tried it and was surprised by the results. https://www.shadertoy.com/view/MsBGRh This is a webgl link so be forewarned.
http://www.youtube.com/v/Z5SOA2xSLnQ&rel=1&fs=1&hd=1 If you prefer a video. Like montecarlo we are grabbing multiple samples but not by shooting multiple rays. Instead one ray adjusts its "sphere of influence" to encompass the Circle of Confusion (CoC). The idea is quite simple (and knighty can correct me where I'm wrong). March until the distance estimate is smaller than the radius of the CoC and grab a sample. Calculate the normal by using the radius of the CoC and average the color samples at these points. So now we have a normal and color that are averages for this march step. Do the typical lighting calculations (including any shadows or reflections) and use the coverage of the CoC to calculate an alpha used to blend this sample with previous samples. Continue marching adding small random jitters (to remove banding). Do this until the alpha becomes too small, you go out of bounds or run out of march steps. Then mix in the background. It is fast because knighty realized you can add a portion of the CoC radius to the DE with each step. This is huge when the aperture is large. You just need to backstep to the edge of the CoC before taking the normal or shooting a shadow ray etc. The best use of this method is in the secondary marches. Soft shadows can take as few as a dozen steps and soft reflections as well, depending on how blurred it is. This is the opposite of montecarlo where it takes more samples for blurred regions to converge. OK now that I've sold you on it I have to warn you it is just barely out of the "fun hack" stage. Hopefully there are many improvements to come. Here are some more samples... Soft Reflections: https://www.shadertoy.com/view/Xd2GR1Hair-like features: https://www.shadertoy.com/view/Md2Gzh...and if someone has done this before let me know because you must have learned some more improvements by now!
|
|
« Last Edit: November 15, 2013, 05:46:48 PM by DarkBeam »
|
Logged
|
|
|
|
marius
Fractal Lover
Posts: 206
|
|
« Reply #1 on: November 09, 2013, 09:23:46 PM » |
|
Super cool, works surprisingly well Have been following the shadertoy activity but haven't had time to tinker much lately.
|
|
|
Logged
|
|
|
|
knighty
Fractal Iambus
Posts: 819
|
|
« Reply #2 on: November 10, 2013, 02:49:14 PM » |
|
Thaks eiffie for starting this thread. I think it's a better place to discuss this new/old technique. New, because you'r the first AFAIK who did it . Old, because there were earlier attempts: David Makin's and Kali's.
|
|
|
Logged
|
|
|
|
knighty
Fractal Iambus
Posts: 819
|
|
« Reply #3 on: November 10, 2013, 03:46:16 PM » |
|
Trying bokeh. I've just used this: scol+=33.*pow(max(0.0,dot(reflect(rd,N),L)),64.0)*vec3(.5,0.25,0.15); for specular componenet...Doesn't look right. One can also spot some other artifacts... Maybe combinig with multisampling (while reducing the apperture accordingly) would give better results (of both multisampling and this -cone tracing- method). BTW! it should also work well with path tracing. :
|
|
|
Logged
|
|
|
|
knighty
Fractal Iambus
Posts: 819
|
|
« Reply #4 on: November 10, 2013, 03:54:56 PM » |
|
And with Iq's soft shadows.
|
|
|
|
eiffie
Guest
|
|
« Reply #5 on: November 10, 2013, 04:35:49 PM » |
|
Thanks for the links to the earlier attempts. I will check them out now. If you do soft shadows with this method it can be faster because you get to add the CoC to the shadow's cone - but it does add some speckling. Thanks for the highlight samples. I'm wondering if they can be shaped with an aperature DE. Any shape you want and then somehow test reflect(rd,N)*CoC against the 2d DE??? Lots of questions still which is fun. I think the method could be called Sphere of Confusion marching/tracing although it does form a cone as you march. (a lumpy cone) Updated (again): I used the following code to produce shaped bokeh highlights. (thin crosses) vec3 H=reflect(L,N); scol+=0.5*pow(max(0.0,dot(rd,H)),512.0)*vec3(1.0,0.5,0.0); vec2 pt=vec2(dot(H,RT),dot(H,UP)); float mask=pow(1.0-min(abs(pt.x),abs(pt.y)),4.0);//a cross scol+=pow(rCoC,2.0)*50.0* pow(max(0.0,mask*dot(rd,H)), max(24.0-rCoC*100.0,2.0))*vec3(1.0,0.5,0.0);
Its just a fist attempt but it worked OK. Needs some more clamping so they don't get too big.
|
|
|
|
DarkBeam
Global Moderator
Fractal Senior
Posts: 2512
Fragments of the fractal -like the tip of it
|
|
« Reply #6 on: November 11, 2013, 07:32:57 PM » |
|
omg guys! please ... finish this script because I am sure it will revolutionize fractal raytracing! Set sticky to encourage ya brains! cheers
|
|
|
Logged
|
No sweat, guardian of wisdom!
|
|
|
eiffie
Guest
|
|
« Reply #7 on: November 12, 2013, 05:01:52 PM » |
|
lol darkbeam - working on that but it takes time. My bokeh highlight shapes above sadly only work on spheres oops sorry about that. It is a nice technique for marching through hair as you can treat it like any other DE. https://www.shadertoy.com/view/XsSGRD (webgl)
|
|
|
Logged
|
|
|
|
mclarekin
|
|
« Reply #8 on: November 13, 2013, 04:45:36 AM » |
|
Well the votes are in! 55,351 for Lumpy Cone of Confusion, and 1 (Eiffie??) for Sphere Of Confusion. And by the way, Lumpy Cone of Confusion is nothing new, as I've lived in it all my life. Due to, what can be loosely called "my lack of ability", this will be my only input to this post. . Seriously, SoC (Sphere Of Confusion) sounds great, keep up the good work!!
|
|
|
Logged
|
|
|
|
3dickulus
|
|
« Reply #9 on: November 13, 2013, 02:16:39 PM » |
|
Works well in Fragmentarium... Nice work eiffie, Fake Monte? what's next Full Monty?
|
|
|
Logged
|
|
|
|
eiffie
Guest
|
|
« Reply #10 on: November 13, 2013, 05:41:08 PM » |
|
Thanks for putting that script together. I hadn't ported it to Fragmentarium yet. Can you post the script here as well? I could post the copy you sent me but I don't want to release your added code without asking.
One great use for this is as a preview of the focalDepth and aperature. I hate shooting 2000 rays and then saying "wish I had focused a little closer".
|
|
|
Logged
|
|
|
|
knighty
Fractal Iambus
Posts: 819
|
|
« Reply #11 on: November 13, 2013, 08:24:35 PM » |
|
Can you post the script here as well? I could post the copy you sent me but I don't want to release your added code without asking.
Please! Thanks for the highlight samples. I'm wondering if they can be shaped with an aperature DE. Any shape you want and then somehow test reflect(rd,N)*CoC against the 2d DE??? Lots of questions still which is fun. I think the method could be called Sphere of Confusion marching/tracing although it does form a cone as you march. (a lumpy cone) Updated (again): I used the following code to produce shaped bokeh highlights. (thin crosses) vec3 H=reflect(L,N); scol+=0.5*pow(max(0.0,dot(rd,H)),512.0)*vec3(1.0,0.5,0.0); vec2 pt=vec2(dot(H,RT),dot(H,UP)); float mask=pow(1.0-min(abs(pt.x),abs(pt.y)),4.0);//a cross scol+=pow(rCoC,2.0)*50.0* pow(max(0.0,mask*dot(rd,H)), max(24.0-rCoC*100.0,2.0))*vec3(1.0,0.5,0.0);
Its just a fist attempt but it worked OK. Needs some more clamping so they don't get too big. Thank you! What are RT and UP? "Sphere of confusion" ? LOL! seems a good name. Partly because it is a little bit confusing. .
|
|
|
Logged
|
|
|
|
eiffie
Guest
|
|
« Reply #12 on: November 13, 2013, 09:46:18 PM » |
|
RT and UP are the vectors UU and VV that produce the ray direction (the directions at right angles to the ray direction). I just use descriptive names "right" and "up". But sadly unless the surface is spherical you get distorted shapes. You have to have a way of determining the center of the highlight. Can't think of one right now.
|
|
|
Logged
|
|
|
|
3dickulus
|
|
« Reply #13 on: November 14, 2013, 12:46:51 AM » |
|
ok here it is, I modified it a little to get progressive rendering to work and to make it fit into the Fragmentarium scheme of things but this is basicly cut and paste from the shadertoy script... 144.7 fps works on my box the guts are in SoC-DE-Raytracer.frag leaving the DE for user fractal mods. EDIT: not as hard as I thought, the SoC-DE-Raytracer.frag (attached) is a plugin replacement for DE-Raytracer.frag, works with Mandelbulb and KaliBox as expected EDIT2: the good script is on page 2
|
|
« Last Edit: November 15, 2013, 07:48:11 PM by 3dickulus, Reason: upd correction »
|
Logged
|
|
|
|
3dickulus
|
|
« Reply #14 on: November 15, 2013, 10:29:50 AM » |
|
Thanks again eiffie! an awsome contrib, the Sphere of Confusion an interesting place. I've just been playing with SoC v2 (from shadertoy) the one with knightys fuzzy shadows, and pushing it a bit to see how to get fine details, if you give me a map, SoC vars -> Fragmentarium Raytracer sliders, I'd be more than happy to put the SoC-Raytracer.frag together, better than the earlier cut'n'paste job. I need a map because I'm just guessing with some help from the comments in the code I've hacked in BaseColor and a few other things but crashed a couple of times pushing the wrong button too hard, lol, I feel like the sorcerer's aprentice trying not to let the magic escape, good fun and learning more about DE in GLSL
|
|
|
Logged
|
|
|
|
|