From: havoc Date: Sat, 12 Mar 2011 05:40:32 +0000 (+0000) Subject: reduce number of varying variables required in shaders by 1 X-Git-Tag: xonotic-v0.5.0~421 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=ece8155ba8cfe398a10352fbc752f1420fc1c733;p=xonotic%2Fdarkplaces.git reduce number of varying variables required in shaders by 1 git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@10909 d7cf8633-e32d-0410-b094-e92efae38249 ::stable-branch::merge=aecef2692778fc042044a5b695ef499471ddb69c --- diff --git a/shader_glsl.h b/shader_glsl.h index 614fbf4e..5cfeef0f 100644 --- a/shader_glsl.h +++ b/shader_glsl.h @@ -427,13 +427,10 @@ "\n" "// common definitions between vertex shader and fragment shader:\n" "\n" -"varying mediump vec2 TexCoord;\n" +"varying mediump vec4 TexCoordSurfaceLightmap;\n" "#ifdef USEVERTEXTEXTUREBLEND\n" "varying mediump vec2 TexCoord2;\n" "#endif\n" -"#ifdef USELIGHTMAP\n" -"varying mediump vec2 TexCoordLightmap;\n" -"#endif\n" "\n" "#ifdef MODE_LIGHTSOURCE\n" "varying mediump vec3 CubeVector;\n" @@ -761,7 +758,7 @@ "uniform highp mat4 ModelViewMatrix;\n" "void main(void)\n" "{\n" -" TexCoord = vec2(TexMatrix * Attrib_TexCoord0);\n" +" TexCoordSurfaceLightmap.xy = vec4((TexMatrix * Attrib_TexCoord0).xy, 0.0, 0.0);\n" "#ifdef USEVERTEXTEXTUREBLEND\n" " VertexColor = Attrib_Color;\n" " TexCoord2 = vec2(BackgroundTexMatrix * Attrib_TexCoord0);\n" @@ -787,8 +784,9 @@ "{\n" "#ifdef USEOFFSETMAPPING\n" " // apply offsetmapping\n" -" vec2 TexCoordOffset = OffsetMapping(TexCoord);\n" -"#define TexCoord TexCoordOffset\n" +" vec2 TexCoord = OffsetMapping(TexCoordSurfaceLightmap.xy);\n" +"#else\n" +"# define TexCoord (TexCoordSurfaceLightmap.xy)\n" "#endif\n" "\n" "#ifdef USEALPHAKILL\n" @@ -919,13 +917,14 @@ " VertexColor = Attrib_Color;\n" "#endif\n" " // copy the surface texcoord\n" -" TexCoord = vec2(TexMatrix * Attrib_TexCoord0);\n" +"#ifdef USELIGHTMAP\n" +" TexCoordSurfaceLightmap = vec4((TexMatrix * Attrib_TexCoord0).xy, Attrib_TexCoord4.xy);\n" +"#else\n" +" TexCoordSurfaceLightmap = vec4((TexMatrix * Attrib_TexCoord0).xy, 0.0, 0.0);\n" +"#endif\n" "#ifdef USEVERTEXTEXTUREBLEND\n" " TexCoord2 = vec2(BackgroundTexMatrix * Attrib_TexCoord0);\n" "#endif\n" -"#ifdef USELIGHTMAP\n" -" TexCoordLightmap = vec2(Attrib_TexCoord4);\n" -"#endif\n" "\n" "#ifdef USEBOUNCEGRID\n" " BounceGridTexCoord = vec3(BounceGridMatrix * Attrib_Position);\n" @@ -1027,8 +1026,9 @@ "{\n" "#ifdef USEOFFSETMAPPING\n" " // apply offsetmapping\n" -" vec2 TexCoordOffset = OffsetMapping(TexCoord);\n" -"#define TexCoord TexCoordOffset\n" +" vec2 TexCoord = OffsetMapping(TexCoordSurfaceLightmap.xy);\n" +"#else\n" +"# define TexCoord (TexCoordSurfaceLightmap.xy)\n" "#endif\n" "\n" " // combine the diffuse textures (base, pants, shirt)\n" @@ -1118,8 +1118,8 @@ "#ifdef MODE_LIGHTDIRECTIONMAP_MODELSPACE\n" "#define SHADING\n" " // deluxemap lightmapping using light vectors in modelspace (q3map2 -light -deluxe)\n" -" myhalf3 lightnormal_modelspace = myhalf3(texture2D(Texture_Deluxemap, TexCoordLightmap)) * 2.0 + myhalf3(-1.0, -1.0, -1.0);\n" -" myhalf3 lightcolor = myhalf3(texture2D(Texture_Lightmap, TexCoordLightmap));\n" +" myhalf3 lightnormal_modelspace = myhalf3(texture2D(Texture_Deluxemap, TexCoordSurfaceLightmap.zw)) * 2.0 + myhalf3(-1.0, -1.0, -1.0);\n" +" myhalf3 lightcolor = myhalf3(texture2D(Texture_Lightmap, TexCoordSurfaceLightmap.zw));\n" " // convert modelspace light vector to tangentspace\n" " myhalf3 lightnormal;\n" " lightnormal.x = dot(lightnormal_modelspace, myhalf3(VectorS));\n" @@ -1140,8 +1140,8 @@ "#ifdef MODE_LIGHTDIRECTIONMAP_TANGENTSPACE\n" "#define SHADING\n" " // deluxemap lightmapping using light vectors in tangentspace (hmap2 -light)\n" -" myhalf3 lightnormal = myhalf3(texture2D(Texture_Deluxemap, TexCoordLightmap)) * 2.0 + myhalf3(-1.0, -1.0, -1.0);\n" -" myhalf3 lightcolor = myhalf3(texture2D(Texture_Lightmap, TexCoordLightmap));\n" +" myhalf3 lightnormal = myhalf3(texture2D(Texture_Deluxemap, TexCoordSurfaceLightmap.zw)) * 2.0 + myhalf3(-1.0, -1.0, -1.0);\n" +" myhalf3 lightcolor = myhalf3(texture2D(Texture_Lightmap, TexCoordSurfaceLightmap.zw));\n" "#endif\n" "\n" "\n" @@ -1157,7 +1157,7 @@ "\n" "\n" "#ifdef MODE_LIGHTMAP\n" -" color.rgb = diffusetex * (Color_Ambient + myhalf3(texture2D(Texture_Lightmap, TexCoordLightmap)) * Color_Diffuse);\n" +" color.rgb = diffusetex * (Color_Ambient + myhalf3(texture2D(Texture_Lightmap, TexCoordSurfaceLightmap.zw)) * Color_Diffuse);\n" "#endif // MODE_LIGHTMAP\n" "#ifdef MODE_VERTEXCOLOR\n" " color.rgb = diffusetex * (Color_Ambient + myhalf3(VertexColor.rgb) * Color_Diffuse);\n"