Files
armorpaint/paint/shaders/bloom_upsample_pass.kong
T

66 lines
1.9 KiB
Plaintext
Raw Normal View History

2025-03-29 21:52:27 +01:00
#[set(everything)]
const constants: {
screen_size_inv: float2;
current_mip_level: int;
sample_scale: float;
2025-08-08 22:40:21 +02:00
bloom_strength: float;
2025-03-29 21:52:27 +01:00
};
2025-04-18 09:28:41 +02:00
#[set(everything)]
2025-04-24 22:19:44 +02:00
const sampler_linear: sampler;
2025-04-18 09:28:41 +02:00
#[set(everything)]
2025-04-24 22:19:44 +02:00
const tex: tex2d;
2025-04-18 09:28:41 +02:00
2025-03-29 21:52:27 +01:00
struct vert_in {
pos: float2;
}
struct vert_out {
pos: float4;
tex: float2;
}
fun bloom_upsample_pass_vert(input: vert_in): vert_out {
var output: vert_out;
output.tex = input.pos.xy * 0.5 + 0.5;
output.tex.y = 1.0 - output.tex.y;
output.pos = float4(input.pos.xy, 0.0, 1.0);
return output;
}
2025-05-16 19:05:00 +02:00
fun upsample_dual_filter(tex_coord: float2, texel_size: float2): float3 {
2025-03-29 21:52:27 +01:00
var delta: float2 = texel_size * constants.sample_scale;
var result: float3;
2025-04-19 12:29:49 +02:00
result = sample_lod(tex, sampler_linear, tex_coord + float2(-delta.x * 2.0, 0.0), 0.0).rgb;
result += sample_lod(tex, sampler_linear, tex_coord + float2(-delta.x, delta.y), 0.0).rgb * 2.0;
result += sample_lod(tex, sampler_linear, tex_coord + float2(0.0, delta.y * 2.0), 0.0).rgb;
2025-05-16 19:05:00 +02:00
result += sample_lod(tex, sampler_linear, tex_coord + delta, 0.0).rgb * 2.0;
2025-04-19 12:29:49 +02:00
result += sample_lod(tex, sampler_linear, tex_coord + float2(delta.x * 2.0, 0.0), 0.0).rgb;
result += sample_lod(tex, sampler_linear, tex_coord + float2(delta.x, -delta.y), 0.0).rgb * 2.0;
result += sample_lod(tex, sampler_linear, tex_coord + float2(0.0, -delta.y * 2.0), 0.0).rgb;
2025-05-16 19:05:00 +02:00
result += sample_lod(tex, sampler_linear, tex_coord - delta, 0.0).rgb * 2.0;
2025-03-29 21:52:27 +01:00
return result * (1.0 / 12.0);
}
fun bloom_upsample_pass_frag(input: vert_out): float4 {
var color: float4;
2025-05-16 19:05:00 +02:00
color.rgb = upsample_dual_filter(input.tex, constants.screen_size_inv);
2025-03-29 21:52:27 +01:00
if (constants.current_mip_level == 0) {
2025-08-08 22:40:21 +02:00
color.rgb = color.rgb * float3(constants.bloom_strength, constants.bloom_strength, constants.bloom_strength);
2025-03-29 21:52:27 +01:00
}
color.a = 1.0;
return color;
}
#[pipe]
struct pipe {
vertex = bloom_upsample_pass_vert;
fragment = bloom_upsample_pass_frag;
}