- reinstated some texturing-based dynamic light code. Not active yet and not tested yet.

This commit is contained in:
Christoph Oelckers 2016-04-28 00:58:44 +02:00
parent ee7a4daa8c
commit d4806f82ca
6 changed files with 214 additions and 98 deletions

View file

@ -140,95 +140,3 @@ bool gl_GetLight(int group, Plane & p, ADynamicLight * light, bool checkside, bo
return true;
}
//==========================================================================
//
// Sets up the parameters to render one dynamic light onto one plane
//
//==========================================================================
bool gl_SetupLight(int group, Plane & p, ADynamicLight * light, Vector & nearPt, Vector & up, Vector & right,
float & scale, int desaturation, bool checkside, bool forceadditive)
{
Vector fn, pos;
DVector3 lpos = light->PosRelative(group);
float dist = fabsf(p.DistToPoint(lpos.X, lpos.Z, lpos.Y));
float radius = (light->GetRadius() * gl_lights_size);
if (radius <= 0.f) return false;
if (dist > radius) return false;
if (checkside && gl_lights_checkside && p.PointOnSide(lpos.X, lpos.Z, lpos.Y))
{
return false;
}
if (light->owned && light->target != NULL && !light->target->IsVisibleToPlayer())
{
return false;
}
scale = 1.0f / ((2.f * radius) - dist);
// project light position onto plane (find closest point on plane)
pos.Set(lpos.X, lpos.Z, lpos.Y);
fn = p.Normal();
fn.GetRightUp(right, up);
#ifdef _MSC_VER
nearPt = pos + fn * dist;
#else
Vector tmpVec = fn * dist;
nearPt = pos + tmpVec;
#endif
float cs = 1.0f - (dist / radius);
if (gl_lights_additive || light->flags4&MF4_ADDITIVE || forceadditive) cs *= 0.2f; // otherwise the light gets too strong.
float r = light->GetRed() / 255.0f * cs * gl_lights_intensity;
float g = light->GetGreen() / 255.0f * cs * gl_lights_intensity;
float b = light->GetBlue() / 255.0f * cs * gl_lights_intensity;
if (light->IsSubtractive())
{
Vector v;
gl_RenderState.BlendEquation(GL_FUNC_REVERSE_SUBTRACT);
v.Set(r, g, b);
r = v.Length() - r;
g = v.Length() - g;
b = v.Length() - b;
}
else
{
gl_RenderState.BlendEquation(GL_FUNC_ADD);
}
if (desaturation > 0 && gl.glslversion > 0) // no-shader excluded because no desaturated textures.
{
float gray = (r * 77 + g * 143 + b * 37) / 257;
r = (r*(32 - desaturation) + gray*desaturation) / 32;
g = (g*(32 - desaturation) + gray*desaturation) / 32;
b = (b*(32 - desaturation) + gray*desaturation) / 32;
}
glColor3f(r, g, b);
return true;
}
//==========================================================================
//
//
//
//==========================================================================
bool gl_SetupLightTexture()
{
if (GLRenderer->gllight == NULL) return false;
FMaterial * pat = FMaterial::ValidateTexture(GLRenderer->gllight, true);
pat->Bind(CLAMP_XY, 0);
return true;
}