话不多说,直接上代码,具体区别我后边会补充上,
暂时委屈各位,先锻炼下自己的“找不同”的能力,哈哈:
Built-CG写法:
Shader "Unity Shaders Book/Chapter 10/Mirror" {
Properties {
_MainTex("Render Tex", 2D) = "white" {}
_AlphaScale("Aplpha Scale", Range(0, 1)) = 0.5
}
SubShader {
// Tags {"Queue"="Geometry" "RenderType"="Opaque"}
Tags {"Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent"}
Pass {
Tags {"Lighting"="ForwardBase"}
ZWrite Off
Blend SrcAlpha OneMinusSrcAlpha
CGPROGRAM
#include "Lighting.cginc"
#pragma vertex vert
#pragma fragment frag
sampler2D _MainTex;
fixed _AlphaScale;
struct a2v {
float4 vertex : POSITION;
float4 texcoord : TEXCOORD0;
};
struct v2f {
float4 pos : SV_POSITION;
float2 uv : TEXCOORD0;
};
v2f vert(a2v v) {
v2f o;
o.pos = UnityObjectToClipPos(v.vertex);
o.uv = v.texcoord.xy;
o.uv.x = 1 - o.uv.x;
return o;
}
fixed4 frag(v2f i) : SV_Target {
fixed4 texColor = tex2D(_MainTex, i.uv);
return fixed4(texColor.rgb, texColor.a * _AlphaScale);
}
ENDCG
}
}
}
URP+HLSL写法:
Shader "Unity Shaders Book/Chapter 10/Mirror" {
Properties {
_MainTex("Render Tex", 2D) = "white" {}
_AlphaScale("Aplpha Scale", Range(0, 1)) = 0.5
}
SubShader {
Tags {
"RenderPipeline"="UniversalPipeline"
"Queue"="Geometry" "RenderType"="Opaque"
}
// Tags {
// "RenderPipeline"="UniversalPipeline"
// "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent"
// }
Pass {
Tags {"Lighting"="UniversalForward"}
// ZWrite Off
// Blend SrcAlpha OneMinusSrcAlpha
HLSLPROGRAM
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
#pragma vertex vert
#pragma fragment frag
CBUFFER_START(UnityPerMaterial)
half _AlphaScale;
CBUFFER_END
TEXTURE2D(_MainTex);
SAMPLER(sampler_MainTex);
struct a2v {
float4 vertex : POSITION;
half4 texcoord : TEXCOORD0;
};
struct v2f {
float4 pos : SV_POSITION;
float2 uv : TEXCOORD0;
};
v2f vert(a2v v) {
v2f o;
o.pos = TransformObjectToHClip(v.vertex.xyz);
o.uv = v.texcoord.xy;
o.uv.x = 1 - o.uv.x;
return o;
}
half4 frag(v2f i) : SV_Target {
half4 texColor = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, i.uv);
return half4(texColor.rgb, texColor.a * _AlphaScale);
}
ENDHLSL
}
}
}