polymer: add support for negative lights

And hook them up to cstat 128 (half-submerged, 'c' in mapster).

git-svn-id: https://svn.eduke32.com/eduke32@3092 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
Plagman 2012-10-21 04:52:43 +00:00
parent 9d10b0b087
commit e726484ccc
7 changed files with 43 additions and 5 deletions

View file

@ -56,6 +56,7 @@ extern void (APIENTRY * bglClear)( GLbitfield mask );
extern void (APIENTRY * bglColorMask)( GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha ); extern void (APIENTRY * bglColorMask)( GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha );
extern void (APIENTRY * bglAlphaFunc)( GLenum func, GLclampf ref ); extern void (APIENTRY * bglAlphaFunc)( GLenum func, GLclampf ref );
extern void (APIENTRY * bglBlendFunc)( GLenum sfactor, GLenum dfactor ); extern void (APIENTRY * bglBlendFunc)( GLenum sfactor, GLenum dfactor );
extern void (APIENTRY * bglBlendEquation)( GLenum mode );
extern void (APIENTRY * bglCullFace)( GLenum mode ); extern void (APIENTRY * bglCullFace)( GLenum mode );
extern void (APIENTRY * bglFrontFace)( GLenum mode ); extern void (APIENTRY * bglFrontFace)( GLenum mode );
extern void (APIENTRY * bglPolygonOffset)( GLfloat factor, GLfloat units ); extern void (APIENTRY * bglPolygonOffset)( GLfloat factor, GLfloat units );

View file

@ -20,6 +20,7 @@ typedef struct s_prlight {
int16_t tilenum; int16_t tilenum;
struct { struct {
int32_t emitshadow : 1; int32_t emitshadow : 1;
int32_t negative : 1;
} publicflags; } publicflags;
// internal members // internal members
float proj[16]; float proj[16];

View file

@ -9980,6 +9980,9 @@ int32_t loadmaphack(const char *filename)
scriptfile_getnumber(script, &value); scriptfile_getnumber(script, &value);
light.tilenum = value; light.tilenum = value;
light.publicflags.emitshadow = 1;
light.publicflags.negative = 0;
if (rendmode == 4) if (rendmode == 4)
{ {
if (maphacklightcnt == PR_MAXLIGHTS) if (maphacklightcnt == PR_MAXLIGHTS)

View file

@ -16,6 +16,7 @@ void (APIENTRY *bglClear)(GLbitfield mask);
void (APIENTRY *bglColorMask)(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha); void (APIENTRY *bglColorMask)(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha);
void (APIENTRY *bglAlphaFunc)(GLenum func, GLclampf ref); void (APIENTRY *bglAlphaFunc)(GLenum func, GLclampf ref);
void (APIENTRY *bglBlendFunc)(GLenum sfactor, GLenum dfactor); void (APIENTRY *bglBlendFunc)(GLenum sfactor, GLenum dfactor);
void (APIENTRY *bglBlendEquation)(GLenum mode);
void (APIENTRY *bglCullFace)(GLenum mode); void (APIENTRY *bglCullFace)(GLenum mode);
void (APIENTRY *bglFrontFace)(GLenum mode); void (APIENTRY *bglFrontFace)(GLenum mode);
void (APIENTRY *bglPolygonOffset)(GLfloat factor, GLfloat units); void (APIENTRY *bglPolygonOffset)(GLfloat factor, GLfloat units);
@ -495,6 +496,8 @@ int32_t loadglextensions(void)
if (!hGLDLL) return 0; if (!hGLDLL) return 0;
#endif #endif
bglBlendEquation = GETPROCEXTSOFT("glBlendEquation");
bglTexImage3D = GETPROCEXTSOFT("glTexImage3D"); bglTexImage3D = GETPROCEXTSOFT("glTexImage3D");
bglCompressedTexImage2DARB = GETPROCEXTSOFT("glCompressedTexImage2DARB"); bglCompressedTexImage2DARB = GETPROCEXTSOFT("glCompressedTexImage2DARB");
bglGetCompressedTexImageARB = GETPROCEXTSOFT("glGetCompressedTexImageARB"); bglGetCompressedTexImageARB = GETPROCEXTSOFT("glGetCompressedTexImageARB");
@ -660,6 +663,7 @@ int32_t unloadgldriver(void)
bglColorMask = NULL; bglColorMask = NULL;
bglAlphaFunc = NULL; bglAlphaFunc = NULL;
bglBlendFunc = NULL; bglBlendFunc = NULL;
bglBlendEquation = NULL;
bglCullFace = NULL; bglCullFace = NULL;
bglFrontFace = NULL; bglFrontFace = NULL;
bglPolygonOffset = NULL; bglPolygonOffset = NULL;

View file

@ -4654,11 +4654,13 @@ static int32_t polymer_bindmaterial(_prmaterial material, int16_t* lights,
// PR_BIT_LIGHTING_PASS // PR_BIT_LIGHTING_PASS
if (programbits & prprogrambits[PR_BIT_LIGHTING_PASS].bit) if (programbits & prprogrambits[PR_BIT_LIGHTING_PASS].bit)
{ {
// Careful with that, it works only if we respect the wrapping order bglPushAttrib(GL_COLOR_BUFFER_BIT);
// or make sure GL_BLEND is the only ENABLE we mess with here. bglEnable(GL_BLEND);
bglPushAttrib(GL_ENABLE_BIT);
bglEnable(GL_BLEND);
bglBlendFunc(GL_ONE, GL_ONE); bglBlendFunc(GL_ONE, GL_ONE);
if (prlights[lights[curlight]].publicflags.negative) {
bglBlendEquation(GL_FUNC_REVERSE_SUBTRACT);
}
} }
// PR_BIT_NORMAL_MAP // PR_BIT_NORMAL_MAP
@ -4900,6 +4902,13 @@ static int32_t polymer_bindmaterial(_prmaterial material, int16_t* lights,
color[1] = prlights[lights[curlight]].color[1] / 255.0f; color[1] = prlights[lights[curlight]].color[1] / 255.0f;
color[2] = prlights[lights[curlight]].color[2] / 255.0f; color[2] = prlights[lights[curlight]].color[2] / 255.0f;
// If this isn't a lighting-only pass, just negate the components
if (!curlight && prlights[lights[curlight]].publicflags.negative) {
color[0] = -color[0];
color[1] = -color[1];
color[2] = -color[2];
}
bglLightfv(GL_LIGHT0, GL_AMBIENT, pos); bglLightfv(GL_LIGHT0, GL_AMBIENT, pos);
bglLightfv(GL_LIGHT0, GL_DIFFUSE, color); bglLightfv(GL_LIGHT0, GL_DIFFUSE, color);
if (material.mdspritespace == GL_TRUE) { if (material.mdspritespace == GL_TRUE) {
@ -4933,7 +4942,6 @@ static void polymer_unbindmaterial(int32_t programbits)
if (programbits & prprogrambits[PR_BIT_LIGHTING_PASS].bit) if (programbits & prprogrambits[PR_BIT_LIGHTING_PASS].bit)
{ {
bglPopAttrib(); bglPopAttrib();
bglBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
} }
// PR_BIT_NORMAL_MAP // PR_BIT_NORMAL_MAP

View file

@ -740,6 +740,9 @@ void G_AddGameLight(int32_t radius, int32_t srcsprite, int32_t zoffset, int32_t
mylight.priority = priority; mylight.priority = priority;
mylight.tilenum = 0; mylight.tilenum = 0;
mylight.publicflags.emitshadow = 1;
mylight.publicflags.negative = 0;
actor[srcsprite].lightId = polymer_addlight(&mylight); actor[srcsprite].lightId = polymer_addlight(&mylight);
if (actor[srcsprite].lightId >= 0) if (actor[srcsprite].lightId >= 0)
actor[srcsprite].lightptr = &prlights[actor[srcsprite].lightId]; actor[srcsprite].lightptr = &prlights[actor[srcsprite].lightId];
@ -7752,6 +7755,7 @@ static void G_DoEffectorLights(void) // STATNUM 14
mylight.maxshade = sprite[i].yoffset; mylight.maxshade = sprite[i].yoffset;
mylight.tilenum = 0; mylight.tilenum = 0;
mylight.publicflags.emitshadow = 0; mylight.publicflags.emitshadow = 0;
mylight.publicflags.negative = !!(CS & 128);
if (CS & 2) if (CS & 2)
{ {
@ -7788,6 +7792,9 @@ static void G_DoEffectorLights(void) // STATNUM 14
actor[i].lightptr->color[1] = sprite[i].yvel; actor[i].lightptr->color[1] = sprite[i].yvel;
actor[i].lightptr->color[2] = sprite[i].zvel; actor[i].lightptr->color[2] = sprite[i].zvel;
} }
if (!!(CS & 128) != actor[i].lightptr->publicflags.negative) {
actor[i].lightptr->publicflags.negative = !!(CS & 128);
}
} }
break; break;
} }
@ -7816,6 +7823,7 @@ static void G_DoEffectorLights(void) // STATNUM 14
mylight.maxshade = sprite[i].yoffset; mylight.maxshade = sprite[i].yoffset;
mylight.tilenum = actor[i].picnum; mylight.tilenum = actor[i].picnum;
mylight.publicflags.emitshadow = !(CS & 64); mylight.publicflags.emitshadow = !(CS & 64);
mylight.publicflags.negative = !!(CS & 128);
if (CS & 2) if (CS & 2)
{ {
@ -7877,6 +7885,9 @@ static void G_DoEffectorLights(void) // STATNUM 14
if (!(CS & 64) != actor[i].lightptr->publicflags.emitshadow) { if (!(CS & 64) != actor[i].lightptr->publicflags.emitshadow) {
actor[i].lightptr->publicflags.emitshadow = !(CS & 64); actor[i].lightptr->publicflags.emitshadow = !(CS & 64);
} }
if (!!(CS & 128) != actor[i].lightptr->publicflags.negative) {
actor[i].lightptr->publicflags.negative = !!(CS & 128);
}
actor[i].lightptr->tilenum = actor[i].picnum; actor[i].lightptr->tilenum = actor[i].picnum;
} }

View file

@ -286,6 +286,8 @@ static void addprlight_common1(_prlight *mylightptr, int32_t i)
else else
mylightptr->priority = PR_LIGHT_PRIO_MAX; mylightptr->priority = PR_LIGHT_PRIO_MAX;
mylightptr->publicflags.negative = !!(CS & 128);
spritelightid[i] = polymer_addlight(mylightptr); spritelightid[i] = polymer_addlight(mylightptr);
if (spritelightid[i] >= 0) if (spritelightid[i] >= 0)
spritelightptr[i] = &prlights[spritelightid[i]]; spritelightptr[i] = &prlights[spritelightid[i]];
@ -10697,6 +10699,10 @@ void ExtPreCheckKeys(void) // just before drawrooms
} }
if (check_prlight_colors(i)) if (check_prlight_colors(i))
copy_prlight_colors(spritelightptr[i], i); copy_prlight_colors(spritelightptr[i], i);
if (!!(CS & 128) != spritelightptr[i]->publicflags.negative)
{
spritelightptr[i]->publicflags.negative = !!(CS & 128);
}
} }
} }
} }
@ -10751,6 +10757,10 @@ void ExtPreCheckKeys(void) // just before drawrooms
{ {
spritelightptr[i]->publicflags.emitshadow = !(CS & 64); spritelightptr[i]->publicflags.emitshadow = !(CS & 64);
} }
if (!!(CS & 128) != spritelightptr[i]->publicflags.negative)
{
spritelightptr[i]->publicflags.negative = !!(CS & 128);
}
spritelightptr[i]->tilenum = OW; spritelightptr[i]->tilenum = OW;
} }
} }