Search Unity

Light glitch when distorting vertices.

Discussion in 'Shaders' started by AlexTemina, Jun 23, 2016.

  1. AlexTemina

    AlexTemina

    Joined:
    Feb 19, 2014
    Posts:
    44
    Hi, I have a bush that moves with the wind like this:



    The problem is that when the bush gets iluminated the vertex distortion produces light glitches that I don't know how to solve.



    I tried putting all the normals of the sprite at 1 from surf method, Tried to separate vertices in Z so they don't overlap, but nothing helps getting rid of that line of light. Can anybody... enlighten me? pun intended.

    Thanks!
     
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,352
    My best guess is this is caused by overlapping polygons and the way additional lights are rendered by Unity.

    Regardless of how the main surface is rendered additional per pixel lights are rendered as additional additive passes. Opaque or alpha tested objects have ZWrite On which usually prevents overlaps in the geometry from getting double lit, but transparent objects usually do not ZWrite so the resulting additive passes are not prevented from this artifact.

    So I would ask if changing the shader to opaque or alpha tested makes this artifact go away or not, and if it does you may need to separate your vertices apart more or reduce the "wiggle" of the vertex animation.
     
  3. AlexTemina

    AlexTemina

    Joined:
    Feb 19, 2014
    Posts:
    44
    Thanks a lot for the help

    No, it doesn't change if I put the queue to AlphaTest, or the RenderType to Opaque or any other thing. Now I added this shader to other objects, and all the polygons that overlap have this problem. It doesn't matter if I move the Z. if I write ZWrite On it disappear, but much other artifacts appear.
     
  4. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,352
    When I say "Opaque" and "AlphaTest" I didn't mean changing the render type / queue. By opaque I meant disabling blend or if you're using a surface shader removing the "alpha" part. Similarly for alpha test I meant adding alphatest:_Cutoff to your surface line or adding a clip(alpha - _Cutoff) to the shader code.

    The fact the problem goes away when you enable zwrite means it is the issue I thought it was, and changing the shader to be alpha tested is likely your only solution beyond reducing the strength of the wind effect. If you can post your shader I can show you more specifically what to change.
     
  5. AlexTemina

    AlexTemina

    Joined:
    Feb 19, 2014
    Posts:
    44
    The problem is that now it happens in other places, and I don't have control on Z there... I will send you the code in private.