Unity Shaders and Effects Cookbook (D-2) Cull Back背面剔除 -- 模型半邊不可見
來源:程序員人生 發(fā)布時間:2016-11-28 13:56:33 閱讀次數(shù):3967次
這兩天從其它游戲里面拔1些資源來給美術(shù)做參考,碰到很多模型都是只有1半可見,另外一半要轉(zhuǎn)動視角才可見。

用的是最簡單的Diffuse Shader:
Shader "Custom/MyDiffuse"
{
Properties
{
_Color ("Color", Color) = (1,1,1,1)
_MainTex ("Albedo (RGB)", 2D) = "white" {}
}
SubShader {
Tags { "RenderType"="Opaque" }
LOD 200
CGPROGRAM
#pragma surface surf Standard
// Use shader model 3.0 target, to get nicer looking lighting
#pragma target 3.0
sampler2D _MainTex;
struct Input
{
float2 uv_MainTex;
};
fixed4 _Color;
void surf (Input IN, inout SurfaceOutputStandard o)
{
// Albedo comes from a texture tinted by color
fixed4 c = tex2D (_MainTex, IN.uv_MainTex) * _Color;
o.Albedo = c.rgb;
o.Alpha = c.a;
}
ENDCG
}
FallBack "Diffuse"
}
那這個問題,實際上是背面剔除的致使的。
我們知道物體都有兩面,1個立方體盒子,有外面和里面之分,對我們游戲來講,玩家1般只能看到外面,里面實際上是不需要的。
所以默許Unity會開啟背面剔除,把背對攝像機的面都剔除掉。
轉(zhuǎn)自http://blog.csdn.net/huutu http://www.thisisgame.com.cn
3角面的正面朝向有兩種定義方式:
1、頂點的繪制順序
2、面法線的朝向
我不知道Unity是哪一種方式。
但是我可以關(guān)閉背面剔除。
首先。
Unity 中的背面剔除有幾種模式:
1、Cull Back 剔除背面,這是默許的方式
2、Cull Front 剔除正面
3、Cull Off 關(guān)閉剔除
默許是 Cull Back

使用 Cull Front 的話,修改Shader以下
Shader "Custom/MyDiffuse"
{
Properties
{
_Color ("Color", Color) = (1,1,1,1)
_MainTex ("Albedo (RGB)", 2D) = "white" {}
}
SubShader {
Tags { "RenderType"="Opaque" }
LOD 200
Cull Front
CGPROGRAM
#pragma surface surf Standard
// Use shader model 3.0 target, to get nicer looking lighting
#pragma target 3.0
sampler2D _MainTex;
struct Input
{
float2 uv_MainTex;
};
fixed4 _Color;
void surf (Input IN, inout SurfaceOutputStandard o)
{
// Albedo comes from a texture tinted by color
fixed4 c = tex2D (_MainTex, IN.uv_MainTex) * _Color;
o.Albedo = c.rgb;
o.Alpha = c.a;
}
ENDCG
}
FallBack "Diffuse"
}
效果
轉(zhuǎn)自http://blog.csdn.net/huutu http://www.thisisgame.com.cn
剔除正面,留下了背面,背面是不受光照的,所以會更暗。
關(guān)閉背面剔除,修改Shader 以下
Shader "Custom/MyDiffuse"
{
Properties
{
_Color ("Color", Color) = (1,1,1,1)
_MainTex ("Albedo (RGB)", 2D) = "white" {}
}
SubShader {
Tags { "RenderType"="Opaque" }
LOD 200
Cull Off
CGPROGRAM
#pragma surface surf Standard
// Use shader model 3.0 target, to get nicer looking lighting
#pragma target 3.0
sampler2D _MainTex;
struct Input
{
float2 uv_MainTex;
};
fixed4 _Color;
void surf (Input IN, inout SurfaceOutputStandard o)
{
// Albedo comes from a texture tinted by color
fixed4 c = tex2D (_MainTex, IN.uv_MainTex) * _Color;
o.Albedo = c.rgb;
o.Alpha = c.a;
}
ENDCG
}
FallBack "Diffuse"
}
效果
轉(zhuǎn)自http://blog.csdn.net/huutu http://www.thisisgame.com.cn
生活不易,碼農(nóng)辛苦
如果您覺得本網(wǎng)站對您的學習有所幫助,可以手機掃描二維碼進行捐贈