Skip to content

Commit 0b284f5

Browse files
committed
renderer: add the EXP_CLAMP bit to normalize the expression value
1 parent 3f48b8d commit 0b284f5

File tree

4 files changed

+23
-21
lines changed

4 files changed

+23
-21
lines changed

src/engine/renderer/tr_local.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -863,6 +863,7 @@ enum class ssaoMode {
863863
enum
864864
{
865865
EXP_NONE,
866+
EXP_CLAMP = BIT( 0 ),
866867
EXP_SRGB = BIT( 1 ),
867868
};
868869

src/engine/renderer/tr_shade.cpp

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1778,7 +1778,7 @@ void Tess_ComputeColor( shaderStage_t *pStage )
17781778

17791779
case colorGen_t::CGEN_CUSTOM_RGB:
17801780
{
1781-
rgb = Math::Clamp( RB_EvalExpression( &pStage->rgbExp, 1.0 ), 0.0f, 1.0f );
1781+
rgb = RB_EvalExpression( &pStage->rgbExp, 1.0 );
17821782

17831783
tess.svars.color = Color::White * rgb;
17841784
break;
@@ -1788,18 +1788,15 @@ void Tess_ComputeColor( shaderStage_t *pStage )
17881788
{
17891789
if ( backEnd.currentEntity )
17901790
{
1791-
red =
1792-
Math::Clamp( RB_EvalExpression( &pStage->redExp, backEnd.currentEntity->e.shaderRGBA.Red() * ( 1.0 / 255.0 ) ), 0.0f, 1.0f );
1793-
green =
1794-
Math::Clamp( RB_EvalExpression( &pStage->greenExp, backEnd.currentEntity->e.shaderRGBA.Green() * ( 1.0 / 255.0 ) ), 0.0f, 1.0f );
1795-
blue =
1796-
Math::Clamp( RB_EvalExpression( &pStage->blueExp, backEnd.currentEntity->e.shaderRGBA.Blue() * ( 1.0 / 255.0 ) ), 0.0f, 1.0f );
1791+
red = RB_EvalExpression( &pStage->redExp, backEnd.currentEntity->e.shaderRGBA.Red() * ( 1.0 / 255.0 ) );
1792+
green = RB_EvalExpression( &pStage->greenExp, backEnd.currentEntity->e.shaderRGBA.Green() * ( 1.0 / 255.0 ) );
1793+
blue = RB_EvalExpression( &pStage->blueExp, backEnd.currentEntity->e.shaderRGBA.Blue() * ( 1.0 / 255.0 ) );
17971794
}
17981795
else
17991796
{
1800-
red = Math::Clamp( RB_EvalExpression( &pStage->redExp, 1.0 ), 0.0f, 1.0f );
1801-
green = Math::Clamp( RB_EvalExpression( &pStage->greenExp, 1.0 ), 0.0f, 1.0f );
1802-
blue = Math::Clamp( RB_EvalExpression( &pStage->blueExp, 1.0 ), 0.0f, 1.0f );
1797+
red = RB_EvalExpression( &pStage->redExp, 1.0 );
1798+
green = RB_EvalExpression( &pStage->greenExp, 1.0 );
1799+
blue = RB_EvalExpression( &pStage->blueExp, 1.0 );
18031800
}
18041801

18051802
tess.svars.color.SetRed( red );
@@ -1878,7 +1875,7 @@ void Tess_ComputeColor( shaderStage_t *pStage )
18781875

18791876
case alphaGen_t::AGEN_CUSTOM:
18801877
{
1881-
alpha = Math::Clamp( RB_EvalExpression( &pStage->alphaExp, 1.0 ), 0.0f, 1.0f );
1878+
alpha = RB_EvalExpression( &pStage->alphaExp, 1.0 );
18821879

18831880
tess.svars.color.SetAlpha( alpha );
18841881
break;

src/engine/renderer/tr_shade_calc.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -441,9 +441,13 @@ float RB_EvalExpression( const expression_t *exp, float defaultValue )
441441

442442
float value = EvalExpression( exp, defaultValue );
443443

444-
if ( exp->bits & EXP_SRGB )
444+
if ( exp->bits & EXP_CLAMP )
445445
{
446446
value = Math::Clamp( value, 0.0f, 1.0f );
447+
}
448+
449+
if ( exp->bits & EXP_SRGB )
450+
{
447451
value = tr.convertFloatFromSRGB( value );
448452
}
449453

src/engine/renderer/tr_shader.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2739,25 +2739,25 @@ static bool ParseStage( shaderStage_t *stage, const char **text )
27392739
else if ( !Q_stricmp( token, "rgb" ) )
27402740
{
27412741
stage->rgbGen = colorGen_t::CGEN_CUSTOM_RGB;
2742-
ParseExpression( text, &stage->rgbExp, EXP_SRGB );
2742+
ParseExpression( text, &stage->rgbExp, EXP_CLAMP | EXP_SRGB );
27432743
}
27442744
// red <arithmetic expression>
27452745
else if ( !Q_stricmp( token, "red" ) )
27462746
{
27472747
stage->rgbGen = colorGen_t::CGEN_CUSTOM_RGBs;
2748-
ParseExpression( text, &stage->redExp, EXP_SRGB );
2748+
ParseExpression( text, &stage->redExp, EXP_CLAMP | EXP_SRGB );
27492749
}
27502750
// green <arithmetic expression>
27512751
else if ( !Q_stricmp( token, "green" ) )
27522752
{
27532753
stage->rgbGen = colorGen_t::CGEN_CUSTOM_RGBs;
2754-
ParseExpression( text, &stage->greenExp, EXP_SRGB );
2754+
ParseExpression( text, &stage->greenExp, EXP_CLAMP | EXP_SRGB );
27552755
}
27562756
// blue <arithmetic expression>
27572757
else if ( !Q_stricmp( token, "blue" ) )
27582758
{
27592759
stage->rgbGen = colorGen_t::CGEN_CUSTOM_RGBs;
2760-
ParseExpression( text, &stage->blueExp, EXP_SRGB );
2760+
ParseExpression( text, &stage->blueExp, EXP_CLAMP | EXP_SRGB );
27612761
}
27622762
// colored
27632763
else if ( !Q_stricmp( token, "colored" ) )
@@ -2859,17 +2859,17 @@ static bool ParseStage( shaderStage_t *stage, const char **text )
28592859
else if ( !Q_stricmp( token, "alpha" ) )
28602860
{
28612861
stage->alphaGen = alphaGen_t::AGEN_CUSTOM;
2862-
ParseExpression( text, &stage->alphaExp );
2862+
ParseExpression( text, &stage->alphaExp, EXP_CLAMP );
28632863
}
28642864
// color <exp>, <exp>, <exp>, <exp>
28652865
else if ( !Q_stricmp( token, "color" ) )
28662866
{
28672867
stage->rgbGen = colorGen_t::CGEN_CUSTOM_RGBs;
28682868
stage->alphaGen = alphaGen_t::AGEN_CUSTOM;
2869-
ParseExpression( text, &stage->redExp, EXP_SRGB );
2870-
ParseExpression( text, &stage->greenExp, EXP_SRGB );
2871-
ParseExpression( text, &stage->blueExp, EXP_SRGB );
2872-
ParseExpression( text, &stage->alphaExp );
2869+
ParseExpression( text, &stage->redExp, EXP_CLAMP | EXP_SRGB );
2870+
ParseExpression( text, &stage->greenExp, EXP_CLAMP | EXP_SRGB );
2871+
ParseExpression( text, &stage->blueExp, EXP_CLAMP | EXP_SRGB );
2872+
ParseExpression( text, &stage->alphaExp, EXP_CLAMP );
28732873
}
28742874
// tcGen <function>
28752875
else if ( !Q_stricmp( token, "texGen" ) || !Q_stricmp( token, "tcGen" ) )

0 commit comments

Comments
 (0)