67 lines
1.9 KiB
Plaintext
67 lines
1.9 KiB
Plaintext
// Shaders/AdvancedBlend.shader
|
|
Shader "Custom/AdvancedBlend" {
|
|
Properties {
|
|
_MainTex ("Base (RGB)", 2D) = "white" {}
|
|
_BlendTex ("Blend Texture", 2D) = "white" {}
|
|
_Position ("Blend Position", Vector) = (0,0,0,0)
|
|
_BlendMode ("Blend Mode", Float) = 0
|
|
}
|
|
|
|
SubShader {
|
|
Tags { "RenderType"="Opaque" }
|
|
LOD 100
|
|
|
|
Pass {
|
|
CGPROGRAM
|
|
#pragma vertex vert
|
|
#pragma fragment frag
|
|
#include "UnityCG.cginc"
|
|
|
|
struct appdata {
|
|
float4 vertex : POSITION;
|
|
float2 uv : TEXCOORD0;
|
|
};
|
|
|
|
struct v2f {
|
|
float2 uv : TEXCOORD0;
|
|
float4 vertex : SV_POSITION;
|
|
};
|
|
|
|
sampler2D _MainTex;
|
|
sampler2D _BlendTex;
|
|
float2 _Position;
|
|
float _BlendMode;
|
|
|
|
v2f vert (appdata v) {
|
|
v2f o;
|
|
o.vertex = UnityObjectToClipPos(v.vertex);
|
|
o.uv = v.uv;
|
|
return o;
|
|
}
|
|
|
|
fixed4 frag (v2f i) : SV_Target {
|
|
fixed4 base = tex2D(_MainTex, i.uv);
|
|
|
|
// 计算混合纹理坐标
|
|
float2 blendUV = i.uv - _Position / _ScreenParams.xy;
|
|
if (any(blendUV < 0) || any(blendUV > 1))
|
|
return base;
|
|
|
|
fixed4 blend = tex2D(_BlendTex, blendUV);
|
|
|
|
// 混合模式选择
|
|
switch ((int)_BlendMode) {
|
|
case 0: // Alpha Blend
|
|
return lerp(base, blend, blend.a);
|
|
case 1: // Multiply
|
|
return base * blend;
|
|
case 2: // Screen
|
|
return 1 - (1 - base) * (1 - blend);
|
|
default:
|
|
return base;
|
|
}
|
|
}
|
|
ENDCG
|
|
}
|
|
}
|
|
} |