Skip to content

Commit

Permalink
Make some uniforms global
Browse files Browse the repository at this point in the history
  • Loading branch information
VReaperV committed Oct 31, 2024
1 parent a8f538a commit 32a79ec
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 30 deletions.
36 changes: 21 additions & 15 deletions src/engine/renderer/Material.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );

Expand Down Expand Up @@ -394,17 +383,13 @@ 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
if ( !enableGridDeluxeMapping ) {
gl_lightMappingShaderMaterial->SetUniform_DeluxeMapBindless(
GL_BindToTMU( BIND_DELUXEMAP, deluxemap )
);
} else {
gl_lightMappingShaderMaterial->SetUniform_LightGrid2Bindless( GL_BindToTMU( BIND_DELUXEMAP, deluxemap ) );
}

// bind u_GlowMap
Expand Down Expand Up @@ -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 );
Expand Down
20 changes: 10 additions & 10 deletions src/engine/renderer/gl_shader.h
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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() {
Expand Down Expand Up @@ -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 ) {
Expand All @@ -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 ) {
Expand All @@ -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 ) {
Expand Down Expand Up @@ -3478,7 +3478,7 @@ class u_VertexInterpolation :
{
public:
u_VertexInterpolation( GLShader *shader ) :
GLUniform1f( shader, "u_VertexInterpolation" )
GLUniform1f( shader, "u_VertexInterpolation", true )
{
}

Expand Down Expand Up @@ -3553,7 +3553,7 @@ class u_EnvironmentInterpolation :
{
public:
u_EnvironmentInterpolation( GLShader *shader ) :
GLUniform1f( shader, "u_EnvironmentInterpolation" )
GLUniform1f( shader, "u_EnvironmentInterpolation", true )
{
}

Expand All @@ -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
{
}

Expand Down
5 changes: 0 additions & 5 deletions src/engine/renderer/glsl_source/material_fp.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit 32a79ec

Please sign in to comment.