Unity URP Shader之灰度化

shader如下:

 1 Shader "TA/Unlit/UI/UIImageGray"
 2 {
 3     Properties
 4     {
 5         _MainTex("Main Texture", 2D) = "white"{}
 6     }
 7 
 8     SubShader
 9     {
10         Tags
11         {
12             "Queue" = "Transparent"
13             "IgnoreProjector" = "True"
14             "RenderType" = "Transparent"
15             "RenderPipeline" = "UniversalForward"
16         }
17 
18         Pass
19         {
20             Blend SrcAlpha OneMinusSrcAlpha
21             Cull Off
22             Lighting Off 
23             ZWrite Off
24 
25             HLSLPROGRAM
26             #pragma vertex vert
27             #pragma fragment frag
28             #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
29 
30             TEXTURE2D(_MainTex); SAMPLER(sampler_MainTex);
31             float4 _MainTex_ST;
32             
33             struct appdata_t
34             {
35                 float4 vertex : POSITION;
36                 float2 texcoord : TEXCOORD0;
37                 half4 color : COLOR;
38             };
39 
40             struct v2f
41             {
42                 float4 clipPos : POSITION;
43                 float2 uv : TEXCOORD0;
44                 half4 color : COLOR;
45             };
46             
47 
48             v2f vert (appdata_t v)
49             {
50                 v2f o;
51                 o.clipPos = mul(UNITY_MATRIX_MVP, v.vertex);
52                 o.uv = TRANSFORM_TEX(v.texcoord,_MainTex);
53                 o.color = v.color;
54                 return o;
55             }
56             
57             half4 frag (v2f i) : SV_Target
58             {
59                 half4 mainCol = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, i.uv);
60                 half4 col;
61                 col.rgb = dot(mainCol.rgb, half3(0.222, 0.707, 0.071));
62                 col.a = mainCol.a;
63                 col *= i.color;
64                 return col;
65             }
66             ENDHLSL
67         }
68     }
69 
70     FallBack Off
71 }

 

转载请注明出处:https://www.cnblogs.com/jietian331/p/17043381.html

posted @ 2023-01-11 12:30  孤独の巡礼  阅读(207)  评论(0编辑  收藏  举报