Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions src.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ set(RENDERERLIST
)

set(GLSLSOURCELIST
${ENGINE_DIR}/renderer/glsl_source/common.glsl
${ENGINE_DIR}/renderer/glsl_source/common_cp.glsl
${ENGINE_DIR}/renderer/glsl_source/shaderProfiler_vp.glsl
${ENGINE_DIR}/renderer/glsl_source/shaderProfiler_fp.glsl
Expand Down
9 changes: 3 additions & 6 deletions src/engine/renderer/Material.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,8 @@ void UpdateSurfaceDataGeneric3D( uint32_t* materials, Material& material, drawSu
alphaGen_t alphaGen = SetAlphaGen( pStage );

bool mayUseVertexOverbright = pStage->type == stageType_t::ST_COLORMAP && drawSurf->bspSurface;
gl_genericShaderMaterial->SetUniform_ColorModulate( rgbGen, alphaGen, mayUseVertexOverbright );
const bool styleLightMap = pStage->type == stageType_t::ST_STYLELIGHTMAP || pStage->type == stageType_t::ST_STYLECOLORMAP;
gl_genericShaderMaterial->SetUniform_ColorModulateColorGen( rgbGen, alphaGen, mayUseVertexOverbright, styleLightMap );

Tess_ComputeColor( pStage );
gl_genericShaderMaterial->SetUniform_Color( tess.svars.color );
Expand Down Expand Up @@ -284,12 +285,8 @@ void UpdateSurfaceDataLightMapping( uint32_t* materials, Material& material, dra
bool enableGridLighting = ( lightMode == lightMode_t::GRID );
bool enableGridDeluxeMapping = ( deluxeMode == deluxeMode_t::GRID );

// u_LightFactor
gl_lightMappingShaderMaterial->SetUniform_LightFactor(
lightMode == lightMode_t::FULLBRIGHT ? 1.0f : tr.mapLightFactor );

// u_ColorModulate
gl_lightMappingShaderMaterial->SetUniform_ColorModulate( rgbGen, alphaGen );
gl_lightMappingShaderMaterial->SetUniform_ColorModulateColorGen( rgbGen, alphaGen, false, lightMode != lightMode_t::FULLBRIGHT );

// u_Color
gl_lightMappingShaderMaterial->SetUniform_Color( tess.svars.color );
Expand Down
29 changes: 17 additions & 12 deletions src/engine/renderer/gl_shader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,10 @@ static std::string GenCompatHeader() {
str += "float smoothstep(float edge0, float edge1, float x) { float t = clamp((x - edge0) / (edge1 - edge0), 0.0, 1.0); return t * t * (3.0 - 2.0 * t); }\n";
}

if ( !glConfig2.gpuShader5Available ) {
str += "#define unpackUnorm4x8( value ) ( ( vec4( value, value >> 8, value >> 16, value >> 24 ) & 0xFF ) / 255.0f )\n";
}

return str;
}

Expand Down Expand Up @@ -1434,9 +1438,12 @@ std::string GLShaderManager::ShaderPostProcess( GLShader *shader, const std::str
bool skip = false;
if ( line.find( "uniform" ) < line.find( "//" ) && line.find( ";" ) != std::string::npos ) {
for ( GLUniform* uniform : shader->_uniforms ) {
if ( !uniform->IsGlobal() && ( line.find( uniform->GetName() ) != std::string::npos ) ) {
skip = true;
break;
if ( !uniform->IsGlobal() ) {
const size_t pos = line.find( uniform->GetName() );
if ( pos != std::string::npos && !Str::cisalpha( line[pos + strlen( uniform->GetName() )] ) ) {
skip = true;
break;
}
}
}
}
Expand Down Expand Up @@ -2187,7 +2194,7 @@ GLShader_generic::GLShader_generic( GLShaderManager *manager ) :
u_AlphaThreshold( this ),
u_ModelMatrix( this ),
u_ModelViewProjectionMatrix( this ),
u_ColorModulate( this ),
u_ColorModulateColorGen( this ),
u_Color( this ),
u_Bones( this ),
u_VertexInterpolation( this ),
Expand Down Expand Up @@ -2219,7 +2226,7 @@ GLShader_genericMaterial::GLShader_genericMaterial( GLShaderManager* manager ) :
u_AlphaThreshold( this ),
u_ModelMatrix( this ),
u_ModelViewProjectionMatrix( this ),
u_ColorModulate( this ),
u_ColorModulateColorGen( this ),
u_Color( this ),
u_DepthScale( this ),
u_ShowTris( this ),
Expand Down Expand Up @@ -2254,13 +2261,12 @@ GLShader_lightMapping::GLShader_lightMapping( GLShaderManager *manager ) :
u_LightTiles( this ),
u_TextureMatrix( this ),
u_SpecularExponent( this ),
u_ColorModulate( this ),
u_ColorModulateColorGen( this ),
u_Color( this ),
u_AlphaThreshold( this ),
u_ViewOrigin( this ),
u_ModelMatrix( this ),
u_ModelViewProjectionMatrix( this ),
u_LightFactor( this ),
u_Bones( this ),
u_VertexInterpolation( this ),
u_ReliefDepthScale( this ),
Expand Down Expand Up @@ -2323,13 +2329,12 @@ GLShader_lightMappingMaterial::GLShader_lightMappingMaterial( GLShaderManager* m
u_LightTiles( this ),
u_TextureMatrix( this ),
u_SpecularExponent( this ),
u_ColorModulate( this ),
u_ColorModulateColorGen( this ),
u_Color( this ),
u_AlphaThreshold( this ),
u_ViewOrigin( this ),
u_ModelMatrix( this ),
u_ModelViewProjectionMatrix( this ),
u_LightFactor( this ),
u_ReliefDepthScale( this ),
u_ReliefOffsetBias( this ),
u_NormalScale( this ),
Expand Down Expand Up @@ -2383,7 +2388,7 @@ GLShader_forwardLighting_omniXYZ::GLShader_forwardLighting_omniXYZ( GLShaderMana
u_TextureMatrix( this ),
u_SpecularExponent( this ),
u_AlphaThreshold( this ),
u_ColorModulate( this ),
u_ColorModulateColorGen( this ),
u_Color( this ),
u_ViewOrigin( this ),
u_LightOrigin( this ),
Expand Down Expand Up @@ -2436,7 +2441,7 @@ GLShader_forwardLighting_projXYZ::GLShader_forwardLighting_projXYZ( GLShaderMana
u_TextureMatrix( this ),
u_SpecularExponent( this ),
u_AlphaThreshold( this ),
u_ColorModulate( this ),
u_ColorModulateColorGen( this ),
u_Color( this ),
u_ViewOrigin( this ),
u_LightOrigin( this ),
Expand Down Expand Up @@ -2500,7 +2505,7 @@ GLShader_forwardLighting_directionalSun::GLShader_forwardLighting_directionalSun
u_TextureMatrix( this ),
u_SpecularExponent( this ),
u_AlphaThreshold( this ),
u_ColorModulate( this ),
u_ColorModulateColorGen( this ),
u_Color( this ),
u_ViewOrigin( this ),
u_LightDir( this ),
Expand Down
111 changes: 56 additions & 55 deletions src/engine/renderer/gl_shader.h
Original file line number Diff line number Diff line change
Expand Up @@ -2136,21 +2136,6 @@ class GLCompileMacro_USE_PHYSICAL_MAPPING :
}
};

class u_LightFactor :
GLUniform1f
{
public:
u_LightFactor( GLShader *shader ) :
GLUniform1f( shader, "u_LightFactor" )
{
}

void SetUniform_LightFactor( const float lightFactor )
{
this->SetValue( lightFactor );
}
};

class u_ColorMap :
GLUniformSampler2D {
public:
Expand Down Expand Up @@ -3099,17 +3084,17 @@ class u_CloudHeight :
};

class u_Color :
GLUniform4f
GLUniform1ui
{
public:
u_Color( GLShader *shader ) :
GLUniform4f( shader, "u_Color" )
GLUniform1ui( shader, "u_Color" )
{
}

void SetUniform_Color( const Color::Color& color )
{
this->SetValue( color.ToArray() );
this->SetValue( packUnorm4x8( color.ToArray() ) );
}
};

Expand Down Expand Up @@ -3603,68 +3588,86 @@ class u_ColorModulate :
{
this->SetValue( v );
}
void SetUniform_ColorModulate( colorGen_t colorGen, alphaGen_t alphaGen, bool vertexOverbright = false )
{
vec4_t v;
};

enum class ColorModulate {
COLOR_ONE = BIT( 0 ),
COLOR_MINUS_ONE = BIT( 1 ),
COLOR_LIGHTFACTOR = BIT( 2 ),
ALPHA_ONE = BIT( 3 ),
ALPHA_MINUS_ONE = BIT( 4 )
};

class u_ColorModulateColorGen :
GLUniform1ui {
public:
u_ColorModulateColorGen( GLShader* shader ) :
GLUniform1ui( shader, "u_ColorModulateColorGen" ) {
}

void SetUniform_ColorModulateColorGen( colorGen_t colorGen, alphaGen_t alphaGen, bool vertexOverbright = false,
const bool useMapLightFactor = false ) {
uint32_t colorModulate = 0;
bool needAttrib = false;

if ( r_logFile->integer )
{
GLimp_LogComment( va( "--- u_ColorModulate::SetUniform_ColorModulate( program = %s, colorGen = %s, alphaGen = %s ) ---\n", _shader->GetName().c_str(), Util::enum_str(colorGen), Util::enum_str(alphaGen)) );
if ( r_logFile->integer ) {
GLimp_LogComment(
va( "--- u_ColorModulate::SetUniform_ColorModulateColorGen( program = %s, colorGen = %s, alphaGen = %s ) ---\n",
_shader->GetName().c_str(), Util::enum_str( colorGen ), Util::enum_str( alphaGen ) )
);
}

switch ( colorGen )
{
uint32_t lightFactor = 0;
switch ( colorGen ) {
case colorGen_t::CGEN_VERTEX:
needAttrib = true;
if ( vertexOverbright )
{
if ( vertexOverbright ) {
// vertexOverbright is only needed for non-lightmapped cases. When there is a
// lightmap, this is done by multiplying with the overbright-scaled white image
VectorSet( v, tr.mapLightFactor, tr.mapLightFactor, tr.mapLightFactor );
}
else
{
VectorSet( v, 1, 1, 1 );
colorModulate |= Util::ordinal( ColorModulate::COLOR_LIGHTFACTOR );
lightFactor = uint32_t( tr.mapLightFactor ) << 5;
} else {
colorModulate |= Util::ordinal( ColorModulate::COLOR_ONE );
}
break;

case colorGen_t::CGEN_ONE_MINUS_VERTEX:
needAttrib = true;
VectorSet( v, -1, -1, -1 );
colorModulate |= Util::ordinal( ColorModulate::COLOR_MINUS_ONE );
break;

default:
VectorSet( v, 0, 0, 0 );
break;
}

switch ( alphaGen )
{
if ( useMapLightFactor ) {
ASSERT_EQ( vertexOverbright, false );
lightFactor = uint32_t( tr.mapLightFactor ) << 5;
}

colorModulate |= lightFactor ? lightFactor : 1 << 5;

switch ( alphaGen ) {
case alphaGen_t::AGEN_VERTEX:
needAttrib = true;
v[ 3 ] = 1.0f;
colorModulate |= Util::ordinal( ColorModulate::ALPHA_ONE );
break;

case alphaGen_t::AGEN_ONE_MINUS_VERTEX:
needAttrib = true;
v[ 3 ] = -1.0f;
colorModulate |= Util::ordinal( ColorModulate::ALPHA_MINUS_ONE );
break;

default:
v[ 3 ] = 0.0f;
break;
}

if ( needAttrib )
{
if ( needAttrib ) {
_shader->AddVertexAttribBit( ATTR_COLOR );
}
else
{
} else {
_shader->DelVertexAttribBit( ATTR_COLOR );
}
this->SetValue( v );
this->SetValue( colorModulate );
}
};

Expand Down Expand Up @@ -3929,7 +3932,7 @@ class GLShader_generic :
public u_AlphaThreshold,
public u_ModelMatrix,
public u_ModelViewProjectionMatrix,
public u_ColorModulate,
public u_ColorModulateColorGen,
public u_Color,
public u_Bones,
public u_VertexInterpolation,
Expand Down Expand Up @@ -3958,7 +3961,7 @@ class GLShader_genericMaterial :
public u_AlphaThreshold,
public u_ModelMatrix,
public u_ModelViewProjectionMatrix,
public u_ColorModulate,
public u_ColorModulateColorGen,
public u_Color,
public u_DepthScale,
public u_ShowTris,
Expand Down Expand Up @@ -3990,13 +3993,12 @@ class GLShader_lightMapping :
public u_LightTiles,
public u_TextureMatrix,
public u_SpecularExponent,
public u_ColorModulate,
public u_ColorModulateColorGen,
public u_Color,
public u_AlphaThreshold,
public u_ViewOrigin,
public u_ModelMatrix,
public u_ModelViewProjectionMatrix,
public u_LightFactor,
public u_Bones,
public u_VertexInterpolation,
public u_ReliefDepthScale,
Expand Down Expand Up @@ -4042,13 +4044,12 @@ class GLShader_lightMappingMaterial :
public u_LightTiles,
public u_TextureMatrix,
public u_SpecularExponent,
public u_ColorModulate,
public u_ColorModulateColorGen,
public u_Color,
public u_AlphaThreshold,
public u_ViewOrigin,
public u_ModelMatrix,
public u_ModelViewProjectionMatrix,
public u_LightFactor,
public u_ReliefDepthScale,
public u_ReliefOffsetBias,
public u_NormalScale,
Expand Down Expand Up @@ -4089,7 +4090,7 @@ class GLShader_forwardLighting_omniXYZ :
public u_TextureMatrix,
public u_SpecularExponent,
public u_AlphaThreshold,
public u_ColorModulate,
public u_ColorModulateColorGen,
public u_Color,
public u_ViewOrigin,
public u_LightOrigin,
Expand Down Expand Up @@ -4132,7 +4133,7 @@ class GLShader_forwardLighting_projXYZ :
public u_TextureMatrix,
public u_SpecularExponent,
public u_AlphaThreshold,
public u_ColorModulate,
public u_ColorModulateColorGen,
public u_Color,
public u_ViewOrigin,
public u_LightOrigin,
Expand Down Expand Up @@ -4182,7 +4183,7 @@ class GLShader_forwardLighting_directionalSun :
public u_TextureMatrix,
public u_SpecularExponent,
public u_AlphaThreshold,
public u_ColorModulate,
public u_ColorModulateColorGen,
public u_Color,
public u_ViewOrigin,
public u_LightDir,
Expand Down
Loading