1. Help us improve the editor usability and artist workflows. Join our discussion to provide your feedback.
    Dismiss Notice
  2. We're looking for feedback on Unity Starter Kits! Let us know what you’d like.
    Dismiss Notice
  3. We’re giving 2017.1 beta testers a chance to win t-shirts and a Nintendo Switch. Read more on the blog.
    Dismiss Notice
  4. Unity 2017.1 beta is now available for download.
    Dismiss Notice
  5. Unity 5.6 is now released.
    Dismiss Notice
  6. Get further faster with the Unity Plus Accelerator Pack, free for new Unity Plus subscribers for a limited time. Click here for more details.
    Dismiss Notice
  7. Check out all the fixes for 5.6 on the patch releases page.
    Dismiss Notice
  8. Learn how you'll soon be able to publish your games to China in four simple steps with Xiaomi. Sign up now for early access.
    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"

    [​IMG]

    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,327
  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.