Skip to content
Permalink
Browse files

gl_shader: implement r_deluxeMapping and code disablement

  • Loading branch information...
illwieckz committed Mar 17, 2019
1 parent 4b47663 commit 3d530754f9f9bc1553b2a732b861e8e57d63dcf4
@@ -1449,6 +1449,7 @@ GLShader_lightMapping::GLShader_lightMapping( GLShaderManager *manager ) :
u_numLights( this ),
u_Lights( this ),
GLDeformStage( this ),
GLCompileMacro_USE_DELUXE_MAPPING( this ),
GLCompileMacro_USE_PARALLAX_MAPPING( this ),
GLCompileMacro_USE_PHYSICAL_SHADING( this )
{
@@ -783,6 +783,7 @@ class GLCompileMacro
USE_VERTEX_SPRITE,
USE_TCGEN_ENVIRONMENT,
USE_TCGEN_LIGHTMAP,
USE_DELUXE_MAPPING,
USE_PARALLAX_MAPPING,
USE_REFLECTIVE_SPECULAR,
USE_SHADOWING,
@@ -983,6 +984,31 @@ class GLCompileMacro_USE_TCGEN_LIGHTMAP :
}
};

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

const char *GetName() const
{
return "USE_DELUXE_MAPPING";
}

EGLCompileMacro GetType() const
{
return EGLCompileMacro::USE_DELUXE_MAPPING;
}

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

class GLCompileMacro_USE_PARALLAX_MAPPING :
GLCompileMacro
{
@@ -2201,6 +2227,7 @@ class GLShader_lightMapping :
public u_numLights,
public u_Lights,
public GLDeformStage,
public GLCompileMacro_USE_DELUXE_MAPPING,
public GLCompileMacro_USE_PARALLAX_MAPPING,
public GLCompileMacro_USE_PHYSICAL_SHADING
{
@@ -89,21 +89,25 @@ void main()

vec4 color = vec4( 0.0, 0.0, 0.0, diffuse.a );

#if defined(USE_DELUXE_MAPPING)
// compute light direction in world space
vec4 deluxe = texture2D(u_DeluxeMap, var_TexLight);
if( deluxe.w < 0.5 ) {
// normal/deluxe mapping is disabled
color.xyz += lightColor.xyz * diffuse.xyz;
} else {
vec3 L = 2.0 * deluxe.xyz - 1.0;
L = normalize(L);

// divide by cosine term to restore original light color
lightColor /= clamp(dot(normalize(var_Normal), L), 0.004, 1.0);

// compute final color
computeLight( L, N, viewDir, lightColor, diffuse, specular, color );
}
#else // !USE_DELUXE_MAPPING
// normal/deluxe mapping is disabled
color.xyz += lightColor.xyz * diffuse.xyz;
#endif // USE_DELUXE_MAPPING

#if defined(USE_DELUXE_MAPPING)
vec3 L = 2.0 * deluxe.xyz - 1.0;
L = normalize(L);

// divide by cosine term to restore original light color
lightColor /= clamp(dot(normalize(var_Normal), L), 0.004, 1.0);

// compute final color
computeLight( L, N, viewDir, lightColor, diffuse, specular, color );
#endif // USE_DELUXE_MAPPING

computeDLights( var_Position, N, viewDir, diffuse, specular, color );

color.rgb += texture2D(u_GlowMap, texGlow).rgb;
@@ -161,6 +161,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
cvar_t *r_specularExponentMin;
cvar_t *r_specularExponentMax;
cvar_t *r_specularScale;
cvar_t *r_deluxeMapping;
cvar_t *r_normalScale;
cvar_t *r_normalMapping;
cvar_t *r_wrapAroundLighting;
@@ -1192,6 +1193,7 @@ ScreenshotCmd screenshotPNGRegistration("screenshotPNG", ssFormat_t::SSF_PNG, "p
r_specularExponentMin = ri.Cvar_Get( "r_specularExponentMin", "0", CVAR_CHEAT );
r_specularExponentMax = ri.Cvar_Get( "r_specularExponentMax", "16", CVAR_CHEAT );
r_specularScale = ri.Cvar_Get( "r_specularScale", "1.0", CVAR_CHEAT | CVAR_SHADER );
r_deluxeMapping = ri.Cvar_Get( "r_deluxeMapping", "1", CVAR_ARCHIVE );
r_normalScale = ri.Cvar_Get( "r_normalScale", "1.0", CVAR_SHADER );
r_normalMapping = ri.Cvar_Get( "r_normalMapping", "1", CVAR_ARCHIVE );
r_parallaxDepthScale = ri.Cvar_Get( "r_parallaxDepthScale", "0.03", CVAR_CHEAT );
@@ -2851,6 +2851,7 @@ static inline void halfToFloat( const f16vec4_t in, vec4_t out )
extern cvar_t *r_specularExponentMin;
extern cvar_t *r_specularExponentMax;
extern cvar_t *r_specularScale;
extern cvar_t *r_deluxeMapping;
extern cvar_t *r_normalScale;
extern cvar_t *r_normalMapping;
extern cvar_t *r_wrapAroundLighting;
@@ -1149,6 +1149,7 @@ static void Render_lightMapping( int stage, bool asColorMap, bool normalMapping,

GL_State( stateBits );

bool deluxeMapping = r_deluxeMapping->integer && tr.worldDeluxeMapping;
if ( pStage->bundle[ TB_NORMALMAP ].image[ 0 ] == nullptr )
{
normalMapping = false;
@@ -1162,6 +1163,7 @@ static void Render_lightMapping( int stage, bool asColorMap, bool normalMapping,
// choose right shader program ----------------------------------
GL_BindToTMU( 8, tr.lighttileRenderImage );

gl_lightMappingShader->SetDeluxeMapping( deluxeMapping );
gl_lightMappingShader->SetParallaxMapping( normalMapping && r_parallaxMapping->integer && tess.surfaceShader->parallax && !tess.surfaceShader->noParallax );

tess.vboVertexSprite = false;
@@ -1253,7 +1255,7 @@ static void Render_lightMapping( int stage, bool asColorMap, bool normalMapping,
gl_lightMappingShader->SetUniform_SpecularExponent( specExpMin, specExpMax );

// bind u_DeluxeMap
if ( normalMapping )
if ( deluxeMapping )
{
BindDeluxeMap( 4 );
}

0 comments on commit 3d53075

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