Files
test/Assets/ModelRenderer/Art/Shaders/Hidden/Custom/BloomBlur.shader
T
2025-12-15 00:12:16 +07:00

111 lines
4.1 KiB
Plaintext

Shader "Hidden/Custom/BloomBlur"
{
Properties
{
_MainTex("Source", 2D) = "white" {}
_Weights("Weights (w2,w1,w0)", Vector) = (0.2,0.4,0.8,0)
_Direction("Direction", Vector) = (1,0,0,0)
_Radius("Radius", Float) = 1.0
_Threshold("Threshold", Float) = 1.0
_Intensity("Intensity", Float) = 1.0
}
SubShader
{
Tags { "RenderType" = "Opaque" "Queue" = "Overlay" }
Cull Off ZWrite Off ZTest Always
Pass
{
Name "Extract"
HLSLPROGRAM
#pragma vertex VertDefault
#pragma fragment FragExtract
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
TEXTURE2D(_MainTex); SAMPLER(sampler_MainTex);
float4 _Weights;
float4 _Direction;
float _Radius;
float _Threshold;
float _Intensity;
struct Attributes { float4 positionOS : POSITION; float2 uv : TEXCOORD0; };
struct Varyings { float4 positionH : SV_POSITION; float2 uv : TEXCOORD0; };
Varyings VertDefault(Attributes IN)
{
Varyings OUT;
OUT.positionH = TransformObjectToHClip(IN.positionOS);
OUT.uv = IN.uv;
return OUT;
}
float Luminance(float3 c) { return dot(c, float3(0.2126, 0.7152, 0.0722)); }
float4 FragExtract(Varyings IN) : SV_Target
{
float3 col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, IN.uv).rgb;
// simple threshold: keep brightness above threshold
float lum = dot(col, float3(0.2126, 0.7152, 0.0722));
float keep = saturate((lum - _Threshold) / max(0.0001, (1.0 - _Threshold)));
return float4(col * keep, 1.0);
}
ENDHLSL
}
Pass
{
Name "5TapBlur"
HLSLPROGRAM
#pragma vertex VertDefault
#pragma fragment FragBlur
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
TEXTURE2D(_MainTex); SAMPLER(sampler_MainTex);
float4 _Weights;
float4 _Direction;
float _Radius;
float _Threshold;
float _Intensity;
struct Attributes { float4 positionOS : POSITION; float2 uv : TEXCOORD0; };
struct Varyings { float4 positionH : SV_POSITION; float2 uv : TEXCOORD0; };
Varyings VertDefault(Attributes IN)
{
Varyings OUT;
OUT.positionH = TransformObjectToHClip(IN.positionOS);
OUT.uv = IN.uv;
return OUT;
}
float4 FragBlur(Varyings IN) : SV_Target
{
// texel size (in UV units)
float2 texel = _ScreenParams.zw; // z = 1/width, w = 1/height
float2 dir = _Direction.xy;
float2 off0 = IN.uv + dir * texel * (_Radius * -2.0);
float2 off1 = IN.uv + dir * texel * (_Radius * -1.0);
float2 off2 = IN.uv + dir * texel * (_Radius * 0.0);
float2 off3 = IN.uv + dir * texel * (_Radius * 1.0);
float2 off4 = IN.uv + dir * texel * (_Radius * 2.0);
float3 s0 = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, off0).rgb;
float3 s1 = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, off1).rgb;
float3 s2 = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, off2).rgb;
float3 s3 = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, off3).rgb;
float3 s4 = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, off4).rgb;
// weights: _Weights = (w2, w1, w0, 0) -> taps: w2,w1,w0,w1,w2
float3 accum = s0 * _Weights.x + s1 * _Weights.y + s2 * _Weights.z + s3 * _Weights.y + s4 * _Weights.x;
return float4(accum * _Intensity, 1.0);
}
ENDHLSL
}
}
}