I think it was just a bunch of ifs. It was something like the distance functions all return a vec2 (distance, material), and the scene function just compares on distance. Then when the ray hits a surface, it uses a separate scene function with all the if()s to find the object it hit, and then gets the material/does relevant lighting, colour etc. At least this way the nasty if() nest is only hit once per pixel.
There's probably a bunch of stuff on this in the 'raymarching toolbox' at pouet.net.
@psonice Thanks for the info , yup that's how I've done it now. I have a separate SceneColor(vec3 P) func for colours - which u can crazy colour fx with (ghosting, marble e.t..c). Shame u can't min/max a vec on only one of it's components - would be awesome then :)
Awesome stuff dood - how did you encode the colours? are u using a set of "if"s in your scene func or have you worked out a way to directly encode the colour into the distance? I tried this - finaldist=(dist*1024)-(frac(dist*1024))+Material; - But I think the GPU floats normalize badly :(
I think it was just a bunch of ifs. It was something like the distance functions all return a vec2 (distance, material), and the scene function just compares on distance. Then when the ray hits a surface, it uses a separate scene function with all the if()s to find the object it hit, and then gets the material/does relevant lighting, colour etc. At least this way the nasty if() nest is only hit once per pixel.
There's probably a bunch of stuff on this in the 'raymarching toolbox' at pouet.net.
psonice 1 month ago
@psonice Thanks for the info , yup that's how I've done it now. I have a separate SceneColor(vec3 P) func for colours - which u can crazy colour fx with (ghosting, marble e.t..c). Shame u can't min/max a vec on only one of it's components - would be awesome then :)
shabtronic 1 month ago
Awesome stuff dood - how did you encode the colours? are u using a set of "if"s in your scene func or have you worked out a way to directly encode the colour into the distance? I tried this - finaldist=(dist*1024)-(frac(dist*1024))+Material; - But I think the GPU floats normalize badly :(
shabtronic 1 month ago