- remove softpoly intersection math class

This commit is contained in:
Magnus Norddahl 2017-03-26 17:12:20 +02:00
parent 28be42675d
commit a12f0862c9
25 changed files with 59 additions and 501 deletions

View file

@ -872,7 +872,6 @@ set( POLYRENDER_SOURCES
polyrenderer/drawers/poly_draw_args.cpp
polyrenderer/drawers/screen_triangle.cpp
polyrenderer/math/tri_matrix.cpp
polyrenderer/math/poly_intersection.cpp
)
# These files will be flagged as "headers" so that they appear in project files

View file

@ -37,12 +37,12 @@
#include "poly_draw_args.h"
#include "swrenderer/viewport/r_viewport.h"
void PolyDrawArgs::SetClipPlane(float a, float b, float c, float d)
void PolyDrawArgs::SetClipPlane(const PolyClipPlane &plane)
{
mClipPlane[0] = a;
mClipPlane[1] = b;
mClipPlane[2] = c;
mClipPlane[3] = d;
mClipPlane[0] = plane.A;
mClipPlane[1] = plane.B;
mClipPlane[2] = plane.C;
mClipPlane[3] = plane.D;
}
void PolyDrawArgs::SetTexture(FTexture *texture)

View file

@ -36,10 +36,19 @@ enum class PolyDrawMode
TriangleStrip
};
class PolyClipPlane
{
public:
PolyClipPlane() : A(0.0f), B(0.0f), C(0.0f), D(1.0f) { }
PolyClipPlane(float a, float b, float c, float d) : A(a), B(b), C(c), D(d) { }
float A, B, C, D;
};
class PolyDrawArgs
{
public:
void SetClipPlane(float a, float b, float c, float d);
void SetClipPlane(const PolyClipPlane &plane);
void SetTexture(FTexture *texture);
void SetTexture(FTexture *texture, uint32_t translationID, bool forcePal = false);
void SetLight(FSWColormap *basecolormap, uint32_t lightlevel, double globVis, bool fixed);

View file

@ -1,235 +0,0 @@
/*
** Various 3D intersection tests
** Copyright (c) 1997-2015 The UICore Team
**
** 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 "poly_intersection.h"
IntersectionTest::Result IntersectionTest::plane_aabb(const Vec4f &plane, const AxisAlignedBoundingBox &aabb)
{
Vec3f center = aabb.center();
Vec3f extents = aabb.extents();
float e = extents.x * std::abs(plane.x) + extents.y * std::abs(plane.y) + extents.z * std::abs(plane.z);
float s = center.x * plane.x + center.y * plane.y + center.z * plane.z + plane.w;
if (s - e > 0)
return inside;
else if (s + e < 0)
return outside;
else
return intersecting;
}
IntersectionTest::Result IntersectionTest::plane_obb(const Vec4f &plane, const OrientedBoundingBox &obb)
{
Vec3f n(plane);
float d = plane.w;
float e = obb.extents.x * std::abs(Vec3f::dot(obb.axis_x, n)) + obb.extents.y * std::abs(Vec3f::dot(obb.axis_y, n)) + obb.extents.z * std::abs(Vec3f::dot(obb.axis_z, n));
float s = Vec3f::dot(obb.center, n) + d;
if (s - e > 0)
return inside;
else if (s + e < 0)
return outside;
else
return intersecting;
}
IntersectionTest::OverlapResult IntersectionTest::sphere(const Vec3f &center1, float radius1, const Vec3f &center2, float radius2)
{
Vec3f h = center1 - center2;
float square_distance = Vec3f::dot(h, h);
float radius_sum = radius1 + radius2;
if (square_distance > radius_sum * radius_sum)
return disjoint;
else
return overlap;
}
IntersectionTest::OverlapResult IntersectionTest::sphere_aabb(const Vec3f &center, float radius, const AxisAlignedBoundingBox &aabb)
{
Vec3f a = aabb.aabb_min - center;
Vec3f b = center - aabb.aabb_max;
a.x = std::max(a.x, 0.0f);
a.y = std::max(a.y, 0.0f);
a.z = std::max(a.z, 0.0f);
b.x = std::max(b.x, 0.0f);
b.y = std::max(b.y, 0.0f);
b.z = std::max(b.z, 0.0f);
Vec3f e = a + b;
float d = Vec3f::dot(e, e);
if (d > radius * radius)
return disjoint;
else
return overlap;
}
IntersectionTest::OverlapResult IntersectionTest::aabb(const AxisAlignedBoundingBox &a, const AxisAlignedBoundingBox &b)
{
if (a.aabb_min.x > b.aabb_max.x || b.aabb_min.x > a.aabb_max.x ||
a.aabb_min.y > b.aabb_max.y || b.aabb_min.y > a.aabb_max.y ||
a.aabb_min.z > b.aabb_max.z || b.aabb_min.z > a.aabb_max.z)
{
return disjoint;
}
else
{
return overlap;
}
}
IntersectionTest::Result IntersectionTest::frustum_aabb(const FrustumPlanes &frustum, const AxisAlignedBoundingBox &box)
{
bool is_intersecting = false;
for (int i = 0; i < 6; i++)
{
Result result = plane_aabb(frustum.planes[i], box);
if (result == outside)
return outside;
else if (result == intersecting)
is_intersecting = true;
break;
}
if (is_intersecting)
return intersecting;
else
return inside;
}
IntersectionTest::Result IntersectionTest::frustum_obb(const FrustumPlanes &frustum, const OrientedBoundingBox &box)
{
bool is_intersecting = false;
for (int i = 0; i < 6; i++)
{
Result result = plane_obb(frustum.planes[i], box);
if (result == outside)
return outside;
else if (result == intersecting)
is_intersecting = true;
}
if (is_intersecting)
return intersecting;
else
return inside;
}
IntersectionTest::OverlapResult IntersectionTest::ray_aabb(const Vec3f &ray_start, const Vec3f &ray_end, const AxisAlignedBoundingBox &aabb)
{
Vec3f c = (ray_start + ray_end) * 0.5f;
Vec3f w = ray_end - c;
Vec3f h = aabb.extents();
c -= aabb.center();
Vec3f v(std::abs(w.x), std::abs(w.y), std::abs(w.z));
if (std::abs(c.x) > v.x + h.x || std::abs(c.y) > v.y + h.y || std::abs(c.z) > v.z + h.z)
return disjoint;
if (std::abs(c.y * w.z - c.z * w.y) > h.y * v.z + h.z * v.y ||
std::abs(c.x * w.z - c.z * w.x) > h.x * v.z + h.z * v.x ||
std::abs(c.x * w.y - c.y * w.x) > h.x * v.y + h.y * v.x)
return disjoint;
return overlap;
}
/////////////////////////////////////////////////////////////////////////////
FrustumPlanes::FrustumPlanes()
{
}
FrustumPlanes::FrustumPlanes(const Mat4f &world_to_projection)
{
planes[0] = near_frustum_plane(world_to_projection);
planes[1] = far_frustum_plane(world_to_projection);
planes[2] = left_frustum_plane(world_to_projection);
planes[3] = right_frustum_plane(world_to_projection);
planes[4] = top_frustum_plane(world_to_projection);
planes[5] = bottom_frustum_plane(world_to_projection);
}
Vec4f FrustumPlanes::left_frustum_plane(const Mat4f &m)
{
Vec4f plane(
m.matrix[3 + 0 * 4] + m.matrix[0 + 0 * 4],
m.matrix[3 + 1 * 4] + m.matrix[0 + 1 * 4],
m.matrix[3 + 2 * 4] + m.matrix[0 + 2 * 4],
m.matrix[3 + 3 * 4] + m.matrix[0 + 3 * 4]);
plane /= plane.length3();
return plane;
}
Vec4f FrustumPlanes::right_frustum_plane(const Mat4f &m)
{
Vec4f plane(
m.matrix[3 + 0 * 4] - m.matrix[0 + 0 * 4],
m.matrix[3 + 1 * 4] - m.matrix[0 + 1 * 4],
m.matrix[3 + 2 * 4] - m.matrix[0 + 2 * 4],
m.matrix[3 + 3 * 4] - m.matrix[0 + 3 * 4]);
plane /= plane.length3();
return plane;
}
Vec4f FrustumPlanes::top_frustum_plane(const Mat4f &m)
{
Vec4f plane(
m.matrix[3 + 0 * 4] - m.matrix[1 + 0 * 4],
m.matrix[3 + 1 * 4] - m.matrix[1 + 1 * 4],
m.matrix[3 + 2 * 4] - m.matrix[1 + 2 * 4],
m.matrix[3 + 3 * 4] - m.matrix[1 + 3 * 4]);
plane /= plane.length3();
return plane;
}
Vec4f FrustumPlanes::bottom_frustum_plane(const Mat4f &m)
{
Vec4f plane(
m.matrix[3 + 0 * 4] + m.matrix[1 + 0 * 4],
m.matrix[3 + 1 * 4] + m.matrix[1 + 1 * 4],
m.matrix[3 + 2 * 4] + m.matrix[1 + 2 * 4],
m.matrix[3 + 3 * 4] + m.matrix[1 + 3 * 4]);
plane /= plane.length3();
return plane;
}
Vec4f FrustumPlanes::near_frustum_plane(const Mat4f &m)
{
Vec4f plane(
m.matrix[3 + 0 * 4] + m.matrix[2 + 0 * 4],
m.matrix[3 + 1 * 4] + m.matrix[2 + 1 * 4],
m.matrix[3 + 2 * 4] + m.matrix[2 + 2 * 4],
m.matrix[3 + 3 * 4] + m.matrix[2 + 3 * 4]);
plane /= plane.length3();
return plane;
}
Vec4f FrustumPlanes::far_frustum_plane(const Mat4f &m)
{
Vec4f plane(
m.matrix[3 + 0 * 4] - m.matrix[2 + 0 * 4],
m.matrix[3 + 1 * 4] - m.matrix[2 + 1 * 4],
m.matrix[3 + 2 * 4] - m.matrix[2 + 2 * 4],
m.matrix[3 + 3 * 4] - m.matrix[2 + 3 * 4]);
plane /= plane.length3();
return plane;
}

View file

@ -1,179 +0,0 @@
/*
** Various 3D intersection tests
** Copyright (c) 1997-2015 The UICore Team
**
** 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.
**
*/
#pragma once
#include "polyrenderer/drawers/poly_triangle.h"
#include <algorithm>
#include <cmath>
class Vec3f;
class Vec4f
{
public:
Vec4f() = default;
Vec4f(const Vec4f &) = default;
Vec4f(float x, float y, float z, float w) : x(x), y(y), z(z), w(w) { }
Vec4f(float v) : x(v), y(v), z(v), w(v) { }
Vec4f(const Vec3f &xyz, float w);
static float dot(const Vec4f &a, const Vec4f &b) { return a.x * b.x + a.y * b.y + a.z * b.z + a.w * b.w; }
static float dot3(const Vec4f &a, const Vec4f &b) { return a.x * b.x + a.y * b.y + a.z * b.z; }
float length3() const { return std::sqrt(dot3(*this, *this)); }
float magnitude() const { return std::sqrt(dot(*this, *this)); }
Vec4f &operator+=(const Vec4f &b) { *this = Vec4f(x + b.x, y + b.y, z + b.z, w + b.w); return *this; }
Vec4f &operator-=(const Vec4f &b) { *this = Vec4f(x - b.x, y - b.y, z - b.z, w - b.w); return *this; }
Vec4f &operator*=(const Vec4f &b) { *this = Vec4f(x * b.x, y * b.y, z * b.z, w * b.w); return *this; }
Vec4f &operator/=(const Vec4f &b) { *this = Vec4f(x / b.x, y / b.y, z / b.z, w / b.w); return *this; }
Vec4f &operator+=(float b) { *this = Vec4f(x + b, y + b, z + b, w + b); return *this; }
Vec4f &operator-=(float b) { *this = Vec4f(x - b, y - b, z - b, w - b); return *this; }
Vec4f &operator*=(float b) { *this = Vec4f(x * b, y * b, z * b, w * b); return *this; }
Vec4f &operator/=(float b) { *this = Vec4f(x / b, y / b, z / b, w / b); return *this; }
float x, y, z, w;
};
inline bool operator==(const Vec4f &a, const Vec4f &b) { return a.x == b.x && a.y == b.y && a.z == b.z && a.w == b.w; }
inline bool operator!=(const Vec4f &a, const Vec4f &b) { return a.x != b.x || a.y != b.y || a.z != b.z || a.w == b.w; }
class Vec3f
{
public:
Vec3f() = default;
Vec3f(const Vec3f &) = default;
Vec3f(const Vec4f &v) : x(v.x), y(v.y), z(v.z) { }
Vec3f(float x, float y, float z) : x(x), y(y), z(z) { }
Vec3f(float v) : x(v), y(v), z(v) { }
static float dot(const Vec3f &a, const Vec3f &b) { return a.x * b.x + a.y * b.y + a.z * b.z; }
float length() const { return std::sqrt(dot(*this, *this)); }
Vec3f &operator+=(const Vec3f &b) { *this = Vec3f(x + b.x, y + b.y, z + b.z); return *this; }
Vec3f &operator-=(const Vec3f &b) { *this = Vec3f(x - b.x, y - b.y, z - b.z); return *this; }
Vec3f &operator*=(const Vec3f &b) { *this = Vec3f(x * b.x, y * b.y, z * b.z); return *this; }
Vec3f &operator/=(const Vec3f &b) { *this = Vec3f(x / b.x, y / b.y, z / b.z); return *this; }
Vec3f &operator+=(float b) { *this = Vec3f(x + b, y + b, z + b); return *this; }
Vec3f &operator-=(float b) { *this = Vec3f(x - b, y - b, z - b); return *this; }
Vec3f &operator*=(float b) { *this = Vec3f(x * b, y * b, z * b); return *this; }
Vec3f &operator/=(float b) { *this = Vec3f(x / b, y / b, z / b); return *this; }
float x, y, z;
};
inline bool operator==(const Vec3f &a, const Vec3f &b) { return a.x == b.x && a.y == b.y && a.z == b.z; }
inline bool operator!=(const Vec3f &a, const Vec3f &b) { return a.x != b.x || a.y != b.y || a.z != b.z; }
inline Vec3f operator+(const Vec3f &a, const Vec3f &b) { return Vec3f(a.x + b.x, a.y + b.y, a.z + b.z); }
inline Vec3f operator-(const Vec3f &a, const Vec3f &b) { return Vec3f(a.x - b.x, a.y - b.y, a.z - b.z); }
inline Vec3f operator*(const Vec3f &a, const Vec3f &b) { return Vec3f(a.x * b.x, a.y * b.y, a.z * b.z); }
inline Vec3f operator/(const Vec3f &a, const Vec3f &b) { return Vec3f(a.x / b.x, a.y / b.y, a.z / b.z); }
inline Vec3f operator+(const Vec3f &a, float b) { return Vec3f(a.x + b, a.y + b, a.z + b); }
inline Vec3f operator-(const Vec3f &a, float b) { return Vec3f(a.x - b, a.y - b, a.z - b); }
inline Vec3f operator*(const Vec3f &a, float b) { return Vec3f(a.x * b, a.y * b, a.z * b); }
inline Vec3f operator/(const Vec3f &a, float b) { return Vec3f(a.x / b, a.y / b, a.z / b); }
inline Vec3f operator+(float a, const Vec3f &b) { return Vec3f(a + b.x, a + b.y, a + b.z); }
inline Vec3f operator-(float a, const Vec3f &b) { return Vec3f(a - b.x, a - b.y, a - b.z); }
inline Vec3f operator*(float a, const Vec3f &b) { return Vec3f(a * b.x, a * b.y, a * b.z); }
inline Vec3f operator/(float a, const Vec3f &b) { return Vec3f(a / b.x, a / b.y, a / b.z); }
inline Vec4f::Vec4f(const Vec3f &xyz, float w) : x(xyz.x), y(xyz.y), z(xyz.z), w(w) { }
typedef TriMatrix Mat4f;
class AxisAlignedBoundingBox
{
public:
AxisAlignedBoundingBox() : aabb_min(), aabb_max() {}
AxisAlignedBoundingBox(const Vec3f &aabb_min, const Vec3f &aabb_max) : aabb_min(aabb_min), aabb_max(aabb_max) { }
AxisAlignedBoundingBox(const AxisAlignedBoundingBox &aabb, const Vec3f &barycentric_min, const Vec3f &barycentric_max)
: aabb_min(mix(aabb.aabb_min, aabb.aabb_max, barycentric_min)), aabb_max(mix(aabb.aabb_min, aabb.aabb_max, barycentric_max)) { }
Vec3f center() const { return (aabb_max + aabb_min) * 0.5f; }
Vec3f extents() const { return (aabb_max - aabb_min) * 0.5f; }
Vec3f aabb_min;
Vec3f aabb_max;
private:
template<typename A, typename B, typename C>
inline A mix(A a, B b, C mix)
{
return a * (C(1) - mix) + b * mix;
}
};
class OrientedBoundingBox
{
public:
Vec3f center;
Vec3f extents;
Vec3f axis_x;
Vec3f axis_y;
Vec3f axis_z;
};
class FrustumPlanes
{
public:
FrustumPlanes();
explicit FrustumPlanes(const Mat4f &world_to_projection);
Vec4f planes[6];
private:
static Vec4f left_frustum_plane(const Mat4f &matrix);
static Vec4f right_frustum_plane(const Mat4f &matrix);
static Vec4f top_frustum_plane(const Mat4f &matrix);
static Vec4f bottom_frustum_plane(const Mat4f &matrix);
static Vec4f near_frustum_plane(const Mat4f &matrix);
static Vec4f far_frustum_plane(const Mat4f &matrix);
};
class IntersectionTest
{
public:
enum Result
{
outside,
inside,
intersecting,
};
enum OverlapResult
{
disjoint,
overlap
};
static Result plane_aabb(const Vec4f &plane, const AxisAlignedBoundingBox &aabb);
static Result plane_obb(const Vec4f &plane, const OrientedBoundingBox &obb);
static OverlapResult sphere(const Vec3f &center1, float radius1, const Vec3f &center2, float radius2);
static OverlapResult sphere_aabb(const Vec3f &center, float radius, const AxisAlignedBoundingBox &aabb);
static OverlapResult aabb(const AxisAlignedBoundingBox &a, const AxisAlignedBoundingBox &b);
static Result frustum_aabb(const FrustumPlanes &frustum, const AxisAlignedBoundingBox &box);
static Result frustum_obb(const FrustumPlanes &frustum, const OrientedBoundingBox &box);
static OverlapResult ray_aabb(const Vec3f &ray_start, const Vec3f &ray_end, const AxisAlignedBoundingBox &box);
};

View file

@ -3,7 +3,6 @@
#include "drawers/poly_draw_args.cpp"
#include "drawers/poly_triangle.cpp"
#include "drawers/screen_triangle.cpp"
#include "math/poly_intersection.cpp"
#include "math/tri_matrix.cpp"
#include "scene/poly_cull.cpp"
#include "scene/poly_decal.cpp"

View file

@ -135,7 +135,7 @@ void PolyRenderer::RenderActorView(AActor *actor, bool dontmaplines)
ClearBuffers();
SetSceneViewport();
SetupPerspectiveMatrix();
MainPortal.SetViewpoint(WorldToClip, Vec4f(0.0f, 0.0f, 0.0f, 1.0f), GetNextStencilValue());
MainPortal.SetViewpoint(WorldToClip, PolyClipPlane(0.0f, 0.0f, 0.0f, 1.0f), GetNextStencilValue());
MainPortal.Render(0);
Skydome.Render(WorldToClip);
MainPortal.RenderTranslucent(0);

View file

@ -28,10 +28,9 @@
#include "poly_cull.h"
#include "polyrenderer/poly_renderer.h"
void PolyCull::CullScene(const TriMatrix &worldToClip, const Vec4f &portalClipPlane)
void PolyCull::CullScene(const TriMatrix &worldToClip, const PolyClipPlane &portalClipPlane)
{
PvsSectors.clear();
frustumPlanes = FrustumPlanes(worldToClip);
PortalClipPlane = portalClipPlane;
// Cull front to back
@ -210,20 +209,6 @@ int PolyCull::PointOnSide(const DVector2 &pos, const node_t *node)
bool PolyCull::CheckBBox(float *bspcoord)
{
#if 0 // This doesn't work because it creates gaps in the angle based clipper segment list :(
// Start using a quick frustum AABB test:
AxisAlignedBoundingBox aabb(Vec3f(bspcoord[BOXLEFT], bspcoord[BOXBOTTOM], (float)PolyRenderer::Instance()->Viewpoint.Pos.Z - 1000.0f), Vec3f(bspcoord[BOXRIGHT], bspcoord[BOXTOP], (float)PolyRenderer::Instance()->Viewpoint.Pos.Z + 1000.0f));
auto result = IntersectionTest::frustum_aabb(frustumPlanes, aabb);
if (result == IntersectionTest::outside)
return false;
// Skip if its in front of the portal:
if (IntersectionTest::plane_aabb(PortalClipPlane, aabb) == IntersectionTest::outside)
return false;
#endif
// Occlusion test using solid segments:
static const uint8_t checkcoord[12][4] =
{

View file

@ -23,13 +23,12 @@
#pragma once
#include "polyrenderer/drawers/poly_triangle.h"
#include "polyrenderer/math/poly_intersection.h"
class PolyCull
{
public:
void ClearSolidSegments();
void CullScene(const TriMatrix &worldToClip, const Vec4f &portalClipPlane);
void CullScene(const TriMatrix &worldToClip, const PolyClipPlane &portalClipPlane);
bool GetAnglesForLine(double x1, double y1, double x2, double y2, angle_t &angle1, angle_t &angle2) const;
void MarkSegmentCulled(angle_t angle1, angle_t angle2);
@ -61,8 +60,7 @@ private:
const int SolidCullScale = 3000;
bool FirstSkyHeight = true;
FrustumPlanes frustumPlanes;
Vec4f PortalClipPlane;
PolyClipPlane PortalClipPlane;
static angle_t PointToPseudoAngle(double x, double y);
static angle_t AngleToPseudo(angle_t ang);

View file

@ -31,7 +31,7 @@
#include "a_sharedglobal.h"
#include "swrenderer/scene/r_scene.h"
void RenderPolyDecal::RenderWallDecals(const TriMatrix &worldToClip, const Vec4f &clipPlane, const seg_t *line, uint32_t subsectorDepth, uint32_t stencilValue)
void RenderPolyDecal::RenderWallDecals(const TriMatrix &worldToClip, const PolyClipPlane &clipPlane, const seg_t *line, uint32_t subsectorDepth, uint32_t stencilValue)
{
if (line->linedef == nullptr && line->sidedef == nullptr)
return;
@ -43,7 +43,7 @@ void RenderPolyDecal::RenderWallDecals(const TriMatrix &worldToClip, const Vec4f
}
}
void RenderPolyDecal::Render(const TriMatrix &worldToClip, const Vec4f &clipPlane, DBaseDecal *decal, const seg_t *line, uint32_t subsectorDepth, uint32_t stencilValue)
void RenderPolyDecal::Render(const TriMatrix &worldToClip, const PolyClipPlane &clipPlane, DBaseDecal *decal, const seg_t *line, uint32_t subsectorDepth, uint32_t stencilValue)
{
if (decal->RenderFlags & RF_INVISIBLE || !viewactive || !decal->PicNum.isValid())
return;
@ -142,7 +142,7 @@ void RenderPolyDecal::Render(const TriMatrix &worldToClip, const Vec4f &clipPlan
args.SetFaceCullCCW(true);
args.SetStencilTestValue(stencilValue);
args.SetWriteStencil(true, stencilValue);
args.SetClipPlane(clipPlane.x, clipPlane.y, clipPlane.z, clipPlane.w);
args.SetClipPlane(clipPlane);
args.SetSubsectorDepthTest(true);
args.SetWriteStencil(false);
args.SetWriteSubsectorDepth(false);

View file

@ -24,13 +24,11 @@
#include "polyrenderer/drawers/poly_triangle.h"
class Vec4f;
class RenderPolyDecal
{
public:
static void RenderWallDecals(const TriMatrix &worldToClip, const Vec4f &clipPlane, const seg_t *line, uint32_t subsectorDepth, uint32_t stencilValue);
static void RenderWallDecals(const TriMatrix &worldToClip, const PolyClipPlane &clipPlane, const seg_t *line, uint32_t subsectorDepth, uint32_t stencilValue);
private:
void Render(const TriMatrix &worldToClip, const Vec4f &clipPlane, DBaseDecal *decal, const seg_t *line, uint32_t subsectorDepth, uint32_t stencilValue);
void Render(const TriMatrix &worldToClip, const PolyClipPlane &clipPlane, DBaseDecal *decal, const seg_t *line, uint32_t subsectorDepth, uint32_t stencilValue);
};

View file

@ -29,7 +29,7 @@
#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)
void RenderPolyParticle::Render(const TriMatrix &worldToClip, const PolyClipPlane &clipPlane, particle_t *particle, subsector_t *sub, uint32_t subsectorDepth, uint32_t stencilValue)
{
DVector3 pos = particle->Pos;
double psize = particle->size / 8.0;
@ -82,6 +82,6 @@ void RenderPolyParticle::Render(const TriMatrix &worldToClip, const Vec4f &clipP
args.SetStencilTestValue(stencilValue);
args.SetWriteStencil(false);
args.SetWriteSubsectorDepth(false);
args.SetClipPlane(clipPlane.x, clipPlane.y, clipPlane.z, clipPlane.w);
args.SetClipPlane(clipPlane);
args.DrawArray(vertices, 4, PolyDrawMode::TriangleFan);
}

View file

@ -25,10 +25,8 @@
#include "polyrenderer/drawers/poly_triangle.h"
#include "p_effect.h"
class Vec4f;
class RenderPolyParticle
{
public:
void Render(const TriMatrix &worldToClip, const Vec4f &clipPlane, particle_t *particle, subsector_t *sub, uint32_t subsectorDepth, uint32_t stencilValue);
void Render(const TriMatrix &worldToClip, const PolyClipPlane &clipPlane, particle_t *particle, subsector_t *sub, uint32_t subsectorDepth, uint32_t stencilValue);
};

View file

@ -33,7 +33,7 @@
EXTERN_CVAR(Int, r_3dfloors)
void RenderPolyPlane::RenderPlanes(const TriMatrix &worldToClip, const Vec4f &clipPlane, PolyCull &cull, subsector_t *sub, uint32_t subsectorDepth, uint32_t stencilValue, double skyCeilingHeight, double skyFloorHeight, std::vector<std::unique_ptr<PolyDrawSectorPortal>> &sectorPortals)
void RenderPolyPlane::RenderPlanes(const TriMatrix &worldToClip, const PolyClipPlane &clipPlane, PolyCull &cull, subsector_t *sub, uint32_t subsectorDepth, uint32_t stencilValue, double skyCeilingHeight, double skyFloorHeight, std::vector<std::unique_ptr<PolyDrawSectorPortal>> &sectorPortals)
{
RenderPolyPlane plane;
@ -91,7 +91,7 @@ void RenderPolyPlane::RenderPlanes(const TriMatrix &worldToClip, const Vec4f &cl
plane.Render(worldToClip, clipPlane, cull, sub, subsectorDepth, stencilValue, false, skyFloorHeight, sectorPortals);
}
void RenderPolyPlane::Render3DFloor(const TriMatrix &worldToClip, const Vec4f &clipPlane, subsector_t *sub, uint32_t subsectorDepth, uint32_t stencilValue, bool ceiling, F3DFloor *fakeFloor)
void RenderPolyPlane::Render3DFloor(const TriMatrix &worldToClip, const PolyClipPlane &clipPlane, subsector_t *sub, uint32_t subsectorDepth, uint32_t stencilValue, bool ceiling, F3DFloor *fakeFloor)
{
FTextureID picnum = ceiling ? *fakeFloor->bottom.texture : *fakeFloor->top.texture;
FTexture *tex = TexMan(picnum);
@ -138,11 +138,11 @@ void RenderPolyPlane::Render3DFloor(const TriMatrix &worldToClip, const Vec4f &c
args.SetStencilTestValue(stencilValue);
args.SetWriteStencil(true, stencilValue + 1);
args.SetTexture(tex);
args.SetClipPlane(clipPlane.x, clipPlane.y, clipPlane.z, clipPlane.w);
args.SetClipPlane(clipPlane);
args.DrawArray(vertices, sub->numlines, PolyDrawMode::TriangleFan);
}
void RenderPolyPlane::Render(const TriMatrix &worldToClip, const Vec4f &clipPlane, PolyCull &cull, subsector_t *sub, uint32_t subsectorDepth, uint32_t stencilValue, bool ceiling, double skyHeight, std::vector<std::unique_ptr<PolyDrawSectorPortal>> &sectorPortals)
void RenderPolyPlane::Render(const TriMatrix &worldToClip, const PolyClipPlane &clipPlane, PolyCull &cull, subsector_t *sub, uint32_t subsectorDepth, uint32_t stencilValue, bool ceiling, double skyHeight, std::vector<std::unique_ptr<PolyDrawSectorPortal>> &sectorPortals)
{
const auto &viewpoint = PolyRenderer::Instance()->Viewpoint;
bool foggy = false;
@ -307,7 +307,7 @@ void RenderPolyPlane::Render(const TriMatrix &worldToClip, const Vec4f &clipPlan
args.SetFaceCullCCW(ccw);
args.SetStencilTestValue(stencilValue);
args.SetWriteStencil(true, stencilValue + 1);
args.SetClipPlane(clipPlane.x, clipPlane.y, clipPlane.z, clipPlane.w);
args.SetClipPlane(clipPlane);
if (!isSky)
{

View file

@ -26,12 +26,11 @@
class PolyDrawSectorPortal;
class PolyCull;
class Vec4f;
class RenderPolyPlane
{
public:
static void RenderPlanes(const TriMatrix &worldToClip, const Vec4f &clipPlane, PolyCull &cull, subsector_t *sub, uint32_t subsectorDepth, uint32_t stencilValue, double skyCeilingHeight, double skyFloorHeight, std::vector<std::unique_ptr<PolyDrawSectorPortal>> &sectorPortals);
static void RenderPlanes(const TriMatrix &worldToClip, const PolyClipPlane &clipPlane, PolyCull &cull, subsector_t *sub, uint32_t subsectorDepth, uint32_t stencilValue, double skyCeilingHeight, double skyFloorHeight, std::vector<std::unique_ptr<PolyDrawSectorPortal>> &sectorPortals);
private:
struct UVTransform
@ -48,7 +47,7 @@ private:
float xOffs, yOffs;
};
void Render3DFloor(const TriMatrix &worldToClip, const Vec4f &clipPlane, subsector_t *sub, uint32_t subsectorDepth, uint32_t stencilValue, bool ceiling, F3DFloor *fakefloor);
void Render(const TriMatrix &worldToClip, const Vec4f &clipPlane, PolyCull &cull, subsector_t *sub, uint32_t subsectorDepth, uint32_t stencilValue, bool ceiling, double skyHeight, std::vector<std::unique_ptr<PolyDrawSectorPortal>> &sectorPortals);
void Render3DFloor(const TriMatrix &worldToClip, const PolyClipPlane &clipPlane, subsector_t *sub, uint32_t subsectorDepth, uint32_t stencilValue, bool ceiling, F3DFloor *fakefloor);
void Render(const TriMatrix &worldToClip, const PolyClipPlane &clipPlane, PolyCull &cull, subsector_t *sub, uint32_t subsectorDepth, uint32_t stencilValue, bool ceiling, double skyHeight, std::vector<std::unique_ptr<PolyDrawSectorPortal>> &sectorPortals);
TriVertex PlaneVertex(vertex_t *v1, double height, const UVTransform &transform);
};

View file

@ -45,7 +45,7 @@ void PolyDrawSectorPortal::Render(int portalDepth)
const auto &viewpoint = PolyRenderer::Instance()->Viewpoint;
Vec4f portalPlane = Vec4f(0.0f);
PolyClipPlane portalPlane(0.0f, 0.0f, 0.0f, 1.0f);
if (Portal->mType != PORTS_SKYVIEWPOINT)
{
float minHeight;
@ -71,17 +71,11 @@ void PolyDrawSectorPortal::Render(int portalDepth)
if (!first && minHeight > viewpoint.Pos.Z)
{
portalPlane.x = 0.0f;
portalPlane.y = 0.0f;
portalPlane.z = 1.0f;
portalPlane.w = -minHeight;
portalPlane = PolyClipPlane(0.0f, 0.0f, 1.0f, -minHeight);
}
else if (!first && maxHeight < viewpoint.Pos.Z)
{
portalPlane.x = 0.0f;
portalPlane.y = 0.0f;
portalPlane.z = -1.0f;
portalPlane.w = maxHeight;
portalPlane = PolyClipPlane(0.0f, 0.0f, -1.0f, maxHeight);
}
}
@ -223,7 +217,7 @@ void PolyDrawLinePortal::Render(int portalDepth)
DVector2 planeNormal = (clipLine->v2->fPos() - clipLine->v1->fPos()).Rotated90CW();
planeNormal.MakeUnit();
double planeD = -(planeNormal | (planePos + planeNormal * 0.001));
Vec4f portalPlane((float)planeNormal.X, (float)planeNormal.Y, 0.0f, (float)planeD);
PolyClipPlane portalPlane((float)planeNormal.X, (float)planeNormal.Y, (float)0.0f, (float)planeD);
RenderPortal.SetViewpoint(worldToClip, portalPlane, StencilValue);
RenderPortal.SetPortalSegments(Segments);

View file

@ -43,7 +43,7 @@ RenderPolyScene::~RenderPolyScene()
{
}
void RenderPolyScene::SetViewpoint(const TriMatrix &worldToClip, const Vec4f &portalPlane, uint32_t stencilValue)
void RenderPolyScene::SetViewpoint(const TriMatrix &worldToClip, const PolyClipPlane &portalPlane, uint32_t stencilValue)
{
WorldToClip = worldToClip;
StencilValue = stencilValue;
@ -252,7 +252,7 @@ void RenderPolyScene::RenderPortals(int portalDepth)
args.SetTransform(&WorldToClip);
args.SetLight(&NormalLight, 255, PolyRenderer::Instance()->Light.WallGlobVis(foggy), true);
args.SetColor(0, 0);
args.SetClipPlane(PortalPlane.x, PortalPlane.y, PortalPlane.z, PortalPlane.w);
args.SetClipPlane(PortalPlane);
args.SetStyle(TriBlendMode::Copy);
for (auto &portal : SectorPortals)
@ -294,7 +294,7 @@ void RenderPolyScene::RenderTranslucent(int portalDepth)
args.SetTransform(&WorldToClip);
args.SetStencilTestValue(portal->StencilValue + 1);
args.SetWriteStencil(true, StencilValue + 1);
args.SetClipPlane(PortalPlane.x, PortalPlane.y, PortalPlane.z, PortalPlane.w);
args.SetClipPlane(PortalPlane);
for (const auto &verts : portal->Shape)
{
args.SetFaceCullCCW(verts.Ccw);
@ -313,7 +313,7 @@ void RenderPolyScene::RenderTranslucent(int portalDepth)
args.SetTransform(&WorldToClip);
args.SetStencilTestValue(portal->StencilValue + 1);
args.SetWriteStencil(true, StencilValue + 1);
args.SetClipPlane(PortalPlane.x, PortalPlane.y, PortalPlane.z, PortalPlane.w);
args.SetClipPlane(PortalPlane);
for (const auto &verts : portal->Shape)
{
args.SetFaceCullCCW(verts.Ccw);

View file

@ -29,7 +29,6 @@
#include "doomdata.h"
#include "r_utility.h"
#include "polyrenderer/drawers/poly_triangle.h"
#include "polyrenderer/math/poly_intersection.h"
#include "poly_wall.h"
#include "poly_sprite.h"
#include "poly_wallsprite.h"
@ -74,7 +73,7 @@ class RenderPolyScene
public:
RenderPolyScene();
~RenderPolyScene();
void SetViewpoint(const TriMatrix &worldToClip, const Vec4f &portalPlane, uint32_t stencilValue);
void SetViewpoint(const TriMatrix &worldToClip, const PolyClipPlane &portalPlane, uint32_t stencilValue);
void SetPortalSegments(const std::vector<PolyPortalSegment> &segments);
void Render(int portalDepth);
void RenderTranslucent(int portalDepth);
@ -91,7 +90,7 @@ private:
void RenderSprite(AActor *thing, double sortDistance, DVector2 left, DVector2 right, double t1, double t2, void *node);
TriMatrix WorldToClip;
Vec4f PortalPlane;
PolyClipPlane PortalPlane;
uint32_t StencilValue = 0;
PolyCull Cull;
uint32_t NextSubsectorDepth = 0;

View file

@ -61,7 +61,7 @@ void PolySkyDome::Render(const TriMatrix &worldToClip)
args.SetTransform(&objectToClip);
args.SetStencilTestValue(255);
args.SetWriteStencil(true, 1);
args.SetClipPlane(0.0f, 0.0f, 0.0f, 0.0f);
args.SetClipPlane(PolyClipPlane(0.0f, 0.0f, 0.0f, 1.0f));
RenderCapColorRow(args, frontskytex, 0, false);
RenderCapColorRow(args, frontskytex, rc, true);

View file

@ -27,7 +27,6 @@
#include "r_data/r_translate.h"
#include "poly_sprite.h"
#include "polyrenderer/poly_renderer.h"
#include "polyrenderer/math/poly_intersection.h"
#include "polyrenderer/scene/poly_light.h"
EXTERN_CVAR(Float, transsouls)
@ -65,7 +64,7 @@ bool RenderPolySprite::GetLine(AActor *thing, DVector2 &left, DVector2 &right)
return true;
}
void RenderPolySprite::Render(const TriMatrix &worldToClip, const Vec4f &clipPlane, AActor *thing, subsector_t *sub, uint32_t subsectorDepth, uint32_t stencilValue, float t1, float t2)
void RenderPolySprite::Render(const TriMatrix &worldToClip, const PolyClipPlane &clipPlane, AActor *thing, subsector_t *sub, uint32_t subsectorDepth, uint32_t stencilValue, float t1, float t2)
{
DVector2 line[2];
if (!GetLine(thing, line[0], line[1]))
@ -146,7 +145,7 @@ void RenderPolySprite::Render(const TriMatrix &worldToClip, const Vec4f &clipPla
args.SetStencilTestValue(stencilValue);
args.SetWriteStencil(true, stencilValue);
args.SetTexture(tex, thing->Translation);
args.SetClipPlane(clipPlane.x, clipPlane.y, clipPlane.z, clipPlane.w);
args.SetClipPlane(clipPlane);
if (thing->RenderStyle == LegacyRenderStyles[STYLE_Normal] ||
(r_drawfuzz == 0 && thing->RenderStyle == LegacyRenderStyles[STYLE_OptFuzzy]))

View file

@ -24,12 +24,10 @@
#include "polyrenderer/drawers/poly_triangle.h"
class Vec4f;
class RenderPolySprite
{
public:
void Render(const TriMatrix &worldToClip, const Vec4f &clipPlane, AActor *thing, subsector_t *sub, uint32_t subsectorDepth, uint32_t stencilValue, float t1, float t2);
void Render(const TriMatrix &worldToClip, const PolyClipPlane &clipPlane, AActor *thing, subsector_t *sub, uint32_t subsectorDepth, uint32_t stencilValue, float t1, float t2);
static bool GetLine(AActor *thing, DVector2 &left, DVector2 &right);
static bool IsThingCulled(AActor *thing);

View file

@ -37,7 +37,7 @@
EXTERN_CVAR(Bool, r_drawmirrors)
bool RenderPolyWall::RenderLine(const TriMatrix &worldToClip, const Vec4f &clipPlane, PolyCull &cull, seg_t *line, sector_t *frontsector, uint32_t subsectorDepth, uint32_t stencilValue, std::vector<PolyTranslucentObject*> &translucentWallsOutput, std::vector<std::unique_ptr<PolyDrawLinePortal>> &linePortals)
bool RenderPolyWall::RenderLine(const TriMatrix &worldToClip, const PolyClipPlane &clipPlane, PolyCull &cull, seg_t *line, sector_t *frontsector, uint32_t subsectorDepth, uint32_t stencilValue, std::vector<PolyTranslucentObject*> &translucentWallsOutput, std::vector<std::unique_ptr<PolyDrawLinePortal>> &linePortals)
{
PolyDrawLinePortal *polyportal = nullptr;
if (line->backsector == nullptr && line->linedef && line->sidedef == line->linedef->sidedef[0] && (line->linedef->special == Line_Mirror && r_drawmirrors))
@ -165,7 +165,7 @@ bool RenderPolyWall::RenderLine(const TriMatrix &worldToClip, const Vec4f &clipP
return polyportal != nullptr;
}
void RenderPolyWall::Render3DFloorLine(const TriMatrix &worldToClip, const Vec4f &clipPlane, PolyCull &cull, seg_t *line, sector_t *frontsector, uint32_t subsectorDepth, uint32_t stencilValue, F3DFloor *fakeFloor, std::vector<PolyTranslucentObject*> &translucentWallsOutput)
void RenderPolyWall::Render3DFloorLine(const TriMatrix &worldToClip, const PolyClipPlane &clipPlane, PolyCull &cull, seg_t *line, sector_t *frontsector, uint32_t subsectorDepth, uint32_t stencilValue, F3DFloor *fakeFloor, std::vector<PolyTranslucentObject*> &translucentWallsOutput)
{
double frontceilz1 = fakeFloor->top.plane->ZatPoint(line->v1);
double frontfloorz1 = fakeFloor->bottom.plane->ZatPoint(line->v1);
@ -198,7 +198,7 @@ void RenderPolyWall::SetCoords(const DVector2 &v1, const DVector2 &v2, double ce
this->floor2 = floor2;
}
void RenderPolyWall::Render(const TriMatrix &worldToClip, const Vec4f &clipPlane, PolyCull &cull)
void RenderPolyWall::Render(const TriMatrix &worldToClip, const PolyClipPlane &clipPlane, PolyCull &cull)
{
bool foggy = false;
FTexture *tex = GetTexture();
@ -256,7 +256,7 @@ void RenderPolyWall::Render(const TriMatrix &worldToClip, const Vec4f &clipPlane
args.SetWriteStencil(true, StencilValue + 1);
if (tex)
args.SetTexture(tex);
args.SetClipPlane(clipPlane.x, clipPlane.y, clipPlane.z, clipPlane.w);
args.SetClipPlane(clipPlane);
if (Polyportal)
{

View file

@ -27,16 +27,15 @@
class PolyTranslucentObject;
class PolyDrawLinePortal;
class PolyCull;
class Vec4f;
class RenderPolyWall
{
public:
static bool RenderLine(const TriMatrix &worldToClip, const Vec4f &clipPlane, PolyCull &cull, seg_t *line, sector_t *frontsector, uint32_t subsectorDepth, uint32_t stencilValue, std::vector<PolyTranslucentObject*> &translucentWallsOutput, std::vector<std::unique_ptr<PolyDrawLinePortal>> &linePortals);
static void Render3DFloorLine(const TriMatrix &worldToClip, const Vec4f &clipPlane, PolyCull &cull, seg_t *line, sector_t *frontsector, uint32_t subsectorDepth, uint32_t stencilValue, F3DFloor *fakeFloor, std::vector<PolyTranslucentObject*> &translucentWallsOutput);
static bool RenderLine(const TriMatrix &worldToClip, const PolyClipPlane &clipPlane, PolyCull &cull, seg_t *line, sector_t *frontsector, uint32_t subsectorDepth, uint32_t stencilValue, std::vector<PolyTranslucentObject*> &translucentWallsOutput, std::vector<std::unique_ptr<PolyDrawLinePortal>> &linePortals);
static void Render3DFloorLine(const TriMatrix &worldToClip, const PolyClipPlane &clipPlane, PolyCull &cull, seg_t *line, sector_t *frontsector, uint32_t subsectorDepth, uint32_t stencilValue, F3DFloor *fakeFloor, std::vector<PolyTranslucentObject*> &translucentWallsOutput);
void SetCoords(const DVector2 &v1, const DVector2 &v2, double ceil1, double floor1, double ceil2, double floor2);
void Render(const TriMatrix &worldToClip, const Vec4f &clipPlane, PolyCull &cull);
void Render(const TriMatrix &worldToClip, const PolyClipPlane &clipPlane, PolyCull &cull);
DVector2 v1;
DVector2 v2;

View file

@ -29,7 +29,7 @@
#include "polyrenderer/poly_renderer.h"
#include "polyrenderer/scene/poly_light.h"
void RenderPolyWallSprite::Render(const TriMatrix &worldToClip, const Vec4f &clipPlane, AActor *thing, subsector_t *sub, uint32_t subsectorDepth, uint32_t stencilValue)
void RenderPolyWallSprite::Render(const TriMatrix &worldToClip, const PolyClipPlane &clipPlane, AActor *thing, subsector_t *sub, uint32_t subsectorDepth, uint32_t stencilValue)
{
if (RenderPolySprite::IsThingCulled(thing))
return;
@ -105,7 +105,7 @@ void RenderPolyWallSprite::Render(const TriMatrix &worldToClip, const Vec4f &cli
args.SetFaceCullCCW(true);
args.SetStencilTestValue(stencilValue);
args.SetTexture(tex);
args.SetClipPlane(clipPlane.x, clipPlane.y, clipPlane.z, clipPlane.w);
args.SetClipPlane(clipPlane);
args.SetSubsectorDepthTest(true);
args.SetWriteSubsectorDepth(false);
args.SetWriteStencil(false);

View file

@ -24,10 +24,8 @@
#include "polyrenderer/drawers/poly_triangle.h"
class Vec4f;
class RenderPolyWallSprite
{
public:
void Render(const TriMatrix &worldToClip, const Vec4f &clipPlane, AActor *thing, subsector_t *sub, uint32_t subsectorDepth, uint32_t stencilValue);
void Render(const TriMatrix &worldToClip, const PolyClipPlane &clipPlane, AActor *thing, subsector_t *sub, uint32_t subsectorDepth, uint32_t stencilValue);
};