在Unity的内建shader中,预设的显像方式是 “Back-Face Culling”,也就是背面是看不见的,如果需要呈现双面法线时,我们可以透过修改Shader来达到正反面都显示的效果。
1.预设的显示模式,反面是看不见的。
2.新增一个自订shader文件。
3.以内建的Diffuse为例,修改其中的Pass函数,增加一行 “Cull Off”。
4.新增一个材质球并套用修改过的shader,即可达到双面显像的效果。
01 | Shader “DoubleSided” { |
02 | |
03 | Properties { |
04 | |
05 | _Color (“Main Color”, Color) = (1,1,1,1) |
06 | |
07 | _MainTex (“Base (RGB)”, 2D) = “white” {} |
08 | |
09 | //_BumpMap (“Bump (RGB) Illumin (A)”, 2D) = “bump” {} |
10 | |
11 | } |
12 | |
13 | SubShader { |
14 | |
15 | //UsePass “Self−Illumin/VertexLit/BASE” |
16 | |
17 | //UsePass “Bumped Diffuse/PPL” |
18 | |
19 | // Ambient pass |
20 | |
21 | Pass { |
22 | |
23 | Name “BASE” |
24 | |
25 | Tags {“LightMode” = “PixelOrNone”} |
26 | |
27 | Color [_PPLAmbient] |
28 | |
29 | SetTexture [_BumpMap] { |
30 | |
31 | constantColor (.5,.5,.5) |
32 | |
33 | combine constant lerp (texture) previous |
34 | |
35 | } |
36 | |
37 | SetTexture [_MainTex] { |
38 | |
39 | constantColor [_Color] |
40 | |
41 | Combine texture * previous DOUBLE, texture*constant |
42 | |
43 | } |
44 | |
45 | } |
46 | |
47 | // Vertex lights |
48 | |
49 | Pass { |
50 | |
51 | Name “BASE” |
52 | |
53 | Tags {“LightMode” = “Vertex”} |
54 | |
55 | Material { |
56 | |
57 | Diffuse [_Color] |
58 | |
59 | Emission [_PPLAmbient] |
60 | |
61 | Shininess [_Shininess] |
62 | |
63 | Specular [_SpecColor] |
64 | |
65 | } |
66 | |
67 | SeparateSpecular On |
68 | |
69 | Lighting On |
70 | |
71 | Cull Off |
72 | |
73 | SetTexture [_BumpMap] { |
74 | |
75 | constantColor (.5,.5,.5) |
76 | |
77 | combine constant lerp (texture) previous |
78 | |
79 | } |
80 | |
81 | SetTexture [_MainTex] { |
82 | |
83 | Combine texture * previous DOUBLE, texture*primary |
84 | |
85 | } |
86 | |
87 | } |
88 | |
89 | } |
90 | |
91 | FallBack “Diffuse”, 1 |
92 | |
93 | } |
http://www.unitymanual.com/4423.html