pouët.net

Raymarching Beginners' Thread

category: code [glöplog]
BB Image
A simple cloudy spikeball with a technique adapted from my code is pron.

Code: uniform float t; uniform vec2 wh; #define pi 3.14159265 #define R(p, a) p=cos(a)*p+sin(a)*vec2(p.y, -p.x) #define hsv(h,s,v) mix(vec3(1.), clamp((abs(fract(h+vec3(3., 2., 1.)/3.)*6.-3.)-1.), 0., 1.), s)*v float pn(vec3 p) { vec3 i = floor(p); vec4 a = dot(i, vec3(1., 57., 21.)) + vec4(0., 57., 21., 78.); vec3 f = cos((p-i)*pi)*(-.5) + .5; a = mix(sin(cos(a)*a), sin(cos(1.+a)*(1.+a)), f.x); a.xy = mix(a.xz, a.yw, f.y); return mix(a.x, a.y, f.z); } float fpn(vec3 p) { return pn(p*.06125)*.5 + pn(p*.125)*.25 + pn(p*.25)*.125; } vec3 n1 = vec3(1.000,0.000,0.000); vec3 n2 = vec3(0.000,1.000,0.000); vec3 n3 = vec3(0.000,0.000,1.000); vec3 n4 = vec3(0.577,0.577,0.577); vec3 n5 = vec3(-0.577,0.577,0.577); vec3 n6 = vec3(0.577,-0.577,0.577); vec3 n7 = vec3(0.577,0.577,-0.577); vec3 n8 = vec3(0.000,0.357,0.934); vec3 n9 = vec3(0.000,-0.357,0.934); vec3 n10 = vec3(0.934,0.000,0.357); vec3 n11 = vec3(-0.934,0.000,0.357); vec3 n12 = vec3(0.357,0.934,0.000); vec3 n13 = vec3(-0.357,0.934,0.000); vec3 n14 = vec3(0.000,0.851,0.526); vec3 n15 = vec3(0.000,-0.851,0.526); vec3 n16 = vec3(0.526,0.000,0.851); vec3 n17 = vec3(-0.526,0.000,0.851); vec3 n18 = vec3(0.851,0.526,0.000); vec3 n19 = vec3(-0.851,0.526,0.000); float spikeball(vec3 p) { vec3 q=p; p = normalize(p); vec4 b = max(max(max( abs(vec4(dot(p,n16), dot(p,n17),dot(p, n18), dot(p,n19))), abs(vec4(dot(p,n12), dot(p,n13), dot(p, n14), dot(p,n15)))), abs(vec4(dot(p,n8), dot(p,n9), dot(p, n10), dot(p,n11)))), abs(vec4(dot(p,n4), dot(p,n5), dot(p, n6), dot(p,n7)))); b.xy = max(b.xy, b.zw); b.x = pow(max(b.x, b.y), 140.); return length(q)-2.5*pow(1.5,b.x*(1.-mix(.3, 1., sin(t*2.)*.5+.5)*b.x)); } float f(vec3 p) { p.z += 6.; R(p.xy, t); R(p.xz, t); return spikeball(p) + fpn(p*50.+t*15.) * 0.45; } vec3 g(vec3 p) { vec2 e = vec2(.0001, .0); return normalize(vec3(f(p+e.xyy) - f(p-e.xyy),f(p+e.yxy) - f(p-e.yxy),f(p+e.yyx) - f(p-e.yyx))); } float as(vec3 p, vec3 n, float d, float i) { float s = sign(d); float o = s*.5+.5; for (; i > 0.; --i) { o -= (i*d - f(p+n*i*d*s)) / exp2(i); } return o; } void main(void) { // p: position on the ray // d: direction of the ray vec3 p = vec3(0.,0.,2.); vec3 d = vec3((gl_FragCoord.xy/(0.5*wh)-1.)*vec2(wh.x/wh.y,1.0), 0.) - p; d = normalize(d); // ld, td: local, total density // w: weighting factor float ld, td= 0.; float w; // total color vec3 tc = vec3(0.); // i: 0 <= i <= 1. // r: length of the ray // l: distance function float i, r, l, b=0.; // rm loop for (i=r=l=0.; i<1. && l>=0.001*r && r < 50. && td < .95; i+=1./64.) { // evaluate distance function l = f(p) * 0.5; // check whether we are close enough if (l < .05) { // compute local density and weighting factor ld = 0.05 - l; w = (1. - td) * ld; // accumulate color and density tc += w; //* hsv(w, 1., 1.); td += w; } td += 1./200.; // enforce minimum stepsize l = max(l, 0.03); // step forward p += l*d; r += l; } gl_FragColor = vec4(tc, 1.0); }
added on the 2011-05-21 16:17:20 by las las
That's just awesome! Looks like cotton candy!
added on the 2011-05-21 16:31:56 by xernobyl xernobyl
BB Image
For my gf :)

But it seems that the distance function for the heart is pretty bad. Is it even an SDF?
added on the 2011-05-21 16:52:44 by las las
(ignore the banding)
added on the 2011-05-21 16:52:58 by las las
nice dustball las. could need some more crisp details and some more transparent fiber like texture. wish I could do it myself but my rig won't compile rm shaders. should do it in classic fake rendering? tsh ... can't focus on coding today anyway. -.-
added on the 2011-05-21 17:15:50 by yumeji yumeji
what do you mean by a fiber like texture?
(credit to chock for the technique of course)
I now implemented it in a completely branchless manner.

...
Code: // check whether we are close enough if (l < .05) { // compute local density and weighting factor ld = 0.05 - l; w = (1. - td) * ld; // accumulate color and density tc += w; //* hsv(w, 1., 1.); td += w; }

branchless:

Code: // check whether we are close enough (step) // compute local density and weighting factor const float h = .05; ld = (h - l) * step(l, h); w = (1. - td) * ld; // accumulate color and density tc += w;// * hsv(w*3.-0.5, 1.-w*20., 1.); td += w;

added on the 2011-05-21 18:23:51 by las las
That cottonwool-spikeball looks good! I'll have to play with that code when i get some time!
added on the 2011-05-21 22:19:03 by psonice psonice
Quote:
what do you mean by a fiber like texture?

Probably another noise octave.
added on the 2011-05-21 22:42:55 by xernobyl xernobyl
I shouldn't talk big but: You don't know or can't translate what a fiber is? My dictionary said it's right. If this is meant to be cottonwool you should know what I mean with that kinda details. and WTF... add more noize. -.- random lines maybe.

Anyway... I'll do some code tommorow when I'm fit again and see what I can do. I even wanna see the old jelly spikeballs with sugar. I'm gonna murder that RM stuff.
added on the 2011-05-21 23:14:19 by yumeji yumeji
My breakfast lacks fiber.
added on the 2011-05-21 23:59:57 by trc_wm trc_wm
So you want it to look like fucking "Zuckerwatte"?
added on the 2011-05-22 00:02:48 by las las
It would work las. so "zuckerwatte" or some other wool. that thing looks something like the ambient only portion of it. just not that detailed. I pictured a lil more in there. somewhat fibers, specular flakes and more contrast to it and it's cool.

can't help it. I like decent spec(tac)ular shading. ;)

added on the 2011-05-22 00:16:20 by yumeji yumeji
It doesn't look like cotton wool because it's supposed to look like cloud ;)

Las: would your SSS work with this? I think clouds look darker at the bottom, because there's more cloud between the surface + the light source there. Not sure if it'll work, but if it's lit from the top, with SSS that bends towards the light source from the surface, you might get good looking clouds
added on the 2011-05-22 00:56:17 by psonice psonice
That is awkward. It's supposed to be like a cloud in the sky? Ok. Well then the background and ambient is the wrong color to generate a feel like looking into the sky.

I can adapt and play. but... -.-
added on the 2011-05-22 01:37:22 by yumeji yumeji
psonice sss isn't that good looking with the technique... but i did some other strange experiments.

BB Image
BB Image
BB Image
added on the 2011-05-22 01:59:46 by las las
0.0

Noice.
added on the 2011-05-22 04:41:37 by Mewler Mewler
that last one is awesome.. looks at bit like cast iron..
las: the middle one looks killer. The last one looks too over-the-top, ruining the subtlety of the effect.
added on the 2011-05-22 12:48:08 by gloom gloom
i'm sceptical -- the stills look great indeed, but how does that texture behave with respect to changes in view position? (I.e. post a video where the thing is rotating!)
added on the 2011-05-22 20:14:41 by Hyde Hyde
hyde: not tried it, but.. it's not a screenspace dependent effect, so it should rotate nicely. It's actual surface noise, so I guess the only problem with rotation will be if the details are so small they're aliasing as it rotates, and I don't think that will happen here (especially if it's animated :)

Las: I'm with gloom. The middle one is killer. Animate it, make lightning ripple through it, win compo.
added on the 2011-05-23 00:55:28 by psonice psonice
Quote:
Las: I'm with gloom. The middle one is killer. Animate it, make lightning ripple through it, win compo.

Don't forget the killer fecal blur overlay.
added on the 2011-05-23 01:25:35 by xernobyl xernobyl
I like the middle one too ;)
I wont take a video - but I've got something else:

BB Image
(You have to trust me - that's a nice twister!)
added on the 2011-05-23 03:06:01 by las las
that looks kinda cool now las. tons of "details" probably made of noize.
added on the 2011-05-23 03:06:35 by yumeji yumeji
Yep, that looks hot (but I hope you're keeping your best stuff secret as a surprise in your next demo ;)
added on the 2011-05-23 03:31:03 by psonice psonice
Actually I shared all the current stuff, it's still far away from what I want.
From now on I'll stop posting screenshots here, it's your turn now! :)
added on the 2011-05-23 03:37:45 by las las

login