2016-11-14 13:19:48 +00:00
|
|
|
/*
|
|
|
|
** Handling drawing a sprite
|
|
|
|
** Copyright (c) 2016 Magnus Norddahl
|
|
|
|
**
|
|
|
|
** This software is provided 'as-is', without any express or implied
|
|
|
|
** warranty. In no event will the authors be held liable for any damages
|
|
|
|
** arising from the use of this software.
|
|
|
|
**
|
|
|
|
** Permission is granted to anyone to use this software for any purpose,
|
|
|
|
** including commercial applications, and to alter it and redistribute it
|
|
|
|
** freely, subject to the following restrictions:
|
|
|
|
**
|
|
|
|
** 1. The origin of this software must not be misrepresented; you must not
|
|
|
|
** claim that you wrote the original software. If you use this software
|
|
|
|
** in a product, an acknowledgment in the product documentation would be
|
|
|
|
** appreciated but is not required.
|
|
|
|
** 2. Altered source versions must be plainly marked as such, and must not be
|
|
|
|
** misrepresented as being the original software.
|
|
|
|
** 3. This notice may not be removed or altered from any source distribution.
|
|
|
|
**
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include "templates.h"
|
|
|
|
#include "doomdef.h"
|
|
|
|
#include "sbar.h"
|
|
|
|
#include "r_data/r_translate.h"
|
2016-12-27 05:31:55 +00:00
|
|
|
#include "poly_sprite.h"
|
|
|
|
#include "polyrenderer/poly_renderer.h"
|
|
|
|
#include "polyrenderer/math/poly_intersection.h"
|
2017-01-12 15:21:46 +00:00
|
|
|
#include "swrenderer/scene/r_light.h"
|
2016-11-14 13:19:48 +00:00
|
|
|
|
2016-11-20 22:07:58 +00:00
|
|
|
EXTERN_CVAR(Float, transsouls)
|
|
|
|
EXTERN_CVAR(Int, r_drawfuzz)
|
|
|
|
|
2016-12-02 07:12:01 +00:00
|
|
|
bool RenderPolySprite::GetLine(AActor *thing, DVector2 &left, DVector2 &right)
|
2016-11-14 13:19:48 +00:00
|
|
|
{
|
|
|
|
if (IsThingCulled(thing))
|
2016-12-02 07:12:01 +00:00
|
|
|
return false;
|
|
|
|
|
2017-03-12 17:54:39 +00:00
|
|
|
const auto &viewpoint = PolyRenderer::Instance()->Thread.Viewport->viewpoint;
|
|
|
|
DVector3 pos = thing->InterpolatedPosition(viewpoint.TicFrac);
|
2016-12-02 07:12:01 +00:00
|
|
|
|
|
|
|
bool flipTextureX = false;
|
|
|
|
FTexture *tex = GetSpriteTexture(thing, flipTextureX);
|
|
|
|
if (tex == nullptr)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
DVector2 spriteScale = thing->Scale;
|
|
|
|
double thingxscalemul = spriteScale.X / tex->Scale.X;
|
|
|
|
double thingyscalemul = spriteScale.Y / tex->Scale.Y;
|
|
|
|
|
|
|
|
if (flipTextureX)
|
|
|
|
pos.X -= (tex->GetWidth() - tex->LeftOffset) * thingxscalemul;
|
|
|
|
else
|
|
|
|
pos.X -= tex->LeftOffset * thingxscalemul;
|
|
|
|
|
|
|
|
double spriteHalfWidth = thingxscalemul * tex->GetWidth() * 0.5;
|
|
|
|
double spriteHeight = thingyscalemul * tex->GetHeight();
|
|
|
|
|
|
|
|
pos.X += spriteHalfWidth;
|
|
|
|
|
2017-03-12 17:54:39 +00:00
|
|
|
left = DVector2(pos.X - viewpoint.Sin * spriteHalfWidth, pos.Y + viewpoint.Cos * spriteHalfWidth);
|
|
|
|
right = DVector2(pos.X + viewpoint.Sin * spriteHalfWidth, pos.Y - viewpoint.Cos * spriteHalfWidth);
|
2016-12-02 07:12:01 +00:00
|
|
|
return true;
|
|
|
|
}
|
2016-11-14 13:19:48 +00:00
|
|
|
|
2016-12-02 12:24:53 +00:00
|
|
|
void RenderPolySprite::Render(const TriMatrix &worldToClip, const Vec4f &clipPlane, AActor *thing, subsector_t *sub, uint32_t subsectorDepth, uint32_t stencilValue, float t1, float t2)
|
2016-12-02 07:12:01 +00:00
|
|
|
{
|
2016-12-02 12:24:53 +00:00
|
|
|
DVector2 line[2];
|
|
|
|
if (!GetLine(thing, line[0], line[1]))
|
2016-12-02 07:12:01 +00:00
|
|
|
return;
|
|
|
|
|
2017-03-12 17:54:39 +00:00
|
|
|
const auto &viewpoint = PolyRenderer::Instance()->Thread.Viewport->viewpoint;
|
|
|
|
DVector3 pos = thing->InterpolatedPosition(viewpoint.TicFrac);
|
|
|
|
pos.Z += thing->GetBobOffset(viewpoint.TicFrac);
|
2016-11-14 13:19:48 +00:00
|
|
|
|
|
|
|
bool flipTextureX = false;
|
|
|
|
FTexture *tex = GetSpriteTexture(thing, flipTextureX);
|
2016-12-07 17:59:48 +00:00
|
|
|
if (tex == nullptr || tex->UseType == FTexture::TEX_Null)
|
2016-11-14 13:19:48 +00:00
|
|
|
return;
|
2016-12-02 07:12:01 +00:00
|
|
|
|
2016-11-14 13:19:48 +00:00
|
|
|
DVector2 spriteScale = thing->Scale;
|
|
|
|
double thingxscalemul = spriteScale.X / tex->Scale.X;
|
|
|
|
double thingyscalemul = spriteScale.Y / tex->Scale.Y;
|
|
|
|
|
|
|
|
if (flipTextureX)
|
|
|
|
pos.X -= (tex->GetWidth() - tex->LeftOffset) * thingxscalemul;
|
|
|
|
else
|
|
|
|
pos.X -= tex->LeftOffset * thingxscalemul;
|
|
|
|
|
|
|
|
//pos.Z -= tex->TopOffset * thingyscalemul;
|
|
|
|
pos.Z -= (tex->GetHeight() - tex->TopOffset) * thingyscalemul + thing->Floorclip;
|
|
|
|
|
|
|
|
double spriteHalfWidth = thingxscalemul * tex->GetWidth() * 0.5;
|
|
|
|
double spriteHeight = thingyscalemul * tex->GetHeight();
|
|
|
|
|
|
|
|
pos.X += spriteHalfWidth;
|
|
|
|
|
|
|
|
//double depth = 1.0;
|
|
|
|
//visstyle_t visstyle = GetSpriteVisStyle(thing, depth);
|
|
|
|
// Rumor has it that AlterWeaponSprite needs to be called with visstyle passed in somewhere around here..
|
|
|
|
//R_SetColorMapLight(visstyle.BaseColormap, 0, visstyle.ColormapNum << FRACBITS);
|
|
|
|
|
|
|
|
TriVertex *vertices = PolyVertexBuffer::GetVertices(4);
|
|
|
|
if (!vertices)
|
|
|
|
return;
|
|
|
|
|
|
|
|
bool foggy = false;
|
2017-03-12 17:54:39 +00:00
|
|
|
int actualextralight = foggy ? 0 : viewpoint.extralight << 4;
|
2016-11-14 13:19:48 +00:00
|
|
|
|
|
|
|
std::pair<float, float> offsets[4] =
|
|
|
|
{
|
2016-12-02 12:24:53 +00:00
|
|
|
{ t1, 1.0f },
|
|
|
|
{ t2, 1.0f },
|
|
|
|
{ t2, 0.0f },
|
|
|
|
{ t1, 0.0f },
|
|
|
|
};
|
|
|
|
|
|
|
|
DVector2 points[2] =
|
|
|
|
{
|
|
|
|
line[0] * (1.0 - t1) + line[1] * t1,
|
|
|
|
line[0] * (1.0 - t2) + line[1] * t2
|
2016-11-14 13:19:48 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
for (int i = 0; i < 4; i++)
|
|
|
|
{
|
|
|
|
auto &p = (i == 0 || i == 3) ? points[0] : points[1];
|
|
|
|
|
|
|
|
vertices[i].x = (float)p.X;
|
|
|
|
vertices[i].y = (float)p.Y;
|
|
|
|
vertices[i].z = (float)(pos.Z + spriteHeight * offsets[i].second);
|
|
|
|
vertices[i].w = 1.0f;
|
|
|
|
vertices[i].varying[0] = (float)(offsets[i].first * tex->Scale.X);
|
|
|
|
vertices[i].varying[1] = (float)((1.0f - offsets[i].second) * tex->Scale.Y);
|
|
|
|
if (flipTextureX)
|
|
|
|
vertices[i].varying[0] = 1.0f - vertices[i].varying[0];
|
|
|
|
}
|
|
|
|
|
2016-11-15 22:30:42 +00:00
|
|
|
bool fullbrightSprite = ((thing->renderflags & RF_FULLBRIGHT) || (thing->flags5 & MF5_BRIGHT));
|
2017-01-26 09:22:54 +00:00
|
|
|
swrenderer::CameraLight *cameraLight = swrenderer::CameraLight::Instance();
|
2016-11-15 22:30:42 +00:00
|
|
|
|
2016-11-21 02:49:55 +00:00
|
|
|
PolyDrawArgs args;
|
2017-03-12 19:40:00 +00:00
|
|
|
args.uniforms.globvis = (float)PolyRenderer::Instance()->Thread.Light->SpriteGlobVis(foggy);
|
2016-11-21 02:49:55 +00:00
|
|
|
args.uniforms.flags = 0;
|
2017-02-03 08:00:46 +00:00
|
|
|
if (fullbrightSprite || cameraLight->FixedLightLevel() >= 0 || cameraLight->FixedColormap())
|
2016-11-15 22:30:42 +00:00
|
|
|
{
|
2016-11-21 02:49:55 +00:00
|
|
|
args.uniforms.light = 256;
|
|
|
|
args.uniforms.flags |= TriUniforms::fixed_light;
|
2016-11-15 22:30:42 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-11-21 02:49:55 +00:00
|
|
|
args.uniforms.light = (uint32_t)((thing->Sector->lightlevel + actualextralight) / 255.0f * 256.0f);
|
2016-11-15 22:30:42 +00:00
|
|
|
}
|
2016-11-21 02:49:55 +00:00
|
|
|
args.uniforms.subsectorDepth = subsectorDepth;
|
2016-11-14 13:19:48 +00:00
|
|
|
|
2016-11-20 01:07:55 +00:00
|
|
|
args.objectToClip = &worldToClip;
|
2016-11-14 13:19:48 +00:00
|
|
|
args.vinput = vertices;
|
|
|
|
args.vcount = 4;
|
|
|
|
args.mode = TriangleDrawMode::Fan;
|
|
|
|
args.ccw = true;
|
2016-11-24 07:23:50 +00:00
|
|
|
args.stenciltestvalue = stencilValue;
|
|
|
|
args.stencilwritevalue = stencilValue;
|
2016-11-19 12:32:57 +00:00
|
|
|
args.SetTexture(tex, thing->Translation);
|
2017-03-15 23:56:03 +00:00
|
|
|
args.SetColormap(GetColorTable(sub->sector->Colormap, sub->sector->SpecialColors[sector_t::sprites], true));
|
2016-11-26 09:49:29 +00:00
|
|
|
args.SetClipPlane(clipPlane.x, clipPlane.y, clipPlane.z, clipPlane.w);
|
2016-11-19 12:32:57 +00:00
|
|
|
|
2016-11-21 02:49:55 +00:00
|
|
|
TriBlendMode blendmode;
|
|
|
|
|
2016-11-20 22:07:58 +00:00
|
|
|
if (thing->RenderStyle == LegacyRenderStyles[STYLE_Normal] ||
|
|
|
|
(r_drawfuzz == 0 && thing->RenderStyle == LegacyRenderStyles[STYLE_OptFuzzy]))
|
|
|
|
{
|
|
|
|
args.uniforms.destalpha = 0;
|
|
|
|
args.uniforms.srcalpha = 256;
|
2016-11-21 02:49:55 +00:00
|
|
|
blendmode = args.translation ? TriBlendMode::TranslateAdd : TriBlendMode::Add;
|
2016-11-20 22:07:58 +00:00
|
|
|
}
|
2016-11-30 06:49:04 +00:00
|
|
|
else if (thing->RenderStyle == LegacyRenderStyles[STYLE_Add] && fullbrightSprite && thing->Alpha == 1.0 && args.translation == nullptr)
|
|
|
|
{
|
|
|
|
args.uniforms.destalpha = 256;
|
|
|
|
args.uniforms.srcalpha = 256;
|
|
|
|
blendmode = TriBlendMode::AddSrcColorOneMinusSrcColor;
|
|
|
|
}
|
2016-11-20 22:07:58 +00:00
|
|
|
else if (thing->RenderStyle == LegacyRenderStyles[STYLE_Add])
|
|
|
|
{
|
|
|
|
args.uniforms.destalpha = (uint32_t)(1.0 * 256);
|
|
|
|
args.uniforms.srcalpha = (uint32_t)(thing->Alpha * 256);
|
2016-11-21 02:49:55 +00:00
|
|
|
blendmode = args.translation ? TriBlendMode::TranslateAdd : TriBlendMode::Add;
|
2016-11-20 22:07:58 +00:00
|
|
|
}
|
|
|
|
else if (thing->RenderStyle == LegacyRenderStyles[STYLE_Subtract])
|
|
|
|
{
|
|
|
|
args.uniforms.destalpha = (uint32_t)(1.0 * 256);
|
|
|
|
args.uniforms.srcalpha = (uint32_t)(thing->Alpha * 256);
|
2016-12-22 08:21:56 +00:00
|
|
|
blendmode = args.translation ? TriBlendMode::TranslateRevSub : TriBlendMode::RevSub;
|
2016-11-20 22:07:58 +00:00
|
|
|
}
|
|
|
|
else if (thing->RenderStyle == LegacyRenderStyles[STYLE_SoulTrans])
|
|
|
|
{
|
|
|
|
args.uniforms.destalpha = (uint32_t)(256 - transsouls * 256);
|
|
|
|
args.uniforms.srcalpha = (uint32_t)(transsouls * 256);
|
2016-11-21 02:49:55 +00:00
|
|
|
blendmode = args.translation ? TriBlendMode::TranslateAdd : TriBlendMode::Add;
|
2016-11-20 22:07:58 +00:00
|
|
|
}
|
|
|
|
else if (thing->RenderStyle == LegacyRenderStyles[STYLE_Fuzzy] ||
|
|
|
|
(r_drawfuzz == 2 && thing->RenderStyle == LegacyRenderStyles[STYLE_OptFuzzy]))
|
|
|
|
{ // NYI - Fuzzy - for now, just a copy of "Shadow"
|
|
|
|
args.uniforms.destalpha = 160;
|
|
|
|
args.uniforms.srcalpha = 0;
|
2016-11-21 02:49:55 +00:00
|
|
|
blendmode = args.translation ? TriBlendMode::TranslateAdd : TriBlendMode::Add;
|
2016-11-20 22:07:58 +00:00
|
|
|
}
|
|
|
|
else if (thing->RenderStyle == LegacyRenderStyles[STYLE_Shadow] ||
|
|
|
|
(r_drawfuzz == 1 && thing->RenderStyle == LegacyRenderStyles[STYLE_OptFuzzy]))
|
|
|
|
{
|
|
|
|
args.uniforms.destalpha = 160;
|
|
|
|
args.uniforms.srcalpha = 0;
|
2016-11-21 02:49:55 +00:00
|
|
|
blendmode = args.translation ? TriBlendMode::TranslateAdd : TriBlendMode::Add;
|
2016-11-20 22:07:58 +00:00
|
|
|
}
|
|
|
|
else if (thing->RenderStyle == LegacyRenderStyles[STYLE_TranslucentStencil])
|
|
|
|
{
|
|
|
|
args.uniforms.destalpha = (uint32_t)(256 - thing->Alpha * 256);
|
|
|
|
args.uniforms.srcalpha = (uint32_t)(thing->Alpha * 256);
|
|
|
|
args.uniforms.color = 0xff000000 | thing->fillcolor;
|
2016-11-21 04:52:02 +00:00
|
|
|
blendmode = TriBlendMode::Stencil;
|
2016-11-20 22:07:58 +00:00
|
|
|
}
|
|
|
|
else if (thing->RenderStyle == LegacyRenderStyles[STYLE_AddStencil])
|
|
|
|
{
|
|
|
|
args.uniforms.destalpha = 256;
|
2016-11-21 14:20:07 +00:00
|
|
|
args.uniforms.srcalpha = (uint32_t)(thing->Alpha * 256);
|
2016-11-20 22:07:58 +00:00
|
|
|
args.uniforms.color = 0xff000000 | thing->fillcolor;
|
2016-11-21 04:52:02 +00:00
|
|
|
blendmode = TriBlendMode::Stencil;
|
2016-11-20 22:07:58 +00:00
|
|
|
}
|
|
|
|
else if (thing->RenderStyle == LegacyRenderStyles[STYLE_Shaded])
|
|
|
|
{
|
|
|
|
args.uniforms.srcalpha = (uint32_t)(thing->Alpha * 256);
|
2016-11-21 02:49:55 +00:00
|
|
|
args.uniforms.destalpha = 256 - args.uniforms.srcalpha;
|
2016-11-20 23:36:26 +00:00
|
|
|
args.uniforms.color = 0;
|
2016-11-21 02:49:55 +00:00
|
|
|
blendmode = TriBlendMode::Shaded;
|
2016-11-20 22:07:58 +00:00
|
|
|
}
|
|
|
|
else if (thing->RenderStyle == LegacyRenderStyles[STYLE_AddShaded])
|
2016-11-21 02:49:55 +00:00
|
|
|
{
|
2016-11-20 22:07:58 +00:00
|
|
|
args.uniforms.destalpha = 256;
|
|
|
|
args.uniforms.srcalpha = (uint32_t)(thing->Alpha * 256);
|
2016-11-20 23:36:26 +00:00
|
|
|
args.uniforms.color = 0;
|
2016-11-21 02:49:55 +00:00
|
|
|
blendmode = TriBlendMode::Shaded;
|
2016-11-20 22:07:58 +00:00
|
|
|
}
|
2016-11-19 12:32:57 +00:00
|
|
|
else
|
2016-11-20 22:07:58 +00:00
|
|
|
{
|
|
|
|
args.uniforms.destalpha = (uint32_t)(256 - thing->Alpha * 256);
|
|
|
|
args.uniforms.srcalpha = (uint32_t)(thing->Alpha * 256);
|
2016-11-21 02:49:55 +00:00
|
|
|
blendmode = args.translation ? TriBlendMode::TranslateAdd : TriBlendMode::Add;
|
|
|
|
}
|
|
|
|
|
2016-11-21 04:52:02 +00:00
|
|
|
if (blendmode == TriBlendMode::Shaded)
|
|
|
|
{
|
|
|
|
args.SetTexture(tex, thing->Translation, true);
|
|
|
|
}
|
|
|
|
|
2017-03-12 17:54:39 +00:00
|
|
|
if (!PolyRenderer::Instance()->Thread.Viewport->RenderTarget->IsBgra())
|
2016-11-21 02:49:55 +00:00
|
|
|
{
|
|
|
|
uint32_t r = (args.uniforms.color >> 16) & 0xff;
|
|
|
|
uint32_t g = (args.uniforms.color >> 8) & 0xff;
|
|
|
|
uint32_t b = args.uniforms.color & 0xff;
|
|
|
|
args.uniforms.color = RGB32k.RGB[r >> 3][g >> 3][b >> 3];
|
2016-11-21 14:40:42 +00:00
|
|
|
|
|
|
|
if (blendmode == TriBlendMode::Sub) // Sub crashes in pal mode for some weird reason.
|
|
|
|
blendmode = TriBlendMode::Add;
|
2016-11-20 22:07:58 +00:00
|
|
|
}
|
|
|
|
|
2016-12-15 23:35:45 +00:00
|
|
|
args.subsectorTest = true;
|
|
|
|
args.writeSubsector = false;
|
|
|
|
args.writeStencil = false;
|
|
|
|
args.blendmode = blendmode;
|
|
|
|
PolyTriangleDrawer::draw(args);
|
2016-11-14 13:19:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool RenderPolySprite::IsThingCulled(AActor *thing)
|
|
|
|
{
|
|
|
|
FIntCVar *cvar = thing->GetClass()->distancecheck;
|
|
|
|
if (cvar != nullptr && *cvar >= 0)
|
|
|
|
{
|
2017-03-12 17:54:39 +00:00
|
|
|
double dist = (thing->Pos() - PolyRenderer::Instance()->Thread.Viewport->viewpoint.Pos).LengthSquared();
|
2016-11-14 13:19:48 +00:00
|
|
|
double check = (double)**cvar;
|
|
|
|
if (dist >= check * check)
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Don't waste time projecting sprites that are definitely not visible.
|
|
|
|
if (thing == nullptr ||
|
|
|
|
(thing->renderflags & RF_INVISIBLE) ||
|
|
|
|
!thing->RenderStyle.IsVisible(thing->Alpha) ||
|
|
|
|
!thing->IsVisibleToPlayer())
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-01-16 15:23:02 +00:00
|
|
|
#if 0
|
2016-11-14 13:19:48 +00:00
|
|
|
visstyle_t RenderPolySprite::GetSpriteVisStyle(AActor *thing, double z)
|
|
|
|
{
|
|
|
|
visstyle_t visstyle;
|
|
|
|
|
|
|
|
bool foggy = false;
|
|
|
|
int actualextralight = foggy ? 0 : extralight << 4;
|
|
|
|
int spriteshade = LIGHT2SHADE(thing->Sector->lightlevel + actualextralight);
|
|
|
|
|
2017-01-16 15:23:02 +00:00
|
|
|
FRenderStyle RenderStyle;
|
|
|
|
RenderStyle = thing->RenderStyle;
|
|
|
|
float Alpha = float(thing->Alpha);
|
|
|
|
int ColormapNum = 0;
|
2016-11-14 13:19:48 +00:00
|
|
|
|
|
|
|
// The software renderer cannot invert the source without inverting the overlay
|
|
|
|
// too. That means if the source is inverted, we need to do the reverse of what
|
|
|
|
// the invert overlay flag says to do.
|
2017-01-16 15:23:02 +00:00
|
|
|
bool invertcolormap = (RenderStyle.Flags & STYLEF_InvertOverlay) != 0;
|
2016-11-14 13:19:48 +00:00
|
|
|
|
2017-01-16 15:23:02 +00:00
|
|
|
if (RenderStyle.Flags & STYLEF_InvertSource)
|
2016-11-14 13:19:48 +00:00
|
|
|
{
|
|
|
|
invertcolormap = !invertcolormap;
|
|
|
|
}
|
|
|
|
|
|
|
|
FDynamicColormap *mybasecolormap = thing->Sector->ColorMap;
|
|
|
|
|
|
|
|
// Sprites that are added to the scene must fade to black.
|
2017-01-16 15:23:02 +00:00
|
|
|
if (RenderStyle == LegacyRenderStyles[STYLE_Add] && mybasecolormap->Fade != 0)
|
2016-11-14 13:19:48 +00:00
|
|
|
{
|
|
|
|
mybasecolormap = GetSpecialLights(mybasecolormap->Color, 0, mybasecolormap->Desaturate);
|
|
|
|
}
|
|
|
|
|
2017-01-16 15:23:02 +00:00
|
|
|
if (RenderStyle.Flags & STYLEF_FadeToBlack)
|
2016-11-14 13:19:48 +00:00
|
|
|
{
|
|
|
|
if (invertcolormap)
|
|
|
|
{ // Fade to white
|
|
|
|
mybasecolormap = GetSpecialLights(mybasecolormap->Color, MAKERGB(255, 255, 255), mybasecolormap->Desaturate);
|
|
|
|
invertcolormap = false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{ // Fade to black
|
|
|
|
mybasecolormap = GetSpecialLights(mybasecolormap->Color, MAKERGB(0, 0, 0), mybasecolormap->Desaturate);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// get light level
|
2016-12-01 01:38:32 +00:00
|
|
|
if (swrenderer::fixedcolormap != nullptr)
|
2016-11-14 13:19:48 +00:00
|
|
|
{ // fixed map
|
2017-01-16 15:23:02 +00:00
|
|
|
BaseColormap = swrenderer::fixedcolormap;
|
|
|
|
ColormapNum = 0;
|
2016-11-14 13:19:48 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (invertcolormap)
|
|
|
|
{
|
|
|
|
mybasecolormap = GetSpecialLights(mybasecolormap->Color, mybasecolormap->Fade.InverseColor(), mybasecolormap->Desaturate);
|
|
|
|
}
|
2016-12-01 01:38:32 +00:00
|
|
|
if (swrenderer::fixedlightlev >= 0)
|
2016-11-14 13:19:48 +00:00
|
|
|
{
|
2017-01-16 15:23:02 +00:00
|
|
|
BaseColormap = mybasecolormap;
|
|
|
|
ColormapNum = swrenderer::fixedlightlev >> COLORMAPSHIFT;
|
2016-11-14 13:19:48 +00:00
|
|
|
}
|
|
|
|
else if (!foggy && ((thing->renderflags & RF_FULLBRIGHT) || (thing->flags5 & MF5_BRIGHT)))
|
|
|
|
{ // full bright
|
2017-01-16 15:23:02 +00:00
|
|
|
BaseColormap = mybasecolormap;
|
|
|
|
ColormapNum = 0;
|
2016-11-14 13:19:48 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{ // diminished light
|
|
|
|
double minz = double((2048 * 4) / double(1 << 20));
|
2017-01-16 15:23:02 +00:00
|
|
|
ColormapNum = GETPALOOKUP(swrenderer::r_SpriteVisibility / MAX(z, minz), spriteshade);
|
|
|
|
BaseColormap = mybasecolormap;
|
2016-11-14 13:19:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return visstyle;
|
|
|
|
}
|
2017-01-16 15:23:02 +00:00
|
|
|
#endif
|
2016-11-14 13:19:48 +00:00
|
|
|
|
|
|
|
FTexture *RenderPolySprite::GetSpriteTexture(AActor *thing, /*out*/ bool &flipX)
|
|
|
|
{
|
2017-03-12 17:54:39 +00:00
|
|
|
const auto &viewpoint = PolyRenderer::Instance()->Thread.Viewport->viewpoint;
|
2016-11-14 13:19:48 +00:00
|
|
|
flipX = false;
|
|
|
|
if (thing->picnum.isValid())
|
|
|
|
{
|
|
|
|
FTexture *tex = TexMan(thing->picnum);
|
|
|
|
if (tex->UseType == FTexture::TEX_Null)
|
|
|
|
{
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (tex->Rotations != 0xFFFF)
|
|
|
|
{
|
|
|
|
// choose a different rotation based on player view
|
|
|
|
spriteframe_t *sprframe = &SpriteFrames[tex->Rotations];
|
2017-03-12 17:54:39 +00:00
|
|
|
DVector3 pos = thing->InterpolatedPosition(viewpoint.TicFrac);
|
|
|
|
pos.Z += thing->GetBobOffset(viewpoint.TicFrac);
|
|
|
|
DAngle ang = (pos - viewpoint.Pos).Angle();
|
2016-11-14 13:19:48 +00:00
|
|
|
angle_t rot;
|
|
|
|
if (sprframe->Texture[0] == sprframe->Texture[1])
|
|
|
|
{
|
|
|
|
rot = (ang - thing->Angles.Yaw + 45.0 / 2 * 9).BAMs() >> 28;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
rot = (ang - thing->Angles.Yaw + (45.0 / 2 * 9 - 180.0 / 16)).BAMs() >> 28;
|
|
|
|
}
|
|
|
|
flipX = (sprframe->Flip & (1 << rot)) != 0;
|
|
|
|
tex = TexMan[sprframe->Texture[rot]]; // Do not animate the rotation
|
|
|
|
}
|
|
|
|
return tex;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// decide which texture to use for the sprite
|
|
|
|
int spritenum = thing->sprite;
|
|
|
|
if (spritenum >= (signed)sprites.Size() || spritenum < 0)
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
spritedef_t *sprdef = &sprites[spritenum];
|
|
|
|
if (thing->frame >= sprdef->numframes)
|
|
|
|
{
|
|
|
|
// If there are no frames at all for this sprite, don't draw it.
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
//picnum = SpriteFrames[sprdef->spriteframes + thing->frame].Texture[0];
|
|
|
|
// choose a different rotation based on player view
|
|
|
|
spriteframe_t *sprframe = &SpriteFrames[sprdef->spriteframes + thing->frame];
|
2017-03-12 17:54:39 +00:00
|
|
|
DVector3 pos = thing->InterpolatedPosition(viewpoint.TicFrac);
|
|
|
|
pos.Z += thing->GetBobOffset(viewpoint.TicFrac);
|
|
|
|
DAngle ang = (pos - viewpoint.Pos).Angle();
|
2016-11-14 13:19:48 +00:00
|
|
|
angle_t rot;
|
|
|
|
if (sprframe->Texture[0] == sprframe->Texture[1])
|
|
|
|
{
|
|
|
|
rot = (ang - thing->Angles.Yaw + 45.0 / 2 * 9).BAMs() >> 28;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
rot = (ang - thing->Angles.Yaw + (45.0 / 2 * 9 - 180.0 / 16)).BAMs() >> 28;
|
|
|
|
}
|
|
|
|
flipX = (sprframe->Flip & (1 << rot)) != 0;
|
|
|
|
return TexMan[sprframe->Texture[rot]]; // Do not animate the rotation
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|