2017-01-12 15:21:46 +00:00
|
|
|
//
|
|
|
|
// Copyright (C) 1993-1996 by id Software, Inc.
|
|
|
|
//
|
|
|
|
// This source is available for distribution and/or modification
|
|
|
|
// only under the terms of the DOOM Source Code License as
|
|
|
|
// published by id Software. All rights reserved.
|
|
|
|
//
|
|
|
|
// The source is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// FITNESS FOR A PARTICULAR PURPOSE. See the DOOM Source Code License
|
|
|
|
// for more details.
|
|
|
|
//
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <float.h>
|
|
|
|
|
|
|
|
#include "templates.h"
|
|
|
|
#include "i_system.h"
|
|
|
|
#include "w_wad.h"
|
|
|
|
#include "doomdef.h"
|
|
|
|
#include "doomstat.h"
|
|
|
|
#include "r_sky.h"
|
|
|
|
#include "stats.h"
|
|
|
|
#include "v_video.h"
|
|
|
|
#include "a_sharedglobal.h"
|
|
|
|
#include "c_console.h"
|
|
|
|
#include "c_dispatch.h"
|
|
|
|
#include "cmdlib.h"
|
|
|
|
#include "d_net.h"
|
|
|
|
#include "g_level.h"
|
|
|
|
#include "r_utility.h"
|
|
|
|
#include "d_player.h"
|
|
|
|
#include "swrenderer/scene/r_light.h"
|
2017-02-02 14:10:06 +00:00
|
|
|
#include "swrenderer/viewport/r_viewport.h"
|
2017-01-12 15:21:46 +00:00
|
|
|
|
|
|
|
CVAR(Bool, r_shadercolormaps, true, CVAR_ARCHIVE)
|
2017-01-28 22:37:57 +00:00
|
|
|
EXTERN_CVAR(Bool, r_fullbrightignoresectorcolor)
|
2017-01-12 15:21:46 +00:00
|
|
|
|
|
|
|
namespace swrenderer
|
|
|
|
{
|
2017-01-26 09:22:54 +00:00
|
|
|
CameraLight *CameraLight::Instance()
|
|
|
|
{
|
|
|
|
static CameraLight instance;
|
|
|
|
return &instance;
|
|
|
|
}
|
2017-01-12 15:21:46 +00:00
|
|
|
|
2017-03-12 17:54:39 +00:00
|
|
|
void CameraLight::SetCamera(RenderViewport *viewport, AActor *actor)
|
2017-01-12 15:21:46 +00:00
|
|
|
{
|
2017-03-12 17:54:39 +00:00
|
|
|
AActor *camera = viewport->viewpoint.camera;
|
2017-01-15 00:54:25 +00:00
|
|
|
player_t *player = actor->player;
|
2017-01-26 09:22:54 +00:00
|
|
|
if (camera && camera->player != nullptr)
|
2017-01-15 00:54:25 +00:00
|
|
|
player = camera->player;
|
|
|
|
|
2017-01-26 09:22:54 +00:00
|
|
|
realfixedcolormap = nullptr;
|
|
|
|
fixedcolormap = nullptr;
|
2017-01-12 15:21:46 +00:00
|
|
|
fixedlightlev = -1;
|
|
|
|
|
2017-01-26 09:22:54 +00:00
|
|
|
if (player != nullptr && camera == player->mo)
|
2017-01-12 15:21:46 +00:00
|
|
|
{
|
|
|
|
if (player->fixedcolormap >= 0 && player->fixedcolormap < (int)SpecialColormaps.Size())
|
|
|
|
{
|
|
|
|
realfixedcolormap = &SpecialColormaps[player->fixedcolormap];
|
2017-02-01 20:42:08 +00:00
|
|
|
if (viewport->RenderTarget == screen && (viewport->RenderTarget->IsBgra() || ((DFrameBuffer *)screen->Accel2D && r_shadercolormaps)))
|
2017-01-12 15:21:46 +00:00
|
|
|
{
|
|
|
|
// Render everything fullbright. The copy to video memory will
|
|
|
|
// apply the special colormap, so it won't be restricted to the
|
|
|
|
// palette.
|
|
|
|
fixedcolormap = &realcolormaps;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-03-15 21:04:23 +00:00
|
|
|
fixedcolormap = &SpecialSWColormaps[player->fixedcolormap];
|
2017-01-12 15:21:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (player->fixedlightlevel >= 0 && player->fixedlightlevel < NUMCOLORMAPS)
|
|
|
|
{
|
|
|
|
fixedlightlev = player->fixedlightlevel * 256;
|
|
|
|
// [SP] Emulate GZDoom's light-amp goggles.
|
2017-01-28 22:37:57 +00:00
|
|
|
if (r_fullbrightignoresectorcolor && fixedlightlev >= 0)
|
2017-01-12 15:21:46 +00:00
|
|
|
{
|
|
|
|
fixedcolormap = &FullNormalLight;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// [RH] Inverse light for shooting the Sigil
|
2017-03-12 17:54:39 +00:00
|
|
|
if (fixedcolormap == nullptr && viewport->viewpoint.extralight == INT_MIN)
|
2017-01-12 15:21:46 +00:00
|
|
|
{
|
2017-03-15 21:04:23 +00:00
|
|
|
fixedcolormap = &SpecialSWColormaps[INVERSECOLORMAP];
|
2017-03-12 17:54:39 +00:00
|
|
|
viewport->viewpoint.extralight = 0;
|
2017-01-12 15:21:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-26 08:49:07 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
// Changes how rapidly things get dark with distance
|
2017-03-12 17:54:39 +00:00
|
|
|
void LightVisibility::SetVisibility(RenderViewport *viewport, double vis)
|
2017-01-26 08:49:07 +00:00
|
|
|
{
|
|
|
|
// Allow negative visibilities, just for novelty's sake
|
|
|
|
vis = clamp(vis, -204.7, 204.7); // (205 and larger do not work in 5:4 aspect ratio)
|
|
|
|
|
|
|
|
CurrentVisibility = vis;
|
|
|
|
|
2017-03-12 17:54:39 +00:00
|
|
|
if (viewport->viewwindow.FocalTangent == 0 || viewport->FocalLengthY == 0)
|
2017-01-26 08:49:07 +00:00
|
|
|
{ // If r_visibility is called before the renderer is all set up, don't
|
|
|
|
// divide by zero. This will be called again later, and the proper
|
|
|
|
// values can be initialized then.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
BaseVisibility = vis;
|
|
|
|
|
2017-03-12 17:54:39 +00:00
|
|
|
MaxVisForWall = (viewport->InvZtoScale * (SCREENWIDTH*r_Yaspect) / (viewwidth*SCREENHEIGHT * viewport->viewwindow.FocalTangent));
|
2017-01-26 08:49:07 +00:00
|
|
|
MaxVisForWall = 32767.0 / MaxVisForWall;
|
2017-02-01 15:02:21 +00:00
|
|
|
MaxVisForFloor = 32767.0 / (viewheight >> 2) * viewport->FocalLengthY / 160;
|
2017-01-26 08:49:07 +00:00
|
|
|
|
|
|
|
// Prevent overflow on walls
|
|
|
|
if (BaseVisibility < 0 && BaseVisibility < -MaxVisForWall)
|
|
|
|
WallVisibility = -MaxVisForWall;
|
|
|
|
else if (BaseVisibility > 0 && BaseVisibility > MaxVisForWall)
|
|
|
|
WallVisibility = MaxVisForWall;
|
|
|
|
else
|
|
|
|
WallVisibility = BaseVisibility;
|
|
|
|
|
2017-03-12 17:54:39 +00:00
|
|
|
WallVisibility = (viewport->InvZtoScale * SCREENWIDTH*AspectBaseHeight(viewport->viewwindow.WidescreenRatio) /
|
|
|
|
(viewwidth*SCREENHEIGHT * 3)) * (WallVisibility * viewport->viewwindow.FocalTangent);
|
2017-01-26 08:49:07 +00:00
|
|
|
|
|
|
|
// Prevent overflow on floors/ceilings. Note that the calculation of
|
|
|
|
// MaxVisForFloor means that planes less than two units from the player's
|
|
|
|
// view could still overflow, but there is no way to totally eliminate
|
|
|
|
// that while still using fixed point math.
|
|
|
|
if (BaseVisibility < 0 && BaseVisibility < -MaxVisForFloor)
|
|
|
|
FloorVisibility = -MaxVisForFloor;
|
|
|
|
else if (BaseVisibility > 0 && BaseVisibility > MaxVisForFloor)
|
|
|
|
FloorVisibility = MaxVisForFloor;
|
|
|
|
else
|
|
|
|
FloorVisibility = BaseVisibility;
|
|
|
|
|
2017-02-01 15:02:21 +00:00
|
|
|
FloorVisibility = 160.0 * FloorVisibility / viewport->FocalLengthY;
|
2017-01-26 08:49:07 +00:00
|
|
|
|
2017-03-12 17:54:39 +00:00
|
|
|
TiltVisibility = float(vis * viewport->viewwindow.FocalTangent * (16.f * 320.f) / viewwidth);
|
2017-03-05 15:57:58 +00:00
|
|
|
|
2017-03-14 17:31:11 +00:00
|
|
|
NoLightFade = !!(level.flags3 & LEVEL3_NOLIGHTFADE);
|
2017-03-06 22:27:02 +00:00
|
|
|
}
|
2017-03-06 21:14:54 +00:00
|
|
|
|
2017-03-06 22:27:02 +00:00
|
|
|
fixed_t LightVisibility::LightLevelToShade(int lightlevel, bool foggy)
|
|
|
|
{
|
2017-03-14 17:31:11 +00:00
|
|
|
bool nolightfade = !foggy && ((level.flags3 & LEVEL3_NOLIGHTFADE));
|
2017-03-06 22:27:02 +00:00
|
|
|
if (nolightfade)
|
|
|
|
{
|
|
|
|
return (MAX(255 - lightlevel, 0) * NUMCOLORMAPS) << (FRACBITS - 8);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Convert a light level into an unbounded colormap index (shade). Result is
|
|
|
|
// fixed point. Why the +12? I wish I knew, but experimentation indicates it
|
|
|
|
// is necessary in order to best reproduce Doom's original lighting.
|
|
|
|
return (NUMCOLORMAPS * 2 * FRACUNIT) - ((lightlevel + 12) * (FRACUNIT*NUMCOLORMAPS / 128));
|
|
|
|
}
|
2017-01-26 08:49:07 +00:00
|
|
|
}
|
|
|
|
|
2017-01-12 15:21:46 +00:00
|
|
|
// Controls how quickly light ramps across a 1/z range. Set this, and it
|
|
|
|
// sets all the r_*Visibility variables (except r_SkyVisibilily, which is
|
|
|
|
// currently unused).
|
|
|
|
CCMD(r_visibility)
|
|
|
|
{
|
|
|
|
if (argv.argc() < 2)
|
|
|
|
{
|
2017-03-12 17:54:39 +00:00
|
|
|
Printf("Visibility is %g\n", Renderer->GetVisibility());
|
2017-01-12 15:21:46 +00:00
|
|
|
}
|
|
|
|
else if (!netgame)
|
|
|
|
{
|
2017-03-12 17:54:39 +00:00
|
|
|
Renderer->SetVisibility(atof(argv[1]));
|
2017-01-12 15:21:46 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Printf("Visibility cannot be changed in net games.\n");
|
|
|
|
}
|
|
|
|
}
|
2017-01-24 03:24:04 +00:00
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
void ColormapLight::SetColormap(double visibility, int shade, FDynamicColormap *basecolormap, bool fullbright, bool invertColormap, bool fadeToBlack)
|
|
|
|
{
|
|
|
|
if (fadeToBlack)
|
|
|
|
{
|
|
|
|
if (invertColormap) // Fade to white
|
|
|
|
{
|
|
|
|
basecolormap = GetSpecialLights(basecolormap->Color, MAKERGB(255, 255, 255), basecolormap->Desaturate);
|
|
|
|
invertColormap = false;
|
|
|
|
}
|
|
|
|
else // Fade to black
|
|
|
|
{
|
|
|
|
basecolormap = GetSpecialLights(basecolormap->Color, MAKERGB(0, 0, 0), basecolormap->Desaturate);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (invertColormap)
|
|
|
|
{
|
|
|
|
basecolormap = GetSpecialLights(basecolormap->Color, basecolormap->Fade.InverseColor(), basecolormap->Desaturate);
|
|
|
|
}
|
|
|
|
|
2017-01-26 09:22:54 +00:00
|
|
|
CameraLight *cameraLight = CameraLight::Instance();
|
2017-02-03 08:00:46 +00:00
|
|
|
if (cameraLight->FixedColormap())
|
2017-01-24 03:24:04 +00:00
|
|
|
{
|
2017-02-03 08:00:46 +00:00
|
|
|
BaseColormap = cameraLight->FixedColormap();
|
2017-01-24 03:24:04 +00:00
|
|
|
ColormapNum = 0;
|
|
|
|
}
|
2017-02-03 08:00:46 +00:00
|
|
|
else if (cameraLight->FixedLightLevel() >= 0)
|
2017-01-24 03:24:04 +00:00
|
|
|
{
|
2017-01-28 22:37:57 +00:00
|
|
|
BaseColormap = (r_fullbrightignoresectorcolor) ? &FullNormalLight : basecolormap;
|
2017-02-03 08:00:46 +00:00
|
|
|
ColormapNum = cameraLight->FixedLightLevel() >> COLORMAPSHIFT;
|
2017-01-24 03:24:04 +00:00
|
|
|
}
|
|
|
|
else if (fullbright)
|
|
|
|
{
|
2017-01-28 22:37:57 +00:00
|
|
|
BaseColormap = (r_fullbrightignoresectorcolor) ? &FullNormalLight : basecolormap;
|
2017-01-24 03:24:04 +00:00
|
|
|
ColormapNum = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
BaseColormap = basecolormap;
|
|
|
|
ColormapNum = GETPALOOKUP(visibility, shade);
|
|
|
|
}
|
|
|
|
}
|
2017-01-12 15:21:46 +00:00
|
|
|
}
|