Skip to content

Commit

Permalink
Don't scale shadow multipliers by overbrightbits, and improve documen…
Browse files Browse the repository at this point in the history
…tation.
  • Loading branch information
SmileTheory committed Apr 23, 2013
1 parent feb0121 commit 8270d54
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 26 deletions.
3 changes: 2 additions & 1 deletion code/renderergl2/tr_bsp.c
Expand Up @@ -3277,7 +3277,8 @@ void RE_LoadWorldMap( const char *name ) {
}

// set default map light scale
tr.mapLightScale = 1.0f;
tr.mapLightScale = 1.0f;
tr.sunShadowScale = 0.5f;

// set default sun direction to be used if it isn't
// overridden by a shader
Expand Down
2 changes: 1 addition & 1 deletion code/renderergl2/tr_init.c
Expand Up @@ -1198,7 +1198,7 @@ void R_Register( void )
r_forceSun = ri.Cvar_Get( "r_forceSun", "0", CVAR_CHEAT );
r_forceSunMapLightScale = ri.Cvar_Get( "r_forceSunMapLightScale", "1.0", CVAR_CHEAT );
r_forceSunLightScale = ri.Cvar_Get( "r_forceSunLightScale", "1.0", CVAR_CHEAT );
r_forceSunAmbientScale = ri.Cvar_Get( "r_forceSunAmbientScale", "0.75", CVAR_CHEAT );
r_forceSunAmbientScale = ri.Cvar_Get( "r_forceSunAmbientScale", "0.5", CVAR_CHEAT );
r_drawSunRays = ri.Cvar_Get( "r_drawSunRays", "0", CVAR_ARCHIVE | CVAR_LATCH );
r_sunlightMode = ri.Cvar_Get( "r_sunlightMode", "1", CVAR_ARCHIVE | CVAR_LATCH );

Expand Down
2 changes: 1 addition & 1 deletion code/renderergl2/tr_local.h
Expand Up @@ -1789,10 +1789,10 @@ typedef struct {
int viewCluster;

float mapLightScale;
float sunShadowScale;

qboolean sunShadows;
vec3_t sunLight; // from the sky shader for this level
vec3_t sunAmbient;
vec3_t sunDirection;

frontEndCounters_t pc;
Expand Down
37 changes: 26 additions & 11 deletions code/renderergl2/tr_scene.c
Expand Up @@ -360,19 +360,34 @@ void RE_RenderScene( const refdef_t *fd ) {
VectorSet(tr.refdef.sunCol, 0, 0, 0);
VectorSet(tr.refdef.sunAmbCol, 0, 0, 0);
}
else if (r_forceSun->integer == 1)
{
float scale = pow(2, r_mapOverBrightBits->integer - tr.overbrightBits - 8);
tr.refdef.colorScale = r_forceSunMapLightScale->value;
VectorScale(tr.sunLight, scale * r_forceSunLightScale->value, tr.refdef.sunCol);
VectorScale(tr.sunLight, scale * r_forceSunAmbientScale->value, tr.refdef.sunAmbCol);
}
else
{
float scale = pow(2, r_mapOverBrightBits->integer - tr.overbrightBits - 8);
tr.refdef.colorScale = tr.mapLightScale;
VectorScale(tr.sunLight, scale, tr.refdef.sunCol);
VectorScale(tr.sunAmbient, scale, tr.refdef.sunAmbCol);
tr.refdef.colorScale = r_forceSun->integer ? r_forceSunMapLightScale->value : tr.mapLightScale;

if (r_sunlightMode->integer == 1)
{
tr.refdef.sunCol[0] =
tr.refdef.sunCol[1] =
tr.refdef.sunCol[2] = 1.0f;

tr.refdef.sunAmbCol[0] =
tr.refdef.sunAmbCol[1] =
tr.refdef.sunAmbCol[2] = r_forceSun->integer ? r_forceSunAmbientScale->value : tr.sunShadowScale;
}
else
{
float scale = pow(2, r_mapOverBrightBits->integer - tr.overbrightBits - 8);
if (r_forceSun->integer)
{
VectorScale(tr.sunLight, scale * r_forceSunLightScale->value, tr.refdef.sunCol);
VectorScale(tr.sunLight, scale * r_forceSunAmbientScale->value, tr.refdef.sunAmbCol);
}
else
{
VectorScale(tr.sunLight, scale, tr.refdef.sunCol);
VectorScale(tr.sunLight, scale * tr.sunShadowScale, tr.refdef.sunAmbCol);
}
}
}

if (r_forceAutoExposure->integer)
Expand Down
4 changes: 1 addition & 3 deletions code/renderergl2/tr_shader.c
Expand Up @@ -1636,8 +1636,6 @@ static qboolean ParseShader( char **text )
a = atof( token );
VectorScale( tr.sunLight, a, tr.sunLight);

VectorSet( tr.sunAmbient, 0.0f, 0.0f, 0.0f);

token = COM_ParseExt( text, qfalse );
a = atof( token );
a = a / 180 * M_PI;
Expand All @@ -1656,7 +1654,7 @@ static qboolean ParseShader( char **text )
tr.mapLightScale = atof(token);

token = COM_ParseExt( text, qfalse );
VectorScale( tr.sunLight, atof(token), tr.sunAmbient );
tr.sunShadowScale = atof(token);
}

SkipRestOfLine( text );
Expand Down
30 changes: 21 additions & 9 deletions opengl2-readme.txt
Expand Up @@ -240,21 +240,31 @@ Cvars for the sunlight and cascaded shadow maps:

r_forceSunMapLightScale - Cheat. Scale map brightness by this factor
when r_forceSun 1.
0.5 - Default
1.0 - Default

r_forceSunLightScale - Cheat. Scale sun brightness by this factor
when r_forceSun 1.
0.5 - Default
1.0 - Default

r_forceSunAmbientScale - Cheat. Scale sun ambient brightness by this
factor when r_forceSun 1.
0.2 - Default
0.5 - Default

r_sunShadows - Enable sunlight and cascaded shadow maps for
it on maps that support it.
0 - No.
1 - Yes. (default)

r_sunlightMode - Specify the method used to add sunlight to
the scene.
0 - No.
1 - Multiply lit areas by light scale, and
shadowed areas by ambient scale.
(default)
2 - Add light. Looks better, but is slower
and doesn't integrate well with existing
maps.

r_shadowFilter - Enable filtering shadows for a smoother
look.
0 - No.
Expand Down Expand Up @@ -468,17 +478,18 @@ and is the equivalent for 'exactVertex'.

This adds a new keyword to sky materials, q3gl2_sun. The syntax is:

q3gl2_sun <red> <green> <blue> <intensity> <degrees> <mapLightScale>
<ambientLightScale>
q3gl2_sun <red> <green> <blue> <intensity> <degrees> <elevation>
<mapLightScale> <ambientLightScale>

Note the first six parameters are the same as in q3map_sun or q3map_sunExt,
and the last two indicate scaling factors for the map brightness and an ambient
light of the same color as the sun.

There are currently two ways to use this in your own (and other people's) maps.

1. Create your map as normal and add a 'q3gl2_sun' line after your
'q3map_sun' line in your sky material, like so:
1. Create your map as normal, set r_sunlightMode to 1, and add a
'q3gl2_sun' line after your 'q3map_sun' line in your sky material, like
so:

textures/skies/bluesky
{
Expand All @@ -489,7 +500,7 @@ There are currently two ways to use this in your own (and other people's) maps.
surfaceparm nolightmap
surfaceparm sky
q3map_sunExt 240 238 200 100 195 35 3 16
q3gl2_sun 240 238 200 50 195 35 3 0.5 0.2
q3gl2_sun 240 238 200 50 195 35 3 1.0 0.2
q3map_skylight 50 16
q3map_lightimage $whiteimage

Expand All @@ -501,7 +512,8 @@ There are currently two ways to use this in your own (and other people's) maps.
can be used with existing maps without recompilation. The downside is
artifacts like doubled shadows and uneven shadow edges.

2. Use 'q3gl2_sun' instead of 'q3map_sun' or 'q3map_sunExt', like so:
2. Set r_sunlightMode to 2 and use 'q3gl2_sun' instead of 'q3map_sun' or
'q3map_sunExt', like so:

textures/skies/bluesky
{
Expand Down

0 comments on commit 8270d54

Please sign in to comment.