diff --git a/src/engine/renderer/Material.cpp b/src/engine/renderer/Material.cpp index d332021b07..0de06ceef1 100644 --- a/src/engine/renderer/Material.cpp +++ b/src/engine/renderer/Material.cpp @@ -527,17 +527,17 @@ void MaterialSystem::GenerateTexturesBuffer( std::vector& textures, } } - // While reflection, liquid and heatHaze shaders use the matrix from TB_NORMALMAP bundle, it's never actually parsed - RB_CalcTexMatrix( textureData.texBundles[0], tess.svars.texMatrices[TB_COLORMAP] ); + const int bundle = textureData.textureMatrixBundle; + RB_CalcTexMatrix( textureData.texBundles[bundle], tess.svars.texMatrices[bundle] ); /* We only actually need these 6 components to get the correct texture transformation, the other ones are unused */ - textureBundles->textureMatrix[0] = tess.svars.texMatrices[TB_COLORMAP][0]; - textureBundles->textureMatrix[1] = tess.svars.texMatrices[TB_COLORMAP][1]; - textureBundles->textureMatrix[2] = tess.svars.texMatrices[TB_COLORMAP][4]; - textureBundles->textureMatrix[3] = tess.svars.texMatrices[TB_COLORMAP][5]; + textureBundles->textureMatrix[0] = tess.svars.texMatrices[bundle][0]; + textureBundles->textureMatrix[1] = tess.svars.texMatrices[bundle][1]; + textureBundles->textureMatrix[2] = tess.svars.texMatrices[bundle][4]; + textureBundles->textureMatrix[3] = tess.svars.texMatrices[bundle][5]; // These are stored as part of a vec4 in a UBO, so we need to convert them here as well - textureBundles->textureMatrix2[0] = tess.svars.texMatrices[TB_COLORMAP][12] * 32768.0f; - textureBundles->textureMatrix2[1] = tess.svars.texMatrices[TB_COLORMAP][13] * 32768.0f; + textureBundles->textureMatrix2[0] = tess.svars.texMatrices[bundle][12] * 32768.0f; + textureBundles->textureMatrix2[1] = tess.svars.texMatrices[bundle][13] * 32768.0f; textureBundles++; } } @@ -1553,7 +1553,9 @@ void MaterialSystem::AddStageTextures( drawSurf_t* drawSurf, const uint32_t stag int bundleNum = 0; bool dynamic = false; - for ( const textureBundle_t& bundle : pStage->bundle ) { + for ( int i = 0; i < MAX_TEXTURE_BUNDLES; i++ ) { + const textureBundle_t& bundle = pStage->bundle[i]; + if ( bundle.isVideoMap ) { material->AddTexture( tr.cinematicImage[bundle.videoMapHandle]->texture ); continue; @@ -1566,6 +1568,7 @@ void MaterialSystem::AddStageTextures( drawSurf_t* drawSurf, const uint32_t stag } if ( bundle.numImages > 1 || bundle.numTexMods > 0 ) { + textureData.textureMatrixBundle = i; dynamic = true; } diff --git a/src/engine/renderer/Material.h b/src/engine/renderer/Material.h index e8dd015751..98fd80738a 100644 --- a/src/engine/renderer/Material.h +++ b/src/engine/renderer/Material.h @@ -145,6 +145,7 @@ struct TextureData { const textureBundle_t* texBundles[MAX_TEXTURE_BUNDLES] = { nullptr, nullptr, nullptr, nullptr, nullptr }; // For ST_STYLELIGHTMAP stages image_t* texBundlesOverride[MAX_TEXTURE_BUNDLES] = { nullptr, nullptr, nullptr, nullptr, nullptr }; + int textureMatrixBundle = 0; bool operator==( const TextureData& other ) const { for ( int i = 0; i < MAX_TEXTURE_BUNDLES; i++ ) { @@ -195,6 +196,7 @@ struct TextureData { TextureData( const TextureData& other ) { memcpy( texBundles, other.texBundles, MAX_TEXTURE_BUNDLES * sizeof( textureBundle_t* ) ); memcpy( texBundlesOverride, other.texBundlesOverride, MAX_TEXTURE_BUNDLES * sizeof( image_t* ) ); + textureMatrixBundle = other.textureMatrixBundle; } }; diff --git a/src/engine/renderer/gl_shader.cpp b/src/engine/renderer/gl_shader.cpp index 12e2594342..fb1989eb4a 100644 --- a/src/engine/renderer/gl_shader.cpp +++ b/src/engine/renderer/gl_shader.cpp @@ -1381,7 +1381,7 @@ std::string GLShaderManager::ShaderPostProcess( GLShader *shader, const std::str " uvec4 u_MaterialGlowMap;\n" "};\n\n" + texBuf + - "#define u_TextureMatrix mat3x2( texData[( baseInstance >> 12 ) & 0xFFF].u_TextureMatrix, vec2( texData[( baseInstance >> 12 ) & 0xFFF].u_TextureDiffuseMap.xy ) * vec2( 1.0f / 32768.0f ) )\n" + "#define u_TextureMatrix mat3x2( texData[( baseInstance >> 12 ) & 0xFFF].u_TextureMatrix.xy, texData[( baseInstance >> 12 ) & 0xFFF].u_TextureMatrix.zw, vec2( texData[( baseInstance >> 12 ) & 0xFFF].u_TextureDiffuseMap.xy ) * vec2( 1.0f / 32768.0f ) )\n" "#define u_DiffuseMap_initial uvec2( texData[( baseInstance >> 12 ) & 0xFFF].u_TextureDiffuseMap.zw )\n" "#define u_NormalMap_initial uvec2( texData[( baseInstance >> 12 ) & 0xFFF].u_NormalHeightMap.xy )\n" "#define u_HeightMap_initial uvec2( texData[( baseInstance >> 12 ) & 0xFFF].u_NormalHeightMap.zw )\n"