diff options
| author | quou <quou@disroot.org> | 2025-01-18 17:35:27 +1100 | 
|---|---|---|
| committer | quou <quou@disroot.org> | 2025-01-18 17:35:27 +1100 | 
| commit | 7b6bda1188cf80ffc85b16e099d7811c92dbd7ac (patch) | |
| tree | 4e27a5a59c7a3d20de9dd15167b2c706aca4a090 /intermediate | |
| parent | b2392cf01e6fd0c15bc52941177fbe4b8a5d1a69 (diff) | |
tonemap
Diffstat (limited to 'intermediate')
| -rw-r--r-- | intermediate/tonemap.glsl | 85 | 
1 files changed, 85 insertions, 0 deletions
| 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 + |