Reorganize a little code so that lightmaps can be used when a spotlight isn't currently casting a shadow. This fixes the problem where the window lights in the E1L1 apartment secret would jump between square and circle-shaped depending on the shadowcount and the view angle.

git-svn-id: https://svn.eduke32.com/eduke32@1674 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
plagman 2010-07-25 02:16:22 +00:00
parent 8a3dd08b14
commit abbe41e97d
2 changed files with 166 additions and 140 deletions

View file

@ -74,6 +74,7 @@ typedef enum {
PR_BIT_MIRROR_MAP,
PR_BIT_FOG,
PR_BIT_GLOW_MAP,
PR_BIT_PROJECTION_MAP,
PR_BIT_SHADOW_MAP,
PR_BIT_LIGHT_MAP,
PR_BIT_SPOT_LIGHT,
@ -137,9 +138,10 @@ typedef struct s_prrograminfo {
GLint uniform_mirrorMap;
// PR_BIT_GLOW_MAP
GLint uniform_glowMap;
// PR_BIT_PROJECTION_MAP
GLint uniform_shadowProjMatrix;
// PR_BIT_SHADOW_MAP
GLint uniform_shadowMap;
GLint uniform_shadowProjMatrix;
// PR_BIT_LIGHT_MAP
GLint uniform_lightMap;
// PR_BIT_SPOT_LIGHT
@ -333,134 +335,134 @@ static void polymer_initrendertargets(int32_t count);
// the following from gle/vvector.h
/* ========================================================== */
/* determinant of matrix
*
* Computes determinant of matrix m, returning d
*/
#define DETERMINANT_3X3(d,m) \
{ \
d = m[0][0] * (m[1][1]*m[2][2] - m[1][2] * m[2][1]); \
d -= m[0][1] * (m[1][0]*m[2][2] - m[1][2] * m[2][0]); \
d += m[0][2] * (m[1][0]*m[2][1] - m[1][1] * m[2][0]); \
}
/* ========================================================== */
/* i,j,th cofactor of a 4x4 matrix
*
*/
#define COFACTOR_4X4_IJ(fac,m,i,j) \
{ \
int ii[4], jj[4], k; \
\
/* compute which row, columnt to skip */ \
for (k=0; k<i; k++) ii[k] = k; \
for (k=i; k<3; k++) ii[k] = k+1; \
for (k=0; k<j; k++) jj[k] = k; \
for (k=j; k<3; k++) jj[k] = k+1; \
\
(fac) = m[ii[0]][jj[0]] * (m[ii[1]][jj[1]]*m[ii[2]][jj[2]] \
- m[ii[1]][jj[2]]*m[ii[2]][jj[1]]); \
(fac) -= m[ii[0]][jj[1]] * (m[ii[1]][jj[0]]*m[ii[2]][jj[2]] \
- m[ii[1]][jj[2]]*m[ii[2]][jj[0]]);\
(fac) += m[ii[0]][jj[2]] * (m[ii[1]][jj[0]]*m[ii[2]][jj[1]] \
- m[ii[1]][jj[1]]*m[ii[2]][jj[0]]);\
\
/* compute sign */ \
k = i+j; \
if ( k != (k/2)*2) { \
(fac) = -(fac); \
} \
}
/* ========================================================== */
/* determinant of matrix
*
* Computes determinant of matrix m, returning d
*/
#define DETERMINANT_4X4(d,m) \
{ \
double cofac; \
COFACTOR_4X4_IJ (cofac, m, 0, 0); \
d = m[0][0] * cofac; \
COFACTOR_4X4_IJ (cofac, m, 0, 1); \
d += m[0][1] * cofac; \
COFACTOR_4X4_IJ (cofac, m, 0, 2); \
d += m[0][2] * cofac; \
COFACTOR_4X4_IJ (cofac, m, 0, 3); \
d += m[0][3] * cofac; \
}
/* ========================================================== */
/* determinant of matrix
*
* Computes determinant of matrix m, returning d
*/
/* ========================================================== */
/* compute adjoint of matrix and scale
*
* Computes adjoint of matrix m, scales it by s, returning a
*/
#define SCALE_ADJOINT_3X3(a,s,m) \
{ \
a[0][0] = (s) * (m[1][1] * m[2][2] - m[1][2] * m[2][1]); \
a[1][0] = (s) * (m[1][2] * m[2][0] - m[1][0] * m[2][2]); \
a[2][0] = (s) * (m[1][0] * m[2][1] - m[1][1] * m[2][0]); \
\
a[0][1] = (s) * (m[0][2] * m[2][1] - m[0][1] * m[2][2]); \
a[1][1] = (s) * (m[0][0] * m[2][2] - m[0][2] * m[2][0]); \
a[2][1] = (s) * (m[0][1] * m[2][0] - m[0][0] * m[2][1]); \
\
a[0][2] = (s) * (m[0][1] * m[1][2] - m[0][2] * m[1][1]); \
a[1][2] = (s) * (m[0][2] * m[1][0] - m[0][0] * m[1][2]); \
a[2][2] = (s) * (m[0][0] * m[1][1] - m[0][1] * m[1][0]); \
}
/* ========================================================== */
/* compute adjoint of matrix and scale
*
* Computes adjoint of matrix m, scales it by s, returning a
*/
#define SCALE_ADJOINT_4X4(a,s,m) \
{ \
int i,j; \
\
for (i=0; i<4; i++) { \
for (j=0; j<4; j++) { \
COFACTOR_4X4_IJ (a[j][i], m, i, j); \
a[j][i] *= s; \
} \
} \
}
#define DETERMINANT_3X3(d,m) \
{ \
d = m[0][0] * (m[1][1]*m[2][2] - m[1][2] * m[2][1]); \
d -= m[0][1] * (m[1][0]*m[2][2] - m[1][2] * m[2][0]); \
d += m[0][2] * (m[1][0]*m[2][1] - m[1][1] * m[2][0]); \
}
/* ========================================================== */
/* inverse of matrix
*
* Compute inverse of matrix a, returning determinant m and
* inverse b
*/
#define INVERT_3X3(b,det,a) \
{ \
double tmp; \
DETERMINANT_3X3 (det, a); \
tmp = 1.0 / (det); \
SCALE_ADJOINT_3X3 (b, tmp, a); \
}
/* ========================================================== */
/* inverse of matrix
*
* Compute inverse of matrix a, returning determinant m and
* inverse b
*/
#define INVERT_4X4(b,det,a) \
{ \
double tmp; \
DETERMINANT_4X4 (det, a); \
tmp = 1.0 / (det); \
SCALE_ADJOINT_4X4 (b, tmp, a); \
/* ========================================================== */
/* i,j,th cofactor of a 4x4 matrix
*
*/
#define COFACTOR_4X4_IJ(fac,m,i,j) \
{ \
int ii[4], jj[4], k; \
\
/* compute which row, columnt to skip */ \
for (k=0; k<i; k++) ii[k] = k; \
for (k=i; k<3; k++) ii[k] = k+1; \
for (k=0; k<j; k++) jj[k] = k; \
for (k=j; k<3; k++) jj[k] = k+1; \
\
(fac) = m[ii[0]][jj[0]] * (m[ii[1]][jj[1]]*m[ii[2]][jj[2]] \
- m[ii[1]][jj[2]]*m[ii[2]][jj[1]]); \
(fac) -= m[ii[0]][jj[1]] * (m[ii[1]][jj[0]]*m[ii[2]][jj[2]] \
- m[ii[1]][jj[2]]*m[ii[2]][jj[0]]);\
(fac) += m[ii[0]][jj[2]] * (m[ii[1]][jj[0]]*m[ii[2]][jj[1]] \
- m[ii[1]][jj[1]]*m[ii[2]][jj[0]]);\
\
/* compute sign */ \
k = i+j; \
if ( k != (k/2)*2) { \
(fac) = -(fac); \
} \
}
/* ========================================================== */
/* determinant of matrix
*
* Computes determinant of matrix m, returning d
*/
#define DETERMINANT_4X4(d,m) \
{ \
double cofac; \
COFACTOR_4X4_IJ (cofac, m, 0, 0); \
d = m[0][0] * cofac; \
COFACTOR_4X4_IJ (cofac, m, 0, 1); \
d += m[0][1] * cofac; \
COFACTOR_4X4_IJ (cofac, m, 0, 2); \
d += m[0][2] * cofac; \
COFACTOR_4X4_IJ (cofac, m, 0, 3); \
d += m[0][3] * cofac; \
}
/* ========================================================== */
/* compute adjoint of matrix and scale
*
* Computes adjoint of matrix m, scales it by s, returning a
*/
#define SCALE_ADJOINT_3X3(a,s,m) \
{ \
a[0][0] = (s) * (m[1][1] * m[2][2] - m[1][2] * m[2][1]); \
a[1][0] = (s) * (m[1][2] * m[2][0] - m[1][0] * m[2][2]); \
a[2][0] = (s) * (m[1][0] * m[2][1] - m[1][1] * m[2][0]); \
\
a[0][1] = (s) * (m[0][2] * m[2][1] - m[0][1] * m[2][2]); \
a[1][1] = (s) * (m[0][0] * m[2][2] - m[0][2] * m[2][0]); \
a[2][1] = (s) * (m[0][1] * m[2][0] - m[0][0] * m[2][1]); \
\
a[0][2] = (s) * (m[0][1] * m[1][2] - m[0][2] * m[1][1]); \
a[1][2] = (s) * (m[0][2] * m[1][0] - m[0][0] * m[1][2]); \
a[2][2] = (s) * (m[0][0] * m[1][1] - m[0][1] * m[1][0]); \
}
/* ========================================================== */
/* compute adjoint of matrix and scale
*
* Computes adjoint of matrix m, scales it by s, returning a
*/
#define SCALE_ADJOINT_4X4(a,s,m) \
{ \
int i,j; \
\
for (i=0; i<4; i++) { \
for (j=0; j<4; j++) { \
COFACTOR_4X4_IJ (a[j][i], m, i, j); \
a[j][i] *= s; \
} \
} \
}
/* ========================================================== */
/* inverse of matrix
*
* Compute inverse of matrix a, returning determinant m and
* inverse b
*/
#define INVERT_3X3(b,det,a) \
{ \
double tmp; \
DETERMINANT_3X3 (det, a); \
tmp = 1.0 / (det); \
SCALE_ADJOINT_3X3 (b, tmp, a); \
}
/* ========================================================== */
/* inverse of matrix
*
* Compute inverse of matrix a, returning determinant m and
* inverse b
*/
#define INVERT_4X4(b,det,a) \
{ \
double tmp; \
DETERMINANT_4X4 (det, a); \
tmp = 1.0 / (det); \
SCALE_ADJOINT_4X4 (b, tmp, a); \
}
# endif // !POLYMER_C

View file

@ -380,7 +380,7 @@ _prprogrambit prprogrambits[PR_BIT_COUNT] = {
"\n",
},
{
1 << PR_BIT_SHADOW_MAP,
1 << PR_BIT_PROJECTION_MAP,
// vert_def
"uniform mat4 shadowProjMatrix;\n"
"\n",
@ -388,6 +388,17 @@ _prprogrambit prprogrambits[PR_BIT_COUNT] = {
" gl_TexCoord[2] = shadowProjMatrix * curVertex;\n"
"\n",
// frag_def
"",
// frag_prog
"",
},
{
1 << PR_BIT_SHADOW_MAP,
// vert_def
"",
// vert_prog
"",
// frag_def
"uniform sampler2DShadow shadowMap;\n"
"\n",
// frag_prog
@ -3785,7 +3796,7 @@ static void polymer_getscratchmaterial(_prmaterial* material)
material->mirrormap = 0;
// PR_BIT_GLOW_MAP
material->glowmap = 0;
// PR_BIT_SHADOW_MAP
// PR_BIT_PROJECTION_MAP
material->mdspritespace = GL_FALSE;
}
@ -3934,9 +3945,12 @@ static int32_t polymer_bindmaterial(_prmaterial material, int16_t* lights,
// PR_BIT_SHADOW_MAP
if (prlights[lights[curlight]].rtindex != -1) {
programbits |= prprogrambits[PR_BIT_SHADOW_MAP].bit;
// PR_BIT_LIGHT_MAP
if (prlights[lights[curlight]].lightmap)
programbits |= prprogrambits[PR_BIT_LIGHT_MAP].bit;
programbits |= prprogrambits[PR_BIT_PROJECTION_MAP].bit;
}
// PR_BIT_LIGHT_MAP
if (prlights[lights[curlight]].lightmap) {
programbits |= prprogrambits[PR_BIT_LIGHT_MAP].bit;
programbits |= prprogrambits[PR_BIT_PROJECTION_MAP].bit;
}
}
}
@ -4163,8 +4177,8 @@ static int32_t polymer_bindmaterial(_prmaterial material, int16_t* lights,
bglUniform3fvARB(prprograms[programbits].uniform_spotDir, 1, dir);
bglUniform2fvARB(prprograms[programbits].uniform_spotRadius, 1, indir);
// PR_BIT_SHADOW_MAP
if (programbits & prprogrambits[PR_BIT_SHADOW_MAP].bit)
// PR_BIT_PROJECTION_MAP
if (programbits & prprogrambits[PR_BIT_PROJECTION_MAP].bit)
{
GLfloat matrix[16];
@ -4178,13 +4192,18 @@ static int32_t polymer_bindmaterial(_prmaterial material, int16_t* lights,
bglLoadIdentity();
bglMatrixMode(GL_MODELVIEW);
bglActiveTextureARB(texunit + GL_TEXTURE0_ARB);
bglBindTexture(prrts[prlights[lights[curlight]].rtindex].target, prrts[prlights[lights[curlight]].rtindex].z);
bglUniform1iARB(prprograms[programbits].uniform_shadowMap, texunit);
bglUniformMatrix4fvARB(prprograms[programbits].uniform_shadowProjMatrix, 1, GL_FALSE, matrix);
texunit++;
// PR_BIT_SHADOW_MAP
if (programbits & prprogrambits[PR_BIT_SHADOW_MAP].bit)
{
bglActiveTextureARB(texunit + GL_TEXTURE0_ARB);
bglBindTexture(prrts[prlights[lights[curlight]].rtindex].target, prrts[prlights[lights[curlight]].rtindex].z);
bglUniform1iARB(prprograms[programbits].uniform_shadowMap, texunit);
texunit++;
}
// PR_BIT_LIGHT_MAP
if (programbits & prprogrambits[PR_BIT_LIGHT_MAP].bit)
@ -4388,11 +4407,16 @@ static void polymer_compileprogram(int32_t programbits)
prprograms[programbits].uniform_glowMap = bglGetUniformLocationARB(program, "glowMap");
}
// PR_BIT_PROJECTION_MAP
if (programbits & prprogrambits[PR_BIT_PROJECTION_MAP].bit)
{
prprograms[programbits].uniform_shadowProjMatrix = bglGetUniformLocationARB(program, "shadowProjMatrix");
}
// PR_BIT_SHADOW_MAP
if (programbits & prprogrambits[PR_BIT_SHADOW_MAP].bit)
{
prprograms[programbits].uniform_shadowMap = bglGetUniformLocationARB(program, "shadowMap");
prprograms[programbits].uniform_shadowProjMatrix = bglGetUniformLocationARB(program, "shadowProjMatrix");
}
// PR_BIT_LIGHT_MAP