Skip to content
Open
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
2 changes: 0 additions & 2 deletions src.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,6 @@ set(GLSL_EMBED_LIST
lightMapping_fp.glsl
liquid_vp.glsl
liquid_fp.glsl
portal_vp.glsl
portal_fp.glsl
reflection_CB_vp.glsl
reflection_CB_fp.glsl
screen_vp.glsl
Expand Down
4 changes: 0 additions & 4 deletions src/engine/renderer/GeometryOptimiser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,6 @@ void MarkShaderBuildScreen( const shaderStage_t* ) {
gl_screenShader->MarkProgramForBuilding();
}

void MarkShaderBuildPortal( const shaderStage_t* ) {
gl_portalShader->MarkProgramForBuilding();
}

void MarkShaderBuildHeatHaze( const shaderStage_t* pStage ) {
ProcessShaderHeatHaze( pStage );
gl_heatHazeShader->MarkProgramForBuilding();
Expand Down
1 change: 0 additions & 1 deletion src/engine/renderer/GeometryOptimiser.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ void MarkShaderBuildLightMapping( const shaderStage_t* pStage );
void MarkShaderBuildReflection( const shaderStage_t* pStage );
void MarkShaderBuildSkybox( const shaderStage_t* pStage );
void MarkShaderBuildScreen( const shaderStage_t* pStage );
void MarkShaderBuildPortal( const shaderStage_t* pStage );
void MarkShaderBuildHeatHaze( const shaderStage_t* pStage );
void MarkShaderBuildLiquid( const shaderStage_t* pStage );

Expand Down
22 changes: 19 additions & 3 deletions src/engine/renderer/Material.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ void UpdateSurfaceDataNOP( uint32_t*, shaderStage_t*, bool, bool ) {
}

void UpdateSurfaceDataGeneric3D( uint32_t* materials, shaderStage_t* pStage, bool, bool ) {
// shader_t* shader = pStage->shader;
shader_t* shader = pStage->shader;

materials += pStage->bufferOffset;

Expand All @@ -154,11 +154,13 @@ void UpdateSurfaceDataGeneric3D( uint32_t* materials, shaderStage_t* pStage, boo
alphaGen_t alphaGen = SetAlphaGen( pStage );

const bool styleLightMap = pStage->type == stageType_t::ST_STYLELIGHTMAP || pStage->type == stageType_t::ST_STYLECOLORMAP;
gl_genericShaderMaterial->SetUniform_ColorModulateColorGen_Uint( rgbGen, alphaGen, styleLightMap );
gl_genericShaderMaterial->SetUniform_ColorModulateColorGen_Uint( rgbGen, alphaGen, styleLightMap || pStage->forceVertexLighting );

Tess_ComputeColor( pStage );
gl_genericShaderMaterial->SetUniform_Color_Uint( tess.svars.color );

gl_genericShaderMaterial->SetUniform_InversePortalRange( 1.0f / shader->portalRange );

gl_genericShaderMaterial->SetUniform_DepthScale( pStage->depthFadeValue );

gl_genericShaderMaterial->WriteUniformsToBuffer( materials, GLShader::MATERIAL );
Expand Down Expand Up @@ -879,6 +881,7 @@ void BindShaderGeneric3D( Material* material ) {
// Select shader permutation.
gl_genericShaderMaterial->SetTCGenEnvironment( material->tcGenEnvironment );
gl_genericShaderMaterial->SetTCGenLightmap( material->tcGen_Lightmap );
gl_genericShaderMaterial->SetAlphaGenPortal( material->alphaGenPortal );
gl_genericShaderMaterial->SetDepthFade( material->hasDepthFade );
gl_genericShaderMaterial->SetDeform( material->deformIndex );

Expand All @@ -892,6 +895,14 @@ void BindShaderGeneric3D( Material* material ) {

gl_genericShaderMaterial->SetUniform_ModelMatrix( backEnd.orientation.transformMatrix );
gl_genericShaderMaterial->SetUniform_ModelViewProjectionMatrix( glState.modelViewProjectionMatrix[glState.stackIndex] );
{
matrix_t unprojectMatrix;
MatrixCopy( backEnd.viewParms.projectionMatrix, unprojectMatrix );
MatrixInverse( unprojectMatrix );
MatrixMultiplyTranslation( unprojectMatrix, -1.0f, -1.0f, -1.0f );
MatrixMultiplyScale( unprojectMatrix, 2.0f / windowConfig.vidWidth, 2.0f / windowConfig.vidHeight, 2.0f );
gl_genericShaderMaterial->SetUniform_UnprojectMatrix( unprojectMatrix );
}

gl_genericShaderMaterial->SetUniform_DepthMapBindless( GL_BindToTMU( 1, tr.depthSamplerImage ) );

Expand Down Expand Up @@ -1097,6 +1108,10 @@ void ProcessMaterialGeneric3D( Material* material, shaderStage_t* pStage, Materi
gl_genericShaderMaterial->SetTCGenEnvironment( pStage->tcGen_Environment );
gl_genericShaderMaterial->SetTCGenLightmap( pStage->tcGen_Lightmap );

bool alphaGenPortal = pStage->alphaGen == alphaGen_t::AGEN_PORTAL;
material->alphaGenPortal = alphaGenPortal;
gl_genericShaderMaterial->SetAlphaGenPortal( alphaGenPortal );

bool hasDepthFade = pStage->hasDepthFade;
material->hasDepthFade = hasDepthFade;
gl_genericShaderMaterial->SetDepthFade( hasDepthFade );
Expand Down Expand Up @@ -1299,7 +1314,8 @@ void MaterialSystem::AddStage( MaterialSurface* surface, shaderStage_t* pStage,
}

if ( pStage->shader->reliefDepthScale != pStage2->shader->reliefDepthScale
|| pStage->shader->reliefOffsetBias != pStage2->shader->reliefOffsetBias )
|| pStage->shader->reliefOffsetBias != pStage2->shader->reliefOffsetBias
|| pStage->shader->portalRange != pStage2->shader->portalRange )
{
continue;
}
Expand Down
1 change: 1 addition & 0 deletions src/engine/renderer/Material.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ struct Material {
int deformIndex;
bool tcGenEnvironment;
bool tcGen_Lightmap;
bool alphaGenPortal;
bool hasDepthFade;

bool bspSurface;
Expand Down
22 changes: 6 additions & 16 deletions src/engine/renderer/gl_shader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ GLShader_heatHaze *gl_heatHazeShader = nullptr;
GLShader_heatHazeMaterial *gl_heatHazeShaderMaterial = nullptr;
GLShader_liquid *gl_liquidShader = nullptr;
GLShader_liquidMaterial *gl_liquidShaderMaterial = nullptr;
GLShader_portal *gl_portalShader = nullptr;
GLShader_reflection *gl_reflectionShader = nullptr;
GLShader_reflectionMaterial *gl_reflectionShaderMaterial = nullptr;
GLShader_screen *gl_screenShader = nullptr;
Expand Down Expand Up @@ -2446,12 +2445,14 @@ GLShader_generic::GLShader_generic() :
u_AlphaThreshold( this ),
u_ModelMatrix( this ),
u_ModelViewProjectionMatrix( this ),
u_UnprojectMatrix( this ),
u_ColorModulateColorGen_Float( this ),
u_ColorModulateColorGen_Uint( this ),
u_Color_Float( this ),
u_Color_Uint( this ),
u_Bones( this ),
u_VertexInterpolation( this ),
u_InversePortalRange( this ),
u_DepthScale( this ),
u_ProfilerZero( this ),
u_ProfilerRenderSubGroups( this ),
Expand All @@ -2460,6 +2461,7 @@ GLShader_generic::GLShader_generic() :
GLCompileMacro_USE_VERTEX_ANIMATION( this ),
GLCompileMacro_USE_TCGEN_ENVIRONMENT( this ),
GLCompileMacro_USE_TCGEN_LIGHTMAP( this ),
GLCompileMacro_USE_ALPHAGEN_PORTAL( this ),
GLCompileMacro_USE_DEPTH_FADE( this )
{
}
Expand All @@ -2480,8 +2482,10 @@ GLShader_genericMaterial::GLShader_genericMaterial() :
u_AlphaThreshold( this ),
u_ModelMatrix( this ),
u_ModelViewProjectionMatrix( this ),
u_UnprojectMatrix( this ),
u_ColorModulateColorGen_Uint( this ),
u_Color_Uint( this ),
u_InversePortalRange( this ),
u_DepthScale( this ),
u_ShowTris( this ),
u_MaterialColour( this ),
Expand All @@ -2490,6 +2494,7 @@ GLShader_genericMaterial::GLShader_genericMaterial() :
GLDeformStage( this ),
GLCompileMacro_USE_TCGEN_ENVIRONMENT( this ),
GLCompileMacro_USE_TCGEN_LIGHTMAP( this ),
GLCompileMacro_USE_ALPHAGEN_PORTAL( this ),
GLCompileMacro_USE_DEPTH_FADE( this ) {
}

Expand Down Expand Up @@ -2769,21 +2774,6 @@ GLShader_screenMaterial::GLShader_screenMaterial() :
u_ModelViewProjectionMatrix( this ) {
}

GLShader_portal::GLShader_portal() :
GLShader( "portal", ATTR_POSITION,
false, "portal", "portal" ),
u_CurrentMap( this ),
u_ModelViewMatrix( this ),
u_ModelViewProjectionMatrix( this ),
u_InversePortalRange( this )
{
}

void GLShader_portal::SetShaderProgramUniforms( ShaderProgramDescriptor *shaderProgram )
{
glUniform1i( glGetUniformLocation( shaderProgram->id, "u_CurrentMap" ), 0 );
}

GLShader_contrast::GLShader_contrast() :
GLShader( "contrast", ATTR_POSITION,
false, "screenSpace", "contrast" ),
Expand Down
51 changes: 37 additions & 14 deletions src/engine/renderer/gl_shader.h
Original file line number Diff line number Diff line change
Expand Up @@ -939,6 +939,7 @@ class GLCompileMacro
USE_REFLECTIVE_SPECULAR,
LIGHT_DIRECTIONAL,
USE_DEPTH_FADE,
USE_ALPHAGEN_PORTAL,
USE_PHYSICAL_MAPPING,
};

Expand Down Expand Up @@ -1425,6 +1426,35 @@ class GLCompileMacro_USE_DEPTH_FADE :
}
};

class GLCompileMacro_USE_ALPHAGEN_PORTAL :
GLCompileMacro
{
public:
GLCompileMacro_USE_ALPHAGEN_PORTAL( GLShader *shader ) :
GLCompileMacro( shader )
{
}

const char *GetName() const override
{
return "USE_ALPHAGEN_PORTAL";
}

EGLCompileMacro GetType() const override
{
return EGLCompileMacro::USE_ALPHAGEN_PORTAL;
}

int GetShaderTypes() const override {
return ShaderType::FRAGMENT;
}

void SetAlphaGenPortal( bool enable )
{
SetMacro( enable );
}
};

class GLCompileMacro_USE_PHYSICAL_MAPPING :
GLCompileMacro
{
Expand Down Expand Up @@ -2401,7 +2431,7 @@ class u_InversePortalRange :
{
public:
u_InversePortalRange( GLShader *shader ) :
GLUniform1f( shader, "u_InversePortalRange", PUSH )
GLUniform1f( shader, "u_InversePortalRange", MATERIAL_OR_PUSH )
{
}

Expand Down Expand Up @@ -2939,12 +2969,14 @@ class GLShader_generic :
public u_AlphaThreshold,
public u_ModelMatrix,
public u_ModelViewProjectionMatrix,
public u_UnprojectMatrix,
public u_ColorModulateColorGen_Float,
public u_ColorModulateColorGen_Uint,
public u_Color_Float,
public u_Color_Uint,
public u_Bones,
public u_VertexInterpolation,
public u_InversePortalRange,
public u_DepthScale,
public u_ProfilerZero,
public u_ProfilerRenderSubGroups,
Expand All @@ -2953,6 +2985,7 @@ class GLShader_generic :
public GLCompileMacro_USE_VERTEX_ANIMATION,
public GLCompileMacro_USE_TCGEN_ENVIRONMENT,
public GLCompileMacro_USE_TCGEN_LIGHTMAP,
public GLCompileMacro_USE_ALPHAGEN_PORTAL,
public GLCompileMacro_USE_DEPTH_FADE
{
public:
Expand All @@ -2969,8 +3002,10 @@ class GLShader_genericMaterial :
public u_AlphaThreshold,
public u_ModelMatrix,
public u_ModelViewProjectionMatrix,
public u_UnprojectMatrix,
public u_ColorModulateColorGen_Uint,
public u_Color_Uint,
public u_InversePortalRange,
public u_DepthScale,
public u_ShowTris,
public u_MaterialColour,
Expand All @@ -2979,6 +3014,7 @@ class GLShader_genericMaterial :
public GLDeformStage,
public GLCompileMacro_USE_TCGEN_ENVIRONMENT,
public GLCompileMacro_USE_TCGEN_LIGHTMAP,
public GLCompileMacro_USE_ALPHAGEN_PORTAL,
public GLCompileMacro_USE_DEPTH_FADE {
public:
GLShader_genericMaterial();
Expand Down Expand Up @@ -3232,18 +3268,6 @@ class GLShader_screenMaterial :
GLShader_screenMaterial();
};

class GLShader_portal :
public GLShader,
public u_CurrentMap,
public u_ModelViewMatrix,
public u_ModelViewProjectionMatrix,
public u_InversePortalRange
{
public:
GLShader_portal();
void SetShaderProgramUniforms( ShaderProgramDescriptor *shaderProgram ) override;
};

class GLShader_contrast :
public GLShader,
public u_ColorMap {
Expand Down Expand Up @@ -3527,7 +3551,6 @@ extern GLShader_heatHaze *gl_heatHazeShader;
extern GLShader_heatHazeMaterial *gl_heatHazeShaderMaterial;
extern GLShader_liquid *gl_liquidShader;
extern GLShader_liquidMaterial *gl_liquidShaderMaterial;
extern GLShader_portal *gl_portalShader;
extern GLShader_reflection *gl_reflectionShader;
extern GLShader_reflectionMaterial *gl_reflectionShaderMaterial;
extern GLShader_screen *gl_screenShader;
Expand Down
3 changes: 1 addition & 2 deletions src/engine/renderer/glsl_source/common.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,6 @@ void ColorModulateColor_lightFactor(

vec4 unpackedColor = UnpackColor( packedColor );

unpackedColor.rgb *= lightFactor;

ModulateColor( colorModulation, unpackedColor, color );
color.rgb *= lightFactor;
}
15 changes: 15 additions & 0 deletions src/engine/renderer/glsl_source/generic_fp.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ IN(smooth) float var_FadeDepth;
uniform sampler2D u_DepthMap;
#endif

#if defined(USE_ALPHAGEN_PORTAL)
uniform float u_InversePortalRange;
uniform mat4 u_UnprojectMatrix;
#endif

#insert shaderProfiler_fp

DECLARE_OUTPUT(vec4)
Expand All @@ -67,6 +72,16 @@ void main()
return;
}

// Normally alpha modulation is supposed to be done before the alpha test, but this looks
// better for the ancient-remains foliage combining alphagen portal with an alpha-tested
// plant image: fades out to 0 smoothly instead of cutting off at 0.5.
#if defined(USE_ALPHAGEN_PORTAL)
vec4 position = u_UnprojectMatrix * vec4(gl_FragCoord.xyz, 1.0);
float portalAlpha = length(position.xyz / position.w) * u_InversePortalRange;
portalAlpha = length(position.xyz / position.w) * (1.0/256.0);
color.a *= clamp(portalAlpha, 0.0, 1.0);
#endif

#if defined(USE_DEPTH_FADE)
float depth = texture2D(u_DepthMap, gl_FragCoord.xy / r_FBufSize).x;

Expand Down
45 changes: 0 additions & 45 deletions src/engine/renderer/glsl_source/portal_fp.glsl

This file was deleted.

Loading
Loading