OpenGL2: Remove map color scaling and r_forceSunMapLightScale.

Also simplify overbright code in ComputeShaderColors().
This commit is contained in:
SmileTheory 2016-09-14 02:59:54 -07:00
parent 4c169ab574
commit 4faf1008a0
11 changed files with 32 additions and 100 deletions

View file

@ -712,9 +712,6 @@ void RB_SetGL2D (void) {
// set time for 2D shaders // set time for 2D shaders
backEnd.refdef.time = ri.Milliseconds(); backEnd.refdef.time = ri.Milliseconds();
backEnd.refdef.floatTime = backEnd.refdef.time * 0.001f; backEnd.refdef.floatTime = backEnd.refdef.time * 0.001f;
// reset color scaling
backEnd.refdef.colorScale = 1.0f;
} }

View file

@ -105,11 +105,7 @@ static void R_ColorShiftLightingBytes( byte in[4], byte out[4] ) {
int shift, r, g, b; int shift, r, g, b;
// shift the color data based on overbright range // shift the color data based on overbright range
#if defined(USE_OVERBRIGHT)
shift = r_mapOverBrightBits->integer - tr.overbrightBits; shift = r_mapOverBrightBits->integer - tr.overbrightBits;
#else
shift = 0;
#endif
// shift the data based on overbright range // shift the data based on overbright range
r = in[0] << shift; r = in[0] << shift;
@ -144,9 +140,7 @@ static void R_ColorShiftLightingFloats(float in[4], float out[4], float scale )
{ {
float r, g, b; float r, g, b;
#if defined(USE_OVERBRIGHT)
scale *= 1 << (r_mapOverBrightBits->integer - tr.overbrightBits); scale *= 1 << (r_mapOverBrightBits->integer - tr.overbrightBits);
#endif
r = in[0] * scale; r = in[0] * scale;
g = in[1] * scale; g = in[1] * scale;
@ -2686,11 +2680,7 @@ void R_LoadLightGrid( lump_t *l ) {
if (hdrLightGrid) if (hdrLightGrid)
{ {
#if defined(USE_OVERBRIGHT)
float lightScale = 1 << (r_mapOverBrightBits->integer - tr.overbrightBits); float lightScale = 1 << (r_mapOverBrightBits->integer - tr.overbrightBits);
#else
float lightScale = 1.0f;
#endif
//ri.Printf(PRINT_ALL, "found!\n"); //ri.Printf(PRINT_ALL, "found!\n");
@ -3165,7 +3155,6 @@ void RE_LoadWorldMap( const char *name ) {
} }
// set default map light scale // set default map light scale
tr.mapLightScale = 1.0f;
tr.sunShadowScale = 0.5f; tr.sunShadowScale = 0.5f;
// set default sun direction to be used if it isn't // set default sun direction to be used if it isn't

View file

@ -2845,11 +2845,7 @@ void R_SetColorMappings( void ) {
int inf; int inf;
// setup the overbright lighting // setup the overbright lighting
#if defined(USE_OVERBRIGHT)
tr.overbrightBits = r_overBrightBits->integer; tr.overbrightBits = r_overBrightBits->integer;
#else
tr.overbrightBits = 0;
#endif
// allow 2 overbright bits // allow 2 overbright bits
if ( tr.overbrightBits > 2 ) { if ( tr.overbrightBits > 2 ) {

View file

@ -155,7 +155,6 @@ cvar_t *r_imageUpsampleMaxSize;
cvar_t *r_imageUpsampleType; cvar_t *r_imageUpsampleType;
cvar_t *r_genNormalMaps; cvar_t *r_genNormalMaps;
cvar_t *r_forceSun; cvar_t *r_forceSun;
cvar_t *r_forceSunMapLightScale;
cvar_t *r_forceSunLightScale; cvar_t *r_forceSunLightScale;
cvar_t *r_forceSunAmbientScale; cvar_t *r_forceSunAmbientScale;
cvar_t *r_sunlightMode; cvar_t *r_sunlightMode;
@ -1245,7 +1244,6 @@ void R_Register( void )
r_genNormalMaps = ri.Cvar_Get( "r_genNormalMaps", "0", CVAR_ARCHIVE | CVAR_LATCH ); r_genNormalMaps = ri.Cvar_Get( "r_genNormalMaps", "0", CVAR_ARCHIVE | CVAR_LATCH );
r_forceSun = ri.Cvar_Get( "r_forceSun", "0", CVAR_CHEAT ); 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_forceSunLightScale = ri.Cvar_Get( "r_forceSunLightScale", "1.0", CVAR_CHEAT );
r_forceSunAmbientScale = ri.Cvar_Get( "r_forceSunAmbientScale", "0.5", 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_drawSunRays = ri.Cvar_Get( "r_drawSunRays", "0", CVAR_ARCHIVE | CVAR_LATCH );

View file

@ -56,7 +56,6 @@ typedef unsigned int glIndex_t;
#define PSHADOW_MAP_SIZE 512 #define PSHADOW_MAP_SIZE 512
#define USE_VERT_TANGENT_SPACE #define USE_VERT_TANGENT_SPACE
#define USE_OVERBRIGHT
typedef struct cubemap_s { typedef struct cubemap_s {
char name[MAX_QPATH]; char name[MAX_QPATH];
@ -761,7 +760,6 @@ typedef struct {
float sunDir[4]; float sunDir[4];
float sunCol[4]; float sunCol[4];
float sunAmbCol[4]; float sunAmbCol[4];
float colorScale;
float autoExposureMinMax[2]; float autoExposureMinMax[2];
float toneMinAvgMaxLinear[3]; float toneMinAvgMaxLinear[3];
@ -1608,7 +1606,6 @@ typedef struct {
int viewCluster; int viewCluster;
float mapLightScale;
float sunShadowScale; float sunShadowScale;
qboolean sunShadows; qboolean sunShadows;
@ -1801,7 +1798,6 @@ extern cvar_t *r_imageUpsampleMaxSize;
extern cvar_t *r_imageUpsampleType; extern cvar_t *r_imageUpsampleType;
extern cvar_t *r_genNormalMaps; extern cvar_t *r_genNormalMaps;
extern cvar_t *r_forceSun; extern cvar_t *r_forceSun;
extern cvar_t *r_forceSunMapLightScale;
extern cvar_t *r_forceSunLightScale; extern cvar_t *r_forceSunLightScale;
extern cvar_t *r_forceSunAmbientScale; extern cvar_t *r_forceSunAmbientScale;
extern cvar_t *r_sunlightMode; extern cvar_t *r_sunlightMode;

View file

@ -2551,7 +2551,6 @@ void R_RenderCubemapSide( int cubemapIndex, int cubemapSide, qboolean subscene )
{ {
refdef_t refdef; refdef_t refdef;
viewParms_t parms; viewParms_t parms;
float oldColorScale = tr.refdef.colorScale;
memset( &refdef, 0, sizeof( refdef ) ); memset( &refdef, 0, sizeof( refdef ) );
refdef.rdflags = 0; refdef.rdflags = 0;
@ -2629,7 +2628,6 @@ void R_RenderCubemapSide( int cubemapIndex, int cubemapSide, qboolean subscene )
R_LightForPoint(tr.refdef.vieworg, ambient, directed, lightDir); R_LightForPoint(tr.refdef.vieworg, ambient, directed, lightDir);
scale = directed[0] + directed[1] + directed[2] + ambient[0] + ambient[1] + ambient[2] + 1.0f; scale = directed[0] + directed[1] + directed[2] + ambient[0] + ambient[1] + ambient[2] + 1.0f;
tr.refdef.colorScale = 1.0f; //766.0f / scale;
// only print message for first side // only print message for first side
if (scale < 1.0001f && cubemapSide == 0) if (scale < 1.0001f && cubemapSide == 0)
{ {
@ -2670,12 +2668,6 @@ void R_RenderCubemapSide( int cubemapIndex, int cubemapSide, qboolean subscene )
R_RenderView(&parms); R_RenderView(&parms);
if (subscene) if (!subscene)
{
tr.refdef.colorScale = oldColorScale;
}
else
{
RE_EndScene(); RE_EndScene();
}
} }

View file

@ -329,18 +329,12 @@ void RE_BeginScene(const refdef_t *fd)
VectorCopy(tr.sunDirection, tr.refdef.sunDir); VectorCopy(tr.sunDirection, tr.refdef.sunDir);
if ( (tr.refdef.rdflags & RDF_NOWORLDMODEL) || !(r_depthPrepass->value) ){ if ( (tr.refdef.rdflags & RDF_NOWORLDMODEL) || !(r_depthPrepass->value) ){
tr.refdef.colorScale = 1.0f;
VectorSet(tr.refdef.sunCol, 0, 0, 0); VectorSet(tr.refdef.sunCol, 0, 0, 0);
VectorSet(tr.refdef.sunAmbCol, 0, 0, 0); VectorSet(tr.refdef.sunAmbCol, 0, 0, 0);
} }
else else
{ {
#if defined(USE_OVERBRIGHT)
float scale = (1 << (r_mapOverBrightBits->integer - tr.overbrightBits)) / 255.0f;
#else
float scale = (1 << r_mapOverBrightBits->integer) / 255.0f; float scale = (1 << r_mapOverBrightBits->integer) / 255.0f;
#endif
tr.refdef.colorScale = r_forceSun->integer ? r_forceSunMapLightScale->value : tr.mapLightScale;
if (r_forceSun->integer) if (r_forceSun->integer)
VectorScale(tr.sunLight, scale * r_forceSunLightScale->value, tr.refdef.sunCol); VectorScale(tr.sunLight, scale * r_forceSunLightScale->value, tr.refdef.sunCol);

View file

@ -446,18 +446,16 @@ static void ComputeShaderColors( shaderStage_t *pStage, vec4_t baseColor, vec4_t
|| ((blend & GLS_SRCBLEND_BITS) == GLS_SRCBLEND_ONE_MINUS_DST_COLOR) || ((blend & GLS_SRCBLEND_BITS) == GLS_SRCBLEND_ONE_MINUS_DST_COLOR)
|| ((blend & GLS_DSTBLEND_BITS) == GLS_DSTBLEND_SRC_COLOR) || ((blend & GLS_DSTBLEND_BITS) == GLS_DSTBLEND_SRC_COLOR)
|| ((blend & GLS_DSTBLEND_BITS) == GLS_DSTBLEND_ONE_MINUS_SRC_COLOR); || ((blend & GLS_DSTBLEND_BITS) == GLS_DSTBLEND_ONE_MINUS_SRC_COLOR);
qboolean isWorldDraw = !(backEnd.refdef.rdflags & RDF_NOWORLDMODEL);
float scale = 1.0f;
#if defined(USE_OVERBRIGHT) qboolean is2DDraw = backEnd.currentEntity == &backEnd.entity2D;
float exactLight = 1.0f;
#else float overbright = (isBlend || is2DDraw) ? 1.0f : (float)(1 << tr.overbrightBits);
float exactLight = (isBlend || !isWorldDraw) ? 1.0f : (float)(1 << r_mapOverBrightBits->integer);
#endif fog_t *fog;
baseColor[0] = baseColor[0] =
baseColor[1] = baseColor[1] =
baseColor[2] = exactLight; baseColor[2] =
baseColor[3] = 1.0f; baseColor[3] = 1.0f;
vertColor[0] = vertColor[0] =
@ -470,11 +468,6 @@ static void ComputeShaderColors( shaderStage_t *pStage, vec4_t baseColor, vec4_t
// //
switch ( pStage->rgbGen ) switch ( pStage->rgbGen )
{ {
case CGEN_IDENTITY_LIGHTING:
baseColor[0] =
baseColor[1] =
baseColor[2] = tr.identityLight;
break;
case CGEN_EXACT_VERTEX: case CGEN_EXACT_VERTEX:
case CGEN_EXACT_VERTEX_LIT: case CGEN_EXACT_VERTEX_LIT:
baseColor[0] = baseColor[0] =
@ -484,7 +477,7 @@ static void ComputeShaderColors( shaderStage_t *pStage, vec4_t baseColor, vec4_t
vertColor[0] = vertColor[0] =
vertColor[1] = vertColor[1] =
vertColor[2] = exactLight; vertColor[2] = overbright;
vertColor[3] = 1.0f; vertColor[3] = 1.0f;
break; break;
case CGEN_CONST: case CGEN_CONST:
@ -494,16 +487,6 @@ static void ComputeShaderColors( shaderStage_t *pStage, vec4_t baseColor, vec4_t
baseColor[3] = pStage->constantColor[3] / 255.0f; baseColor[3] = pStage->constantColor[3] / 255.0f;
break; break;
case CGEN_VERTEX: case CGEN_VERTEX:
baseColor[0] =
baseColor[1] =
baseColor[2] =
baseColor[3] = 0.0f;
vertColor[0] =
vertColor[1] =
vertColor[2] = tr.identityLight;
vertColor[3] = 1.0f;
break;
case CGEN_VERTEX_LIT: case CGEN_VERTEX_LIT:
baseColor[0] = baseColor[0] =
baseColor[1] = baseColor[1] =
@ -513,28 +496,24 @@ static void ComputeShaderColors( shaderStage_t *pStage, vec4_t baseColor, vec4_t
vertColor[0] = vertColor[0] =
vertColor[1] = vertColor[1] =
vertColor[2] = vertColor[2] =
vertColor[3] = tr.identityLight; vertColor[3] = 1.0f;
break; break;
case CGEN_ONE_MINUS_VERTEX: case CGEN_ONE_MINUS_VERTEX:
baseColor[0] = baseColor[0] =
baseColor[1] = baseColor[1] =
baseColor[2] = tr.identityLight; baseColor[2] = 1.0f;
vertColor[0] = vertColor[0] =
vertColor[1] = vertColor[1] =
vertColor[2] = -tr.identityLight; vertColor[2] = -1.0f;
break; break;
case CGEN_FOG: case CGEN_FOG:
{ fog = tr.world->fogs + tess.fogNum;
fog_t *fog;
fog = tr.world->fogs + tess.fogNum; baseColor[0] = ((unsigned char *)(&fog->colorInt))[0] / 255.0f;
baseColor[1] = ((unsigned char *)(&fog->colorInt))[1] / 255.0f;
baseColor[0] = ((unsigned char *)(&fog->colorInt))[0] / 255.0f; baseColor[2] = ((unsigned char *)(&fog->colorInt))[2] / 255.0f;
baseColor[1] = ((unsigned char *)(&fog->colorInt))[1] / 255.0f; baseColor[3] = ((unsigned char *)(&fog->colorInt))[3] / 255.0f;
baseColor[2] = ((unsigned char *)(&fog->colorInt))[2] / 255.0f;
baseColor[3] = ((unsigned char *)(&fog->colorInt))[3] / 255.0f;
}
break; break;
case CGEN_WAVEFORM: case CGEN_WAVEFORM:
baseColor[0] = baseColor[0] =
@ -561,6 +540,11 @@ static void ComputeShaderColors( shaderStage_t *pStage, vec4_t baseColor, vec4_t
break; break;
case CGEN_IDENTITY: case CGEN_IDENTITY:
case CGEN_LIGHTING_DIFFUSE: case CGEN_LIGHTING_DIFFUSE:
baseColor[0] =
baseColor[1] =
baseColor[2] = overbright;
break;
case CGEN_IDENTITY_LIGHTING:
case CGEN_BAD: case CGEN_BAD:
break; break;
} }
@ -611,18 +595,6 @@ static void ComputeShaderColors( shaderStage_t *pStage, vec4_t baseColor, vec4_t
break; break;
} }
if (tr.overbrightBits && !isBlend)
scale *= 1 << tr.overbrightBits;
if ((backEnd.refdef.colorScale != 1.0f) && !isBlend && isWorldDraw)
scale *= backEnd.refdef.colorScale;
if (scale != 1.0f)
{
VectorScale(baseColor, scale, baseColor);
VectorScale(vertColor, scale, vertColor);
}
// FIXME: find some way to implement this. // FIXME: find some way to implement this.
#if 0 #if 0
// if in greyscale rendering mode turn all color values into greyscale. // if in greyscale rendering mode turn all color values into greyscale.

View file

@ -1826,11 +1826,13 @@ static qboolean ParseShader( char **text )
if (isGL2Sun) if (isGL2Sun)
{ {
token = COM_ParseExt( text, qfalse );
tr.mapLightScale = atof(token);
token = COM_ParseExt( text, qfalse ); token = COM_ParseExt( text, qfalse );
tr.sunShadowScale = atof(token); tr.sunShadowScale = atof(token);
// parse twice, since older shaders may include mapLightScale before sunShadowScale
token = COM_ParseExt( text, qfalse );
if (token[0])
tr.sunShadowScale = atof(token);
} }
SkipRestOfLine( text ); SkipRestOfLine( text );

View file

@ -448,7 +448,7 @@ static void DrawSkySide( struct image_s *image, const int mins[2], const int max
color[0] = color[0] =
color[1] = color[1] =
color[2] = backEnd.refdef.colorScale; color[2] =
color[3] = 1.0f; color[3] = 1.0f;
GLSL_SetUniformVec4(sp, UNIFORM_BASECOLOR, color); GLSL_SetUniformVec4(sp, UNIFORM_BASECOLOR, color);

View file

@ -264,10 +264,6 @@ Cvars for the sunlight and cascaded shadow maps:
1 - Do. 1 - Do.
2 - Sunrise, sunset. 2 - Sunrise, sunset.
* `r_forceSunMapLightScale` - Cheat. Scale map brightness by this factor
when r_forceSun 1.
1.0 - Default
* `r_forceSunLightScale` - Cheat. Scale sun brightness by this factor * `r_forceSunLightScale` - Cheat. Scale sun brightness by this factor
when r_forceSun 1. when r_forceSun 1.
1.0 - Default 1.0 - Default
@ -506,7 +502,7 @@ and is the equivalent for 'exactVertex'.
This adds a new keyword to sky materials, q3gl2_sun. The syntax is: This adds a new keyword to sky materials, q3gl2_sun. The syntax is:
q3gl2_sun <red> <green> <blue> <intensity> <degrees> <elevation> <mapLightScale> <ambientLightScale> q3gl2_sun <red> <green> <blue> <intensity> <degrees> <elevation> <shadowScale>
Note the first six parameters are the same as in q3map_sun or q3map_sunExt, 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 and the last two indicate scaling factors for the map brightness and an ambient
@ -527,7 +523,7 @@ There are currently two ways to use this in your own (and other people's) maps.
surfaceparm nolightmap surfaceparm nolightmap
surfaceparm sky surfaceparm sky
q3map_sunExt 240 238 200 100 195 35 3 16 q3map_sunExt 240 238 200 100 195 35 3 16
q3gl2_sun 240 238 200 50 195 35 1.0 0.2 q3gl2_sun 240 238 200 50 195 35 0.2
q3map_skylight 50 16 q3map_skylight 50 16
q3map_lightimage $whiteimage q3map_lightimage $whiteimage
@ -550,7 +546,7 @@ There are currently two ways to use this in your own (and other people's) maps.
surfaceparm noimpact surfaceparm noimpact
surfaceparm nolightmap surfaceparm nolightmap
surfaceparm sky surfaceparm sky
q3gl2_sun 240 238 200 50 195 35 0.5 0.2 q3gl2_sun 240 238 200 50 195 35 0.2
q3map_skylight 50 16 q3map_skylight 50 16
q3map_lightimage $whiteimage q3map_lightimage $whiteimage