Optimize shaders code. Add settings at compile time.
authorRealBadAngel <mk@realbadangel.pl>
Mon, 9 Dec 2013 12:25:43 +0000 (13:25 +0100)
committerRealBadAngel <mk@realbadangel.pl>
Mon, 9 Dec 2013 12:28:50 +0000 (13:28 +0100)
13 files changed:
client/shaders/alpha_shader/opengl_fragment.glsl
client/shaders/alpha_shader/opengl_vertex.glsl
client/shaders/leaves_shader/opengl_fragment.glsl
client/shaders/leaves_shader/opengl_vertex.glsl
client/shaders/liquids_shader/opengl_fragment.glsl
client/shaders/liquids_shader/opengl_vertex.glsl
client/shaders/plants_shader/opengl_fragment.glsl
client/shaders/plants_shader/opengl_vertex.glsl
client/shaders/solids_shader/opengl_fragment.glsl
client/shaders/solids_shader/opengl_vertex.glsl
src/game.cpp
src/mapblock_mesh.cpp
src/shader.cpp

index 3c0f35eaec9a68d95dd4572840e4bb8bbb6701fd..6ed00be251008215429b2bc48a617912e1f8e382 100644 (file)
@@ -1,45 +1,44 @@
-#version 120\r
-\r
 uniform sampler2D baseTexture;\r
 uniform sampler2D normalTexture;\r
 uniform sampler2D useNormalmap;\r
 \r
-uniform float enableBumpmapping;\r
-uniform float enableParallaxOcclusion;\r
-uniform float parallaxOcclusionScale;\r
-uniform float parallaxOcclusionBias;\r
-\r
-\r
 uniform vec4 skyBgColor;\r
 uniform float fogDistance;\r
+uniform vec3 eyePosition;\r
 \r
 varying vec3 vPosition;\r
-varying vec3 tsEyeVec;\r
 varying vec3 eyeVec;\r
 \r
+#ifdef ENABLE_PARALLAX_OCCLUSION\r
+varying vec3 tsEyeVec;\r
+#endif\r
+\r
 const float e = 2.718281828459;\r
 \r
 void main (void)\r
 {\r
        vec3 color;\r
        vec2 uv = gl_TexCoord[0].st;\r
-       \r
-#ifdef NORMALS\r
+\r
+#ifdef USE_NORMALMAPS\r
+       float use_normalmap = texture2D(useNormalmap,vec2(1.0,1.0)).r;\r
+#endif\r
+\r
+#ifdef ENABLE_PARALLAX_OCCLUSION\r
        float height;\r
        vec2 tsEye = vec2(tsEyeVec.x,-tsEyeVec.y);\r
-       \r
-       float use_normalmap = texture2D(useNormalmap,vec2(1.0,1.0)).r;\r
-       float enable_bumpmapping = enableBumpmapping;\r
-       \r
-       if ((enableParallaxOcclusion == 1.0) && (use_normalmap > 0.0)) {\r
+\r
+       if (use_normalmap > 0.0) {\r
                float map_height = texture2D(normalTexture, uv).a;\r
                        if (map_height < 1.0){\r
-                               float height = parallaxOcclusionScale * map_height - parallaxOcclusionBias;\r
+                               float height = PARALLAX_OCCLUSION_SCALE * map_height - PARALLAX_OCCLUSION_BIAS;\r
                                uv = uv + height * tsEye;\r
                        }\r
        }\r
+#endif\r
 \r
-       if ((enable_bumpmapping == 1.0) && (use_normalmap > 0.0)) {\r
+#ifdef ENABLE_BUMPMAPPING\r
+       if (use_normalmap > 0.0) {\r
                vec3 base = texture2D(baseTexture, uv).rgb;\r
                vec3 vVec = normalize(eyeVec);\r
                vec3 bump = normalize(texture2D(normalTexture, uv).xyz * 2.0 - 1.0);\r
@@ -68,5 +67,5 @@ void main (void)
                float d = max(0.0, min(vPosition.z / fogDistance * 1.5 - 0.6, 1.0));\r
                col = mix(col, skyBgColor, d);\r
        }\r
-    gl_FragColor = vec4(col.r, col.g, col.b, alpha);   \r
+    gl_FragColor = vec4(col.r, col.g, col.b, alpha);\r
 }\r
index c26fdd3d51daa1bb879a47802666e959092a3ce8..e359955d08edf144e3cab0bde558f82a79c45acc 100644 (file)
@@ -1,5 +1,3 @@
-#version 120\r
-\r
 uniform mat4 mWorldViewProj;\r
 uniform mat4 mInvWorld;\r
 uniform mat4 mTransWorld;\r
@@ -9,14 +7,19 @@ uniform vec3 eyePosition;
 \r
 varying vec3 vPosition;\r
 varying vec3 eyeVec;\r
+\r
+#ifdef ENABLE_PARALLAX_OCCLUSION\r
 varying vec3 tsEyeVec;\r
+#endif\r
 \r
 void main(void)\r
 {\r
        gl_Position = mWorldViewProj * gl_Vertex;\r
        vPosition = (mWorldViewProj * gl_Vertex).xyz;\r
+       eyeVec = (gl_ModelViewMatrix * gl_Vertex).xyz;\r
 \r
-       vec3 normal,tangent,binormal; \r
+#ifdef ENABLE_PARALLAX_OCCLUSION\r
+       vec3 normal,tangent,binormal;\r
        normal = normalize(gl_NormalMatrix * gl_Normal);\r
 \r
        if (gl_Normal.x > 0.5) {\r
@@ -44,14 +47,14 @@ void main(void)
                tangent  = normalize(gl_NormalMatrix * vec3(-1.0,  0.0,  0.0));\r
                binormal = normalize(gl_NormalMatrix * vec3( 0.0, -1.0,  0.0));\r
        }\r
-       \r
-       mat3 tbnMatrix = mat3(tangent.x, binormal.x, normal.x,\r
-                          tangent.y, binormal.y, normal.y,\r
-                          tangent.z, binormal.z, normal.z);\r
 \r
-       eyeVec = (gl_ModelViewMatrix * gl_Vertex).xyz;\r
+       mat3 tbnMatrix = mat3(  tangent.x, binormal.x, normal.x,\r
+                                                       tangent.y, binormal.y, normal.y,\r
+                                                       tangent.z, binormal.z, normal.z);\r
+\r
        tsEyeVec = normalize(eyeVec * tbnMatrix);\r
-       \r
+#endif\r
+\r
        vec4 color;\r
        //color = vec4(1.0, 1.0, 1.0, 1.0);\r
 \r
index 00b6884ab8222ed16029a0998e3439b5f287a7f6..31981f9b9aa51476757730eaf8dad1dad63cc4a2 100644 (file)
@@ -1,18 +1,13 @@
-#version 120\r
-\r
 uniform sampler2D baseTexture;\r
 uniform sampler2D normalTexture;\r
 uniform sampler2D useNormalmap;\r
 \r
-uniform float enableBumpmapping;\r
-\r
 uniform vec4 skyBgColor;\r
 uniform float fogDistance;\r
 uniform vec3 eyePosition;\r
 \r
 varying vec3 vPosition;\r
 varying vec3 eyeVec;\r
-varying vec4 vColor;\r
 \r
 const float e = 2.718281828459;\r
 \r
@@ -21,11 +16,12 @@ void main (void)
        vec3 color;\r
        vec2 uv = gl_TexCoord[0].st;\r
 \r
-#ifdef NORMALS\r
+#ifdef USE_NORMALMAPS\r
        float use_normalmap = texture2D(useNormalmap,vec2(1.0,1.0)).r;\r
-       float enable_bumpmapping = enableBumpmapping;\r
+#endif\r
 \r
-       if ((enable_bumpmapping == 1.0) && (use_normalmap > 0.0)) {\r
+#ifdef ENABLE_BUMPMAPPING\r
+       if (use_normalmap > 0.0) {\r
                vec3 base = texture2D(baseTexture, uv).rgb;\r
                vec3 vVec = normalize(eyeVec);\r
                vec3 bump = normalize(texture2D(normalTexture, uv).xyz * 2.0 - 1.0);\r
@@ -54,5 +50,5 @@ void main (void)
                float d = max(0.0, min(vPosition.z / fogDistance * 1.5 - 0.6, 1.0));\r
                col = mix(col, skyBgColor, d);\r
        }\r
-    gl_FragColor = vec4(col.r, col.g, col.b, alpha);   \r
+    gl_FragColor = vec4(col.r, col.g, col.b, alpha);\r
 }\r
index 8dfb0669ee0092744a949aeccd1de8af10014cca..3702b1b50eb39d61a327aaab8aba8dd67ad68900 100644 (file)
@@ -1,40 +1,40 @@
-#version 120\r
-\r
 uniform mat4 mWorldViewProj;\r
 uniform mat4 mInvWorld;\r
 uniform mat4 mTransWorld;\r
 uniform float dayNightRatio;\r
 uniform float animationTimer;\r
 \r
-uniform float enableWavingLeaves;\r
 uniform vec3 eyePosition;\r
 \r
 varying vec3 vPosition;\r
 varying vec3 eyeVec;\r
 \r
-float smoothCurve( float x ) {  \r
-  return x * x *( 3.0 - 2.0 * x );  \r
-}  \r
-float triangleWave( float x ) {  \r
-  return abs( fract( x + 0.5 ) * 2.0 - 1.0 );  \r
-}  \r
-float smoothTriangleWave( float x ) {  \r
-  return smoothCurve( triangleWave( x ) ) * 2.0 - 1.0;  \r
-} \r
+#ifdef ENABLE_WAVING_LEAVES\r
+float smoothCurve( float x ) {\r
+  return x * x *( 3.0 - 2.0 * x );\r
+}\r
+float triangleWave( float x ) {\r
+  return abs( fract( x + 0.5 ) * 2.0 - 1.0 );\r
+}\r
+float smoothTriangleWave( float x ) {\r
+  return smoothCurve( triangleWave( x ) ) * 2.0 - 1.0;\r
+}\r
+#endif\r
 \r
 void main(void)\r
 {\r
        gl_TexCoord[0] = gl_MultiTexCoord0;\r
-       if (enableWavingLeaves == 1.0){ \r
-               vec4 pos = gl_Vertex;\r
-               vec4 pos2 = mTransWorld*gl_Vertex;\r
-               pos.x += (smoothTriangleWave(animationTimer*10.0 + pos2.x * 0.01 + pos2.z * 0.01) * 2.0 - 1.0) * 0.4;\r
-               pos.y += (smoothTriangleWave(animationTimer*15.0 + pos2.x * -0.01 + pos2.z * -0.01) * 2.0 - 1.0) * 0.2;\r
-               pos.z += (smoothTriangleWave(animationTimer*10.0 + pos2.x * -0.01 + pos2.z * -0.01) * 2.0 - 1.0) * 0.4;\r
-               gl_Position = mWorldViewProj * pos;\r
-       }\r
-       else \r
-               gl_Position = mWorldViewProj * gl_Vertex;\r
+\r
+#ifdef ENABLE_WAVING_LEAVES\r
+       vec4 pos = gl_Vertex;\r
+       vec4 pos2 = mTransWorld*gl_Vertex;\r
+       pos.x += (smoothTriangleWave(animationTimer*10.0 + pos2.x * 0.01 + pos2.z * 0.01) * 2.0 - 1.0) * 0.4;\r
+       pos.y += (smoothTriangleWave(animationTimer*15.0 + pos2.x * -0.01 + pos2.z * -0.01) * 2.0 - 1.0) * 0.2;\r
+       pos.z += (smoothTriangleWave(animationTimer*10.0 + pos2.x * -0.01 + pos2.z * -0.01) * 2.0 - 1.0) * 0.4;\r
+       gl_Position = mWorldViewProj * pos;\r
+#else\r
+       gl_Position = mWorldViewProj * gl_Vertex;\r
+#endif\r
 \r
        vPosition = (mWorldViewProj * gl_Vertex).xyz;\r
 \r
index b9156d06e88cdb0bb56dc3518e549bf9b7453852..cab8d8e01413e480c87e0b5e8a6b0cdec0b235bd 100644 (file)
@@ -1,11 +1,7 @@
-#version 120\r
-\r
 uniform sampler2D baseTexture;\r
 uniform sampler2D normalTexture;\r
 uniform sampler2D useNormalmap;\r
 \r
-uniform float enableBumpmapping;\r
-\r
 uniform vec4 skyBgColor;\r
 uniform float fogDistance;\r
 uniform vec3 eyePosition;\r
@@ -19,12 +15,13 @@ void main (void)
 {\r
        vec3 color;\r
        vec2 uv = gl_TexCoord[0].st;\r
-       \r
-#ifdef NORMALS\r
+\r
+#ifdef USE_NORMALMAPS\r
        float use_normalmap = texture2D(useNormalmap,vec2(1.0,1.0)).r;\r
-       float enable_bumpmapping = enableBumpmapping;\r
+#endif\r
 \r
-       if ((enable_bumpmapping == 1.0) && (use_normalmap > 0.0)) {\r
+#ifdef ENABLE_BUMPMAPPING\r
+       if (use_normalmap > 0.0) {\r
                vec3 base = texture2D(baseTexture, uv).rgb;\r
                vec3 vVec = normalize(eyeVec);\r
                vec3 bump = normalize(texture2D(normalTexture, uv).xyz * 2.0 - 1.0);\r
@@ -53,5 +50,5 @@ void main (void)
                float d = max(0.0, min(vPosition.z / fogDistance * 1.5 - 0.6, 1.0));\r
                alpha = mix(alpha, 0.0, d);\r
        }\r
-    gl_FragColor = vec4(col.r, col.g, col.b, alpha); \r
+    gl_FragColor = vec4(col.r, col.g, col.b, alpha);\r
 }\r
index 8ceb9f2cbc093a1f36f28a51d377efd5c98c4277..e8f1858255b6f833e6ac12e762b1cc183ae37ad6 100644 (file)
@@ -1,16 +1,9 @@
-#version 120\r
-\r
 uniform mat4 mWorldViewProj;\r
 uniform mat4 mInvWorld;\r
 uniform mat4 mTransWorld;\r
 uniform float dayNightRatio;\r
 uniform float animationTimer;\r
 \r
-uniform float enableWavingWater;\r
-uniform float waterWaveLength;\r
-uniform float waterWaveHeight;\r
-uniform float waterWaveSpeed;\r
-\r
 uniform vec3 eyePosition;\r
 \r
 varying vec3 vPosition;\r
@@ -18,14 +11,15 @@ varying vec3 eyeVec;
 \r
 void main(void)\r
 {\r
-       if (enableWavingWater == 1.0){\r
-               vec4 pos2 = gl_Vertex;\r
-               pos2.y -= 2.0;\r
-               pos2.y -= sin (pos2.z/waterWaveLength + animationTimer * waterWaveSpeed * waterWaveLength) * waterWaveHeight\r
-                       + sin ((pos2.z/waterWaveLength + animationTimer * waterWaveSpeed * waterWaveLength) / 7.0) * waterWaveHeight;\r
-               gl_Position = mWorldViewProj * pos2;\r
-       } else\r
-               gl_Position = mWorldViewProj * gl_Vertex;\r
+#ifdef ENABLE_WAVING_WATER\r
+       vec4 pos2 = gl_Vertex;\r
+       pos2.y -= 2.0;\r
+       pos2.y -= sin (pos2.z/WATER_WAVE_LENGTH + animationTimer * WATER_WAVE_SPEED * WATER_WAVE_LENGTH) * WATER_WAVE_HEIGHT\r
+               + sin ((pos2.z/WATER_WAVE_LENGTH + animationTimer * WATER_WAVE_SPEED * WATER_WAVE_LENGTH) / 7.0) * WATER_WAVE_HEIGHT;\r
+       gl_Position = mWorldViewProj * pos2;\r
+#else\r
+       gl_Position = mWorldViewProj * gl_Vertex;\r
+#endif\r
 \r
        eyeVec = (gl_ModelViewMatrix * gl_Vertex).xyz;\r
        vPosition = (mWorldViewProj * gl_Vertex).xyz;\r
index abbcada88e23be685763faf04ae0d4ba884107c8..31981f9b9aa51476757730eaf8dad1dad63cc4a2 100644 (file)
@@ -1,11 +1,7 @@
-#version 120\r
-\r
 uniform sampler2D baseTexture;\r
 uniform sampler2D normalTexture;\r
 uniform sampler2D useNormalmap;\r
 \r
-uniform float enableBumpmapping;\r
-\r
 uniform vec4 skyBgColor;\r
 uniform float fogDistance;\r
 uniform vec3 eyePosition;\r
@@ -19,12 +15,13 @@ void main (void)
 {\r
        vec3 color;\r
        vec2 uv = gl_TexCoord[0].st;\r
-       \r
-#ifdef NORMALS\r
+\r
+#ifdef USE_NORMALMAPS\r
        float use_normalmap = texture2D(useNormalmap,vec2(1.0,1.0)).r;\r
-       float enable_bumpmapping = enableBumpmapping;\r
+#endif\r
 \r
-       if ((enable_bumpmapping == 1.0) && (use_normalmap > 0.0)) {\r
+#ifdef ENABLE_BUMPMAPPING\r
+       if (use_normalmap > 0.0) {\r
                vec3 base = texture2D(baseTexture, uv).rgb;\r
                vec3 vVec = normalize(eyeVec);\r
                vec3 bump = normalize(texture2D(normalTexture, uv).xyz * 2.0 - 1.0);\r
@@ -53,5 +50,5 @@ void main (void)
                float d = max(0.0, min(vPosition.z / fogDistance * 1.5 - 0.6, 1.0));\r
                col = mix(col, skyBgColor, d);\r
        }\r
-    gl_FragColor = vec4(col.r, col.g, col.b, alpha);   \r
+    gl_FragColor = vec4(col.r, col.g, col.b, alpha);\r
 }\r
index c1bdd62a9219be79b894f3d9a9a1f384032a8222..7987fc16d5b011862227fc88faa9fddb89c2c437 100644 (file)
@@ -1,43 +1,42 @@
-#version 120\r
-\r
 uniform mat4 mWorldViewProj;\r
 uniform mat4 mInvWorld;\r
 uniform mat4 mTransWorld;\r
 uniform float dayNightRatio;\r
 uniform float animationTimer;\r
 \r
-uniform float enableWavingPlants;\r
-\r
 uniform vec3 eyePosition;\r
 \r
 varying vec3 vPosition;\r
 varying vec3 eyeVec;\r
 \r
-float smoothCurve( float x ) {  \r
-  return x * x *( 3.0 - 2.0 * x );  \r
-}  \r
-float triangleWave( float x ) {  \r
-  return abs( fract( x + 0.5 ) * 2.0 - 1.0 );  \r
-}  \r
-float smoothTriangleWave( float x ) {  \r
-  return smoothCurve( triangleWave( x ) ) * 2.0 - 1.0;  \r
-} \r
+#ifdef ENABLE_WAVING_PLANTS\r
+float smoothCurve( float x ) {\r
+  return x * x *( 3.0 - 2.0 * x );\r
+}\r
+float triangleWave( float x ) {\r
+  return abs( fract( x + 0.5 ) * 2.0 - 1.0 );\r
+}\r
+float smoothTriangleWave( float x ) {\r
+  return smoothCurve( triangleWave( x ) ) * 2.0 - 1.0;\r
+}\r
+#endif\r
 \r
 void main(void)\r
 {\r
 \r
        gl_TexCoord[0] = gl_MultiTexCoord0;\r
-       if (enableWavingPlants == 1.0){\r
-               vec4 pos = gl_Vertex;\r
-               vec4 pos2 = mTransWorld * gl_Vertex;\r
-               if (gl_TexCoord[0].y < 0.05) {\r
-                       pos.x += (smoothTriangleWave(animationTimer * 20.0 + pos2.x * 0.1 + pos2.z * 0.1) * 2.0 - 1.0) * 0.8;\r
-                       pos.y -= (smoothTriangleWave(animationTimer * 10.0 + pos2.x * -0.5 + pos2.z * -0.5) * 2.0 - 1.0) * 0.4;          \r
-               }\r
-               gl_Position = mWorldViewProj * pos;\r
+\r
+#ifdef ENABLE_WAVING_PLANTS\r
+       vec4 pos = gl_Vertex;\r
+       vec4 pos2 = mTransWorld * gl_Vertex;\r
+       if (gl_TexCoord[0].y < 0.05) {\r
+               pos.x += (smoothTriangleWave(animationTimer * 20.0 + pos2.x * 0.1 + pos2.z * 0.1) * 2.0 - 1.0) * 0.8;\r
+               pos.y -= (smoothTriangleWave(animationTimer * 10.0 + pos2.x * -0.5 + pos2.z * -0.5) * 2.0 - 1.0) * 0.4;\r
        }\r
-       else \r
-               gl_Position = mWorldViewProj * gl_Vertex;\r
+       gl_Position = mWorldViewProj * pos;\r
+#else\r
+       gl_Position = mWorldViewProj * gl_Vertex;\r
+#endif\r
 \r
        vPosition = (mWorldViewProj * gl_Vertex).xyz;\r
        eyeVec = (gl_ModelViewMatrix * gl_Vertex).xyz;\r
index 0b6d8f3fccf7703d871d1b708f897823b697b8c7..d81506a4f2efc2d076cec59a815fcb610c25691b 100644 (file)
@@ -1,23 +1,17 @@
-#version 120\r
-\r
 uniform sampler2D baseTexture;\r
 uniform sampler2D normalTexture;\r
 uniform sampler2D useNormalmap;\r
 \r
-uniform float enableBumpmapping;\r
-uniform float enableParallaxOcclusion;\r
-uniform float parallaxOcclusionScale;\r
-uniform float parallaxOcclusionBias;\r
-\r
-\r
 uniform vec4 skyBgColor;\r
 uniform float fogDistance;\r
 uniform vec3 eyePosition;\r
 \r
 varying vec3 vPosition;\r
-varying vec3 tsEyeVec;\r
 varying vec3 eyeVec;\r
-varying vec4 vColor;\r
+\r
+#ifdef ENABLE_PARALLAX_OCCLUSION\r
+varying vec3 tsEyeVec;\r
+#endif\r
 \r
 const float e = 2.718281828459;\r
 \r
@@ -25,21 +19,24 @@ void main (void)
 {\r
        vec3 color;\r
        vec2 uv = gl_TexCoord[0].st;\r
-       \r
-#ifdef NORMALS\r
+\r
+#ifdef USE_NORMALMAPS\r
+       float use_normalmap = texture2D(useNormalmap,vec2(1.0,1.0)).r;\r
+#endif\r
+\r
+#ifdef ENABLE_PARALLAX_OCCLUSION\r
        float height;\r
        vec2 tsEye = vec2(tsEyeVec.x,-tsEyeVec.y);\r
-       \r
-       float use_normalmap = texture2D(useNormalmap,vec2(1.0,1.0)).r;\r
-       float enable_bumpmapping = enableBumpmapping;\r
-       \r
-       if ((enableParallaxOcclusion == 1.0) && (use_normalmap > 0.0)) {\r
+\r
+       if (use_normalmap > 0.0) {\r
                float map_height = texture2D(normalTexture, uv).a;\r
                        if (map_height < 1.0){\r
-                               float height = parallaxOcclusionScale * map_height - parallaxOcclusionBias;\r
+                               float height = PARALLAX_OCCLUSION_SCALE * map_height - PARALLAX_OCCLUSION_BIAS;\r
                                uv = uv + height * tsEye;\r
                        }\r
        }\r
+#endif\r
+\r
 /* Steep parallax code, for future use\r
        if ((parallaxMappingMode == 2.0) && (use_normalmap > 0.0)) {\r
                const float numSteps = 40.0;\r
@@ -59,7 +56,8 @@ void main (void)
        }\r
 */\r
 \r
-       if ((enable_bumpmapping == 1.0) && (use_normalmap > 0.0)) {\r
+#ifdef ENABLE_BUMPMAPPING\r
+       if (use_normalmap > 0.0) {\r
                vec3 base = texture2D(baseTexture, uv).rgb;\r
                vec3 vVec = normalize(eyeVec);\r
                vec3 bump = normalize(texture2D(normalTexture, uv).xyz * 2.0 - 1.0);\r
@@ -88,5 +86,5 @@ void main (void)
                float d = max(0.0, min(vPosition.z / fogDistance * 1.5 - 0.6, 1.0));\r
                col = mix(col, skyBgColor, d);\r
        }\r
-    gl_FragColor = vec4(col.r, col.g, col.b, alpha);   \r
+    gl_FragColor = vec4(col.r, col.g, col.b, alpha);\r
 }\r
index c26fdd3d51daa1bb879a47802666e959092a3ce8..e359955d08edf144e3cab0bde558f82a79c45acc 100644 (file)
@@ -1,5 +1,3 @@
-#version 120\r
-\r
 uniform mat4 mWorldViewProj;\r
 uniform mat4 mInvWorld;\r
 uniform mat4 mTransWorld;\r
@@ -9,14 +7,19 @@ uniform vec3 eyePosition;
 \r
 varying vec3 vPosition;\r
 varying vec3 eyeVec;\r
+\r
+#ifdef ENABLE_PARALLAX_OCCLUSION\r
 varying vec3 tsEyeVec;\r
+#endif\r
 \r
 void main(void)\r
 {\r
        gl_Position = mWorldViewProj * gl_Vertex;\r
        vPosition = (mWorldViewProj * gl_Vertex).xyz;\r
+       eyeVec = (gl_ModelViewMatrix * gl_Vertex).xyz;\r
 \r
-       vec3 normal,tangent,binormal; \r
+#ifdef ENABLE_PARALLAX_OCCLUSION\r
+       vec3 normal,tangent,binormal;\r
        normal = normalize(gl_NormalMatrix * gl_Normal);\r
 \r
        if (gl_Normal.x > 0.5) {\r
@@ -44,14 +47,14 @@ void main(void)
                tangent  = normalize(gl_NormalMatrix * vec3(-1.0,  0.0,  0.0));\r
                binormal = normalize(gl_NormalMatrix * vec3( 0.0, -1.0,  0.0));\r
        }\r
-       \r
-       mat3 tbnMatrix = mat3(tangent.x, binormal.x, normal.x,\r
-                          tangent.y, binormal.y, normal.y,\r
-                          tangent.z, binormal.z, normal.z);\r
 \r
-       eyeVec = (gl_ModelViewMatrix * gl_Vertex).xyz;\r
+       mat3 tbnMatrix = mat3(  tangent.x, binormal.x, normal.x,\r
+                                                       tangent.y, binormal.y, normal.y,\r
+                                                       tangent.z, binormal.z, normal.z);\r
+\r
        tsEyeVec = normalize(eyeVec * tbnMatrix);\r
-       \r
+#endif\r
+\r
        vec4 color;\r
        //color = vec4(1.0, 1.0, 1.0, 1.0);\r
 \r
index 68bd12b97b72d65b3b29e9ca11b7c5deea50d206..b67602f5a1f55c8d859dbeba91b106fe03974f20 100644 (file)
@@ -815,44 +815,6 @@ public:
                services->setPixelShaderConstant("eyePosition", (irr::f32*)&eye_position, 3);
                services->setVertexShaderConstant("eyePosition", (irr::f32*)&eye_position, 3);
 
-               float enable_bumpmapping = 0;
-               if (g_settings->getBool("enable_bumpmapping"))
-                       enable_bumpmapping = 1;
-               services->setPixelShaderConstant("enableBumpmapping", &enable_bumpmapping, 1);
-
-               float enable_parallax_occlusion = 0;
-               if (g_settings->getBool("enable_parallax_occlusion")) {
-                       enable_parallax_occlusion = 1;
-                       float parallax_occlusion_scale = g_settings->getFloat("parallax_occlusion_scale");
-                       services->setPixelShaderConstant("parallaxOcclusionScale", &parallax_occlusion_scale, 1);
-                       float parallax_occlusion_bias = g_settings->getFloat("parallax_occlusion_bias");
-                       services->setPixelShaderConstant("parallaxOcclusionBias", &parallax_occlusion_bias, 1);
-               }
-               services->setPixelShaderConstant("enableParallaxOcclusion", &enable_parallax_occlusion, 1);
-
-               float enable_waving_water = 0;
-               if (g_settings->getBool("enable_waving_water")){
-                       enable_waving_water = 1;
-                       float water_wave_height_f = g_settings->getFloat("water_wave_height");
-                       services->setVertexShaderConstant("waterWaveHeight", &water_wave_height_f, 1);
-                       float water_wave_length_f = g_settings->getFloat("water_wave_length");
-                       services->setVertexShaderConstant("waterWaveLength", &water_wave_length_f, 1);
-                       float water_wave_speed_f = g_settings->getFloat("water_wave_speed");
-                       services->setVertexShaderConstant("waterWaveSpeed", &water_wave_speed_f, 1);
-               }
-               services->setVertexShaderConstant("enableWavingWater", &enable_waving_water, 1);
-
-               float enable_waving_leaves = 0;
-               if (g_settings->getBool("enable_waving_leaves"))
-                       enable_waving_leaves = 1;
-               services->setVertexShaderConstant("enableWavingLeaves", &enable_waving_leaves, 1);
-
-               float enable_waving_plants = 0;
-               if (g_settings->getBool("enable_waving_plants"))
-                       enable_waving_plants = 1;
-               services->setVertexShaderConstant("enableWavingPlants", &enable_waving_plants, 1);
-
-
                // Normal map texture layer
                int layer1 = 1;
                int layer2 = 2;
index 81aac72d7c4cfe81eb8730444688a8fa9228d1db..afea3dcce2e9224d3d894b69c366834ae99d20ec 100644 (file)
@@ -1111,6 +1111,7 @@ MapBlockMesh::MapBlockMesh(MeshMakeData *data):
        */
        bool enable_shaders     = g_settings->getBool("enable_shaders");
        bool enable_bumpmapping = g_settings->getBool("enable_bumpmapping");
+       bool enable_parallax_occlusion = g_settings->getBool("enable_parallax_occlusion");
 
        video::E_MATERIAL_TYPE  shadermat1, shadermat2, shadermat3,
                                                        shadermat4, shadermat5;
@@ -1210,7 +1211,7 @@ MapBlockMesh::MapBlockMesh(MeshMakeData *data):
                if (enable_shaders) {
                        ITextureSource *tsrc = data->m_gamedef->tsrc();
                        material.setTexture(2, tsrc->getTexture("disable_img.png"));
-                       if (enable_bumpmapping) {
+                       if (enable_bumpmapping || enable_parallax_occlusion) {
                                std::string fname_base = tsrc->getTextureName(p.tile.texture_id);
                                std::string normal_ext = "_normal.png";
                                size_t pos = fname_base.find(".");
@@ -1292,7 +1293,8 @@ bool MapBlockMesh::animate(bool faraway, float time, int crack, u32 daynight_rat
 {
        bool enable_shaders = g_settings->getBool("enable_shaders");
        bool enable_bumpmapping = g_settings->getBool("enable_bumpmapping");
-       
+       bool enable_parallax_occlusion = g_settings->getBool("enable_parallax_occlusion");
+
        if(!m_has_animation)
        {
                m_animation_force_timer = 100000;
@@ -1362,7 +1364,7 @@ bool MapBlockMesh::animate(bool faraway, float time, int crack, u32 daynight_rat
                // Set the texture
                buf->getMaterial().setTexture(0, tsrc->getTexture(os.str()));
                buf->getMaterial().setTexture(2, tsrc->getTexture("disable_img.png"));
-               if (enable_shaders && enable_bumpmapping)
+               if (enable_shaders && (enable_bumpmapping || enable_parallax_occlusion))
                        {
                                std::string fname_base,fname_normal;
                                fname_base = tsrc->getTextureName(tile.texture_id);
index 76af23686b8aedb7d00fc716b47e45ec0c903dcf..39296f6a3a60fcfac5cfebf1e63d55aa855f336e 100644 (file)
@@ -673,15 +673,51 @@ ShaderInfo generate_shader(std::string name, IrrlichtDevice *device,
        if(vertex_program == "" && pixel_program == "" && geometry_program == "")
                return shaderinfo;
 
-       if (g_settings->getBool("enable_bumpmapping") || g_settings->getBool("enable_parallax_occlusion")) {
-               if(vertex_program != "")
-                       vertex_program = "#define NORMALS\n" + vertex_program;
-               if(pixel_program != "")
-                       pixel_program = "#define NORMALS\n" + pixel_program;
-               if(geometry_program != "")
-                       geometry_program = "#define NORMALS\n" + geometry_program;
-       }
+       // Create shaders header
+       std::string shaders_header = "#version 120\n";
        
+       if (g_settings->getBool("enable_bumpmapping"))
+               shaders_header += "#define ENABLE_BUMPMAPPING\n";
+
+       if (g_settings->getBool("enable_parallax_occlusion")){
+               shaders_header += "#define ENABLE_PARALLAX_OCCLUSION\n";
+               shaders_header += "#define PARALLAX_OCCLUSION_SCALE ";
+               shaders_header += ftos(g_settings->getFloat("parallax_occlusion_scale"));
+               shaders_header += "\n";
+               shaders_header += "#define PARALLAX_OCCLUSION_BIAS ";
+               shaders_header += ftos(g_settings->getFloat("parallax_occlusion_bias"));
+               shaders_header += "\n";
+               }
+
+       if (g_settings->getBool("enable_bumpmapping") || g_settings->getBool("enable_parallax_occlusion"))
+               shaders_header += "#define USE_NORMALMAPS\n";
+
+       if (g_settings->getBool("enable_waving_water")){
+               shaders_header += "#define ENABLE_WAVING_WATER\n";
+               shaders_header += "#define WATER_WAVE_HEIGHT ";
+               shaders_header += ftos(g_settings->getFloat("water_wave_height"));
+               shaders_header += "\n";
+               shaders_header += "#define WATER_WAVE_LENGTH ";
+               shaders_header += ftos(g_settings->getFloat("water_wave_length"));
+               shaders_header += "\n";
+               shaders_header += "#define WATER_WAVE_SPEED ";
+               shaders_header += ftos(g_settings->getFloat("water_wave_speed"));
+               shaders_header += "\n";
+       }
+
+       if (g_settings->getBool("enable_waving_leaves"))
+               shaders_header += "#define ENABLE_WAVING_LEAVES\n";
+
+       if (g_settings->getBool("enable_waving_plants"))
+               shaders_header += "#define ENABLE_WAVING_PLANTS\n";
+
+       if(pixel_program != "")
+               pixel_program = shaders_header + pixel_program;
+       if(vertex_program != "")
+               vertex_program = shaders_header + vertex_program;
+       if(geometry_program != "")
+               geometry_program = shaders_header + geometry_program;
+
        // Call addHighLevelShaderMaterial() or addShaderMaterial()
        const c8* vertex_program_ptr = 0;
        const c8* pixel_program_ptr = 0;