Logo by bib - Contribute your own Logo!

END OF AN ERA, FRACTALFORUMS.COM IS CONTINUED ON FRACTALFORUMS.ORG

it was a great time but no longer maintainable by c.Kleinhuis contact him for any data retrieval,
thanks and see you perhaps in 10 years again

this forum will stay online for reference
News: Visit us on facebook
 
*
Welcome, Guest. Please login or register. January 17, 2019, 04:56:47 AM


Login with username, password and session length


The All New FractalForums is now in Public Beta Testing! Visit FractalForums.org and check it out!


Pages: [1] 2 3 4   Go Down
  Print  
Share this topic on DiggShare this topic on FacebookShare this topic on GoogleShare this topic on RedditShare this topic on StumbleUponShare this topic on Twitter
Author Topic: Fast fake montecarlo for raymarching - Now with fragmentarium script!  (Read 9458 times)
Description: a rendering technique to quickly produce DOF,AA,Soft Shadows and Reflections
0 Members and 1 Guest are viewing this topic.
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 smiley 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.

<a href="http://www.youtube.com/v/Z5SOA2xSLnQ&rel=1&fs=1&hd=1" target="_blank">http://www.youtube.com/v/Z5SOA2xSLnQ&rel=1&fs=1&hd=1</a> 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/Xd2GR1
Hair-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  A Beer Cup

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  grin. 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. Sceptical

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.  :smiley



* DOF000.JPG (23.24 KB, 640x512 - viewed 636 times.)

* DOF010.JPG (23.39 KB, 640x512 - viewed 626 times.)
Logged
knighty
Fractal Iambus
***
Posts: 819


« Reply #4 on: November 10, 2013, 03:54:56 PM »

And with Iq's soft shadows.


* DOF020.JPG (21.72 KB, 640x512 - viewed 653 times.)
Logged
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)
Code:
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.


* bokeh.jpg (9.18 KB, 574x320 - viewed 662 times.)
« Last Edit: November 11, 2013, 03:13:15 PM by eiffie, Reason: code fix » Logged
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! cheesy
Set sticky to encourage ya brains! cheesy 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 sad 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
Fractal Senior
******
Posts: 1739



« 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!! smiley smiley
Logged
3dickulus
Global Moderator
Fractal Senior
******
Posts: 1558



WWW
« Reply #9 on: November 13, 2013, 02:16:39 PM »

Works well in Fragmentarium...

Nice work eiffie,       Fake Monte? what's next Full Monty?   rolling on floor laughing



* Fake-Monty.jpg (20.77 KB, 720x480 - viewed 654 times.)
Logged

Resistance is fertile...
You will be illuminated!

                            #B^] https://en.wikibooks.org/wiki/Fractals/fragmentarium
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!  cheesy

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)
Code:
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.  grin.
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
Global Moderator
Fractal Senior
******
Posts: 1558



WWW
« 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 cheesy 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 cheesy

EDIT2: the good script is on page 2


* SoC-DE-by-eiffie.jpg (86.9 KB, 1059x485 - viewed 647 times.)
* SoC-DE-Raytracer.frag (14.44 KB - downloaded 183 times.)

* SoC-DE-KaliBox.jpg (81.52 KB, 1056x475 - viewed 625 times.)
« Last Edit: November 15, 2013, 07:48:11 PM by 3dickulus, Reason: upd correction » Logged

Resistance is fertile...
You will be illuminated!

                            #B^] https://en.wikibooks.org/wiki/Fractals/fragmentarium
3dickulus
Global Moderator
Fractal Senior
******
Posts: 1558



WWW
« Reply #14 on: November 15, 2013, 10:29:50 AM »

Thanks again eiffie! an awsome contrib, the Sphere of Confusion grin 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 embarrass

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


* Eiffie-SoC-DE4.jpg (203.73 KB, 840x600 - viewed 705 times.)
Logged

Resistance is fertile...
You will be illuminated!

                            #B^] https://en.wikibooks.org/wiki/Fractals/fragmentarium
Pages: [1] 2 3 4   Go Down
  Print  
 
Jump to:  

Related Topics
Subject Started by Replies Views Last post
Major Raymarching Optimization Mandelbulb Implementation keldor314 8 4943 Last post December 27, 2013, 08:48:22 PM
by Syntopia
buddhabrot montecarlo and quasi-montecarlo Programming knighty 3 2123 Last post September 25, 2013, 04:27:03 PM
by Roquen
raymarching optimization using golden ratio ... General Discussion cKleinhuis 4 1741 Last post December 29, 2012, 12:21:32 PM
by cKleinhuis
Raymarching misses fractal? Programming fractalnoob 1 894 Last post June 21, 2013, 06:35:43 AM
by AndyAlias
How to get Z-Depth mask in MonteCarlo. Mandelbulber alive 1 823 Last post May 05, 2017, 11:12:10 AM
by Sockratease

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines

Valid XHTML 1.0! Valid CSS! Dilber MC Theme by HarzeM
Page created in 0.149 seconds with 28 queries. (Pretty URLs adds 0.01s, 2q)