mirror of
https://github.com/AxioDL/metaforce.git
synced 2025-07-05 05:15:53 +00:00
CFogVolumeFilter: Convert to hsh pipeline
This commit is contained in:
parent
b632885c81
commit
ba904ff996
@ -63,4 +63,5 @@ runtime_add_hsh(Graphics
|
|||||||
Shaders/CThermalHotFilter.cpp
|
Shaders/CThermalHotFilter.cpp
|
||||||
Shaders/CElementGenShaders.cpp
|
Shaders/CElementGenShaders.cpp
|
||||||
Shaders/CEnvFxShaders.cpp
|
Shaders/CEnvFxShaders.cpp
|
||||||
|
Shaders/CFogVolumeFilter.cpp
|
||||||
)
|
)
|
||||||
|
@ -1,60 +1,81 @@
|
|||||||
#include "Runtime/Graphics/Shaders/CFogVolumeFilter.hpp"
|
#include "Runtime/Graphics/Shaders/CFogVolumeFilter.hpp"
|
||||||
|
|
||||||
#include <array>
|
#include <array>
|
||||||
|
#include <zeus/CColor.hpp>
|
||||||
|
|
||||||
#include "Runtime/GameGlobalObjects.hpp"
|
#include "Runtime/GameGlobalObjects.hpp"
|
||||||
#include "Runtime/Graphics/CBooRenderer.hpp"
|
#include "Runtime/Graphics/CBooRenderer.hpp"
|
||||||
#include "Runtime/Graphics/CGraphics.hpp"
|
#include "Runtime/Graphics/CGraphics.hpp"
|
||||||
|
|
||||||
#include <boo/graphicsdev/IGraphicsDataFactory.hpp>
|
#include "CFogVolumeFilter.cpp.hshhead"
|
||||||
#include <hecl/Pipeline.hpp>
|
|
||||||
#include <zeus/CColor.hpp>
|
|
||||||
|
|
||||||
namespace urde {
|
namespace urde {
|
||||||
|
using namespace hsh::pipeline;
|
||||||
|
|
||||||
|
template <bool TwoWay>
|
||||||
|
struct CFogVolumeFilterPipeline
|
||||||
|
// FIXME replace BlendAttachment with ERglBlendFactor DstAlpha:One equivalent
|
||||||
|
: pipeline<topology<hsh::TriangleStrip>, std::conditional_t<TwoWay, SubtractAttachment<>, BlendAttachment<>>,
|
||||||
|
depth_compare<hsh::Always>, depth_write<false>> {
|
||||||
|
CFogVolumeFilterPipeline(hsh::vertex_buffer<CFogVolumeFilter::Vert> vbo,
|
||||||
|
hsh::uniform_buffer<CFogVolumeFilter::Uniform> uniBuf, hsh::render_texture2d frontfaceTex,
|
||||||
|
hsh::render_texture2d backfaceTex, hsh::texture2d linearizer) {
|
||||||
|
this->position = hsh::float4(vbo->m_pos.x, -vbo->m_pos.y, 0.f, 1.f);
|
||||||
|
const float linScale = 65535.f / 65536.f * 256.f;
|
||||||
|
const float uvBias = 0.5f / 256.f;
|
||||||
|
if constexpr (TwoWay) {
|
||||||
|
float frontY;
|
||||||
|
float backY;
|
||||||
|
float frontX = hsh::modf((1.f - frontfaceTex.sample<float>(vbo->m_uv).x) * linScale, frontY);
|
||||||
|
float backX = hsh::modf((1.f - backfaceTex.sample<float>(vbo->m_uv).x) * linScale, backY);
|
||||||
|
float frontLin =
|
||||||
|
linearizer.sample<float>(hsh::float2(frontX * 255.f / 256.f + uvBias, frontY / 256.f + uvBias)).x;
|
||||||
|
float backLin = linearizer.sample<float>(hsh::float2(backX * 255.f / 256.f + uvBias, backY / 256.f + uvBias)).x;
|
||||||
|
this->color_out[0] = hsh::float4(uniBuf->m_color.xyz(), (frontLin - backLin) * 10.f);
|
||||||
|
} else {
|
||||||
|
float y;
|
||||||
|
float x = hsh::modf((1.f - frontfaceTex.sample<float>(vbo->m_uv).x) * linScale, y);
|
||||||
|
float alpha = linearizer.sample<float>(hsh::float2(x * 255.f / 256.f + uvBias, y / 256.f + uvBias)).x * 10.f;
|
||||||
|
this->color_out[0] = uniBuf->m_color * alpha;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
template struct CFogVolumeFilterPipeline<true>;
|
||||||
|
template struct CFogVolumeFilterPipeline<false>;
|
||||||
|
|
||||||
CFogVolumeFilter::CFogVolumeFilter() {
|
CFogVolumeFilter::CFogVolumeFilter() {
|
||||||
CGraphics::CommitResources([&](boo::IGraphicsDataFactory::Context& ctx) {
|
constexpr std::array<Vert, 4> verts{{
|
||||||
constexpr std::array<Vert, 4> verts{{
|
{{-1.0, -1.0}, {0.0, 0.0}},
|
||||||
{{-1.0, -1.0}, {0.0, 0.0}},
|
{{-1.0, 1.0}, {0.0, 1.0}},
|
||||||
{{-1.0, 1.0}, {0.0, 1.0}},
|
{{1.0, -1.0}, {1.0, 0.0}},
|
||||||
{{1.0, -1.0}, {1.0, 0.0}},
|
{{1.0, 1.0}, {1.0, 1.0}},
|
||||||
{{1.0, 1.0}, {1.0, 1.0}},
|
}};
|
||||||
}};
|
m_vbo = hsh::create_vertex_buffer(verts);
|
||||||
m_vbo = ctx.newStaticBuffer(boo::BufferUse::Vertex, verts.data(), sizeof(Vert), verts.size());
|
m_uniBuf = hsh::create_dynamic_uniform_buffer<Uniform>();
|
||||||
m_uniBuf = ctx.newDynamicBuffer(boo::BufferUse::Uniform, sizeof(zeus::CColor), 1);
|
|
||||||
const std::array<boo::ObjToken<boo::ITexture>, 3> texs{
|
|
||||||
CGraphics::g_SpareTexture.get(),
|
|
||||||
CGraphics::g_SpareTexture.get(),
|
|
||||||
g_Renderer->GetFogRampTex().get(),
|
|
||||||
};
|
|
||||||
constexpr std::array bindIdxs{0, 1, 0};
|
|
||||||
constexpr std::array bindDepth{true, true, false};
|
|
||||||
const std::array<boo::ObjToken<boo::IGraphicsBuffer>, 1> ubufs{m_uniBuf.get()};
|
|
||||||
|
|
||||||
m_dataBind1Way =
|
// FIXME hsh bug: can't bind all constant values
|
||||||
ctx.newShaderDataBinding(s_1WayPipeline, m_vbo.get(), nullptr, nullptr, ubufs.size(), ubufs.data(), nullptr,
|
bool twoWay = false;
|
||||||
nullptr, nullptr, texs.size(), texs.data(), bindIdxs.data(), bindDepth.data());
|
m_dataBind1Way.hsh_1way_bind(
|
||||||
m_dataBind2Way =
|
CFogVolumeFilterPipeline<twoWay>(m_vbo.get(), m_uniBuf.get(), CGraphics::g_SpareTexture.get_depth(0),
|
||||||
ctx.newShaderDataBinding(s_2WayPipeline, m_vbo.get(), nullptr, nullptr, ubufs.size(), ubufs.data(), nullptr,
|
CGraphics::g_SpareTexture.get_depth(1), g_Renderer->GetFogRampTex()));
|
||||||
nullptr, nullptr, texs.size(), texs.data(), bindIdxs.data(), bindDepth.data());
|
twoWay = true;
|
||||||
return true;
|
m_dataBind2Way.hsh_2way_bind(
|
||||||
} BooTrace);
|
CFogVolumeFilterPipeline<twoWay>(m_vbo.get(), m_uniBuf.get(), CGraphics::g_SpareTexture.get_depth(0),
|
||||||
|
CGraphics::g_SpareTexture.get_depth(1), g_Renderer->GetFogRampTex()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void CFogVolumeFilter::draw2WayPass(const zeus::CColor& color) {
|
void CFogVolumeFilter::draw2WayPass(const zeus::CColor& color) {
|
||||||
SCOPED_GRAPHICS_DEBUG_GROUP("CFogVolumeFilter::draw2WayPass", zeus::skMagenta);
|
SCOPED_GRAPHICS_DEBUG_GROUP("CFogVolumeFilter::draw2WayPass", zeus::skMagenta);
|
||||||
|
|
||||||
m_uniBuf->load(&color, sizeof(zeus::CColor));
|
m_uniBuf.load({color});
|
||||||
CGraphics::SetShaderDataBinding(m_dataBind2Way);
|
m_dataBind2Way.draw(0, 4);
|
||||||
CGraphics::DrawArray(0, 4);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CFogVolumeFilter::draw1WayPass(const zeus::CColor& color) {
|
void CFogVolumeFilter::draw1WayPass(const zeus::CColor& color) {
|
||||||
SCOPED_GRAPHICS_DEBUG_GROUP("CFogVolumeFilter::draw1WayPass", zeus::skMagenta);
|
SCOPED_GRAPHICS_DEBUG_GROUP("CFogVolumeFilter::draw1WayPass", zeus::skMagenta);
|
||||||
|
|
||||||
m_uniBuf->load(&color, sizeof(zeus::CColor));
|
m_uniBuf.load({color});
|
||||||
CGraphics::SetShaderDataBinding(m_dataBind1Way);
|
m_dataBind1Way.draw(0, 4);
|
||||||
CGraphics::DrawArray(0, 4);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace urde
|
} // namespace urde
|
||||||
|
@ -4,11 +4,12 @@
|
|||||||
|
|
||||||
namespace zeus {
|
namespace zeus {
|
||||||
class CColor;
|
class CColor;
|
||||||
}
|
} // namespace zeus
|
||||||
|
|
||||||
namespace urde {
|
namespace urde {
|
||||||
|
|
||||||
class CFogVolumeFilter {
|
class CFogVolumeFilter {
|
||||||
|
public:
|
||||||
struct Vert {
|
struct Vert {
|
||||||
hsh::float2 m_pos;
|
hsh::float2 m_pos;
|
||||||
hsh::float2 m_uv;
|
hsh::float2 m_uv;
|
||||||
@ -17,6 +18,7 @@ class CFogVolumeFilter {
|
|||||||
hsh::float4 m_color;
|
hsh::float4 m_color;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
private:
|
||||||
hsh::owner<hsh::vertex_buffer<Vert>> m_vbo;
|
hsh::owner<hsh::vertex_buffer<Vert>> m_vbo;
|
||||||
hsh::dynamic_owner<hsh::uniform_buffer<Uniform>> m_uniBuf;
|
hsh::dynamic_owner<hsh::uniform_buffer<Uniform>> m_uniBuf;
|
||||||
hsh::binding m_dataBind1Way;
|
hsh::binding m_dataBind1Way;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user