diff options
author | SmileTheory <SmileTheory@gmail.com> | 2013-11-03 19:34:22 -0800 |
---|---|---|
committer | Tim Angus <tim@ngus.net> | 2014-06-17 17:43:35 +0100 |
commit | c845aa58e29b95bfcbe0ef2cf441068148328803 (patch) | |
tree | 6935664284d550596a112ae4e5b8684fa6762a37 | |
parent | 2fee3c939af105c5a75696702f58ef267da7bf49 (diff) |
OpenGL2: Reduce glsl shader count by using a uniform to disable textures.
-rw-r--r-- | src/renderergl2/glsl/lightall_fp.glsl | 13 | ||||
-rw-r--r-- | src/renderergl2/glsl/lightall_vp.glsl | 31 | ||||
-rw-r--r-- | src/renderergl2/tr_glsl.c | 117 | ||||
-rw-r--r-- | src/renderergl2/tr_image.c | 3 | ||||
-rw-r--r-- | src/renderergl2/tr_local.h | 13 | ||||
-rw-r--r-- | src/renderergl2/tr_shade.c | 109 | ||||
-rw-r--r-- | src/renderergl2/tr_shader.c | 11 |
7 files changed, 145 insertions, 152 deletions
diff --git a/src/renderergl2/glsl/lightall_fp.glsl b/src/renderergl2/glsl/lightall_fp.glsl index f223bb0c..53fd1b43 100644 --- a/src/renderergl2/glsl/lightall_fp.glsl +++ b/src/renderergl2/glsl/lightall_fp.glsl @@ -24,6 +24,10 @@ uniform sampler2D u_ShadowMap; uniform samplerCube u_CubeMap; #endif +#if defined(USE_NORMALMAP) || defined(USE_DELUXEMAP) || defined(USE_SPECULARMAP) || defined(USE_CUBEMAP) +uniform vec4 u_EnableTextures; // x = normal, y = deluxe, z = specular, w = cube +#endif + #if defined(USE_LIGHT_VECTOR) && !defined(USE_FAST_LIGHT) uniform vec3 u_DirectedLight; uniform vec3 u_AmbientLight; @@ -52,7 +56,7 @@ varying vec4 var_Bitangent; varying vec3 var_LightColor; #endif -#if defined(USE_LIGHT) && !defined(USE_DELUXEMAP) && !defined(USE_FAST_LIGHT) +#if defined(USE_LIGHT) && !defined(USE_FAST_LIGHT) varying vec4 var_LightDir; #endif @@ -304,6 +308,7 @@ void main() #if defined(USE_TANGENT_SPACE_LIGHT) L = L * tangentToWorld; #endif + L = L * u_EnableTextures.y + var_LightDir.xyz; #elif defined(USE_LIGHT) && !defined(USE_FAST_LIGHT) L = var_LightDir.xyz; #endif @@ -352,6 +357,7 @@ void main() #else N.xy = 2.0 * texture2D(u_NormalMap, texCoords).rg - vec2(1.0); #endif + N.xy *= u_EnableTextures.x; N.z = sqrt(1.0 - clamp(dot(N.xy, N.xy), 0.0, 1.0)); #if !defined(USE_TANGENT_SPACE_LIGHT) N = normalize(tangentToWorld * N); @@ -412,6 +418,7 @@ void main() #if defined(USE_SPECULARMAP) vec4 specular = texture2D(u_SpecularMap, texCoords); + specular = mix(vec4(1.0), specular, u_EnableTextures.z); #if defined(USE_GAMMA2_TEXTURES) specular.rgb *= specular.rgb; #endif @@ -470,7 +477,7 @@ void main() R = tangentToWorld * R; #endif - vec3 cubeLightColor = textureCubeLod(u_CubeMap, R, 7.0 - gloss * 7.0).rgb; + vec3 cubeLightColor = textureCubeLod(u_CubeMap, R, 7.0 - gloss * 7.0).rgb * u_EnableTextures.w; #if defined(USE_LIGHTMAP) cubeLightColor *= lightSample.rgb; @@ -480,7 +487,7 @@ void main() cubeLightColor *= lightColor * NL + ambientColor; #endif - //gl_FragColor.rgb += diffuse.rgb * textureCubeLod(u_CubeMap, N, 7.0).rgb; + //gl_FragColor.rgb += diffuse.rgb * textureCubeLod(u_CubeMap, N, 7.0).rgb * u_EnableTextures.w; gl_FragColor.rgb += cubeLightColor * reflectance; #endif diff --git a/src/renderergl2/glsl/lightall_vp.glsl b/src/renderergl2/glsl/lightall_vp.glsl index ce83d10a..284b3973 100644 --- a/src/renderergl2/glsl/lightall_vp.glsl +++ b/src/renderergl2/glsl/lightall_vp.glsl @@ -20,15 +20,19 @@ attribute vec3 attr_Bitangent2; attribute vec3 attr_LightDirection; #endif -#if defined(USE_TCGEN) || defined(USE_NORMALMAP) || defined(USE_LIGHT) && !defined(USE_FAST_LIGHT) +#if defined(USE_DELUXEMAP) +uniform vec4 u_EnableTextures; // x = normal, y = deluxe, z = specular, w = cube +#endif + +#if defined(USE_LIGHT) && !defined(USE_FAST_LIGHT) uniform vec3 u_ViewOrigin; -uniform vec3 u_LocalViewOrigin; #endif #if defined(USE_TCGEN) uniform int u_TCGen0; uniform vec3 u_TCGen0Vector0; uniform vec3 u_TCGen0Vector1; +uniform vec3 u_LocalViewOrigin; #endif #if defined(USE_TCMOD) @@ -51,8 +55,8 @@ uniform float u_VertexLerp; #if defined(USE_LIGHT_VECTOR) uniform vec4 u_LightOrigin; uniform float u_LightRadius; -uniform vec3 u_DirectedLight; #if defined(USE_FAST_LIGHT) +uniform vec3 u_DirectedLight; uniform vec3 u_AmbientLight; #endif #endif @@ -66,7 +70,7 @@ varying vec4 var_TexCoords; varying vec4 var_Color; -#if (defined(USE_LIGHT) && !defined(USE_FAST_LIGHT)) || defined(USE_PARALLAXMAP) +#if defined(USE_LIGHT) && !defined(USE_FAST_LIGHT) varying vec4 var_Normal; varying vec4 var_Tangent; varying vec4 var_Bitangent; @@ -76,7 +80,7 @@ varying vec4 var_Bitangent; varying vec3 var_LightColor; #endif -#if defined(USE_LIGHT) && !defined(USE_DELUXEMAP) && !defined(USE_FAST_LIGHT) +#if defined(USE_LIGHT) && !defined(USE_FAST_LIGHT) varying vec4 var_LightDir; #endif @@ -150,7 +154,7 @@ float CalcLightAttenuation(vec3 dir, float sqrRadius) void main() { #if defined(USE_VERTEX_ANIMATION) - vec3 position = mix(attr_Position, attr_Position2, u_VertexLerp); + vec3 position = mix(attr_Position, attr_Position2, u_VertexLerp); vec3 normal = normalize(mix(attr_Normal, attr_Normal2, u_VertexLerp)); vec3 tangent = normalize(mix(attr_Tangent, attr_Tangent2, u_VertexLerp)); vec3 bitangent = normalize(mix(attr_Bitangent, attr_Bitangent2, u_VertexLerp)); @@ -184,7 +188,7 @@ void main() #if defined(USE_LIGHT_VECTOR) vec3 L = u_LightOrigin.xyz - (position * u_LightOrigin.w); -#elif defined(USE_LIGHT) && !defined(USE_DELUXEMAP) +#elif defined(USE_LIGHT) vec3 L = attr_LightDirection; #if defined(USE_MODELMATRIX) L = (u_ModelMatrix * vec4(L, 0.0)).xyz; @@ -213,15 +217,18 @@ void main() var_PrimaryLightDir.w = u_PrimaryLightRadius * u_PrimaryLightRadius; #endif -#if defined(USE_LIGHT) && !defined(USE_DELUXEMAP) && !defined(USE_FAST_LIGHT) +#if defined(USE_LIGHT) && !defined(USE_FAST_LIGHT) #if defined(USE_LIGHT_VECTOR) var_LightDir = vec4(L, u_LightRadius * u_LightRadius); #else var_LightDir = vec4(L, 0.0); #endif + #if defined(USE_DELUXEMAP) + var_LightDir *= 1.0 - u_EnableTextures.y; + #endif #endif -#if (defined(USE_LIGHT) && !defined(USE_FAST_LIGHT)) || defined(USE_PARALLAXMAP) +#if defined(USE_LIGHT) && !defined(USE_FAST_LIGHT) vec3 viewDir = u_ViewOrigin - position; #endif @@ -232,16 +239,16 @@ void main() var_PrimaryLightDir.xyz = var_PrimaryLightDir.xyz * tangentToWorld; #endif - #if defined(USE_LIGHT) && !defined(USE_DELUXEMAP) && !defined(USE_FAST_LIGHT) + #if defined(USE_LIGHT) && !defined(USE_FAST_LIGHT) var_LightDir.xyz = var_LightDir.xyz * tangentToWorld; #endif - #if (defined(USE_LIGHT) && !defined(USE_FAST_LIGHT)) || defined(USE_PARALLAXMAP) + #if defined(USE_LIGHT) && !defined(USE_FAST_LIGHT) viewDir = viewDir * tangentToWorld; #endif #endif -#if (defined(USE_LIGHT) && !defined(USE_FAST_LIGHT)) || defined(USE_PARALLAXMAP) +#if defined(USE_LIGHT) && !defined(USE_FAST_LIGHT) // store view direction in tangent space to save on varyings var_Normal = vec4(normal, viewDir.x); var_Tangent = vec4(tangent, viewDir.y); diff --git a/src/renderergl2/tr_glsl.c b/src/renderergl2/tr_glsl.c index 8203e68b..d67744f8 100644 --- a/src/renderergl2/tr_glsl.c +++ b/src/renderergl2/tr_glsl.c @@ -84,6 +84,8 @@ static uniformInfo_t uniformsInfo[] = { "u_ShadowMvp2", GLSL_MAT16 }, { "u_ShadowMvp3", GLSL_MAT16 }, + { "u_EnableTextures", GLSL_VEC4 }, + { "u_DiffuseTexMatrix", GLSL_VEC4 }, { "u_DiffuseTexOffTurb", GLSL_VEC4 }, { "u_Texture1Env", GLSL_INT }, @@ -997,27 +999,19 @@ void GLSL_InitGPUShaders(void) for (i = 0; i < LIGHTDEF_COUNT; i++) { + int lightType = i & LIGHTDEF_LIGHTTYPE_MASK; + qboolean fastLight = !(r_normalMapping->integer || r_specularMapping->integer); + // skip impossible combos if ((i & LIGHTDEF_USE_PARALLAXMAP) && !r_parallaxMapping->integer) continue; - if ((i & LIGHTDEF_USE_DELUXEMAP) && !r_deluxeMapping->integer) - continue; - - if ((i & LIGHTDEF_USE_CUBEMAP) && !r_cubeMapping->integer) + if (!lightType && (i & LIGHTDEF_USE_PARALLAXMAP)) continue; - if (!((i & LIGHTDEF_LIGHTTYPE_MASK) == LIGHTDEF_USE_LIGHTMAP) && (i & LIGHTDEF_USE_DELUXEMAP)) + if (!lightType && (i & LIGHTDEF_USE_SHADOWMAP)) continue; - if (!(i & LIGHTDEF_LIGHTTYPE_MASK)) - { - if (i & LIGHTDEF_USE_SHADOWMAP) - continue; - if (i & LIGHTDEF_USE_CUBEMAP) - continue; - } - attribs = ATTR_POSITION | ATTR_TEXCOORD | ATTR_COLOR | ATTR_NORMAL; extradefines[0] = '\0'; @@ -1026,30 +1020,30 @@ void GLSL_InitGPUShaders(void) Q_strcat(extradefines, 1024, va("#define r_deluxeSpecular %f\n", r_deluxeSpecular->value)); if (r_specularIsMetallic->value) - Q_strcat(extradefines, 1024, va("#define SPECULAR_IS_METALLIC\n")); + Q_strcat(extradefines, 1024, "#define SPECULAR_IS_METALLIC\n"); if (r_dlightMode->integer >= 2) Q_strcat(extradefines, 1024, "#define USE_SHADOWMAP\n"); if (1) - { Q_strcat(extradefines, 1024, "#define SWIZZLE_NORMALMAP\n"); - } if (r_hdr->integer && !(glRefConfig.textureFloat && glRefConfig.halfFloatPixel && r_floatLightmap->integer)) Q_strcat(extradefines, 1024, "#define RGBM_LIGHTMAP\n"); - if (i & LIGHTDEF_LIGHTTYPE_MASK) + if (lightType) { Q_strcat(extradefines, 1024, "#define USE_LIGHT\n"); - if (r_normalMapping->integer == 0 && r_specularMapping->integer == 0) + if (fastLight) Q_strcat(extradefines, 1024, "#define USE_FAST_LIGHT\n"); - switch (i & LIGHTDEF_LIGHTTYPE_MASK) + switch (lightType) { case LIGHTDEF_USE_LIGHTMAP: Q_strcat(extradefines, 1024, "#define USE_LIGHTMAP\n"); + if (r_deluxeMapping->integer && !fastLight) + Q_strcat(extradefines, 1024, "#define USE_DELUXEMAP\n"); attribs |= ATTR_LIGHTCOORD | ATTR_LIGHTDIRECTION; break; case LIGHTDEF_USE_LIGHT_VECTOR: @@ -1062,61 +1056,58 @@ void GLSL_InitGPUShaders(void) default: break; } - } - if (r_normalMapping->integer) - { - Q_strcat(extradefines, 1024, "#define USE_NORMALMAP\n"); + if (r_normalMapping->integer) + { + Q_strcat(extradefines, 1024, "#define USE_NORMALMAP\n"); - if (r_normalMapping->integer == 2) - Q_strcat(extradefines, 1024, "#define USE_OREN_NAYAR\n"); + if (r_normalMapping->integer == 2) + Q_strcat(extradefines, 1024, "#define USE_OREN_NAYAR\n"); - if (r_normalMapping->integer == 3) - Q_strcat(extradefines, 1024, "#define USE_TRIACE_OREN_NAYAR\n"); + if (r_normalMapping->integer == 3) + Q_strcat(extradefines, 1024, "#define USE_TRIACE_OREN_NAYAR\n"); #ifdef USE_VERT_TANGENT_SPACE - Q_strcat(extradefines, 1024, "#define USE_VERT_TANGENT_SPACE\n"); - attribs |= ATTR_TANGENT | ATTR_BITANGENT; + Q_strcat(extradefines, 1024, "#define USE_VERT_TANGENT_SPACE\n"); + attribs |= ATTR_TANGENT | ATTR_BITANGENT; #endif - } - if (r_specularMapping->integer) - { - Q_strcat(extradefines, 1024, "#define USE_SPECULARMAP\n"); + if ((i & LIGHTDEF_USE_PARALLAXMAP) && !(i & LIGHTDEF_ENTITY) && r_parallaxMapping->integer) + Q_strcat(extradefines, 1024, "#define USE_PARALLAXMAP\n"); + } - switch (r_specularMapping->integer) + if (r_specularMapping->integer) { - case 1: - default: - Q_strcat(extradefines, 1024, "#define USE_BLINN\n"); - break; - - case 2: - Q_strcat(extradefines, 1024, "#define USE_BLINN_FRESNEL\n"); - break; - - case 3: - Q_strcat(extradefines, 1024, "#define USE_MCAULEY\n"); - break; - - case 4: - Q_strcat(extradefines, 1024, "#define USE_GOTANDA\n"); - break; - - case 5: - Q_strcat(extradefines, 1024, "#define USE_LAZAROV\n"); - break; + Q_strcat(extradefines, 1024, "#define USE_SPECULARMAP\n"); + + switch (r_specularMapping->integer) + { + case 1: + default: + Q_strcat(extradefines, 1024, "#define USE_BLINN\n"); + break; + + case 2: + Q_strcat(extradefines, 1024, "#define USE_BLINN_FRESNEL\n"); + break; + + case 3: + Q_strcat(extradefines, 1024, "#define USE_MCAULEY\n"); + break; + + case 4: + Q_strcat(extradefines, 1024, "#define USE_GOTANDA\n"); + break; + + case 5: + Q_strcat(extradefines, 1024, "#define USE_LAZAROV\n"); + break; + } } - } - if ((i & LIGHTDEF_USE_DELUXEMAP) && r_deluxeMapping->integer) - Q_strcat(extradefines, 1024, "#define USE_DELUXEMAP\n"); - - if ((i & LIGHTDEF_USE_PARALLAXMAP) && !(i & LIGHTDEF_ENTITY) && r_parallaxMapping->integer) - Q_strcat(extradefines, 1024, "#define USE_PARALLAXMAP\n"); - - if ((i & LIGHTDEF_USE_CUBEMAP)) - Q_strcat(extradefines, 1024, "#define USE_CUBEMAP\n"); + if (r_cubeMapping->integer) + Q_strcat(extradefines, 1024, "#define USE_CUBEMAP\n"); + } if (i & LIGHTDEF_USE_SHADOWMAP) { diff --git a/src/renderergl2/tr_image.c b/src/renderergl2/tr_image.c index f4a4d9fa..2467aac8 100644 --- a/src/renderergl2/tr_image.c +++ b/src/renderergl2/tr_image.c @@ -2876,9 +2876,6 @@ void R_CreateBuiltinImages( void ) { Com_Memset( data, 255, sizeof( data ) ); tr.whiteImage = R_CreateImage("*white", (byte *)data, 8, 8, IMGTYPE_COLORALPHA, IMGFLAG_NONE, 0); - Com_Memset( data, 128, sizeof( data ) ); - tr.greyImage = R_CreateImage("*grey", (byte *)data, 8, 8, IMGTYPE_COLORALPHA, IMGFLAG_NONE, GL_RGBA8); - if (r_dlightMode->integer >= 2) { for( x = 0; x < MAX_DLIGHTS; x++) diff --git a/src/renderergl2/tr_local.h b/src/renderergl2/tr_local.h index 94659fcc..da3edba2 100644 --- a/src/renderergl2/tr_local.h +++ b/src/renderergl2/tr_local.h @@ -681,12 +681,10 @@ enum LIGHTDEF_LIGHTTYPE_MASK = 0x0003, LIGHTDEF_ENTITY = 0x0004, LIGHTDEF_USE_TCGEN_AND_TCMOD = 0x0008, - LIGHTDEF_USE_DELUXEMAP = 0x0010, - LIGHTDEF_USE_PARALLAXMAP = 0x0020, - LIGHTDEF_USE_SHADOWMAP = 0x0040, - LIGHTDEF_USE_CUBEMAP = 0x0080, - LIGHTDEF_ALL = 0x00FF, - LIGHTDEF_COUNT = 0x0100 + LIGHTDEF_USE_PARALLAXMAP = 0x0010, + LIGHTDEF_USE_SHADOWMAP = 0x0020, + LIGHTDEF_ALL = 0x003F, + LIGHTDEF_COUNT = 0x0040 }; enum @@ -723,6 +721,8 @@ typedef enum UNIFORM_SHADOWMVP2, UNIFORM_SHADOWMVP3, + UNIFORM_ENABLETEXTURES, + UNIFORM_DIFFUSETEXMATRIX, UNIFORM_DIFFUSETEXOFFTURB, UNIFORM_TEXTURE1ENV, @@ -1610,7 +1610,6 @@ typedef struct { image_t *fogImage; image_t *dlightImage; // inverse-quare highlight for projective adding image_t *flareImage; - image_t *greyImage; // full of 0x80 image_t *whiteImage; // full of 0xff image_t *identityLightImage; // full of tr.identityLightByte diff --git a/src/renderergl2/tr_shade.c b/src/renderergl2/tr_shade.c index 06dc94b6..d6837b2a 100644 --- a/src/renderergl2/tr_shade.c +++ b/src/renderergl2/tr_shade.c @@ -731,7 +731,7 @@ static void ForwardDlight( void ) { { int index = pStage->glslShaderIndex; - index &= ~(LIGHTDEF_LIGHTTYPE_MASK | LIGHTDEF_USE_DELUXEMAP); + index &= ~LIGHTDEF_LIGHTTYPE_MASK; index |= LIGHTDEF_USE_LIGHT_VECTOR; sp = &tr.lightallShader[index]; @@ -1099,11 +1099,6 @@ static void RB_IterateStagesGeneric( shaderCommands_t *input ) index |= LIGHTDEF_USE_SHADOWMAP; } - if (!(tr.viewParms.flags & VPF_NOCUBEMAPS) && (index & LIGHTDEF_LIGHTTYPE_MASK) && input->cubemapIndex) - { - index |= LIGHTDEF_USE_CUBEMAP; - } - if (r_lightmap->integer && index & LIGHTDEF_USE_LIGHTMAP) { index = LIGHTDEF_USE_LIGHTMAP; @@ -1229,6 +1224,7 @@ static void RB_IterateStagesGeneric( shaderCommands_t *input ) else if ( pStage->glslShaderGroup == tr.lightallShader ) { int i; + vec4_t enableTextures; if ((backEnd.viewParms.flags & VPF_USESUNLIGHT) && (pStage->glslShaderIndex & LIGHTDEF_LIGHTTYPE_MASK)) { @@ -1238,73 +1234,78 @@ static void RB_IterateStagesGeneric( shaderCommands_t *input ) GLSL_SetUniformVec4(sp, UNIFORM_PRIMARYLIGHTORIGIN, backEnd.refdef.sunDir); } + VectorSet4(enableTextures, 0, 0, 0, 0); if ((r_lightmap->integer == 1 || r_lightmap->integer == 2) && pStage->bundle[TB_LIGHTMAP].image[0]) { for (i = 0; i < NUM_TEXTURE_BUNDLES; i++) { - if (pStage->bundle[i].image[0]) - { - switch(i) - { - case TB_LIGHTMAP: - R_BindAnimatedImageToTMU( &pStage->bundle[TB_LIGHTMAP], i); - break; - - case TB_DIFFUSEMAP: - case TB_SPECULARMAP: - case TB_SHADOWMAP: - case TB_CUBEMAP: - default: - GL_BindToTMU( tr.whiteImage, i); - break; - - case TB_NORMALMAP: - case TB_DELUXEMAP: - GL_BindToTMU( tr.greyImage, i); - break; - } - } + if (i == TB_LIGHTMAP) + R_BindAnimatedImageToTMU( &pStage->bundle[TB_LIGHTMAP], i); + else + GL_BindToTMU( tr.whiteImage, i ); } } else if (r_lightmap->integer == 3 && pStage->bundle[TB_DELUXEMAP].image[0]) { for (i = 0; i < NUM_TEXTURE_BUNDLES; i++) { - if (pStage->bundle[i].image[0]) - { - switch(i) - { - case TB_LIGHTMAP: - R_BindAnimatedImageToTMU( &pStage->bundle[TB_DELUXEMAP], i); - break; - - case TB_DIFFUSEMAP: - case TB_SPECULARMAP: - case TB_SHADOWMAP: - case TB_CUBEMAP: - default: - GL_BindToTMU( tr.whiteImage, i); - break; - - case TB_NORMALMAP: - case TB_DELUXEMAP: - GL_BindToTMU( tr.greyImage, i); - break; - } - } + if (i == TB_LIGHTMAP) + R_BindAnimatedImageToTMU( &pStage->bundle[TB_DELUXEMAP], i); + else + GL_BindToTMU( tr.whiteImage, i ); } - } else { - for (i = 0; i < NUM_TEXTURE_BUNDLES; i++) + qboolean light = (pStage->glslShaderIndex & LIGHTDEF_LIGHTTYPE_MASK) != 0; + qboolean fastLight = !(r_normalMapping->integer || r_specularMapping->integer); + + if (pStage->bundle[TB_DIFFUSEMAP].image[0]) + R_BindAnimatedImageToTMU( &pStage->bundle[TB_DIFFUSEMAP], TB_DIFFUSEMAP); + + if (pStage->bundle[TB_LIGHTMAP].image[0]) + R_BindAnimatedImageToTMU( &pStage->bundle[TB_LIGHTMAP], TB_LIGHTMAP); + + // bind textures that are sampled and used in the glsl shader, and + // bind whiteImage to textures that are sampled but zeroed in the glsl shader + // + // alternatives: + // - use the last bound texture + // -> costs more to sample a higher res texture then throw out the result + // - disable texture sampling in glsl shader with #ifdefs, as before + // -> increases the number of shaders that must be compiled + // + if (light && !fastLight) { - if (pStage->bundle[i].image[0]) + if (pStage->bundle[TB_NORMALMAP].image[0]) { - R_BindAnimatedImageToTMU( &pStage->bundle[i], i); + R_BindAnimatedImageToTMU( &pStage->bundle[TB_NORMALMAP], TB_NORMALMAP); + enableTextures[0] = 1.0f; } + else if (r_normalMapping->integer) + GL_BindToTMU( tr.whiteImage, TB_NORMALMAP ); + + if (pStage->bundle[TB_DELUXEMAP].image[0]) + { + R_BindAnimatedImageToTMU( &pStage->bundle[TB_DELUXEMAP], TB_DELUXEMAP); + enableTextures[1] = 1.0f; + } + else if (r_deluxeMapping->integer) + GL_BindToTMU( tr.whiteImage, TB_DELUXEMAP ); + + if (pStage->bundle[TB_SPECULARMAP].image[0]) + { + R_BindAnimatedImageToTMU( &pStage->bundle[TB_SPECULARMAP], TB_SPECULARMAP); + enableTextures[2] = 1.0f; + } + else if (r_specularMapping->integer) + GL_BindToTMU( tr.whiteImage, TB_SPECULARMAP ); } + + enableTextures[3] = (r_cubeMapping->integer && !(tr.viewParms.flags & VPF_NOCUBEMAPS) && input->cubemapIndex) ? 1.0f : 0.0f; } + + GLSL_SetUniformVec4(sp, UNIFORM_ENABLETEXTURES, enableTextures); } else if ( pStage->bundle[1].image[0] != 0 ) { diff --git a/src/renderergl2/tr_shader.c b/src/renderergl2/tr_shader.c index c27e016f..836fb5b8 100644 --- a/src/renderergl2/tr_shader.c +++ b/src/renderergl2/tr_shader.c @@ -2209,7 +2209,6 @@ static void CollapseStagesToLightall(shaderStage_t *diffuse, //ri.Printf(PRINT_ALL, ", deluxemap"); diffuse->bundle[TB_DELUXEMAP] = lightmap->bundle[0]; diffuse->bundle[TB_DELUXEMAP].image[0] = tr.deluxemaps[shader.lightmapIndex]; - defs |= LIGHTDEF_USE_DELUXEMAP; } if (r_normalMapping->integer) @@ -2526,8 +2525,6 @@ static qboolean CollapseStagesToGLSL(void) { pStage->glslShaderGroup = tr.lightallShader; pStage->glslShaderIndex = LIGHTDEF_USE_LIGHTMAP; - if (r_deluxeMapping->integer && tr.worldDeluxeMapping) - pStage->glslShaderIndex |= LIGHTDEF_USE_DELUXEMAP; pStage->bundle[TB_LIGHTMAP] = pStage->bundle[TB_DIFFUSEMAP]; pStage->bundle[TB_DIFFUSEMAP].image[0] = tr.whiteImage; pStage->bundle[TB_DIFFUSEMAP].isLightmap = qfalse; @@ -2560,7 +2557,7 @@ static qboolean CollapseStagesToGLSL(void) } } - // insert default normal and specular textures if necessary + // insert default material info if needed for (i = 0; i < MAX_SHADER_STAGES; i++) { shaderStage_t *pStage = &stages[i]; @@ -2574,14 +2571,8 @@ static qboolean CollapseStagesToGLSL(void) if ((pStage->glslShaderIndex & LIGHTDEF_LIGHTTYPE_MASK) == 0) continue; - if (!pStage->bundle[TB_NORMALMAP].image[0] && r_normalMapping->integer) - { - pStage->bundle[TB_NORMALMAP].image[0] = tr.greyImage; - } - if (!pStage->bundle[TB_SPECULARMAP].image[0] && r_specularMapping->integer) { - pStage->bundle[TB_SPECULARMAP].image[0] = tr.whiteImage; if (!pStage->materialInfo[0]) pStage->materialInfo[0] = r_baseSpecular->value; if (!pStage->materialInfo[1]) |