mirror of
https://github.com/AxioDL/metaforce.git
synced 2025-12-10 03:47:42 +00:00
Work on HUD interfaces
This commit is contained in:
@@ -9,7 +9,7 @@ static const char* VS =
|
||||
"#version 330\n"
|
||||
BOO_GLSL_BINDING_HEAD
|
||||
"layout(location=0) in vec4 posIn;\n"
|
||||
"layout(location=0) in vec4 uvIn;\n"
|
||||
"layout(location=1) in vec4 uvIn;\n"
|
||||
"\n"
|
||||
"UBINDING0 uniform EnergyBarUniform\n"
|
||||
"{\n"
|
||||
|
||||
40
Runtime/Graphics/Shaders/CRadarPaintShader.cpp
Normal file
40
Runtime/Graphics/Shaders/CRadarPaintShader.cpp
Normal file
@@ -0,0 +1,40 @@
|
||||
#include "CRadarPaintShader.hpp"
|
||||
|
||||
namespace urde
|
||||
{
|
||||
|
||||
void CRadarPaintShader::draw(const std::vector<Instance>& instances, const CTexture* tex)
|
||||
{
|
||||
if (!instances.size())
|
||||
return;
|
||||
|
||||
if (instances.size() > m_maxInsts)
|
||||
{
|
||||
m_maxInsts = instances.size();
|
||||
m_tex = tex;
|
||||
m_token = CGraphics::CommitResources([this](boo::IGraphicsDataFactory::Context& ctx)
|
||||
{
|
||||
m_vbo = ctx.newDynamicBuffer(boo::BufferUse::Vertex, sizeof(Instance), m_maxInsts);
|
||||
m_uniBuf = ctx.newDynamicBuffer(boo::BufferUse::Uniform, sizeof(zeus::CMatrix4f), 1);
|
||||
TShader<CRadarPaintShader>::BuildShaderDataBinding(ctx, *this);
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
zeus::CMatrix4f uniMtx = CGraphics::GetPerspectiveProjectionMatrix(true) * CGraphics::g_GXModelView.toMatrix4f();
|
||||
m_uniBuf->load(&uniMtx, sizeof(zeus::CMatrix4f));
|
||||
|
||||
size_t mapSz = sizeof(Instance) * instances.size();
|
||||
Instance* insts = reinterpret_cast<Instance*>(m_vbo->map(mapSz));
|
||||
memmove(insts, instances.data(), mapSz);
|
||||
m_vbo->unmap();
|
||||
|
||||
CGraphics::SetShaderDataBinding(m_dataBind);
|
||||
CGraphics::DrawInstances(0, 4, instances.size());
|
||||
}
|
||||
|
||||
URDE_SPECIALIZE_SHADER(CRadarPaintShader)
|
||||
|
||||
void CRadarPaintShader::Shutdown() {}
|
||||
|
||||
}
|
||||
45
Runtime/Graphics/Shaders/CRadarPaintShader.hpp
Normal file
45
Runtime/Graphics/Shaders/CRadarPaintShader.hpp
Normal file
@@ -0,0 +1,45 @@
|
||||
#ifndef __URDE_CRADARPAINTSHADER_HPP__
|
||||
#define __URDE_CRADARPAINTSHADER_HPP__
|
||||
|
||||
#include "TShader.hpp"
|
||||
#include "zeus/CMatrix4f.hpp"
|
||||
#include "zeus/CColor.hpp"
|
||||
#include "zeus/CRectangle.hpp"
|
||||
#include "Camera/CCameraFilter.hpp"
|
||||
|
||||
namespace urde
|
||||
{
|
||||
|
||||
class CRadarPaintShader
|
||||
{
|
||||
friend struct CRadarPaintShaderGLDataBindingFactory;
|
||||
friend struct CRadarPaintShaderVulkanDataBindingFactory;
|
||||
friend struct CRadarPaintShaderMetalDataBindingFactory;
|
||||
friend struct CRadarPaintShaderD3DDataBindingFactory;
|
||||
|
||||
public:
|
||||
struct Instance
|
||||
{
|
||||
zeus::CVector3f pos[4];
|
||||
zeus::CVector2f uv[4];
|
||||
zeus::CColor color;
|
||||
};
|
||||
|
||||
private:
|
||||
boo::GraphicsDataToken m_token;
|
||||
boo::IGraphicsBufferD* m_vbo;
|
||||
boo::IGraphicsBufferD* m_uniBuf;
|
||||
boo::IShaderDataBinding* m_dataBind;
|
||||
const CTexture* m_tex = nullptr;
|
||||
size_t m_maxInsts = 0;
|
||||
|
||||
public:
|
||||
void draw(const std::vector<Instance>& instances, const CTexture* tex);
|
||||
|
||||
using _CLS = CRadarPaintShader;
|
||||
#include "TShaderDecl.hpp"
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // __URDE_CRADARPAINTSHADER_HPP__
|
||||
137
Runtime/Graphics/Shaders/CRadarPaintShaderGLSL.cpp
Normal file
137
Runtime/Graphics/Shaders/CRadarPaintShaderGLSL.cpp
Normal file
@@ -0,0 +1,137 @@
|
||||
#include "CRadarPaintShader.hpp"
|
||||
#include "TShader.hpp"
|
||||
#include "Graphics/CTexture.hpp"
|
||||
|
||||
namespace urde
|
||||
{
|
||||
|
||||
static const char* VS =
|
||||
"#version 330\n"
|
||||
BOO_GLSL_BINDING_HEAD
|
||||
"layout(location=0) in vec4 posIn[4];\n"
|
||||
"layout(location=4) in vec4 uvIn[4];\n"
|
||||
"layout(location=8) in vec4 colorIn;\n"
|
||||
"\n"
|
||||
"UBINDING0 uniform RadarPaintUniform\n"
|
||||
"{\n"
|
||||
" mat4 xf;\n"
|
||||
"};\n"
|
||||
"\n"
|
||||
"struct VertToFrag\n"
|
||||
"{\n"
|
||||
" vec4 color;\n"
|
||||
" vec2 uv;\n"
|
||||
"};\n"
|
||||
"\n"
|
||||
"SBINDING(0) out VertToFrag vtf;\n"
|
||||
"void main()\n"
|
||||
"{\n"
|
||||
" vtf.color = colorIn;\n"
|
||||
" vtf.uv = uvIn[gl_VertexID].xy;\n"
|
||||
" gl_Position = xf * vec4(posIn[gl_VertexID].xyz, 1.0);\n"
|
||||
"}\n";
|
||||
|
||||
static const char* FS =
|
||||
"#version 330\n"
|
||||
BOO_GLSL_BINDING_HEAD
|
||||
"struct VertToFrag\n"
|
||||
"{\n"
|
||||
" vec4 color;\n"
|
||||
" vec2 uv;\n"
|
||||
"};\n"
|
||||
"\n"
|
||||
"SBINDING(0) in VertToFrag vtf;\n"
|
||||
"layout(location=0) out vec4 colorOut;\n"
|
||||
"TBINDING0 uniform sampler2D tex;\n"
|
||||
"void main()\n"
|
||||
"{\n"
|
||||
" colorOut = vtf.color * texture(tex, vtf.uv);\n"
|
||||
"}\n";
|
||||
|
||||
URDE_DECL_SPECIALIZE_SHADER(CRadarPaintShader)
|
||||
|
||||
static boo::IVertexFormat* s_VtxFmt = nullptr;
|
||||
static boo::IShaderPipeline* s_Pipeline = nullptr;
|
||||
|
||||
struct CRadarPaintShaderGLDataBindingFactory : TShader<CRadarPaintShader>::IDataBindingFactory
|
||||
{
|
||||
boo::IShaderDataBinding* BuildShaderDataBinding(boo::IGraphicsDataFactory::Context& ctx,
|
||||
CRadarPaintShader& filter)
|
||||
{
|
||||
boo::GLDataFactory::Context& cctx = static_cast<boo::GLDataFactory::Context&>(ctx);
|
||||
|
||||
const boo::VertexElementDescriptor VtxVmt[] =
|
||||
{
|
||||
{filter.m_vbo, nullptr, boo::VertexSemantic::Position4, 0},
|
||||
{filter.m_vbo, nullptr, boo::VertexSemantic::Position4, 1},
|
||||
{filter.m_vbo, nullptr, boo::VertexSemantic::Position4, 2},
|
||||
{filter.m_vbo, nullptr, boo::VertexSemantic::Position4, 3},
|
||||
{filter.m_vbo, nullptr, boo::VertexSemantic::UV4, 0},
|
||||
{filter.m_vbo, nullptr, boo::VertexSemantic::UV4, 1},
|
||||
{filter.m_vbo, nullptr, boo::VertexSemantic::UV4, 2},
|
||||
{filter.m_vbo, nullptr, boo::VertexSemantic::UV4, 3},
|
||||
{filter.m_vbo, nullptr, boo::VertexSemantic::Color}
|
||||
};
|
||||
boo::IVertexFormat* vtxFmt = ctx.newVertexFormat(9, VtxVmt);
|
||||
boo::IGraphicsBuffer* bufs[] = {filter.m_uniBuf};
|
||||
boo::PipelineStage stages[] = {boo::PipelineStage::Vertex};
|
||||
boo::ITexture* texs[] = {filter.m_tex->GetBooTexture()};
|
||||
return cctx.newShaderDataBinding(s_Pipeline,
|
||||
vtxFmt, nullptr, filter.m_vbo, nullptr,
|
||||
1, bufs, stages, nullptr, nullptr, 1, texs, nullptr, nullptr);
|
||||
}
|
||||
};
|
||||
|
||||
#if BOO_HAS_VULKAN
|
||||
struct CRadarPaintShaderVulkanDataBindingFactory : TShader<CRadarPaintShader>::IDataBindingFactory
|
||||
{
|
||||
boo::IShaderDataBinding* BuildShaderDataBinding(boo::IGraphicsDataFactory::Context& ctx,
|
||||
CEnergyBarShader& filter)
|
||||
{
|
||||
boo::VulkanDataFactory::Context& cctx = static_cast<boo::VulkanDataFactory::Context&>(ctx);
|
||||
|
||||
boo::IGraphicsBuffer* bufs[] = {filter.m_uniBuf};
|
||||
boo::ITexture* texs[] = {filter.m_tex->GetBooTexture()};
|
||||
return cctx.newShaderDataBinding(s_Pipeline, s_VtxFmt,
|
||||
nullptr, filter.m_vbo, nullptr, 1, bufs,
|
||||
nullptr, nullptr, nullptr, 1, texs, nullptr, nullptr);
|
||||
}
|
||||
};
|
||||
#endif
|
||||
|
||||
TShader<CRadarPaintShader>::IDataBindingFactory*
|
||||
CRadarPaintShader::Initialize(boo::GLDataFactory::Context& ctx)
|
||||
{
|
||||
const char* uniNames[] = {"RadarPaintUniform"};
|
||||
const char* texNames[] = {"tex"};
|
||||
s_Pipeline = ctx.newShaderPipeline(VS, FS, 1, texNames, 1, uniNames, boo::BlendFactor::SrcAlpha,
|
||||
boo::BlendFactor::One, boo::Primitive::TriStrips,
|
||||
boo::ZTest::None, false, true, false, boo::CullMode::None);
|
||||
return new CRadarPaintShaderGLDataBindingFactory;
|
||||
}
|
||||
|
||||
#if BOO_HAS_VULKAN
|
||||
TShader<CRadarPaintShader>::IDataBindingFactory*
|
||||
CRadarPaintShader::Initialize(boo::VulkanDataFactory::Context& ctx)
|
||||
{
|
||||
const boo::VertexElementDescriptor VtxVmt[] =
|
||||
{
|
||||
{nullptr, nullptr, boo::VertexSemantic::Position4, 0},
|
||||
{nullptr, nullptr, boo::VertexSemantic::Position4, 1},
|
||||
{nullptr, nullptr, boo::VertexSemantic::Position4, 2},
|
||||
{nullptr, nullptr, boo::VertexSemantic::Position4, 3},
|
||||
{nullptr, nullptr, boo::VertexSemantic::UV4, 0},
|
||||
{nullptr, nullptr, boo::VertexSemantic::UV4, 1},
|
||||
{nullptr, nullptr, boo::VertexSemantic::UV4, 2},
|
||||
{nullptr, nullptr, boo::VertexSemantic::UV4, 3},
|
||||
{nullptr, nullptr, boo::VertexSemantic::Color}
|
||||
};
|
||||
s_VtxFmt = ctx.newVertexFormat(2, VtxVmt);
|
||||
s_Pipeline = ctx.newShaderPipeline(VS, FS, s_VtxFmt, boo::BlendFactor::SrcAlpha,
|
||||
boo::BlendFactor::One, boo::Primitive::TriStrips,
|
||||
boo::ZTest::None, false, true, false, boo::CullMode::None);
|
||||
return new CRadarPaintShaderVulkanDataBindingFactory;
|
||||
}
|
||||
#endif
|
||||
|
||||
}
|
||||
0
Runtime/Graphics/Shaders/CRadarPaintShaderHLSL.cpp
Normal file
0
Runtime/Graphics/Shaders/CRadarPaintShaderHLSL.cpp
Normal file
102
Runtime/Graphics/Shaders/CRadarPaintShaderMetal.cpp
Normal file
102
Runtime/Graphics/Shaders/CRadarPaintShaderMetal.cpp
Normal file
@@ -0,0 +1,102 @@
|
||||
#include "CRadarPaintShader.hpp"
|
||||
#include "TShader.hpp"
|
||||
#include "Graphics/CTexture.hpp"
|
||||
|
||||
namespace urde
|
||||
{
|
||||
|
||||
static const char* VS =
|
||||
"#include <metal_stdlib>\n"
|
||||
"using namespace metal;\n"
|
||||
"struct VertData\n"
|
||||
"{\n"
|
||||
" float4 posIn[4];\n"
|
||||
" float4 uvIn[4];\n"
|
||||
" float4 colorIn;\n"
|
||||
"};\n"
|
||||
"\n"
|
||||
"struct RadarPaintUniform\n"
|
||||
"{\n"
|
||||
" float4x4 xf;\n"
|
||||
"};\n"
|
||||
"\n"
|
||||
"struct VertToFrag\n"
|
||||
"{\n"
|
||||
" float4 position [[ position ]];\n"
|
||||
" float4 color;\n"
|
||||
" float2 uv;\n"
|
||||
"};\n"
|
||||
"\n"
|
||||
"vertex VertToFrag vmain(constant VertData* va [[ buffer(1) ]],\n"
|
||||
" uint vertId [[ vertex_id ]], uint instId [[ instance_id ]],\n"
|
||||
" constant RadarPaintUniform& rpu [[ buffer(2) ]])\n"
|
||||
"{\n"
|
||||
" VertToFrag vtf;\n"
|
||||
" constant VertData& v = va[instId];\n"
|
||||
" vtf.color = v.colorIn;\n"
|
||||
" vtf.uv = v.uvIn[vertId].xy;\n"
|
||||
" vtf.position = rpu.xf * vec4(v.posIn[vertId].xyz, 1.0);\n"
|
||||
" return vtf;\n"
|
||||
"}\n";
|
||||
|
||||
static const char* FS =
|
||||
"#include <metal_stdlib>\n"
|
||||
"using namespace metal;\n"
|
||||
"constexpr sampler samp(address::repeat, filter::linear, mip_filter::linear);\n"
|
||||
"struct VertToFrag\n"
|
||||
"{\n"
|
||||
" float4 position [[ position ]];\n"
|
||||
" float4 color;\n"
|
||||
" float2 uv;\n"
|
||||
"};\n"
|
||||
"\n"
|
||||
"fragment float4 fmain(VertToFrag vtf [[ stage_in ]],\n"
|
||||
" texture2d<float> tex [[ texture(0) ]])\n"
|
||||
"{\n"
|
||||
" return vtf.color * tex.sample(samp, vtf.uv);\n"
|
||||
"}\n";
|
||||
|
||||
URDE_DECL_SPECIALIZE_SHADER(CRadarPaintShader)
|
||||
|
||||
static boo::IVertexFormat* s_VtxFmt = nullptr;
|
||||
static boo::IShaderPipeline* s_Pipeline = nullptr;
|
||||
|
||||
struct CRadarPaintShaderMetalDataBindingFactory : TShader<CRadarPaintShader>::IDataBindingFactory
|
||||
{
|
||||
boo::IShaderDataBinding* BuildShaderDataBinding(boo::IGraphicsDataFactory::Context& ctx,
|
||||
CRadarPaintShader& filter)
|
||||
{
|
||||
boo::MetalDataFactory::Context& cctx = static_cast<boo::MetalDataFactory::Context&>(ctx);
|
||||
|
||||
boo::IGraphicsBuffer* bufs[] = {filter.m_uniBuf};
|
||||
boo::ITexture* texs[] = {filter.m_tex->GetBooTexture()};
|
||||
return cctx.newShaderDataBinding(s_Pipeline, s_VtxFmt,
|
||||
nullptr, filter.m_vbo, nullptr, 1, bufs,
|
||||
nullptr, nullptr, nullptr, 1, texs, nullptr, nullptr);
|
||||
}
|
||||
};
|
||||
|
||||
TShader<CRadarPaintShader>::IDataBindingFactory*
|
||||
CRadarPaintShader::Initialize(boo::MetalDataFactory::Context& ctx)
|
||||
{
|
||||
const boo::VertexElementDescriptor VtxVmt[] =
|
||||
{
|
||||
{nullptr, nullptr, boo::VertexSemantic::Position4, 0},
|
||||
{nullptr, nullptr, boo::VertexSemantic::Position4, 1},
|
||||
{nullptr, nullptr, boo::VertexSemantic::Position4, 2},
|
||||
{nullptr, nullptr, boo::VertexSemantic::Position4, 3},
|
||||
{nullptr, nullptr, boo::VertexSemantic::UV4, 0},
|
||||
{nullptr, nullptr, boo::VertexSemantic::UV4, 1},
|
||||
{nullptr, nullptr, boo::VertexSemantic::UV4, 2},
|
||||
{nullptr, nullptr, boo::VertexSemantic::UV4, 3},
|
||||
{nullptr, nullptr, boo::VertexSemantic::Color}
|
||||
};
|
||||
s_VtxFmt = ctx.newVertexFormat(2, VtxVmt);
|
||||
s_Pipeline = ctx.newShaderPipeline(VS, FS, s_VtxFmt, CGraphics::g_ViewportSamples,
|
||||
boo::BlendFactor::SrcAlpha,
|
||||
boo::BlendFactor::One, boo::Primitive::TriStrips,
|
||||
boo::ZTest::None, false, true, false, boo::CullMode::None);
|
||||
return new CRadarPaintShaderMetalDataBindingFactory;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user