Support more tcgens in lightall shader.

This commit is contained in:
SmileTheory 2013-03-14 23:11:27 -07:00
parent 369956eb63
commit e14a814ba2
2 changed files with 38 additions and 18 deletions

View file

@ -1,5 +1,5 @@
attribute vec4 attr_TexCoord0; attribute vec4 attr_TexCoord0;
#if defined(USE_LIGHTMAP) #if defined(USE_LIGHTMAP) || defined(USE_TCGEN)
attribute vec4 attr_TexCoord1; attribute vec4 attr_TexCoord1;
#endif #endif
attribute vec4 attr_Color; attribute vec4 attr_Color;
@ -31,6 +31,8 @@ uniform vec3 u_ViewOrigin;
#if defined(USE_TCGEN) #if defined(USE_TCGEN)
uniform int u_TCGen0; uniform int u_TCGen0;
uniform vec3 u_TCGen0Vector0;
uniform vec3 u_TCGen0Vector1;
#endif #endif
#if defined(USE_TCMOD) #if defined(USE_TCMOD)
@ -92,6 +94,29 @@ varying vec3 var_VertLight;
varying vec3 var_WorldLight; varying vec3 var_WorldLight;
#endif #endif
#if defined(USE_TCGEN)
vec2 GenTexCoords(int TCGen, vec3 position, vec3 normal, vec3 TCGenVector0, vec3 TCGenVector1)
{
vec2 tex = attr_TexCoord0.st;
if (TCGen == TCGEN_LIGHTMAP)
{
tex = attr_TexCoord1.st;
}
else if (TCGen == TCGEN_ENVIRONMENT_MAPPED)
{
vec3 viewer = normalize(u_ViewOrigin - position);
tex = -reflect(viewer, normal).yz * vec2(0.5, -0.5) + 0.5;
}
else if (TCGen == TCGEN_VECTOR)
{
tex = vec2(dot(position, TCGenVector0), dot(position, TCGenVector1));
}
return tex;
}
#endif
#if defined(USE_TCMOD) #if defined(USE_TCMOD)
vec2 ModTexCoords(vec2 st, vec3 position, vec4 texMatrix, vec4 offTurb) vec2 ModTexCoords(vec2 st, vec3 position, vec4 texMatrix, vec4 offTurb)
{ {
@ -158,18 +183,11 @@ void main()
var_SampleToView = SampleToView; var_SampleToView = SampleToView;
#endif #endif
vec2 tex;
#if defined(USE_TCGEN) #if defined(USE_TCGEN)
if (u_TCGen0 == TCGEN_ENVIRONMENT_MAPPED) vec2 tex = GenTexCoords(u_TCGen0, position.xyz, normal, u_TCGen0Vector0, u_TCGen0Vector1);
{ #else
tex = -reflect(normalize(SampleToView), normal).yz * vec2(0.5, -0.5) + 0.5; vec2 tex = attr_TexCoord0.st;
}
else
#endif #endif
{
tex = attr_TexCoord0.st;
}
#if defined(USE_TCMOD) #if defined(USE_TCMOD)
var_DiffuseTex = ModTexCoords(tex, position.xyz, u_DiffuseTexMatrix, u_DiffuseTexOffTurb); var_DiffuseTex = ModTexCoords(tex, position.xyz, u_DiffuseTexMatrix, u_DiffuseTexOffTurb);

View file

@ -2163,7 +2163,7 @@ static qboolean CollapseMultitexture( void ) {
static void CollapseStagesToLightall(shaderStage_t *diffuse, static void CollapseStagesToLightall(shaderStage_t *diffuse,
shaderStage_t *normal, shaderStage_t *specular, shaderStage_t *lightmap, shaderStage_t *normal, shaderStage_t *specular, shaderStage_t *lightmap,
qboolean useLightVector, qboolean useLightVertex, qboolean parallax, qboolean environment) qboolean useLightVector, qboolean useLightVertex, qboolean parallax, qboolean tcgen)
{ {
int defs = 0; int defs = 0;
@ -2241,7 +2241,7 @@ static void CollapseStagesToLightall(shaderStage_t *diffuse,
} }
} }
if (environment || diffuse->bundle[0].numTexMods) if (tcgen || diffuse->bundle[0].numTexMods)
{ {
defs |= LIGHTDEF_USE_TCGEN_AND_TCMOD; defs |= LIGHTDEF_USE_TCGEN_AND_TCMOD;
} }
@ -2347,7 +2347,7 @@ static qboolean CollapseStagesToGLSL(void)
{ {
shaderStage_t *pStage = &stages[i]; shaderStage_t *pStage = &stages[i];
shaderStage_t *diffuse, *normal, *specular, *lightmap; shaderStage_t *diffuse, *normal, *specular, *lightmap;
qboolean parallax, environment, diffuselit, vertexlit; qboolean parallax, tcgen, diffuselit, vertexlit;
if (!pStage->active) if (!pStage->active)
continue; continue;
@ -2410,10 +2410,12 @@ static qboolean CollapseStagesToGLSL(void)
} }
} }
environment = qfalse; tcgen = qfalse;
if (diffuse->bundle[0].tcGen == TCGEN_ENVIRONMENT_MAPPED) if (diffuse->bundle[0].tcGen == TCGEN_ENVIRONMENT_MAPPED
|| diffuse->bundle[0].tcGen == TCGEN_LIGHTMAP
|| diffuse->bundle[0].tcGen == TCGEN_VECTOR)
{ {
environment = qtrue; tcgen = qtrue;
} }
diffuselit = qfalse; diffuselit = qfalse;
@ -2428,7 +2430,7 @@ static qboolean CollapseStagesToGLSL(void)
vertexlit = qtrue; vertexlit = qtrue;
} }
CollapseStagesToLightall(diffuse, normal, specular, lightmap, diffuselit, vertexlit, parallax, environment); CollapseStagesToLightall(diffuse, normal, specular, lightmap, diffuselit, vertexlit, parallax, tcgen);
} }
// deactivate lightmap stages // deactivate lightmap stages