Standard shader: Add tonemapping;
ACES.
@@ -141,6 +141,7 @@ const char* lovrStandardFragmentShader = ""
"uniform samplerCube lovrSpecularIrradianceTexture; \n"
"uniform vec3 lovrIrradiance[9]; \n"
"uniform vec3 lovrLightDirection = vec3(-1., -1., -1.); \n"
+"uniform float lovrExposure = 1.; \n"
""
"float D_GGX(float NoH, float roughness) { \n"
" float alpha = roughness * roughness; \n"
@@ -176,6 +177,15 @@ const char* lovrStandardFragmentShader = ""
", 0.); \n"
"} \n"
""
+"vec3 tonemap_ACES(vec3 color) { \n"
+" float a = 2.51; \n"
+" float b = 0.03; \n"
+" float c = 2.43; \n"
+" float d = 0.59; \n"
+" float e = 0.14; \n"
+" return (color * (a * color + b)) / (color * (c * color + d) + e); \n"
+"} \n"
+""
"vec4 color(vec4 graphicsColor, sampler2D image, vec2 uv) { \n"
" vec3 normal = vTangentMatrix * (texture(lovrNormalTexture, uv).rgb * 2. - 1.); \n"
" vec3 baseColor = texture(lovrDiffuseTexture, uv).rgb * lovrDiffuseColor.rgb; \n"
@@ -209,7 +219,10 @@ const char* lovrStandardFragmentShader = ""
" vec3 diffuseIndirect = diffuseDirect * E_SphericalHarmonics(lovrIrradiance, N); \n"
" vec3 indirect = diffuseIndirect + specularIndirect; \n"
""
-" return vec4(direct + indirect + emissive, 1.); \n"
+" vec3 color = direct + indirect + emissive; \n"
+" color = tonemap_ACES(color * lovrExposure); \n"
+""
+" return vec4(color, 1.); \n"
"}";
const char* lovrCubeVertexShader = ""
