Skip to content

Commit 061fe63

Browse files
committed
tr_shader: add the naiveBlend keyword
1 parent c34e93d commit 061fe63

File tree

4 files changed

+32
-9
lines changed

4 files changed

+32
-9
lines changed

src/engine/renderer/tr_init.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1283,7 +1283,7 @@ ScreenshotCmd screenshotPNGRegistration("screenshotPNG", ssFormat_t::SSF_PNG, "p
12831283
}
12841284

12851285
static float convertFloatFromSRGB_NOP( float f ) { return f; }
1286-
static Color::Color convertColorFromSRGB_NOP( Color::Color c ) { return c; }
1286+
Color::Color convertColorFromSRGB_NOP( Color::Color c ) { return c; }
12871287

12881288
/*
12891289
===============

src/engine/renderer/tr_local.h

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -979,6 +979,11 @@ enum
979979
ALL = BIT( 3 )
980980
};
981981

982+
using floatProcessor_t = float(*)(float);
983+
using colorProcessor_t = Color::Color(*)(Color::Color);
984+
985+
Color::Color convertColorFromSRGB_NOP( Color::Color c );
986+
982987
struct shaderStage_t
983988
{
984989
stageType_t type;
@@ -998,6 +1003,8 @@ enum
9981003
stageShaderBinder_t shaderBinder;
9991004
stageMaterialProcessor_t materialProcessor;
10001005

1006+
colorProcessor_t convertColorFromSRGB;
1007+
10011008
textureBundle_t bundle[ MAX_TEXTURE_BUNDLES ];
10021009

10031010
expression_t ifExp;
@@ -1269,6 +1276,8 @@ enum
12691276
| GLS_BLUEMASK_FALSE
12701277
| GLS_ALPHAMASK_FALSE,
12711278

1279+
GLS_NAIVEBLEND = ( 1 << 30 ),
1280+
12721281
GLS_DEFAULT = GLS_DEPTHMASK_TRUE
12731282
};
12741283

@@ -2397,9 +2406,6 @@ enum
23972406
int h;
23982407
};
23992408

2400-
using floatProcessor_t = float(*)(float);
2401-
using colorProcessor_t = Color::Color(*)(Color::Color);
2402-
24032409
/*
24042410
** trGlobals_t
24052411
**

src/engine/renderer/tr_shade.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1698,7 +1698,7 @@ void Tess_ComputeColor( shaderStage_t *pStage )
16981698
{
16991699
tess.svars.color = pStage->constantColor;
17001700
tess.svars.color.Clamp();
1701-
tess.svars.color = tr.convertColorFromSRGB( tess.svars.color );
1701+
tess.svars.color = pStage->convertColorFromSRGB( tess.svars.color );
17021702
break;
17031703
}
17041704

@@ -1708,7 +1708,7 @@ void Tess_ComputeColor( shaderStage_t *pStage )
17081708
{
17091709
tess.svars.color = backEnd.currentEntity->e.shaderRGBA;
17101710
tess.svars.color.Clamp();
1711-
tess.svars.color = tr.convertColorFromSRGB( tess.svars.color );
1711+
tess.svars.color = pStage->convertColorFromSRGB( tess.svars.color );
17121712
}
17131713
else
17141714
{
@@ -1724,7 +1724,7 @@ void Tess_ComputeColor( shaderStage_t *pStage )
17241724
{
17251725
tess.svars.color = backEnd.currentEntity->e.shaderRGBA;
17261726
tess.svars.color.Clamp();
1727-
tess.svars.color = tr.convertColorFromSRGB( tess.svars.color );
1727+
tess.svars.color = pStage->convertColorFromSRGB( tess.svars.color );
17281728
}
17291729
else
17301730
{
@@ -1757,7 +1757,7 @@ void Tess_ComputeColor( shaderStage_t *pStage )
17571757

17581758
tess.svars.color = Color::White * glow;
17591759
tess.svars.color.Clamp();
1760-
tess.svars.color = tr.convertColorFromSRGB( tess.svars.color );
1760+
tess.svars.color = pStage->convertColorFromSRGB( tess.svars.color );
17611761
break;
17621762
}
17631763

src/engine/renderer/tr_shader.cpp

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1495,6 +1495,16 @@ static bool LoadMap( shaderStage_t *stage, const char *buffer, stageType_t type,
14951495
{
14961496
case stageType_t::ST_COLORMAP:
14971497
case stageType_t::ST_DIFFUSEMAP:
1498+
{
1499+
bool naiveBlend = stage->stateBits & GLS_NAIVEBLEND;
1500+
1501+
if ( !naiveBlend )
1502+
{
1503+
imageParams.bits |= IF_SRGB;
1504+
stage->convertColorFromSRGB = tr.convertColorFromSRGB;
1505+
}
1506+
}
1507+
break;
14981508
case stageType_t::ST_GLOWMAP:
14991509
case stageType_t::ST_REFLECTIONMAP:
15001510
case stageType_t::ST_SKYBOXMAP:
@@ -2088,13 +2098,16 @@ static bool ParseStage( shaderStage_t *stage, const char **text )
20882098
const char *token;
20892099
int colorMaskBits = 0;
20902100
int depthMaskBits = GLS_DEPTHMASK_TRUE, blendSrcBits = 0, blendDstBits = 0, atestBits = 0, depthFuncBits = 0, polyModeBits = 0;
2101+
int naiveBlendBits = 0;
20912102
bool depthMaskExplicit = false;
20922103
int imageBits = 0;
20932104
filterType_t filterType;
20942105
char buffer[ 1024 ] = "";
20952106
bool loadMap = false;
20962107
bool loadAnimMap = true;
20972108

2109+
stage->convertColorFromSRGB = convertColorFromSRGB_NOP;
2110+
20982111
memset( delayedStageTextures, 0, sizeof( delayedStageTextures ) );
20992112
memset( delayedAnimationTextures, 0, sizeof( delayedAnimationTextures ) );
21002113

@@ -2641,6 +2654,10 @@ static bool ParseStage( shaderStage_t *stage, const char **text )
26412654
depthMaskBits = 0;
26422655
}
26432656
}
2657+
else if ( !Q_stricmp( token, "naiveBlend" ) )
2658+
{
2659+
naiveBlendBits |= GLS_NAIVEBLEND;
2660+
}
26442661
// stage <type>
26452662
else if ( !Q_stricmp( token, "stage" ) )
26462663
{
@@ -3329,7 +3346,7 @@ static bool ParseStage( shaderStage_t *stage, const char **text )
33293346
}
33303347

33313348
// compute state bits
3332-
stage->stateBits = colorMaskBits | depthMaskBits | blendSrcBits | blendDstBits | atestBits | depthFuncBits | polyModeBits;
3349+
stage->stateBits = colorMaskBits | depthMaskBits | blendSrcBits | blendDstBits | atestBits | depthFuncBits | polyModeBits | naiveBlendBits;
33333350

33343351
// Do not load heatHaze maps when r_heatHaze is disabled.
33353352
if ( stage->type == stageType_t::ST_HEATHAZEMAP && !r_heatHaze->integer )

0 commit comments

Comments
 (0)