Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/engine/renderer/tr_init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1283,7 +1283,7 @@ ScreenshotCmd screenshotPNGRegistration("screenshotPNG", ssFormat_t::SSF_PNG, "p
}

static float convertFloatFromSRGB_NOP( float f ) { return f; }
static Color::Color convertColorFromSRGB_NOP( Color::Color c ) { return c; }
Color::Color convertColorFromSRGB_NOP( Color::Color c ) { return c; }

/*
===============
Expand Down
13 changes: 10 additions & 3 deletions src/engine/renderer/tr_local.h
Original file line number Diff line number Diff line change
Expand Up @@ -979,6 +979,11 @@ enum
ALL = BIT( 3 )
};

using floatProcessor_t = float(*)(float);
using colorProcessor_t = Color::Color(*)(Color::Color);

Color::Color convertColorFromSRGB_NOP( Color::Color c );

struct shaderStage_t
{
stageType_t type;
Expand All @@ -998,6 +1003,8 @@ enum
stageShaderBinder_t shaderBinder;
stageMaterialProcessor_t materialProcessor;

colorProcessor_t convertColorFromSRGB;

textureBundle_t bundle[ MAX_TEXTURE_BUNDLES ];

expression_t ifExp;
Expand Down Expand Up @@ -1269,6 +1276,9 @@ enum
| GLS_BLUEMASK_FALSE
| GLS_ALPHAMASK_FALSE,

GLS_LINEAR_COLORMAP = ( 1 << 30 ),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't belong here since it doesn't affect the OpenGL state while rendering.

GLS_LINEAR_COLOR = ( 1 << 31 ),

GLS_DEFAULT = GLS_DEPTHMASK_TRUE
};

Expand Down Expand Up @@ -2397,9 +2407,6 @@ enum
int h;
};

using floatProcessor_t = float(*)(float);
using colorProcessor_t = Color::Color(*)(Color::Color);

/*
** trGlobals_t
**
Expand Down
8 changes: 4 additions & 4 deletions src/engine/renderer/tr_shade.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1698,7 +1698,7 @@ void Tess_ComputeColor( shaderStage_t *pStage )
{
tess.svars.color = pStage->constantColor;
tess.svars.color.Clamp();
tess.svars.color = tr.convertColorFromSRGB( tess.svars.color );
tess.svars.color = pStage->convertColorFromSRGB( tess.svars.color );
break;
}

Expand All @@ -1708,7 +1708,7 @@ void Tess_ComputeColor( shaderStage_t *pStage )
{
tess.svars.color = backEnd.currentEntity->e.shaderRGBA;
tess.svars.color.Clamp();
tess.svars.color = tr.convertColorFromSRGB( tess.svars.color );
tess.svars.color = pStage->convertColorFromSRGB( tess.svars.color );
}
else
{
Expand All @@ -1724,7 +1724,7 @@ void Tess_ComputeColor( shaderStage_t *pStage )
{
tess.svars.color = backEnd.currentEntity->e.shaderRGBA;
tess.svars.color.Clamp();
tess.svars.color = tr.convertColorFromSRGB( tess.svars.color );
tess.svars.color = pStage->convertColorFromSRGB( tess.svars.color );
}
else
{
Expand Down Expand Up @@ -1757,7 +1757,7 @@ void Tess_ComputeColor( shaderStage_t *pStage )

tess.svars.color = Color::White * glow;
tess.svars.color.Clamp();
tess.svars.color = tr.convertColorFromSRGB( tess.svars.color );
tess.svars.color = pStage->convertColorFromSRGB( tess.svars.color );
break;
}

Expand Down
28 changes: 27 additions & 1 deletion src/engine/renderer/tr_shader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1495,6 +1495,21 @@ static bool LoadMap( shaderStage_t *stage, const char *buffer, stageType_t type,
{
case stageType_t::ST_COLORMAP:
case stageType_t::ST_DIFFUSEMAP:
{
bool linearColorMap = stage->stateBits & GLS_LINEAR_COLORMAP;
bool linearColor = stage->stateBits & GLS_LINEAR_COLOR;

if ( !linearColorMap )
{
imageParams.bits |= IF_SRGB;
}

if ( !linearColor )
{
stage->convertColorFromSRGB = tr.convertColorFromSRGB;
}
}
break;
case stageType_t::ST_GLOWMAP:
case stageType_t::ST_REFLECTIONMAP:
case stageType_t::ST_SKYBOXMAP:
Expand Down Expand Up @@ -2088,13 +2103,16 @@ static bool ParseStage( shaderStage_t *stage, const char **text )
const char *token;
int colorMaskBits = 0;
int depthMaskBits = GLS_DEPTHMASK_TRUE, blendSrcBits = 0, blendDstBits = 0, atestBits = 0, depthFuncBits = 0, polyModeBits = 0;
int linearBits = 0;
bool depthMaskExplicit = false;
int imageBits = 0;
filterType_t filterType;
char buffer[ 1024 ] = "";
bool loadMap = false;
bool loadAnimMap = false;

stage->convertColorFromSRGB = convertColorFromSRGB_NOP;

memset( delayedStageTextures, 0, sizeof( delayedStageTextures ) );
memset( delayedAnimationTextures, 0, sizeof( delayedAnimationTextures ) );

Expand Down Expand Up @@ -2641,6 +2659,14 @@ static bool ParseStage( shaderStage_t *stage, const char **text )
depthMaskBits = 0;
}
}
else if ( !Q_stricmp( token, "linearColorMap" ) )
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dislike the "linear X" naming. It suggests that the input is in a linear color space and so it should be converted to whatever colorspace is used for further operations. But the point is rather that the resulting color is deliberately made different depending on the blend regime by not converting. So I suggest a name that describes it more as disabling color conversion, like noTextureColorspaceConversion.

Also for the case of the color uniform, maybe we could make it more obvious what the modifier is used for by making it part of the rgbgen syntax. Something like rgbgen noconvert const (0.5 0.5 0.5)

{
linearBits |= GLS_LINEAR_COLORMAP;
}
else if ( !Q_stricmp( token, "linearColor" ) )
{
linearBits |= GLS_LINEAR_COLOR;
}
// stage <type>
else if ( !Q_stricmp( token, "stage" ) )
{
Expand Down Expand Up @@ -3329,7 +3355,7 @@ static bool ParseStage( shaderStage_t *stage, const char **text )
}

// compute state bits
stage->stateBits = colorMaskBits | depthMaskBits | blendSrcBits | blendDstBits | atestBits | depthFuncBits | polyModeBits;
stage->stateBits = colorMaskBits | depthMaskBits | blendSrcBits | blendDstBits | atestBits | depthFuncBits | polyModeBits | linearBits;

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