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

How to create a shader with border detect

Discussion in 'Shaders' started by kaicho, Nov 13, 2015.

  1. kaicho

    kaicho

    Joined:
    May 14, 2015
    Posts:
    4
    Hi all.
    I'am trying to reproduce this lava effect of Donkey Kong Tropical Freeze, needing the shader to detect my meshes and glow on those parts just because my platforms will grown from and sink in the lava. Any clue what i should start looking for?



    I've seen it before with water shores, but in this case I was expecting to get a more solid feeling, so the characters could get in contact with it's surface and not symply dive into a gas mass.
     
    Last edited: Nov 13, 2015
  2. rchmiel

    rchmiel

    Joined:
    Apr 5, 2015
    Posts:
    49
    If this is not done like unity terrain?! The walkable blocks doesn't move so you can use alpha channel.
     
  3. jvo3dc

    jvo3dc

    Joined:
    Oct 11, 2013
    Posts:
    1,520
    You can't just do that with one shader. There is no direct way to "detect" other geometry.

    You'll have to do a prepass in which you mark your platforms in for example a top view render and then look it up in the lava shader.
     
  4. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    6,450
    The lava shader has to read the depth value (_CameraDepthTexture) at the lava pixel position that is about to be drawn. Use it to calculate the distance between the already drawn pixel in the depth buffer and the lava pixel. The result can be used to create various (blending) effects depending on the distance between the two.

    Pretty much just just like soft-particles work, but rather than modifying the alpha value, use it to change color or whatever you see fit.

    Download the Unity built-in shader package and take a look at the "Particle Blend.shader" file to see how the soft-particles technique is implemented.
     
  5. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Seems like you want the classic way water does it in all well known titles: there's no requirement for depth buffer or hacks or tricks or complexity, merely just a mask texture. and a "foam" texture.

    In DK, I suspect they went even simpler: it is not a mask texture, but instead vertex colours on the underlying mesh and / or just billboard sprites at the bases / texture.

    It's one of those things that's really quite simple and mobile friendly tbh in this case.



    After 2 min mark.
     
  6. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    6,450
    How would this work with platforms that change position, like he wrote for platforms that sink into lava.

    Edit: Using a mask texture also requires to update this texture whenever someone changes the level, eg moves platforms around. I would try avoid such dependencies unless there is a good reason for it (like rendering and reading depth is too costly).
     
  7. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Watch the video and read the rest of my post.
     
  8. kaicho

    kaicho

    Joined:
    May 14, 2015
    Posts:
    4
    Thanks, I'll dive into it as soon as I can, if i make any progress I'll let you know.