Highlight (Intersection) Shader

Hello,

Is it possible in current Shader Graph state to create a shader, that would highlight intersecting geometry?
To elaborate: the shader would go on a sphere, and would highlight any surface it touches.

It can use either the mesh of the sphere itself, or a SphereMask.
I’ve tried everything, but can’t seem to get anywhere close.

This could be similar to the effect you’re after, just without the added noise texture https://www.patreon.com/posts/26438849

There’s also this video on making an Intersection Material using Shader Graph https://www.youtube.com/watch?v=ayd8L6ZyCvw

@nikefootbag Thank you for replying!
Sadly both of the solutions are a bit different still. First one uses the position of the sphere inside the shader, which means, I must have all shaders in my scene have that logic, which is not ideal.
What I’m looking is sort of an omnidirectional decal. The object that projects color/image to any surface, not just the ones with built-in logic.

@romanpapush ah I see, goodluck in finding a solution!
I just realised I follow you on youtube and twitter, your tutorials are great (and also real funny), keep it up!

Thank you for saying that @nikefootbag :slight_smile:
Yeah, I guess will be using the alternative methods for now. Cheers!

@romanpapush I am trying the same as you, could you please share what alternative methods you used?
Many thanks!

Hello! Which SRP are you using? Also, would it always be on a sphere or other simple mesh?
So long as you have access to scene depth (deffered or forward rendering with the flag checked for depth buffer) and are doing simple shapes I can think of a few ways to achieve this.

As long as you have access to scene depth, and the shader is set to be transparent, this should work:


Will match the scale of the sphere too, as long as it’s not scaled non-uniformly. It will only work on spheres, however.

I find an inner radius of 0.493 and an outer radius of 0.495 looks the best.

Thanks for posting this, works great in editor but doesn’t work in VR (single pass rendering mode) Is there any way to make it work with VR

If there was a way to make this work with a box collider, non uniformly scaled, you’d be a hero.

This is amazing! I’ve been looking everywhere for something like this! Thank you so much.

Would it be possible to have this work with any mesh instead of only a sphere?

Unfortunately that would not be as simple to implement, as the reason the shader works is it’s checking the distance in the depth buffer from the center of the sphere in order to know where to draw.

Kind of on a similar vein, how would one go about making something like this in Shader Graph? I’ve been struggling with it. It’s essentially a decal shader for URP, would be nice to be able to hook something up like this for shader graph so you can tweak and do scrolling effects and such.

@LandonTownsend Thank you so much for your answer, this is exactly what I was looking and it is working wonderfully!
But I can’t seem to make it work with transparent objects as well. I’ve tried writing them to the depth buffer through Renderer Features, but with no luck. Can it be achieved with the current setup?

Once again, a million thanks for the shader graph solution you posted above

I had the same problem with transparent objects not being applied.
Do you know how to solve that problem?

Hi! I’ve actually resorted to rendering another material with a spherical mask on top of my objects using URP’s Renderer Features material override. Did the trick for my case. Cheers!

Thanks for replying to you and found this.
https://docs.unity3d.com/Packages/com.unity.render-pipelines.universal@11.0/manual/renderer-features/how-to-custom-effect-render-objects.html

it work

7640695--951895--upload_2021-11-9_13-14-44.png

Just use the shader above and the method you described.

But the problem with this is that whenever the camera position changes, the overlap of the stationary red sphere is not constant.
In my opinion, this method prioritizes the rendering order (zbuffer) of objects with a specific layer in the camera.
I don’t think this has anything to do with the surface changing whenever the camera position changes, isn’t it?

Hi!

Have you checked your “Depth > Write depth” checkbox settings on your sphere vs the rest of the objects in your Render Objects Renderer Feature?
And if you’re using newer versions of Shader Graph there’s a Depth Test setting in Graph Settings you might want to check also for your shaders.

I don’t know how your scene is set up, but to a lesser extent double check if you’re excluding layers from Filtering setting (in Universal Render Data) which you are manually rendering with Render Objects feature. Also changing the event to, say, “AfterRenderingSkyBox”, might solve the issue if your objects are using transparent materials and being rendered after the highlight object.

thankyou

7657171--955372--upload_2021-11-15_17-4-7.png

The color is faded, but it seems to have deviated from the wrong application. Thank you…

6741043--776845--upload_2021-1-19_19-3-0.png

Does anyone know how to get this to work with an orthographic camera?