Search Unity

  1. The 2022.1 beta is now available for testing. To find out what's new, have a look at our 2022.1 beta blog post.
    Dismiss Notice

Help Wanted Is it possible to render a uniform opaque outline along mesh intersections?

Discussion in 'Shader Graph' started by Astrauk, Aug 17, 2020.

  1. Astrauk

    Astrauk

    Joined:
    Jan 14, 2010
    Posts:
    872
    Alright, I'm still working my way through learning Shader Graph, and I was working on figuring out how to draw an outline around the intersection of opaque meshes, I found numerous transparent depth-based effects, so I started working with that, but, rather than simply visually rendering the depth of the objects, I want to render more or less an outline along the intersection with a set width. I honestly have no idea if it's possible, but, I figured I'd throw it out there as a question because I've had a heck of a time trying to google it.

    The below image shows the current effect and its issue, as clearly it's just rendering an edge based on the depth of the meshes, I want to essentially just take the actual intersection point and create a uniform outline around it.

    Intersect Tex1.JPG

    And the nodes
    Intersect Tex3.JPG
     
  2. Oxeren

    Oxeren

    Joined:
    Aug 14, 2013
    Posts:
    113
    If you want both objects to be opaque, this is not really possible in shader, since there is no access to the depth texture at this stage. And depth-based effects with one opaque and one transparent object will look more or less like in your screenshot. I don't have any reasonably simple solutions in mind, the only two ways I can think of without delving too deep are: 1) Generate actual intersection geometry. This is not trivial, but maybe there are ready solutions for it out there. This is done on the CPU, not in the shader 2) You can render it as a post effect, to get a result similar to those orange selection outlines in the scene view. This cannot be done in shader graph alone and will require a custom renderer feature.
     
  3. Astrauk

    Astrauk

    Joined:
    Jan 14, 2010
    Posts:
    872
    Alright, yea, that's more or less what I thought, perhaps I'll take a gander at generating geometry. Thanks for insight!
     
  4. MaxYari

    MaxYari

    Joined:
    Feb 20, 2018
    Posts:
    10
    Alright, this is somewhat old but it's a first google result, so I'll describe a solution that I put together and that wasn't mentioned here. This might or might not work depending on your requirements, but I think it's still worth leaving here an overall idea.

    So essentially I needed a way to determine the intersection of an object with terrain to draw material on the bottom of the object that will "blend" it into terrain. So in that, or a similar case - what you can do is create a top-down orthographic camera that will render a depth map of terrain into a render texture.
    Then you can pass this depth map and camera's near, far plane and position into the object's shader. There, using Position - World node and all the camera data you can figure out where on the terrain map this object's pixel is located, use that to sample height from a map, transform height into world position using camera data and then use it to figure height of the object's pixel above the ground.

    Most likely will not work or will need some rethinking if you want "everything" to intersect with "everything" and not just some objects that intersect only with a specific layer of objects.

    I will assume that the performance impact of this approach is negligible, but might not be the case on some weak mobile devices maybe... but then if you don't need this to be active on dynamic objects - you don't even need this camera to run in realtime.

    Thing in action:
    upload_2021-4-28_23-47-36.png
     
  5. Yatis

    Yatis

    Joined:
    Sep 22, 2018
    Posts:
    8
    @Astrauk hey mate I'm doing something similar to yours had you found any alternative that works?
     
unityunity