From 232b0b3bb1526bf5da864b347020b1c06c0c9c3c Mon Sep 17 00:00:00 2001 From: VReaperV Date: Sat, 11 Jan 2025 17:17:26 +0300 Subject: [PATCH] Fix u_TextureMatrix with material system --- src/engine/renderer/Material.cpp | 5 ++--- src/engine/renderer/Material.h | 3 +-- src/engine/renderer/gl_shader.cpp | 23 +++++++++++++---------- 3 files changed, 16 insertions(+), 15 deletions(-) diff --git a/src/engine/renderer/Material.cpp b/src/engine/renderer/Material.cpp index cc5600d399..e8571fc119 100644 --- a/src/engine/renderer/Material.cpp +++ b/src/engine/renderer/Material.cpp @@ -535,9 +535,8 @@ void MaterialSystem::GenerateTexturesBuffer( std::vector& textures, 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[bundle][12] * 32768.0f; - textureBundles->textureMatrix2[1] = tess.svars.texMatrices[bundle][13] * 32768.0f; + textureBundles->textureMatrix[4] = tess.svars.texMatrices[bundle][12]; + textureBundles->textureMatrix[5] = tess.svars.texMatrices[bundle][13]; textureBundles++; } } diff --git a/src/engine/renderer/Material.h b/src/engine/renderer/Material.h index d460f39d5e..3e03121c61 100644 --- a/src/engine/renderer/Material.h +++ b/src/engine/renderer/Material.h @@ -136,8 +136,7 @@ struct Material { }; struct TexBundle { - vec_t textureMatrix[4]; - uint32_t textureMatrix2[2]; + vec_t textureMatrix[6]; GLuint64 textures[MAX_TEXTURE_BUNDLES]; }; diff --git a/src/engine/renderer/gl_shader.cpp b/src/engine/renderer/gl_shader.cpp index 26bfc75895..5181d97b4a 100644 --- a/src/engine/renderer/gl_shader.cpp +++ b/src/engine/renderer/gl_shader.cpp @@ -1372,20 +1372,23 @@ std::string GLShaderManager::ShaderPostProcess( GLShader *shader, const std::str : "layout(std430, binding = 7) restrict readonly buffer texDataSSBO {\n" " TexData texData[];\n" "};\n\n"; - // We have to store these as a bunch of vec4/uvec4 because std140 pads everything to a vec4 + // We have to store u_TextureMatrix as vec4 + vec2 because otherwise it would be aligned to a vec4 under std140 std::string texDataBlock = "struct TexData {\n" " vec4 u_TextureMatrix;\n" - " uvec4 u_TextureDiffuseMap;\n" - " uvec4 u_NormalHeightMap;\n" - " uvec4 u_MaterialGlowMap;\n" + " vec2 u_TextureMatrix2;\n" + " uvec2 u_DiffuseMap;\n" + " uvec2 u_NormalMap;\n" + " uvec2 u_HeightMap;\n" + " uvec2 u_MaterialMap;\n" + " uvec2 u_GlowMap;\n" "};\n\n" + texBuf + - "#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" - "#define u_MaterialMap_initial uvec2( texData[( baseInstance >> 12 ) & 0xFFF].u_MaterialGlowMap.xy )\n" - "#define u_GlowMap_initial uvec2( texData[( baseInstance >> 12 ) & 0xFFF].u_MaterialGlowMap.zw )\n\n" + "#define u_TextureMatrix mat3x2( texData[( baseInstance >> 12 ) & 0xFFF].u_TextureMatrix.xy, texData[( baseInstance >> 12 ) & 0xFFF].u_TextureMatrix.zw, texData[( baseInstance >> 12 ) & 0xFFF].u_TextureMatrix2 )\n" + "#define u_DiffuseMap_initial texData[( baseInstance >> 12 ) & 0xFFF].u_DiffuseMap\n" + "#define u_NormalMap_initial texData[( baseInstance >> 12 ) & 0xFFF].u_NormalMap\n" + "#define u_HeightMap_initial texData[( baseInstance >> 12 ) & 0xFFF].u_HeightMap\n" + "#define u_MaterialMap_initial texData[( baseInstance >> 12 ) & 0xFFF].u_MaterialMap\n" + "#define u_GlowMap_initial texData[( baseInstance >> 12 ) & 0xFFF].u_GlowMap\n\n" "struct LightMapData {\n" " uvec2 u_LightMap;\n" " uvec2 u_DeluxeMap;\n"