国内最全IT社区平台 联系我们 | 收藏本站
华晨云阿里云优惠2
您当前位置:首页 > php开源 > 综合技术 > Unity Shaders and Effects Cookbook (D-2) Cull Back背面剔除 -- 模型半边不可见

Unity Shaders and Effects Cookbook (D-2) Cull Back背面剔除 -- 模型半边不可见

来源:程序员人生   发布时间:2016-11-28 13:56:33 阅读次数:3554次

这两天从其它游戏里面拔1些资源来给美术做参考,碰到很多模型都是只有1半可见,另外一半要转动视角才可见。



用的是最简单的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会开启背面剔除,把背对摄像机的面都剔除掉。

转自http://blog.csdn.net/huutu http://www.thisisgame.com.cn

3角面的正面朝向有两种定义方式:

1、顶点的绘制顺序

2、面法线的朝向


我不知道Unity是哪一种方式。

但是我可以关闭背面剔除。


首先。

Unity 中的背面剔除有几种模式:

1、Cull Back 剔除背面,这是默许的方式

2、Cull Front 剔除正面

3、Cull Off 关闭剔除


默许是 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" }

效果转自http://blog.csdn.net/huutu http://www.thisisgame.com.cn


剔除正面,留下了背面,背面是不受光照的,所以会更暗。


关闭背面剔除,修改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" }

效果转自http://blog.csdn.net/huutu http://www.thisisgame.com.cn



生活不易,码农辛苦
如果您觉得本网站对您的学习有所帮助,可以手机扫描二维码进行捐赠
程序员人生
------分隔线----------------------------
分享到:
------分隔线----------------------------
关闭
程序员人生