OpenGL2: Fix merged lightmap hacks to have real lightmap index

This fixes the texcoord range to be 0.0 to 1.0 for external lightmaps in
shaders that also have an internal lightmap. (Instead of 2.0 to 3.0 for
example.) This only affects clampMap as repeating wrapping sampled the
correct location. I haven't found such a shader but I need to get real
lightmap index for future merged lightmap hacks.
This commit is contained in:
Zack Middleton 2024-02-09 09:48:51 -06:00
parent 7426ac2176
commit eaefa35580
3 changed files with 17 additions and 6 deletions

View file

@ -617,7 +617,7 @@ static shader_t *ShaderForShaderNum( int shaderNum, int lightmapNum ) {
lightmapNum = LIGHTMAP_WHITEIMAGE;
}
shader = R_FindShader( dsh->shader, lightmapNum, qtrue );
shader = R_FindShaderEx( dsh->shader, FatLightmap( lightmapNum ), qtrue, lightmapNum );
// if the shader had errors, just use default shader
if ( shader->defaultShader ) {
@ -706,7 +706,7 @@ static void ParseFace( dsurface_t *ds, drawVert_t *verts, float *hdrVertColors,
surf->fogIndex = LittleLong( ds->fogNum ) + 1;
// get shader value
surf->shader = ShaderForShaderNum( ds->shaderNum, FatLightmap(realLightmapNum) );
surf->shader = ShaderForShaderNum( ds->shaderNum, realLightmapNum );
if ( r_singleShader->integer && !surf->shader->isSky ) {
surf->shader = tr.defaultShader;
}
@ -813,7 +813,7 @@ static void ParseMesh ( dsurface_t *ds, drawVert_t *verts, float *hdrVertColors,
surf->fogIndex = LittleLong( ds->fogNum ) + 1;
// get shader value
surf->shader = ShaderForShaderNum( ds->shaderNum, FatLightmap(realLightmapNum) );
surf->shader = ShaderForShaderNum( ds->shaderNum, realLightmapNum );
if ( r_singleShader->integer && !surf->shader->isSky ) {
surf->shader = tr.defaultShader;
}

View file

@ -1995,6 +1995,7 @@ const void *RB_TakeVideoFrameCmd( const void *data );
// tr_shader.c
//
shader_t *R_FindShader( const char *name, int lightmapIndex, qboolean mipRawImage );
shader_t *R_FindShaderEx( const char *name, int lightmapIndex, qboolean mipRawImage, int realLightmapIndex );
shader_t *R_GetShaderByHandle( qhandle_t hShader );
shader_t *R_GetShaderByState( int index, long *cycleTime );
shader_t *R_FindShaderByName( const char *name );

View file

@ -30,6 +30,7 @@ static char *s_shaderText;
static shaderStage_t stages[MAX_SHADER_STAGES];
static shader_t shader;
static texModInfo_t texMods[MAX_SHADER_STAGES][TR_MAX_TEXMODS];
static int shader_realLightmapIndex;
#define FILE_HASH_SIZE 1024
static shader_t* hashTable[FILE_HASH_SIZE];
@ -2929,7 +2930,7 @@ static void FixFatLightmapTexCoords(void)
return;
}
lightmapnum = shader.lightmapIndex;
lightmapnum = shader_realLightmapIndex;
if (tr.worldDeluxeMapping)
lightmapnum >>= 1;
@ -2987,7 +2988,7 @@ static void FixFatLightmapTexCoords(void)
InitShader
===============
*/
static void InitShader( const char *name, int lightmapIndex ) {
static void InitShaderEx( const char *name, int lightmapIndex, int realLightmapIndex ) {
int i;
// clear the global shader
@ -2996,6 +2997,7 @@ static void InitShader( const char *name, int lightmapIndex ) {
Q_strncpyz( shader.name, name, sizeof( shader.name ) );
shader.lightmapIndex = lightmapIndex;
shader_realLightmapIndex = realLightmapIndex;
for ( i = 0 ; i < MAX_SHADER_STAGES ; i++ ) {
stages[i].bundle[0].texMods = texMods[i];
@ -3016,6 +3018,10 @@ static void InitShader( const char *name, int lightmapIndex ) {
}
}
static void InitShader( const char *name, int lightmapIndex ) {
InitShaderEx( name, lightmapIndex, lightmapIndex );
}
/*
=========================
FinishShader
@ -3337,6 +3343,10 @@ most world construction surfaces.
===============
*/
shader_t *R_FindShader( const char *name, int lightmapIndex, qboolean mipRawImage ) {
return R_FindShaderEx( name, lightmapIndex, mipRawImage, lightmapIndex );
}
shader_t *R_FindShaderEx( const char *name, int lightmapIndex, qboolean mipRawImage, int realLightmapIndex ) {
char strippedName[MAX_QPATH];
int hash;
char *shaderText;
@ -3376,7 +3386,7 @@ shader_t *R_FindShader( const char *name, int lightmapIndex, qboolean mipRawImag
}
}
InitShader( strippedName, lightmapIndex );
InitShaderEx( strippedName, lightmapIndex, realLightmapIndex );
//
// attempt to define shader from an explicit parameter file