From 7b6bda1188cf80ffc85b16e099d7811c92dbd7ac Mon Sep 17 00:00:00 2001 From: quou Date: Sat, 18 Jan 2025 17:35:27 +1100 Subject: tonemap --- intermediate/tonemap.glsl | 85 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 intermediate/tonemap.glsl (limited to 'intermediate') diff --git a/intermediate/tonemap.glsl b/intermediate/tonemap.glsl new file mode 100644 index 0000000..5c41a6e --- /dev/null +++ b/intermediate/tonemap.glsl @@ -0,0 +1,85 @@ +#ifdef DESC +[program] +type: graphics +vertex: main +fragment: main + +[binding] +name: verts +rate: vertex +[attribute] +name: position +type: vec2 +[attribute] +name: uv +type: vec2 + +[interpolator] +name: uv +type: vec2 + +[struct] +name: Config +[variable] +name: exposure +type: float + +[cbuffer] +name: config +type: Config +stage: fragment + +[texture] +name: src +stage: fragment +dimension: 2 + +[target] +name: colour +type: vec4 +#endif + +#ifdef VERTEX_SHADER +void main() { + interpolator.uv = uv; + gl_Position = vec4(position, 1.0, 1.0); +} +#endif + +#ifdef FRAGMENT_SHADER + +vec3 to_srgb(vec3 lin) { + bvec3 cutoff = lessThan(lin, 0.0031308.xxx); + vec3 higher = 1.055.xxx * pow(lin, vec3(1.0 / 2.4)) - 0.055.xxx; + vec3 lower = lin.rgb * 12.92.xxx; + return mix(higher, lower, cutoff); +} + +vec3 aces(vec3 x) { + float a = 2.51; + float b = 0.03; + float c = 2.43; + float d = 0.59; + float e = 0.14; + return clamp( + (x * (a * x + b)) / (x * (c * x + d) + e), + 0.0, + 1.0f + ); +} + +vec3 hejl(vec3 x, float whitepoint) { + vec4 vh = vec4(x, whitepoint); + vec4 va = (1.425 * vh) + 0.05; + vec4 vf = ((vh * va + 0.004f) / ((vh * (va + 0.55f) + 0.0491f))) - 0.0821f; + return vf.rgb / vf.www; +} + +void main() { + vec2 uv = interpolator.uv; + vec3 lin = texture(src, uv).rgb * config.exposure; + lin = hejl(lin, 1.0); + colour = vec4(to_srgb(lin), 1.0); +} +#endif + -- cgit v1.2.3-54-g00ecf