General purpose ray-marcher

hi all! i’m kinda developing a standard, general purpose ray marching shader “engine” and a simple “library” all in .fx files. i’m making progress, there are already some useful stuffs in it.
but i’d like to have it as a kinda “community built” stuff. i mean if anybody has the affinity to improve it please do so because now it doesn’t have any kind of optimization and produces some ugly artifacts which i couldn’t overcome. also it doesn’t have more advanced primitives and modifiers (like BVH and stuff), only the sphere has texture mapping and i haven’t tried any texture based data input yet (there are some placeholders though)
so the stuff itself:
http://dl.dropbox.com/u/1218206/RayMarcher%20help-DirectX%20Renderer_2012.05.11-05.24.33.png

geometries/primitives: (geometries.fx)

every geometry have to be expressed in distance and could be transformed by altering the current ray position before calculating the geometry itself. i’m planning to use a structure called “geometrydata” as output for geometry functions which contains a float “distance” and a float2 “texture” coordinate. currently only the sphere uses this structure.
i need help in calculating the texture coordinates for the other primitives too (i’m not a math expert)
and i need a lot of help in calculating distance of an arbitrary mesh stored in textures (separate textures for vertices and for indices i thought of a flexible data format too).

modifiers: (modifiers.fx)

they alter the ray position so a geometry will be “tricked” and will be rendered somewhere else as it’s supposed to by default. they return a float3 altered ray position. i need help in bending and in finding out how to do fish-eye

operators: (modifiers.fx)

mainly for boolean modelling. which operation wouldn’t involve material blending that returns a structure called “opdata” which has 2 parts a float “distance” and an int “material”

materials: (materials.fx)

scene management happens in shaders i copied Kian Bashiri’s method (materials have separate int ID’s and distanceField.fx manages them). materials.fx is only a list of used materials and their basic properties (like colors as it’s now, but i’m planning to put there textures and light reaction properties too) also i would define ray direction modifiers here too (like reflection and refraction) since i couldn’t do any of them i just wrote the function prototypes there.

shaders: (shaders.fx)

they return the structure “shaderdata” which has float “lightness” for altering main color and int “operations” for debugging. the current shadows are ugly i’d need some help with that too.

currently i only implemented sun light but creating a point light is quite straightforward i was just lazy. i don’t know how to do spotlight though

the main shader (RayMarcher.fx) output 4 rendertargets (color, position, normal, debug). it compiles for a loooong time so don’t be confused vvvv isn’t freezed permanently, and it’s very gpu-heavy so watch your temperature too.

also i’m curious if something like this could be done in vvvv: http://www.iquilezles.org/www/articles/raypolys/raypolys.htm

references:
http://www.mazapan.se/news/2010/07/15/gpu-ray-marching-with-distance-fields/
http://www.iquilezles.org/www/index.htm

that’s all. if somebody has some opinion idea please share it!

there you can see it in action (10.9 kB)

cool was on the way to build my own ;]
hmm seems bit crashy ;] ah ya, crash appears after i click in to renderer
open shader results crash also… I heard dx11 thous things much less complicated

great work! heats up my powerbook immediately. helppatch runs at 6 fps and crashes when i hit into the renderer.

big up!

dd

Great Mr Microdee !

I don’t have any particular bug, just slow fps but it’s fine as my graphic cards is not the best we can find.

I can notice some strange shadow around the shape in the center. Nothing else.

impressive work.

@lecloneur: yep those are the ugly artifacts I was talking about.
well I have gtx 560 the raymarcher runs 45 fps on it. I only experienced a crash once but it looks like it’s quite big for vvvv or dx9.

Thanks a lot for sharing this!
it works at ± 50fps with an ati radeon HD 6900

Hi I found I takes a lot of ram to load (vvvv = 1.200.000 KB ca as Mr TaskManager states) to go back to normal values once loaded (77.000 KB ca).
Also I found that setting Windowed AA, in the first Renderer, other than NONE outputs something like this

No problem instead with full screen.

GF 9600 GT, here.

Anyways it’s great!

ok there is a serious trouble i can confirm that insane ram consumption and now i cannot open RayMarcher.fx. as soon as it compiles vvvv consums 1200 MB of ram renders the first frame and it crashes. what could be the problem (apart from the size of the shader)?

superb! a lot to learn

cool it crashes because of the shadows. as soon as i remove it from the main pixelshader it works. i’ll try to implement a method with a static number of iterations i don’t know how yet. also i got an idea how to display arbitrary shapes using 6 textures but i need a method for generating texture coordinates for the box. does anybody know how to do that?

@h99: i can confirm that, i don’t know what could cause that, don’t use native AA :D

Oh. I should also understand this, then. If you would be so kind to give me a hint to have a look to, though…
Is it something that can be done through settings panel of the card? Or you use… what?

Oh! I’ll be forever noob :(

oh i meant native AA what you find in the inspector but there’s the FXAA texture filter instead that does the job

very bad news: no texture input is possible currently. for tex2D inside the marching loop the compiler says: “Can’t use gradient instructions in loops with break. forcing loop to unroll” at line which contains tex2D, “Forced to unroll loop, but unrolling failed” at line which contains the main marching loop
is this solvable with dx10 or dx11 or there are still no “gradient instructions in loops with break”?

Hi all,

first, I’d like to thank you Microdee for this initiative. You created a good way to learn and play with raymarching.

Because the shadow is GPU consuming I finally don’t use it and it’s not that bad. AO is also very heavy so I’m just playing with the modifier at the moment.

It seems that when you substract a geometry by an other, the inside is grey, no color but it receive light anyway. Do you know how to get the same material, or even a different one inside the final geometry.

Here is a screenshot of what I’m talking about.

well you have to define a separate material for one of the inputs of subtract and in theory it would do what you’ve just described. i don’t know however what’s this grey-ish part on the bottom and what could cause it.

Hi Micro-D

got it for the material, and the dark part here is just because the cube is half way under the floor (which is turned off but…).

This raymarching works really good for experimenting with endless shape and boolean operation. No texture, buggy shadow and heavy AO but still very interesting.

With a kind of GPU patch I think realtime 3D can goes to a new world of experimentation.

I will post my experiment here later.

Cheers.

What’s the status on this one, any new developments (maybe with DX11)?

i’ve done a dx11 port but it still looks shit, still slow and still impractical. also vux gave me a patch which fits the raymarched world to the rasterized world by the same view and projection transform. if i will have time i will look on marching cubes that would eliminate the banding artifacts but currently i’m developing the next md.bot from sketch (almost ready) and the mre port for dx11 (that is not so ready but it’s already nice)