summaryrefslogtreecommitdiff
path: root/src/renderergl2/tr_shade.c
diff options
context:
space:
mode:
authorTim Angus <tim@ngus.net>2016-04-09 17:57:28 +0100
committerTim Angus <tim@ngus.net>2016-04-09 17:57:28 +0100
commitf45fbef604e05144057dec8d1dbfc5d4f5a2a822 (patch)
tree152d2a428b078f7a89756ea9e156695fc69f1686 /src/renderergl2/tr_shade.c
parent7f9e97d611b4b267d9dd913144cb9632f96c90c2 (diff)
parent87abdd914988724e164ffb16380ad26be8420b84 (diff)
Merge branch 'master' into gpp
Diffstat (limited to 'src/renderergl2/tr_shade.c')
-rw-r--r--src/renderergl2/tr_shade.c144
1 files changed, 89 insertions, 55 deletions
diff --git a/src/renderergl2/tr_shade.c b/src/renderergl2/tr_shade.c
index 9853313c..2578420c 100644
--- a/src/renderergl2/tr_shade.c
+++ b/src/renderergl2/tr_shade.c
@@ -102,11 +102,9 @@ static void R_BindAnimatedImageToTMU( textureBundle_t *bundle, int tmu ) {
int index;
if ( bundle->isVideoMap ) {
- int oldtmu = glState.currenttmu;
- GL_SelectTexture(tmu);
ri.CIN_RunCinematic(bundle->videoMapHandle);
ri.CIN_UploadCinematic(bundle->videoMapHandle);
- GL_SelectTexture(oldtmu);
+ GL_BindToTMU(tr.scratchImage[bundle->videoMapHandle], tmu);
return;
}
@@ -137,7 +135,7 @@ Draws triangle outlines for debugging
================
*/
static void DrawTris (shaderCommands_t *input) {
- GL_Bind( tr.whiteImage );
+ GL_BindToTMU( tr.whiteImage, TB_COLORMAP );
GL_State( GLS_POLYMODE_LINE | GLS_DEPTHMASK_TRUE );
qglDepthRange( 0, 0 );
@@ -415,7 +413,7 @@ static void ProjectDlightTexture( void ) {
vector[3] = scale;
GLSL_SetUniformVec4(sp, UNIFORM_DLIGHTINFO, vector);
- GL_Bind( tr.dlightImage );
+ GL_BindToTMU( tr.dlightImage, TB_COLORMAP );
// include GLS_DEPTHFUNC_EQUAL so alpha tested surfaces don't add light
// where they aren't rendered
@@ -445,9 +443,22 @@ static void ProjectDlightTexture( void ) {
static void ComputeShaderColors( shaderStage_t *pStage, vec4_t baseColor, vec4_t vertColor, int blend )
{
+ qboolean isBlend = ((blend & GLS_SRCBLEND_BITS) == GLS_SRCBLEND_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_ONE_MINUS_SRC_COLOR);
+ qboolean isWorldDraw = !(backEnd.refdef.rdflags & RDF_NOWORLDMODEL);
+ float scale = 1.0f;
+
+#if defined(USE_OVERBRIGHT)
+ float exactLight = 1.0f;
+#else
+ float exactLight = (isBlend || !isWorldDraw) ? 1.0f : (float)(1 << r_mapOverBrightBits->integer);
+#endif
+
baseColor[0] =
baseColor[1] =
- baseColor[2] =
+ baseColor[2] = exactLight;
baseColor[3] = 1.0f;
vertColor[0] =
@@ -474,7 +485,7 @@ static void ComputeShaderColors( shaderStage_t *pStage, vec4_t baseColor, vec4_t
vertColor[0] =
vertColor[1] =
- vertColor[2] =
+ vertColor[2] = exactLight;
vertColor[3] = 1.0f;
break;
case CGEN_CONST:
@@ -601,21 +612,16 @@ static void ComputeShaderColors( shaderStage_t *pStage, vec4_t baseColor, vec4_t
break;
}
- // multiply color by overbrightbits if this isn't a blend
- if (tr.overbrightBits
- && !((blend & GLS_SRCBLEND_BITS) == GLS_SRCBLEND_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_ONE_MINUS_SRC_COLOR))
+ if (tr.overbrightBits && !isBlend)
+ scale *= 1 << tr.overbrightBits;
+
+ if ((backEnd.refdef.colorScale != 1.0f) && !isBlend && isWorldDraw)
+ scale *= backEnd.refdef.colorScale;
+
+ if (scale != 1.0f)
{
- float scale = 1 << tr.overbrightBits;
-
- baseColor[0] *= scale;
- baseColor[1] *= scale;
- baseColor[2] *= scale;
- vertColor[0] *= scale;
- vertColor[1] *= scale;
- vertColor[2] *= scale;
+ VectorScale(baseColor, scale, baseColor);
+ VectorScale(vertColor, scale, vertColor);
}
// FIXME: find some way to implement this.
@@ -855,11 +861,7 @@ static void ForwardDlight( void ) {
}
if (r_dlightMode->integer >= 2)
- {
- GL_SelectTexture(TB_SHADOWMAP);
- GL_Bind(tr.shadowCubemaps[l]);
- GL_SelectTexture(0);
- }
+ GL_BindToTMU(tr.shadowCubemaps[l], TB_SHADOWMAP);
ComputeTexMods( pStage, TB_DIFFUSEMAP, texMatrix, texOffTurb );
GLSL_SetUniformVec4(sp, UNIFORM_DIFFUSETEXMATRIX, texMatrix);
@@ -1070,6 +1072,8 @@ static void RB_IterateStagesGeneric( shaderCommands_t *input )
int deformGen;
vec5_t deformParams;
+ qboolean renderToCubemap = tr.renderCubeFbo && glState.currentFBO == tr.renderCubeFbo;
+
ComputeDeformValues(&deformGen, deformParams);
ComputeFogValues(fogDistanceVector, fogDepthVector, &eyeT);
@@ -1140,9 +1144,9 @@ static void RB_IterateStagesGeneric( shaderCommands_t *input )
index |= LIGHTDEF_USE_SHADOWMAP;
}
- if (r_lightmap->integer && index & LIGHTDEF_USE_LIGHTMAP)
+ if (r_lightmap->integer && ((index & LIGHTDEF_LIGHTTYPE_MASK) == LIGHTDEF_USE_LIGHTMAP))
{
- index = LIGHTDEF_USE_LIGHTMAP;
+ index = LIGHTDEF_USE_TCGEN_AND_TCMOD;
}
sp = &pStage->glslShaderGroup[index];
@@ -1185,13 +1189,6 @@ static void RB_IterateStagesGeneric( shaderCommands_t *input )
ComputeShaderColors(pStage, baseColor, vertColor, pStage->stateBits);
- if ((backEnd.refdef.colorScale != 1.0f) && !(backEnd.refdef.rdflags & RDF_NOWORLDMODEL))
- {
- // use VectorScale to only scale first three values, not alpha
- VectorScale(baseColor, backEnd.refdef.colorScale, baseColor);
- VectorScale(vertColor, backEnd.refdef.colorScale, vertColor);
- }
-
GLSL_SetUniformVec4(sp, UNIFORM_BASECOLOR, baseColor);
GLSL_SetUniformVec4(sp, UNIFORM_VERTCOLOR, vertColor);
}
@@ -1231,25 +1228,51 @@ static void RB_IterateStagesGeneric( shaderCommands_t *input )
GLSL_SetUniformVec4(sp, UNIFORM_FOGCOLORMASK, fogColorMask);
}
- ComputeTexMods( pStage, TB_DIFFUSEMAP, texMatrix, texOffTurb );
- GLSL_SetUniformVec4(sp, UNIFORM_DIFFUSETEXMATRIX, texMatrix);
- GLSL_SetUniformVec4(sp, UNIFORM_DIFFUSETEXOFFTURB, texOffTurb);
+ if (r_lightmap->integer)
+ {
+ vec4_t v;
+ VectorSet4(v, 1.0f, 0.0f, 0.0f, 1.0f);
+ GLSL_SetUniformVec4(sp, UNIFORM_DIFFUSETEXMATRIX, v);
+ VectorSet4(v, 0.0f, 0.0f, 0.0f, 0.0f);
+ GLSL_SetUniformVec4(sp, UNIFORM_DIFFUSETEXOFFTURB, v);
- GLSL_SetUniformInt(sp, UNIFORM_TCGEN0, pStage->bundle[0].tcGen);
- if (pStage->bundle[0].tcGen == TCGEN_VECTOR)
+ GLSL_SetUniformInt(sp, UNIFORM_TCGEN0, TCGEN_LIGHTMAP);
+ }
+ else
{
- vec3_t vec;
+ ComputeTexMods(pStage, TB_DIFFUSEMAP, texMatrix, texOffTurb);
+ GLSL_SetUniformVec4(sp, UNIFORM_DIFFUSETEXMATRIX, texMatrix);
+ GLSL_SetUniformVec4(sp, UNIFORM_DIFFUSETEXOFFTURB, texOffTurb);
+
+ GLSL_SetUniformInt(sp, UNIFORM_TCGEN0, pStage->bundle[0].tcGen);
+ if (pStage->bundle[0].tcGen == TCGEN_VECTOR)
+ {
+ vec3_t vec;
- VectorCopy(pStage->bundle[0].tcGenVectors[0], vec);
- GLSL_SetUniformVec3(sp, UNIFORM_TCGEN0VECTOR0, vec);
- VectorCopy(pStage->bundle[0].tcGenVectors[1], vec);
- GLSL_SetUniformVec3(sp, UNIFORM_TCGEN0VECTOR1, vec);
+ VectorCopy(pStage->bundle[0].tcGenVectors[0], vec);
+ GLSL_SetUniformVec3(sp, UNIFORM_TCGEN0VECTOR0, vec);
+ VectorCopy(pStage->bundle[0].tcGenVectors[1], vec);
+ GLSL_SetUniformVec3(sp, UNIFORM_TCGEN0VECTOR1, vec);
+ }
}
GLSL_SetUniformMat4(sp, UNIFORM_MODELMATRIX, backEnd.or.transformMatrix);
GLSL_SetUniformVec4(sp, UNIFORM_NORMALSCALE, pStage->normalScale);
- GLSL_SetUniformVec4(sp, UNIFORM_SPECULARSCALE, pStage->specularScale);
+
+ {
+ vec4_t specularScale;
+ Vector4Copy(pStage->specularScale, specularScale);
+
+ if (renderToCubemap)
+ {
+ // force specular to nonmetal if rendering cubemaps
+ if (r_pbr->integer)
+ specularScale[1] = 0.0f;
+ }
+
+ GLSL_SetUniformVec4(sp, UNIFORM_SPECULARSCALE, pStage->specularScale);
+ }
//GLSL_SetUniformFloat(sp, UNIFORM_MAPLIGHTSCALE, backEnd.refdef.mapLightScale);
@@ -1259,7 +1282,7 @@ static void RB_IterateStagesGeneric( shaderCommands_t *input )
if ( backEnd.depthFill )
{
if (!(pStage->stateBits & GLS_ATEST_BITS))
- GL_BindToTMU( tr.whiteImage, 0 );
+ GL_BindToTMU( tr.whiteImage, TB_COLORMAP );
else if ( pStage->bundle[TB_COLORMAP].image[0] != 0 )
R_BindAnimatedImageToTMU( &pStage->bundle[TB_COLORMAP], TB_COLORMAP );
}
@@ -1272,7 +1295,19 @@ static void RB_IterateStagesGeneric( shaderCommands_t *input )
{
GL_BindToTMU(tr.screenShadowImage, TB_SHADOWMAP);
GLSL_SetUniformVec3(sp, UNIFORM_PRIMARYLIGHTAMBIENT, backEnd.refdef.sunAmbCol);
- GLSL_SetUniformVec3(sp, UNIFORM_PRIMARYLIGHTCOLOR, backEnd.refdef.sunCol);
+ if (r_pbr->integer)
+ {
+ vec3_t color;
+
+ color[0] = backEnd.refdef.sunCol[0] * backEnd.refdef.sunCol[0];
+ color[1] = backEnd.refdef.sunCol[1] * backEnd.refdef.sunCol[1];
+ color[2] = backEnd.refdef.sunCol[2] * backEnd.refdef.sunCol[2];
+ GLSL_SetUniformVec3(sp, UNIFORM_PRIMARYLIGHTCOLOR, color);
+ }
+ else
+ {
+ GLSL_SetUniformVec3(sp, UNIFORM_PRIMARYLIGHTCOLOR, backEnd.refdef.sunCol);
+ }
GLSL_SetUniformVec4(sp, UNIFORM_PRIMARYLIGHTORIGIN, backEnd.refdef.sunDir);
}
@@ -1281,7 +1316,7 @@ static void RB_IterateStagesGeneric( shaderCommands_t *input )
{
for (i = 0; i < NUM_TEXTURE_BUNDLES; i++)
{
- if (i == TB_LIGHTMAP)
+ if (i == TB_COLORMAP)
R_BindAnimatedImageToTMU( &pStage->bundle[TB_LIGHTMAP], i);
else
GL_BindToTMU( tr.whiteImage, i );
@@ -1291,7 +1326,7 @@ static void RB_IterateStagesGeneric( shaderCommands_t *input )
{
for (i = 0; i < NUM_TEXTURE_BUNDLES; i++)
{
- if (i == TB_LIGHTMAP)
+ if (i == TB_COLORMAP)
R_BindAnimatedImageToTMU( &pStage->bundle[TB_DELUXEMAP], i);
else
GL_BindToTMU( tr.whiteImage, i );
@@ -1368,15 +1403,14 @@ static void RB_IterateStagesGeneric( shaderCommands_t *input )
if (!(tr.viewParms.flags & VPF_NOCUBEMAPS) && input->cubemapIndex && r_cubeMapping->integer)
{
vec4_t vec;
+ cubemap_t *cubemap = &tr.cubemaps[input->cubemapIndex - 1];
- GL_BindToTMU( tr.cubemaps[input->cubemapIndex - 1], TB_CUBEMAP);
+ GL_BindToTMU( cubemap->image, TB_CUBEMAP);
- vec[0] = tr.cubemapOrigins[input->cubemapIndex - 1][0] - backEnd.viewParms.or.origin[0];
- vec[1] = tr.cubemapOrigins[input->cubemapIndex - 1][1] - backEnd.viewParms.or.origin[1];
- vec[2] = tr.cubemapOrigins[input->cubemapIndex - 1][2] - backEnd.viewParms.or.origin[2];
+ VectorSubtract(cubemap->origin, backEnd.viewParms.or.origin, vec);
vec[3] = 1.0f;
- VectorScale4(vec, 1.0f / 1000.0f, vec);
+ VectorScale4(vec, 1.0f / cubemap->parallaxRadius, vec);
GLSL_SetUniformVec4(sp, UNIFORM_CUBEMAPINFO, vec);
}