UE4 - Highlighting the cross section of intersecting geometry

I want to make a material that, when applied to a model, will only render a flat-color cross section of the model as it intersects with other geometry.

Ico has a similar effect to what I’m looking for, with the wave of black advancing outward in a circle.

Would this be possible in UE4?

1 Like

Use Custom Depth Flag. And compare depths in your material to original depth and render what U want :wink:

Can you be more specific on how to do this? I’m still a novice when it comes to creating shaders.

I linked it :slight_smile: there are so examples there

After a while. If U r only interested in intersection and not hidden areas U can use just depthfade node and then invert it. U will get nice gradient along collisions.

I looked through the tutorials and they don’t really get into any depth as far as the implementation goes, which is what I’m still trying to learn.

I suppose a way I could accomplish it would be to do two render passes, one where the object renders normally, and one where the object renders only when occluded. Then take the two render passes and cull everything other than where they intersect. Though like I said, I’m not familiar enough with shader creation to know what I’d need to be able to do this.

hey bud, no need to set up multiple render passes for this.
Depending on your primitives - ie if it’s just a sphere or box you need - it’s fairly simple to do in a shader.

I can’t upload a txt doc with the shader network but it’s this:

Make sure you only transform if its absolutely necessary as it can add expense. if you are just using a sphere you are fine to not transform.

I would think that most primitives here would translate pretty well with this, keeping in mind you’re only going to be drawing on world positions,
http://mercury.sexy/hg_sdf/

Where P in those functions is, in the image, SphereMask(A). I’m only using the sphere mask as a convenience function to tweak distance fields.

5 Likes

Whoa it works! Awesome! I wish I better understood how it works, but this is plenty for me to work with.

The only error I’m noticing is if you’re inside the object, the results switch from rendering inside the object to outside of it. Any way to fix that or do I just have to deal with it?

Enable two sided rendering & disable depth test.

heads up, I’ve done a few of these types of shaders before, there’s always a lot of edge cases to patch up for production.

1 Like

Excellent! Thanks for the help!

Hi everyone, I know this thread is kind of old, but I was wondering if you could help with a problem I had. I am trying to highlight the itersection between 3D solids and a plane, like the image here.
Does anyone know if some sort of depthfade code could make this work? Very new to UE4.

1 Like

Inverse depth fade and you will get same result

please elaborate, I am not sure how I would implement this

There’s a node in Unreal’s material editor called “Depth Fade”. cghow is suggesting you use this and then run the result of that through a 1-x node, which will give you the opposite of it’s default functionality

image


Thanks so much, we got depthfade running with fresnels involved and it turned out like this. Now our difficulty is how to implement this on a transparent material? Is this possible.

We are attempting to use the Allow Custom Depth Writes setting but it is still not working when we make the solids transparent.

this is what i was talking about. and the edge thickness on ground you can adjust with fade distance in depth fade node.

1 Like

Hi! Thank you so much for all your help btw im the other partner working on this project. What we are trying to do is have the shape and the plane be transparent and have the intersection of the two show in an opaque color (essentially just like the “cross section” earlier in the thread). We have pretty much that exact blueprint in our plane except with another lerp modifying the transparency of the plane. We’re having trouble making the intersecting object transparent except for the plane of intersection.