Search Unity

Shader compiler error on build

Discussion in 'Shaders' started by mholub, May 14, 2015.

  1. mholub

    mholub

    Joined:
    Oct 3, 2012
    Posts:
    123
    So I have a shader which outputs to single-float texture.

    Code (csharp):
    1.  
    2. //Fragment Shader
    3. float frag (v2f i) : SV_Target0 { // look output type here is float not float4
    4.     float2 uv = i.scrPos.xy / i.scrPos.z;
    5.  
    6.     float sceneDepth = tex2D(DepthTexture, uv);
    7.     float4 mask = tex2D(MaskTexture, uv);
    8.  
    9.     float lDepth = i.scrPos.z;
    10.  
    11.     return (lDepth - sceneDepth) * mask.r;
    12. }
    13.  
    It works fine. When I build my project, it works fine in the build too but I get this error.
    Code (csharp):
    1.  
    2. Shader error in 'Depth/DepthDifference': SV_Target0 must be a four-component vector at line 44 (on d3d11_9x)
    3.  
    4. Compiling Fragment program
    5.  
    Is it a bug in the compiler or my fault?

    https://msdn.microsoft.com/en-us/li...tion_from_direct3d_9_to_direct3d_10_and_later states I can use simple float with SV_Target<N> semantic. And it works, so I think the error message should be fixed.
     
  2. mholub

    mholub

    Joined:
    Oct 3, 2012
    Posts:
    123
    I realized SV_Target0 is dx11 semantic and fragment shader output can be plain float only for dx11.

    So
    Code (csharp):
    1.  
    2. #pragma only_renderers d3d11
    3.  
    solved the problem. So it's not a bug