Unity Community


Results 1 to 5 of 5

  1. Posts
    94

    Two-sided shader - shadow problem

    Hi
    Anyone knows how to fix shadow sorting? I changed shader AlphaTest-BumpSpec by adding "Cull Off"



    Code:  
    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. }


  2. Location
    NE Ohio, USA
    Posts
    7,173
    Why would you think having culling off would work for something that takes lighting?

    http://danielbrauer.com/files/archive-mar-2011.html



  3. 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?


  4. Posts
    94
    Quote Originally Posted by Killstar View Post
    "...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?
    Read to the end of the article. *Hint* you won't need to learn how to do it.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •