Search Unity

  1. We've closed the job boards. If you're looking for work, or looking to hire check out Unity Connect. You can see more information here.
    Dismiss Notice
  2. Check out our Unite Austin 2017 YouTube playlist to catch up on what you missed. More videos coming soon.
    Dismiss Notice
  3. Unity 2017.2 is now released.
    Dismiss Notice
  4. The Unity Gear Store is here to help you look great at your next meetup, user group or conference. With all new Unity apparel, stickers and more!
    Dismiss Notice
  5. Introducing the Unity Essentials Packs! Find out more.
    Dismiss Notice
  6. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice
  7. Unity 2017.3 beta is now available for download.
    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.