Skip to content
Permalink
Browse files

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 8efc535 commit fb8b561ed9aea150d755388d1f9b309167af8325
Showing with 140 additions and 358 deletions.
  1. +12 −27 src/engine/renderer/gl_shader.cpp
  2. +16 −91 src/engine/renderer/gl_shader.h
  3. +1 −1 src/engine/renderer/glsl_source/cameraEffects_fp.glsl
  4. +3 −3 src/engine/renderer/glsl_source/cameraEffects_vp.glsl
  5. +2 −2 src/engine/renderer/glsl_source/fogQuake3_fp.glsl
  6. +2 −2 src/engine/renderer/glsl_source/fogQuake3_vp.glsl
  7. +7 −14 src/engine/renderer/glsl_source/forwardLighting_fp.glsl
  8. +6 −17 src/engine/renderer/glsl_source/forwardLighting_vp.glsl
  9. +2 −2 src/engine/renderer/glsl_source/generic_fp.glsl
  10. +5 −5 src/engine/renderer/glsl_source/generic_vp.glsl
  11. +2 −2 src/engine/renderer/glsl_source/heatHaze_fp.glsl
  12. +3 −3 src/engine/renderer/glsl_source/heatHaze_vp.glsl
  13. +8 −17 src/engine/renderer/glsl_source/lightMapping_fp.glsl
  14. +4 −18 src/engine/renderer/glsl_source/lightMapping_vp.glsl
  15. +0 −1 src/engine/renderer/glsl_source/lightVolume_omni_fp.glsl
  16. +2 −2 src/engine/renderer/glsl_source/liquid_fp.glsl
  17. +3 −3 src/engine/renderer/glsl_source/liquid_vp.glsl
  18. +2 −2 src/engine/renderer/glsl_source/reflection_CB_fp.glsl
  19. +3 −3 src/engine/renderer/glsl_source/reflection_CB_vp.glsl
  20. +2 −2 src/engine/renderer/glsl_source/shadowFill_fp.glsl
  21. +3 −3 src/engine/renderer/glsl_source/shadowFill_vp.glsl
  22. +9 −19 src/engine/renderer/glsl_source/vertexLighting_DBS_entity_fp.glsl
  23. +3 −18 src/engine/renderer/glsl_source/vertexLighting_DBS_entity_vp.glsl
  24. +8 −18 src/engine/renderer/glsl_source/vertexLighting_DBS_world_fp.glsl
  25. +3 −18 src/engine/renderer/glsl_source/vertexLighting_DBS_world_vp.glsl
  26. +15 −15 src/engine/renderer/tr_backend.cpp
  27. +14 −50 src/engine/renderer/tr_shade.cpp
@@ -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 ),
@@ -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 ),
@@ -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 ),
@@ -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 ),
@@ -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 ),
@@ -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 ),
@@ -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 ),
@@ -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 ),
@@ -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 ),
@@ -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 ),
@@ -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 )
@@ -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 ),
@@ -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 );
}
@@ -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,
@@ -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,
@@ -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,
@@ -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,
@@ -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,
@@ -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,
@@ -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,
@@ -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,
@@ -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,
@@ -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,
@@ -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
@@ -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,
@@ -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)

@@ -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;
}
@@ -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;
@@ -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,
@@ -96,7 +96,7 @@ void main()
}
}

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

var_Color = color;
}
Oops, something went wrong.

0 comments on commit fb8b561

Please sign in to comment.
You can’t perform that action at this time.