light: only shadow-casting faces generate bounce lights

This commit is contained in:
Eric Wasylishen 2016-05-20 13:34:30 -06:00
parent 11ea23f6f2
commit e290d844bf
3 changed files with 20 additions and 15 deletions

View File

@ -55,7 +55,8 @@ typedef struct {
typedef struct {
const dmodel_t *model;
qboolean shadowself;
qboolean shadowself; /* is it shadow casting only on itself? */
qboolean shadow; /* is it shadow casting? */
lightsample_t minlight;
char minlight_exclude[16]; /* texture name to exclude from minlight */
float lightmapscale;

View File

@ -295,6 +295,7 @@ FindModelInfo(const bsp2_t *bsp, const char *lmscaleoverride)
if (i != lightmapscale)
logprint("WARNING: lightmap scale is not a power of 2\n");
modelinfo[0].lightmapscale = lightmapscale;
modelinfo[0].shadow = true; /* world always casts shadows */
for (i = 1, info = modelinfo + 1; i < bsp->nummodels; i++, info++) {
info->model = &bsp->dmodels[i];
@ -311,6 +312,7 @@ FindModelInfo(const bsp2_t *bsp, const char *lmscaleoverride)
shadow = atoi(ValueForKey(entity, "_shadow"));
if (shadow) {
shadowmodels[numshadowmodels++] = info;
info->shadow = true;
} else {
shadow = atoi(ValueForKey(entity, "_shadowself"));
if (shadow) {

View File

@ -2162,22 +2162,24 @@ LightFace(bsp2_dface_t *face, facesup_t *facesup, const modelinfo_t *modelinfo,
}
VectorScale(lightsurf->texturecolor, 1.0f/lightsurf->numpoints, lightsurf->texturecolor);
// make bounce light
if (bounce) {
vec3_t gray = {127, 127, 127};
// lerp between gray and the texture color according to `bouncecolorscale`
vec3_t blendedcolor = {0, 0, 0};
VectorMA(blendedcolor, bouncecolorscale, lightsurf->texturecolor, blendedcolor);
VectorMA(blendedcolor, 1-bouncecolorscale, gray, blendedcolor);
vec3_t emitcolor;
for (int k=0; k<3; k++) {
emitcolor[k] = (lightsurf->radiosity[k] / 255.0f) * (blendedcolor[k] / 255.0f);
// make bounce light, only if this face is shadow casting
if (modelinfo->shadow) {
vec3_t gray = {127, 127, 127};
// lerp between gray and the texture color according to `bouncecolorscale`
vec3_t blendedcolor = {0, 0, 0};
VectorMA(blendedcolor, bouncecolorscale, lightsurf->texturecolor, blendedcolor);
VectorMA(blendedcolor, 1-bouncecolorscale, gray, blendedcolor);
vec3_t emitcolor;
for (int k=0; k<3; k++) {
emitcolor[k] = (lightsurf->radiosity[k] / 255.0f) * (blendedcolor[k] / 255.0f);
}
winding_t *w = WindingFromFace(bsp, face);
AddBounceLight(lightsurf->midpoint, emitcolor, lightsurf->plane.normal, WindingArea(w), bsp);
free(w);
}
winding_t *w = WindingFromFace(bsp, face);
AddBounceLight(lightsurf->midpoint, emitcolor, lightsurf->plane.normal, WindingArea(w), bsp);
free(w);
} else {
WriteLightmaps(face, facesup, lightsurf, lightmaps);
}