ztest option

This commit is contained in:
h4570
2022-08-02 18:36:08 +02:00
parent 5aae7cff7e
commit da958cb094
8 changed files with 83 additions and 8 deletions
+2 -4
View File
@@ -20,14 +20,11 @@ namespace Demo {
Skybox::Skybox(TextureRepository* repo) { Skybox::Skybox(TextureRepository* repo) {
TyrobjLoader loader; TyrobjLoader loader;
auto* data = loader.load(FileUtils::fromCwd("game/models/skybox/skybox.obj"), auto* data = loader.load(FileUtils::fromCwd("game/models/skybox/skybox.obj"),
1, 400.0F, true); 1, 100.0F, true);
data->normalsEnabled = false; data->normalsEnabled = false;
mesh = new StaticMesh(*data); mesh = new StaticMesh(*data);
delete data; delete data;
mesh->scale.scaleX(2.0F);
mesh->scale.scaleZ(2.0F);
for (u32 i = 0; i < mesh->getMaterialsCount(); i++) { for (u32 i = 0; i < mesh->getMaterialsCount(); i++) {
auto* material = mesh->getMaterial(i); auto* material = mesh->getMaterial(i);
material->print(); material->print();
@@ -58,6 +55,7 @@ void Skybox::allocateOptions() {
options = new StaPipOptions(); options = new StaPipOptions();
options->frustumCulling = Tyra::PipelineFrustumCulling_None; options->frustumCulling = Tyra::PipelineFrustumCulling_None;
options->shadingType = Tyra::TyraShadingGouraud; options->shadingType = Tyra::TyraShadingGouraud;
options->zTestType = Tyra::StaPipZTest_AllPass;
options->textureMappingType = Tyra::TyraNearest; options->textureMappingType = Tyra::TyraNearest;
options->blendingEnabled = true; options->blendingEnabled = true;
options->antiAliasingEnabled = false; options->antiAliasingEnabled = false;
@@ -16,6 +16,7 @@
#include "./bag/packaging/stapip_bag_package.hpp" #include "./bag/packaging/stapip_bag_package.hpp"
#include "./bag/packaging/stapip_bag_packager.hpp" #include "./bag/packaging/stapip_bag_packager.hpp"
#include "./stapip_qbuffer_renderer.hpp" #include "./stapip_qbuffer_renderer.hpp"
#include "../stapip_ztest.hpp"
#include "renderer/3d/pipeline/shared/pipeline_frustum_culling.hpp" #include "renderer/3d/pipeline/shared/pipeline_frustum_culling.hpp"
namespace Tyra { namespace Tyra {
@@ -28,7 +29,7 @@ class StaPipCore {
void init(RendererCore* t_core); void init(RendererCore* t_core);
/** Render 3D via "bags" */ /** Render 3D via "bags" */
void render(StaPipBag* bag, const bool& frustumCull, void render(StaPipBag* bag, const bool& frustumCull, const StaPipZTest& zTest,
StaPipBagPackagesBBox* bbox = nullptr); StaPipBagPackagesBBox* bbox = nullptr);
/** Get max vert count of VU1 qbuffer (for optimizations) */ /** Get max vert count of VU1 qbuffer (for optimizations) */
@@ -11,14 +11,21 @@
#pragma once #pragma once
#include "renderer/3d/pipeline/shared/pipeline_options.hpp" #include "renderer/3d/pipeline/shared/pipeline_options.hpp"
#include "./stapip_ztest.hpp"
namespace Tyra { namespace Tyra {
class StaPipOptions : public PipelineOptions { class StaPipOptions : public PipelineOptions {
public: public:
StaPipOptions() { fullClipChecks = false; } StaPipOptions() {
fullClipChecks = false;
zTestType = StaPipZTest_Standard;
}
~StaPipOptions() {} ~StaPipOptions() {}
/** @brief Type of z buffer testing. */
StaPipZTest zTestType;
/** /**
* @brief Experimental! True -> enables "clip against each plane" algorithm. * @brief Experimental! True -> enables "clip against each plane" algorithm.
* Mandatory, default: False. * Mandatory, default: False.
@@ -0,0 +1,20 @@
/*
# ______ ____ ___
# | \/ ____| |___|
# | | | \ | |
#-----------------------------------------------------------------------
# Copyright 2022, tyra - https://github.com/h4570/tyra
# Licenced under Apache License 2.0
# Sandro Sobczyński <sandro.sobczynski@gmail.com>
*/
#pragma once
namespace Tyra {
enum StaPipZTest {
StaPipZTest_Standard = 0,
StaPipZTest_AllPass = 1,
};
} // namespace Tyra
@@ -27,6 +27,10 @@ class RendererCoreGS {
void flipBuffers(); void flipBuffers();
void setStandardZTest();
void setAllPassZTest();
private: private:
constexpr static float gsCenter = 4096.0F; constexpr static float gsCenter = 4096.0F;
constexpr static float screenCenter = gsCenter / 2.0F; constexpr static float screenCenter = gsCenter / 2.0F;
@@ -34,6 +38,7 @@ class RendererCoreGS {
RendererSettings* settings; RendererSettings* settings;
framebuffer_t frameBuffers[2]; framebuffer_t frameBuffers[2];
packet2_t* flipPacket; packet2_t* flipPacket;
packet2_t* zTestPacket;
u8 context; u8 context;
u8 currentField; u8 currentField;
@@ -43,6 +48,7 @@ class RendererCoreGS {
void updateCurrentField(); void updateCurrentField();
qword_t* setXYOffset(qword_t* q, const int& drawContext, const float& x, qword_t* setXYOffset(qword_t* q, const int& drawContext, const float& x,
const float& y); const float& y);
qword_t* addAllPassZTest(qword_t* q, int context, zbuffer_t* z);
}; };
} // namespace Tyra } // namespace Tyra
@@ -73,7 +73,7 @@ u32 StaPipCore::getMaxVertCountByParams(const bool& isSingleColor,
} }
void StaPipCore::render(StaPipBag* bag, const bool& frustumCull, void StaPipCore::render(StaPipBag* bag, const bool& frustumCull,
StaPipBagPackagesBBox* bbox) { const StaPipZTest& zTest, StaPipBagPackagesBBox* bbox) {
if (bag->count <= 0) return; if (bag->count <= 0) return;
TYRA_ASSERT(bag->vertices != nullptr, TYRA_ASSERT(bag->vertices != nullptr,
@@ -128,6 +128,10 @@ void StaPipCore::render(StaPipBag* bag, const bool& frustumCull,
} }
} }
if (zTest == StaPipZTest_AllPass) {
rendererCore->gs.setAllPassZTest();
}
packager.setRenderBBox(renderBbox); packager.setRenderBBox(renderBbox);
M4x4 mvp; M4x4 mvp;
@@ -204,6 +208,10 @@ void StaPipCore::render(StaPipBag* bag, const bool& frustumCull,
qbufferRenderer.flushBuffers(); qbufferRenderer.flushBuffers();
if (zTest == StaPipZTest_AllPass) {
rendererCore->gs.setStandardZTest();
}
Verbose("Render finished"); Verbose("Render finished");
} }
@@ -40,6 +40,7 @@ void StaticPipeline::render(StaticMesh* mesh, const StaPipOptions* options) {
auto model = mesh->getModelMatrix(); auto model = mesh->getModelMatrix();
auto* infoBag = getInfoBag(mesh, options, &model); auto* infoBag = getInfoBag(mesh, options, &model);
auto zTesting = options ? options->zTestType : StaPipZTest_Standard;
auto frustumCulling = auto frustumCulling =
options ? options->frustumCulling : PipelineFrustumCulling_Simple; options ? options->frustumCulling : PipelineFrustumCulling_Simple;
@@ -75,7 +76,8 @@ void StaticPipeline::render(StaticMesh* mesh, const StaPipOptions* options) {
bag.texture = getTextureBag(material, materialFrame); bag.texture = getTextureBag(material, materialFrame);
bag.lighting = getLightingBag(materialFrame, &model, options); bag.lighting = getLightingBag(materialFrame, &model, options);
core.render(&bag, frustumCulling == PipelineFrustumCulling_Precise); core.render(&bag, frustumCulling == PipelineFrustumCulling_Precise,
zTesting);
deallocDrawBags(&bag, material); deallocDrawBags(&bag, material);
} }
@@ -32,6 +32,9 @@ RendererCoreGS::~RendererCoreGS() {
if (flipPacket) { if (flipPacket) {
packet2_free(flipPacket); packet2_free(flipPacket);
} }
if (zTestPacket) {
packet2_free(zTestPacket);
}
} }
void RendererCoreGS::init(RendererSettings* t_settings) { void RendererCoreGS::init(RendererSettings* t_settings) {
@@ -39,6 +42,7 @@ void RendererCoreGS::init(RendererSettings* t_settings) {
initChannels(); initChannels();
flipPacket = packet2_create(4, P2_TYPE_UNCACHED_ACCL, P2_MODE_NORMAL, 0); flipPacket = packet2_create(4, P2_TYPE_UNCACHED_ACCL, P2_MODE_NORMAL, 0);
zTestPacket = packet2_create(3, P2_TYPE_NORMAL, P2_MODE_NORMAL, 0);
allocateBuffers(); allocateBuffers();
initDrawingEnvironment(); initDrawingEnvironment();
@@ -49,6 +53,21 @@ void RendererCoreGS::initChannels() {
dma_channel_initialize(DMA_CHANNEL_GIF, NULL, 0); dma_channel_initialize(DMA_CHANNEL_GIF, NULL, 0);
} }
void RendererCoreGS::setStandardZTest() {
packet2_reset(zTestPacket, false);
packet2_update(zTestPacket,
draw_enable_tests(zTestPacket->base, 0, &zBuffer));
dma_channel_wait(DMA_CHANNEL_GIF, 0);
dma_channel_send_packet2(zTestPacket, DMA_CHANNEL_GIF, true);
}
void RendererCoreGS::setAllPassZTest() {
packet2_reset(zTestPacket, false);
packet2_update(zTestPacket, addAllPassZTest(zTestPacket->base, 0, &zBuffer));
dma_channel_wait(DMA_CHANNEL_GIF, 0);
dma_channel_send_packet2(zTestPacket, DMA_CHANNEL_GIF, true);
}
void RendererCoreGS::allocateBuffers() { void RendererCoreGS::allocateBuffers() {
frameBuffers[0].width = static_cast<unsigned int>(settings->getWidth()); frameBuffers[0].width = static_cast<unsigned int>(settings->getWidth());
frameBuffers[0].height = static_cast<unsigned int>(settings->getHeight()); frameBuffers[0].height = static_cast<unsigned int>(settings->getHeight());
@@ -119,6 +138,20 @@ qword_t* RendererCoreGS::setXYOffset(qword_t* q, const int& drawContext,
return q; return q;
} }
qword_t* RendererCoreGS::addAllPassZTest(qword_t* q, int context,
zbuffer_t* z) {
(void)z;
PACK_GIFTAG(q, GIF_SET_TAG(1, 0, 0, 0, GIF_FLG_PACKED, 1), GIF_REG_AD);
q++;
PACK_GIFTAG(q, GS_SET_TEST(0, 0, 0, 0, 0, 0, 0, ZTEST_METHOD_ALLPASS),
GS_REG_TEST + context);
q++;
return q;
}
void RendererCoreGS::flipBuffers() { void RendererCoreGS::flipBuffers() {
graph_set_framebuffer_filtered(frameBuffers[context].address, graph_set_framebuffer_filtered(frameBuffers[context].address,
frameBuffers[context].width, frameBuffers[context].width,