From 32a79ecb1ab59594cd7d2b1760f4657b670fa520 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 | 36 +++++++++++-------- src/engine/renderer/gl_shader.h | 20 +++++------ .../renderer/glsl_source/material_fp.glsl | 5 --- 3 files changed, 31 insertions(+), 30 deletions(-) diff --git a/src/engine/renderer/Material.cpp b/src/engine/renderer/Material.cpp index a1aba21687..17e8884a0b 100644 --- a/src/engine/renderer/Material.cpp +++ b/src/engine/renderer/Material.cpp @@ -304,17 +304,6 @@ void UpdateSurfaceDataLightMapping( uint32_t* materials, Material& material, dra // 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 +383,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 +390,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 @@ -1051,6 +1036,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 ); diff --git a/src/engine/renderer/gl_shader.h b/src/engine/renderer/gl_shader.h index f9821d8572..6f7e8c1261 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 ) { @@ -3478,7 +3478,7 @@ class u_VertexInterpolation : { public: u_VertexInterpolation( GLShader *shader ) : - GLUniform1f( shader, "u_VertexInterpolation" ) + GLUniform1f( shader, "u_VertexInterpolation", true ) { } @@ -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 { } 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)