内置管线

 1     Properties {
 2         _MainTex("Main Tex", 2D) = "while"{}
 3     }
 4     SubShader {
 5         Pass {
 6             Tags {"LightMode" = "ForwardBase"}
 7  
 8             CGPROGRAM
 9  
10             #pragma vertex vert
11             #pragma fragment frag
12             
13             #include "Lighting.cginc"
14  
15             sampler2D _MainTex;
16             float4 _MainTex_ST;
17  
18             struct a2v {
19                 float4 vertex: POSITION;
20                 float4 texcoord: TEXCOORD0;
21             };
22  
23             struct v2f {
24                 float4 position: SV_POSITION;
25                 float2 uv: TEXCOORD0;
26             };
27  
28             v2f vert(a2v v) {
29                 v2f o;
30                 o.position = UnityObjectToClipPos(v.vertex);
31                 o.uv = TRANSFORM_TEX(v.texcoord, _MainTex);
32                 return o;
33             }
34  
35             fixed4 frag(v2f i) : SV_Target {
36                 fixed4 c = tex2D(_MainTex, i.uv);
37                 return fixed4(c.rgb, 1.0);
38             }
39  
40             ENDCG
41         }
42     }
43     FallBack "Diffuse"
44 }

urp管线

 1 Shader "Unity Shaders Book/Chapter 7/Texture Properties" {
 2     Properties {
 3         _MainTex("Main Tex", 2D) = "while"{}
 4     }
 5     SubShader {
 6         Tags {
 7             "RenderPipeline"="UniversalPipeline"
 8         }
 9         Pass {
10             Tags {"LightMode" = "UniversalForward"}
11  
12             HLSLPROGRAM
13  
14             #pragma vertex vert
15             #pragma fragment frag
16             
17             #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
18  
19         CBUFFER_START(UnityPerMaterial)
20             float4 _MainTex_ST;
21         CBUFFER_END
22  
23             TEXTURE2D(_MainTex);
24             SAMPLER(sampler_MainTex);
25  
26             struct a2v {
27                 float4 vertex: POSITION;
28                 float4 texcoord: TEXCOORD0;
29             };
30  
31             struct v2f {
32                 float4 position: SV_POSITION;
33                 float2 uv: TEXCOORD0;
34             };
35  
36             v2f vert(a2v v) {
37                 v2f o;
38                 o.position = TransformObjectToHClip(v.vertex.xyz);
39                 o.uv = TRANSFORM_TEX(v.texcoord, _MainTex);
40                 return o;
41             }
42  
43             half4 frag(v2f i) : SV_Target {
44                 half4 c = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, i.uv);
45                 return half4(c.rgb, 1.0);
46             }
47  
48             ENDHLSL
49         }
50     }
51     FallBack "Universal Render Pipeline/Simple Lit"
52 }