summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSmileTheory <SmileTheory@gmail.com>2013-10-10 03:41:31 -0700
committerTim Angus <tim@ngus.net>2014-06-17 17:43:34 +0100
commitd3de16e2c53104de6364a280e8970c9fea379042 (patch)
tree3c5135de7c6b62e5adc0208c7b3498dbe863e1f6
parent5c678ec30b0b83c4ed216d06b7b38c77f96e4b77 (diff)
OpenGL2: Fix TCGEN_ENVIRONMENT stages not rendering correctly.
-rw-r--r--src/renderergl2/glsl/generic_vp.glsl10
-rw-r--r--src/renderergl2/glsl/lightall_vp.glsl3
-rw-r--r--src/renderergl2/tr_glsl.c12
-rw-r--r--src/renderergl2/tr_light.c5
-rw-r--r--src/renderergl2/tr_local.h5
-rw-r--r--src/renderergl2/tr_shade.c3
-rw-r--r--src/renderergl2/tr_shader.c15
7 files changed, 34 insertions, 19 deletions
diff --git a/src/renderergl2/glsl/generic_vp.glsl b/src/renderergl2/glsl/generic_vp.glsl
index 429d62f5..94e3c83e 100644
--- a/src/renderergl2/glsl/generic_vp.glsl
+++ b/src/renderergl2/glsl/generic_vp.glsl
@@ -17,7 +17,7 @@ uniform vec4 u_DiffuseTexMatrix;
uniform vec4 u_DiffuseTexOffTurb;
#if defined(USE_TCGEN) || defined(USE_RGBAGEN)
-uniform vec3 u_ViewOrigin;
+uniform vec3 u_LocalViewOrigin;
#endif
#if defined(USE_TCGEN)
@@ -48,7 +48,7 @@ uniform int u_ColorGen;
uniform int u_AlphaGen;
uniform vec3 u_AmbientLight;
uniform vec3 u_DirectedLight;
-uniform vec4 u_LightOrigin;
+uniform vec3 u_ModelLightDir;
uniform float u_PortalRange;
#endif
@@ -123,7 +123,7 @@ vec2 GenTexCoords(int TCGen, vec3 position, vec3 normal, vec3 TCGenVector0, vec3
}
else if (TCGen == TCGEN_ENVIRONMENT_MAPPED)
{
- vec3 viewer = normalize(u_ViewOrigin - position);
+ vec3 viewer = normalize(u_LocalViewOrigin - position);
tex = -reflect(viewer, normal).yz * vec2(0.5, -0.5) + 0.5;
}
else if (TCGen == TCGEN_VECTOR)
@@ -158,12 +158,12 @@ vec4 CalcColor(vec3 position, vec3 normal)
if (u_ColorGen == CGEN_LIGHTING_DIFFUSE)
{
- float incoming = clamp(dot(normal, u_LightOrigin.xyz), 0.0, 1.0);
+ float incoming = clamp(dot(normal, u_ModelLightDir), 0.0, 1.0);
color.rgb = clamp(u_DirectedLight * incoming + u_AmbientLight, 0.0, 1.0);
}
- vec3 viewer = u_ViewOrigin - position;
+ vec3 viewer = u_LocalViewOrigin - position;
if (u_AlphaGen == AGEN_LIGHTING_SPECULAR)
{
diff --git a/src/renderergl2/glsl/lightall_vp.glsl b/src/renderergl2/glsl/lightall_vp.glsl
index d9655ebe..ce83d10a 100644
--- a/src/renderergl2/glsl/lightall_vp.glsl
+++ b/src/renderergl2/glsl/lightall_vp.glsl
@@ -22,6 +22,7 @@ attribute vec3 attr_LightDirection;
#if defined(USE_TCGEN) || defined(USE_NORMALMAP) || defined(USE_LIGHT) && !defined(USE_FAST_LIGHT)
uniform vec3 u_ViewOrigin;
+uniform vec3 u_LocalViewOrigin;
#endif
#if defined(USE_TCGEN)
@@ -94,7 +95,7 @@ vec2 GenTexCoords(int TCGen, vec3 position, vec3 normal, vec3 TCGenVector0, vec3
}
else if (TCGen == TCGEN_ENVIRONMENT_MAPPED)
{
- vec3 viewer = normalize(u_ViewOrigin - position);
+ vec3 viewer = normalize(u_LocalViewOrigin - position);
tex = -reflect(viewer, normal).yz * vec2(0.5, -0.5) + 0.5;
}
else if (TCGen == TCGEN_VECTOR)
diff --git a/src/renderergl2/tr_glsl.c b/src/renderergl2/tr_glsl.c
index 54b05dc5..dd6211be 100644
--- a/src/renderergl2/tr_glsl.c
+++ b/src/renderergl2/tr_glsl.c
@@ -106,6 +106,7 @@ static uniformInfo_t uniformsInfo[] =
{ "u_LightUp", GLSL_VEC3 },
{ "u_LightRight", GLSL_VEC3 },
{ "u_LightOrigin", GLSL_VEC4 },
+ { "u_ModelLightDir", GLSL_VEC3 },
{ "u_LightRadius", GLSL_FLOAT },
{ "u_AmbientLight", GLSL_VEC3 },
{ "u_DirectedLight", GLSL_VEC3 },
@@ -124,11 +125,12 @@ static uniformInfo_t uniformsInfo[] =
{ "u_VertexLerp" , GLSL_FLOAT },
{ "u_MaterialInfo", GLSL_VEC2 },
- { "u_ViewInfo", GLSL_VEC4 },
- { "u_ViewOrigin", GLSL_VEC3 },
- { "u_ViewForward", GLSL_VEC3 },
- { "u_ViewLeft", GLSL_VEC3 },
- { "u_ViewUp", GLSL_VEC3 },
+ { "u_ViewInfo", GLSL_VEC4 },
+ { "u_ViewOrigin", GLSL_VEC3 },
+ { "u_LocalViewOrigin", GLSL_VEC3 },
+ { "u_ViewForward", GLSL_VEC3 },
+ { "u_ViewLeft", GLSL_VEC3 },
+ { "u_ViewUp", GLSL_VEC3 },
{ "u_InvTexRes", GLSL_VEC2 },
{ "u_AutoExposureMinMax", GLSL_VEC2 },
diff --git a/src/renderergl2/tr_light.c b/src/renderergl2/tr_light.c
index ba493198..01ce46d2 100644
--- a/src/renderergl2/tr_light.c
+++ b/src/renderergl2/tr_light.c
@@ -404,8 +404,11 @@ void R_SetupEntityLighting( const trRefdef_t *refdef, trRefEntity_t *ent ) {
((byte *)&ent->ambientLightInt)[3] = 0xff;
// transform the direction to local space
- // no need to do this if using lightentity glsl shader
VectorNormalize( lightDir );
+ ent->modelLightDir[0] = DotProduct( lightDir, ent->e.axis[0] );
+ ent->modelLightDir[1] = DotProduct( lightDir, ent->e.axis[1] );
+ ent->modelLightDir[2] = DotProduct( lightDir, ent->e.axis[2] );
+
VectorCopy(lightDir, ent->lightDir);
}
diff --git a/src/renderergl2/tr_local.h b/src/renderergl2/tr_local.h
index 1c97df7d..fe9990bb 100644
--- a/src/renderergl2/tr_local.h
+++ b/src/renderergl2/tr_local.h
@@ -85,7 +85,8 @@ typedef struct {
qboolean needDlights; // true for bmodels that touch a dlight
qboolean lightingCalculated;
qboolean mirrored; // mirrored matrix, needs reversed culling
- vec3_t lightDir; // normalized direction towards light
+ vec3_t lightDir; // normalized direction towards light, in world space
+ vec3_t modelLightDir; // normalized direction towards light, in model space
vec3_t ambientLight; // color normalized to 0-255
int ambientLightInt; // 32 bit rgba packed
vec3_t directedLight;
@@ -765,6 +766,7 @@ typedef enum
UNIFORM_LIGHTUP,
UNIFORM_LIGHTRIGHT,
UNIFORM_LIGHTORIGIN,
+ UNIFORM_MODELLIGHTDIR,
UNIFORM_LIGHTRADIUS,
UNIFORM_AMBIENTLIGHT,
UNIFORM_DIRECTEDLIGHT,
@@ -785,6 +787,7 @@ typedef enum
UNIFORM_VIEWINFO, // znear, zfar, width/2, height/2
UNIFORM_VIEWORIGIN,
+ UNIFORM_LOCALVIEWORIGIN,
UNIFORM_VIEWFORWARD,
UNIFORM_VIEWLEFT,
UNIFORM_VIEWUP,
diff --git a/src/renderergl2/tr_shade.c b/src/renderergl2/tr_shade.c
index a6b956bb..69869c88 100644
--- a/src/renderergl2/tr_shade.c
+++ b/src/renderergl2/tr_shade.c
@@ -720,6 +720,7 @@ static void ForwardDlight( void ) {
GLSL_SetUniformMatrix16(sp, UNIFORM_MODELVIEWPROJECTIONMATRIX, glState.modelviewProjection);
GLSL_SetUniformVec3(sp, UNIFORM_VIEWORIGIN, backEnd.viewParms.or.origin);
+ GLSL_SetUniformVec3(sp, UNIFORM_LOCALVIEWORIGIN, backEnd.or.viewOrigin);
GLSL_SetUniformFloat(sp, UNIFORM_VERTEXLERP, glState.vertexAttribsInterpolation);
@@ -1103,6 +1104,7 @@ static void RB_IterateStagesGeneric( shaderCommands_t *input )
GLSL_SetUniformMatrix16(sp, UNIFORM_MODELVIEWPROJECTIONMATRIX, glState.modelviewProjection);
GLSL_SetUniformVec3(sp, UNIFORM_VIEWORIGIN, backEnd.viewParms.or.origin);
+ GLSL_SetUniformVec3(sp, UNIFORM_LOCALVIEWORIGIN, backEnd.or.viewOrigin);
GLSL_SetUniformFloat(sp, UNIFORM_VERTEXLERP, glState.vertexAttribsInterpolation);
@@ -1151,6 +1153,7 @@ static void RB_IterateStagesGeneric( shaderCommands_t *input )
VectorCopy(backEnd.currentEntity->lightDir, vec);
vec[3] = 0.0f;
GLSL_SetUniformVec4(sp, UNIFORM_LIGHTORIGIN, vec);
+ GLSL_SetUniformVec3(sp, UNIFORM_MODELLIGHTDIR, backEnd.currentEntity->modelLightDir);
GLSL_SetUniformFloat(sp, UNIFORM_LIGHTRADIUS, 0.0f);
}
diff --git a/src/renderergl2/tr_shader.c b/src/renderergl2/tr_shader.c
index 36e159b4..4c2832fd 100644
--- a/src/renderergl2/tr_shader.c
+++ b/src/renderergl2/tr_shader.c
@@ -2283,7 +2283,7 @@ static qboolean CollapseStagesToGLSL(void)
{
// if 2+ stages and first stage is lightmap, switch them
// this makes it easier for the later bits to process
- if (stages[0].active && stages[0].bundle[0].isLightmap && stages[1].active)
+ if (stages[0].active && stages[0].bundle[0].tcGen == TCGEN_LIGHTMAP && stages[1].active)
{
int blendBits = stages[1].stateBits & ( GLS_DSTBLEND_BITS | GLS_SRCBLEND_BITS );
@@ -2320,7 +2320,7 @@ static qboolean CollapseStagesToGLSL(void)
break;
}
- if (pStage->bundle[0].isLightmap)
+ if (pStage->bundle[0].tcGen == TCGEN_LIGHTMAP)
{
int blendBits = pStage->stateBits & ( GLS_DSTBLEND_BITS | GLS_SRCBLEND_BITS );
@@ -2371,7 +2371,7 @@ static qboolean CollapseStagesToGLSL(void)
continue;
// skip lightmaps
- if (pStage->bundle[0].isLightmap)
+ if (pStage->bundle[0].tcGen == TCGEN_LIGHTMAP)
continue;
diffuse = pStage;
@@ -2413,7 +2413,7 @@ static qboolean CollapseStagesToGLSL(void)
break;
case ST_COLORMAP:
- if (pStage2->bundle[0].isLightmap)
+ if (pStage2->bundle[0].tcGen == TCGEN_LIGHTMAP)
{
lightmap = pStage2;
}
@@ -2455,7 +2455,7 @@ static qboolean CollapseStagesToGLSL(void)
if (!pStage->active)
continue;
- if (pStage->bundle[0].isLightmap)
+ if (pStage->bundle[0].tcGen == TCGEN_LIGHTMAP)
{
pStage->active = qfalse;
}
@@ -2521,7 +2521,7 @@ static qboolean CollapseStagesToGLSL(void)
if (pStage->adjustColorsForFog)
continue;
- if (pStage->bundle[TB_DIFFUSEMAP].isLightmap)
+ if (pStage->bundle[TB_DIFFUSEMAP].tcGen == TCGEN_LIGHTMAP)
{
pStage->glslShaderGroup = tr.lightallShader;
pStage->glslShaderIndex = LIGHTDEF_USE_LIGHTMAP;
@@ -2551,6 +2551,9 @@ static qboolean CollapseStagesToGLSL(void)
{
pStage->glslShaderGroup = tr.lightallShader;
pStage->glslShaderIndex = LIGHTDEF_USE_LIGHT_VECTOR;
+
+ if (pStage->bundle[0].tcGen != TCGEN_TEXTURE || pStage->bundle[0].numTexMods != 0)
+ pStage->glslShaderIndex |= LIGHTDEF_USE_TCGEN_AND_TCMOD;
}
}
}