如何让模型产生双面法线效果

在Unity的內建shader中,預設的顯像方式是 "Back-Face Culling",也就是背面是看不見的,如果需要呈現雙面法線時,我們可以透過修改Shader來達到正反面都顯示的效果。

1.預設的顯示模式,反面是看不見的。


TwoSideNormal-1.png



2.新增一個自訂shader文件。


TwoSideNormal-2.png



3.以內建的Diffuse為例,修改其中的Pass函数,增加一行 "Cull Off"。


TwoSideNormal-3.png



4.新增一個材質球並套用修改過的shader,即可達到雙面顯像的效果。


TwoSideNormal-4.png 
Shader "DoubleSided" { 
   Properties { 
      _Color ("Main Color", Color) = (1,1,1,1) 
      _MainTex ("Base (RGB)", 2D) = "white" {} 
      //_BumpMap ("Bump (RGB) Illumin (A)", 2D) = "bump" {} 
   } 
   SubShader {       
      //UsePass "Self-Illumin/VertexLit/BASE" 
      //UsePass "Bumped Diffuse/PPL" 
       
      // Ambient pass 
      Pass { 
      Name "BASE" 
      Tags {"LightMode" = "PixelOrNone"} 
      Color [_PPLAmbient] 
      SetTexture [_BumpMap] { 
         constantColor (.5,.5,.5) 
         combine constant lerp (texture) previous 
         } 
      SetTexture [_MainTex] { 
         constantColor [_Color] 
         Combine texture * previous DOUBLE, texture*constant 
         } 
      } 
    
   // Vertex lights 
   Pass { 
      Name "BASE" 
      Tags {"LightMode" = "Vertex"} 
      Material { 
         Diffuse [_Color] 
         Emission [_PPLAmbient] 
         Shininess [_Shininess] 
         Specular [_SpecColor] 
         } 
      SeparateSpecular On 
      Lighting On 
      Cull Off 
      SetTexture [_BumpMap] { 
         constantColor (.5,.5,.5) 
         combine constant lerp (texture) previous 
         } 
      SetTexture [_MainTex] { 
         Combine texture * previous DOUBLE, texture*primary 
         } 
      } 
   } 
   FallBack "Diffuse", 1 
}

转载于:https://www.cnblogs.com/lm3515/archive/2010/09/01/1814776.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值