Skip to content

Commit 217f21e

Browse files
committed
Material System: always write all of a given stage's data
1 parent 66d6c68 commit 217f21e

File tree

1 file changed

+43
-60
lines changed

1 file changed

+43
-60
lines changed

src/engine/renderer/Material.cpp

Lines changed: 43 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,12 @@ static void ComputeDynamics( shaderStage_t* pStage ) {
127127
pStage->dynamic = pStage->dynamic || pStage->colorDynamic;
128128
}
129129

130-
// UpdateSurface*() functions will actually write the uniform values to the SSBO
131-
// Mirrors parts of the Render_*() functions in tr_shade.cpp
130+
/* UpdateSurfaceData*() functions will write the material uniform values to the UBO
131+
Mirrors parts of the Render_*() functions in tr_shade.cpp
132+
133+
All of these functions must write stage material data regardless of whether pStage has the related feature enabled,
134+
because stages here are combined into as few as possible,
135+
and the stage chosen for storage might not have all of those enabled */
132136

133137
void UpdateSurfaceDataNONE( uint32_t*, shaderStage_t*, bool, bool, bool ) {
134138
ASSERT_UNREACHABLE();
@@ -155,10 +159,7 @@ void UpdateSurfaceDataGeneric3D( uint32_t* materials, shaderStage_t* pStage, boo
155159
Tess_ComputeColor( pStage );
156160
gl_genericShaderMaterial->SetUniform_Color_Uint( tess.svars.color );
157161

158-
bool hasDepthFade = pStage->hasDepthFade;
159-
if ( hasDepthFade ) {
160-
gl_genericShaderMaterial->SetUniform_DepthScale( pStage->depthFadeValue );
161-
}
162+
gl_genericShaderMaterial->SetUniform_DepthScale( pStage->depthFadeValue );
162163

163164
gl_genericShaderMaterial->WriteUniformsToBuffer( materials );
164165
}
@@ -189,28 +190,22 @@ void UpdateSurfaceDataLightMapping( uint32_t* materials, shaderStage_t* pStage,
189190
gl_lightMappingShaderMaterial->SetUniform_AlphaTest( pStage->stateBits );
190191

191192
// HeightMap
192-
if ( pStage->enableReliefMapping ) {
193-
float depthScale = RB_EvalExpression( &pStage->depthScaleExp, r_reliefDepthScale->value );
194-
depthScale *= shader->reliefDepthScale;
193+
float depthScale = RB_EvalExpression( &pStage->depthScaleExp, r_reliefDepthScale->value );
194+
depthScale *= shader->reliefDepthScale;
195195

196-
gl_lightMappingShaderMaterial->SetUniform_ReliefDepthScale( depthScale );
197-
gl_lightMappingShaderMaterial->SetUniform_ReliefOffsetBias( shader->reliefOffsetBias );
198-
}
196+
gl_lightMappingShaderMaterial->SetUniform_ReliefDepthScale( depthScale );
197+
gl_lightMappingShaderMaterial->SetUniform_ReliefOffsetBias( shader->reliefOffsetBias );
199198

200199
// bind u_NormalScale
201-
if ( pStage->enableNormalMapping ) {
202-
vec3_t normalScale;
203-
SetNormalScale( pStage, normalScale );
200+
vec3_t normalScale;
201+
SetNormalScale( pStage, normalScale );
204202

205-
gl_lightMappingShaderMaterial->SetUniform_NormalScale( normalScale );
206-
}
203+
gl_lightMappingShaderMaterial->SetUniform_NormalScale( normalScale );
207204

208-
if ( pStage->enableSpecularMapping ) {
209-
float specExpMin = RB_EvalExpression( &pStage->specularExponentMin, r_specularExponentMin->value );
210-
float specExpMax = RB_EvalExpression( &pStage->specularExponentMax, r_specularExponentMax->value );
205+
float specExpMin = RB_EvalExpression( &pStage->specularExponentMin, r_specularExponentMin->value );
206+
float specExpMax = RB_EvalExpression( &pStage->specularExponentMax, r_specularExponentMax->value );
211207

212-
gl_lightMappingShaderMaterial->SetUniform_SpecularExponent( specExpMin, specExpMax );
213-
}
208+
gl_lightMappingShaderMaterial->SetUniform_SpecularExponent( specExpMin, specExpMax );
214209

215210
gl_lightMappingShaderMaterial->WriteUniformsToBuffer( materials );
216211
}
@@ -237,21 +232,17 @@ void UpdateSurfaceDataReflection( uint32_t* materials, shaderStage_t* pStage, bo
237232
GL_BindToTMU( 0, probes[0]->cubemap )
238233
);
239234

240-
if ( pStage->enableNormalMapping ) {
241-
vec3_t normalScale;
242-
SetNormalScale( pStage, normalScale );
235+
vec3_t normalScale;
236+
SetNormalScale( pStage, normalScale );
243237

244-
gl_reflectionShaderMaterial->SetUniform_NormalScale( normalScale );
245-
}
238+
gl_reflectionShaderMaterial->SetUniform_NormalScale( normalScale );
246239

247240
// u_depthScale u_reliefOffsetBias
248-
if ( pStage->enableReliefMapping ) {
249-
float depthScale = RB_EvalExpression( &pStage->depthScaleExp, r_reliefDepthScale->value );
250-
float reliefDepthScale = shader->reliefDepthScale;
251-
depthScale *= reliefDepthScale == 0 ? 1 : reliefDepthScale;
252-
gl_reflectionShaderMaterial->SetUniform_ReliefDepthScale( depthScale );
253-
gl_reflectionShaderMaterial->SetUniform_ReliefOffsetBias( shader->reliefOffsetBias );
254-
}
241+
float depthScale = RB_EvalExpression( &pStage->depthScaleExp, r_reliefDepthScale->value );
242+
float reliefDepthScale = shader->reliefDepthScale;
243+
depthScale *= reliefDepthScale == 0 ? 1 : reliefDepthScale;
244+
gl_reflectionShaderMaterial->SetUniform_ReliefDepthScale( depthScale );
245+
gl_reflectionShaderMaterial->SetUniform_ReliefOffsetBias( shader->reliefOffsetBias );
255246

256247
gl_reflectionShaderMaterial->WriteUniformsToBuffer( materials );
257248
}
@@ -288,13 +279,11 @@ void UpdateSurfaceDataHeatHaze( uint32_t* materials, shaderStage_t* pStage, bool
288279
float deformMagnitude = RB_EvalExpression( &pStage->deformMagnitudeExp, 1.0 );
289280
gl_heatHazeShaderMaterial->SetUniform_DeformMagnitude( deformMagnitude );
290281

291-
if ( pStage->enableNormalMapping ) {
292-
vec3_t normalScale;
293-
SetNormalScale( pStage, normalScale );
282+
vec3_t normalScale;
283+
SetNormalScale( pStage, normalScale );
294284

295-
// bind u_NormalScale
296-
gl_heatHazeShaderMaterial->SetUniform_NormalScale( normalScale );
297-
}
285+
// bind u_NormalScale
286+
gl_heatHazeShaderMaterial->SetUniform_NormalScale( normalScale );
298287

299288
gl_heatHazeShaderMaterial->WriteUniformsToBuffer( materials );
300289
}
@@ -318,35 +307,29 @@ void UpdateSurfaceDataLiquid( uint32_t* materials, shaderStage_t* pStage, bool,
318307

319308
// NOTE: specular component is computed by shader.
320309
// FIXME: physical mapping is not implemented.
321-
if ( pStage->enableSpecularMapping ) {
322-
float specMin = RB_EvalExpression( &pStage->specularExponentMin, r_specularExponentMin->value );
323-
float specMax = RB_EvalExpression( &pStage->specularExponentMax, r_specularExponentMax->value );
324-
gl_liquidShaderMaterial->SetUniform_SpecularExponent( specMin, specMax );
325-
}
310+
float specMin = RB_EvalExpression( &pStage->specularExponentMin, r_specularExponentMin->value );
311+
float specMax = RB_EvalExpression( &pStage->specularExponentMax, r_specularExponentMax->value );
312+
gl_liquidShaderMaterial->SetUniform_SpecularExponent( specMin, specMax );
326313

327314
// bind u_CurrentMap
328315
gl_liquidShaderMaterial->SetUniform_CurrentMapBindless( GL_BindToTMU( 0, tr.currentRenderImage[backEnd.currentMainFBO] ) );
329316

330317
// bind u_HeightMap u_depthScale u_reliefOffsetBias
331-
if ( pStage->enableReliefMapping ) {
332-
float depthScale;
333-
float reliefDepthScale;
318+
float depthScale;
319+
float reliefDepthScale;
334320

335-
depthScale = RB_EvalExpression( &pStage->depthScaleExp, r_reliefDepthScale->value );
336-
reliefDepthScale = tess.surfaceShader->reliefDepthScale;
337-
depthScale *= reliefDepthScale == 0 ? 1 : reliefDepthScale;
338-
gl_liquidShaderMaterial->SetUniform_ReliefDepthScale( depthScale );
339-
gl_liquidShaderMaterial->SetUniform_ReliefOffsetBias( tess.surfaceShader->reliefOffsetBias );
340-
}
321+
depthScale = RB_EvalExpression( &pStage->depthScaleExp, r_reliefDepthScale->value );
322+
reliefDepthScale = tess.surfaceShader->reliefDepthScale;
323+
depthScale *= reliefDepthScale == 0 ? 1 : reliefDepthScale;
324+
gl_liquidShaderMaterial->SetUniform_ReliefDepthScale( depthScale );
325+
gl_liquidShaderMaterial->SetUniform_ReliefOffsetBias( tess.surfaceShader->reliefOffsetBias );
341326

342327
// bind u_NormalScale
343-
if ( pStage->enableNormalMapping ) {
344-
vec3_t normalScale;
345-
// FIXME: NormalIntensity default was 0.5
346-
SetNormalScale( pStage, normalScale );
328+
vec3_t normalScale;
329+
// FIXME: NormalIntensity default was 0.5
330+
SetNormalScale( pStage, normalScale );
347331

348-
gl_liquidShaderMaterial->SetUniform_NormalScale( normalScale );
349-
}
332+
gl_liquidShaderMaterial->SetUniform_NormalScale( normalScale );
350333

351334
gl_liquidShaderMaterial->WriteUniformsToBuffer( materials );
352335
}

0 commit comments

Comments
 (0)