OpenGL2: remove lightmap support from generic glsl shader.
This path was barely used and doing this compiles fewer shaders.
This commit is contained in:
parent
1d016e6ff5
commit
b1821e303d
6 changed files with 3 additions and 238 deletions
|
@ -1,45 +1,12 @@
|
||||||
uniform sampler2D u_DiffuseMap;
|
uniform sampler2D u_DiffuseMap;
|
||||||
|
|
||||||
#if defined(USE_LIGHTMAP)
|
|
||||||
uniform sampler2D u_LightMap;
|
|
||||||
|
|
||||||
uniform int u_Texture1Env;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
varying vec2 var_DiffuseTex;
|
varying vec2 var_DiffuseTex;
|
||||||
|
|
||||||
#if defined(USE_LIGHTMAP)
|
|
||||||
varying vec2 var_LightTex;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
varying vec4 var_Color;
|
varying vec4 var_Color;
|
||||||
|
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
vec4 color = texture2D(u_DiffuseMap, var_DiffuseTex);
|
vec4 color = texture2D(u_DiffuseMap, var_DiffuseTex);
|
||||||
#if defined(USE_LIGHTMAP)
|
|
||||||
vec4 color2 = texture2D(u_LightMap, var_LightTex);
|
|
||||||
#if defined(RGBM_LIGHTMAP)
|
|
||||||
color2.rgb *= color2.a;
|
|
||||||
color2.a = 1.0;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (u_Texture1Env == TEXENV_MODULATE)
|
|
||||||
{
|
|
||||||
color *= color2;
|
|
||||||
}
|
|
||||||
else if (u_Texture1Env == TEXENV_ADD)
|
|
||||||
{
|
|
||||||
color += color2;
|
|
||||||
}
|
|
||||||
else if (u_Texture1Env == TEXENV_REPLACE)
|
|
||||||
{
|
|
||||||
color = color2;
|
|
||||||
}
|
|
||||||
|
|
||||||
//color = color * (u_Texture1Env.xxxx + color2 * u_Texture1Env.z) + color2 * u_Texture1Env.y;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
gl_FragColor = color * var_Color;
|
gl_FragColor = color * var_Color;
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,7 @@ attribute vec3 attr_Normal2;
|
||||||
attribute vec4 attr_Color;
|
attribute vec4 attr_Color;
|
||||||
attribute vec4 attr_TexCoord0;
|
attribute vec4 attr_TexCoord0;
|
||||||
|
|
||||||
#if defined(USE_LIGHTMAP) || defined(USE_TCGEN)
|
#if defined(USE_TCGEN)
|
||||||
attribute vec4 attr_TexCoord1;
|
attribute vec4 attr_TexCoord1;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -57,9 +57,6 @@ uniform float u_VertexLerp;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
varying vec2 var_DiffuseTex;
|
varying vec2 var_DiffuseTex;
|
||||||
#if defined(USE_LIGHTMAP)
|
|
||||||
varying vec2 var_LightTex;
|
|
||||||
#endif
|
|
||||||
varying vec4 var_Color;
|
varying vec4 var_Color;
|
||||||
|
|
||||||
#if defined(USE_DEFORM_VERTEXES)
|
#if defined(USE_DEFORM_VERTEXES)
|
||||||
|
@ -230,10 +227,6 @@ void main()
|
||||||
var_DiffuseTex = tex;
|
var_DiffuseTex = tex;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(USE_LIGHTMAP)
|
|
||||||
var_LightTex = attr_TexCoord1.st;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(USE_RGBAGEN)
|
#if defined(USE_RGBAGEN)
|
||||||
var_Color = CalcColor(position, normal);
|
var_Color = CalcColor(position, normal);
|
||||||
#else
|
#else
|
||||||
|
|
|
@ -90,7 +90,6 @@ static uniformInfo_t uniformsInfo[] =
|
||||||
|
|
||||||
{ "u_DiffuseTexMatrix", GLSL_VEC4 },
|
{ "u_DiffuseTexMatrix", GLSL_VEC4 },
|
||||||
{ "u_DiffuseTexOffTurb", GLSL_VEC4 },
|
{ "u_DiffuseTexOffTurb", GLSL_VEC4 },
|
||||||
{ "u_Texture1Env", GLSL_INT },
|
|
||||||
|
|
||||||
{ "u_TCGen0", GLSL_INT },
|
{ "u_TCGen0", GLSL_INT },
|
||||||
{ "u_TCGen0Vector0", GLSL_VEC3 },
|
{ "u_TCGen0Vector0", GLSL_VEC3 },
|
||||||
|
@ -919,12 +918,6 @@ void GLSL_InitGPUShaders(void)
|
||||||
if (i & GENERICDEF_USE_RGBAGEN)
|
if (i & GENERICDEF_USE_RGBAGEN)
|
||||||
Q_strcat(extradefines, 1024, "#define USE_RGBAGEN\n");
|
Q_strcat(extradefines, 1024, "#define USE_RGBAGEN\n");
|
||||||
|
|
||||||
if (i & GENERICDEF_USE_LIGHTMAP)
|
|
||||||
Q_strcat(extradefines, 1024, "#define USE_LIGHTMAP\n");
|
|
||||||
|
|
||||||
if (r_hdr->integer && !glRefConfig.floatLightmap)
|
|
||||||
Q_strcat(extradefines, 1024, "#define RGBM_LIGHTMAP\n");
|
|
||||||
|
|
||||||
if (!GLSL_InitGPUShader(&tr.genericShader[i], "generic", attribs, qtrue, extradefines, qtrue, fallbackShader_generic_vp, fallbackShader_generic_fp))
|
if (!GLSL_InitGPUShader(&tr.genericShader[i], "generic", attribs, qtrue, extradefines, qtrue, fallbackShader_generic_vp, fallbackShader_generic_fp))
|
||||||
{
|
{
|
||||||
ri.Error(ERR_FATAL, "Could not load generic shader!");
|
ri.Error(ERR_FATAL, "Could not load generic shader!");
|
||||||
|
@ -1495,11 +1488,6 @@ shaderProgram_t *GLSL_GetGenericShaderProgram(int stage)
|
||||||
shaderAttribs |= GENERICDEF_USE_FOG;
|
shaderAttribs |= GENERICDEF_USE_FOG;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pStage->bundle[1].image[0] && tess.shader->multitextureEnv)
|
|
||||||
{
|
|
||||||
shaderAttribs |= GENERICDEF_USE_LIGHTMAP;
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (pStage->rgbGen)
|
switch (pStage->rgbGen)
|
||||||
{
|
{
|
||||||
case CGEN_LIGHTING_DIFFUSE:
|
case CGEN_LIGHTING_DIFFUSE:
|
||||||
|
|
|
@ -451,8 +451,6 @@ typedef struct shader_s {
|
||||||
float portalRange; // distance to fog out at
|
float portalRange; // distance to fog out at
|
||||||
qboolean isPortal;
|
qboolean isPortal;
|
||||||
|
|
||||||
int multitextureEnv; // 0, GL_MODULATE, GL_ADD (FIXME: put in stage)
|
|
||||||
|
|
||||||
cullType_t cullType; // CT_FRONT_SIDED, CT_BACK_SIDED, or CT_TWO_SIDED
|
cullType_t cullType; // CT_FRONT_SIDED, CT_BACK_SIDED, or CT_TWO_SIDED
|
||||||
qboolean polygonOffset; // set for decals and other items that must be offset
|
qboolean polygonOffset; // set for decals and other items that must be offset
|
||||||
qboolean noMipMaps; // for console fonts, 2D elements, etc.
|
qboolean noMipMaps; // for console fonts, 2D elements, etc.
|
||||||
|
@ -563,9 +561,8 @@ enum
|
||||||
GENERICDEF_USE_VERTEX_ANIMATION = 0x0004,
|
GENERICDEF_USE_VERTEX_ANIMATION = 0x0004,
|
||||||
GENERICDEF_USE_FOG = 0x0008,
|
GENERICDEF_USE_FOG = 0x0008,
|
||||||
GENERICDEF_USE_RGBAGEN = 0x0010,
|
GENERICDEF_USE_RGBAGEN = 0x0010,
|
||||||
GENERICDEF_USE_LIGHTMAP = 0x0020,
|
GENERICDEF_ALL = 0x001F,
|
||||||
GENERICDEF_ALL = 0x003F,
|
GENERICDEF_COUNT = 0x0020,
|
||||||
GENERICDEF_COUNT = 0x0040,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
enum
|
enum
|
||||||
|
@ -637,7 +634,6 @@ typedef enum
|
||||||
|
|
||||||
UNIFORM_DIFFUSETEXMATRIX,
|
UNIFORM_DIFFUSETEXMATRIX,
|
||||||
UNIFORM_DIFFUSETEXOFFTURB,
|
UNIFORM_DIFFUSETEXOFFTURB,
|
||||||
UNIFORM_TEXTURE1ENV,
|
|
||||||
|
|
||||||
UNIFORM_TCGEN0,
|
UNIFORM_TCGEN0,
|
||||||
UNIFORM_TCGEN0VECTOR0,
|
UNIFORM_TCGEN0VECTOR0,
|
||||||
|
|
|
@ -1351,16 +1351,6 @@ static void RB_IterateStagesGeneric( shaderCommands_t *input )
|
||||||
else if ( pStage->bundle[1].image[0] != 0 )
|
else if ( pStage->bundle[1].image[0] != 0 )
|
||||||
{
|
{
|
||||||
R_BindAnimatedImageToTMU( &pStage->bundle[0], 0 );
|
R_BindAnimatedImageToTMU( &pStage->bundle[0], 0 );
|
||||||
|
|
||||||
//
|
|
||||||
// lightmap/secondary pass
|
|
||||||
//
|
|
||||||
if ( r_lightmap->integer ) {
|
|
||||||
GLSL_SetUniformInt(sp, UNIFORM_TEXTURE1ENV, GL_REPLACE);
|
|
||||||
} else {
|
|
||||||
GLSL_SetUniformInt(sp, UNIFORM_TEXTURE1ENV, tess.shader->multitextureEnv);
|
|
||||||
}
|
|
||||||
|
|
||||||
R_BindAnimatedImageToTMU( &pStage->bundle[1], 1 );
|
R_BindAnimatedImageToTMU( &pStage->bundle[1], 1 );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -1369,8 +1359,6 @@ static void RB_IterateStagesGeneric( shaderCommands_t *input )
|
||||||
// set state
|
// set state
|
||||||
//
|
//
|
||||||
R_BindAnimatedImageToTMU( &pStage->bundle[0], 0 );
|
R_BindAnimatedImageToTMU( &pStage->bundle[0], 0 );
|
||||||
|
|
||||||
GLSL_SetUniformInt(sp, UNIFORM_TEXTURE1ENV, 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|
|
@ -2122,161 +2122,6 @@ static void ComputeVertexAttribs(void)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
int blendA;
|
|
||||||
int blendB;
|
|
||||||
|
|
||||||
int multitextureEnv;
|
|
||||||
int multitextureBlend;
|
|
||||||
} collapse_t;
|
|
||||||
|
|
||||||
static collapse_t collapse[] = {
|
|
||||||
{ 0, GLS_DSTBLEND_SRC_COLOR | GLS_SRCBLEND_ZERO,
|
|
||||||
GL_MODULATE, 0 },
|
|
||||||
|
|
||||||
{ 0, GLS_DSTBLEND_ZERO | GLS_SRCBLEND_DST_COLOR,
|
|
||||||
GL_MODULATE, 0 },
|
|
||||||
|
|
||||||
{ GLS_DSTBLEND_ZERO | GLS_SRCBLEND_DST_COLOR, GLS_DSTBLEND_ZERO | GLS_SRCBLEND_DST_COLOR,
|
|
||||||
GL_MODULATE, GLS_DSTBLEND_ZERO | GLS_SRCBLEND_DST_COLOR },
|
|
||||||
|
|
||||||
{ GLS_DSTBLEND_SRC_COLOR | GLS_SRCBLEND_ZERO, GLS_DSTBLEND_ZERO | GLS_SRCBLEND_DST_COLOR,
|
|
||||||
GL_MODULATE, GLS_DSTBLEND_ZERO | GLS_SRCBLEND_DST_COLOR },
|
|
||||||
|
|
||||||
{ GLS_DSTBLEND_ZERO | GLS_SRCBLEND_DST_COLOR, GLS_DSTBLEND_SRC_COLOR | GLS_SRCBLEND_ZERO,
|
|
||||||
GL_MODULATE, GLS_DSTBLEND_ZERO | GLS_SRCBLEND_DST_COLOR },
|
|
||||||
|
|
||||||
{ GLS_DSTBLEND_SRC_COLOR | GLS_SRCBLEND_ZERO, GLS_DSTBLEND_SRC_COLOR | GLS_SRCBLEND_ZERO,
|
|
||||||
GL_MODULATE, GLS_DSTBLEND_ZERO | GLS_SRCBLEND_DST_COLOR },
|
|
||||||
|
|
||||||
{ 0, GLS_DSTBLEND_ONE | GLS_SRCBLEND_ONE,
|
|
||||||
GL_ADD, 0 },
|
|
||||||
|
|
||||||
{ GLS_DSTBLEND_ONE | GLS_SRCBLEND_ONE, GLS_DSTBLEND_ONE | GLS_SRCBLEND_ONE,
|
|
||||||
GL_ADD, GLS_DSTBLEND_ONE | GLS_SRCBLEND_ONE },
|
|
||||||
#if 0
|
|
||||||
{ 0, GLS_DSTBLEND_ONE_MINUS_SRC_ALPHA | GLS_SRCBLEND_SRC_ALPHA,
|
|
||||||
GL_DECAL, 0 },
|
|
||||||
#endif
|
|
||||||
{ -1 }
|
|
||||||
};
|
|
||||||
|
|
||||||
/*
|
|
||||||
================
|
|
||||||
CollapseMultitexture
|
|
||||||
|
|
||||||
Attempt to combine two stages into a single multitexture stage
|
|
||||||
FIXME: I think modulated add + modulated add collapses incorrectly
|
|
||||||
=================
|
|
||||||
*/
|
|
||||||
static qboolean CollapseMultitexture( void ) {
|
|
||||||
int abits, bbits;
|
|
||||||
int i;
|
|
||||||
textureBundle_t tmpBundle;
|
|
||||||
|
|
||||||
if ( !qglActiveTextureARB ) {
|
|
||||||
return qfalse;
|
|
||||||
}
|
|
||||||
|
|
||||||
// make sure both stages are active
|
|
||||||
if ( !stages[0].active || !stages[1].active ) {
|
|
||||||
return qfalse;
|
|
||||||
}
|
|
||||||
|
|
||||||
// on voodoo2, don't combine different tmus
|
|
||||||
if ( glConfig.driverType == GLDRV_VOODOO ) {
|
|
||||||
if ( stages[0].bundle[0].image[0]->TMU ==
|
|
||||||
stages[1].bundle[0].image[0]->TMU ) {
|
|
||||||
return qfalse;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
abits = stages[0].stateBits;
|
|
||||||
bbits = stages[1].stateBits;
|
|
||||||
|
|
||||||
// make sure that both stages have identical state other than blend modes
|
|
||||||
if ( ( abits & ~( GLS_DSTBLEND_BITS | GLS_SRCBLEND_BITS | GLS_DEPTHMASK_TRUE ) ) !=
|
|
||||||
( bbits & ~( GLS_DSTBLEND_BITS | GLS_SRCBLEND_BITS | GLS_DEPTHMASK_TRUE ) ) ) {
|
|
||||||
return qfalse;
|
|
||||||
}
|
|
||||||
|
|
||||||
abits &= ( GLS_DSTBLEND_BITS | GLS_SRCBLEND_BITS );
|
|
||||||
bbits &= ( GLS_DSTBLEND_BITS | GLS_SRCBLEND_BITS );
|
|
||||||
|
|
||||||
// search for a valid multitexture blend function
|
|
||||||
for ( i = 0; collapse[i].blendA != -1 ; i++ ) {
|
|
||||||
if ( abits == collapse[i].blendA
|
|
||||||
&& bbits == collapse[i].blendB ) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// nothing found
|
|
||||||
if ( collapse[i].blendA == -1 ) {
|
|
||||||
return qfalse;
|
|
||||||
}
|
|
||||||
|
|
||||||
// GL_ADD is a separate extension
|
|
||||||
if ( collapse[i].multitextureEnv == GL_ADD && !glConfig.textureEnvAddAvailable ) {
|
|
||||||
return qfalse;
|
|
||||||
}
|
|
||||||
|
|
||||||
// make sure waveforms have identical parameters
|
|
||||||
if ( ( stages[0].rgbGen != stages[1].rgbGen ) ||
|
|
||||||
( stages[0].alphaGen != stages[1].alphaGen ) ) {
|
|
||||||
return qfalse;
|
|
||||||
}
|
|
||||||
|
|
||||||
// an add collapse can only have identity colors
|
|
||||||
if ( collapse[i].multitextureEnv == GL_ADD && stages[0].rgbGen != CGEN_IDENTITY ) {
|
|
||||||
return qfalse;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( stages[0].rgbGen == CGEN_WAVEFORM )
|
|
||||||
{
|
|
||||||
if ( memcmp( &stages[0].rgbWave,
|
|
||||||
&stages[1].rgbWave,
|
|
||||||
sizeof( stages[0].rgbWave ) ) )
|
|
||||||
{
|
|
||||||
return qfalse;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if ( stages[0].alphaGen == AGEN_WAVEFORM )
|
|
||||||
{
|
|
||||||
if ( memcmp( &stages[0].alphaWave,
|
|
||||||
&stages[1].alphaWave,
|
|
||||||
sizeof( stages[0].alphaWave ) ) )
|
|
||||||
{
|
|
||||||
return qfalse;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// make sure that lightmaps are in bundle 1 for 3dfx
|
|
||||||
if ( stages[0].bundle[0].isLightmap )
|
|
||||||
{
|
|
||||||
tmpBundle = stages[0].bundle[0];
|
|
||||||
stages[0].bundle[0] = stages[1].bundle[0];
|
|
||||||
stages[0].bundle[1] = tmpBundle;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
stages[0].bundle[1] = stages[1].bundle[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
// set the new blend state bits
|
|
||||||
shader.multitextureEnv = collapse[i].multitextureEnv;
|
|
||||||
stages[0].stateBits &= ~( GLS_DSTBLEND_BITS | GLS_SRCBLEND_BITS );
|
|
||||||
stages[0].stateBits |= collapse[i].multitextureBlend;
|
|
||||||
|
|
||||||
//
|
|
||||||
// move down subsequent shaders
|
|
||||||
//
|
|
||||||
memmove( &stages[1], &stages[2], sizeof( stages[0] ) * ( MAX_SHADER_STAGES - 2 ) );
|
|
||||||
Com_Memset( &stages[MAX_SHADER_STAGES-1], 0, sizeof( stages[0] ) );
|
|
||||||
|
|
||||||
return qtrue;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void CollapseStagesToLightall(shaderStage_t *diffuse,
|
static void CollapseStagesToLightall(shaderStage_t *diffuse,
|
||||||
shaderStage_t *normal, shaderStage_t *specular, shaderStage_t *lightmap,
|
shaderStage_t *normal, shaderStage_t *specular, shaderStage_t *lightmap,
|
||||||
|
@ -2607,9 +2452,6 @@ static int CollapseStagesToGLSL(void)
|
||||||
numStages++;
|
numStages++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (numStages == i && i >= 2 && CollapseMultitexture())
|
|
||||||
numStages--;
|
|
||||||
|
|
||||||
// convert any remaining lightmap stages to a lighting pass with a white texture
|
// convert any remaining lightmap stages to a lighting pass with a white texture
|
||||||
// only do this with r_sunlightMode non-zero, as it's only for correct shadows.
|
// only do this with r_sunlightMode non-zero, as it's only for correct shadows.
|
||||||
if (r_sunlightMode->integer && shader.numDeforms == 0)
|
if (r_sunlightMode->integer && shader.numDeforms == 0)
|
||||||
|
@ -3647,15 +3489,6 @@ void R_ShaderList_f (void) {
|
||||||
} else {
|
} else {
|
||||||
ri.Printf (PRINT_ALL, " ");
|
ri.Printf (PRINT_ALL, " ");
|
||||||
}
|
}
|
||||||
if ( shader->multitextureEnv == GL_ADD ) {
|
|
||||||
ri.Printf( PRINT_ALL, "MT(a) " );
|
|
||||||
} else if ( shader->multitextureEnv == GL_MODULATE ) {
|
|
||||||
ri.Printf( PRINT_ALL, "MT(m) " );
|
|
||||||
} else if ( shader->multitextureEnv == GL_DECAL ) {
|
|
||||||
ri.Printf( PRINT_ALL, "MT(d) " );
|
|
||||||
} else {
|
|
||||||
ri.Printf( PRINT_ALL, " " );
|
|
||||||
}
|
|
||||||
if ( shader->explicitlyDefined ) {
|
if ( shader->explicitlyDefined ) {
|
||||||
ri.Printf( PRINT_ALL, "E " );
|
ri.Printf( PRINT_ALL, "E " );
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue