Search Unity

[Resolved] Problem with Offest Depth.

Discussion in 'Shaders' started by Nova-Shade, Apr 2, 2017.

  1. Nova-Shade

    Nova-Shade

    Joined:
    Oct 15, 2015
    Posts:
    136
    Hi everyone !

    I'm coming in this forum section with hope of getting some enlighted comments concerning the Depth settings in a shader. :)

    Here is what I've done so far :

    - I have a planet and its atmosphere in two separate meshes, and want to render the planet in front of the atmosphere so only the border of it will be visible on the edges.

    - It's working well but I have a logical problem with this set up : If I have another object behind the original planet, the original atmosphere will render last and behind everything.

    Here is a picture to summarize :

    After reading the docs of Amplify Shader Editor, the problem is most likely to comes from the "Offest" settings in the Depth parameters. But after trying a lot of settings, here is the best result.

    Anyone already had a similar issue ? Thanks in advance for any help on the matter ! :oops:
     
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,352
    The offset setting for shaders is an odd beast, they're basically "magic numbers" where you just have to play with the values to get what you want, and their implementation is vendor / API / or even GPU specific, so there's no guarantee the same values will produce the same results between AMD, Nvidia, and Intel, or various mobile GPUs, or even if they'll be the same between DirectX and OpenGL on the same card.

    However they're generally intended for dealing with preventing zfighting or ensuring that thing draws on top of something else, but I've had less success using it to ensure the object using it draws behind something in a logical manner.

    There's also a much easier solution to this. Use Cull Front instead of the default Cull Back. You'll probably have to negate the dot product you're using for the edge fade though.

    edit: fix some odd typos
     
    Last edited: Apr 3, 2017
    Nova-Shade likes this.
  3. Nova-Shade

    Nova-Shade

    Joined:
    Oct 15, 2015
    Posts:
    136
    Aw you were right , I should have investigated more on the culling, it worked ! Thanks a lot man :oops: