Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Shader - smooth the intersection of two objects

Discussion in 'Shaders' started by immeasurability, Oct 16, 2018.

  1. immeasurability

    immeasurability

    Joined:
    Apr 22, 2014
    Posts:
    125
    hi! I need help finding a shader that smoothes the intersection of two different objects

    what to look for?
    or ready asset?

    Без имени-1.png
     
  2. MuckSponge

    MuckSponge

    Joined:
    Jul 11, 2015
    Posts:
    41
    A colleague of mine accomplished this by blurring the normals texture via a command buffer. I guess you'd need to use deferred rendering path and add a command buffer to the main camera, which blits with a deferred shader applying a Gaussian blur to the normals texture only, and this should be injected before lighting is applied so that your modified normals take effect.

    See here for more information. Blurry refractions shader is a good one to look at, you just need to inject it sooner and blur the normals texture instead of final colour.
     
  3. bluescrn

    bluescrn

    Joined:
    Feb 25, 2013
    Posts:
    628
    Another option may be to use the depth texture and the same approach as soft particles (and render the sphere with transparency calculated from (pixel Z - depth texture Z)*scale )

    (Wouldn't work well if you've got lots of intersecting objects, only if you've got a small number of objects like that example sphere intersecting an opaque environment)
     
  4. Fledered

    Fledered

    Joined:
    Jun 15, 2017
    Posts:
    10
    Hi! I'm trying to achieve the same effect. I have a character whose legs are two separated parts (the thigh and the bottom of the leg) which is the solution that fits the best the artstyle I'm aiming for.

    But how can I get rid of these seams?

    (Here is what I have VS what I'd like)

    IntersectionSharp.png

    IntersectionSmooth.png

    I already managed to get the normals on a render texture and apply it back on the 3D objects, so all I have to do is alter the texture in shader graph.
    But there is no blur node and I'm afraid it would not give proper results.

    2021-03-27 18_46_38-Main.png

    What would be the best approach ?