Unity3D shader(16)——“Queue”、“IgnoreProjector”、"RenderType"、Ztest、Zwrite、cull

经常在Unity3D里的shader里见到这样的Tags{"Queue"="Transparent"  "IgnoreProjector"="True" "RenderType"="Transparent"}语句,这些语句都有什么意思呢?在不同的情景上,又怎么去用好这些命令,今天就主要讲讲这些问题。

首先第一个"Queue"="Transparent"  ,"Queue"可以无视物体实际的位置,随意控制哪个物体显示在前面。以下是对渲染队列的描述。


来试试效果:

可以发现并没有什么效果。所以这个一般也很少用,它被用在天空上,天空是只一个被渲染的,然后被后渲染的物体遮挡住。

 Tags { "Queue"="Background" }



来试试后面的球体的shader加上Tags { "Queue"="Geometry" },给在前面的球体的shader加上Tags { "Queue"="Geometry-100" },表示前面的球体先渲染。另外,程序默认是记录深度,即ZWrite默认是on,也即Tags { "Queue"="Geometry-100" }不起作用, 要想Tags { "Queue"="Geometry-100" }起作用,ZWrite的值必须为Off。运行后发现前面的球体看起来在后面。


再来试试Tags { "Queue"="Transparent" },对于透明的物体,加上Blend SrcAlpha OneMinusSrcAlpha才会有效果,其中同Geometry一样,Tags { "Queue"="Transparent-100" }也可以控制物体显示的前后顺序。

最后试了下Tags { "Queue"="Overlay" },也没有什么效果。

所以,我们可以通过Tags { "Queue"="Geometry" },和Tags { "Queue"="Transparent" }加减值控制重要物体的显示顺序,这个时候ZWrite的值必须为Off。


“IgnoreProjector”=“True”告诉Unity3D,我们不希望任何投影类型材质或者贴图,影响我们的物体或者着色器。这个特性往往那个用在GUI上。程序默认“IgnoreProjector”=“Flase”。

"RenderType"的用法类似于“Queue”。它将着色器归类到相机效果中。

Ztest的介绍见:http://blog.csdn.net/liqiangeastsun/article/details/44962661。

在渲染的时候,默认情况下是只有朝向摄像机的面才会被渲染,可以告诉Unity,我想渲染哪一个朝向的面,使用Cull命令在计算体积阴影的时候会用到对Cull的操作来计算和物体相交的投影。

Cull 有三种 

Cull Off 不剔除 
Cull Back 剔除背面(背向摄像机的面) 
Cull Front 剔除前面 (朝向摄像机的面)









  • 7
    点赞
  • 29
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是一个简单的Unity3D着色器,可以制作冰冻效果。它使用了一个简单的反射纹理和一个噪声纹理来创建冰的外观。 ``` Shader "Custom/IceShader" { Properties { _MainTex ("Texture", 2D) = "white" {} _ReflectTex ("Reflect Texture", 2D) = "white" {} _NoiseTex ("Noise Texture", 2D) = "white" {} _BumpScale ("Bump Scale", Range(0.01, 0.1)) = 0.05 _Reflectivity ("Reflectivity", Range(0.0, 1.0)) = 0.5 _NoiseScale ("Noise Scale", Range(0.1, 10.0)) = 1.0 _IceColor ("Ice Color", Color) = (1,1,1,1) } SubShader { Tags { "Queue"="Transparent" "RenderType"="Opaque" } LOD 100 CGPROGRAM #pragma surface surf Standard sampler2D _MainTex; sampler2D _ReflectTex; sampler2D _NoiseTex; float _BumpScale; float _Reflectivity; float _NoiseScale; fixed4 _IceColor; struct Input { float2 uv_MainTex; float2 uv_ReflectTex; float2 uv_NoiseTex; float3 worldPos; float3 worldNormal; }; void surf (Input IN, inout SurfaceOutputStandard o) { // Get the base color from the main texture fixed4 baseColor = tex2D(_MainTex, IN.uv_MainTex); // Get the reflection from the reflect texture fixed4 reflectColor = tex2D(_ReflectTex, IN.uv_ReflectTex); // Combine the base color and reflection fixed4 finalColor = lerp(baseColor, reflectColor, _Reflectivity); // Apply the ice color finalColor *= _IceColor; // Get the bump from the noise texture float4 noise = tex2D(_NoiseTex, IN.uv_NoiseTex); // Convert the noise to a normal vector float3 normal = UnpackNormal(noise.rgb); // Apply the bump to the surface normal IN.worldNormal += normal * _BumpScale; // Set output parameters o.Albedo = finalColor.rgb; o.Metallic = 0.0; o.Smoothness = 1.0; o.Normal = normalize(IN.worldNormal); o.Emission = finalColor.rgb; o.Occlusion = 1.0; o.Alpha = finalColor.a; } ENDCG } FallBack "Diffuse" } ``` 要使用这个着色器,您需要将三个纹理分别指定给_MainTex,_ReflectTex和_NoiseTex属性。您还可以调整_BumpScale,_Reflectivity和_NoiseScale参数来改变效果。最后,您可以使用_IceColor来指定冰的颜色。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值