From: vortex Date: Sat, 30 Oct 2010 23:10:35 +0000 (+0000) Subject: R_CompleteLightPoint: more correct sampling X-Git-Tag: xonotic-v0.1.0preview~82 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=09e094b9e84fbb8befb8bdeeef5c5365a65b30d7;p=xonotic%2Fdarkplaces.git R_CompleteLightPoint: more correct sampling git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@10574 d7cf8633-e32d-0410-b094-e92efae38249 ::stable-branch::merge=57b67e4e7fa223b3fb7d76fe5702ae636aa8fc0f --- diff --git a/r_shadow.c b/r_shadow.c index cb68955b..654cfa91 100644 --- a/r_shadow.c +++ b/r_shadow.c @@ -6023,7 +6023,7 @@ void R_CompleteLightPoint(vec3_t ambientcolor, vec3_t diffusecolor, vec3_t diffu if (dynamic) { int i, numlights, flag; - float f, v[3]; + float f, relativepoint[3], dist, dist2, lightradius2; rtlight_t *light; dlight_t *dlight; @@ -6040,10 +6040,17 @@ void R_CompleteLightPoint(vec3_t ambientcolor, vec3_t diffusecolor, vec3_t diffu light = &dlight->rtlight; if (!(light->flags & flag)) continue; - Matrix4x4_Transform(&light->matrix_worldtolight, p, v); - f = 1 - VectorLength2(v); + // sample + lightradius2 = light->radius * light->radius; + VectorSubtract(light->shadoworigin, p, relativepoint); + dist2 = VectorLength2(relativepoint); + if (dist2 >= lightradius2) + continue; + dist = sqrt(dist2) / light->radius; + f = dist < 1 ? (r_shadow_lightintensityscale.value * ((1.0f - dist) * r_shadow_lightattenuationlinearscale.value / (r_shadow_lightattenuationdividebias.value + dist*dist))) : 0; if (f <= 0) continue; + // todo: add to both ambient and diffuse if (!light->shadow || CL_TraceLine(p, light->shadoworigin, MOVE_NOMONSTERS, NULL, SUPERCONTENTS_SOLID, true, false, NULL, false).fraction == 1) VectorMA(ambientcolor, f, light->currentcolor, ambientcolor); } @@ -6053,10 +6060,17 @@ void R_CompleteLightPoint(vec3_t ambientcolor, vec3_t diffusecolor, vec3_t diffu for (i = 0;i < r_refdef.scene.numlights;i++) { light = r_refdef.scene.lights[i]; - Matrix4x4_Transform(&light->matrix_worldtolight, p, v); - f = (1 - VectorLength2(v)) * r_refdef.scene.rtlightstylevalue[light->style]; + // sample + lightradius2 = light->radius * light->radius; + VectorSubtract(light->shadoworigin, p, relativepoint); + dist2 = VectorLength2(relativepoint); + if (dist2 >= lightradius2) + continue; + dist = sqrt(dist2) / light->radius; + f = dist < 1 ? (r_shadow_lightintensityscale.value * ((1.0f - dist) * r_shadow_lightattenuationlinearscale.value / (r_shadow_lightattenuationdividebias.value + dist*dist))) : 0; if (f <= 0) continue; + // todo: add to both ambient and diffuse if (!light->shadow || CL_TraceLine(p, light->shadoworigin, MOVE_NOMONSTERS, NULL, SUPERCONTENTS_SOLID, true, false, NULL, false).fraction == 1) VectorMA(ambientcolor, f, light->color, ambientcolor); }