qzdoom/src/polyrenderer/scene/poly_particle.cpp

88 lines
3.1 KiB
C++
Raw Normal View History

/*
** Particle drawing
** 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_particle.h"
#include "polyrenderer/poly_renderer.h"
#include "polyrenderer/scene/poly_light.h"
void RenderPolyParticle::Render(const TriMatrix &worldToClip, const Vec4f &clipPlane, particle_t *particle, subsector_t *sub, uint32_t subsectorDepth, uint32_t stencilValue)
{
2016-11-17 00:29:08 +00:00
DVector3 pos = particle->Pos;
double psize = particle->size / 8.0;
double zpos = pos.Z;
const auto &viewpoint = PolyRenderer::Instance()->Viewpoint;
2016-11-17 00:29:08 +00:00
DVector2 points[2] =
{
{ pos.X - viewpoint.Sin * psize, pos.Y + viewpoint.Cos * psize },
{ pos.X + viewpoint.Sin * psize, pos.Y - viewpoint.Cos * psize }
2016-11-17 00:29:08 +00:00
};
TriVertex *vertices = PolyRenderer::Instance()->FrameMemory.AllocMemory<TriVertex>(4);
2016-11-17 00:29:08 +00:00
bool foggy = false;
int actualextralight = foggy ? 0 : viewpoint.extralight << 4;
2016-11-17 00:29:08 +00:00
std::pair<float, float> offsets[4] =
{
{ 0.0f, 1.0f },
{ 1.0f, 1.0f },
{ 1.0f, 0.0f },
{ 0.0f, 0.0f },
};
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)(zpos + psize * (2.0 * offsets[i].second - 1.0));
vertices[i].w = 1.0f;
vertices[i].varying[0] = (float)(offsets[i].first);
vertices[i].varying[1] = (float)(1.0f - offsets[i].second);
}
bool fullbrightSprite = particle->bright != 0;
2017-03-26 08:10:55 +00:00
int lightlevel = fullbrightSprite ? 255 : sub->sector->lightlevel + actualextralight;
2016-11-17 00:29:08 +00:00
PolyDrawArgs args;
2017-03-26 08:10:55 +00:00
args.SetLight(GetColorTable(sub->sector->Colormap), lightlevel, PolyRenderer::Instance()->Light.ParticleGlobVis(foggy), fullbrightSprite);
args.SetSubsectorDepth(subsectorDepth);
args.SetSubsectorDepthTest(true);
args.SetColor(particle->color | 0xff000000, particle->color >> 24);
args.SetStyle(TriBlendMode::AlphaBlend, particle->alpha, 1.0 - particle->alpha);
args.SetTransform(&worldToClip);
args.SetFaceCullCCW(true);
args.SetStencilTestValue(stencilValue);
args.SetWriteStencil(false);
args.SetWriteSubsectorDepth(false);
args.SetClipPlane(clipPlane.x, clipPlane.y, clipPlane.z, clipPlane.w);
2017-03-26 08:10:55 +00:00
args.DrawArray(vertices, 4, PolyDrawMode::TriangleFan);
}