58 lines
1.6 KiB
Plaintext
Raw Normal View History

2026-02-02 15:26:23 +08:00
Shader "Hidden/OIT/WBOITBlend"
2026-01-31 12:25:51 +08:00
{
SubShader
{
ZTest Always Cull Back ZWrite Off Fog { Mode Off }
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
struct v2f
{
float2 uv : TEXCOORD0;
float4 vertex : SV_POSITION;
};
2026-01-31 15:54:25 +08:00
sampler2D _CameraColorTex;
2026-01-31 12:25:51 +08:00
sampler2D _AccumTex;
sampler2D _RevealageTex;
v2f vert (uint vertexID: SV_VertexID)
{
v2f o;
float2 uv = float2((vertexID << 1) & 2, vertexID & 2);
2026-02-05 21:13:37 +08:00
// 如果 ZWrite Off在 gl 下 CCW 逆时针环绕dx 默认 CW 顺时针环绕,需要 uv.xy = uv.yx;
2026-01-31 12:25:51 +08:00
float4 pos = float4(uv * 2.0 - 1.0, UNITY_NEAR_CLIP_VALUE, 1.0);
#ifdef UNITY_PRETRANSFORM_TO_DISPLAY_ORIENTATION
pos = ApplyPretransformRotation(pos);
#endif
#if UNITY_UV_STARTS_AT_TOP
uv = float2((vertexID << 1) & 2, 1.0 - (vertexID & 2));
#endif
o.vertex = pos;
o.uv = uv;
return o;
}
fixed4 frag (v2f i) : SV_Target
{
2026-01-31 15:54:25 +08:00
fixed4 background = tex2D(_CameraColorTex, i.uv);
2026-01-31 12:25:51 +08:00
float4 accum = tex2D(_AccumTex, i.uv);
float r = tex2D(_RevealageTex, i.uv).r;
fixed4 col = float4(accum.rgb / clamp(accum.a, 1e-4, 5e4), r);
return (1.0 - col.a) * col + col.a * background;
}
ENDCG
}
}
}