2
0
mirror of https://github.com/AxioDL/metaforce.git synced 2025-12-16 02:57:03 +00:00

CEnvFxShaders: Convert to hsh pipeline

This commit is contained in:
2020-10-02 21:32:22 -04:00
parent 6c56f6452e
commit b632885c81
6 changed files with 101 additions and 74 deletions

View File

@@ -2,44 +2,50 @@
#include "Runtime/World/CEnvFxManager.hpp"
#include <hecl/Pipeline.hpp>
#include "CEnvFxShaders.cpp.hshhead"
namespace urde {
using namespace hsh::pipeline;
void CEnvFxShaders::BuildShaderDataBinding(boo::IGraphicsDataFactory::Context& ctx, CEnvFxManager& fxMgr,
CEnvFxManagerGrid& grid) {
const auto uBufInfo = grid.m_uniformBuf.getBufferInfo();
const auto iBufInfo = grid.m_instBuf.getBufferInfo();
template <bool Blend>
struct CEnvFxShadersPipeline
// FIXME replace MultiplyAttachment with ERglBlendFactor One:One equivalent
: pipeline<topology<hsh::TriangleStrip>, std::conditional_t<Blend, BlendAttachment<false>, MultiplyAttachment<false>>,
depth_compare<hsh::LEqual>, depth_write<false>> {
CEnvFxShadersPipeline(hsh::vertex_buffer<CEnvFxShaders::Instance> vbo,
hsh::uniform_buffer<CEnvFxShaders::Uniform> envFxUniBuf,
hsh::uniform_buffer<CGraphics::CFogState> fogUniBuf, hsh::texture2d texFlake,
hsh::texture2d texEnv) {
hsh::float4 posIn = hsh::float4(vbo->positions[this->vertex_id], 1.f);
hsh::float4 flakeTexel = texFlake.sample<float>(vbo->uvs[this->vertex_id]);
hsh::float4 envTexel = texEnv.sample<float>(
(envFxUniBuf->envMtx * posIn).xy(),
// FIXME hsh bug: this appears to be completely ignored
hsh::sampler{hsh::Linear, hsh::Linear, hsh::Linear, hsh::ClampToEdge, hsh::ClampToEdge, hsh::ClampToEdge});
hsh::float4 color = vbo->color * envFxUniBuf->moduColor * flakeTexel * envTexel;
this->position = envFxUniBuf->proj * (envFxUniBuf->mv * posIn);
FOG_SHADER_UNIFORM(fogUniBuf)
// FIXME: hsh binds fog uniform to fragment stage
// only because of m_color reference in here. can/should we avoid that?
FOG_OUT_UNIFORM(this->color_out[0], fogUniBuf, color)
}
};
template struct CEnvFxShadersPipeline<true>;
template struct CEnvFxShadersPipeline<false>;
const std::array<boo::ObjToken<boo::IGraphicsBuffer>, 2> uniforms{{
uBufInfo.first.get(),
fxMgr.m_fogUniformBuf.get(),
}};
const std::array<size_t, 2> ubufOffsets{
size_t(uBufInfo.second),
0,
};
constexpr std::array<size_t, 2> ubufSizes{
sizeof(CEnvFxShaders::Uniform),
sizeof(CGraphics::g_Fog),
};
constexpr std::array<boo::PipelineStage, 2> uniformStages{
boo::PipelineStage::Vertex,
boo::PipelineStage::Fragment,
};
std::array<boo::ObjToken<boo::ITexture>, 2> textures{
fxMgr.xb74_txtrSnowFlake->GetBooTexture(),
fxMgr.x40_txtrEnvGradient->GetBooTexture(),
};
grid.m_snowBinding = ctx.newShaderDataBinding(
m_snowPipeline, nullptr, iBufInfo.first.get(), nullptr, uniforms.size(), uniforms.data(), uniformStages.data(),
ubufOffsets.data(), ubufSizes.data(), textures.size(), textures.data(), nullptr, nullptr, 0, iBufInfo.second);
textures[0] = fxMgr.xc48_underwaterFlake->GetBooTexture();
grid.m_underwaterBinding =
ctx.newShaderDataBinding(m_underwaterPipeline, nullptr, iBufInfo.first.get(), nullptr, uniforms.size(),
uniforms.data(), uniformStages.data(), ubufOffsets.data(), ubufSizes.data(),
textures.size(), textures.data(), nullptr, nullptr, 0, iBufInfo.second);
void CEnvFxShaders::BuildShaderDataBinding(CEnvFxManager& fxMgr, CEnvFxManagerGrid& grid) {
hsh::texture2d texFlake = fxMgr.xb74_txtrSnowFlake->GetBooTexture();
hsh::texture2d texEnv = fxMgr.x40_txtrEnvGradient->GetBooTexture();
hsh::vertex_buffer<Instance> vboBuf = grid.m_instBuf.get();
hsh::uniform_buffer<Uniform> envFxUniBuf = grid.m_uniformBuf.get();
hsh::uniform_buffer<CGraphics::CFogState> fogUniBuf = fxMgr.m_fogUniformBuf.get();
// FIXME hsh bug: can't bind all constant values
bool isUnderwater = false;
grid.m_snowBinding.hsh_snow_bind(
CEnvFxShadersPipeline<isUnderwater>(vboBuf, envFxUniBuf, fogUniBuf, texFlake, texEnv));
isUnderwater = true;
grid.m_underwaterBinding.hsh_underwater_bind(
CEnvFxShadersPipeline<isUnderwater>(vboBuf, envFxUniBuf, fogUniBuf, texFlake, texEnv));
}
} // namespace urde

View File

@@ -2,6 +2,8 @@
#include <array>
#include "hsh/hsh.h"
namespace urde {
class CEnvFxManager;
class CEnvFxManagerGrid;
@@ -20,8 +22,7 @@ public:
hsh::float4 moduColor;
};
static void BuildShaderDataBinding(CEnvFxManager& fxMgr,
CEnvFxManagerGrid& grid);
static void BuildShaderDataBinding(CEnvFxManager& fxMgr, CEnvFxManagerGrid& grid);
};
} // namespace urde

View File

@@ -16,7 +16,8 @@ struct CThermalColdFilterPipeline : pipeline<topology<hsh::TriangleStrip>,
CThermalColdFilterPipeline(hsh::vertex_buffer<CThermalColdFilter::Vert> vbo,
hsh::uniform_buffer<CThermalColdFilter::Uniform> ubo, hsh::render_texture2d sceneTex,
hsh::texture2d noiseTex) {
static hsh::float4 kRGBToYPrime = {0.257f, 0.504f, 0.098f, 0.f};
// FIXME hsh bug: cannot be const or static
hsh::float4 kRGBToYPrime{0.257f, 0.504f, 0.098f, 0.f};
this->position = hsh::float4(vbo->m_pos, 0.f, 1.f);
hsh::float4 noiseTexel = noiseTex.read<float>(Lookup8BPP(vbo->m_uvNoise, ubo->m_randOff));