創建透明材質
Unity Shader 透明 屬性需要設置 相應的 渲染隊列:
渲染隊列 | 渲染隊列描述 | 渲染隊列的值 |
Background | 是第一個渲染列隊, 常用語天空盒 背景的渲染 | 1000 |
Geometry | 默認的渲染隊列, 被用於大多數場景對象。 不透明幾何體使用 該列隊 | 2000 |
AlphaTest | alpha 測試的 幾何體 使用該列隊, 與 Geometry 隊列不同的在於: 在所有實體對象 繪製完畢之後 它 渲染 alpha測試對象的 效率更高 | 2450 |
Transparent | 該 列隊在 Geometry 和 AlphaTest 隊列之後渲染, 按照從後面 到前面的順序。 任何 alpha 融合(alpha blending , 這些 Shader 不寫入 深度緩存中) 需要在這一隊列中進行, 比如玻璃離子和特效 | 3000 |
Overlay | 該隊列是用於 疊加特效的; 任何需要最後 渲染的對象 需要放在這裏。 比如鏡頭炫光效果 | 4000 |
Shader "Custom/chapter02/TransparentShader"
{
Properties
{
_Color ("Color", Color) = (1,1,1,1)
_MainTex ("Albedo (RGB)", 2D) = "white" {}
}
SubShader
{
Tags {
"RenderType" = "Transparent"
"IgnoreProjector" = "True"
"Queue" = "Transparent"
}
LOD 200
Cull Off
CGPROGRAM
// Physically based Standard lighting model, and enable shadows on all light types
#pragma surface surf Standard alpha:fade
// Use shader model 3.0 target, to get nicer looking lighting
#pragma target 3.0
sampler2D _MainTex;
struct Input
{
float2 uv_MainTex;
};
fixed4 _Color;
// Add instancing support for this shader. You need to check 'Enable Instancing' on materials that use the shader.
// See https://docs.unity3d.com/Manual/GPUInstancing.html for more information about instancing.
// #pragma instancing_options assumeuniformscaling
UNITY_INSTANCING_BUFFER_START(Props)
// put more per-instance properties here
UNITY_INSTANCING_BUFFER_END(Props)
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"
}
這裏要把 默認的 渲染標籤 修改爲: "Transparent"
Tags {
"RenderType" = "Transparent"
"IgnoreProjector" = "True"
"Queue" = "Transparent"
}
而且和設置 Alpha 融合
#pragma surface surf Standard alpha:fade