Skip to content

Commit

Permalink
Add basic tonemapping
Browse files Browse the repository at this point in the history
After some experimentation for now go with the tried-and-true filmic
option. Needed to tweak the lighting a little bit for that, and also fix
the specular that was not taking sun intensity into account.
  • Loading branch information
zeux committed Jan 8, 2025
1 parent a538e16 commit 08294ca
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/shaders/final.comp.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,12 @@ void main()
if (shadeData.shadowsEnabled == 1)
shadow = texture(shadowImage, uv).r;

float ambient = 0.03;
float shadowAmbient = 0.03;
float sunIntensity = 1.5;
float ambient = 0.07;
float shadowAmbient = 0.05;
float sunIntensity = 2.5;

vec3 outputColor = albedo.rgb * (ndotl * min(shadow + shadowAmbient, 1.0) * sunIntensity + ambient) + vec3(specular * shadow) + emissive;
vec3 outputColor = albedo.rgb * (ndotl * min(shadow + shadowAmbient, 1.0) * sunIntensity + ambient) + vec3(specular * shadow) * sunIntensity + emissive;

float deband = gradientNoise(vec2(pos)) * 2 - 1;
imageStore(outImage, ivec2(pos), vec4(tosrgb(outputColor) + deband * (0.5 / 255), 1.0));
imageStore(outImage, ivec2(pos), vec4(tonemap(outputColor) + deband * (0.5 / 255), 1.0));
}
8 changes: 8 additions & 0 deletions src/shaders/math.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,14 @@ vec4 fromsrgb(vec4 c)
return vec4(pow(c.xyz, vec3(2.2)), c.w);
}

// Optimized filmic operator by Jim Hejl and Richard Burgess-Dawson
// http://filmicworlds.com/blog/filmic-tonemapping-operators/
vec3 tonemap(vec3 c)
{
vec3 x = max(vec3(0), c - 0.004);
return (x * (6.2 * x + .5)) / (x * (6.2 * x + 1.7) + 0.06);
}

// Gradient noise from Jorge Jimenez's presentation:
// http://www.iryoku.com/next-generation-post-processing-in-call-of-duty-advanced-warfare
float gradientNoise(vec2 uv)
Expand Down

0 comments on commit 08294ca

Please sign in to comment.