#pragma once #include #include #include "Runtime/CToken.hpp" #include "Runtime/Graphics/CTexture.hpp" #include "Runtime/Graphics/Shaders/CModelShaders.hpp" #include "Runtime/World/CFluidPlaneManager.hpp" #include "zeus/CColor.hpp" #include "zeus/CMatrix4f.hpp" #include "zeus/CVector3f.hpp" #include "zeus/CVector4f.hpp" namespace urde { enum class EFluidType { NormalWater, PoisonWater, Lava, PhazonFluid, Four, ThickLava }; class CFluidPlaneShader { public: 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; std::array m_outerLevels{}; std::array m_innerLevels{}; }; struct RenderSetupInfo { std::array texMtxs; zeus::CMatrix4f normMtx; float indScale = 1.f; std::array kColors; std::vector lights; }; private: struct BindingPair { hsh::binding m_regular, m_tessellation; }; struct Ripple { zeus::CVector4f center; // time, distFalloff zeus::CVector4f params; // amplitude, lookupPhase, lookupTime }; struct Uniform { zeus::CMatrix4f m_mv; zeus::CMatrix4f m_mvNorm; zeus::CMatrix4f m_proj; std::array m_texMtxs; std::array m_ripple; zeus::CVector4f m_colorMul; std::array 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 }; TLockedToken m_patternTex1; TLockedToken m_patternTex2; TLockedToken m_colorTex; TLockedToken m_bumpMap; TLockedToken m_envMap; TLockedToken m_envBumpMap; TLockedToken m_lightmap; hsh::texture2d m_rippleMap; hsh::dynamic_owner> m_vbo; hsh::dynamic_owner> m_pvbo; hsh::dynamic_owner> m_uniBuf; BindingPair m_dataBind; void PrepareBinding(u32 maxVertCount); public: CFluidPlaneShader(EFluidType type, const TLockedToken& patternTex1, const TLockedToken& patternTex2, const TLockedToken& colorTex, const TLockedToken& bumpMap, const TLockedToken& envMap, const TLockedToken& envBumpMap, const TLockedToken& lightmap, hsh::texture2d rippleMap, bool doubleLightmapBlend, bool additive, u32 maxVertCount); CFluidPlaneShader(const TLockedToken& patternTex1, const TLockedToken& patternTex2, const TLockedToken& 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 drawRegular(u32 start, u32 count) { m_dataBind.m_regular.draw(start, count); } void drawTessellation(u32 start, u32 count) { m_dataBind.m_tessellation.draw(start, count); } void loadVerts(const std::vector& verts, const std::vector& pVerts); }; } // namespace urde