OpenGL2: Fix TCGEN_ENVIRONMENT stages not rendering correctly.

This commit is contained in:
SmileTheory 2013-10-10 03:41:31 -07:00
parent a836c2db89
commit f8355ba2fb
7 changed files with 34 additions and 19 deletions

View file

@ -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)
{

View file

@ -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)

View file

@ -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 },

View file

@ -403,8 +403,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);
}

View file

@ -84,7 +84,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;
@ -764,6 +765,7 @@ typedef enum
UNIFORM_LIGHTUP,
UNIFORM_LIGHTRIGHT,
UNIFORM_LIGHTORIGIN,
UNIFORM_MODELLIGHTDIR,
UNIFORM_LIGHTRADIUS,
UNIFORM_AMBIENTLIGHT,
UNIFORM_DIRECTEDLIGHT,
@ -784,6 +786,7 @@ typedef enum
UNIFORM_VIEWINFO, // znear, zfar, width/2, height/2
UNIFORM_VIEWORIGIN,
UNIFORM_LOCALVIEWORIGIN,
UNIFORM_VIEWFORWARD,
UNIFORM_VIEWLEFT,
UNIFORM_VIEWUP,

View file

@ -719,6 +719,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);
@ -1102,6 +1103,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);
@ -1150,6 +1152,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);
}

View file

@ -2282,7 +2282,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 );
@ -2319,7 +2319,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 );
@ -2370,7 +2370,7 @@ static qboolean CollapseStagesToGLSL(void)
continue;
// skip lightmaps
if (pStage->bundle[0].isLightmap)
if (pStage->bundle[0].tcGen == TCGEN_LIGHTMAP)
continue;
diffuse = pStage;
@ -2412,7 +2412,7 @@ static qboolean CollapseStagesToGLSL(void)
break;
case ST_COLORMAP:
if (pStage2->bundle[0].isLightmap)
if (pStage2->bundle[0].tcGen == TCGEN_LIGHTMAP)
{
lightmap = pStage2;
}
@ -2454,7 +2454,7 @@ static qboolean CollapseStagesToGLSL(void)
if (!pStage->active)
continue;
if (pStage->bundle[0].isLightmap)
if (pStage->bundle[0].tcGen == TCGEN_LIGHTMAP)
{
pStage->active = qfalse;
}
@ -2520,7 +2520,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;
@ -2550,6 +2550,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;
}
}
}