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 Nov 2, 2024
1 parent ef89e9b commit 88c856d
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 97 deletions.
59 changes: 21 additions & 38 deletions src/engine/renderer/Material.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}

Expand Down Expand Up @@ -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 );

Expand Down Expand Up @@ -394,17 +378,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 All @@ -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] )
Expand Down Expand Up @@ -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 );
Expand All @@ -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 );
Expand All @@ -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 );
Expand Down Expand Up @@ -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 );
Expand Down Expand Up @@ -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 );

Expand Down Expand Up @@ -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 );

Expand All @@ -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;
Expand Down Expand Up @@ -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 );
}

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

Expand Down
1 change: 0 additions & 1 deletion src/engine/renderer/Material.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ struct Material {
GLShader* shader;

int deformIndex;
bool vertexAnimation;
bool tcGenEnvironment;
bool tcGen_Lightmap;
bool hasDepthFade;
Expand Down
24 changes: 2 additions & 22 deletions src/engine/renderer/gl_shader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) {
Expand Down Expand Up @@ -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 ),
Expand All @@ -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 ),
Expand Down Expand Up @@ -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 ) {
}
Expand Down Expand Up @@ -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 ) {
Expand Down Expand Up @@ -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 )
{
}

Expand Down
Loading

0 comments on commit 88c856d

Please sign in to comment.