This is an automated email from the git hooks/post-receive script.

smcv pushed a commit to annotated tag 1.42d
in repository iortcw.

commit a1c7583377610767563f1ad32a42e5992b11f832
Author: m4n4t4...@gmail.com 
<m4n4t4...@gmail.com@e65d2741-a53d-b2dc-ae96-bb75fa5e4c4a>
Date:   Sun Nov 2 14:06:10 2014 +0000

    All: Rend2: Speed up tonemap shader
---
 MP/code/rend2/glsl/tonemap_fp.glsl | 43 ++++++++++++++++++--------------------
 MP/code/rend2/glsl/tonemap_vp.glsl | 14 +++++++++++++
 SP/code/rend2/glsl/tonemap_fp.glsl | 43 ++++++++++++++++++--------------------
 SP/code/rend2/glsl/tonemap_vp.glsl | 14 +++++++++++++
 4 files changed, 68 insertions(+), 46 deletions(-)

diff --git a/MP/code/rend2/glsl/tonemap_fp.glsl 
b/MP/code/rend2/glsl/tonemap_fp.glsl
index 4c914ac..1368c5b 100644
--- a/MP/code/rend2/glsl/tonemap_fp.glsl
+++ b/MP/code/rend2/glsl/tonemap_fp.glsl
@@ -3,14 +3,16 @@ uniform sampler2D u_LevelsMap;
 
 uniform vec4      u_Color;
 
+
 uniform vec2      u_AutoExposureMinMax;
 uniform vec3      u_ToneMinAvgMaxLinear;
 
 varying vec2      var_TexCoords;
+varying float     var_InvWhite;
 
 const vec3  LUMINANCE_VECTOR =   vec3(0.2125, 0.7154, 0.0721); //vec3(0.299, 
0.587, 0.114);
 
-vec3 FilmicTonemap(vec3 x)
+float FilmicTonemap(float x)
 {
        const float SS  = 0.22; // Shoulder Strength
        const float LS  = 0.30; // Linear Strength
@@ -18,40 +20,35 @@ vec3 FilmicTonemap(vec3 x)
        const float TS  = 0.20; // Toe Strength
        const float TAN = 0.01; // Toe Angle Numerator
        const float TAD = 0.30; // Toe Angle Denominator
-       
-       vec3 SSxx = SS * x * x;
-       vec3 LSx = LS * x;
-       vec3 LALSx = LSx * LA;
-       
-       return ((SSxx + LALSx + TS * TAN) / (SSxx + LSx + TS * TAD)) - TAN / 
TAD;
-
-       //return ((x*(SS*x+LA*LS)+TS*TAN)/(x*(SS*x+LS)+TS*TAD)) - TAN/TAD;
 
+       return ((x*(SS*x+LA*LS)+TS*TAN)/(x*(SS*x+LS)+TS*TAD)) - TAN/TAD;
 }
 
 void main()
 {
        vec4 color = texture2D(u_TextureMap, var_TexCoords) * u_Color;
 
-  #if defined(r_framebufferGamma)
+#if defined(r_framebufferGamma)
        color.rgb = pow(color.rgb, vec3(r_framebufferGamma));
-  #endif
+#endif
 
        vec3 minAvgMax = texture2D(u_LevelsMap, var_TexCoords).rgb;
        vec3 logMinAvgMaxLum = clamp(minAvgMax * 20.0 - 10.0, 
-u_AutoExposureMinMax.y, -u_AutoExposureMinMax.x);
-               
-       float avgLum = exp2(logMinAvgMaxLum.y);
-       //float maxLum = exp2(logMinAvgMaxLum.z);
 
-       color.rgb *= u_ToneMinAvgMaxLinear.y / avgLum;
-       color.rgb = max(vec3(0.0), color.rgb - vec3(u_ToneMinAvgMaxLinear.x));
+       float invAvgLum = u_ToneMinAvgMaxLinear.y * exp2(-logMinAvgMaxLum.y);
+
+       color.rgb = color.rgb * invAvgLum - u_ToneMinAvgMaxLinear.xxx;
+       color.rgb = max(vec3(0.0), color.rgb);
 
-       vec3 fWhite = 1.0 / FilmicTonemap(vec3(u_ToneMinAvgMaxLinear.z - 
u_ToneMinAvgMaxLinear.x));
-       color.rgb = FilmicTonemap(color.rgb) * fWhite;
-       
-  #if defined(r_tonemapGamma)
+       color.r = FilmicTonemap(color.r);
+       color.g = FilmicTonemap(color.g);
+       color.b = FilmicTonemap(color.b);
+
+       color.rgb = clamp(color.rgb * var_InvWhite, 0.0, 1.0);
+
+#if defined(r_tonemapGamma)
        color.rgb = pow(color.rgb, vec3(1.0 / r_tonemapGamma));
-  #endif
-       
-       gl_FragColor = clamp(color, 0.0, 1.0);
+#endif
+
+       gl_FragColor = color;
 }
diff --git a/MP/code/rend2/glsl/tonemap_vp.glsl 
b/MP/code/rend2/glsl/tonemap_vp.glsl
index bdaa74a..577c0a1 100644
--- a/MP/code/rend2/glsl/tonemap_vp.glsl
+++ b/MP/code/rend2/glsl/tonemap_vp.glsl
@@ -2,12 +2,26 @@ attribute vec3 attr_Position;
 attribute vec4 attr_TexCoord0;
 
 uniform mat4   u_ModelViewProjectionMatrix;
+uniform vec3   u_ToneMinAvgMaxLinear;
 
 varying vec2   var_TexCoords;
+varying float  var_InvWhite;
 
+float FilmicTonemap(float x)
+{
+       const float SS  = 0.22; // Shoulder Strength
+       const float LS  = 0.30; // Linear Strength
+       const float LA  = 0.10; // Linear Angle
+       const float TS  = 0.20; // Toe Strength
+       const float TAN = 0.01; // Toe Angle Numerator
+       const float TAD = 0.30; // Toe Angle Denominator
+
+       return ((x*(SS*x+LA*LS)+TS*TAN)/(x*(SS*x+LS)+TS*TAD)) - TAN/TAD;
+}
 
 void main()
 {
        gl_Position = u_ModelViewProjectionMatrix * vec4(attr_Position, 1.0);
        var_TexCoords = attr_TexCoord0.st;
+       var_InvWhite = 1.0 / FilmicTonemap(u_ToneMinAvgMaxLinear.z - 
u_ToneMinAvgMaxLinear.x);
 }
diff --git a/SP/code/rend2/glsl/tonemap_fp.glsl 
b/SP/code/rend2/glsl/tonemap_fp.glsl
index 4c914ac..1368c5b 100644
--- a/SP/code/rend2/glsl/tonemap_fp.glsl
+++ b/SP/code/rend2/glsl/tonemap_fp.glsl
@@ -3,14 +3,16 @@ uniform sampler2D u_LevelsMap;
 
 uniform vec4      u_Color;
 
+
 uniform vec2      u_AutoExposureMinMax;
 uniform vec3      u_ToneMinAvgMaxLinear;
 
 varying vec2      var_TexCoords;
+varying float     var_InvWhite;
 
 const vec3  LUMINANCE_VECTOR =   vec3(0.2125, 0.7154, 0.0721); //vec3(0.299, 
0.587, 0.114);
 
-vec3 FilmicTonemap(vec3 x)
+float FilmicTonemap(float x)
 {
        const float SS  = 0.22; // Shoulder Strength
        const float LS  = 0.30; // Linear Strength
@@ -18,40 +20,35 @@ vec3 FilmicTonemap(vec3 x)
        const float TS  = 0.20; // Toe Strength
        const float TAN = 0.01; // Toe Angle Numerator
        const float TAD = 0.30; // Toe Angle Denominator
-       
-       vec3 SSxx = SS * x * x;
-       vec3 LSx = LS * x;
-       vec3 LALSx = LSx * LA;
-       
-       return ((SSxx + LALSx + TS * TAN) / (SSxx + LSx + TS * TAD)) - TAN / 
TAD;
-
-       //return ((x*(SS*x+LA*LS)+TS*TAN)/(x*(SS*x+LS)+TS*TAD)) - TAN/TAD;
 
+       return ((x*(SS*x+LA*LS)+TS*TAN)/(x*(SS*x+LS)+TS*TAD)) - TAN/TAD;
 }
 
 void main()
 {
        vec4 color = texture2D(u_TextureMap, var_TexCoords) * u_Color;
 
-  #if defined(r_framebufferGamma)
+#if defined(r_framebufferGamma)
        color.rgb = pow(color.rgb, vec3(r_framebufferGamma));
-  #endif
+#endif
 
        vec3 minAvgMax = texture2D(u_LevelsMap, var_TexCoords).rgb;
        vec3 logMinAvgMaxLum = clamp(minAvgMax * 20.0 - 10.0, 
-u_AutoExposureMinMax.y, -u_AutoExposureMinMax.x);
-               
-       float avgLum = exp2(logMinAvgMaxLum.y);
-       //float maxLum = exp2(logMinAvgMaxLum.z);
 
-       color.rgb *= u_ToneMinAvgMaxLinear.y / avgLum;
-       color.rgb = max(vec3(0.0), color.rgb - vec3(u_ToneMinAvgMaxLinear.x));
+       float invAvgLum = u_ToneMinAvgMaxLinear.y * exp2(-logMinAvgMaxLum.y);
+
+       color.rgb = color.rgb * invAvgLum - u_ToneMinAvgMaxLinear.xxx;
+       color.rgb = max(vec3(0.0), color.rgb);
 
-       vec3 fWhite = 1.0 / FilmicTonemap(vec3(u_ToneMinAvgMaxLinear.z - 
u_ToneMinAvgMaxLinear.x));
-       color.rgb = FilmicTonemap(color.rgb) * fWhite;
-       
-  #if defined(r_tonemapGamma)
+       color.r = FilmicTonemap(color.r);
+       color.g = FilmicTonemap(color.g);
+       color.b = FilmicTonemap(color.b);
+
+       color.rgb = clamp(color.rgb * var_InvWhite, 0.0, 1.0);
+
+#if defined(r_tonemapGamma)
        color.rgb = pow(color.rgb, vec3(1.0 / r_tonemapGamma));
-  #endif
-       
-       gl_FragColor = clamp(color, 0.0, 1.0);
+#endif
+
+       gl_FragColor = color;
 }
diff --git a/SP/code/rend2/glsl/tonemap_vp.glsl 
b/SP/code/rend2/glsl/tonemap_vp.glsl
index bdaa74a..577c0a1 100644
--- a/SP/code/rend2/glsl/tonemap_vp.glsl
+++ b/SP/code/rend2/glsl/tonemap_vp.glsl
@@ -2,12 +2,26 @@ attribute vec3 attr_Position;
 attribute vec4 attr_TexCoord0;
 
 uniform mat4   u_ModelViewProjectionMatrix;
+uniform vec3   u_ToneMinAvgMaxLinear;
 
 varying vec2   var_TexCoords;
+varying float  var_InvWhite;
 
+float FilmicTonemap(float x)
+{
+       const float SS  = 0.22; // Shoulder Strength
+       const float LS  = 0.30; // Linear Strength
+       const float LA  = 0.10; // Linear Angle
+       const float TS  = 0.20; // Toe Strength
+       const float TAN = 0.01; // Toe Angle Numerator
+       const float TAD = 0.30; // Toe Angle Denominator
+
+       return ((x*(SS*x+LA*LS)+TS*TAN)/(x*(SS*x+LS)+TS*TAD)) - TAN/TAD;
+}
 
 void main()
 {
        gl_Position = u_ModelViewProjectionMatrix * vec4(attr_Position, 1.0);
        var_TexCoords = attr_TexCoord0.st;
+       var_InvWhite = 1.0 / FilmicTonemap(u_ToneMinAvgMaxLinear.z - 
u_ToneMinAvgMaxLinear.x);
 }

-- 
Alioth's /usr/local/bin/git-commit-notice on 
/srv/git.debian.org/git/pkg-games/iortcw.git

_______________________________________________
Pkg-games-commits mailing list
Pkg-games-commits@lists.alioth.debian.org
http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/pkg-games-commits

Reply via email to