Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Voting for the Unity Awards are OPEN! We’re looking to celebrate creators across games, industry, film, and many more categories. Cast your vote now for all categories
    Dismiss Notice
  3. Dismiss Notice

Shadows

Discussion in 'Shaders' started by unity_qVcVUUYUTy628A, Mar 29, 2018.

  1. unity_qVcVUUYUTy628A

    unity_qVcVUUYUTy628A

    Joined:
    Feb 20, 2018
    Posts:
    33
    Hi,
    I'm trying to force my shader to cast shadows, but he is very stubborn :D
    Please let me know what I do wrong.
    In frag I multiply finalColor *= tex2D(_ShadowMapTexture, i.shadow).a;
    and this is my shadow caster pass :
    Code (CSharp):
    1. Pass{
    2.             Name "ShadowCaster"
    3.             Tags {"Queue" = "Opaque" "LightMode" = "ShadowCaster"}
    4.             ZWrite On
    5.             Cull Off
    6.  
    7.             CGPROGRAM
    8.             #pragma vertex vert
    9.             #pragma fragment frag
    10.  
    11.             struct input {
    12.                 float4 pos : POSITION;
    13.             };
    14.  
    15.             struct output {
    16.                 float4 pos : SV_POSITION;
    17.             };
    18.  
    19.             output vert(input v) {
    20.                 output o;
    21.                 o.pos = UnityObjectToClipPos(v.pos);
    22.                 return o;
    23.             }
    24.  
    25.             float4 frag(output i) : SV_Target{
    26.                 return 0;
    27.             }
    28.  
    29.             ENDCG
    30.         }
     
  2. Kumo-Kairo

    Kumo-Kairo

    Joined:
    Sep 2, 2013
    Posts:
    343
  3. MadeFromPolygons

    MadeFromPolygons

    Joined:
    Oct 5, 2013
    Posts:
    3,874
    EDIT: thought this was a bot as other bots have similar names, but their posting actually seems potentially real :/ confusing!
     
  4. unity_qVcVUUYUTy628A

    unity_qVcVUUYUTy628A

    Joined:
    Feb 20, 2018
    Posts:
    33
    In the article I see some functions probably from UnityCG.cginc, but I want to understand it deeply and do it more manually. I want to use global sampler2D variable for shadows or something like this.
     
  5. Kumo-Kairo

    Kumo-Kairo

    Joined:
    Sep 2, 2013
    Posts:
    343
    If you want to understand it more deeply, just go check out the contents of UnityCG.cginc and see what those macros unroll to. UnityCG can be downloaded from Unity download archive -> built-in shaders. https://unity3d.com/get-unity/download/archive

    You can also always check the final GLSL or HLSL shader if you're comfortable with that.
     
  6. unity_qVcVUUYUTy628A

    unity_qVcVUUYUTy628A

    Joined:
    Feb 20, 2018
    Posts:
    33
    Could you explain me what unity_WorldToShadow[] array contains? I googled it but with poor result :(
     
  7. Kumo-Kairo

    Kumo-Kairo

    Joined:
    Sep 2, 2013
    Posts:
    343
    Most likely it's the transform matrix to that's used to convert world space coordinates to a "shadow space" coordinates. Much like you would do when rendering from a light's point of view. But it should be of different position than the light itself so it covers the whole screen of objects.