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"
|
|
|
|
#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"
|
|
|
|
#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"
|
2017-01-26 07:13:39 +00:00
|
|
|
#include "swrenderer/scene/r_opaque_pass.h"
|
|
|
|
#include "swrenderer/scene/r_3dfloors.h"
|
|
|
|
#include "swrenderer/scene/r_translucent_pass.h"
|
2016-12-31 11:45:07 +00:00
|
|
|
#include "swrenderer/scene/r_portal.h"
|
2017-01-12 15:21:46 +00:00
|
|
|
#include "swrenderer/scene/r_viewport.h"
|
|
|
|
#include "swrenderer/scene/r_light.h"
|
2017-01-26 07:13:39 +00:00
|
|
|
#include "swrenderer/segments/r_drawsegment.h"
|
|
|
|
#include "swrenderer/line/r_renderdrawsegment.h"
|
|
|
|
#include "swrenderer/things/r_particle.h"
|
|
|
|
#include "swrenderer/drawers/r_draw_rgba.h"
|
|
|
|
#include "swrenderer/drawers/r_draw_pal.h"
|
|
|
|
#include "swrenderer/r_memory.h"
|
2016-12-30 06:26:25 +00:00
|
|
|
|
2017-01-28 22:37:57 +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;
|
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;
|
2017-02-01 15:02:21 +00:00
|
|
|
|
|
|
|
auto viewport = RenderViewport::Instance();
|
2016-12-30 06:26:25 +00:00
|
|
|
|
|
|
|
yscale = xscale; // YaspectMul is not needed for particles as they should always be square
|
|
|
|
ty = particle->Pos.Z - ViewPos.Z;
|
2017-02-01 15:02:21 +00:00
|
|
|
y1 = xs_RoundToInt(viewport->CenterY - (ty + psize) * yscale);
|
|
|
|
y2 = xs_RoundToInt(viewport->CenterY - (ty - psize) * yscale);
|
2016-12-30 06:26:25 +00:00
|
|
|
|
|
|
|
// 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;
|
2017-01-17 00:30:12 +00:00
|
|
|
FDynamicColormap *map;
|
2016-12-30 06:26:25 +00:00
|
|
|
|
|
|
|
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-23 05:17:25 +00:00
|
|
|
|
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;
|
2017-01-12 19:13:21 +00:00
|
|
|
vis->foggy = foggy;
|
2016-12-30 06:26:25 +00:00
|
|
|
|
2017-01-26 08:49:07 +00:00
|
|
|
vis->Light.SetColormap(tiz * LightVisibility::Instance()->ParticleGlobVis(), shade, map, particle->bright != 0, false, false);
|
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
|
|
|
{
|
2017-01-16 04:26:22 +00:00
|
|
|
auto vis = this;
|
|
|
|
|
2016-12-30 06:26:25 +00:00
|
|
|
int spacing;
|
2017-01-24 03:15:54 +00:00
|
|
|
BYTE color = vis->Light.BaseColormap->Maps[vis->startfrac];
|
2016-12-30 06:26:25 +00:00
|
|
|
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
|
|
|
|
2017-01-24 03:15:54 +00:00
|
|
|
uint32_t fg = LightBgra::shade_pal_index_simple(color, LightBgra::calc_light_multiplier(LIGHTSCALE(0, vis->Light.ColormapNum << FRACBITS)));
|
2016-12-30 06:26:25 +00:00
|
|
|
|
|
|
|
// vis->renderflags holds translucency level (0-255)
|
|
|
|
fixed_t fglevel = ((vis->renderflags + 1) << 8) & ~0x3ff;
|
|
|
|
uint32_t alpha = fglevel * 256 / FRACUNIT;
|
2017-02-01 15:02:21 +00:00
|
|
|
|
|
|
|
auto viewport = RenderViewport::Instance();
|
2016-12-30 06:26:25 +00:00
|
|
|
|
2017-02-01 15:02:21 +00:00
|
|
|
spacing = viewport->RenderTarget->GetPitch();
|
2016-12-30 06:26:25 +00:00
|
|
|
|
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;
|
|
|
|
|
2017-01-26 07:36:28 +00:00
|
|
|
RenderTranslucentPass *translucentPass = RenderTranslucentPass::Instance();
|
|
|
|
|
2017-02-01 15:02:21 +00:00
|
|
|
if (viewport->r_swtruecolor)
|
2016-12-30 06:26:25 +00:00
|
|
|
{
|
|
|
|
for (int x = x1; x < (x1 + countbase); x++, fracposx += fracstepx)
|
|
|
|
{
|
2017-01-26 07:36:28 +00:00
|
|
|
if (translucentPass->ClipSpriteColumnWithPortals(x, vis))
|
2016-12-30 06:26:25 +00:00
|
|
|
continue;
|
2017-02-01 15:02:21 +00:00
|
|
|
uint32_t *dest = ylookup[yl] + x + (uint32_t*)viewport->dc_destorg;
|
2016-12-30 06:26:25 +00:00
|
|
|
DrawerCommandQueue::QueueCommand<DrawParticleColumnRGBACommand>(dest, yl, spacing, ycount, fg, alpha, fracposx);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for (int x = x1; x < (x1 + countbase); x++, fracposx += fracstepx)
|
|
|
|
{
|
2017-01-26 07:36:28 +00:00
|
|
|
if (translucentPass->ClipSpriteColumnWithPortals(x, vis))
|
2016-12-30 06:26:25 +00:00
|
|
|
continue;
|
2017-02-01 15:02:21 +00:00
|
|
|
uint8_t *dest = ylookup[yl] + x + viewport->dc_destorg;
|
2016-12-30 06:26:25 +00:00
|
|
|
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.
|
2017-01-26 07:01:44 +00:00
|
|
|
DrawSegmentList *segmentlist = DrawSegmentList::Instance();
|
|
|
|
for (unsigned int p = segmentlist->InterestingDrawsegs.Size(); p-- > segmentlist->FirstInterestingDrawseg; )
|
2016-12-30 06:26:25 +00:00
|
|
|
{
|
2017-01-26 07:01:44 +00:00
|
|
|
DrawSegment *ds = &segmentlist->drawsegs[segmentlist->InterestingDrawsegs[p]];
|
2016-12-30 06:26:25 +00:00
|
|
|
// 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)
|
2017-01-26 07:01:44 +00:00
|
|
|
{
|
|
|
|
RenderDrawSegment renderer;
|
|
|
|
renderer.Render(ds, MAX<int>(ds->x1, x1), MIN<int>(ds->x2, x2));
|
|
|
|
}
|
2016-12-30 06:26:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|