pouët.net

SDF to fragColor projection

category: code [glöplog]
you may have realized that i also only added operators when needed, "float2" misses some that are in "float3" for example...well, deadlines and their side-effects! ;)
Is there a signed distance function for the tetrahedron? i tried to google for it, but no luck..
added on the 2018-04-26 00:29:41 by rudi rudi
Here´s my Octahedron, you may be able to derive a Tetrahedron from it:
Code: //___OctAhEdrOn___ float octahedron(float3 p,float x) { p=abs(p); return (p.x+p.y+p.z-x)/3; }

I just tried and didn´t get it right, it´s still endless in y-direction! ;)

But i found this for you:
Code: // Isohedral Tetrahedron distance function float sdIsoTet(vec3 p, float h) { vec3 q = abs(p); float y = p.y, d1 = q.z-max(0.,y), d2 = max(q.x*.5 + y*.5,.0) - min(h, h+y); return length(max(vec2(d1,d2),.005)) + min(max(d1,d2), 0.); }

taken from this Shadertoy-Shader after searching for "tetrahedron".
ok. cool, will check that out!
added on the 2018-04-26 14:22:56 by rudi rudi
implemented adaptive subsampling. need to make the interpolation routine.
seemed to just get +10 fps, so must be a bottleneck somewhere else that i havent found yet.

BB Image
added on the 2018-04-29 17:16:55 by rudi rudi
maybe you forgot to break out of your loop once you found a color for your pixel?
sounds dumb,i know, but happened to me a lot when i was rewriting my marcher from scratch every 25 mins <- practice for shaderShowdown! ;)
Dont think so.

Code: //Make this function iterative or recursive such that we subdivide the local block into smaller and smaller ones. //square-groups: 32x32, 16x16, 8x8, 4x4, 2x2, 1x1... //Coordinates should be local. void Subsample(WORD x0, WORD y0, WORD x1, WORD y1, WORD x2, WORD y2, WORD x3, WORD y3, SceneSDF *sdf, Hash *hash) { if (x0 == x1) return; UINT pixelPos[4] = { x0 + y0 * WIDTH, x1 + y1 * WIDTH, x2 + y2 * WIDTH, x3 + y3 * WIDTH }; //Trace the four corner-rays sdf->raymarch(fvec3((-1.0f + (float)(x0 * TW)) * ASPECT, -1.0f + (float)(y0 * TH), -1.0f), &hash[pixelPos[0]]); sdf->raymarch(fvec3((-1.0f + (float)(x1 * TW)) * ASPECT, -1.0f + (float)(y1 * TH), -1.0f), &hash[pixelPos[1]]); sdf->raymarch(fvec3((-1.0f + (float)(x2 * TW)) * ASPECT, -1.0f + (float)(y2 * TH), -1.0f), &hash[pixelPos[2]]); sdf->raymarch(fvec3((-1.0f + (float)(x3 * TW)) * ASPECT, -1.0f + (float)(y3 * TH), -1.0f), &hash[pixelPos[3]]); WORD numIntersections = 0; numIntersections += hash[pixelPos[0]].intersect; numIntersections += hash[pixelPos[1]].intersect; numIntersections += hash[pixelPos[2]].intersect; numIntersections += hash[pixelPos[3]].intersect; if (numIntersections == 0) return; else if (numIntersections == 4) {} //if numIntersections == 4 then interpolate and return else if (numIntersections > 0) //If one or more of the corners are different: { int dx = (x1 - x0) >> 1; int dy = (y2 - y0) >> 1; //Find 5 new points and recurse. (Based on North, South, East and West definitions) Subsample(x0,y0,x0+dx,y0,x0+dx,y0+dy,x0,y0+dy,sdf,hash); Subsample(x0+dx,y0,x0+dx+dx,y0,x0+dx,y0+dy,x0+dx+dx,y0+dy,sdf,hash); Subsample(x0,y0+dy,x0+dx,y0+dy,x2,y2,x0+dx,y2,sdf,hash); Subsample(x0+dx,y0+dy,x0+dx+dx,y0+dy,x0+dx,y2,x3,y3,sdf,hash); } } //Draw Hash void Raymarcher::DrawAdaptiveSubsampling(UINT *pixel) { UINT yaddr = 0; for (WORD y = 0; y < HEIGHT - SAMPLESIZE; y += SAMPLESIZE, yaddr += WIDTH) for (WORD x = 0; x < WIDTH - SAMPLESIZE; x += SAMPLESIZE) { Subsample(x, y, x + SAMPLESIZE, y, x, y + SAMPLESIZE, x + SAMPLESIZE, y + SAMPLESIZE, sdf, hash); } //Draw hash points and blocks. yaddr = 0; for (WORD y = 0; y < HEIGHT - SAMPLESIZE; y++, yaddr += WIDTH) for (WORD x = 0; x < WIDTH - SAMPLESIZE; x++) { Hash *hashPtr = &hash[x + yaddr]; //if the hash suggests that there are any intersections we draw that fragment color if (hashPtr->intersect == TRUE) pixel[x + yaddr] = RGB32((int)(255 * hashPtr->color.r), (int)(255 * hashPtr->color.g), (int)(255 * hashPtr->color.b)); } }
added on the 2018-04-29 21:14:40 by rudi rudi
blerp gone wrong :P

BB Image
added on the 2018-04-30 00:27:23 by rudi rudi
Prettiest thing so far.
added on the 2018-04-30 01:54:27 by noby noby
Uglyest thing so far...

BB Image

hm. the thing is interpolating the blocks right, but since its doing this locally, the smaller blocks look like shit when combined. What to do to fix this? there shoud be a way to resolve this, but i cant figure it out at this late hour...
added on the 2018-04-30 02:23:47 by rudi rudi
I made a very compact tetrahedron today:
Code: // tEtrAhEdrOn float tetrahedron(float3 p, float a) { return max( (abs(p.x)+abs(p.y)+abs(p.z)-a)/3, p.y); }
macro version:
Code: #define tetra(p,a) max((abs(p.x)+abs(p.y)+abs(p.z)-a)/3,p.y)
LJ just fixed it...i had it rotating and so i wasn´t aware it´s upside down! ;)

LJ wrote:
Quote:

(flip sign on p.y to have it point up) :)
neat!
added on the 2018-05-04 00:12:16 by rudi rudi

login