Search Unity

Combining alphatest and finalcolor generates shader error

Discussion in 'Shaders' started by ToddScott, Jul 23, 2014.

  1. ToddScott

    ToddScott

    Joined:
    Dec 17, 2013
    Posts:
    1
    I am trying to modify the Transparent/Cutout/ Bumped Specular shader to not write the alpha value to the backbuffer in a deferred rendering environment.

    If I try to set the alpha value to zero using a finalcolor function I get the following shader error:

    Shader error in 'UNITY/Transparent/Cutout/Bumped Specular/Default Bloom': D3D shader assembly failed with: (10): error X5204: Read of uninitialized components(*) in r0: *r/x/0 *g/y/1 b/z/2 a/w/3

    I can modify the rgb components of the color individually without causing the error.

    I was going to use the alpha blend mode to not write out the alpha value to the frame buffer, but since alpha is used to store specular power during the lighting pre-pass and we don't have separate blend modes for the different passes, this won't work.

    UPDATE
    I commented out the line where I was modifying the alpha value in my finalcolor function and added #pragma debug to see the generated shader. I then took the generated shader and commented the alpha value line back in....and using this modified generated shader works.

    I am guessing that maybe there are some optimizations going on if I remove #pragma debug that are causing this problem?

    Any ideas?

    Best Regard,
    Todd
     
    Last edited: Jul 24, 2014
  2. jvo3dc

    jvo3dc

    Joined:
    Oct 11, 2013
    Posts:
    1,520
    Idea 1: If you don't want to write the alpha, just don't write it.

    In the pass:
    Code (csharp):
    1.  
    2. ColorMask RGB
    3.  
    Idea 2: Write the alpha, but don't change the actual value using blending with separate alpha blending.

    Again in the pass:
    Code (csharp):
    1.  
    2. Blend SrcAlpha OneMinusSrcAlpha, Zero One
    3.