From: Novatux Date: Sun, 8 Dec 2013 07:01:20 +0000 (+0100) Subject: Fix shaders on some GPUs X-Git-Url: http://81.2.79.47:8989/gitweb/?a=commitdiff_plain;h=206565d9650eeffc86b4223a75203a29bc94cce7;p=zefram%2Fminetest%2Fminetest_engine.git Fix shaders on some GPUs --- diff --git a/client/shaders/alpha_shader/opengl_fragment.glsl b/client/shaders/alpha_shader/opengl_fragment.glsl index e72c1b9a..3c0f35ea 100644 --- a/client/shaders/alpha_shader/opengl_fragment.glsl +++ b/client/shaders/alpha_shader/opengl_fragment.glsl @@ -21,14 +21,16 @@ const float e = 2.718281828459; void main (void) { - float use_normalmap = texture2D(useNormalmap,vec2(1.0,1.0)).r; - float enable_bumpmapping = enableBumpmapping; - vec3 color; vec2 uv = gl_TexCoord[0].st; + +#ifdef NORMALS float height; vec2 tsEye = vec2(tsEyeVec.x,-tsEyeVec.y); + float use_normalmap = texture2D(useNormalmap,vec2(1.0,1.0)).r; + float enable_bumpmapping = enableBumpmapping; + if ((enableParallaxOcclusion == 1.0) && (use_normalmap > 0.0)) { float map_height = texture2D(normalTexture, uv).a; if (map_height < 1.0){ @@ -49,6 +51,9 @@ void main (void) } else { color = texture2D(baseTexture, uv).rgb; } +#else + color = texture2D(baseTexture, uv).rgb; +#endif float alpha = texture2D(baseTexture, uv).a; vec4 col = vec4(color.r, color.g, color.b, alpha); diff --git a/client/shaders/leaves_shader/opengl_fragment.glsl b/client/shaders/leaves_shader/opengl_fragment.glsl index 127b32d5..00b6884a 100644 --- a/client/shaders/leaves_shader/opengl_fragment.glsl +++ b/client/shaders/leaves_shader/opengl_fragment.glsl @@ -18,12 +18,13 @@ const float e = 2.718281828459; void main (void) { - float use_normalmap = texture2D(useNormalmap,vec2(1.0,1.0)).r; - float enable_bumpmapping = enableBumpmapping; - vec3 color; vec2 uv = gl_TexCoord[0].st; +#ifdef NORMALS + float use_normalmap = texture2D(useNormalmap,vec2(1.0,1.0)).r; + float enable_bumpmapping = enableBumpmapping; + if ((enable_bumpmapping == 1.0) && (use_normalmap > 0.0)) { vec3 base = texture2D(baseTexture, uv).rgb; vec3 vVec = normalize(eyeVec); @@ -36,6 +37,9 @@ void main (void) } else { color = texture2D(baseTexture, uv).rgb; } +#else + color = texture2D(baseTexture, uv).rgb; +#endif float alpha = texture2D(baseTexture, uv).a; vec4 col = vec4(color.r, color.g, color.b, alpha); diff --git a/client/shaders/liquids_shader/opengl_fragment.glsl b/client/shaders/liquids_shader/opengl_fragment.glsl index a5ffd71b..b9156d06 100644 --- a/client/shaders/liquids_shader/opengl_fragment.glsl +++ b/client/shaders/liquids_shader/opengl_fragment.glsl @@ -17,11 +17,12 @@ const float e = 2.718281828459; void main (void) { - float use_normalmap = texture2D(useNormalmap,vec2(1.0,1.0)).r; - float enable_bumpmapping = enableBumpmapping; - vec3 color; vec2 uv = gl_TexCoord[0].st; + +#ifdef NORMALS + float use_normalmap = texture2D(useNormalmap,vec2(1.0,1.0)).r; + float enable_bumpmapping = enableBumpmapping; if ((enable_bumpmapping == 1.0) && (use_normalmap > 0.0)) { vec3 base = texture2D(baseTexture, uv).rgb; @@ -35,6 +36,9 @@ void main (void) } else { color = texture2D(baseTexture, uv).rgb; } +#else + color = texture2D(baseTexture, uv).rgb; +#endif float alpha = gl_Color.a; vec4 col = vec4(color.r, color.g, color.b, alpha); diff --git a/client/shaders/plants_shader/opengl_fragment.glsl b/client/shaders/plants_shader/opengl_fragment.glsl index de6ad4c0..abbcada8 100644 --- a/client/shaders/plants_shader/opengl_fragment.glsl +++ b/client/shaders/plants_shader/opengl_fragment.glsl @@ -17,11 +17,12 @@ const float e = 2.718281828459; void main (void) { - float use_normalmap = texture2D(useNormalmap,vec2(1.0,1.0)).r; - float enable_bumpmapping = enableBumpmapping; - vec3 color; vec2 uv = gl_TexCoord[0].st; + +#ifdef NORMALS + float use_normalmap = texture2D(useNormalmap,vec2(1.0,1.0)).r; + float enable_bumpmapping = enableBumpmapping; if ((enable_bumpmapping == 1.0) && (use_normalmap > 0.0)) { vec3 base = texture2D(baseTexture, uv).rgb; @@ -35,6 +36,9 @@ void main (void) } else { color = texture2D(baseTexture, uv).rgb; } +#else + color = texture2D(baseTexture, uv).rgb; +#endif float alpha = texture2D(baseTexture, uv).a; vec4 col = vec4(color.r, color.g, color.b, alpha); diff --git a/client/shaders/solids_shader/opengl_fragment.glsl b/client/shaders/solids_shader/opengl_fragment.glsl index 80efc86a..0b6d8f3f 100644 --- a/client/shaders/solids_shader/opengl_fragment.glsl +++ b/client/shaders/solids_shader/opengl_fragment.glsl @@ -23,14 +23,16 @@ const float e = 2.718281828459; void main (void) { - float use_normalmap = texture2D(useNormalmap,vec2(1.0,1.0)).r; - float enable_bumpmapping = enableBumpmapping; - vec3 color; vec2 uv = gl_TexCoord[0].st; + +#ifdef NORMALS float height; vec2 tsEye = vec2(tsEyeVec.x,-tsEyeVec.y); + float use_normalmap = texture2D(useNormalmap,vec2(1.0,1.0)).r; + float enable_bumpmapping = enableBumpmapping; + if ((enableParallaxOcclusion == 1.0) && (use_normalmap > 0.0)) { float map_height = texture2D(normalTexture, uv).a; if (map_height < 1.0){ @@ -69,6 +71,9 @@ void main (void) } else { color = texture2D(baseTexture, uv).rgb; } +#else + color = texture2D(baseTexture, uv).rgb; +#endif float alpha = texture2D(baseTexture, uv).a; vec4 col = vec4(color.r, color.g, color.b, alpha); diff --git a/src/shader.cpp b/src/shader.cpp index ec192b9a..76af2368 100644 --- a/src/shader.cpp +++ b/src/shader.cpp @@ -673,6 +673,15 @@ 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; + } + // Call addHighLevelShaderMaterial() or addShaderMaterial() const c8* vertex_program_ptr = 0; const c8* pixel_program_ptr = 0;