]> git.xonotic.org Git - xonotic/darkplaces.git/commitdiff
reduce number of varying variables required in shaders by 1
authorhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Sat, 12 Mar 2011 05:40:32 +0000 (05:40 +0000)
committerhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Sat, 12 Mar 2011 05:40:32 +0000 (05:40 +0000)
git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@10909 d7cf8633-e32d-0410-b094-e92efae38249

shader_glsl.h

index 614fbf4e943716424dcad191c507f640d2a7fe9c..5cfeef0fd87cc1b7438b7ba8dc61d9a1b4a62ac5 100644 (file)
 "\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"
 "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"
 "{\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"
 "      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"
 "{\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"
 "#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"
 "#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"
 "\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"