Search Unity

Why might modifying vertex x position in shader.... break z-sort ?

Discussion in 'Shaders' started by JonPQ, Jun 26, 2017.

  1. JonPQ

    JonPQ

    Joined:
    Aug 10, 2016
    Posts:
    120
    I made a surface shader for sprite , that bends the vertex X position, with vertex Y position as the modifying input.
    In the vertex shader, if I read appdata_full v.vertex, and write it straight back out... sprite renders same as normal.
    If I modify the x position... x+= someRandomConstant; then write it back out.... so whole sprite is offset in X.... it renders same as normal.
    If I calculate some offset..... such as... xAdd = pow (vertex.y + yOff); then add that into vertex.x.... suddenly the sprite starts z-fighting with other sprites and disappears.... but if I move the camera real close... it looks fine.


    any idea what I am doing wrong here ? maybe I shouldn't be using surface shader ?
    how can modifying X, break Z sort of a sprite ?

    Help appreciated.
    Thx in advance.