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

用的是最簡(jiǎ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"
}
那這個(gè)問(wèn)題,實(shí)際上是背面剔除的致使的。
我們知道物體都有兩面,1個(gè)立方體盒子,有外面和里面之分,對(duì)我們游戲來(lái)講,玩家1般只能看到外面,里面實(shí)際上是不需要的。
所以默許Unity會(huì)開(kāi)啟背面剔除,把背對(duì)攝像機(jī)的面都剔除掉。
轉(zhuǎn)自http://blog.csdn.net/huutu http://www.thisisgame.com.cn
3角面的正面朝向有兩種定義方式:
1、頂點(diǎn)的繪制順序
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
剔除正面,留下了背面,背面是不受光照的,所以會(huì)更暗。
關(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)辛苦
如果您覺(jué)得本網(wǎng)站對(duì)您的學(xué)習(xí)有所幫助,可以手機(jī)掃描二維碼進(jìn)行捐贈(zèng)