Fix that sprite light wasn't calculated using the center of the sprite

This commit is contained in:
Magnus Norddahl 2017-02-23 09:27:00 +01:00
parent 4121a1e174
commit 0702e4523d

View file

@ -59,6 +59,7 @@
#include "gl/dynlights/gl_dynlight.h" #include "gl/dynlights/gl_dynlight.h"
EXTERN_CVAR(Bool, r_fullbrightignoresectorcolor) EXTERN_CVAR(Bool, r_fullbrightignoresectorcolor)
EXTERN_CVAR(Bool, gl_light_sprites)
namespace swrenderer namespace swrenderer
{ {
@ -227,7 +228,7 @@ namespace swrenderer
bool fullbright = !vis->foggy && ((renderflags & RF_FULLBRIGHT) || (thing->flags5 & MF5_BRIGHT)); bool fullbright = !vis->foggy && ((renderflags & RF_FULLBRIGHT) || (thing->flags5 & MF5_BRIGHT));
bool fadeToBlack = (vis->RenderStyle.Flags & STYLEF_FadeToBlack) != 0; bool fadeToBlack = (vis->RenderStyle.Flags & STYLEF_FadeToBlack) != 0;
if (r_dynlights) if (r_dynlights && gl_light_sprites)
{ {
float lit_red = 0; float lit_red = 0;
float lit_green = 0; float lit_green = 0;
@ -238,9 +239,9 @@ namespace swrenderer
ADynamicLight *light = node->lightsource; ADynamicLight *light = node->lightsource;
if (light->visibletoplayer && !(light->flags2&MF2_DORMANT) && (!(light->flags4&MF4_DONTLIGHTSELF) || light->target != thing)) if (light->visibletoplayer && !(light->flags2&MF2_DORMANT) && (!(light->flags4&MF4_DONTLIGHTSELF) || light->target != thing))
{ {
float lx = (float)(light->X() - pos.X); float lx = (float)(light->X() - thing->X());
float ly = (float)(light->Y() - pos.Y); float ly = (float)(light->Y() - thing->Y());
float lz = (float)(light->Z() - pos.Z); float lz = (float)(light->Z() - thing->Center());
float LdotL = lx * lx + ly * ly + lz * lz; float LdotL = lx * lx + ly * ly + lz * lz;
float radius = node->lightsource->GetRadius(); float radius = node->lightsource->GetRadius();
if (radius * radius >= LdotL) if (radius * radius >= LdotL)