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.
The slides are actually all that's available (here btw) :) But deformations are clearly shown on slides 37 and 38.
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!
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
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
Thanks to this thread I finally understand the distance field / sphere tracing stuff... The simplicity is ridiculous once you get it. Thanks you all :)
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 :)
Great to see it worked for you :)
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 :)
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 :)
cross product: 313 FPS!? Are you working on a Tesla Cluster?
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.
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.
I find it very hard to believe :). I should be learning in a few weeks, when I have access to the said card.
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).
And I'm with Decipher on this one....check your FPS counter code please ;)
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.
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.
*to synchronize
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.
I am utmost curious, could you post the code please?
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?
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?
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:
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);
}
Also, when working with normal scenes (primitives) and some SSAO and some post processing I have around 40 FPS at 1920x1200.
Ah I see, so your GPU-based program measures CPU efficiency :)
You want the shader code?
(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.)
It's only a cube and a sphere sir :) No AO/No Lighting/No shadows/No perlin noise/NOTHING!!! :D
how bout you post the .exe? :) Then we can all test it to see if it's the card.
I'm quite curious. :)
I'm quite curious. :)
I'm pretty sure this gives the high speed:
Instead of your
So probably when I add some perlin noise to distort the surface I have to make this value much lower.
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.
i'd love to give it a whirl on my GMA950? *grin*