diff --git a/Runtime/Graphics/CGraphics.cpp b/Runtime/Graphics/CGraphics.cpp index ebd7bedd0..62473bd76 100644 --- a/Runtime/Graphics/CGraphics.cpp +++ b/Runtime/Graphics/CGraphics.cpp @@ -28,7 +28,7 @@ zeus::CVector3f CGraphics::g_ViewPoint; zeus::CTransform CGraphics::g_GXViewPointMatrix; zeus::CTransform CGraphics::g_CameraMatrix; SClipScreenRect CGraphics::g_CroppedViewport; -int CGraphics::g_ViewportSamples = 1; +unsigned int CGraphics::g_ViewportSamples = 1; bool CGraphics::g_IsGXModelMatrixIdentity = true; SViewport g_Viewport = {0, 0, 640, 480, 640 / 2.f, 480 / 2.f}; u32 CGraphics::g_FrameCounter = 0; diff --git a/Runtime/Graphics/CGraphics.hpp b/Runtime/Graphics/CGraphics.hpp index e88c88db3..9016cf0d4 100644 --- a/Runtime/Graphics/CGraphics.hpp +++ b/Runtime/Graphics/CGraphics.hpp @@ -247,7 +247,7 @@ public: static zeus::CTransform g_GXViewPointMatrix; static zeus::CTransform g_CameraMatrix; static SClipScreenRect g_CroppedViewport; - static int g_ViewportSamples; + static unsigned int g_ViewportSamples; static bool g_IsGXModelMatrixIdentity; static void DisableAllLights(); diff --git a/Runtime/Graphics/CMakeLists.txt b/Runtime/Graphics/CMakeLists.txt index 879261acd..77084dcbe 100644 --- a/Runtime/Graphics/CMakeLists.txt +++ b/Runtime/Graphics/CMakeLists.txt @@ -20,7 +20,8 @@ if(WIN32) Shaders/CRandomStaticFilterHLSL.cpp Shaders/CElementGenShadersHLSL.cpp Shaders/CParticleSwooshShadersHLSL.cpp - Shaders/CFluidPlaneShaderHLSL.cpp) + Shaders/CFluidPlaneShaderHLSL.cpp + Shaders/CAABoxShaderHLSL.cpp) elseif(BOO_HAS_METAL) set(PLAT_SRCS Shaders/CLineRendererShadersMetal.cpp @@ -43,7 +44,8 @@ elseif(BOO_HAS_METAL) Shaders/CRandomStaticFilterMetal.cpp Shaders/CElementGenShadersMetal.cpp Shaders/CParticleSwooshShadersMetal.cpp - Shaders/CFluidPlaneShaderMetal.cpp) + Shaders/CFluidPlaneShaderMetal.cpp + Shaders/CAABoxShaderMetal.cpp) endif() set(GRAPHICS_SOURCES @@ -89,6 +91,7 @@ set(GRAPHICS_SOURCES Shaders/CElementGenShaders.hpp Shaders/CElementGenShaders.cpp Shaders/CElementGenShadersGLSL.cpp Shaders/CParticleSwooshShaders.hpp Shaders/CParticleSwooshShaders.cpp Shaders/CParticleSwooshShadersGLSL.cpp Shaders/CFluidPlaneShader.hpp Shaders/CFluidPlaneShader.cpp Shaders/CFluidPlaneShaderGLSL.cpp + Shaders/CAABoxShader.hpp Shaders/CAABoxShader.cpp Shaders/CAABoxShaderGLSL.cpp ${PLAT_SRCS}) runtime_add_list(Graphics GRAPHICS_SOURCES) diff --git a/Runtime/Graphics/Shaders/CAABoxShader.cpp b/Runtime/Graphics/Shaders/CAABoxShader.cpp new file mode 100644 index 000000000..f55ecbb6a --- /dev/null +++ b/Runtime/Graphics/Shaders/CAABoxShader.cpp @@ -0,0 +1,80 @@ +#include "CAABoxShader.hpp" + +namespace urde +{ + +CAABoxShader::CAABoxShader(bool zOnly) +: m_zOnly(zOnly) +{ + m_token = CGraphics::g_BooFactory->commitTransaction([&](boo::IGraphicsDataFactory::Context& ctx) + { + m_vbo = ctx.newDynamicBuffer(boo::BufferUse::Vertex, sizeof(zeus::CVector3f), 34); + m_uniBuf = ctx.newDynamicBuffer(boo::BufferUse::Uniform, sizeof(Uniform), 1); + m_dataBind = TShader::BuildShaderDataBinding(ctx, *this); + return true; + }); +} + +void CAABoxShader::setAABB(const zeus::CAABox& aabb) +{ + zeus::CVector3f vboData[] = + { + {aabb.max.x, aabb.max.y, aabb.min.z}, + {aabb.max.x, aabb.min.y, aabb.min.z}, + {aabb.max.x, aabb.max.y, aabb.max.z}, + {aabb.max.x, aabb.min.y, aabb.max.z}, + {aabb.max.x, aabb.min.y, aabb.max.z}, + + {aabb.min.x, aabb.max.y, aabb.min.z}, + {aabb.min.x, aabb.max.y, aabb.min.z}, + {aabb.max.x, aabb.max.y, aabb.min.z}, + {aabb.min.x, aabb.max.y, aabb.max.z}, + {aabb.max.x, aabb.max.y, aabb.max.z}, + {aabb.max.x, aabb.max.y, aabb.max.z}, + + {aabb.min.x, aabb.max.y, aabb.min.z}, + {aabb.min.x, aabb.max.y, aabb.min.z}, + {aabb.min.x, aabb.min.y, aabb.min.z}, + {aabb.min.x, aabb.max.y, aabb.max.z}, + {aabb.min.x, aabb.min.y, aabb.max.z}, + {aabb.min.x, aabb.min.y, aabb.max.z}, + + {aabb.min.x, aabb.min.y, aabb.min.z}, + {aabb.min.x, aabb.min.y, aabb.min.z}, + {aabb.max.x, aabb.min.y, aabb.min.z}, + {aabb.min.x, aabb.min.y, aabb.max.z}, + {aabb.max.x, aabb.min.y, aabb.max.z}, + {aabb.max.x, aabb.min.y, aabb.max.z}, + + {aabb.min.x, aabb.min.y, aabb.max.z}, + {aabb.min.x, aabb.min.y, aabb.max.z}, + {aabb.max.x, aabb.min.y, aabb.max.z}, + {aabb.min.x, aabb.max.y, aabb.max.z}, + {aabb.max.x, aabb.max.y, aabb.max.z}, + {aabb.max.x, aabb.max.y, aabb.max.z}, + + {aabb.min.x, aabb.min.y, aabb.min.z}, + {aabb.min.x, aabb.min.y, aabb.min.z}, + {aabb.max.x, aabb.min.y, aabb.min.z}, + {aabb.min.x, aabb.max.y, aabb.min.z}, + {aabb.max.x, aabb.max.y, aabb.min.z}, + }; + + m_vbo->load(vboData, sizeof(zeus::CVector3f) * 34); +} + +void CAABoxShader::draw(const zeus::CColor& color) +{ + m_uniform.m_xf = CGraphics::GetPerspectiveProjectionMatrix(true) * CGraphics::g_GXModelView.toMatrix4f(); + m_uniform.m_color = color; + m_uniBuf->load(&m_uniform, sizeof(Uniform)); + + CGraphics::g_BooMainCommandQueue->setShaderDataBinding(m_dataBind); + CGraphics::g_BooMainCommandQueue->draw(0, 34); +} + +void CAABoxShader::Shutdown() {} + +URDE_SPECIALIZE_SHADER(CAABoxShader) + +} diff --git a/Runtime/Graphics/Shaders/CAABoxShader.hpp b/Runtime/Graphics/Shaders/CAABoxShader.hpp new file mode 100644 index 000000000..8ebd65344 --- /dev/null +++ b/Runtime/Graphics/Shaders/CAABoxShader.hpp @@ -0,0 +1,42 @@ +#ifndef __URDE_CAABOXSHADER_HPP__ +#define __URDE_CAABOXSHADER_HPP__ + +#include "TShader.hpp" +#include "zeus/CMatrix4f.hpp" +#include "zeus/CColor.hpp" +#include "zeus/CAABox.hpp" + +namespace urde +{ + +class CAABoxShader +{ + friend struct CAABoxShaderGLDataBindingFactory; + friend struct CAABoxShaderVulkanDataBindingFactory; + friend struct CAABoxShaderMetalDataBindingFactory; + friend struct CAABoxShaderD3DDataBindingFactory; + + struct Uniform + { + zeus::CMatrix4f m_xf; + zeus::CColor m_color; + }; + boo::GraphicsDataToken m_token; + boo::IGraphicsBufferD* m_vbo; + boo::IGraphicsBufferD* m_uniBuf; + boo::IShaderDataBinding* m_dataBind = nullptr; + Uniform m_uniform; + bool m_zOnly; + +public: + CAABoxShader(bool zOnly); + void setAABB(const zeus::CAABox& aabb); + void draw(const zeus::CColor& color); + + using _CLS = CAABoxShader; +#include "TShaderDecl.hpp" +}; + +} + +#endif // __URDE_CAABOXSHADER_HPP__ \ No newline at end of file diff --git a/Runtime/Graphics/Shaders/CAABoxShaderGLSL.cpp b/Runtime/Graphics/Shaders/CAABoxShaderGLSL.cpp new file mode 100644 index 000000000..469c116e5 --- /dev/null +++ b/Runtime/Graphics/Shaders/CAABoxShaderGLSL.cpp @@ -0,0 +1,116 @@ +#include "CAABoxShader.hpp" +#include "Graphics/CBooRenderer.hpp" + +namespace urde +{ + +static const char* VS = +"#version 330\n" +BOO_GLSL_BINDING_HEAD +"layout(location=0) in vec4 posIn;\n" +"\n" +"UBINDING0 uniform CAABoxUniform\n" +"{\n" +" mat4 xf;\n" +" vec4 color;\n" +"};\n" +"\n" +"struct VertToFrag\n" +"{\n" +" vec4 color;\n" +"};\n" +"\n" +"SBINDING(0) out VertToFrag vtf;\n" +"void main()\n" +"{\n" +" vtf.color = color;\n" +" gl_Position = xf * vec4(posIn.xyz, 1.0);\n" +"}\n"; + +static const char* FS = +"#version 330\n" +BOO_GLSL_BINDING_HEAD +"struct VertToFrag\n" +"{\n" +" vec4 color;\n" +"};\n" +"\n" +"SBINDING(0) in VertToFrag vtf;\n" +"layout(location=0) out vec4 colorOut;\n" +"void main()\n" +"{\n" +" colorOut = vtf.color;\n" +"}\n"; + +URDE_DECL_SPECIALIZE_SHADER(CAABoxShader) + +static boo::IVertexFormat* s_VtxFmt = nullptr; +static boo::IShaderPipeline* s_Pipeline = nullptr; +static boo::IShaderPipeline* s_zOnlyPipeline = nullptr; + +struct CAABoxShaderGLDataBindingFactory : TShader::IDataBindingFactory +{ + boo::IShaderDataBinding* BuildShaderDataBinding(boo::IGraphicsDataFactory::Context& ctx, + CAABoxShader& filter) + { + boo::GLDataFactory::Context& cctx = static_cast(ctx); + + const boo::VertexElementDescriptor VtxVmt[] = + { + {filter.m_vbo, nullptr, boo::VertexSemantic::Position4}, + }; + boo::IGraphicsBuffer* bufs[] = {filter.m_uniBuf}; + boo::PipelineStage stages[] = {boo::PipelineStage::Vertex}; + return cctx.newShaderDataBinding(filter.m_zOnly ? s_zOnlyPipeline : s_Pipeline, + ctx.newVertexFormat(1, VtxVmt), filter.m_vbo, nullptr, nullptr, + 1, bufs, stages, nullptr, nullptr, 0, nullptr, nullptr, nullptr); + } +}; + +#if BOO_HAS_VULKAN +struct CAABoxShaderVulkanDataBindingFactory : TShader::IDataBindingFactory +{ + boo::IShaderDataBinding* BuildShaderDataBinding(boo::IGraphicsDataFactory::Context& ctx, + CAABoxShader& filter) + { + boo::VulkanDataFactory::Context& cctx = static_cast(ctx); + + boo::IGraphicsBuffer* bufs[] = {filter.m_uniBuf}; + return cctx.newShaderDataBinding(filter.m_zOnly ? s_zOnlyPipeline : s_Pipeline, s_VtxFmt, + filter.m_vbo, nullptr, nullptr, 1, bufs, + nullptr, nullptr, nullptr, 0, nullptr, nullptr, nullptr); + } +}; +#endif + +TShader::IDataBindingFactory* CAABoxShader::Initialize(boo::GLDataFactory::Context& ctx) +{ + const char* uniNames[] = {"CAABoxUniform"}; + s_Pipeline = ctx.newShaderPipeline(VS, FS, 0, nullptr, 1, uniNames, boo::BlendFactor::SrcAlpha, + boo::BlendFactor::InvSrcAlpha, boo::Primitive::TriStrips, + boo::ZTest::LEqual, true, true, false, boo::CullMode::None); + s_zOnlyPipeline = ctx.newShaderPipeline(VS, FS, 0, nullptr, 1, uniNames, boo::BlendFactor::SrcAlpha, + boo::BlendFactor::InvSrcAlpha, boo::Primitive::TriStrips, + boo::ZTest::LEqual, true, false, false, boo::CullMode::None); + return new CAABoxShaderGLDataBindingFactory; +} + +#if BOO_HAS_VULKAN +TShader::IDataBindingFactory* CAABoxShader::Initialize(boo::VulkanDataFactory::Context& ctx) +{ + const boo::VertexElementDescriptor VtxVmt[] = + { + {nullptr, nullptr, boo::VertexSemantic::Position4}, + }; + s_VtxFmt = ctx.newVertexFormat(1, VtxVmt); + s_Pipeline = ctx.newShaderPipeline(VS, FS, s_VtxFmt, boo::BlendFactor::SrcAlpha, + boo::BlendFactor::InvSrcAlpha, boo::Primitive::TriStrips, + boo::ZTest::LEqual, true, true, false, boo::CullMode::None); + s_zOnlyPipeline = ctx.newShaderPipeline(VS, FS, s_VtxFmt, boo::BlendFactor::SrcAlpha, + boo::BlendFactor::InvSrcAlpha, boo::Primitive::TriStrips, + boo::ZTest::LEqual, true, false, false, boo::CullMode::None); + return new CAABoxShaderVulkanDataBindingFactory; +} +#endif + +} diff --git a/Runtime/Graphics/Shaders/CAABoxShaderHLSL.cpp b/Runtime/Graphics/Shaders/CAABoxShaderHLSL.cpp new file mode 100644 index 000000000..ff54dc447 --- /dev/null +++ b/Runtime/Graphics/Shaders/CAABoxShaderHLSL.cpp @@ -0,0 +1,83 @@ +#include "CAABoxShader.hpp" +#include "Graphics/CBooRenderer.hpp" + +namespace urde +{ + +static const char* VS = +"struct VertData\n" +"{\n" +" float4 posIn : POSITION;\n" +"};\n" +"\n" +"cbuffer CAABoxUniform : register(b0)\n" +"{\n" +" float4x4 xf;\n" +" float4 color;\n" +"};\n" +"\n" +"struct VertToFrag\n" +"{\n" +" float4 pos : SV_Position;\n" +" float4 color : COLOR;\n" +"};\n" +"\n" +"VertToFrag main(in VertData v)\n" +"{\n" +" VertToFrag vtf;\n" +" vtf.color = bu.color;\n" +" vtf.pos = bu.xf * vec4(v.posIn.xyz, 1.0);\n" +" return vtf;\n" +"}\n"; + +static const char* FS = +"#include \n" +"using namespace metal;\n" +"struct VertToFrag\n" +"{\n" +" float4 pos : SV_Position;\n" +" float4 color : COLOR;\n" +"};\n" +"\n" +"float4 main(in VertToFrag vtf) : SV_Target0\n" +"{\n" +" return vtf.color;\n" +"}\n"; + +URDE_DECL_SPECIALIZE_SHADER(CAABoxShader) + +static boo::IVertexFormat* s_VtxFmt = nullptr; +static boo::IShaderPipeline* s_Pipeline = nullptr; +static boo::IShaderPipeline* s_zOnlyPipeline = nullptr; + +struct CAABoxShaderD3DDataBindingFactory : TShader::IDataBindingFactory +{ + boo::IShaderDataBinding* BuildShaderDataBinding(boo::IGraphicsDataFactory::Context& ctx, + CAABoxShader& filter) + { + boo::ID3DDataFactory::Context& cctx = static_cast(ctx); + + boo::IGraphicsBuffer* bufs[] = {filter.m_uniBuf}; + return cctx.newShaderDataBinding(filter.m_zOnly ? s_zOnlyPipeline : s_Pipeline, s_VtxFmt, + filter.m_vbo, nullptr, nullptr, 1, bufs, + nullptr, nullptr, nullptr, 0, nullptr, nullptr, nullptr); + } +}; + +TShader::IDataBindingFactory* CAABoxShader::Initialize(boo::ID3DDataFactory::Context& ctx) +{ + const boo::VertexElementDescriptor VtxVmt[] = + { + {nullptr, nullptr, boo::VertexSemantic::Position4}, + }; + s_VtxFmt = ctx.newVertexFormat(1, VtxVmt); + s_Pipeline = ctx.newShaderPipeline(VS, FS, nullptr, nullptr, nullptr, s_VtxFmt, boo::BlendFactor::SrcAlpha, + boo::BlendFactor::InvSrcAlpha, boo::Primitive::TriStrips, + boo::ZTest::LEqual, true, true, false, boo::CullMode::None); + s_zOnlyPipeline = ctx.newShaderPipeline(VS, FS, nullptr, nullptr, nullptr, s_VtxFmt, boo::BlendFactor::SrcAlpha, + boo::BlendFactor::InvSrcAlpha, boo::Primitive::TriStrips, + boo::ZTest::LEqual, true, false, false, boo::CullMode::None); + return new CAABoxShaderD3DDataBindingFactory; +} + +} diff --git a/Runtime/Graphics/Shaders/CAABoxShaderMetal.cpp b/Runtime/Graphics/Shaders/CAABoxShaderMetal.cpp new file mode 100644 index 000000000..7542c6cbb --- /dev/null +++ b/Runtime/Graphics/Shaders/CAABoxShaderMetal.cpp @@ -0,0 +1,85 @@ +#include "CAABoxShader.hpp" +#include "Graphics/CBooRenderer.hpp" + +namespace urde +{ + +static const char* VS = +"#include \n" +"using namespace metal;\n" +"struct VertData\n" +"{\n" +" float4 posIn [[ attribute(0) ]];\n" +"};\n" +"\n" +"struct CAABoxUniform\n" +"{\n" +" float4x4 xf;\n" +" float4 color;\n" +"};\n" +"\n" +"struct VertToFrag\n" +"{\n" +" float4 pos [[ position ]];\n" +" float4 color;\n" +"};\n" +"\n" +"vertex VertToFrag vmain(VertData v [[ stage_in ]], constant CAABoxUniform& bu [[ buffer(2) ]])\n" +"{\n" +" VertToFrag vtf;\n" +" vtf.color = bu.color;\n" +" vtf.pos = bu.xf * vec4(v.posIn.xyz, 1.0);\n" +" return vtf;\n" +"}\n"; + +static const char* FS = +"#include \n" +"using namespace metal;\n" +"struct VertToFrag\n" +"{\n" +" float4 pos [[ position ]];\n" +" float4 color;\n" +"};\n" +"\n" +"fragment float4 fmain(VertToFrag vtf [[ stage_in ]])\n" +"{\n" +" return vtf.color;\n" +"}\n"; + +URDE_DECL_SPECIALIZE_SHADER(CAABoxShader) + +static boo::IVertexFormat* s_VtxFmt = nullptr; +static boo::IShaderPipeline* s_Pipeline = nullptr; +static boo::IShaderPipeline* s_zOnlyPipeline = nullptr; + +struct CAABoxShaderMetalDataBindingFactory : TShader::IDataBindingFactory +{ + boo::IShaderDataBinding* BuildShaderDataBinding(boo::IGraphicsDataFactory::Context& ctx, + CAABoxShader& filter) + { + boo::MetalDataFactory::Context& cctx = static_cast(ctx); + + boo::IGraphicsBuffer* bufs[] = {filter.m_uniBuf}; + return cctx.newShaderDataBinding(filter.m_zOnly ? s_zOnlyPipeline : s_Pipeline, s_VtxFmt, + filter.m_vbo, nullptr, nullptr, 1, bufs, + nullptr, nullptr, nullptr, 0, nullptr, nullptr, nullptr); + } +}; + +TShader::IDataBindingFactory* CAABoxShader::Initialize(boo::MetalDataFactory::Context& ctx) +{ + const boo::VertexElementDescriptor VtxVmt[] = + { + {nullptr, nullptr, boo::VertexSemantic::Position4}, + }; + s_VtxFmt = ctx.newVertexFormat(1, VtxVmt); + s_Pipeline = ctx.newShaderPipeline(VS, FS, s_VtxFmt, CGraphics::g_ViewportSamples, boo::BlendFactor::SrcAlpha, + boo::BlendFactor::InvSrcAlpha, boo::Primitive::TriStrips, + boo::ZTest::LEqual, true, true, false, boo::CullMode::None); + s_zOnlyPipeline = ctx.newShaderPipeline(VS, FS, s_VtxFmt, CGraphics::g_ViewportSamples, boo::BlendFactor::SrcAlpha, + boo::BlendFactor::InvSrcAlpha, boo::Primitive::TriStrips, + boo::ZTest::LEqual, true, false, false, boo::CullMode::None); + return new CAABoxShaderMetalDataBindingFactory; +} + +} diff --git a/Runtime/Graphics/Shaders/CCameraBlurFilter.cpp b/Runtime/Graphics/Shaders/CCameraBlurFilter.cpp index 02619333d..bcaff6440 100644 --- a/Runtime/Graphics/Shaders/CCameraBlurFilter.cpp +++ b/Runtime/Graphics/Shaders/CCameraBlurFilter.cpp @@ -1,5 +1,4 @@ #include "CCameraBlurFilter.hpp" -#include "Graphics/CGraphics.hpp" namespace urde { diff --git a/Runtime/Graphics/Shaders/CCameraBlurFilterGLSL.cpp b/Runtime/Graphics/Shaders/CCameraBlurFilterGLSL.cpp index d7feb81bc..1825a764e 100644 --- a/Runtime/Graphics/Shaders/CCameraBlurFilterGLSL.cpp +++ b/Runtime/Graphics/Shaders/CCameraBlurFilterGLSL.cpp @@ -1,6 +1,5 @@ #include "CCameraBlurFilter.hpp" #include "Graphics/CBooRenderer.hpp" -#include "GameGlobalObjects.hpp" namespace urde { @@ -127,7 +126,7 @@ TShader::IDataBindingFactory* CCameraBlurFilter::Initialize(b const char* uniNames[] = {"CameraBlurUniform"}; s_Pipeline = ctx.newShaderPipeline(VS, FS, 1, texNames, 1, uniNames, boo::BlendFactor::SrcAlpha, boo::BlendFactor::InvSrcAlpha, boo::Primitive::TriStrips, - boo::ZTest::None, false, true, true, boo::CullMode::None); + boo::ZTest::None, false, true, false, boo::CullMode::None); return new CCameraBlurFilterGLDataBindingFactory; } diff --git a/Runtime/Graphics/Shaders/CCameraBlurFilterHLSL.cpp b/Runtime/Graphics/Shaders/CCameraBlurFilterHLSL.cpp index 283c52907..3609976e6 100644 --- a/Runtime/Graphics/Shaders/CCameraBlurFilterHLSL.cpp +++ b/Runtime/Graphics/Shaders/CCameraBlurFilterHLSL.cpp @@ -1,6 +1,5 @@ #include "CCameraBlurFilter.hpp" #include "Graphics/CBooRenderer.hpp" -#include "GameGlobalObjects.hpp" namespace urde { diff --git a/Runtime/Graphics/Shaders/CCameraBlurFilterMetal.cpp b/Runtime/Graphics/Shaders/CCameraBlurFilterMetal.cpp index 274ad242a..3237384c6 100644 --- a/Runtime/Graphics/Shaders/CCameraBlurFilterMetal.cpp +++ b/Runtime/Graphics/Shaders/CCameraBlurFilterMetal.cpp @@ -1,6 +1,5 @@ #include "CCameraBlurFilter.hpp" #include "Graphics/CBooRenderer.hpp" -#include "GameGlobalObjects.hpp" namespace urde { diff --git a/Runtime/Graphics/Shaders/CTexturedQuadFilter.cpp b/Runtime/Graphics/Shaders/CTexturedQuadFilter.cpp index c793d03af..bd42a3490 100644 --- a/Runtime/Graphics/Shaders/CTexturedQuadFilter.cpp +++ b/Runtime/Graphics/Shaders/CTexturedQuadFilter.cpp @@ -9,8 +9,8 @@ CTexturedQuadFilter::CTexturedQuadFilter(boo::ITexture* tex) { } -CTexturedQuadFilter::CTexturedQuadFilter(EFilterType type, boo::ITexture* tex) -: m_booTex(tex) +CTexturedQuadFilter::CTexturedQuadFilter(EFilterType type, boo::ITexture* tex, bool gequal) +: m_booTex(tex), m_gequal(gequal) { m_token = CGraphics::g_BooFactory->commitTransaction([&](boo::IGraphicsDataFactory::Context& ctx) -> bool { @@ -28,14 +28,14 @@ CTexturedQuadFilter::CTexturedQuadFilter(EFilterType type, m_tex = tex; } -void CTexturedQuadFilter::draw(const zeus::CColor& color, float uvScale, const zeus::CRectangle& rect) +void CTexturedQuadFilter::draw(const zeus::CColor& color, float uvScale, const zeus::CRectangle& rect, float z) { Vert verts[4] = { - {{0.f, 0.f, 0.f}, {0.f, 0.f}}, - {{0.f, 1.f, 0.f}, {0.f, uvScale}}, - {{1.f, 0.f, 0.f}, {uvScale, 0.f}}, - {{1.f, 1.f, 0.f}, {uvScale, uvScale}}, + {{0.f, 0.f, z}, {0.f, 0.f}}, + {{0.f, 1.f, z}, {0.f, uvScale}}, + {{1.f, 0.f, z}, {uvScale, 0.f}}, + {{1.f, 1.f, z}, {uvScale, uvScale}}, }; m_vbo->load(verts, sizeof(verts)); diff --git a/Runtime/Graphics/Shaders/CTexturedQuadFilter.hpp b/Runtime/Graphics/Shaders/CTexturedQuadFilter.hpp index 5f01423ae..37e94ea46 100644 --- a/Runtime/Graphics/Shaders/CTexturedQuadFilter.hpp +++ b/Runtime/Graphics/Shaders/CTexturedQuadFilter.hpp @@ -32,6 +32,7 @@ protected: boo::IGraphicsBufferD* m_uniBuf; boo::IShaderDataBinding* m_dataBind = nullptr; Uniform m_uniform; + bool m_gequal; CTexturedQuadFilter(boo::ITexture* tex); @@ -44,12 +45,12 @@ public: static const zeus::CRectangle DefaultRect; CTexturedQuadFilter(EFilterType type, TLockedToken tex); - CTexturedQuadFilter(EFilterType type, boo::ITexture* tex); + CTexturedQuadFilter(EFilterType type, boo::ITexture* tex, bool gequal = false); CTexturedQuadFilter(const CTexturedQuadFilter&) = delete; CTexturedQuadFilter& operator=(const CTexturedQuadFilter&) = delete; CTexturedQuadFilter(CTexturedQuadFilter&&) = default; CTexturedQuadFilter& operator=(CTexturedQuadFilter&&) = default; - void draw(const zeus::CColor& color, float uvScale, const zeus::CRectangle& rect=DefaultRect); + void draw(const zeus::CColor& color, float uvScale, const zeus::CRectangle& rect=DefaultRect, float z=0.f); void drawCropped(const zeus::CColor& color, float uvScale); void drawVerts(const zeus::CColor& color, const Vert verts[4], float lod=0.f); void DrawFilter(EFilterShape shape, const zeus::CColor& color, float t); diff --git a/Runtime/Graphics/Shaders/CTexturedQuadFilterGLSL.cpp b/Runtime/Graphics/Shaders/CTexturedQuadFilterGLSL.cpp index a4c464f19..51e9d6bfe 100644 --- a/Runtime/Graphics/Shaders/CTexturedQuadFilterGLSL.cpp +++ b/Runtime/Graphics/Shaders/CTexturedQuadFilterGLSL.cpp @@ -105,11 +105,14 @@ URDE_DECL_SPECIALIZE_MULTI_BLEND_SHADER(CTexturedQuadFilter) static boo::IVertexFormat* s_VtxFmt = nullptr; static boo::IShaderPipeline* s_AlphaPipeline = nullptr; +static boo::IShaderPipeline* s_AlphaGEqualPipeline = nullptr; static boo::IShaderPipeline* s_AddPipeline = nullptr; static boo::IShaderPipeline* s_MultPipeline = nullptr; -static boo::IShaderPipeline* SelectPipeline(EFilterType type) +static boo::IShaderPipeline* SelectPipeline(EFilterType type, bool gequal) { + if (gequal) + return s_AlphaGEqualPipeline; switch (type) { case EFilterType::Blend: @@ -159,7 +162,7 @@ struct CTexturedQuadFilterGLDataBindingFactory : TMultiBlendShader::IDataBindingFactory { boo::IShaderDataBinding* BuildShaderDataBinding(boo::IGraphicsDataFactory::Context& ctx, @@ -178,7 +204,7 @@ struct CTexturedQuadFilterAlphaMetalDataBindingFactory : TMultiBlendShader::Initialize(); TShader::Initialize(); TShader::Initialize(); + TShader::Initialize(); TMultiBlendShader::Initialize(); TMultiBlendShader::Initialize(); TMultiBlendShader::Initialize(); @@ -364,6 +367,7 @@ void CMain::Shutdown() TShader::Shutdown(); TShader::Shutdown(); TShader::Shutdown(); + TShader::Shutdown(); TMultiBlendShader::Shutdown(); TMultiBlendShader::Shutdown(); TMultiBlendShader::Shutdown(); diff --git a/Runtime/Weapon/CPlayerGun.cpp b/Runtime/Weapon/CPlayerGun.cpp index a93bad19a..7b20fbcd2 100644 --- a/Runtime/Weapon/CPlayerGun.cpp +++ b/Runtime/Weapon/CPlayerGun.cpp @@ -80,6 +80,8 @@ CPlayerGun::CPlayerGun(TUniqueId playerId) x550_camBob.SetPlayerVelocity(zeus::CVector3f::skZero); x550_camBob.SetBobMagnitude(0.f); x550_camBob.SetBobTimeScale(0.f); + + m_aaboxShader.setAABB(x6c8_hologramClipCube); } void CPlayerGun::InitBeamData() @@ -2455,9 +2457,26 @@ zeus::CVector3f CPlayerGun::ConvertToScreenSpace(const zeus::CVector3f& pos, con return {-1.f, -1.f, 1.f}; } -static void CopyScreenTex() {} -static void DrawScreenTex(float f1) {} -static void DrawClipCube(const zeus::CAABox& aabb) {} +void CPlayerGun::CopyScreenTex() +{ + // Copy lower right quadrant to gpCopyTexBuf as RGBA8 + CGraphics::ResolveSpareTexture(g_Viewport); +} + +void CPlayerGun::DrawScreenTex(float z) const +{ + // Use CopyScreenTex rendering to draw over framebuffer pixels in front of `z` + // This is accomplished using orthographic projection quad with sweeping `y` coordinates + // Depth is set to GEQUAL to obscure pixels in front rather than behind + m_screenQuad.draw(zeus::CColor::skWhite, 1.f, CTexturedQuadFilter::DefaultRect, z); +} + +void CPlayerGun::DrawClipCube(const zeus::CAABox& aabb) const +{ + // Render AABB as completely transparent object, only modifying Z-buffer + // AABB has already been set in constructor (since it's constant) + m_aaboxShader.draw(zeus::CColor::skClear); +} static const CModelFlags kHandThermalFlag = {7, 0, 3, zeus::CColor::skWhite}; static const CModelFlags kHandHoloFlag = {1, 0, 3, zeus::CColor(0.75f, 0.5f, 0.f, 1.f)}; diff --git a/Runtime/Weapon/CPlayerGun.hpp b/Runtime/Weapon/CPlayerGun.hpp index 409d0024c..7c00d68b9 100644 --- a/Runtime/Weapon/CPlayerGun.hpp +++ b/Runtime/Weapon/CPlayerGun.hpp @@ -20,6 +20,8 @@ #include "World/CWorldShadow.hpp" #include "World/ScriptObjectSupport.hpp" #include "Graphics/CRainSplashGenerator.hpp" +#include "Graphics/Shaders/CTexturedQuadFilter.hpp" +#include "Graphics/Shaders/CAABoxShader.hpp" namespace urde { @@ -311,6 +313,9 @@ private: u32 _dummy = 0; }; + mutable CTexturedQuadFilter m_screenQuad = {EFilterType::Blend, CGraphics::g_SpareTexture, true}; + mutable CAABoxShader m_aaboxShader = {true}; + void InitBeamData(); void InitBombData(); void InitMuzzleData(); @@ -363,6 +368,9 @@ private: void RenderEnergyDrainEffects(const CStateManager& mgr) const; void DrawArm(const CStateManager& mgr, const zeus::CVector3f& pos, const CModelFlags& flags) const; zeus::CVector3f ConvertToScreenSpace(const zeus::CVector3f& pos, const CGameCamera& cam) const; + static void CopyScreenTex(); + void DrawScreenTex(float z) const; + void DrawClipCube(const zeus::CAABox& aabb) const; public: explicit CPlayerGun(TUniqueId playerId); diff --git a/hecl b/hecl index 2466f4f0e..af4857cfa 160000 --- a/hecl +++ b/hecl @@ -1 +1 @@ -Subproject commit 2466f4f0e37974b37709f1f4447d1adf185343b3 +Subproject commit af4857cfae81cb2ca03526bdbb76335d913a6e24