Download

Rendering Signed Distance Field primitives

Hi all,

I’m new to the forums and this is my first post!

I’ve been working with SDF’s and SDF primitives (think shadertoy) recently and figured I would try and use them for a university project I’m working on. My question is, has anyone done anything like this before? If yes, I’d love to hear how you approached it? So far I’ve been unable to find almost anything related to this as most of the SDF usage revolves around shadows and AO.

I did quickly prototype this by creating a custom pixel shader following the custom shader creation ideas discussed in https://forums.unrealengine.com/showthread.php?58489-Tutorial-Pixel-and-Compute-Shaders-in-UE4. As for the pixel shader it is pretty standard when it comes to raymarching SDF primitives. The output is written to a render target and for now I’m using the alpha channel to store the depth of the trace for culling later. As for displaying the result in the scene I created a post process material where I compare the depth value to the Scene Depth.

sdf_post_process_material.png

At the moment the solution still has many problems and it doesn’t take into account any of the lights in the scene nor does it generate any shadows whatsoever. Also for now there are no interaction between the object and the rest of the scene but I’m planning on approximating the shape with simple collision shapes as the size of the object is not random but can be estimated. One problem I noticed as well with this prototype is that there’s something wrong with the depth estimation when rendering the post process material as you can see a thick outline of the object when looking against the sky as seen below

sdf_black_outline.png

All in all there’s still a lot to do but would love to hear your opinions and suggestions.

A small video of the prototype:

[video]https://drive.google.com/file/d/0B__it93ohjaNTzBMdFZnTnVVQkU/view?usp=sharing[/video]

I added walls to the scene to “rid” the scene of the black outlines

The rendered SDF scene is a slightly modified version of https://www.shadertoy.com/view/MtSGRt so all glory of that to the creator.

Sorry for the short post, I wanted to write something up quickly before heading from the University. I’d be happy to answer any questions that you might have and will try and keep this post updated as I make progress. Also forgive me if my terminology is off somewhere, feel free to correct the mistakes :slight_smile:

Hi - this is fantastic! I am experimenting with rendering SDF primitives in UE4 myself… I’d almost given up finding anyone else doing the same.

Have you taken this prototype any further? I would be keen to hear what you’ve learnt.

Rendering fractals

Hey guys I too have been experimenting with rendering using raymarching and SDFs and have some results to share:

https://youtube.com/watch?v=9u403BbaAv0

Till now been using Volumetric decals but they are prohibitively expensive. Trying to figure out how to raymarch using a normal Surface domain material as I saw in this post:

https://forums.unrealengine.com/showthread.php?97053-Writing-shaders-for-UE4-where-do-I-start&p=453269&viewfull=1#post453269

It’s not working right now but knowing that it’s possible is half the battle IMO. Will update if it changes. If you guys want more on the Volumetric decals look here:

https://forums.unrealengine.com/showthread.php?97053-Writing-shaders-for-UE4-where-do-I-start&p=453269&viewfull=1#post453269