Search Unity

  1. Looking for a job or to hire someone for a project? Check out the re-opened job forums.
    Dismiss Notice
  2. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Help Wanted Highlight (Intersection) Shader

Discussion in 'Shader Graph' started by romanpapush, Aug 20, 2019.

  1. romanpapush

    romanpapush

    Joined:
    Sep 20, 2012
    Posts:
    37
    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.
     
  2. nikefootbag

    nikefootbag

    Joined:
    Jun 13, 2017
    Posts:
    17
  3. romanpapush

    romanpapush

    Joined:
    Sep 20, 2012
    Posts:
    37
    @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.
     
  4. nikefootbag

    nikefootbag

    Joined:
    Jun 13, 2017
    Posts:
    17
    @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!
     
  5. romanpapush

    romanpapush

    Joined:
    Sep 20, 2012
    Posts:
    37
    Thank you for saying that @nikefootbag :)
    Yeah, I guess will be using the alternative methods for now. Cheers!
     
  6. planetmatrix

    planetmatrix

    Joined:
    Dec 8, 2015
    Posts:
    37
    @romanpapush I am trying the same as you, could you please share what alternative methods you used?
    Many thanks!
     
  7. Elizabeth_LeGros

    Elizabeth_LeGros

    Unity Technologies

    Joined:
    Jan 7, 2020
    Posts:
    50
    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.
     
  8. LandonTownsend

    LandonTownsend

    Unity Technologies

    Joined:
    Aug 21, 2019
    Posts:
    32
    As long as you have access to scene depth, and the shader is set to be transparent, this should work:
    upload_2020-1-9_14-46-23.png upload_2020-1-9_14-47-10.png
    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.
     
    Last edited: Jan 9, 2020
  9. adrian-taylor09

    adrian-taylor09

    Joined:
    Dec 22, 2016
    Posts:
    40
    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
     
  10. alanmthomas

    alanmthomas

    Joined:
    Sep 7, 2015
    Posts:
    197
    If there was a way to make this work with a box collider, non uniformly scaled, you'd be a hero.
     
    JamesArndt likes this.
  11. JukeBoxDelta

    JukeBoxDelta

    Joined:
    Mar 21, 2019
    Posts:
    3
    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?
     
  12. LandonTownsend

    LandonTownsend

    Unity Technologies

    Joined:
    Aug 21, 2019
    Posts:
    32
    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.
     
  13. Madix

    Madix

    Joined:
    Nov 22, 2013
    Posts:
    15
    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.

    https://github.com/ColinLeung-NiloCat/UnityURPUnlitScreenSpaceDecalShader
     
  14. romanpapush

    romanpapush

    Joined:
    Sep 20, 2012
    Posts:
    37
    @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
     
unityunity