|
@@ -144,6 +144,38 @@ vec4 texture2D_bicubic(sampler2D tex, vec2 uv,int p_lod)
|
|
|
#endif
|
|
|
|
|
|
|
|
|
+vec3 tonemap_filmic(vec3 color,float white) {
|
|
|
+
|
|
|
+ float A = 0.15;
|
|
|
+ float B = 0.50;
|
|
|
+ float C = 0.10;
|
|
|
+ float D = 0.20;
|
|
|
+ float E = 0.02;
|
|
|
+ float F = 0.30;
|
|
|
+ float W = 11.2;
|
|
|
+
|
|
|
+ vec3 coltn = ((color*(A*color+C*B)+D*E)/(color*(A*color+B)+D*F))-E/F;
|
|
|
+ float whitetn = ((white*(A*white+C*B)+D*E)/(white*(A*white+B)+D*F))-E/F;
|
|
|
+
|
|
|
+ return coltn/whitetn;
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+vec3 tonemap_aces(vec3 color) {
|
|
|
+ float a = 2.51f;
|
|
|
+ float b = 0.03f;
|
|
|
+ float c = 2.43f;
|
|
|
+ float d = 0.59f;
|
|
|
+ float e = 0.14f;
|
|
|
+ return color = clamp((color*(a*color+b))/(color*(c*color+d)+e),vec3(0.0),vec3(1.0));
|
|
|
+}
|
|
|
+
|
|
|
+vec3 tonemap_reindhart(vec3 color,vec3 white) {
|
|
|
+
|
|
|
+ return ( color * ( 1.0 + ( color / ( white) ) ) ) / ( 1.0 + color );
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
void main() {
|
|
|
|
|
|
ivec2 coord = ivec2(gl_FragCoord.xy);
|
|
@@ -157,8 +189,11 @@ void main() {
|
|
|
|
|
|
color*=exposure;
|
|
|
|
|
|
-
|
|
|
#if defined(USE_GLOW_LEVEL1) || defined(USE_GLOW_LEVEL2) || defined(USE_GLOW_LEVEL3) || defined(USE_GLOW_LEVEL4) || defined(USE_GLOW_LEVEL5) || defined(USE_GLOW_LEVEL6) || defined(USE_GLOW_LEVEL7)
|
|
|
+#define USING_GLOW
|
|
|
+#endif
|
|
|
+
|
|
|
+#if defined(USING_GLOW)
|
|
|
vec3 glow = vec3(0.0);
|
|
|
|
|
|
#ifdef USE_GLOW_LEVEL1
|
|
@@ -193,85 +228,83 @@ void main() {
|
|
|
|
|
|
glow *= glow_intensity;
|
|
|
|
|
|
+#endif
|
|
|
|
|
|
|
|
|
-#ifdef USE_GLOW_REPLACE
|
|
|
+#ifdef USE_REINDHART_TONEMAPPER
|
|
|
|
|
|
- color.rgb = glow;
|
|
|
+ color.rgb = tonemap_reindhart(color.rgb,white);
|
|
|
+
|
|
|
+# if defined(USING_GLOW)
|
|
|
+ glow = tonemap_reindhart(glow,white);
|
|
|
+# endif
|
|
|
|
|
|
#endif
|
|
|
|
|
|
-#ifdef USE_GLOW_SCREEN
|
|
|
+#ifdef USE_FILMIC_TONEMAPPER
|
|
|
|
|
|
- color.rgb = clamp((color.rgb + glow) - (color.rgb * glow), 0.0, 1.0);
|
|
|
+ color.rgb = tonemap_filmic(color.rgb,white);
|
|
|
+
|
|
|
+# if defined(USING_GLOW)
|
|
|
+ glow = tonemap_filmic(glow,white);
|
|
|
+# endif
|
|
|
|
|
|
#endif
|
|
|
|
|
|
-#ifdef USE_GLOW_SOFTLIGHT
|
|
|
+#ifdef USE_ACES_TONEMAPPER
|
|
|
|
|
|
- {
|
|
|
+ color.rgb = tonemap_aces(color.rgb);
|
|
|
|
|
|
- glow = (glow * 0.5) + 0.5;
|
|
|
- color.r = (glow.r <= 0.5) ? (color.r - (1.0 - 2.0 * glow.r) * color.r * (1.0 - color.r)) : (((glow.r > 0.5) && (color.r <= 0.25)) ? (color.r + (2.0 * glow.r - 1.0) * (4.0 * color.r * (4.0 * color.r + 1.0) * (color.r - 1.0) + 7.0 * color.r)) : (color.r + (2.0 * glow.r - 1.0) * (sqrt(color.r) - color.r)));
|
|
|
- color.g = (glow.g <= 0.5) ? (color.g - (1.0 - 2.0 * glow.g) * color.g * (1.0 - color.g)) : (((glow.g > 0.5) && (color.g <= 0.25)) ? (color.g + (2.0 * glow.g - 1.0) * (4.0 * color.g * (4.0 * color.g + 1.0) * (color.g - 1.0) + 7.0 * color.g)) : (color.g + (2.0 * glow.g - 1.0) * (sqrt(color.g) - color.g)));
|
|
|
- color.b = (glow.b <= 0.5) ? (color.b - (1.0 - 2.0 * glow.b) * color.b * (1.0 - color.b)) : (((glow.b > 0.5) && (color.b <= 0.25)) ? (color.b + (2.0 * glow.b - 1.0) * (4.0 * color.b * (4.0 * color.b + 1.0) * (color.b - 1.0) + 7.0 * color.b)) : (color.b + (2.0 * glow.b - 1.0) * (sqrt(color.b) - color.b)));
|
|
|
- }
|
|
|
+# if defined(USING_GLOW)
|
|
|
+ glow = tonemap_aces(glow);
|
|
|
+# endif
|
|
|
|
|
|
#endif
|
|
|
|
|
|
-#if !defined(USE_GLOW_SCREEN) && !defined(USE_GLOW_SOFTLIGHT) && !defined(USE_GLOW_REPLACE)
|
|
|
- color.rgb+=glow;
|
|
|
-#endif
|
|
|
-
|
|
|
+ //regular Linear -> SRGB conversion
|
|
|
+ vec3 a = vec3(0.055);
|
|
|
+ color.rgb = mix( (vec3(1.0)+a)*pow(color.rgb,vec3(1.0/2.4))-a , 12.92*color.rgb , lessThan(color.rgb,vec3(0.0031308)));
|
|
|
|
|
|
+#if defined(USING_GLOW)
|
|
|
+ glow = mix( (vec3(1.0)+a)*pow(glow,vec3(1.0/2.4))-a , 12.92*glow , lessThan(glow,vec3(0.0031308)));
|
|
|
#endif
|
|
|
|
|
|
+//glow needs to be added in SRGB space (together with image space effects)
|
|
|
|
|
|
-#ifdef USE_REINDHART_TONEMAPPER
|
|
|
+ color.rgb = clamp(color.rgb,0.0,1.0);
|
|
|
|
|
|
- {
|
|
|
- color.rgb = ( color.rgb * ( 1.0 + ( color.rgb / ( white) ) ) ) / ( 1.0 + color.rgb );
|
|
|
-
|
|
|
- }
|
|
|
+#if defined(USING_GLOW)
|
|
|
+ glow = clamp(glow,0.0,1.0);
|
|
|
#endif
|
|
|
|
|
|
-#ifdef USE_FILMIC_TONEMAPPER
|
|
|
+#ifdef USE_GLOW_REPLACE
|
|
|
|
|
|
- {
|
|
|
+ color.rgb = glow;
|
|
|
|
|
|
- float A = 0.15;
|
|
|
- float B = 0.50;
|
|
|
- float C = 0.10;
|
|
|
- float D = 0.20;
|
|
|
- float E = 0.02;
|
|
|
- float F = 0.30;
|
|
|
- float W = 11.2;
|
|
|
+#endif
|
|
|
|
|
|
- vec3 coltn = ((color.rgb*(A*color.rgb+C*B)+D*E)/(color.rgb*(A*color.rgb+B)+D*F))-E/F;
|
|
|
- float whitetn = ((white*(A*white+C*B)+D*E)/(white*(A*white+B)+D*F))-E/F;
|
|
|
+#ifdef USE_GLOW_SCREEN
|
|
|
|
|
|
- color.rgb=coltn/whitetn;
|
|
|
+ color.rgb = max((color.rgb + glow) - (color.rgb * glow), vec3(0.0));
|
|
|
|
|
|
- }
|
|
|
#endif
|
|
|
|
|
|
-#ifdef USE_ACES_TONEMAPPER
|
|
|
+#ifdef USE_GLOW_SOFTLIGHT
|
|
|
|
|
|
{
|
|
|
- float a = 2.51f;
|
|
|
- float b = 0.03f;
|
|
|
- float c = 2.43f;
|
|
|
- float d = 0.59f;
|
|
|
- float e = 0.14f;
|
|
|
- color.rgb = clamp((color.rgb*(a*color.rgb+b))/(color.rgb*(c*color.rgb+d)+e),vec3(0.0),vec3(1.0));
|
|
|
+
|
|
|
+ glow = (glow * 0.5) + 0.5;
|
|
|
+ color.r = (glow.r <= 0.5) ? (color.r - (1.0 - 2.0 * glow.r) * color.r * (1.0 - color.r)) : (((glow.r > 0.5) && (color.r <= 0.25)) ? (color.r + (2.0 * glow.r - 1.0) * (4.0 * color.r * (4.0 * color.r + 1.0) * (color.r - 1.0) + 7.0 * color.r)) : (color.r + (2.0 * glow.r - 1.0) * (sqrt(color.r) - color.r)));
|
|
|
+ color.g = (glow.g <= 0.5) ? (color.g - (1.0 - 2.0 * glow.g) * color.g * (1.0 - color.g)) : (((glow.g > 0.5) && (color.g <= 0.25)) ? (color.g + (2.0 * glow.g - 1.0) * (4.0 * color.g * (4.0 * color.g + 1.0) * (color.g - 1.0) + 7.0 * color.g)) : (color.g + (2.0 * glow.g - 1.0) * (sqrt(color.g) - color.g)));
|
|
|
+ color.b = (glow.b <= 0.5) ? (color.b - (1.0 - 2.0 * glow.b) * color.b * (1.0 - color.b)) : (((glow.b > 0.5) && (color.b <= 0.25)) ? (color.b + (2.0 * glow.b - 1.0) * (4.0 * color.b * (4.0 * color.b + 1.0) * (color.b - 1.0) + 7.0 * color.b)) : (color.b + (2.0 * glow.b - 1.0) * (sqrt(color.b) - color.b)));
|
|
|
}
|
|
|
|
|
|
#endif
|
|
|
|
|
|
- //regular Linear -> SRGB conversion
|
|
|
- vec3 a = vec3(0.055);
|
|
|
- color.rgb = mix( (vec3(1.0)+a)*pow(color.rgb,vec3(1.0/2.4))-a , 12.92*color.rgb , lessThan(color.rgb,vec3(0.0031308)));
|
|
|
-
|
|
|
+#if defined(USING_GLOW) && !defined(USE_GLOW_SCREEN) && !defined(USE_GLOW_SOFTLIGHT) && !defined(USE_GLOW_REPLACE)
|
|
|
+ //additive
|
|
|
+ color.rgb+=glow;
|
|
|
+#endif
|
|
|
|
|
|
#ifdef USE_BCS
|
|
|
|