Skip to content

Commit 3493cb6

Browse files
committed
Implement stage-level colorspace shader keyword
Allows making conditional stages that depend on whether naive or linear blending is used.
1 parent b2ab4b6 commit 3493cb6

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

src/engine/renderer/tr_shader.cpp

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2020,6 +2020,7 @@ static bool ParseStage( shaderStage_t *stage, const char **text )
20202020
filterType_t filterType;
20212021
char buffer[ 1024 ] = "";
20222022
bool loadMap = false;
2023+
bool colorspaceMatch = true;
20232024

20242025
while ( true )
20252026
{
@@ -2855,6 +2856,23 @@ static bool ParseStage( shaderStage_t *stage, const char **text )
28552856
continue;
28562857
}
28572858
}
2859+
// disable the stage if the renderer's blending mode does not match the specified mode
2860+
else if ( !Q_stricmp( token, "colorspace" ) )
2861+
{
2862+
token = COM_ParseExt2( text, false );
2863+
if ( !Q_stricmp( token, "naive" ) )
2864+
{
2865+
colorspaceMatch = !tr.worldLinearizeTexture;
2866+
}
2867+
else if ( !Q_stricmp( token, "linear" ) )
2868+
{
2869+
colorspaceMatch = tr.worldLinearizeTexture;
2870+
}
2871+
else
2872+
{
2873+
Log::Warn( "unknown colorspace '%s' in shader '%s'", token, shader.name );
2874+
}
2875+
}
28582876
// alpha <arithmetic expression>
28592877
else if ( !Q_stricmp( token, "alpha" ) )
28602878
{
@@ -3233,6 +3251,11 @@ static bool ParseStage( shaderStage_t *stage, const char **text )
32333251
}
32343252
}
32353253

3254+
if ( !colorspaceMatch )
3255+
{
3256+
return true; // parsing succeeded, but not active
3257+
}
3258+
32363259
// parsing succeeded
32373260
stage->active = true;
32383261

@@ -3866,8 +3889,6 @@ static bool ParseShader( const char *_text )
38663889
return false;
38673890
}
38683891

3869-
stage->active = true;
3870-
38713892
/* Examples of shaders with light styles, those
38723893
shaders are generated by the q3map2 map compiler.
38733894

0 commit comments

Comments
 (0)