2018-10-07 03:42:33 +00:00
|
|
|
#pragma once
|
2017-08-08 06:03:57 +00:00
|
|
|
|
2019-09-29 02:22:12 +00:00
|
|
|
#include <array>
|
2019-09-28 02:53:03 +00:00
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
#include "Runtime/CToken.hpp"
|
|
|
|
#include "Runtime/Graphics/CTexture.hpp"
|
|
|
|
#include "Runtime/Graphics/Shaders/CModelShaders.hpp"
|
|
|
|
#include "Runtime/World/CFluidPlaneManager.hpp"
|
|
|
|
|
2018-10-07 02:59:17 +00:00
|
|
|
#include "Shaders/shader_CFluidPlaneShader.hpp"
|
2017-08-08 06:03:57 +00:00
|
|
|
|
2022-02-01 00:06:54 +00:00
|
|
|
//#include <boo/graphicsdev/IGraphicsDataFactory.hpp>
|
2019-09-28 02:53:03 +00:00
|
|
|
|
|
|
|
#include <zeus/CColor.hpp>
|
|
|
|
#include <zeus/CMatrix4f.hpp>
|
|
|
|
#include <zeus/CVector3f.hpp>
|
|
|
|
#include <zeus/CVector4f.hpp>
|
|
|
|
|
2021-04-10 08:42:06 +00:00
|
|
|
namespace metaforce {
|
2017-08-08 06:03:57 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
class CFluidPlaneShader {
|
2017-08-10 23:13:25 +00:00
|
|
|
public:
|
2018-12-08 05:30:43 +00:00
|
|
|
struct Vertex {
|
|
|
|
zeus::CVector3f m_pos;
|
|
|
|
zeus::CVector3f m_norm;
|
|
|
|
zeus::CVector3f m_binorm;
|
|
|
|
zeus::CVector3f m_tangent;
|
|
|
|
zeus::CColor m_color;
|
|
|
|
|
|
|
|
Vertex() = default;
|
|
|
|
Vertex(const zeus::CVector3f& position) : m_pos(position) {}
|
|
|
|
Vertex(const zeus::CVector3f& position, const zeus::CColor& color) : m_pos(position), m_color(color) {}
|
|
|
|
Vertex(const zeus::CVector3f& position, const zeus::CVector3f& normal, const zeus::CColor& color)
|
|
|
|
: m_pos(position), m_norm(normal), m_color(color) {}
|
|
|
|
Vertex(const zeus::CVector3f& position, const zeus::CVector3f& normal, const zeus::CVector3f& binormal,
|
|
|
|
const zeus::CVector3f& tangent, const zeus::CColor& color)
|
|
|
|
: m_pos(position), m_norm(normal), m_binorm(binormal), m_tangent(tangent), m_color(color) {}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct PatchVertex {
|
|
|
|
zeus::CVector4f m_pos;
|
2019-09-29 02:22:12 +00:00
|
|
|
std::array<float, 4> m_outerLevels{};
|
|
|
|
std::array<float, 4> m_innerLevels{};
|
2018-12-08 05:30:43 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct RenderSetupInfo {
|
2019-09-29 02:22:12 +00:00
|
|
|
std::array<zeus::CMatrix4f, 6> texMtxs;
|
2018-12-08 05:30:43 +00:00
|
|
|
zeus::CMatrix4f normMtx;
|
|
|
|
float indScale = 1.f;
|
2019-09-29 02:22:12 +00:00
|
|
|
std::array<zeus::CColor, 4> kColors;
|
2018-12-08 05:30:43 +00:00
|
|
|
std::vector<CLight> lights;
|
|
|
|
};
|
2017-08-14 03:55:06 +00:00
|
|
|
|
2017-08-10 23:13:25 +00:00
|
|
|
private:
|
2022-02-01 00:06:54 +00:00
|
|
|
// struct ShaderPair {
|
|
|
|
// boo::ObjToken<boo::IShaderPipeline> m_regular;
|
|
|
|
// boo::ObjToken<boo::IShaderPipeline> m_tessellation;
|
|
|
|
// void reset() {
|
|
|
|
// m_regular.reset();
|
|
|
|
// m_tessellation.reset();
|
|
|
|
// }
|
|
|
|
// };
|
|
|
|
//
|
|
|
|
// struct BindingPair {
|
|
|
|
// boo::ObjToken<boo::IShaderDataBinding> m_regular;
|
|
|
|
// boo::ObjToken<boo::IShaderDataBinding> m_tessellation;
|
|
|
|
// };
|
|
|
|
|
|
|
|
// class Cache {
|
|
|
|
// std::array<ShaderPair, 1024> m_cache{};
|
|
|
|
// std::array<ShaderPair, 8> m_doorCache{};
|
|
|
|
// ShaderPair& CacheSlot(const SFluidPlaneShaderInfo& info, int i) { return m_cache[i]; }
|
|
|
|
// ShaderPair& CacheSlot(const SFluidPlaneDoorShaderInfo& info, int i) { return m_doorCache[i]; }
|
|
|
|
// static u16 MakeCacheKey(const SFluidPlaneShaderInfo& info);
|
|
|
|
// static u16 MakeCacheKey(const SFluidPlaneDoorShaderInfo& info);
|
|
|
|
//
|
|
|
|
// public:
|
|
|
|
// template <class T>
|
|
|
|
// ShaderPair GetOrBuildShader(const T& info);
|
|
|
|
// void Clear();
|
|
|
|
// };
|
|
|
|
// static Cache _cache;
|
2018-12-08 05:30:43 +00:00
|
|
|
|
|
|
|
struct Ripple {
|
|
|
|
zeus::CVector4f center; // time, distFalloff
|
|
|
|
zeus::CVector4f params; // amplitude, lookupPhase, lookupTime
|
|
|
|
};
|
|
|
|
|
2022-05-02 23:42:59 +00:00
|
|
|
// struct Uniform {
|
|
|
|
// zeus::CMatrix4f m_mv;
|
|
|
|
// zeus::CMatrix4f m_mvNorm;
|
|
|
|
// zeus::CMatrix4f m_proj;
|
|
|
|
// std::array<zeus::CMatrix4f, 6> m_texMtxs;
|
|
|
|
// std::array<Ripple, 20> m_ripple;
|
|
|
|
// zeus::CVector4f m_colorMul;
|
|
|
|
// std::array<zeus::CVector4f, 3> m_pad; // rippleNormResolution, Pad out to 1280 bytes
|
|
|
|
// CModelShaders::LightingUniform m_lighting;
|
|
|
|
// zeus::CVector3f m_pad2; // Pad out to 768 bytes, also holds ind scale
|
|
|
|
// };
|
2018-12-08 05:30:43 +00:00
|
|
|
|
|
|
|
TLockedToken<CTexture> m_patternTex1;
|
|
|
|
TLockedToken<CTexture> m_patternTex2;
|
|
|
|
TLockedToken<CTexture> m_colorTex;
|
|
|
|
TLockedToken<CTexture> m_bumpMap;
|
|
|
|
TLockedToken<CTexture> m_envMap;
|
|
|
|
TLockedToken<CTexture> m_envBumpMap;
|
|
|
|
TLockedToken<CTexture> m_lightmap;
|
2022-07-29 20:16:55 +00:00
|
|
|
// aurora::gfx::TextureHandle m_rippleMap;
|
2022-02-01 00:06:54 +00:00
|
|
|
// boo::ObjToken<boo::IGraphicsBufferD> m_vbo;
|
|
|
|
// boo::ObjToken<boo::IGraphicsBufferD> m_pvbo;
|
|
|
|
// boo::ObjToken<boo::IGraphicsBufferD> m_uniBuf;
|
|
|
|
// ShaderPair m_pipelines;
|
|
|
|
// BindingPair m_dataBind;
|
2018-12-08 05:30:43 +00:00
|
|
|
int m_lastBind = -1;
|
2017-08-08 06:03:57 +00:00
|
|
|
|
2022-02-01 00:06:54 +00:00
|
|
|
//#if BOO_HAS_GL
|
|
|
|
// static ShaderPair BuildShader(boo::GLDataFactory::Context& ctx, const SFluidPlaneShaderInfo& info);
|
|
|
|
// static ShaderPair BuildShader(boo::GLDataFactory::Context& ctx, const SFluidPlaneDoorShaderInfo& info);
|
|
|
|
// BindingPair BuildBinding(boo::GLDataFactory::Context& ctx, const ShaderPair& pipeline);
|
|
|
|
//#endif
|
|
|
|
//#if _WIN32
|
|
|
|
// static ShaderPair BuildShader(boo::D3D11DataFactory::Context& ctx, const SFluidPlaneShaderInfo& info);
|
|
|
|
// static ShaderPair BuildShader(boo::D3D11DataFactory::Context& ctx, const SFluidPlaneDoorShaderInfo& info);
|
|
|
|
// BindingPair BuildBinding(boo::D3D11DataFactory::Context& ctx, const ShaderPair& pipeline);
|
|
|
|
//#endif
|
|
|
|
//#if BOO_HAS_METAL
|
|
|
|
// static ShaderPair BuildShader(boo::MetalDataFactory::Context& ctx, const SFluidPlaneShaderInfo& info);
|
|
|
|
// static ShaderPair BuildShader(boo::MetalDataFactory::Context& ctx, const SFluidPlaneDoorShaderInfo& info);
|
|
|
|
// BindingPair BuildBinding(boo::MetalDataFactory::Context& ctx, const ShaderPair& pipeline);
|
|
|
|
//#endif
|
|
|
|
//#if BOO_HAS_VULKAN
|
|
|
|
// static ShaderPair BuildShader(boo::VulkanDataFactory::Context& ctx, const SFluidPlaneShaderInfo& info);
|
|
|
|
// static ShaderPair BuildShader(boo::VulkanDataFactory::Context& ctx, const SFluidPlaneDoorShaderInfo& info);
|
|
|
|
// BindingPair BuildBinding(boo::VulkanDataFactory::Context& ctx, const ShaderPair& pipeline);
|
|
|
|
//#endif
|
2017-08-08 06:03:57 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
template <class F>
|
|
|
|
static void _Shutdown();
|
|
|
|
|
2019-06-21 06:02:56 +00:00
|
|
|
void PrepareBinding(u32 maxVertCount);
|
2018-05-20 22:38:56 +00:00
|
|
|
|
2017-08-08 06:03:57 +00:00
|
|
|
public:
|
2018-12-08 05:30:43 +00:00
|
|
|
CFluidPlaneShader(EFluidType type, const TLockedToken<CTexture>& patternTex1,
|
|
|
|
const TLockedToken<CTexture>& patternTex2, const TLockedToken<CTexture>& colorTex,
|
|
|
|
const TLockedToken<CTexture>& bumpMap, const TLockedToken<CTexture>& envMap,
|
|
|
|
const TLockedToken<CTexture>& envBumpMap, const TLockedToken<CTexture>& lightmap,
|
2022-07-29 20:16:55 +00:00
|
|
|
CTexture& rippleMap, bool doubleLightmapBlend, bool additive,
|
2018-12-08 05:30:43 +00:00
|
|
|
u32 maxVertCount);
|
|
|
|
CFluidPlaneShader(const TLockedToken<CTexture>& patternTex1, const TLockedToken<CTexture>& patternTex2,
|
|
|
|
const TLockedToken<CTexture>& colorTex, u32 maxVertCount);
|
|
|
|
void prepareDraw(const RenderSetupInfo& info);
|
|
|
|
void prepareDraw(const RenderSetupInfo& info, const zeus::CVector3f& waterCenter, const CRippleManager& rippleManager,
|
|
|
|
const zeus::CColor& colorMul, float rippleNormResolution);
|
|
|
|
void bindRegular() {
|
|
|
|
if (m_lastBind != 0) {
|
2022-02-01 00:06:54 +00:00
|
|
|
// CGraphics::SetShaderDataBinding(m_dataBind.m_regular);
|
2018-12-08 05:30:43 +00:00
|
|
|
m_lastBind = 0;
|
2018-06-07 04:43:26 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
|
|
|
bool bindTessellation() {
|
|
|
|
if (m_lastBind != 1) {
|
2022-02-01 00:06:54 +00:00
|
|
|
// CGraphics::SetShaderDataBinding(m_dataBind.m_tessellation);
|
2018-12-08 05:30:43 +00:00
|
|
|
m_lastBind = 1;
|
2018-06-07 04:43:26 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
void doneDrawing() { m_lastBind = -1; }
|
|
|
|
void loadVerts(const std::vector<Vertex>& verts, const std::vector<PatchVertex>& pVerts);
|
2019-06-21 06:02:56 +00:00
|
|
|
bool isReady() const {
|
2022-02-01 00:06:54 +00:00
|
|
|
// return m_pipelines.m_regular->isReady() && (!m_pipelines.m_tessellation || m_pipelines.m_tessellation->isReady());
|
|
|
|
return false;
|
2019-06-21 06:02:56 +00:00
|
|
|
}
|
2017-08-14 03:55:06 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
static void Shutdown();
|
2017-08-08 06:03:57 +00:00
|
|
|
};
|
|
|
|
|
2021-04-10 08:42:06 +00:00
|
|
|
} // namespace metaforce
|