I recently started messing around with shaders in Unity and thought I’d try creating a raymarch volume shader. I found some success, but I’ve run into a rather ugly problem that I’m not really sure how to approach. As in the title, I am getting this banding in the render:
Increasing the step count helps to a point, this was done at 256 steps, and it becomes such a drain on performance that I would like to decrease the steps rather than increase them.
I would appreciate any insight into this issue. I would like to also understand any solutions as much as possible, so diagrams would also be greatly appreciated. Thanks!
Could you upload this broken shader or send me code in private message ? I will try to fix it.
Have you used domain deformations in this shader ? Sometimes operations like bending / twisting can cause artifacts.
Also you can visit my Git repository, where you can find some raymarch shaders for Unity3D…
In a way, yes it is a precision problem. The step size can be changed and that can help reduce the effect, but it never quite goes away. I suppose one path may be that a dynamic system is needed to balance this out in real time, but it would be messy and kind of complicated.
I’ve also found an academic paper in which this is avoided via a random depth offset. The problem is getting a random number, and it creates a static like effect which isn’t very desirable.
Jittering the ray depth can help a lot but it does created a “static” pattern. You should blur the volume then do a bilateral upsample to keep the sharp edges.
Another option is using old school interleaved sampling. Basically render the volume 4 times at a (slices/4) count with a different initial ray offset.
Then in your final composite pass use an interleaved pattern (dither pattern) to sample from those 4 previous samples.
This will give you a better quality than if you had rendered all those passes together. It will give you a dither pattern but in either case you should do a blur pass.