2017-01-03 06:17:54 +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.
|
|
|
|
//
|
2016-12-30 06:26:25 +00:00
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <algorithm>
|
|
|
|
#include "p_lnspec.h"
|
|
|
|
#include "templates.h"
|
|
|
|
#include "doomdef.h"
|
|
|
|
#include "m_swap.h"
|
|
|
|
#include "i_system.h"
|
|
|
|
#include "w_wad.h"
|
2016-12-31 11:45:07 +00:00
|
|
|
#include "swrenderer/things/r_particle.h"
|
2016-12-30 06:26:25 +00:00
|
|
|
#include "c_console.h"
|
|
|
|
#include "c_cvars.h"
|
|
|
|
#include "c_dispatch.h"
|
|
|
|
#include "doomstat.h"
|
|
|
|
#include "v_video.h"
|
|
|
|
#include "sc_man.h"
|
|
|
|
#include "s_sound.h"
|
|
|
|
#include "sbar.h"
|
|
|
|
#include "gi.h"
|
|
|
|
#include "r_sky.h"
|
|
|
|
#include "cmdlib.h"
|
|
|
|
#include "g_level.h"
|
|
|
|
#include "d_net.h"
|
|
|
|
#include "colormatcher.h"
|
|
|
|
#include "d_netinf.h"
|
|
|
|
#include "p_effect.h"
|
2017-01-11 19:42:39 +00:00
|
|
|
#include "swrenderer/scene/r_opaque_pass.h"
|
2016-12-31 11:45:07 +00:00
|
|
|
#include "swrenderer/scene/r_3dfloors.h"
|
2017-01-11 19:42:39 +00:00
|
|
|
#include "swrenderer/scene/r_translucent_pass.h"
|
2016-12-30 06:26:25 +00:00
|
|
|
#include "swrenderer/drawers/r_draw_rgba.h"
|
|
|
|
#include "swrenderer/drawers/r_draw_pal.h"
|
|
|
|
#include "v_palette.h"
|
|
|
|
#include "r_data/r_translate.h"
|
|
|
|
#include "r_data/colormaps.h"
|
|
|
|
#include "r_data/voxels.h"
|
|
|
|
#include "p_local.h"
|
|
|
|
#include "p_maputl.h"
|
|
|
|
#include "r_voxel.h"
|
2016-12-31 11:45:07 +00:00
|
|
|
#include "swrenderer/segments/r_drawsegment.h"
|
|
|
|
#include "swrenderer/scene/r_portal.h"
|
2016-12-30 06:26:25 +00:00
|
|
|
#include "swrenderer/r_memory.h"
|
2017-01-12 15:21:46 +00:00
|
|
|
#include "swrenderer/scene/r_viewport.h"
|
|
|
|
#include "swrenderer/scene/r_light.h"
|
2016-12-30 06:26:25 +00:00
|
|
|
|
2017-01-11 14:41:42 +00:00
|
|
|
EXTERN_CVAR(Bool, r_fullbrightignoresectorcolor);
|
|
|
|
|
2016-12-30 06:26:25 +00:00
|
|
|
namespace swrenderer
|
|
|
|
{
|
2017-01-12 19:13:21 +00:00
|
|
|
void RenderParticle::Project(particle_t *particle, const sector_t *sector, int shade, WaterFakeSide fakeside, bool foggy)
|
2016-12-30 06:26:25 +00:00
|
|
|
{
|
|
|
|
double tr_x, tr_y;
|
|
|
|
double tx, ty;
|
|
|
|
double tz, tiz;
|
|
|
|
double xscale, yscale;
|
|
|
|
int x1, x2, y1, y2;
|
|
|
|
sector_t* heightsec = NULL;
|
|
|
|
FSWColormap* map;
|
2017-01-05 03:55:26 +00:00
|
|
|
|
|
|
|
RenderPortal *renderportal = RenderPortal::Instance();
|
2016-12-30 06:26:25 +00:00
|
|
|
|
|
|
|
// [ZZ] Particle not visible through the portal plane
|
2017-01-05 03:55:26 +00:00
|
|
|
if (renderportal->CurrentPortal && !!P_PointOnLineSide(particle->Pos, renderportal->CurrentPortal->dst))
|
2016-12-30 06:26:25 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
// transform the origin point
|
|
|
|
tr_x = particle->Pos.X - ViewPos.X;
|
|
|
|
tr_y = particle->Pos.Y - ViewPos.Y;
|
|
|
|
|
|
|
|
tz = tr_x * ViewTanCos + tr_y * ViewTanSin;
|
|
|
|
|
|
|
|
// particle is behind view plane?
|
|
|
|
if (tz < MINZ)
|
|
|
|
return;
|
|
|
|
|
|
|
|
tx = tr_x * ViewSin - tr_y * ViewCos;
|
|
|
|
|
|
|
|
// Flip for mirrors
|
2017-01-05 03:55:26 +00:00
|
|
|
if (renderportal->MirrorFlags & RF_XFLIP)
|
2016-12-30 06:26:25 +00:00
|
|
|
{
|
|
|
|
tx = viewwidth - tx - 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// too far off the side?
|
|
|
|
if (tz <= fabs(tx))
|
|
|
|
return;
|
|
|
|
|
|
|
|
tiz = 1 / tz;
|
|
|
|
xscale = centerx * tiz;
|
|
|
|
|
|
|
|
// calculate edges of the shape
|
|
|
|
double psize = particle->size / 8.0;
|
|
|
|
|
2017-01-05 03:55:26 +00:00
|
|
|
x1 = MAX<int>(renderportal->WindowLeft, centerx + xs_RoundToInt((tx - psize) * xscale));
|
|
|
|
x2 = MIN<int>(renderportal->WindowRight, centerx + xs_RoundToInt((tx + psize) * xscale));
|
2016-12-30 06:26:25 +00:00
|
|
|
|
|
|
|
if (x1 >= x2)
|
|
|
|
return;
|
|
|
|
|
|
|
|
yscale = xscale; // YaspectMul is not needed for particles as they should always be square
|
|
|
|
ty = particle->Pos.Z - ViewPos.Z;
|
|
|
|
y1 = xs_RoundToInt(CenterY - (ty + psize) * yscale);
|
|
|
|
y2 = xs_RoundToInt(CenterY - (ty - psize) * yscale);
|
|
|
|
|
|
|
|
// Clip the particle now. Because it's a point and projected as its subsector is
|
|
|
|
// entered, we don't need to clip it to drawsegs like a normal sprite.
|
|
|
|
|
|
|
|
// Clip particles behind walls.
|
2017-01-11 19:42:39 +00:00
|
|
|
auto ceilingclip = RenderOpaquePass::Instance()->ceilingclip;
|
|
|
|
auto floorclip = RenderOpaquePass::Instance()->floorclip;
|
2016-12-30 06:26:25 +00:00
|
|
|
if (y1 < ceilingclip[x1]) y1 = ceilingclip[x1];
|
|
|
|
if (y1 < ceilingclip[x2 - 1]) y1 = ceilingclip[x2 - 1];
|
|
|
|
if (y2 >= floorclip[x1]) y2 = floorclip[x1] - 1;
|
|
|
|
if (y2 >= floorclip[x2 - 1]) y2 = floorclip[x2 - 1] - 1;
|
|
|
|
|
|
|
|
if (y1 > y2)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Clip particles above the ceiling or below the floor.
|
|
|
|
heightsec = sector->GetHeightSec();
|
|
|
|
|
|
|
|
const secplane_t *topplane;
|
|
|
|
const secplane_t *botplane;
|
|
|
|
FTextureID toppic;
|
|
|
|
FTextureID botpic;
|
|
|
|
|
|
|
|
if (heightsec) // only clip things which are in special sectors
|
|
|
|
{
|
2017-01-04 18:03:33 +00:00
|
|
|
if (fakeside == WaterFakeSide::AboveCeiling)
|
2016-12-30 06:26:25 +00:00
|
|
|
{
|
|
|
|
topplane = §or->ceilingplane;
|
|
|
|
botplane = &heightsec->ceilingplane;
|
|
|
|
toppic = sector->GetTexture(sector_t::ceiling);
|
|
|
|
botpic = heightsec->GetTexture(sector_t::ceiling);
|
|
|
|
map = heightsec->ColorMap;
|
|
|
|
}
|
2017-01-04 18:03:33 +00:00
|
|
|
else if (fakeside == WaterFakeSide::BelowFloor)
|
2016-12-30 06:26:25 +00:00
|
|
|
{
|
|
|
|
topplane = &heightsec->floorplane;
|
|
|
|
botplane = §or->floorplane;
|
|
|
|
toppic = heightsec->GetTexture(sector_t::floor);
|
|
|
|
botpic = sector->GetTexture(sector_t::floor);
|
|
|
|
map = heightsec->ColorMap;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
topplane = &heightsec->ceilingplane;
|
|
|
|
botplane = &heightsec->floorplane;
|
|
|
|
toppic = heightsec->GetTexture(sector_t::ceiling);
|
|
|
|
botpic = heightsec->GetTexture(sector_t::floor);
|
|
|
|
map = sector->ColorMap;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
topplane = §or->ceilingplane;
|
|
|
|
botplane = §or->floorplane;
|
|
|
|
toppic = sector->GetTexture(sector_t::ceiling);
|
|
|
|
botpic = sector->GetTexture(sector_t::floor);
|
|
|
|
map = sector->ColorMap;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (botpic != skyflatnum && particle->Pos.Z < botplane->ZatPoint(particle->Pos))
|
|
|
|
return;
|
|
|
|
if (toppic != skyflatnum && particle->Pos.Z >= topplane->ZatPoint(particle->Pos))
|
|
|
|
return;
|
|
|
|
|
|
|
|
// store information in a vissprite
|
2017-01-16 04:26:22 +00:00
|
|
|
RenderParticle *vis = RenderMemory::NewObject<RenderParticle>();
|
2017-01-05 03:55:26 +00:00
|
|
|
vis->CurrentPortalUniq = renderportal->CurrentPortalUniq;
|
2016-12-30 06:26:25 +00:00
|
|
|
vis->heightsec = heightsec;
|
|
|
|
vis->xscale = FLOAT2FIXED(xscale);
|
|
|
|
vis->yscale = (float)xscale;
|
|
|
|
// vis->yscale *= InvZtoScale;
|
|
|
|
vis->depth = (float)tz;
|
|
|
|
vis->idepth = float(1 / tz);
|
|
|
|
vis->gpos = { (float)particle->Pos.X, (float)particle->Pos.Y, (float)particle->Pos.Z };
|
|
|
|
vis->y1 = y1;
|
|
|
|
vis->y2 = y2;
|
|
|
|
vis->x1 = x1;
|
|
|
|
vis->x2 = x2;
|
|
|
|
vis->Translation = 0;
|
|
|
|
vis->startfrac = 255 & (particle->color >> 24);
|
|
|
|
vis->pic = NULL;
|
2017-01-07 16:44:15 +00:00
|
|
|
vis->renderflags = (short)(particle->alpha * 255.0f + 0.5f);
|
2016-12-30 06:26:25 +00:00
|
|
|
vis->FakeFlatStat = fakeside;
|
|
|
|
vis->floorclip = 0;
|
|
|
|
vis->Style.ColormapNum = 0;
|
2017-01-12 19:13:21 +00:00
|
|
|
vis->foggy = foggy;
|
2016-12-30 06:26:25 +00:00
|
|
|
|
|
|
|
if (fixedlightlev >= 0)
|
|
|
|
{
|
|
|
|
vis->Style.BaseColormap = map;
|
|
|
|
vis->Style.ColormapNum = fixedlightlev >> COLORMAPSHIFT;
|
|
|
|
}
|
|
|
|
else if (fixedcolormap)
|
|
|
|
{
|
|
|
|
vis->Style.BaseColormap = fixedcolormap;
|
|
|
|
vis->Style.ColormapNum = 0;
|
|
|
|
}
|
|
|
|
else if (particle->bright)
|
|
|
|
{
|
|
|
|
vis->Style.BaseColormap = (r_fullbrightignoresectorcolor) ? &FullNormalLight : map;
|
|
|
|
vis->Style.ColormapNum = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Particles are slightly more visible than regular sprites.
|
|
|
|
vis->Style.ColormapNum = GETPALOOKUP(tiz * r_SpriteVisibility * 0.5, shade);
|
|
|
|
vis->Style.BaseColormap = map;
|
|
|
|
}
|
2017-01-16 02:46:05 +00:00
|
|
|
|
|
|
|
VisibleSpriteList::Instance()->Push(vis);
|
2016-12-30 06:26:25 +00:00
|
|
|
}
|
|
|
|
|
2017-01-16 04:26:22 +00:00
|
|
|
void RenderParticle::Render(short *cliptop, short *clipbottom, int minZ, int maxZ)
|
2016-12-30 06:26:25 +00:00
|
|
|
{
|
|
|
|
using namespace drawerargs;
|
|
|
|
|
2017-01-16 04:26:22 +00:00
|
|
|
auto vis = this;
|
|
|
|
|
2016-12-30 06:26:25 +00:00
|
|
|
int spacing;
|
|
|
|
BYTE color = vis->Style.BaseColormap->Maps[vis->startfrac];
|
|
|
|
int yl = vis->y1;
|
|
|
|
int ycount = vis->y2 - yl + 1;
|
|
|
|
int x1 = vis->x1;
|
|
|
|
int countbase = vis->x2 - x1;
|
|
|
|
|
|
|
|
if (ycount <= 0 || countbase <= 0)
|
|
|
|
return;
|
|
|
|
|
2017-01-16 04:26:22 +00:00
|
|
|
DrawMaskedSegsBehindParticle();
|
2016-12-30 06:26:25 +00:00
|
|
|
|
|
|
|
uint32_t fg = LightBgra::shade_pal_index_simple(color, LightBgra::calc_light_multiplier(LIGHTSCALE(0, vis->Style.ColormapNum << FRACBITS)));
|
|
|
|
|
|
|
|
// vis->renderflags holds translucency level (0-255)
|
|
|
|
fixed_t fglevel = ((vis->renderflags + 1) << 8) & ~0x3ff;
|
|
|
|
uint32_t alpha = fglevel * 256 / FRACUNIT;
|
|
|
|
|
|
|
|
spacing = RenderTarget->GetPitch();
|
|
|
|
|
2017-01-13 15:12:43 +00:00
|
|
|
uint32_t fracstepx = PARTICLE_TEXTURE_SIZE * FRACUNIT / countbase;
|
2016-12-30 06:26:25 +00:00
|
|
|
uint32_t fracposx = fracstepx / 2;
|
|
|
|
|
|
|
|
if (r_swtruecolor)
|
|
|
|
{
|
|
|
|
for (int x = x1; x < (x1 + countbase); x++, fracposx += fracstepx)
|
|
|
|
{
|
2017-01-11 19:42:39 +00:00
|
|
|
if (RenderTranslucentPass::ClipSpriteColumnWithPortals(x, vis))
|
2016-12-30 06:26:25 +00:00
|
|
|
continue;
|
|
|
|
uint32_t *dest = ylookup[yl] + x + (uint32_t*)dc_destorg;
|
|
|
|
DrawerCommandQueue::QueueCommand<DrawParticleColumnRGBACommand>(dest, yl, spacing, ycount, fg, alpha, fracposx);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for (int x = x1; x < (x1 + countbase); x++, fracposx += fracstepx)
|
|
|
|
{
|
2017-01-11 19:42:39 +00:00
|
|
|
if (RenderTranslucentPass::ClipSpriteColumnWithPortals(x, vis))
|
2016-12-30 06:26:25 +00:00
|
|
|
continue;
|
|
|
|
uint8_t *dest = ylookup[yl] + x + dc_destorg;
|
|
|
|
DrawerCommandQueue::QueueCommand<DrawParticleColumnPalCommand>(dest, yl, spacing, ycount, fg, alpha, fracposx);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-16 04:26:22 +00:00
|
|
|
void RenderParticle::DrawMaskedSegsBehindParticle()
|
2016-12-30 06:26:25 +00:00
|
|
|
{
|
|
|
|
// Draw any masked textures behind this particle so that when the
|
|
|
|
// particle is drawn, it will be in front of them.
|
|
|
|
for (unsigned int p = InterestingDrawsegs.Size(); p-- > FirstInterestingDrawseg; )
|
|
|
|
{
|
|
|
|
drawseg_t *ds = &drawsegs[InterestingDrawsegs[p]];
|
|
|
|
// kg3D - no fake segs
|
|
|
|
if (ds->fake) continue;
|
|
|
|
if (ds->x1 >= x2 || ds->x2 <= x1)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
2017-01-16 04:26:22 +00:00
|
|
|
if ((ds->siz2 - ds->siz1) * ((x2 + x1) / 2 - ds->sx1) / (ds->sx2 - ds->sx1) + ds->siz1 < idepth)
|
2016-12-30 06:26:25 +00:00
|
|
|
{
|
|
|
|
// [ZZ] only draw stuff that's inside the same portal as the particle, other portals will care for themselves
|
2017-01-16 04:26:22 +00:00
|
|
|
if (ds->CurrentPortalUniq == CurrentPortalUniq)
|
2016-12-30 06:26:25 +00:00
|
|
|
R_RenderMaskedSegRange(ds, MAX<int>(ds->x1, x1), MIN<int>(ds->x2, x2));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|