From 66d26f707efb082b49e1246f5ff04ec7075abf30 Mon Sep 17 00:00:00 2001 From: VReaperV Date: Fri, 20 Sep 2024 21:18:34 +0300 Subject: [PATCH] Make some uniforms global --- src/engine/renderer/Material.cpp | 59 +++++++------------ src/engine/renderer/Material.h | 1 - src/engine/renderer/gl_shader.cpp | 24 +------- src/engine/renderer/gl_shader.h | 42 ++++--------- .../renderer/glsl_source/material_fp.glsl | 5 -- 5 files changed, 34 insertions(+), 97 deletions(-) diff --git a/src/engine/renderer/Material.cpp b/src/engine/renderer/Material.cpp index a1aba21687..34fb5ddf9d 100644 --- a/src/engine/renderer/Material.cpp +++ b/src/engine/renderer/Material.cpp @@ -260,8 +260,6 @@ void UpdateSurfaceDataGeneric3D( uint32_t* materials, Material& material, drawSu gl_genericShaderMaterial->SetUniform_DepthScale( pStage->depthFadeValue ); } - gl_genericShaderMaterial->SetUniform_VertexInterpolation( false ); - gl_genericShaderMaterial->WriteUniformsToBuffer( materials ); } @@ -301,20 +299,6 @@ void UpdateSurfaceDataLightMapping( uint32_t* materials, Material& material, dra bool enableGridLighting = ( lightMode == lightMode_t::GRID ); bool enableGridDeluxeMapping = ( deluxeMode == deluxeMode_t::GRID ); - // TODO: Update this when this is extended to MDV support - gl_lightMappingShaderMaterial->SetUniform_VertexInterpolation( false ); - - if ( glConfig2.realtimeLighting ) { - gl_lightMappingShaderMaterial->SetUniformBlock_Lights( tr.dlightUBO ); - - // bind u_LightTiles - if ( r_realtimeLightingRenderer.Get() == Util::ordinal( realtimeLightingRenderer_t::TILED ) ) { - gl_lightMappingShaderMaterial->SetUniform_LightTilesBindless( - GL_BindToTMU( BIND_LIGHTTILES, tr.lighttileRenderImage ) - ); - } - } - // u_DeformGen gl_lightMappingShaderMaterial->SetUniform_Time( backEnd.refdef.floatTime - backEnd.currentEntity->e.shaderTime ); @@ -394,8 +378,6 @@ void UpdateSurfaceDataLightMapping( uint32_t* materials, Material& material, dra gl_lightMappingShaderMaterial->SetUniform_LightMapBindless( GL_BindToTMU( BIND_LIGHTMAP, lightmap ) ); - } else { - gl_lightMappingShaderMaterial->SetUniform_LightGrid1Bindless( GL_BindToTMU( BIND_LIGHTMAP, lightmap ) ); } // bind u_DeluxeMap @@ -403,8 +385,6 @@ void UpdateSurfaceDataLightMapping( uint32_t* materials, Material& material, dra gl_lightMappingShaderMaterial->SetUniform_DeluxeMapBindless( GL_BindToTMU( BIND_DELUXEMAP, deluxemap ) ); - } else { - gl_lightMappingShaderMaterial->SetUniform_LightGrid2Bindless( GL_BindToTMU( BIND_DELUXEMAP, deluxemap ) ); } // bind u_GlowMap @@ -430,8 +410,6 @@ void UpdateSurfaceDataReflection( uint32_t* materials, Material& material, drawS } drawSurf->initialized[stage] = true; - gl_reflectionShaderMaterial->SetUniform_VertexInterpolation( false ); - // bind u_NormalMap gl_reflectionShaderMaterial->SetUniform_NormalMapBindless( GL_BindToTMU( 1, pStage->bundle[TB_NORMALMAP].image[0] ) @@ -1004,7 +982,6 @@ void BindShaderNOP( Material* ) { void BindShaderGeneric3D( Material* material ) { // Select shader permutation. - gl_genericShaderMaterial->SetVertexAnimation( material->vertexAnimation ); gl_genericShaderMaterial->SetTCGenEnvironment( material->tcGenEnvironment ); gl_genericShaderMaterial->SetTCGenLightmap( material->tcGen_Lightmap ); gl_genericShaderMaterial->SetDepthFade( material->hasDepthFade ); @@ -1029,7 +1006,6 @@ void BindShaderGeneric3D( Material* material ) { void BindShaderLightMapping( Material* material ) { // Select shader permutation. - gl_lightMappingShaderMaterial->SetVertexAnimation( material->vertexAnimation ); gl_lightMappingShaderMaterial->SetBspSurface( material->bspSurface ); gl_lightMappingShaderMaterial->SetDeluxeMapping( material->enableDeluxeMapping ); gl_lightMappingShaderMaterial->SetGridLighting( material->enableGridLighting ); @@ -1051,6 +1027,27 @@ void BindShaderLightMapping( Material* material ) { } // FIXME: else + // bind u_LightGrid1 + if ( material->enableGridLighting ) { + gl_lightMappingShaderMaterial->SetUniform_LightGrid1Bindless( GL_BindToTMU( BIND_LIGHTMAP, tr.lightGrid1Image ) ); + } + + // bind u_LightGrid2 + if ( material->enableGridDeluxeMapping ) { + gl_lightMappingShaderMaterial->SetUniform_LightGrid2Bindless( GL_BindToTMU( BIND_DELUXEMAP, tr.lightGrid2Image ) ); + } + + if ( glConfig2.realtimeLighting ) { + gl_lightMappingShaderMaterial->SetUniformBlock_Lights( tr.dlightUBO ); + + // bind u_LightTiles + if ( r_realtimeLightingRenderer.Get() == Util::ordinal( realtimeLightingRenderer_t::TILED ) ) { + gl_lightMappingShaderMaterial->SetUniform_LightTilesBindless( + GL_BindToTMU( BIND_LIGHTTILES, tr.lighttileRenderImage ) + ); + } + } + gl_lightMappingShaderMaterial->SetUniform_ViewOrigin( backEnd.orientation.viewOrigin ); gl_lightMappingShaderMaterial->SetUniform_numLights( backEnd.refdef.numLights ); gl_lightMappingShaderMaterial->SetUniform_ModelMatrix( backEnd.orientation.transformMatrix ); @@ -1107,7 +1104,6 @@ void BindShaderReflection( Material* material ) { // Select shader permutation. gl_reflectionShaderMaterial->SetHeightMapInNormalMap( material->hasHeightMapInNormalMap ); gl_reflectionShaderMaterial->SetReliefMapping( material->enableReliefMapping ); - gl_reflectionShaderMaterial->SetVertexAnimation( material->vertexAnimation ); // Bind shader program. gl_reflectionShaderMaterial->BindProgram( material->deformIndex ); @@ -1137,9 +1133,6 @@ void BindShaderScreen( Material* material ) { } void BindShaderHeatHaze( Material* material ) { - // Select shader permutation. - gl_heatHazeShaderMaterial->SetVertexAnimation( material->vertexAnimation ); - // Bind shader program. gl_heatHazeShaderMaterial->BindProgram( material->deformIndex ); @@ -1188,13 +1181,10 @@ void ProcessMaterialNOP( Material*, shaderStage_t*, drawSurf_t* ) { void ProcessMaterialGeneric3D( Material* material, shaderStage_t* pStage, drawSurf_t* ) { material->shader = gl_genericShaderMaterial; - material->vertexAnimation = false; material->tcGenEnvironment = pStage->tcGen_Environment; material->tcGen_Lightmap = pStage->tcGen_Lightmap; material->deformIndex = pStage->deformIndex; - gl_genericShaderMaterial->SetVertexAnimation( false ); - gl_genericShaderMaterial->SetTCGenEnvironment( pStage->tcGen_Environment ); gl_genericShaderMaterial->SetTCGenLightmap( pStage->tcGen_Lightmap ); @@ -1208,10 +1198,8 @@ void ProcessMaterialGeneric3D( Material* material, shaderStage_t* pStage, drawSu void ProcessMaterialLightMapping( Material* material, shaderStage_t* pStage, drawSurf_t* drawSurf ) { material->shader = gl_lightMappingShaderMaterial; - material->vertexAnimation = false; material->bspSurface = false; - gl_lightMappingShaderMaterial->SetVertexAnimation( false ); gl_lightMappingShaderMaterial->SetBspSurface( drawSurf->bspSurface ); lightMode_t lightMode; @@ -1256,15 +1244,12 @@ void ProcessMaterialReflection( Material* material, shaderStage_t* pStage, drawS material->hasHeightMapInNormalMap = pStage->hasHeightMapInNormalMap; material->enableReliefMapping = pStage->enableReliefMapping; - material->vertexAnimation = false; material->deformIndex = pStage->deformIndex; gl_reflectionShaderMaterial->SetHeightMapInNormalMap( pStage->hasHeightMapInNormalMap ); gl_reflectionShaderMaterial->SetReliefMapping( pStage->enableReliefMapping ); - gl_reflectionShaderMaterial->SetVertexAnimation( false ); - material->program = gl_reflectionShaderMaterial->GetProgram( pStage->deformIndex ); } @@ -1287,10 +1272,8 @@ void ProcessMaterialScreen( Material* material, shaderStage_t* pStage, drawSurf_ void ProcessMaterialHeatHaze( Material* material, shaderStage_t* pStage, drawSurf_t* ) { material->shader = gl_heatHazeShaderMaterial; - material->vertexAnimation = false; material->deformIndex = pStage->deformIndex; - gl_heatHazeShaderMaterial->SetVertexAnimation( false ); material->program = gl_heatHazeShaderMaterial->GetProgram( pStage->deformIndex ); } diff --git a/src/engine/renderer/Material.h b/src/engine/renderer/Material.h index 0cd89e86cd..b661264c88 100644 --- a/src/engine/renderer/Material.h +++ b/src/engine/renderer/Material.h @@ -94,7 +94,6 @@ struct Material { GLShader* shader; int deformIndex; - bool vertexAnimation; bool tcGenEnvironment; bool tcGen_Lightmap; bool hasDepthFade; diff --git a/src/engine/renderer/gl_shader.cpp b/src/engine/renderer/gl_shader.cpp index 2755f58eba..f87ce32313 100644 --- a/src/engine/renderer/gl_shader.cpp +++ b/src/engine/renderer/gl_shader.cpp @@ -2246,16 +2246,12 @@ GLShader_genericMaterial::GLShader_genericMaterial( GLShaderManager* manager ) : u_InverseLightFactor( this ), u_ColorModulate( this ), u_Color( this ), - // u_Bones( this ), - u_VertexInterpolation( this ), u_DepthScale( this ), u_ShowTris( this ), u_MaterialColour( this ), u_ProfilerZero( this ), u_ProfilerRenderSubGroups( this ), GLDeformStage( this ), - // GLCompileMacro_USE_VERTEX_SKINNING( this ), - GLCompileMacro_USE_VERTEX_ANIMATION( this ), GLCompileMacro_USE_TCGEN_ENVIRONMENT( this ), GLCompileMacro_USE_TCGEN_LIGHTMAP( this ), GLCompileMacro_USE_DEPTH_FADE( this ) { @@ -2359,8 +2355,6 @@ GLShader_lightMappingMaterial::GLShader_lightMappingMaterial( GLShaderManager* m u_ModelMatrix( this ), u_ModelViewProjectionMatrix( this ), u_InverseLightFactor( this ), - // u_Bones( this ), - u_VertexInterpolation( this ), u_ReliefDepthScale( this ), u_ReliefOffsetBias( this ), u_NormalScale( this ), @@ -2375,8 +2369,6 @@ GLShader_lightMappingMaterial::GLShader_lightMappingMaterial( GLShaderManager* m u_ProfilerRenderSubGroups( this ), GLDeformStage( this ), GLCompileMacro_USE_BSP_SURFACE( this ), - // GLCompileMacro_USE_VERTEX_SKINNING( this ), - GLCompileMacro_USE_VERTEX_ANIMATION( this ), GLCompileMacro_USE_DELUXE_MAPPING( this ), GLCompileMacro_USE_GRID_LIGHTING( this ), GLCompileMacro_USE_GRID_DELUXE_MAPPING( this ), @@ -2655,16 +2647,12 @@ GLShader_reflectionMaterial::GLShader_reflectionMaterial( GLShaderManager* manag u_ViewOrigin( this ), u_ModelMatrix( this ), u_ModelViewProjectionMatrix( this ), - // u_Bones( this ), u_ReliefDepthScale( this ), u_ReliefOffsetBias( this ), u_NormalScale( this ), - u_VertexInterpolation( this ), u_CameraPosition( this ), u_InverseLightFactor( this ), GLDeformStage( this ), - // GLCompileMacro_USE_VERTEX_SKINNING( this ), - GLCompileMacro_USE_VERTEX_ANIMATION( this ), GLCompileMacro_USE_HEIGHTMAP_IN_NORMALMAP( this ), GLCompileMacro_USE_RELIEF_MAPPING( this ) { } @@ -2745,14 +2733,10 @@ GLShader_fogQuake3Material::GLShader_fogQuake3Material( GLShaderManager* manager u_ModelViewProjectionMatrix( this ), u_InverseLightFactor( this ), u_Color( this ), - // u_Bones( this ), - u_VertexInterpolation( this ), u_FogDistanceVector( this ), u_FogDepthVector( this ), u_FogEyeT( this ), - GLDeformStage( this ), - // GLCompileMacro_USE_VERTEX_SKINNING( this ), - GLCompileMacro_USE_VERTEX_ANIMATION( this ) { + GLDeformStage( this ) { } void GLShader_fogQuake3Material::SetShaderProgramUniforms( shaderProgram_t* shaderProgram ) { @@ -2827,12 +2811,8 @@ GLShader_heatHazeMaterial::GLShader_heatHazeMaterial( GLShaderManager* manager ) u_ProjectionMatrixTranspose( this ), u_ColorModulate( this ), u_Color( this ), - // u_Bones( this ), u_NormalScale( this ), - u_VertexInterpolation( this ), - GLDeformStage( this ), - // GLCompileMacro_USE_VERTEX_SKINNING( this ), - GLCompileMacro_USE_VERTEX_ANIMATION( this ) + GLDeformStage( this ) { } diff --git a/src/engine/renderer/gl_shader.h b/src/engine/renderer/gl_shader.h index f9821d8572..b356b79102 100644 --- a/src/engine/renderer/gl_shader.h +++ b/src/engine/renderer/gl_shader.h @@ -597,8 +597,8 @@ class GLUniformSampler2D : protected GLUniformSampler { class GLUniformSampler3D : protected GLUniformSampler { protected: - GLUniformSampler3D( GLShader* shader, const char* name ) : - GLUniformSampler( shader, name, "sampler3D", 1 ) { + GLUniformSampler3D( GLShader* shader, const char* name, const bool global = false ) : + GLUniformSampler( shader, name, "sampler3D", 1, global ) { } inline GLint GetLocation() { @@ -619,8 +619,8 @@ class GLUniformSampler3D : protected GLUniformSampler { class GLUniformUSampler3D : protected GLUniformSampler { protected: - GLUniformUSampler3D( GLShader* shader, const char* name ) : - GLUniformSampler( shader, name, "usampler3D", 1 ) { + GLUniformUSampler3D( GLShader* shader, const char* name, const bool global = false ) : + GLUniformSampler( shader, name, "usampler3D", 1, global ) { } inline GLint GetLocation() { @@ -2393,7 +2393,7 @@ class u_LightTiles : GLUniformSampler3D { public: u_LightTiles( GLShader* shader ) : - GLUniformSampler3D( shader, "u_LightTiles" ) { + GLUniformSampler3D( shader, "u_LightTiles", true ) { } void SetUniform_LightTilesBindless( GLuint64 bindlessHandle ) { @@ -2409,7 +2409,7 @@ class u_LightGrid1 : GLUniformSampler3D { public: u_LightGrid1( GLShader* shader ) : - GLUniformSampler3D( shader, "u_LightGrid1" ) { + GLUniformSampler3D( shader, "u_LightGrid1", true ) { } void SetUniform_LightGrid1Bindless( GLuint64 bindlessHandle ) { @@ -2425,7 +2425,7 @@ class u_LightGrid2 : GLUniformSampler3D { public: u_LightGrid2( GLShader* shader ) : - GLUniformSampler3D( shader, "u_LightGrid2" ) { + GLUniformSampler3D( shader, "u_LightGrid2", true ) { } void SetUniform_LightGrid2Bindless( GLuint64 bindlessHandle ) { @@ -3553,7 +3553,7 @@ class u_EnvironmentInterpolation : { public: u_EnvironmentInterpolation( GLShader *shader ) : - GLUniform1f( shader, "u_EnvironmentInterpolation" ) + GLUniform1f( shader, "u_EnvironmentInterpolation", true ) { } @@ -3568,7 +3568,7 @@ class u_Time : { public: u_Time( GLShader *shader ) : - GLUniform1f( shader, "u_Time" ) + GLUniform1f( shader, "u_Time", true ) // Source this from a buffer when entity support is added to the material system { } @@ -3963,16 +3963,12 @@ class GLShader_genericMaterial : public u_InverseLightFactor, public u_ColorModulate, public u_Color, - // public u_Bones, - public u_VertexInterpolation, public u_DepthScale, public u_ShowTris, public u_MaterialColour, public u_ProfilerZero, public u_ProfilerRenderSubGroups, public GLDeformStage, - // public GLCompileMacro_USE_VERTEX_SKINNING, - public GLCompileMacro_USE_VERTEX_ANIMATION, public GLCompileMacro_USE_TCGEN_ENVIRONMENT, public GLCompileMacro_USE_TCGEN_LIGHTMAP, public GLCompileMacro_USE_DEPTH_FADE { @@ -4056,8 +4052,6 @@ class GLShader_lightMappingMaterial : public u_ModelMatrix, public u_ModelViewProjectionMatrix, public u_InverseLightFactor, - // public u_Bones, - public u_VertexInterpolation, public u_ReliefDepthScale, public u_ReliefOffsetBias, public u_NormalScale, @@ -4072,8 +4066,6 @@ class GLShader_lightMappingMaterial : public u_ProfilerRenderSubGroups, public GLDeformStage, public GLCompileMacro_USE_BSP_SURFACE, - // public GLCompileMacro_USE_VERTEX_SKINNING, - public GLCompileMacro_USE_VERTEX_ANIMATION, public GLCompileMacro_USE_DELUXE_MAPPING, public GLCompileMacro_USE_GRID_LIGHTING, public GLCompileMacro_USE_GRID_DELUXE_MAPPING, @@ -4288,16 +4280,12 @@ class GLShader_reflectionMaterial : public u_ViewOrigin, public u_ModelMatrix, public u_ModelViewProjectionMatrix, - // public u_Bones, public u_ReliefDepthScale, public u_ReliefOffsetBias, public u_NormalScale, - public u_VertexInterpolation, public u_CameraPosition, public u_InverseLightFactor, public GLDeformStage, - // public GLCompileMacro_USE_VERTEX_SKINNING, - public GLCompileMacro_USE_VERTEX_ANIMATION, public GLCompileMacro_USE_HEIGHTMAP_IN_NORMALMAP, public GLCompileMacro_USE_RELIEF_MAPPING { public: @@ -4368,14 +4356,10 @@ class GLShader_fogQuake3Material : public u_ModelViewProjectionMatrix, public u_InverseLightFactor, public u_Color, - // public u_Bones, - public u_VertexInterpolation, public u_FogDistanceVector, public u_FogDepthVector, public u_FogEyeT, - public GLDeformStage, - // public GLCompileMacro_USE_VERTEX_SKINNING, - public GLCompileMacro_USE_VERTEX_ANIMATION { + public GLDeformStage { public: GLShader_fogQuake3Material( GLShaderManager* manager ); void SetShaderProgramUniforms( shaderProgram_t* shaderProgram ) override; @@ -4442,12 +4426,8 @@ class GLShader_heatHazeMaterial : public u_ProjectionMatrixTranspose, public u_ColorModulate, public u_Color, - // public u_Bones, public u_NormalScale, - public u_VertexInterpolation, - public GLDeformStage, - // public GLCompileMacro_USE_VERTEX_SKINNING, - public GLCompileMacro_USE_VERTEX_ANIMATION + public GLDeformStage { public: GLShader_heatHazeMaterial( GLShaderManager* manager ); diff --git a/src/engine/renderer/glsl_source/material_fp.glsl b/src/engine/renderer/glsl_source/material_fp.glsl index dcd97e77d1..3b0b1e70af 100644 --- a/src/engine/renderer/glsl_source/material_fp.glsl +++ b/src/engine/renderer/glsl_source/material_fp.glsl @@ -58,7 +58,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. samplerCube u_EnvironmentMap0 = samplerCube( u_EnvironmentMap0_initial ); samplerCube u_EnvironmentMap1 = samplerCube( u_EnvironmentMap1_initial ); #endif // !USE_REFLECTIVE_SPECULAR */ -usampler3D u_LightTiles = usampler3D( u_LightTiles_initial ); #endif // !COMPUTELIGHT_GLSL #if defined(FOGQUAKE3_GLSL) @@ -77,16 +76,12 @@ sampler2D u_DiffuseMap = sampler2D( u_DiffuseMap_initial ); sampler2D u_MaterialMap = sampler2D( u_MaterialMap_initial ); sampler2D u_GlowMap = sampler2D( u_GlowMap_initial ); sampler2D u_LightMap = sampler2D( u_LightMap_initial ); -sampler3D u_LightGrid1 = sampler3D( u_LightGrid1_initial ); sampler2D u_DeluxeMap = sampler2D( u_DeluxeMap_initial ); -sampler3D u_LightGrid2 = sampler3D( u_LightGrid2_initial ); #endif // !LIGHTMAPPING_GLSL #if defined(LIQUID_GLSL) sampler2D u_PortalMap = sampler2D( u_PortalMap_initial ); sampler2D u_DepthMap = sampler2D( u_DepthMap_initial ); -sampler3D u_LightGrid1 = sampler3D( u_LightGrid1_initial ); -sampler3D u_LightGrid2 = sampler3D( u_LightGrid2_initial ); #endif // !LIQUID_GLSL #if defined(REFLECTION_CB_GLSL)