Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Two-sided shader - shadow problem

Discussion in 'Shaders' started by Killstar, Feb 11, 2012.

  1. Killstar

    Killstar

    Joined:
    May 11, 2011
    Posts:
    94
    Hi
    Anyone knows how to fix shadow sorting? I changed shader AlphaTest-BumpSpec by adding "Cull Off"



    Code (csharp):
    1. Shader "2-sided Bumped Specular" {
    2. Properties {
    3.     _Color ("Main Color", Color) = (1,1,1,1)
    4.     _SpecColor ("Specular Color", Color) = (0.5, 0.5, 0.5, 0)
    5.     _Shininess ("Shininess", Range (0.01, 10)) = 0.078125
    6.     _MainTex ("Base (RGB) TransGloss (A)", 2D) = "white" {}
    7.     _BumpMap ("Normalmap", 2D) = "bump" {}
    8.     _Cutoff ("Alpha cutoff", Range(0,1)) = 0.5
    9. }
    10.  
    11. SubShader {
    12.     Tags {"Queue"="AlphaTest" "IgnoreProjector"="True" "RenderType"="TransparentCutout"}
    13.     LOD 400
    14.     Cull Off
    15.    
    16. CGPROGRAM
    17. #pragma surface surf BlinnPhong alphatest:_Cutoff
    18.  
    19. sampler2D _MainTex;
    20. sampler2D _BumpMap;
    21. fixed4 _Color;
    22. half _Shininess;
    23.  
    24. struct Input {
    25.     float2 uv_MainTex;
    26.     float2 uv_BumpMap;
    27. };
    28.  
    29. void surf (Input IN, inout SurfaceOutput o) {
    30.     fixed4 tex = tex2D(_MainTex, IN.uv_MainTex);
    31.     o.Albedo = tex.rgb * _Color.rgb;
    32.     o.Gloss = tex.rgb * _Color.rgb;
    33.     o.Alpha = tex.a * _Color.a;
    34.     o.Specular = _Shininess;
    35.     o.Normal = UnpackNormal(tex2D(_BumpMap, IN.uv_BumpMap));
    36. }
    37. ENDCG
    38. }
    39.  
    40. FallBack "Transparent/Cutout/VertexLit"
    41. }
    42.  
     
  2. Jessy

    Jessy

    Joined:
    Jun 7, 2007
    Posts:
    7,325
  3. Killstar

    Killstar

    Joined:
    May 11, 2011
    Posts:
    94
    I did not think. I do not know much about programming, so I was looking for help :)
     
  4. Killstar

    Killstar

    Joined:
    May 11, 2011
    Posts:
    94
    "...There is an easy way around this, which is to split the shader into two passes. The first pass uses Cull Back, and treats each normal as usual. The second pass uses Cull Front, and inverts each normal in the vertex program. Now we have a shader that renders both sides of each triangle with correct lighting..."

    How to do it?
     
  5. Andrew_atl

    Andrew_atl

    Joined:
    Sep 21, 2010
    Posts:
    103
    Read to the end of the article. *Hint* you won't need to learn how to do it.