pouët.net

So, what do distance field equations look like? And how do we solve them?

category: code [glöplog]
If this is for 4k i think matrices are pretty much just overhead for this kind of rendering..however it really is a fantastic idea to start with simple primitives and work your way up.

The slides are actually all that's available (here btw) :) But deformations are clearly shown on slides 37 and 38.
added on the 2009-08-08 20:24:28 by ferris ferris
Quote:
however it really is a fantastic idea to start with simple primitives and work your way up


I agree, complex geometry defined by simple distance fields is a really fucking fresh concept. It's a pretty exciting idea!
added on the 2009-08-08 20:29:25 by sigflup sigflup
I don't think it's fresh, I think it's very old. But it's still very funny!

My version of the distance to the box:

// b is defines the size of the box in x, y, z directions
float distanceToBox( in vec3 p, in vec3 b )
{
vec3 di = max(abs(p)-b,0.0);
return sqrt(dot(di,di));
}

Note that usually you don´t need to do the square root for all the boxes of the scene, but only once when you know witch one is the closest. You determine that one by combining the distances with min(), as Decipher said.

Distance to a sphere:

// r is the radius of the sphere
float distanceToSphere( in vec3 p, float r )
{
return length(p) - r;
}

etc, I suppose you can guess the others (plane, cylinder, torus).

Perhaps this helps: http://iquilezles.org/www/material/nvscene2008/nvscene2008.htm
added on the 2009-08-08 23:28:00 by iq iq
Thanks to this thread I finally understand the distance field / sphere tracing stuff... The simplicity is ridiculous once you get it. Thanks you all :)

BB Image
added on the 2009-08-17 21:34:51 by Rob Rob
CrossProduct: Exactly the same for me..once you get it you start bapping yourself on the head over and over and over :P

Great to see it worked for you :)
added on the 2009-08-17 21:42:00 by ferris ferris
Ferris: Yeah, I feel so stupid for not getting it before...

Only problem now is the DX HLSL compiler. It's already taking some time to compile the shader. It's increasing with every line of code added :( Tried the skip optimization flags but no cigar. Oh well... patience :)
added on the 2009-08-17 22:16:24 by Rob Rob
cross product: 313 FPS!? Are you working on a Tesla Cluster?
added on the 2009-08-17 22:21:20 by decipher decipher
Decipher: Almost! ;)

Actually, it's 500 FPS in 1280x720 without the post processing blur stuff.

But it's only a cube and a sphere and some normal calculations.

It's a Radeon 4870 1GB btw.
added on the 2009-08-17 22:27:26 by Rob Rob
I find it very hard to believe :). I should be learning in a few weeks, when I have access to the said card.
added on the 2009-08-17 22:31:12 by decipher decipher
CrossProduct: yeah ATI cards have much longer shader compile times than NVidia; at least for GLSL (I'm unfamiliar with HLSL but I'd imagine the shader compiler can't be much different in speed).
added on the 2009-08-17 22:31:38 by ferris ferris
And I'm with Decipher on this one....check your FPS counter code please ;)
added on the 2009-08-17 22:32:05 by ferris ferris
Ferris: I am pretty sure it's correct. I have been coding fps counters since 1997 ;)

And also, in full screen I get 60 fps when I tell D3D to synchronizing with the refresh rate. 60 FPS is exactly the refresh rate of my monitor.
added on the 2009-08-17 22:41:17 by Rob Rob
*to synchronize
added on the 2009-08-17 22:44:52 by Rob Rob
It is a really powerful card. It also consumes LOTS of power! Thank god the ventilator is running at around 25 % when idling and coding because at 100 % it sounds and feels, with the hot wind blowing out of the case, like a vacuum cleaner.
added on the 2009-08-17 22:50:52 by Rob Rob
I am utmost curious, could you post the code please?
added on the 2009-08-17 22:53:52 by decipher decipher
You sure your fps counter is correct? the reason I ask is because the GPU doesn't stall the CPU till it's done rendering. If you're simply checking CPU timer values per frame, then your main loop could be executing over and over while your GPU is working on the frame, and thus incorrect. 1997 didn't have shaders, mind you :P (BTW you drawing fps info to the window title supports this, since window titles can easily be updated faster than the frame is drawn).

The only thing that throws a wrench in the hypothesis is the D3D synchronize. But even then (and I'm no D3D expert; far from it) perhaps D3D caps CPU framerate?
added on the 2009-08-17 22:56:00 by ferris ferris
I am calculating the fps once every second :)

Then I write it to the window and to a log file.

Very basic/ugly/don't care code following after the beep:

Code: // RENDER COOL STUFF frameCount++; float currentTime = Timer::Get(); if ((currentTime - oldTime) > 1000.f) { currentFps = (frameCount / (float)(currentTime - oldTime)) * 1000.f; frameCount = 0; oldTime = currentTime; sprintf(titleBuffer, "%03.0f.00 - %06.2f fps", currentTime / 1000.f, currentFps); SetWindowText(hWnd, titleBuffer); Logger::Write(titleBuffer); }
added on the 2009-08-17 23:01:55 by Rob Rob
Also, when working with normal scenes (primitives) and some SSAO and some post processing I have around 40 FPS at 1920x1200.
added on the 2009-08-17 23:02:59 by Rob Rob
Ah I see, so your GPU-based program measures CPU efficiency :)
added on the 2009-08-17 23:04:10 by ferris ferris
You want the shader code?
added on the 2009-08-17 23:05:42 by Rob Rob
(We're not trying to bring you down btw. We're simply impressed and thus quite skeptical..either you've written the best GPU marcher to date [putting YUP, iq, and even mentor to shame] or you have wrong info.)
added on the 2009-08-17 23:05:42 by ferris ferris
It's only a cube and a sphere sir :) No AO/No Lighting/No shadows/No perlin noise/NOTHING!!! :D
added on the 2009-08-17 23:06:33 by Rob Rob
how bout you post the .exe? :) Then we can all test it to see if it's the card.

I'm quite curious. :)
added on the 2009-08-17 23:08:24 by ferris ferris
I'm pretty sure this gives the high speed:

Code: float d = distance(rayPosition); if (d < 0.005f)


Instead of your

Code: float d = distance(rayPosition); if (d < 0.f)


So probably when I add some perlin noise to distort the surface I have to make this value much lower.
added on the 2009-08-17 23:09:37 by Rob Rob
i'd love to give it a whirl on my GMA950? *grin*
added on the 2009-08-17 23:11:11 by superplek superplek

login