utility functions

This commit is contained in:
h4570
2022-08-17 00:19:16 +02:00
parent 4fb0ab3b6c
commit fea2398699
27 changed files with 419 additions and 247 deletions
+5 -1
View File
@@ -19,13 +19,17 @@ namespace Tyra {
/** Bounding box with more features */
class BBox : public CoreBBox {
public:
BBox(const BBox& t_bbox);
explicit BBox(CoreBBox** t_bboxes, const u32& count);
explicit BBox(Vec4* t_vertices, u32* faces, u32 t_count);
explicit BBox(Vec4* t_vertices, u32 t_count);
explicit BBox(const BBox& t_bbox, const M4x4& t_matrix);
explicit BBox(const BBox& t_bbox);
explicit BBox(Vec4* t_vertices);
static BBox create(const Vec4& center, const float& size);
void operator=(const BBox& v);
const float& getHeight() const { return _height; }
const float& getDepth() const { return _depth; }
const float& getWidth() const { return _width; }
@@ -18,7 +18,7 @@
#include "../../mcpip_block.hpp"
#include "../../data/mcpip_block_data.hpp"
#include "./mcpip_vu1_as_is_shared_defines.h"
#include "renderer/core/3d/clipper/ee_clip_algorithm.hpp"
#include "renderer/core/3d/clipper/planes_clip_algorithm.hpp"
namespace Tyra {
@@ -27,7 +27,7 @@ class McpipClip {
McpipClip();
~McpipClip();
EEClipAlgorithm algorithm;
PlanesClipAlgorithm algorithm;
EEClipAlgorithmSettings algoSettings;
void init(RendererCore* core, McpipBlockData* t_singleBlockData,
@@ -52,14 +52,16 @@ class McpipClip {
u16 vu1DBufferSize;
Vec4 inputVerts[3];
EEClipVertexPtrs inputTriangle[3];
EEClipVertex clippedTriangle[9];
PlanesClipVertexPtrs inputTriangle[3];
PlanesClipVertex clippedTriangle[9];
Vec4 vertexBuffers[2][108];
Vec4 texCoordBuffers[2][108];
void addCorrections(std::vector<EEClipVertex>* vertices, McpipBlock* block);
void moveDataToBuffer(std::vector<EEClipVertex>* vertices, const u8& context);
void addCorrections(std::vector<PlanesClipVertex>* vertices,
McpipBlock* block);
void moveDataToBuffer(std::vector<PlanesClipVertex>* vertices,
const u8& context);
void addDataToPacket(packet2_t* packet, const u8& context, McpipBlock* block,
const int& count,
RendererCoreTextureBuffers* texBuffers);
@@ -12,7 +12,7 @@
#include "renderer/core/3d/bbox/core_bbox.hpp"
#include "renderer/core/3d/renderer_3d_frustum_planes.hpp"
#include "renderer/core/3d/clipper/ee_clip_algorithm.hpp"
#include "renderer/core/3d/clipper/planes_clip_algorithm.hpp"
#include "./stapip_bag_packages_bbox.hpp"
#include "./stapip_bag_package.hpp"
#include "../stapip_bag.hpp"
@@ -14,7 +14,7 @@
#include "debug/debug.hpp"
#include "./stapip_qbuffer.hpp"
#include "renderer/renderer_settings.hpp"
#include "renderer/core/3d/clipper/ee_clip_algorithm.hpp"
#include "renderer/core/3d/clipper/planes_clip_algorithm.hpp"
namespace Tyra {
@@ -36,15 +36,15 @@ class StaPipClipper {
private:
u32 maxVertCount;
EEClipAlgorithm algorithm;
PlanesClipAlgorithm algorithm;
M4x4* mvp;
Vec4 inputVerts[3];
EEClipVertexPtrs inputTriangle[3];
EEClipVertex clippedTriangle[9];
PlanesClipVertexPtrs inputTriangle[3];
PlanesClipVertex clippedTriangle[9];
void perspectiveDivide(std::vector<EEClipVertex>* vertices);
void moveDataToBuffer(const std::vector<EEClipVertex>& vertices,
void perspectiveDivide(std::vector<PlanesClipVertex>* vertices);
void moveDataToBuffer(const std::vector<PlanesClipVertex>& vertices,
StaPipQBuffer* buffer);
};
+27 -5
View File
@@ -14,10 +14,16 @@
#include "renderer/models/color.hpp"
#include "renderer/core/3d/bbox/core_bbox.hpp"
#include "../core/renderer_core.hpp"
#include "renderer/core/3d/clipper/planes_clip_algorithm.hpp"
namespace Tyra {
/** Debug functions, with bad performance. */
/**
* Debug functions, with bad performance.
*
* Remember that you need to use them AFTER ALLPASS rendering.
* (for example after skybox), otherwise colors will not work.
*/
class Renderer3DUtility {
public:
Renderer3DUtility();
@@ -25,8 +31,8 @@ class Renderer3DUtility {
void init(RendererCore* core);
void drawPoint(const Vec4& v);
void drawPoint(const Vec4& v, const Color& color);
void drawBox(const Vec4& v, const float& size);
void drawBox(const Vec4& v, const float& size, const Color& color);
void drawLine(const Vec4& from, const Vec4& to);
void drawLine(const Vec4& from, const Vec4& to, const Color& color);
@@ -35,10 +41,26 @@ class Renderer3DUtility {
void drawBBox(const CoreBBox& v, const Color& color);
private:
std::array<PlanesClipVertex, 9> clippedVerts;
std::array<PlanesClipVertexPtrs, 3> clipInput;
RendererCore* core;
prim_t basePrim;
color_t baseColor;
prim_t prim;
void fillBBoxVertices(std::array<std::array<Vec4, 4>, 6>& v,
const CoreBBox& bbox);
color_t getGSColor(const Color& color);
/**
* @return true - To draw
* @return false - To skip (outside view frustum)
*/
bool calcLineVertices(xyz_t* outputArray, const Vec4& a, const Vec4& b,
const u8& displayOffset);
PlanesClipAlgorithm planesClipAlgorithm;
};
} // namespace Tyra
@@ -37,7 +37,7 @@ class RendererCore2D {
prim_t prim;
lod_t lod;
static const float GS_CENTER;
static const float GS_DRAW_AREA;
static const float SCREEN_CENTER;
u8 context;
+24 -9
View File
@@ -21,17 +21,31 @@ namespace Tyra {
/** Bounding box */
class CoreBBox {
public:
explicit CoreBBox();
CoreBBox();
CoreBBox(const CoreBBox& t_bbox);
explicit CoreBBox(Vec4* t_vertices, u32* faces, u32 t_count);
explicit CoreBBox(Vec4* t_vertices, u32 t_count);
explicit CoreBBox(Vec4* t_vertices);
explicit CoreBBox(const CoreBBox& t_bbox);
explicit CoreBBox(CoreBBox** t_bboxes, const u32& count);
explicit CoreBBox(const std::vector<CoreBBox>& t_bboxes,
const u32& startIndex, const u32& stopIndex);
static CoreBBox create(const Vec4& center, const float& size);
/**
* 0 - lowX, lowY, lowZ
* 1 - lowX, lowY, hiZ
* 2 - lowX, hiY, lowZ
* 3 - lowX, hiY, hiZ
* 4 - hiX, lowY, lowZ
* 5 - hiX, lowY, hiZ
* 6 - hiX, hiY, lowZ
* 7 - hiX, hiY, hiZ
*/
Vec4 vertices[8];
void operator=(const CoreBBox& v);
const Vec4& operator[](const u8& i) const { return vertices[i]; }
const u8 getVertexCount() const { return 8; }
@@ -41,13 +55,14 @@ class CoreBBox {
void print(const std::string& name) const { print(name.c_str()); }
std::string getPrint(const char* name = nullptr) const;
/**
* @brief Check if bbox is in view frustum
*
* @param frustumPlanes Available in engine.renderer.core.renderer3D.frustumPlanes
* @param model Model matrix
* @param margins Optional margins
*/
/**
* @brief Check if bbox is in view frustum
*
* @param frustumPlanes Available in
* engine.renderer.core.renderer3D.frustumPlanes
* @param model Model matrix
* @param margins Optional margins
*/
CoreBBoxFrustum isInFrustum(const Plane* frustumPlanes, const M4x4& model,
const float* margins = nullptr) const;
};
@@ -11,7 +11,7 @@
#pragma once
#include <vector>
#include "./ee_clip_vertex.hpp"
#include "./planes_clip_vertex.hpp"
#include "debug/debug.hpp"
#include "renderer/renderer_settings.hpp"
@@ -21,30 +21,30 @@ struct EEClipAlgorithmSettings {
bool lerpNormals, lerpTexCoords, lerpColors;
};
class EEClipAlgorithm {
class PlanesClipAlgorithm {
public:
EEClipAlgorithm();
~EEClipAlgorithm();
PlanesClipAlgorithm();
~PlanesClipAlgorithm();
void init(const RendererSettings& settings);
u8 clip(EEClipVertex* o_vertices, EEClipVertexPtrs* i_vertices,
u8 clip(PlanesClipVertex* o_vertices, PlanesClipVertexPtrs* i_vertices,
const EEClipAlgorithmSettings& settings);
static float clipMargin;
private:
float halfWidth, halfHeight, near, far;
EEClipVertex* tempVertices;
PlanesClipVertex* tempVertices;
float getValueByPlane(const EEClipVertex& v, const int& plane);
float getValueByPlane(const PlanesClipVertex& v, const int& plane);
bool isInside(const int& plane, const float& v, const float& w,
const float& planeLimitValue);
/** @return clipped size */
u8 clipAgainstPlane(EEClipVertex* original, const u8& originalSize,
EEClipVertex* clipped, const int& plane,
u8 clipAgainstPlane(PlanesClipVertex* original, const u8& originalSize,
PlanesClipVertex* clipped, const int& plane,
const float& planeLimitValue,
const EEClipAlgorithmSettings& settings);
};
@@ -14,11 +14,11 @@
namespace Tyra {
struct EEClipVertex {
struct PlanesClipVertex {
Vec4 position, normal, st, color;
};
struct EEClipVertexPtrs {
struct PlanesClipVertexPtrs {
Vec4 *position, *normal, *st, *color;
};