mirror of
https://github.com/ZDoom/qzdoom.git
synced 2024-11-27 22:42:57 +00:00
Add menu option to enable dynamic lights (independent of the OpenGL setting so that you can have it on in OpenGL and off in Software)
This commit is contained in:
parent
06bc911828
commit
2bb2395569
6 changed files with 109 additions and 87 deletions
|
@ -53,6 +53,8 @@
|
|||
#include "r_draw_pal.h"
|
||||
#include "r_thread.h"
|
||||
|
||||
CVAR(Bool, r_dynlights, 1, CVAR_ARCHIVE | CVAR_GLOBALCONFIG);
|
||||
|
||||
namespace swrenderer
|
||||
{
|
||||
// Needed by R_DrawFogBoundary (which probably shouldn't be part of this file)
|
||||
|
|
|
@ -16,6 +16,7 @@ EXTERN_CVAR(Int, r_drawfuzz);
|
|||
EXTERN_CVAR(Bool, r_drawtrans);
|
||||
EXTERN_CVAR(Float, transsouls);
|
||||
EXTERN_CVAR(Int, r_columnmethod);
|
||||
EXTERN_CVAR(Bool, r_dynlights);
|
||||
|
||||
namespace swrenderer
|
||||
{
|
||||
|
|
|
@ -258,54 +258,61 @@ void R_MapPlane (int y, int x1)
|
|||
|
||||
if (r_swtruecolor)
|
||||
{
|
||||
// Find row position in view space
|
||||
float zspan = planeheight / (fabs(y + 0.5 - CenterY) / InvZtoScale);
|
||||
dc_viewpos.X = (float)((x1 + 0.5 - CenterX) / CenterX * zspan);
|
||||
dc_viewpos.Y = zspan;
|
||||
dc_viewpos.Z = (float)((CenterY - y - 0.5) / InvZtoScale * zspan);
|
||||
dc_viewpos_step.X = (float)(zspan / CenterX);
|
||||
|
||||
static TriLight lightbuffer[64 * 1024];
|
||||
static int nextlightindex = 0;
|
||||
|
||||
// Setup lights for column
|
||||
dc_num_lights = 0;
|
||||
dc_lights = lightbuffer + nextlightindex;
|
||||
visplane_light *cur_node = ds_light_list;
|
||||
while (cur_node && nextlightindex < 64 * 1024)
|
||||
if (r_dynlights)
|
||||
{
|
||||
double lightX = cur_node->lightsource->X() - ViewPos.X;
|
||||
double lightY = cur_node->lightsource->Y() - ViewPos.Y;
|
||||
double lightZ = cur_node->lightsource->Z() - ViewPos.Z;
|
||||
// Find row position in view space
|
||||
float zspan = planeheight / (fabs(y + 0.5 - CenterY) / InvZtoScale);
|
||||
dc_viewpos.X = (float)((x1 + 0.5 - CenterX) / CenterX * zspan);
|
||||
dc_viewpos.Y = zspan;
|
||||
dc_viewpos.Z = (float)((CenterY - y - 0.5) / InvZtoScale * zspan);
|
||||
dc_viewpos_step.X = (float)(zspan / CenterX);
|
||||
|
||||
float lx = (float)(lightX * ViewSin - lightY * ViewCos);
|
||||
float ly = (float)(lightX * ViewTanCos + lightY * ViewTanSin) - dc_viewpos.Y;
|
||||
float lz = (float)lightZ - dc_viewpos.Z;
|
||||
static TriLight lightbuffer[64 * 1024];
|
||||
static int nextlightindex = 0;
|
||||
|
||||
// Precalculate the constant part of the dot here so the drawer doesn't have to.
|
||||
float lconstant = ly * ly + lz * lz;
|
||||
|
||||
// Include light only if it touches this row
|
||||
float radius = cur_node->lightsource->GetRadius();
|
||||
if (radius * radius >= lconstant)
|
||||
// Setup lights for column
|
||||
dc_num_lights = 0;
|
||||
dc_lights = lightbuffer + nextlightindex;
|
||||
visplane_light *cur_node = ds_light_list;
|
||||
while (cur_node && nextlightindex < 64 * 1024)
|
||||
{
|
||||
uint32_t red = cur_node->lightsource->GetRed();
|
||||
uint32_t green = cur_node->lightsource->GetGreen();
|
||||
uint32_t blue = cur_node->lightsource->GetBlue();
|
||||
double lightX = cur_node->lightsource->X() - ViewPos.X;
|
||||
double lightY = cur_node->lightsource->Y() - ViewPos.Y;
|
||||
double lightZ = cur_node->lightsource->Z() - ViewPos.Z;
|
||||
|
||||
nextlightindex++;
|
||||
auto &light = dc_lights[dc_num_lights++];
|
||||
light.x = lx;
|
||||
light.y = lconstant;
|
||||
light.radius = 256.0f / radius;
|
||||
light.color = (red << 16) | (green << 8) | blue;
|
||||
float lx = (float)(lightX * ViewSin - lightY * ViewCos);
|
||||
float ly = (float)(lightX * ViewTanCos + lightY * ViewTanSin) - dc_viewpos.Y;
|
||||
float lz = (float)lightZ - dc_viewpos.Z;
|
||||
|
||||
// Precalculate the constant part of the dot here so the drawer doesn't have to.
|
||||
float lconstant = ly * ly + lz * lz;
|
||||
|
||||
// Include light only if it touches this row
|
||||
float radius = cur_node->lightsource->GetRadius();
|
||||
if (radius * radius >= lconstant)
|
||||
{
|
||||
uint32_t red = cur_node->lightsource->GetRed();
|
||||
uint32_t green = cur_node->lightsource->GetGreen();
|
||||
uint32_t blue = cur_node->lightsource->GetBlue();
|
||||
|
||||
nextlightindex++;
|
||||
auto &light = dc_lights[dc_num_lights++];
|
||||
light.x = lx;
|
||||
light.y = lconstant;
|
||||
light.radius = 256.0f / radius;
|
||||
light.color = (red << 16) | (green << 8) | blue;
|
||||
}
|
||||
|
||||
cur_node = cur_node->next;
|
||||
}
|
||||
|
||||
cur_node = cur_node->next;
|
||||
if (nextlightindex == 64 * 1024)
|
||||
nextlightindex = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
dc_num_lights = 0;
|
||||
}
|
||||
|
||||
if (nextlightindex == 64 * 1024)
|
||||
nextlightindex = 0;
|
||||
}
|
||||
|
||||
ds_y = y;
|
||||
|
@ -348,6 +355,9 @@ namespace
|
|||
|
||||
void R_AddPlaneLights(visplane_t *plane, FLightNode *node)
|
||||
{
|
||||
if (!r_dynlights)
|
||||
return;
|
||||
|
||||
while (node)
|
||||
{
|
||||
if (!(node->lightsource->flags2&MF2_DORMANT))
|
||||
|
|
|
@ -539,61 +539,68 @@ static void Draw1Column(int x, int y1, int y2, WallSampler &sampler, void(*draw1
|
|||
{
|
||||
if (r_swtruecolor)
|
||||
{
|
||||
// Find column position in view space
|
||||
float w1 = 1.0f / WallC.sz1;
|
||||
float w2 = 1.0f / WallC.sz2;
|
||||
float t = (x - WallC.sx1 + 0.5f) / (WallC.sx2 - WallC.sx1);
|
||||
float wcol = w1 * (1.0f - t) + w2 * t;
|
||||
float zcol = 1.0f / wcol;
|
||||
dc_viewpos.X = (float)((x + 0.5 - CenterX) / CenterX * zcol);
|
||||
dc_viewpos.Y = zcol;
|
||||
dc_viewpos.Z = (float)((CenterY - y1 - 0.5) / InvZtoScale * zcol);
|
||||
dc_viewpos_step.Z = (float)(-zcol / InvZtoScale);
|
||||
|
||||
static TriLight lightbuffer[64 * 1024];
|
||||
static int nextlightindex = 0;
|
||||
|
||||
// Setup lights for column
|
||||
dc_num_lights = 0;
|
||||
dc_lights = lightbuffer + nextlightindex;
|
||||
FLightNode *cur_node = dc_light_list;
|
||||
while (cur_node && nextlightindex < 64 * 1024)
|
||||
if (r_dynlights)
|
||||
{
|
||||
if (!(cur_node->lightsource->flags2&MF2_DORMANT))
|
||||
// Find column position in view space
|
||||
float w1 = 1.0f / WallC.sz1;
|
||||
float w2 = 1.0f / WallC.sz2;
|
||||
float t = (x - WallC.sx1 + 0.5f) / (WallC.sx2 - WallC.sx1);
|
||||
float wcol = w1 * (1.0f - t) + w2 * t;
|
||||
float zcol = 1.0f / wcol;
|
||||
dc_viewpos.X = (float)((x + 0.5 - CenterX) / CenterX * zcol);
|
||||
dc_viewpos.Y = zcol;
|
||||
dc_viewpos.Z = (float)((CenterY - y1 - 0.5) / InvZtoScale * zcol);
|
||||
dc_viewpos_step.Z = (float)(-zcol / InvZtoScale);
|
||||
|
||||
static TriLight lightbuffer[64 * 1024];
|
||||
static int nextlightindex = 0;
|
||||
|
||||
// Setup lights for column
|
||||
dc_num_lights = 0;
|
||||
dc_lights = lightbuffer + nextlightindex;
|
||||
FLightNode *cur_node = dc_light_list;
|
||||
while (cur_node && nextlightindex < 64 * 1024)
|
||||
{
|
||||
double lightX = cur_node->lightsource->X() - ViewPos.X;
|
||||
double lightY = cur_node->lightsource->Y() - ViewPos.Y;
|
||||
double lightZ = cur_node->lightsource->Z() - ViewPos.Z;
|
||||
|
||||
float lx = (float)(lightX * ViewSin - lightY * ViewCos) - dc_viewpos.X;
|
||||
float ly = (float)(lightX * ViewTanCos + lightY * ViewTanSin) - dc_viewpos.Y;
|
||||
float lz = (float)lightZ;
|
||||
|
||||
// Precalculate the constant part of the dot here so the drawer doesn't have to.
|
||||
float lconstant = lx * lx + ly * ly;
|
||||
|
||||
// Include light only if it touches this column
|
||||
float radius = cur_node->lightsource->GetRadius();
|
||||
if (radius * radius >= lconstant)
|
||||
if (!(cur_node->lightsource->flags2&MF2_DORMANT))
|
||||
{
|
||||
uint32_t red = cur_node->lightsource->GetRed();
|
||||
uint32_t green = cur_node->lightsource->GetGreen();
|
||||
uint32_t blue = cur_node->lightsource->GetBlue();
|
||||
double lightX = cur_node->lightsource->X() - ViewPos.X;
|
||||
double lightY = cur_node->lightsource->Y() - ViewPos.Y;
|
||||
double lightZ = cur_node->lightsource->Z() - ViewPos.Z;
|
||||
|
||||
nextlightindex++;
|
||||
auto &light = dc_lights[dc_num_lights++];
|
||||
light.x = lconstant;
|
||||
light.z = lz;
|
||||
light.radius = 256.0f / cur_node->lightsource->GetRadius();
|
||||
light.color = (red << 16) | (green << 8) | blue;
|
||||
float lx = (float)(lightX * ViewSin - lightY * ViewCos) - dc_viewpos.X;
|
||||
float ly = (float)(lightX * ViewTanCos + lightY * ViewTanSin) - dc_viewpos.Y;
|
||||
float lz = (float)lightZ;
|
||||
|
||||
// Precalculate the constant part of the dot here so the drawer doesn't have to.
|
||||
float lconstant = lx * lx + ly * ly;
|
||||
|
||||
// Include light only if it touches this column
|
||||
float radius = cur_node->lightsource->GetRadius();
|
||||
if (radius * radius >= lconstant)
|
||||
{
|
||||
uint32_t red = cur_node->lightsource->GetRed();
|
||||
uint32_t green = cur_node->lightsource->GetGreen();
|
||||
uint32_t blue = cur_node->lightsource->GetBlue();
|
||||
|
||||
nextlightindex++;
|
||||
auto &light = dc_lights[dc_num_lights++];
|
||||
light.x = lconstant;
|
||||
light.z = lz;
|
||||
light.radius = 256.0f / cur_node->lightsource->GetRadius();
|
||||
light.color = (red << 16) | (green << 8) | blue;
|
||||
}
|
||||
}
|
||||
|
||||
cur_node = cur_node->nextLight;
|
||||
}
|
||||
|
||||
cur_node = cur_node->nextLight;
|
||||
if (nextlightindex == 64 * 1024)
|
||||
nextlightindex = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
dc_num_lights = 0;
|
||||
}
|
||||
|
||||
if (nextlightindex == 64 * 1024)
|
||||
nextlightindex = 0;
|
||||
|
||||
int count = y2 - y1;
|
||||
|
||||
|
|
|
@ -2754,4 +2754,5 @@ TCMNU_TRUECOLOR = "True color output";
|
|||
TCMNU_MINFILTER = "Linear filter when downscaling";
|
||||
TCMNU_MAGFILTER = "Linear filter when upscaling";
|
||||
TCMNU_MIPMAP = "Use mipmapped textures";
|
||||
TCMNU_DYNLIGHTS = "Dynamic lights";
|
||||
|
||||
|
|
|
@ -675,6 +675,7 @@ OptionMenu "TrueColorOptions"
|
|||
Option "$TCMNU_MINFILTER", "r_minfilter", "OnOff"
|
||||
Option "$TCMNU_MAGFILTER", "r_magfilter", "OnOff"
|
||||
Option "$TCMNU_MIPMAP", "r_mipmap", "OnOff"
|
||||
Option "$TCMNU_DYNLIGHTS", "r_dynlights", "OnOff"
|
||||
}
|
||||
|
||||
OptionMenu "VideoOptions"
|
||||
|
|
Loading…
Reference in a new issue