Using a global shader for true Texture3D raymarching

Okay, so Unreal doesn’t support 3DTextures from the editor but you really want a raymarcher. What do you do?

Either you settle for pseudovolume textures by Ryan Brucks (which are amazing, by the way), or you start trying to rape the engine.
I obviously chose the second option and these are my results. In short, I use a global shader plugin to render a raymarched volume to a RenderTarget using my own shader pipeline, shaders and draw commands. After I have that, I slap the resulting texture over the whole viewport, so it looks like the volume is part of the actual scene (until there’s an object “in front” of it and it looks weird and makes you feel dizzy).

This is a work in progress and should be improved in the coming weeks, so if you like what you’re seeing, stay posted.

Also, this is pretty much just a “getting into the rendering magic of UE” for me, the end-goal is actual integration in a Material Shader (or actual 3D Texture support from within the editor, but that seems like a lot of work from where I’m standing). I’m posting this because I had to figure out way too many things on my own and if anybody is trying to do something similar in the future, this could save that guy/gal some frustration.

Check it out here:

Screenshots/videos coming tomorrow.

Thanks for sharing!

It’s this sort of thing, and lack of much info about using compute shaders with UE4, that have prevented me from seriously considering using UE4 as my primary engine so far. I love the work Ryan Brucks did with this stuff and a fluid sim, but performance is significantly worse than what I can achieve elsewhere by using a compute shader approach to the sim. This means I havent put very much effort into UE4 as a whole, but if at least the 3D texture & raymarching side of things had elegant support in UE4, I would be more likely to be prepared to learn how to do the compute shader side of things the hard way with UE4.

I havent looked at your stuff yet, but are you aware that UE4.20 has support for Volume Texture Assets? I’ve not tried it with any github or preview release of 4.20, but I understand this to be the same thing as 3DTextures, and it is right there on the roadmap for 4.20.

Holy cow, thanks! I kept looking for this as “3D Textures” and it didn’t occur to me to look for “Volume textures” (and yes, it is the very same thing). You just saved me a lot of unnecessary work. After downloading the 4.20.0-preview5, I can confirm that there is full support for them in the editor and material editor too.

Well, the code is still a good example of how to run your own shaders and I will probably reuse it for data preprocessing (gaussian smoothing a 3D texture on the GPU and other stuff).

Thanks a bunch!