pouët.net

Go to bottom

Raymarching Beginners' Thread

category: code [glöplog]
Just started cleaning up the code and had an idea, and I see what the problem is now. This might apply to raymarching too, in some cases, depending on the 'distance to sphere' implementation and the scene.

What happens is roughly this:

- You have a reflective object in the centre of the scene (like my shiny ball above)

- You have an inverted sphere enclosing it (radius is negative, or you're doing min(obj, -sphere) or similar). This is the 'sky' in my pic above.

- With an inverted sphere, you only see the "far side" of the sphere, so the front is open. You can't see the 'front' of it.

- The reflection means you can see the back AND the front in the camera view. Worse, in a sphere reflection, the viewing angle is extremely wide - more than 180 degrees, so you see the front and back together.

- The front is invisible, so in some cases you'll only see the reflection of a hemisphere. In my case, I see both sides, but there is a glitch at the seem (not sure why this is, but I remember having trouble with this before so I guess my fix is slightly fucked).
added on the 2011-06-10 17:18:59 by psonice psonice
That should be pretty simple to fix - maybe you screwed up the sphere intersection test?
added on the 2011-06-10 17:52:56 by las las
Yeah, I think i understand where I went wrong now. The 'glitch' is caused by the different perspective between the front and rear halves of the sphere. Just taking the negative of the distance is not enough here, I'll have to rewrite it.
added on the 2011-06-11 00:05:25 by psonice psonice
you must have a bug, cause the sky is reflected wrong too: red left, green right, but the sphere shows the opposite. a sign bug, or the wrong order of params in the reflect() function, or something like that?

by the way, No Chrome Spheres Over Checkboards Permitted In This Thread, please! :D http://www.pouet.net/prod.php?which=32735
added on the 2011-06-11 19:29:34 by iq iq
you must have a bug, cause the sky is reflected wrong too: red left, green right, but the sphere shows the opposite. a sign bug, or the wrong order of params in the reflect() function, or something like that?

by the way, No Chrome Spheres Over Checkboards Permitted In This Thread, please! :D http://www.pouet.net/prod.php?which=32735
added on the 2011-06-11 19:29:35 by iq iq
huh? how did i do that?
added on the 2011-06-11 19:30:06 by iq iq
Ninja skills, that's how. Or coders stutter.

Actually I started with a nice (as in stolen) floor texture. But you know what? Checkerboard is the best for debugging reflections, and so is a sphere :) I noticed the reversed reflections too, my hack for inverted spheres is to blame again :( Well, it needed optimising anyway, with 2 nasty bugs I'll just rewrite it properly.
added on the 2011-06-12 00:29:46 by psonice psonice
I've looked at that reflections problem a bit more, and realised that using an inverted sphere for the 'sky' is utterly wrong. Or, at least, it's incredibly inefficient.

If you take the 'sky' as a sphere that's infinitely far away (which is actually ideal in most cases), the distance from any point in the scene to the sky is always infinity. Swap infinity for a large number, and your distance function is simply 'distance = largeNumber'. Can't get more optimised than that :)

Also, the normal (which is handy for texture coords and the like) is trivial. The centre of the sphere is always the current point, so it's simply 'normal = -rayDirection'.
added on the 2011-06-13 18:00:55 by psonice psonice
I'm currently writing down a list of names for the greetings & thanks slide for my vienna talk (almost random order):
Quote:
Raymarchers: iq, Decipher, Ferris, psonice, chock, unc, XT95, manx, smash, kusma, nystep, nytrik, a13X_B, PauloFalcao, Lord Graga, Tigrou, auld, Sdw, flure, Psycho, Mewler, toxie, knighty, gopher, Sleo, Pirx, msqrt, vibrator, cupe, rarefluid, Xetick, mudlord

Some are actually not really raymarchers but came up with some helpful hints :) (or listened hours to some ideas which I didn't mention here yet for certain reasons ;))

Did I forget YOU?! Mention it - NOW.
added on the 2011-06-15 00:19:28 by las las
Game of the day : someone in this list don't understand shit about code : find him :)

iq, Decipher, Ferris, psonice, chock, unc, XT95, manx, smash, kusma, nystep, nytrik, a13X_B, PauloFalcao, Lord Graga, Tigrou, auld, Sdw, flure, Psycho, Mewler, toxie, knighty, gopher, Sleo, Pirx, msqrt, vibrator, cupe, rarefluid, Xetick, mudlord
added on the 2011-06-15 13:26:18 by nytrik nytrik
Quite glad of ending in this list without having provided any signficant help :D
added on the 2011-06-15 13:45:47 by flure flure
nytrik, does that matter at all? ;)
I crawled through the whole thread and created that list, damn I forgot to mention texel, and already added some other guys too.

Some of those names will be bold - those who are know why ;)
added on the 2011-06-15 16:32:35 by las las
I will give it a try +ne day and follow rez exemple.
added on the 2011-06-15 19:24:57 by nytrik nytrik
Hello,

I'm trying to get into raymarching in webgl using iq's ShaderToy, but currently most of examples there aren't working at all... I've read those two remarkably helpful and inspiring threads here but I still can't get the work done.

I would really appreciate if someone could provide me with simpliest raymarcher with cube or whatever working in ShaderToy.
added on the 2011-06-17 14:46:30 by boased boased
I've not been posting much, but heres a little snippet of an upcoming demo to make up for it :) 3D Perlin Noise <3

BB Image

BB Image
added on the 2011-06-18 05:06:31 by Mewler Mewler
Make it move, dammit :D
added on the 2011-06-18 05:15:51 by moredhel moredhel
Mewler: awesome! can't wait for your demo :)

I wanted to post about GLSL shader disassembly otherwise.
It's actually possible to get assembly out of these.

On AMD/ATI there is: ASHLI - Advanced Shading Language Interface

And on nVidia, one has to use cg's compiler command line:

Quote:

cgc -oglsl -profile fp30unlimited something.frag
cgc -oglsl -profile vp30 something.vert


hope it helps.
added on the 2011-06-18 22:32:21 by nystep nystep
nystep: "opengl assembly" isn't really any more useful or closer to the metal than the glsl itself.
For AMD you can use the GPU Shader Analyzer to get actual gpu assembly, which is very useful, at least to check for proper vliw utilization.
added on the 2011-06-18 22:57:20 by Psycho Psycho
Mewler: NICE. I demand a torrent!
Is there any way to get in contact with you?
IRC? ICQ? Jabber?
added on the 2011-06-18 23:31:42 by las las
Yesterday, I manually unrolled a loop. Didn't change the contents at all, just unrolled it. It was much faster. Wtf! This is on ipad/iOS/SGX543, not desktop though (and it wasn't raymarching too).

I'm guessing that was just a strange compiler fail, but it did make me think. Anyone tried an unrolled raymarcher for speed? I guess it shouldn't be hard to code an unroller. And of course it *should* be no faster, but on the ipad I got >30fps compared to 18fps, and that's the kind of speedup we don't want to miss :)
added on the 2011-06-19 01:33:44 by psonice psonice
usually you profile every code you write. if youre not, feel to unroll and debug time every line you write.
added on the 2011-06-19 02:06:48 by Hatikvah Hatikvah
wait...why do you think "it *should* be no faster"?
added on the 2011-06-19 03:19:38 by shuffle2 shuffle2
psonice: im not sure i understand what you mean - did you assume it wouldnt be faster because the compiler would have unrolled for you already, or did you assume it wouldnt be faster because you didnt understand the implications of using flow control in shaders?
added on the 2011-06-19 10:53:06 by smash smash
I thought the compiler unrolled loops in simple cases? (This was an extremely simple loop, fixed iteration count (just 5 iterations too), no early bailout/conditionals etc.).

I do have a (very basic) understanding of the implications of flow control - I've just re-written this shader to remove conditionals + early bailout (it's a tweaked bilateral filter). This one for() loop was the only remaining flow control in any of the shaders for this app :)

More knowledge would be very good though - any suggestions for reading material? This is the beginners thread remember :D
added on the 2011-06-19 15:54:06 by psonice psonice

login

Go to top