Fix stencil shadows not drawing if has 500 or more vertexes

Stencil shadow is not drawn if a mesh, or multiple meshes with the same
entity and shader, have more than 500 vertexes. The issue is caused by storing
the projected positions in the tess vertex buffer. Use a new array instead.
This commit is contained in:
Zack Middleton 2014-11-16 21:21:15 -06:00
parent d06deb41c8
commit c787cf3aef
2 changed files with 16 additions and 24 deletions

View file

@ -44,6 +44,7 @@ typedef struct {
static edgeDef_t edgeDefs[SHADER_MAX_VERTEXES][MAX_EDGE_DEFS];
static int numEdgeDefs[SHADER_MAX_VERTEXES];
static int facing[SHADER_MAX_INDEXES/3];
static vec3_t shadowXyz[SHADER_MAX_VERTEXES];
void R_AddEdgeDef( int i1, int i2, int facing ) {
int c;
@ -80,13 +81,13 @@ void R_RenderShadowEdges( void ) {
qglBegin( GL_TRIANGLE_STRIP );
qglVertex3fv( tess.xyz[ i1 ] );
qglVertex3fv( tess.xyz[ i1 + tess.numVertexes ] );
qglVertex3fv( shadowXyz[ i1 ] );
qglVertex3fv( tess.xyz[ i2 ] );
qglVertex3fv( tess.xyz[ i2 + tess.numVertexes ] );
qglVertex3fv( shadowXyz[ i2 ] );
qglVertex3fv( tess.xyz[ i3 ] );
qglVertex3fv( tess.xyz[ i3 + tess.numVertexes ] );
qglVertex3fv( shadowXyz[ i3 ] );
qglVertex3fv( tess.xyz[ i1 ] );
qglVertex3fv( tess.xyz[ i1 + tess.numVertexes ] );
qglVertex3fv( shadowXyz[ i1 ] );
qglEnd();
}
#else
@ -126,9 +127,9 @@ void R_RenderShadowEdges( void ) {
if ( hit[ 1 ] == 0 ) {
qglBegin( GL_TRIANGLE_STRIP );
qglVertex3fv( tess.xyz[ i ] );
qglVertex3fv( tess.xyz[ i + tess.numVertexes ] );
qglVertex3fv( shadowXyz[ i ] );
qglVertex3fv( tess.xyz[ i2 ] );
qglVertex3fv( tess.xyz[ i2 + tess.numVertexes ] );
qglVertex3fv( shadowXyz[ i2 ] );
qglEnd();
c_edges++;
} else {
@ -157,11 +158,6 @@ void RB_ShadowTessEnd( void ) {
vec3_t lightDir;
GLboolean rgba[4];
// we can only do this if we have enough space in the vertex buffers
if ( tess.numVertexes >= SHADER_MAX_VERTEXES / 2 ) {
return;
}
if ( glConfig.stencilBits < 4 ) {
return;
}
@ -170,7 +166,7 @@ void RB_ShadowTessEnd( void ) {
// project vertexes away from light direction
for ( i = 0 ; i < tess.numVertexes ; i++ ) {
VectorMA( tess.xyz[i], -512, lightDir, tess.xyz[i+tess.numVertexes] );
VectorMA( tess.xyz[i], -512, lightDir, shadowXyz[i] );
}
// decide which triangles face the light

View file

@ -44,6 +44,7 @@ typedef struct {
static edgeDef_t edgeDefs[SHADER_MAX_VERTEXES][MAX_EDGE_DEFS];
static int numEdgeDefs[SHADER_MAX_VERTEXES];
static int facing[SHADER_MAX_INDEXES/3];
static vec3_t shadowXyz[SHADER_MAX_VERTEXES];
void R_AddEdgeDef( int i1, int i2, int facing ) {
int c;
@ -80,13 +81,13 @@ void R_RenderShadowEdges( void ) {
qglBegin( GL_TRIANGLE_STRIP );
qglVertex3fv( tess.xyz[ i1 ] );
qglVertex3fv( tess.xyz[ i1 + tess.numVertexes ] );
qglVertex3fv( shadowXyz[ i1 ] );
qglVertex3fv( tess.xyz[ i2 ] );
qglVertex3fv( tess.xyz[ i2 + tess.numVertexes ] );
qglVertex3fv( shadowXyz[ i2 ] );
qglVertex3fv( tess.xyz[ i3 ] );
qglVertex3fv( tess.xyz[ i3 + tess.numVertexes ] );
qglVertex3fv( shadowXyz[ i3 ] );
qglVertex3fv( tess.xyz[ i1 ] );
qglVertex3fv( tess.xyz[ i1 + tess.numVertexes ] );
qglVertex3fv( shadowXyz[ i1 ] );
qglEnd();
}
#else
@ -126,9 +127,9 @@ void R_RenderShadowEdges( void ) {
if ( hit[ 1 ] == 0 ) {
qglBegin( GL_TRIANGLE_STRIP );
qglVertex3fv( tess.xyz[ i ] );
qglVertex3fv( tess.xyz[ i + tess.numVertexes ] );
qglVertex3fv( shadowXyz[ i ] );
qglVertex3fv( tess.xyz[ i2 ] );
qglVertex3fv( tess.xyz[ i2 + tess.numVertexes ] );
qglVertex3fv( shadowXyz[ i2 ] );
qglEnd();
c_edges++;
} else {
@ -157,11 +158,6 @@ void RB_ShadowTessEnd( void ) {
vec3_t lightDir;
GLboolean rgba[4];
// we can only do this if we have enough space in the vertex buffers
if ( tess.numVertexes >= SHADER_MAX_VERTEXES / 2 ) {
return;
}
if ( glConfig.stencilBits < 4 ) {
return;
}
@ -170,7 +166,7 @@ void RB_ShadowTessEnd( void ) {
// project vertexes away from light direction
for ( i = 0 ; i < tess.numVertexes ; i++ ) {
VectorMA( tess.xyz[i], -512, lightDir, tess.xyz[i+tess.numVertexes] );
VectorMA( tess.xyz[i], -512, lightDir, shadowXyz[i] );
}
// decide which triangles face the light