diff --git a/demo/src/states/game/skybox/skybox.cpp b/demo/src/states/game/skybox/skybox.cpp index b5c971a..05c8767 100644 --- a/demo/src/states/game/skybox/skybox.cpp +++ b/demo/src/states/game/skybox/skybox.cpp @@ -20,14 +20,11 @@ namespace Demo { Skybox::Skybox(TextureRepository* repo) { TyrobjLoader loader; auto* data = loader.load(FileUtils::fromCwd("game/models/skybox/skybox.obj"), - 1, 400.0F, true); + 1, 100.0F, true); data->normalsEnabled = false; mesh = new StaticMesh(*data); delete data; - mesh->scale.scaleX(2.0F); - mesh->scale.scaleZ(2.0F); - for (u32 i = 0; i < mesh->getMaterialsCount(); i++) { auto* material = mesh->getMaterial(i); material->print(); @@ -58,6 +55,7 @@ void Skybox::allocateOptions() { options = new StaPipOptions(); options->frustumCulling = Tyra::PipelineFrustumCulling_None; options->shadingType = Tyra::TyraShadingGouraud; + options->zTestType = Tyra::StaPipZTest_AllPass; options->textureMappingType = Tyra::TyraNearest; options->blendingEnabled = true; options->antiAliasingEnabled = false; diff --git a/engine/inc/renderer/3d/pipeline/static/core/stapip_core.hpp b/engine/inc/renderer/3d/pipeline/static/core/stapip_core.hpp index 89449f3..8b4de13 100644 --- a/engine/inc/renderer/3d/pipeline/static/core/stapip_core.hpp +++ b/engine/inc/renderer/3d/pipeline/static/core/stapip_core.hpp @@ -16,6 +16,7 @@ #include "./bag/packaging/stapip_bag_package.hpp" #include "./bag/packaging/stapip_bag_packager.hpp" #include "./stapip_qbuffer_renderer.hpp" +#include "../stapip_ztest.hpp" #include "renderer/3d/pipeline/shared/pipeline_frustum_culling.hpp" namespace Tyra { @@ -28,7 +29,7 @@ class StaPipCore { void init(RendererCore* t_core); /** Render 3D via "bags" */ - void render(StaPipBag* bag, const bool& frustumCull, + void render(StaPipBag* bag, const bool& frustumCull, const StaPipZTest& zTest, StaPipBagPackagesBBox* bbox = nullptr); /** Get max vert count of VU1 qbuffer (for optimizations) */ diff --git a/engine/inc/renderer/3d/pipeline/static/stapip_options.hpp b/engine/inc/renderer/3d/pipeline/static/stapip_options.hpp index 3d4128a..9bed69a 100644 --- a/engine/inc/renderer/3d/pipeline/static/stapip_options.hpp +++ b/engine/inc/renderer/3d/pipeline/static/stapip_options.hpp @@ -11,14 +11,21 @@ #pragma once #include "renderer/3d/pipeline/shared/pipeline_options.hpp" +#include "./stapip_ztest.hpp" namespace Tyra { class StaPipOptions : public PipelineOptions { public: - StaPipOptions() { fullClipChecks = false; } + StaPipOptions() { + fullClipChecks = false; + zTestType = StaPipZTest_Standard; + } ~StaPipOptions() {} + /** @brief Type of z buffer testing. */ + StaPipZTest zTestType; + /** * @brief Experimental! True -> enables "clip against each plane" algorithm. * Mandatory, default: False. diff --git a/engine/inc/renderer/3d/pipeline/static/stapip_ztest.hpp b/engine/inc/renderer/3d/pipeline/static/stapip_ztest.hpp new file mode 100644 index 0000000..87441fb --- /dev/null +++ b/engine/inc/renderer/3d/pipeline/static/stapip_ztest.hpp @@ -0,0 +1,20 @@ +/* +# ______ ____ ___ +# | \/ ____| |___| +# | | | \ | | +#----------------------------------------------------------------------- +# Copyright 2022, tyra - https://github.com/h4570/tyra +# Licenced under Apache License 2.0 +# Sandro Sobczyński +*/ + +#pragma once + +namespace Tyra { + +enum StaPipZTest { + StaPipZTest_Standard = 0, + StaPipZTest_AllPass = 1, +}; + +} // namespace Tyra diff --git a/engine/inc/renderer/core/gs/renderer_core_gs.hpp b/engine/inc/renderer/core/gs/renderer_core_gs.hpp index cf154f5..4079853 100644 --- a/engine/inc/renderer/core/gs/renderer_core_gs.hpp +++ b/engine/inc/renderer/core/gs/renderer_core_gs.hpp @@ -27,6 +27,10 @@ class RendererCoreGS { void flipBuffers(); + void setStandardZTest(); + + void setAllPassZTest(); + private: constexpr static float gsCenter = 4096.0F; constexpr static float screenCenter = gsCenter / 2.0F; @@ -34,6 +38,7 @@ class RendererCoreGS { RendererSettings* settings; framebuffer_t frameBuffers[2]; packet2_t* flipPacket; + packet2_t* zTestPacket; u8 context; u8 currentField; @@ -43,6 +48,7 @@ class RendererCoreGS { void updateCurrentField(); qword_t* setXYOffset(qword_t* q, const int& drawContext, const float& x, const float& y); + qword_t* addAllPassZTest(qword_t* q, int context, zbuffer_t* z); }; } // namespace Tyra diff --git a/engine/src/renderer/3d/pipeline/static/core/stapip_core.cpp b/engine/src/renderer/3d/pipeline/static/core/stapip_core.cpp index ae96514..b05a3fd 100644 --- a/engine/src/renderer/3d/pipeline/static/core/stapip_core.cpp +++ b/engine/src/renderer/3d/pipeline/static/core/stapip_core.cpp @@ -73,7 +73,7 @@ u32 StaPipCore::getMaxVertCountByParams(const bool& isSingleColor, } void StaPipCore::render(StaPipBag* bag, const bool& frustumCull, - StaPipBagPackagesBBox* bbox) { + const StaPipZTest& zTest, StaPipBagPackagesBBox* bbox) { if (bag->count <= 0) return; 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); M4x4 mvp; @@ -204,6 +208,10 @@ void StaPipCore::render(StaPipBag* bag, const bool& frustumCull, qbufferRenderer.flushBuffers(); + if (zTest == StaPipZTest_AllPass) { + rendererCore->gs.setStandardZTest(); + } + Verbose("Render finished"); } diff --git a/engine/src/renderer/3d/pipeline/static/static_pipeline.cpp b/engine/src/renderer/3d/pipeline/static/static_pipeline.cpp index 38642ae..73e8332 100644 --- a/engine/src/renderer/3d/pipeline/static/static_pipeline.cpp +++ b/engine/src/renderer/3d/pipeline/static/static_pipeline.cpp @@ -40,6 +40,7 @@ void StaticPipeline::render(StaticMesh* mesh, const StaPipOptions* options) { auto model = mesh->getModelMatrix(); auto* infoBag = getInfoBag(mesh, options, &model); + auto zTesting = options ? options->zTestType : StaPipZTest_Standard; auto frustumCulling = options ? options->frustumCulling : PipelineFrustumCulling_Simple; @@ -75,7 +76,8 @@ void StaticPipeline::render(StaticMesh* mesh, const StaPipOptions* options) { bag.texture = getTextureBag(material, materialFrame); bag.lighting = getLightingBag(materialFrame, &model, options); - core.render(&bag, frustumCulling == PipelineFrustumCulling_Precise); + core.render(&bag, frustumCulling == PipelineFrustumCulling_Precise, + zTesting); deallocDrawBags(&bag, material); } diff --git a/engine/src/renderer/core/gs/renderer_core_gs.cpp b/engine/src/renderer/core/gs/renderer_core_gs.cpp index b4a1280..8749b0e 100644 --- a/engine/src/renderer/core/gs/renderer_core_gs.cpp +++ b/engine/src/renderer/core/gs/renderer_core_gs.cpp @@ -32,6 +32,9 @@ RendererCoreGS::~RendererCoreGS() { if (flipPacket) { packet2_free(flipPacket); } + if (zTestPacket) { + packet2_free(zTestPacket); + } } void RendererCoreGS::init(RendererSettings* t_settings) { @@ -39,6 +42,7 @@ void RendererCoreGS::init(RendererSettings* t_settings) { initChannels(); flipPacket = packet2_create(4, P2_TYPE_UNCACHED_ACCL, P2_MODE_NORMAL, 0); + zTestPacket = packet2_create(3, P2_TYPE_NORMAL, P2_MODE_NORMAL, 0); allocateBuffers(); initDrawingEnvironment(); @@ -49,6 +53,21 @@ void RendererCoreGS::initChannels() { 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() { frameBuffers[0].width = static_cast(settings->getWidth()); frameBuffers[0].height = static_cast(settings->getHeight()); @@ -119,6 +138,20 @@ qword_t* RendererCoreGS::setXYOffset(qword_t* q, const int& drawContext, 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() { graph_set_framebuffer_filtered(frameBuffers[context].address, frameBuffers[context].width,