Welcome to Fractal Forums

Fractal Software => Fragmentarium Gallery => Topic started by: Kali on December 17, 2012, 06:31:32 AM




Title: Prophetic
Post by: Kali on December 17, 2012, 06:31:32 AM
Prophetic

(http://nocache-nocookies.digitalgott.com/gallery/12/3869_17_12_12_6_31_31.jpeg)

http://www.fractalforums.com/index.php?action=gallery;sa=view;id=12985

Testing an experimental Fragmentarium renderer of mine, featuring positional light, and some kind of cheap/fake volumetric fog/lighting.



Title: Re: Prophetic
Post by: eiffie on December 18, 2012, 05:48:22 PM
Like it! Fakes are fun. Glad to see your making your own renderers - very interesting stuff.


Title: Re: Prophetic
Post by: Kali on December 20, 2012, 02:15:46 AM
Thanks eiffie! to be honest, I haven't wrote any own full renderer from scratch yet, I should said "a Fragmentarium raytracer mod of mine" instead, because I'm always introducing my own modifications on Syntopia's default Fragmentarium renderer, adding features and doing a lot of "experiments"  ;D

I'm having fun lately, indeed, with this kind of light effects, they are very cheap because is like a fog based on the minimum distance to positional light during the raytrace. Then I add regular distance fog, and clear a bit of light fog based on the distance between the ray hit position and the light position.

Here's another image:

(https://dl.dropbox.com/s/haqaob2azkl6sa7/kifsmounts.jpg)

Now I want to make the hard shadow projections on the fog, I think I know a way for doing it easily, let's see if it could work...


Title: Re: Prophetic
Post by: Kali on December 20, 2012, 09:20:47 PM
First attempts... not bad, but still have to work a lot on it. Also the script runs too slow for my taste...

(https://dl.dropbox.com/s/iun0pdp93c3bp9o/volutest1.jpg)

(https://dl.dropbox.com/s/hyn3okyo6aut1oa/volutest2.jpg)


A short clip with a moving light should be nice for better appreciation of the effect... I'll do some later.



Title: Re: Prophetic
Post by: M Benesi on December 20, 2012, 10:52:15 PM
  Nice.  Next up, light paths determined by surface normals of an object.  Then we make the disco ball light sources, or diamonds (stellated cuboctahedrons would work nicely, especially if Knighty corrects my formula...).

  About script times-  For whatever reason, locking variables seems to decrease render times.  Doesn't make sense, since the compiler is the thing that should do the branch tracing.... 

  and, well... the compiler does- add multiple if statements to a formula in Fragmentarium and it increases the time to compile exponentially-compile \, time \, \times \, 2^{number \, of \, if \, statements}, I think it does it less for if else statements...


Title: Re: Prophetic
Post by: Syntopia on December 21, 2012, 12:06:04 AM
Great light rays, Kali!

  About script times-  For whatever reason, locking variables seems to decrease render times.  Doesn't make sense, since the compiler is the thing that should do the branch tracing.... 
When you lock a variable in Fragmentarium, it replaces the uniform variable with a constant definition. This allows the GLSL compiler to remove dead code branches and do other optimizations. The GLSL compiler knows nothing about uniform variable values, so here it cannot optimize as much.

Quote
  and, well... the compiler does- add multiple if statements to a formula in Fragmentarium and it increases the time to compile exponentially-<Quoted Image Removed>, I think it does it less for if else statements...

The compile time does not double when you add an if-statement. This is easy to test in Fragmentarium since it always outputs the compile time. Just remember that you have to change the program before the compile - otherwise the GLSL compiler uses a cached version of the code, resulting in much faster compilation.


Title: Re: Prophetic
Post by: Kali on December 21, 2012, 12:14:49 AM
Thanks! at the moment I have to find manually the right adjustments to make them look good enough, it's a bit difficult and unhandy... also fog translucency is not properly done but well it's a start :)

  Nice.  Next up, light paths determined by surface normals of an object.  Then we make the disco ball light sources, or diamonds (stellated cuboctahedrons would work nicely, especially if Knighty corrects my formula...).

Well, this positional light script is indeed based on normals of a DE object... Here I'm using a sphere, but could be whatever DE object, I already made some tests with fractals as lights (not the same as eiffie's emissive material, but...). The disco ball light is a great idea... do you know how to do a DE version? anyway, first I want to improve the renderer (maybe this weekend, if the world is still here  :D)


Title: Re: Prophetic
Post by: M Benesi on December 21, 2012, 05:32:44 AM
  I'll see if I can do a DE type implementation of the stellated cuboctahedron.

  I mainly do escape time, which is totally sdrowkcab.  Unless you consider that it's easier to mix certain types of ET  :alien: formulas. 


Title: Re: Prophetic
Post by: M Benesi on December 21, 2012, 08:35:25 AM
@Kali-  If you want to make it "rounder" (for better dispersion of light) change the r2 part of the DE return function to:   r2 = length (z) -1.;

Ok, here's a frag for the DE Stellated CubeOctohedron.  Uncheck the "stellated" boolean (in the fractal tab) to make a standard one.

  The whole frag is below, based off of Knighty's Menger formula (it was easier to start from there).  I don't understand all the options for the DE raytracer, nor do I know if I used the "best" raytracer, so modify the frag (defaults as well) to optimize it if desired.  

Just the code for the DE section:
Code:
float DE(vec3 z)
{
float r;
float r2=0.;
int n = 0;
vec3 rmin=vec3(0.);
vec3 zoff=vec3(0.);
vec3 zstore=vec3(0.);
while (n < Iterations) {
z*=rot;
z=abs(z);
zstore=z;
rmin=vec3(100.,100.,100.);
//  x part  
r=(z.x-OffSet.x);
r=r*r;
if (r<rmin.x) { rmin.x=r;zoff.x= OffSet.x;}

r=(z.x)*z.x;
if (r<rmin.x) { rmin.x=r;zoff.x= 0.;}
// y part
r=(z.y-OffSet.y);
r=r*r;
if (r<rmin.y) { rmin.y=r;zoff.y= OffSet.y;}

r=(z.y)*z.y;
if (r<rmin.y) { rmin.y=r;zoff.y= 0.;}
//z part
r=(z.z-OffSet.z); r=r*r;
if (r<rmin.z) { rmin.z=r;zoff.z= OffSet.z;}

r=(z.z)*z.z;
if (r<rmin.z) { rmin.z=r;zoff.z= 0.;}

z=Scale*z-zoff*(Scale-1.0);

if (!Stellated) { // you can take out the not Stellated part here
if (abs(zstore.x)<abs(zstore.y)) {
if (abs(zstore.x)<abs(zstore.z)) {
z.x+=zoff.x;
} else {
z.z+=zoff.z;
}
} else {
if (abs(zstore.y)<abs(zstore.z)) {
z.y+=zoff.y;
} else {
z.z+=zoff.z;
}
}
} else { //  and just use the following section
if (rmin.x<rmin.y) { // if you do, remove the zstore variable, as it is
if (rmin.x<rmin.z) { // superfluous.  hahah... superfluous....  :D
z.x+=zoff.x;
} else {
z.z+=zoff.z;
}
} else {
if (rmin.y<rmin.z) {
z.y+=zoff.y;
} else {
z.z+=zoff.z;
}
}
}
if (n<ColorIterations) orbitTrap = min(orbitTrap, (vec4(abs(z),dot(z,z))));

n++;
}

r2=(max(abs(z.x),max(abs(z.y),abs(z.z)))-1.);

return r2*pow(Scale,float(-n));
}

@ Syntopia-  Just noticed your message.  First part I get (about the GLSL compiler).  Makes sense to lock branches.

  2nd part "The compile time does not double when you add an if-statement."

  I believe (I could be wrong, can try to duplicate if you'd like) I've ended up increasing compile time exponentially with each additional if statement (of one specific variety).

  Basically, I set up an integer check (not if -- else!):
Code:

vec3 example (vec3 hrmm) {
  if (check==1) { code  }

  some code.....

  if (check==2)  { code }

 some code

  if (check==3) { code }

  some code ...   etc.

  When I did it this way, each additional if statement doubled the compile time (from 752 to 1484 to 2888 or something along those lines- I had other stuff going on).  I can probably duplicate it if you want.  Yes.  I did offer to attempt to duplicate it twice.  


Title: Re: Prophetic
Post by: Sockratease on December 21, 2012, 12:02:49 PM
Ok, here's a frag for the DE Stellated CubeOctohedron.  Uncheck the "stellated" boolean (in the fractal tab) to make a standard one.

No Fair!!

I have been wanting a 3D Model of a CubeOctahedron ever since I saw the documentary "Black Whole" about Nassim Haramein's work.  His views are a bit far-fetched, but his findings about this structure are fascinating!

But...

I can't even run Fragmentarium on my hardware :(

Anybody (Darkbeam?) care to try to implement the formula in Mandelbubl3D so I can try to make an obj from a voxel stack?



Title: Re: Prophetic
Post by: eiffie on December 21, 2012, 05:42:36 PM
Wow kali I didn't think the fog shadows would be as easy as you thought - maybe they weren't. But great job!!! Now I am scratching my head on how you did it :)


Title: Re: Prophetic
Post by: knighty on December 21, 2012, 06:04:52 PM
@Benesi: I don't think that a stellated cubeoctahedron based fractal is achievable as a KIFS (meaning using only foldings and no "if' statement). After factoring the symmetries of the figure one needs to apply two scalings: one about the vetex of the cube and the other about the vertex of the octahedron. These two transformations are not symmetric. A recursive algorithme (which needs a stack) would be necessary... or just accept a non continuous DE.

The only advantage of KIFS over IFS is that it's possible to get a DE with an iterative algorithm. The drawback is that the obtained figures are always "very" symmetric.

@Kali: Those volumetric effects are :wow:
Code:
#info Faceted sphere Distance Estimator just like Darkbeam's discoballIFS
#include "DE-Raytracer.frag"
#group discoballIFS

// Number of faces in xy and yz planes.
uniform int Nfaces;  slider[0,9,100]

vec2 fold2D(vec2 p, vec2 fp){//algorithmically this is O(n)... It could be done in O(log(n)). Gess how ;o)
vec2 ap=p+vec2(1.);
int i=0;
while(i++<20 && any(notEqual( p, ap))){
ap=p;
p.y=abs(p.y);
float t=2.*min(0.,dot(p,fp)); p-=t*fp;
}
return p;
}

float DE(vec3 p) {
#define PI 3.14159
float angle = PI/float(Nfaces);
vec2 foldingPlaneNormal=vec2(sin(angle),-cos(angle));
p.xy=fold2D(p.xy,foldingPlaneNormal);
p.xz=fold2D(p.xz,foldingPlaneNormal);
return p.x-1.;
}


Title: Re: Prophetic
Post by: M Benesi on December 22, 2012, 04:19:29 AM
@Benesi: I don't think that a stellated cubeoctahedron based fractal is achievable as a KIFS (meaning using only foldings and no "if' statement). After factoring the symmetries of the figure one needs to apply two scalings: one about the vetex of the cube and the other about the vertex of the octahedron. These two transformations are not symmetric. A recursive algorithme (which needs a stack) would be necessary... or just accept a non continuous DE.

The only advantage of KIFS over IFS is that it's possible to get a DE with an iterative algorithm. The drawback is that the obtained figures are always "very" symmetric.

  Yeah.  There is a bit of weirdness with the stellated vs. normal (using the same DE):
(https://lh4.googleusercontent.com/-0UCcY5oBT-0/UNUmPCFuCTI/AAAAAAAAB7c/5vzpagYArSc/s400/non%2520stellated.jpg) (https://lh3.googleusercontent.com/-22PDzvheS0g/UNUmPCmJ90I/AAAAAAAAB7c/4RSa4wQ5_nE/s400/stellated-3.jpg)


Title: Re: Prophetic
Post by: Kali on December 22, 2012, 06:01:30 AM
@Benesi/@knighty: thanks! I'll try the codes later...

Wow kali I didn't think the fog shadows would be as easy as you thought - maybe they weren't. But great job!!! Now I am scratching my head on how you did it :)

Thanks! Well, no fake stuff this time... I added a fixed-step volumetric tracer to test if the point is on the light path or under shadow.
This is the main cause for being slow... I'm trying with bigger fixed-steps and then jittering using progressive renderer, it works faster and still looks ok. But my goal is to achieve real-time rendering so I must find another tricks and optimizations.

A short animation: (I'm too lazy and impatient for longer ones  :embarrass:)

https://dl.dropbox.com/s/z6reuqxayc3f2iw/volumetric_light_test.swf



Title: Re: Prophetic
Post by: eiffie on January 03, 2013, 05:49:01 PM
So every time Knighty posts links to papers I quickly download them, start reading, hit a math formula and stop, figure I can wing it from there - and then things go bad :) but this worked!
The idea is to place the camera in the light first and create a spherical depth texture then instead of DE checks along the ray you simply check the distance to the light against the depth texture and add fog if less than.
Code:
void main() {//first pass - render from light's perspective to get a depth texture
vec2 pt=(gl_FragCoord.xy/vec2(resolution))*PI;//map screen coords to sphere
vec3 rayDir = vec3(sin(pt.y)*cos(pt.x),cos(pt.y),sin(pt.y)*sin(pt.x));
vec3 ray = lightPosition;//place the camera at the light
float rayLen=0.0,dist=lightFallOff;
for(int iSteps=0;iSteps<MaxSteps && dist>=HitDistance && rayLen<=lightFallOff;iSteps++){
rayLen+=dist=DE(ray+rayLen*rayDir);
}//march until you hit something or the light gets too weak
rayLen=clamp(rayLen/lightFallOff,0.0,0.99);
gl_FragColor = Encode(rayLen);//for non-float textures just shove the float into bytes
gl_FragDepth = rayLen;
}
void main() {//second pass - draw the scene as usual then fill in fog
... usual rendering code here ...
... rayLen has depth of scene, ray is position of hit, color has color:)

for(float rl=0.0;rl<rayLen;rl+=fogStep){//take small steps along the ray checking depth
vec3 lightCamDir=ray+rayDir*rl-lightPosition;//get the direction FROM light
float d=length(lightCamDir);
lightCamDir=normalize(lightCamDir);
float phi=acos(lightCamDir.y);//map back to screen coords
vec2 pt=vec2(acos(lightCamDir.x/sin(phi)),phi)/3.1416;
//add fog light only if the distance to the light is less than that in texture
if(d<Decode(texture2D(tex,pt))*lightFallOff)color.rgb+=fogColor/(d*d);
}
}
You could do these two passes in Fragmentarium using the backBuffer and the backBufferCounter to flip back and forth then throw away every other frame.

http://youtu.be/AnA3s3ncL94 (http://youtu.be/AnA3s3ncL94)


Title: Re: Prophetic
Post by: Kali on January 03, 2013, 08:00:56 PM
Nice work!! does it render fast?

I took a look at the papers but I didn't have the time for making an implementation in fragmentarium yet. Thanks for the code!


Title: Re: Prophetic
Post by: DarkBeam on January 03, 2013, 08:01:17 PM
Stunning stuff Pablo :beer:


Title: Re: Prophetic
Post by: DarkBeam on January 03, 2013, 08:11:13 PM
Code:
#info Faceted sphere Distance Estimator just like Darkbeam's discoballIFS
#include "DE-Raytracer.frag"
#group discoballIFS

// Number of faces in xy and yz planes.
uniform int Nfaces;  slider[0,9,100]

vec2 fold2D(vec2 p, vec2 fp){//algorithmically this is O(n)... It could be done in O(log(n)). Gess how ;o)
vec2 ap=p+vec2(1.);
int i=0;
while(i++<20 && any(notEqual( p, ap))){
ap=p;
p.y=abs(p.y);
float t=2.*min(0.,dot(p,fp)); p-=t*fp;
}
return p;
}

float DE(vec3 p) {
#define PI 3.14159
float angle = PI/float(Nfaces);
vec2 foldingPlaneNormal=vec2(sin(angle),-cos(angle));
p.xy=fold2D(p.xy,foldingPlaneNormal);
p.xz=fold2D(p.xz,foldingPlaneNormal);
return p.x-1.;
}

It's brilliant but I'm not sure if it's so fast when facets become a lot (say, 50,100) - I used polyfold instead. :beer:


Title: Re: Prophetic
Post by: eiffie on January 03, 2013, 09:24:53 PM
Yes the depth texture version runs fast since you are replacing a DE march towards the light with a single texture lookup. Less than 2x normal rendering speed and if the light and fractal aren't moving with respect to each other (only the camera moves) then you can precompute the depth texture once! You could use this texture to calculate shadows as well but you would need a large texture to avoid pixelating.

So your version is still better when zooming in and for high precision stills.


Title: Re: Prophetic
Post by: Syntopia on January 03, 2013, 09:45:40 PM
Yes the depth texture version runs fast since you are replacing a DE march towards the light with a single texture lookup. Less than 2x normal rendering speed and if the light and fractal aren't moving with respect to each other (only the camera moves) then you can precompute the depth texture once! You could use this texture to calculate shadows as well but you would need a large texture to avoid pixelating.

Kudos for implementing that, Eiffie! It is a great idea to use shadowmaps for volumetric lights.

Did you see Quilez recent post: http://www.iquilezles.org/www/articles/multiresaocc/multiresaocc.htm
Here he uses a blurred shadowmap for low-frequency shadows (combined with SSAO and baked AO :-))

You could do these two passes in Fragmentarium using the backBuffer and the backBufferCounter to flip back and forth then throw away every other frame.

I'm not sure this is the best way (how would you throw away every other frame?), but Fragmentarium already supports two-pass shading. You can add an additional buffershader (e.g. with the command: #buffershader "DepthBufferShader.frag"), which can read from an 'uniform sampler2D frontbuffer'.

But this is really something I'd like to redesign at some point - it is quite hackish. It would be great to be able to setup a arbitrary pipeline of shaders and buffers, and only recalculate specific buffers if the uniforms bound to them changes (e.g. a shadowmap would only be recalculated if the light source moved, the tone mapping shader would not need to render the whole scene to change a simple color parameters and so on).




Title: Re: Prophetic
Post by: M Benesi on January 03, 2013, 11:47:58 PM
  Nice job.  Fog shadows are pretty awesome. 


Title: Re: Prophetic
Post by: eiffie on January 04, 2013, 05:44:16 PM
Thanks Syntopia for explaining about the buffers - I also now see there is an init() in the vertex section - lol. I should have guessed you thought of those things already :) I would love to see the geometry shader IQ is working on!


Title: Re: Prophetic
Post by: eiffie on January 05, 2013, 06:20:08 PM
Kali have you tried using your dynamic fractal waves (3d version) with this fog shadow effect? It should give a nice smokey look. I haven't been able to render a good example of it.


Title: Re: Prophetic
Post by: Kali on January 05, 2013, 10:25:54 PM
I was thinking of finding a way for texturing the fog, I was going to try the 3DKaliset formula with some julias and low ierations, but the fractal waves could be a better idea also for animating, will give it a try when I find the time, thanks for the suggestion  :dink:


Title: Re: Prophetic
Post by: Kali on January 09, 2013, 08:08:06 AM
I just saw your smoke fog video, eiffie, looks great!

I used 3D Kaliset for the fog here:

(http://nocache-nocookies.digitalgott.com/gallery/13/thumb_3869_09_01_13_7_40_56.jpeg)
http://www.fractalforums.com/index.php?action=gallery;sa=view;id=13145

I will try some fog animation later.


Title: Re: Prophetic
Post by: knighty on January 09, 2013, 03:55:39 PM
Great one effie! it could maybe be faster with the tricks described by the papers  :tease:. I don't think it could then be feasible in fragmentarium.

Kali: this last render is absolutely marvelous: atmosphere and sens of scale... perfect!

Darkbeam: actually you can also do it in O(1): get angle then apply an infinite folding... I don't know how it is done in polyfold though.


Title: Re: Prophetic
Post by: Kali on February 23, 2013, 01:04:39 AM
I came back to this thread to look for eiffie's optimization code I want to implement in Fragmentarium, and I noticed I didn't thank knighty's kind comment on "ARQ" render
so... thanks knighty!! :)

Now back to coding, wish me luck... I never used the buffer before :embarrass:


Title: Re: Prophetic
Post by: Kali on February 27, 2013, 12:22:59 AM
After some problems, I got it working... I want to implement a few more things and I'll share the .frag.

@eiffie: I implemented full 360º shadowmap, so mapping resolution is quite low. Does your original code make only 180º view shadow mapping? I mean, only fog shadows between light and camera are calculated? I'll maybe add a "shadowmap field of view" parameter.


First test render:

(https://dl.dropbox.com/s/tlvf9ab8ojoyk1n/vfogoptimized.jpg?token_hash=AAEXe8QKkqioc9wB0XTc2Qy5k3IyH6eAF5IglYMzu6wSRw)



Title: Re: Prophetic
Post by: eiffie on February 27, 2013, 06:01:41 PM
I have done that to get quick shadows (180 and less) but for the fog effect I just use a bigger texture because I want the light moving "inside" a fractal.


Title: Re: Prophetic
Post by: Kali on March 02, 2013, 03:56:29 AM
I have done that to get quick shadows (180 and less) but for the fog effect I just use a bigger texture because I want the light moving "inside" a fractal.

Yep, too bad I only have the alpha channel of the screen-size buffer to store things in Fragmentarium.
But today I managed to put two shadowmaps in a floating point this way:


encode:

Code:
smap=min(50000,floor(smap1*1000))+fract(smap2/100);

decode:
 
Code:
if (lightdir.z>0) smap=floor(smap)/1000; else smap=fract(smap)*100;


So I have two 180º maps, one on the integer part, and the other on the fractional part. I choose the right one based on light direction (lightdir.z>0), and as each one is the size of the screen, I have twice the resolution than before ;)

On the other hand, I have less distance accuracy (.001), but only noticeable in big zooms. Also fog shadow works only if object is at a max distance of 50 from light source, but it's far enough I think.

I still want to have a better fog translucency approach, so I'll be working a bit more on the script before making it public.







Title: Re: Prophetic
Post by: eiffie on March 02, 2013, 05:21:10 PM
Your original method has the nice property of allowing you to cast cloud shadows as well - meaning the cloud actually casts a shadow on itself when it is too dense. I like your work-around :)


Title: Re: Prophetic
Post by: eiffie on March 06, 2013, 05:33:48 PM
Here is a sample of fog (clouds) catching light AND casting shadows. It means adding yet another loop :). Well that's why we have GPUs! You can still use the texture lookup method so my last post is incorrect but I wrote this up without using buffers. As you can imagine it is pretty slow :(
http://www.youtube.com/watch?v=wI6-mVBFoz0&feature=player_embedded


Title: Re: Prophetic
Post by: Kali on March 07, 2013, 09:27:47 AM
Awesome stuff, eiffie!!!