Search Unity

Question 100% shadows after shadow distance.

Discussion in 'Shaders' started by ShaderRig, Jun 23, 2020.

  1. ShaderRig

    ShaderRig

    Joined:
    Feb 26, 2019
    Posts:
    18
    Looking for some advice on a shader issue. On a project, they are using this shader: https://alastaira.wordpress.com/201...-unity-vertexfragment-shader-in-7-easy-steps/

    Code (CSharp):
    1.  
    2. Shader "Custom/SolidColor" {
    3.        SubShader{
    4.  
    5.               Pass {
    6.               Tags { "LightMode" = "ForwardBase" }
    7.  
    8.  
    9.               CGPROGRAM
    10.               #pragma vertex vert
    11.               #pragma fragment frag
    12.  
    13.               #include "UnityCG.cginc"
    14.               #pragma multi_compile_fwdbase
    15.               #include "AutoLight.cginc"
    16.  
    17.               struct v2f
    18.               {
    19.                      float4 pos : SV_POSITION;
    20.                      LIGHTING_COORDS(0,1)
    21.               };
    22.  
    23.               v2f vert(appdata_base v) {
    24.  
    25.                      v2f o;
    26.                      o.pos = UnityObjectToClipPos(v.vertex);
    27.                      TRANSFER_VERTEX_TO_FRAGMENT(o);
    28.  
    29.                      return o;
    30.               }
    31.  
    32.  
    33.               fixed4 frag(v2f i) : COLOR {
    34.  
    35.                      float attenuation = LIGHT_ATTENUATION(i);
    36.                      return fixed4(1.0,1.0,1.0,1.0) * attenuation;
    37.               }
    38.               ENDCG
    39.        }
    40. }
    41. Fallback "VertexLit"
    42. }

    The issue being, after the ‘Shadow Distance’ value, it’s filling the plane with black. Being related to the shadow the line moves as I rotate the light.

    To make things more interesting, this works fine on IOS devices but shows up on Windows.

    Does anyone know what is causing this?
     

    Attached Files:

  2. Samuel_Herb

    Samuel_Herb

    Joined:
    Jun 23, 2020
    Posts:
    8
    hm- I'm not really sure. But maybe returning a non 1 alpha value is messing it up? Try
    return fixed4(attenuation, attenuation, attenuation, 1.0);
     
    ShaderRig likes this.
  3. ShaderRig

    ShaderRig

    Joined:
    Feb 26, 2019
    Posts:
    18
    Hi Samuel, thank you for the reply, unfortunately this had no effect on the issue.
     
  4. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,352
    I believe it's a bug when using no cascades on desktop. It might be fixed in a newer version of Unity, otherwise report it or use at least 2 cascades.
     
    ShaderRig likes this.
  5. 00christian00

    00christian00

    Joined:
    Jul 22, 2012
    Posts:
    1,035
    @ShaderRig Having the same problem, I thought it was my fault.