当前位置:   article > 正文

unity UI shader 之Overlay Mode_unity shader uioverlay

unity shader uioverlay

在这里插入图片描述

// Unity built-in shader source. Copyright (c) 2016 Unity Technologies. MIT license (see license.txt)

Shader "UI/PS-Overlay_Mode" {
Properties {
	[KeywordEnum(None,Darken,Multiply,ColorBurn,LinearBurn,Lighten,Screen,ColorDodge,LinearDodge)] _Overlay ("Overlay mode 1", Float) = 0
	[KeywordEnum(None, Overlay,SoftLight,HardLight,VividLight,LinearLight,PinLight,Difference,Exclusion)] _Overlay2 ("Overlay mode 2", Float) = 0
	_TintColor1("Color1",Color) = (1,1,1,1)
	_TintColor2("Color2",Color) = (1,1,1,1)
    _MainTex ("Particle Texture", 2D) = "white" {}
}

Category {
    Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" "PreviewType"="Plane" }
    Blend One OneMinusSrcColor
//    Blend OneMinusSrcColor One
//	Blend SrcAlpha OneMinusSrcColor
//	Blend SrcAlpha One
//    Blend One One
//    Blend One Zero
//    Blend Zero One
//    ColorMask RGB
//    Cull Off 
    Lighting Off 
    ZWrite Off

    SubShader {
        Pass {
            CGPROGRAM
            #pragma vertex vert
            #pragma fragment frag
            #pragma target 2.0
            #pragma multi_compile _OVERLAY_NONE _OVERLAY_DARKEN _OVERLAY_MULTIPLY _OVERLAY_COLORBURN _OVERLAY_LINEARBURN _OVERLAY_LIGHTEN _OVERLAY_SCREEN _OVERLAY_COLORDODGE _OVERLAY_LINEARDODGE 
			#pragma multi_compile _OVERLAY2_NONE _OVERLAY2_OVERLAY _OVERLAY2_SOFTLIGHT _OVERLAY2_HARDLIGHT _OVERLAY2_VIVIDLIGHT _OVERLAY2_LINEARLIGHT _OVERLAY2_PINLIGHT _OVERLAY2_DIFFERENCE _OVERLAY2_EXCLUSION
            #include "UnityCG.cginc"

            sampler2D _MainTex;
            float4 _MainTex_ST;
            fixed4 _TintColor1;
			fixed4 _TintColor2;
            struct appdata_t {
                float4 vertex : POSITION;
                fixed4 color : COLOR;
                float2 texcoord : TEXCOORD0;
            };

            struct v2f {
                float4 vertex : SV_POSITION;
                fixed4 color : COLOR;
                float2 texcoord : TEXCOORD0;
            };

            v2f vert (appdata_t v)
            {
                v2f o = (v2f)0;
                o.vertex =mul(UNITY_MATRIX_MVP, v.vertex);// UnityObjectToClipPos(v.vertex);
                o.color = v.color;
                o.texcoord = TRANSFORM_TEX(v.texcoord,_MainTex);
                return o;
            }

            fixed4 frag (v2f i) : SV_Target
            {
                half4 tex = tex2D(_MainTex, i.texcoord);
                half4 col = i.color * tex * _TintColor2;
//                col.rgb *= col.a;

                //Darken 变暗
				#if _OVERLAY_DARKEN
					col.rgb = min(col.rgb,col.rgb);
				#endif
					
				//Multiply 正片叠底
				#if _OVERLAY_MULTIPLY
					col.rgb = col.rgb * col.rgb; 
					col.rgb *=col.rgb*2;
	                
				#endif
				
				//ColorBurn 颜色加深
				#if _OVERLAY_COLORBURN
					col.rgb = 1.0 - (1.0 - col.rgb) / col.rgb; 
				#endif
				
				//LinearBurn 线性加深
				#if _OVERLAY_LINEARBURN
					col.rgb = col.rgb + col.rgb - 1.0; 
				#endif
				
				//Lighten 变亮
				#if _OVERLAY_LIGHTEN
					col.rgb = max(col.rgb,col.rgb);
					//col = col*_TintColor1;
				#endif
				
				//Screen 滤色
				#if _OVERLAY_SCREEN
					col.rgb = 1.0 - (1.0 - col.rgb) * (1.0 - col.rgb);
				#endif
				
				//ColorDodge 颜色减淡
				#if _OVERLAY_COLORDODGE
					col.rgb = col.rgb / (1.0 - col.rgb);
				#endif
				
				//LinearDodge(Add) 线性减淡(添加)
				#if _OVERLAY_LINEARDODGE
					col.rgb = col.rgb + col.rgb;
				#endif
				
				//Overlay 叠加
				#if _OVERLAY2_OVERLAY
					col.rgb = step(0.5, col.rgb);				
					col.rgb = lerp((col.rgb*col.rgb*2), (1.0-(2.0*(1.0-col.rgb)*(1.0-col.rgb))), col.rgb);
				#endif
				
				//Soft Light 柔光
				#if _OVERLAY2_SOFTLIGHT
					if(col.r > .5){col.r = col.r * (1.0-(1.0-col.r)*(1.0-2*col.r));}
					else{col.r = 1.0-(1.0-col.r)*(1.0-(col.r*2.0*col.r));}
					
					if(col.g > .5){col.g = col.g * (1.0-(1.0-col.g)*(1.0-2*col.g));}
					else{col.g = 1.0-(1.0-col.g)*(1.0-(col.g*2.0*col.g));}
					
					if(col.b > .5){col.b = col.b * (1.0-(1.0-col.b)*(1.0-2*col.b));}
					else{col.b = 1.0-(1.0-col.b)*(1.0-(col.b*2.0*col.b));}
				#endif
							
				//Hard Light 强光
				#if _OVERLAY2_HARDLIGHT
					if(col.r > .5){col.r = 1.0-(1.0-col.r)*(1-2*col.r);}
					else{col.r = col.r*2*col.r;}
					
					if(col.g > .5){col.g = 1.0-(1.0-col.g)*(1-2*col.g);}
					else{col.g = col.g*2*col.g;}
					
					if(col.b > .5){col.b = 1.0-(1.0-col.b)*(1-2*col.b);}
					else{col.b = col.b*2*col.b;}
				#endif
				
				//Vivid Light 亮光
				#if _OVERLAY2_VIVIDLIGHT
					if(col.r > .5){col.r = 1.0-(1.0-col.r)/(2*(col.r-.5));}
					else{col.r = col.r/(1-2*col.r);}
					
					if(col.g > .5){col.g = 1.0-(1.0-col.g)/(2*(col.g-.5));}
					else{col.g = col.g/(1-2*col.g);}
					
					if(col.b > .5){col.b = 1.0-(1.0-col.b)/(2*(col.b-.5));}
					else{col.b = col.b/(1-2*col.b);}
				#endif			
				
				//Linear Light 线性光
				#if _OVERLAY2_LINEARLIGHT
					if(col.r > .5){col.r = col.r + 2.0*(col.r - .5);}
					else{col.r = col.r + 2 * col.r - 1;}
					
					if(col.g > .5){col.g = col.g + 2.0*(col.g - .5);}
					else{col.g = col.g + 2 * col.g - 1;}
					
					if(col.b > .5){col.b = col.b + 2.0*(col.b - .5);}
					else{col.b = col.b + 2 * col.b - 1;}
				#endif
				
				//Pin Light 点光
				#if _OVERLAY2_PINLIGHT
					if(col.r > .5){col.r = max(col.r,2*(col.r-.5));}
					else{col.r = min(col.r,2*col.r);}
					
					if(col.g > .5){col.g = max(col.g,2*(col.g-.5));}
					else{col.g = min(col.g,2*col.g);}
					
					if(col.b > .5){col.b = max(col.b,2*(col.b-.5));}
					else{col.b = min(col.b,2*col.b);}
				#endif
				
				//Difference 差值	
				#if _OVERLAY2_DIFFERENCE
					col.rgb = abs(col.rgb - col.rgb);
				#endif
				
				//Exclusion 排除	
				#if _OVERLAY2_EXCLUSION
					col.rgb = .5 - 2*(col.rgb - 0.5) * (col.rgb - 0.5);
				#endif

                return col+_TintColor1;
            }
            ENDCG
        }
    }
}
}

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • 113
  • 114
  • 115
  • 116
  • 117
  • 118
  • 119
  • 120
  • 121
  • 122
  • 123
  • 124
  • 125
  • 126
  • 127
  • 128
  • 129
  • 130
  • 131
  • 132
  • 133
  • 134
  • 135
  • 136
  • 137
  • 138
  • 139
  • 140
  • 141
  • 142
  • 143
  • 144
  • 145
  • 146
  • 147
  • 148
  • 149
  • 150
  • 151
  • 152
  • 153
  • 154
  • 155
  • 156
  • 157
  • 158
  • 159
  • 160
  • 161
  • 162
  • 163
  • 164
  • 165
  • 166
  • 167
  • 168
  • 169
  • 170
  • 171
  • 172
  • 173
  • 174
  • 175
  • 176
  • 177
  • 178
  • 179
  • 180
  • 181
  • 182
  • 183
  • 184
  • 185
  • 186
  • 187
  • 188
  • 189
  • 190
  • 191
  • 192
  • 193
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/码创造者/article/detail/760183
推荐阅读
相关标签
  

闽ICP备14008679号