Files
Kepler/shaders/tonemap.shader

70 lines
1.3 KiB
Plaintext
Raw Permalink Normal View History

2025-11-17 17:18:43 +01:00
/**
* Kepler - Core
* Copyright (c) 2010 kaj dijkstra STUDIOS
* All rights reserved.
*/
/**
* Author: Kaj Dijksta
*/
attribute vec3 position;
attribute vec2 uv;
uniform mat4 viewProjection;
varying vec2 v_textureCoord;
void main(void) {
v_textureCoord = uv;
gl_Position = viewProjection * vec4(position, 1.0);
}
// #keplerEngine - Split
precision highp float;
uniform sampler2D colorSampler;
uniform float exposure;
varying vec2 v_textureCoord;
vec3 HDR_ACES(const vec3 x) {
// Narkowicz 2015, "ACES Filmic Tone Mapping Curve"
const float a = 2.51;
const float b = 0.03;
const float c = 2.43;
const float d = 0.59;
const float e = 0.14;
return (x * (a * x + b)) / (x * (c * x + d) + e);
}
vec3 tonemap(const vec3 x) {
return HDR_ACES(x);
}
float linearToSRGB(float c) {
return (c <= 0.0031308) ? c * 12.92 : (pow(abs(c), 1.0 / 2.4) * 1.055) - 0.055;
}
vec3 linearToSRGB(vec3 c) {
return vec3(linearToSRGB(c.r), linearToSRGB(c.g), linearToSRGB(c.b));
}
void main() {
vec3 pbr = texture2D( colorSampler, v_textureCoord ).rgb;
gl_FragColor = vec4( pbr , 1.0 );
//pbr.rgb *= exposure;
//if(v_textureCoord.x < 0.5) {
// gl_FragColor = vec4( linearToSRGB( tonemap(pbr) ), 1.0 );
//} else {
// gl_FragColor = vec4(
//}
}