fx: move tonemap shaders to engine art dir

main
Dominik Madarász 2024-03-27 16:02:28 +01:00
parent cc3eedce9b
commit b94c56ec58
9 changed files with 42 additions and 17 deletions

View File

@ -28,7 +28,7 @@ int main() {
// fx: load all post fx files in all subdirs.
fx_load("fx**.fs");
fx_enable(fx_find("fxAces.fs"), 1);
fx_enable(fx_find("fxTonemapACES.fs"), 1);
// load video, RGB texture, no audio
video_t *v = video( "pexels-pachon-in-motion-17486489.mp4", VIDEO_RGB | VIDEO_NO_AUDIO | VIDEO_LOOP ); video_seek(v, 30);

View File

@ -1,16 +0,0 @@
out vec4 color;
void main(void) {
vec2 uv = TEXCOORD.st;
vec3 src = texture2D(iChannel0, uv).rgb;
vec3 x = src;
// aces film (CC0, src: https://knarkowicz.wordpress.com/2016/01/06/aces-filmic-tone-mapping-curve/)
float a = 2.51f;
float b = 0.03f;
float c = 2.43f;
float d = 0.59f;
float e = 0.14f;
src = clamp((x*(a*x+b))/(x*(c*x+d)+e), 0.0, 1.0);
color = vec4(src, 1.0);
}

View File

@ -0,0 +1,41 @@
// Uchimura 2017, "HDR theory and practice"
// Math: https://www.desmos.com/calculator/gslcdxvipg
// Source: https://www.slideshare.net/nikuque/hdr-theory-and-practicce-jp
vec3 uchimura(vec3 x, float P, float a, float m, float l, float c, float b) {
float l0 = ((P - m) * l) / a;
float L0 = m - m / a;
float L1 = m + (1.0 - m) / a;
float S0 = m + l0;
float S1 = m + a * l0;
float C2 = (a * P) / (P - S1);
float CP = -C2 / P;
vec3 w0 = vec3(1.0 - smoothstep(0.0, m, x));
vec3 w2 = vec3(step(m + l0, x));
vec3 w1 = vec3(1.0 - w0 - w2);
vec3 T = vec3(m * pow(x / m, vec3(c)) + b);
vec3 S = vec3(P - (P - S1) * exp(CP * (x - S0)));
vec3 L = vec3(m + a * (x - m));
return T * w0 + L * w1 + S * w2;
}
vec3 uchimura(vec3 x) {
const float P = 1.0; // max display brightness
const float a = 1.0; // contrast
const float m = 0.22; // linear section start
const float l = 0.4; // linear section length
const float c = 1.33; // black
const float b = 0.0; // pedestal
return uchimura(x, P, a, m, l, c, b);
}
out vec4 color;
void main(void) {
vec2 uv = TEXCOORD.st;
vec4 src = texture2D(iChannel0, uv);
color = vec4( uchimura(src.xyz), src.a);
}