Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
use only one texCoords per surface
the extra compute and boilerplate code seem useless and it already
ended in bugs when parallax offset was applied to diffuse, normal,
specular but nor glow map, and I would find stupid to add more
boilerplate when height map will be implemented

diffuse/normal/specular/glow/height maps are component
of the same material, so there is no reason to handle
their coordinates separately

doing this would also avoid the need for a lot of ifdef code
when normal/specular/glow/parallax support is disabled

and well, that extra code seems useless even when they are enabled

it unify the symbol names to var_TexCoords

alongside the var_TexDiffuse, var_TexNormal, var_TexSpecular,
var_TexGlow there was some occurrence of var_Tex

some comments in already rewritten code told that Tr3b had issue
with some driver/hardware suffered from "too much var" issue when
passed from vp to fp shaders, leading him to abuse some variables,
see 72268b, even if I have not faced this issue with hardware that
is so old the game is unplayable, this is an even better way to
reduce the number of variables passed from vp to fp

for multimap material (diffuse/normal/specular/glow), the texCoords
used is the diffuse one

note that we already computed the parallax texOffset from diffuse coords
only, and applied it to other maps as it would be stupid and inefficient
to compute the parallax texOffset on each normal/specular/glow coords
  • Loading branch information
illwieckz committed Mar 30, 2019
1 parent 0beb003 commit 4079b72
Show file tree
Hide file tree
Showing 27 changed files with 140 additions and 358 deletions.
39 changes: 12 additions & 27 deletions src/engine/renderer/gl_shader.cpp
Expand Up @@ -1410,7 +1410,7 @@ void GLShader::SetRequiredVertexPointers()

GLShader_generic::GLShader_generic( GLShaderManager *manager ) :
GLShader( "generic", ATTR_POSITION | ATTR_TEXCOORD | ATTR_QTANGENT, manager ),
u_ColorTextureMatrix( this ),
u_TextureMatrix( this ),
u_ViewOrigin( this ),
u_ViewUp( this ),
u_AlphaThreshold( this ),
Expand Down Expand Up @@ -1446,10 +1446,7 @@ void GLShader_generic::SetShaderProgramUniforms( shaderProgram_t *shaderProgram

GLShader_lightMapping::GLShader_lightMapping( GLShaderManager *manager ) :
GLShader( "lightMapping", ATTR_POSITION | ATTR_TEXCOORD | ATTR_QTANGENT | ATTR_COLOR, manager ),
u_DiffuseTextureMatrix( this ),
u_NormalTextureMatrix( this ),
u_SpecularTextureMatrix( this ),
u_GlowTextureMatrix( this ),
u_TextureMatrix( this ),
u_SpecularExponent( this ),
u_ColorModulate( this ),
u_Color( this ),
Expand Down Expand Up @@ -1500,10 +1497,7 @@ void GLShader_lightMapping::SetShaderProgramUniforms( shaderProgram_t *shaderPro

GLShader_vertexLighting_DBS_entity::GLShader_vertexLighting_DBS_entity( GLShaderManager *manager ) :
GLShader( "vertexLighting_DBS_entity", ATTR_POSITION | ATTR_TEXCOORD | ATTR_QTANGENT, manager ),
u_DiffuseTextureMatrix( this ),
u_NormalTextureMatrix( this ),
u_SpecularTextureMatrix( this ),
u_GlowTextureMatrix( this ),
u_TextureMatrix( this ),
u_SpecularExponent( this ),
u_AlphaThreshold( this ),
u_ViewOrigin( this ),
Expand Down Expand Up @@ -1564,10 +1558,7 @@ GLShader_vertexLighting_DBS_world::GLShader_vertexLighting_DBS_world( GLShaderMa
ATTR_POSITION | ATTR_TEXCOORD | ATTR_QTANGENT | ATTR_COLOR,
manager
),
u_DiffuseTextureMatrix( this ),
u_NormalTextureMatrix( this ),
u_SpecularTextureMatrix( this ),
u_GlowTextureMatrix( this ),
u_TextureMatrix( this ),
u_SpecularExponent( this ),
u_ColorModulate( this ),
u_Color( this ),
Expand Down Expand Up @@ -1619,9 +1610,7 @@ void GLShader_vertexLighting_DBS_world::SetShaderProgramUniforms( shaderProgram_

GLShader_forwardLighting_omniXYZ::GLShader_forwardLighting_omniXYZ( GLShaderManager *manager ):
GLShader("forwardLighting_omniXYZ", "forwardLighting", ATTR_POSITION | ATTR_TEXCOORD | ATTR_QTANGENT, manager),
u_DiffuseTextureMatrix( this ),
u_NormalTextureMatrix( this ),
u_SpecularTextureMatrix( this ),
u_TextureMatrix( this ),
u_SpecularExponent( this ),
u_AlphaThreshold( this ),
u_ColorModulate( this ),
Expand Down Expand Up @@ -1679,9 +1668,7 @@ void GLShader_forwardLighting_omniXYZ::SetShaderProgramUniforms( shaderProgram_t

GLShader_forwardLighting_projXYZ::GLShader_forwardLighting_projXYZ( GLShaderManager *manager ):
GLShader("forwardLighting_projXYZ", "forwardLighting", ATTR_POSITION | ATTR_TEXCOORD | ATTR_QTANGENT, manager),
u_DiffuseTextureMatrix( this ),
u_NormalTextureMatrix( this ),
u_SpecularTextureMatrix( this ),
u_TextureMatrix( this ),
u_SpecularExponent( this ),
u_AlphaThreshold( this ),
u_ColorModulate( this ),
Expand Down Expand Up @@ -1741,9 +1728,7 @@ void GLShader_forwardLighting_projXYZ::SetShaderProgramUniforms( shaderProgram_t

GLShader_forwardLighting_directionalSun::GLShader_forwardLighting_directionalSun( GLShaderManager *manager ):
GLShader("forwardLighting_directionalSun", "forwardLighting", ATTR_POSITION | ATTR_TEXCOORD | ATTR_QTANGENT, manager),
u_DiffuseTextureMatrix( this ),
u_NormalTextureMatrix( this ),
u_SpecularTextureMatrix( this ),
u_TextureMatrix( this ),
u_SpecularExponent( this ),
u_AlphaThreshold( this ),
u_ColorModulate( this ),
Expand Down Expand Up @@ -1812,7 +1797,7 @@ void GLShader_forwardLighting_directionalSun::SetShaderProgramUniforms( shaderPr

GLShader_shadowFill::GLShader_shadowFill( GLShaderManager *manager ) :
GLShader( "shadowFill", ATTR_POSITION | ATTR_TEXCOORD | ATTR_QTANGENT, manager ),
u_ColorTextureMatrix( this ),
u_TextureMatrix( this ),
u_ViewOrigin( this ),
u_AlphaThreshold( this ),
u_LightOrigin( this ),
Expand Down Expand Up @@ -1841,7 +1826,7 @@ void GLShader_shadowFill::SetShaderProgramUniforms( shaderProgram_t *shaderProgr

GLShader_reflection::GLShader_reflection( GLShaderManager *manager ):
GLShader("reflection", "reflection_CB", ATTR_POSITION | ATTR_TEXCOORD | ATTR_QTANGENT, manager ),
u_NormalTextureMatrix( this ),
u_TextureMatrix( this ),
u_ViewOrigin( this ),
u_ModelMatrix( this ),
u_ModelViewProjectionMatrix( this ),
Expand Down Expand Up @@ -1941,7 +1926,7 @@ void GLShader_fogGlobal::SetShaderProgramUniforms( shaderProgram_t *shaderProgra

GLShader_heatHaze::GLShader_heatHaze( GLShaderManager *manager ) :
GLShader( "heatHaze", ATTR_POSITION | ATTR_TEXCOORD | ATTR_QTANGENT, manager ),
u_NormalTextureMatrix( this ),
u_TextureMatrix( this ),
u_ViewOrigin( this ),
u_ViewUp( this ),
u_DeformMagnitude( this ),
Expand Down Expand Up @@ -2015,7 +2000,7 @@ void GLShader_contrast::SetShaderProgramUniforms( shaderProgram_t *shaderProgram
GLShader_cameraEffects::GLShader_cameraEffects( GLShaderManager *manager ) :
GLShader( "cameraEffects", ATTR_POSITION | ATTR_TEXCOORD, manager ),
u_ColorModulate( this ),
u_ColorTextureMatrix( this ),
u_TextureMatrix( this ),
u_ModelViewProjectionMatrix( this ),
u_DeformMagnitude( this ),
u_InverseGamma( this )
Expand Down Expand Up @@ -2103,7 +2088,7 @@ void GLShader_lightVolume_omni::SetShaderProgramUniforms( shaderProgram_t *shade

GLShader_liquid::GLShader_liquid( GLShaderManager *manager ) :
GLShader( "liquid", ATTR_POSITION | ATTR_TEXCOORD | ATTR_QTANGENT, manager ),
u_NormalTextureMatrix( this ),
u_TextureMatrix( this ),
u_ViewOrigin( this ),
u_RefractionIndex( this ),
u_ModelMatrix( this ),
Expand Down
107 changes: 16 additions & 91 deletions src/engine/renderer/gl_shader.h
Expand Up @@ -1185,76 +1185,16 @@ class GLCompileMacro_USE_ALPHA_TESTING :
}
};

class u_ColorTextureMatrix :
class u_TextureMatrix :
GLUniformMatrix4f
{
public:
u_ColorTextureMatrix( GLShader *shader ) :
GLUniformMatrix4f( shader, "u_ColorTextureMatrix" )
u_TextureMatrix( GLShader *shader ) :
GLUniformMatrix4f( shader, "u_TextureMatrix" )
{
}

void SetUniform_ColorTextureMatrix( const matrix_t m )
{
this->SetValue( GL_FALSE, m );
}
};

class u_DiffuseTextureMatrix :
GLUniformMatrix4f
{
public:
u_DiffuseTextureMatrix( GLShader *shader ) :
GLUniformMatrix4f( shader, "u_DiffuseTextureMatrix" )
{
}

void SetUniform_DiffuseTextureMatrix( const matrix_t m )
{
this->SetValue( GL_FALSE, m );
}
};

class u_NormalTextureMatrix :
GLUniformMatrix4f
{
public:
u_NormalTextureMatrix( GLShader *shader ) :
GLUniformMatrix4f( shader, "u_NormalTextureMatrix" )
{
}

void SetUniform_NormalTextureMatrix( const matrix_t m )
{
this->SetValue( GL_FALSE, m );
}
};

class u_SpecularTextureMatrix :
GLUniformMatrix4f
{
public:
u_SpecularTextureMatrix( GLShader *shader ) :
GLUniformMatrix4f( shader, "u_SpecularTextureMatrix" )
{
}

void SetUniform_SpecularTextureMatrix( const matrix_t m )
{
this->SetValue( GL_FALSE, m );
}
};

class u_GlowTextureMatrix :
GLUniformMatrix4f
{
public:
u_GlowTextureMatrix( GLShader *shader ) :
GLUniformMatrix4f( shader, "u_GlowTextureMatrix" )
{
}

void SetUniform_GlowTextureMatrix( const matrix_t m )
void SetUniform_TextureMatrix( const matrix_t m )
{
this->SetValue( GL_FALSE, m );
}
Expand Down Expand Up @@ -2180,7 +2120,7 @@ class u_Lights :

class GLShader_generic :
public GLShader,
public u_ColorTextureMatrix,
public u_TextureMatrix,
public u_ViewOrigin,
public u_ViewUp,
public u_AlphaThreshold,
Expand Down Expand Up @@ -2209,10 +2149,7 @@ class GLShader_generic :

class GLShader_lightMapping :
public GLShader,
public u_DiffuseTextureMatrix,
public u_NormalTextureMatrix,
public u_SpecularTextureMatrix,
public u_GlowTextureMatrix,
public u_TextureMatrix,
public u_SpecularExponent,
public u_ColorModulate,
public u_Color,
Expand Down Expand Up @@ -2241,10 +2178,7 @@ class GLShader_lightMapping :

class GLShader_vertexLighting_DBS_entity :
public GLShader,
public u_DiffuseTextureMatrix,
public u_NormalTextureMatrix,
public u_SpecularTextureMatrix,
public u_GlowTextureMatrix,
public u_TextureMatrix,
public u_SpecularExponent,
public u_AlphaThreshold,
public u_ViewOrigin,
Expand Down Expand Up @@ -2278,10 +2212,7 @@ class GLShader_vertexLighting_DBS_entity :

class GLShader_vertexLighting_DBS_world :
public GLShader,
public u_DiffuseTextureMatrix,
public u_NormalTextureMatrix,
public u_SpecularTextureMatrix,
public u_GlowTextureMatrix,
public u_TextureMatrix,
public u_SpecularExponent,
public u_ColorModulate,
public u_Color,
Expand Down Expand Up @@ -2312,9 +2243,7 @@ class GLShader_vertexLighting_DBS_world :

class GLShader_forwardLighting_omniXYZ :
public GLShader,
public u_DiffuseTextureMatrix,
public u_NormalTextureMatrix,
public u_SpecularTextureMatrix,
public u_TextureMatrix,
public u_SpecularExponent,
public u_AlphaThreshold,
public u_ColorModulate,
Expand Down Expand Up @@ -2352,9 +2281,7 @@ class GLShader_forwardLighting_omniXYZ :

class GLShader_forwardLighting_projXYZ :
public GLShader,
public u_DiffuseTextureMatrix,
public u_NormalTextureMatrix,
public u_SpecularTextureMatrix,
public u_TextureMatrix,
public u_SpecularExponent,
public u_AlphaThreshold,
public u_ColorModulate,
Expand Down Expand Up @@ -2393,9 +2320,7 @@ class GLShader_forwardLighting_projXYZ :

class GLShader_forwardLighting_directionalSun :
public GLShader,
public u_DiffuseTextureMatrix,
public u_NormalTextureMatrix,
public u_SpecularTextureMatrix,
public u_TextureMatrix,
public u_SpecularExponent,
public u_AlphaThreshold,
public u_ColorModulate,
Expand Down Expand Up @@ -2436,7 +2361,7 @@ class GLShader_forwardLighting_directionalSun :

class GLShader_shadowFill :
public GLShader,
public u_ColorTextureMatrix,
public u_TextureMatrix,
public u_ViewOrigin,
public u_AlphaThreshold,
public u_LightOrigin,
Expand All @@ -2459,7 +2384,7 @@ class GLShader_shadowFill :

class GLShader_reflection :
public GLShader,
public u_NormalTextureMatrix,
public u_TextureMatrix,
public u_ViewOrigin,
public u_ModelMatrix,
public u_ModelViewProjectionMatrix,
Expand Down Expand Up @@ -2534,7 +2459,7 @@ class GLShader_fogGlobal :

class GLShader_heatHaze :
public GLShader,
public u_NormalTextureMatrix,
public u_TextureMatrix,
public u_ViewOrigin,
public u_ViewUp,
public u_DeformMagnitude,
Expand Down Expand Up @@ -2591,7 +2516,7 @@ class GLShader_contrast :
class GLShader_cameraEffects :
public GLShader,
public u_ColorModulate,
public u_ColorTextureMatrix,
public u_TextureMatrix,
public u_ModelViewProjectionMatrix,
public u_DeformMagnitude,
public u_InverseGamma
Expand Down Expand Up @@ -2662,7 +2587,7 @@ class GLShader_lightVolume_omni :

class GLShader_liquid :
public GLShader,
public u_NormalTextureMatrix,
public u_TextureMatrix,
public u_ViewOrigin,
public u_RefractionIndex,
public u_ModelMatrix,
Expand Down
2 changes: 1 addition & 1 deletion src/engine/renderer/glsl_source/cameraEffects_fp.glsl
Expand Up @@ -27,7 +27,7 @@ uniform sampler3D u_ColorMap;
uniform vec4 u_ColorModulate;
uniform float u_InverseGamma;

IN(smooth) vec2 var_Tex;
IN(smooth) vec2 var_TexCoords;

DECLARE_OUTPUT(vec4)

Expand Down
6 changes: 3 additions & 3 deletions src/engine/renderer/glsl_source/cameraEffects_vp.glsl
Expand Up @@ -26,14 +26,14 @@ IN vec3 attr_Position;
IN vec2 attr_TexCoord0;

uniform mat4 u_ModelViewProjectionMatrix;
uniform mat4 u_ColorTextureMatrix;
uniform mat4 u_TextureMatrix;

OUT(smooth) vec2 var_Tex;
OUT(smooth) vec2 var_TexCoords;

void main()
{
// transform vertex position into homogenous clip-space
gl_Position = u_ModelViewProjectionMatrix * vec4(attr_Position, 1.0);

var_Tex = (u_ColorTextureMatrix * vec4(attr_TexCoord0, 0.0, 1.0)).st;
var_TexCoords = (u_TextureMatrix * vec4(attr_TexCoord0, 0.0, 1.0)).st;
}
4 changes: 2 additions & 2 deletions src/engine/renderer/glsl_source/fogQuake3_fp.glsl
Expand Up @@ -25,14 +25,14 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
uniform sampler2D u_ColorMap;

IN(smooth) vec3 var_Position;
IN(smooth) vec2 var_Tex;
IN(smooth) vec2 var_TexCoords;
IN(smooth) vec4 var_Color;

DECLARE_OUTPUT(vec4)

void main()
{
vec4 color = texture2D(u_ColorMap, var_Tex);
vec4 color = texture2D(u_ColorMap, var_TexCoords);

color *= var_Color;
outputColor = color;
Expand Down
4 changes: 2 additions & 2 deletions src/engine/renderer/glsl_source/fogQuake3_vp.glsl
Expand Up @@ -36,7 +36,7 @@ uniform vec4 u_FogDepthVector;
uniform float u_FogEyeT;

OUT(smooth) vec3 var_Position;
OUT(smooth) vec2 var_Tex;
OUT(smooth) vec2 var_TexCoords;
OUT(smooth) vec4 var_Color;

void DeformVertex( inout vec4 pos,
Expand Down Expand Up @@ -96,7 +96,7 @@ void main()
}
}

var_Tex = vec2(s, t);
var_TexCoords = vec2(s, t);

var_Color = color;
}

0 comments on commit 4079b72

Please sign in to comment.