Files
armorpaint/base/shaders/compositor_pass.kong
T

68 lines
1.8 KiB
Plaintext
Raw Normal View History

2025-03-29 21:52:27 +01:00
2025-04-18 09:28:41 +02:00
#[set(everything)]
const constants: {
vignette_strength: float;
grain_strength: float;
};
2025-04-24 22:19:44 +02:00
#[set(everything)]
const sampler_linear: sampler;
2025-03-29 21:52:27 +01:00
#[set(everything)]
const tex: tex2d;
// #[set(everything)]
// const histogram: tex2d;
struct vert_in {
pos: float2;
}
struct vert_out {
pos: float4;
tex: float2;
}
fun compositor_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;
}
fun tonemap_filmic(color: float3): float3 {
// Based on Filmic Tonemapping Operators http://filmicgames.com/archives/75
// var x: float3 = max(float3(0.0, 0.0, 0.0), color - 0.004);
var x: float3;
2025-04-16 20:18:38 +02:00
x.x = max(0.0, color.x - 0.004);
x.y = max(0.0, color.y - 0.004);
x.z = max(0.0, color.z - 0.004);
2025-05-16 19:05:00 +02:00
return (x * (x * 6.2 + 0.5)) / (x * (x * 6.2 + 1.7) + 0.06);
2025-03-29 21:52:27 +01:00
}
fun compositor_pass_frag(input: vert_out): float4 {
2025-04-19 12:29:49 +02:00
var color: float4 = sample_lod(tex, sampler_linear, input.tex, 0.0);
2025-03-29 21:52:27 +01:00
// Static grain
var x: float = (input.tex.x + 4.0) * (input.tex.y + 4.0) * 10.0;
var g: float = (((x % 13.0) + 1.0) * ((x % 123.0) + 1.0) % 0.01) - 0.005;
2025-05-16 19:05:00 +02:00
color.rgb = color.rgb + (float3(g, g, g) * constants.grain_strength);
2025-03-29 21:52:27 +01:00
2025-05-16 19:05:00 +02:00
color.rgb = color.rgb * ((1.0 - constants.vignette_strength) + constants.vignette_strength * pow(16.0 * input.tex.x * input.tex.y * (1.0 - input.tex.x) * (1.0 - input.tex.y), 0.2));
2025-03-29 21:52:27 +01:00
// Auto exposure
2025-05-16 19:05:00 +02:00
// const auto_exposure_strength: float = 1.0;
// var expo: float = 2.0 - clamp(length(sample_lod(histogram, sampler_linear, float2(0.5, 0.5), 0.0).rgb), 0.0, 1.0);
2025-03-29 21:52:27 +01:00
// color.rgb *= pow(expo, auto_exposure_strength * 2.0);
color.rgb = tonemap_filmic(color.rgb); // With gamma
return color;
}
#[pipe]
struct pipe {
vertex = compositor_pass_vert;
fragment = compositor_pass_frag;
}