内置管线

 1 Shader "Unity Shaders Book/Chapter 10/Mirror" {
 2     Properties {
 3         _MainTex("Render Tex", 2D) = "white" {}
 4         _AlphaScale("Aplpha Scale", Range(0, 1)) = 0.5
 5     }
 6  
 7     SubShader {
 8         // Tags {"Queue"="Geometry" "RenderType"="Opaque"}
 9         Tags {"Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent"}
10  
11         Pass {
12             Tags {"Lighting"="ForwardBase"}
13             ZWrite Off
14             Blend SrcAlpha OneMinusSrcAlpha
15  
16             CGPROGRAM
17             #include "Lighting.cginc"
18  
19             #pragma vertex vert
20             #pragma fragment frag
21  
22             sampler2D _MainTex;
23             fixed _AlphaScale;
24  
25             struct a2v {
26                 float4 vertex : POSITION;
27                 float4 texcoord : TEXCOORD0;
28             };
29  
30             struct v2f {
31                 float4 pos : SV_POSITION;
32                 float2 uv : TEXCOORD0;
33             };
34  
35             v2f vert(a2v v) {
36                 v2f o;
37                 o.pos = UnityObjectToClipPos(v.vertex);
38                 o.uv = v.texcoord.xy;
39                 o.uv.x = 1 - o.uv.x;
40                 return o;
41             }
42  
43             fixed4 frag(v2f i) : SV_Target {
44                 fixed4 texColor = tex2D(_MainTex, i.uv);
45                 return fixed4(texColor.rgb, texColor.a * _AlphaScale);
46             }
47  
48             ENDCG
49         }
50     }
51 }

urp管线

 1 Shader "Unity Shaders Book/Chapter 10/Mirror" {
 2     Properties {
 3         _MainTex("Render Tex", 2D) = "white" {}
 4         _AlphaScale("Aplpha Scale", Range(0, 1)) = 0.5
 5     }
 6  
 7     SubShader {
 8         Tags {
 9             "RenderPipeline"="UniversalPipeline"
10             "Queue"="Geometry" "RenderType"="Opaque"
11         }
12  
13         // Tags {
14         //     "RenderPipeline"="UniversalPipeline"
15         //     "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent"
16         // }
17  
18         Pass {
19             Tags {"Lighting"="UniversalForward"}
20             // ZWrite Off
21             // Blend SrcAlpha OneMinusSrcAlpha
22  
23             HLSLPROGRAM
24  
25             #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
26  
27             #pragma vertex vert
28             #pragma fragment frag
29  
30 CBUFFER_START(UnityPerMaterial)
31             half _AlphaScale;
32 CBUFFER_END
33  
34             TEXTURE2D(_MainTex);
35             SAMPLER(sampler_MainTex);
36  
37             struct a2v {
38                 float4 vertex : POSITION;
39                 half4 texcoord : TEXCOORD0;
40             };
41  
42             struct v2f {
43                 float4 pos : SV_POSITION;
44                 float2 uv : TEXCOORD0;
45             };
46  
47             v2f vert(a2v v) {
48                 v2f o;
49                 o.pos = TransformObjectToHClip(v.vertex.xyz);
50                 o.uv = v.texcoord.xy;
51                 o.uv.x = 1 - o.uv.x;
52                 return o;
53             }
54  
55             half4 frag(v2f i) : SV_Target {
56                 half4 texColor = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, i.uv);
57                 return half4(texColor.rgb, texColor.a * _AlphaScale);
58             }
59  
60             ENDHLSL
61         }
62     }
63 }