2017-08-08 06:03:57 +00:00
|
|
|
#ifndef CFLUIDPLANESHADER_HPP
|
|
|
|
#define CFLUIDPLANESHADER_HPP
|
|
|
|
|
|
|
|
#include "RetroTypes.hpp"
|
|
|
|
#include "boo/graphicsdev/IGraphicsDataFactory.hpp"
|
|
|
|
#include "CModelShaders.hpp"
|
|
|
|
#include "boo/graphicsdev/GL.hpp"
|
|
|
|
#include "boo/graphicsdev/D3D.hpp"
|
|
|
|
#include "boo/graphicsdev/Metal.hpp"
|
|
|
|
#include "boo/graphicsdev/Vulkan.hpp"
|
2018-06-07 04:43:26 +00:00
|
|
|
#include "World/CFluidPlaneManager.hpp"
|
|
|
|
#include "Graphics/CTexture.hpp"
|
|
|
|
#include "CToken.hpp"
|
|
|
|
#include "zeus/CAABox.hpp"
|
2017-08-08 06:03:57 +00:00
|
|
|
|
|
|
|
namespace urde
|
|
|
|
{
|
|
|
|
|
|
|
|
struct SFluidPlaneShaderInfo
|
|
|
|
{
|
2018-06-07 04:43:26 +00:00
|
|
|
EFluidType m_type;
|
2017-08-08 06:03:57 +00:00
|
|
|
bool m_hasPatternTex1;
|
|
|
|
bool m_hasPatternTex2;
|
|
|
|
bool m_hasColorTex;
|
|
|
|
bool m_hasBumpMap;
|
|
|
|
bool m_hasEnvMap;
|
|
|
|
bool m_hasEnvBumpMap;
|
|
|
|
bool m_hasLightmap;
|
2018-06-07 04:43:26 +00:00
|
|
|
bool m_tessellation;
|
2017-08-08 06:03:57 +00:00
|
|
|
bool m_doubleLightmapBlend;
|
|
|
|
bool m_additive;
|
|
|
|
|
2018-06-07 04:43:26 +00:00
|
|
|
SFluidPlaneShaderInfo(EFluidType type, bool hasPatternTex1, bool hasPatternTex2, bool hasColorTex,
|
2017-08-08 06:03:57 +00:00
|
|
|
bool hasBumpMap, bool hasEnvMap, bool hasEnvBumpMap, bool hasLightmap,
|
2018-06-07 04:43:26 +00:00
|
|
|
bool tessellation, bool doubleLightmapBlend, bool additive)
|
2017-08-08 06:03:57 +00:00
|
|
|
: m_type(type), m_hasPatternTex1(hasPatternTex1), m_hasPatternTex2(hasPatternTex2), m_hasColorTex(hasColorTex),
|
|
|
|
m_hasBumpMap(hasBumpMap), m_hasEnvMap(hasEnvMap), m_hasEnvBumpMap(hasEnvBumpMap), m_hasLightmap(hasLightmap),
|
2018-06-07 04:43:26 +00:00
|
|
|
m_tessellation(tessellation), m_doubleLightmapBlend(doubleLightmapBlend), m_additive(additive)
|
2017-08-08 06:03:57 +00:00
|
|
|
{}
|
|
|
|
};
|
|
|
|
|
2017-08-14 03:55:06 +00:00
|
|
|
struct SFluidPlaneDoorShaderInfo
|
|
|
|
{
|
|
|
|
bool m_hasPatternTex1;
|
|
|
|
bool m_hasPatternTex2;
|
|
|
|
bool m_hasColorTex;
|
|
|
|
|
|
|
|
SFluidPlaneDoorShaderInfo(bool hasPatternTex1, bool hasPatternTex2, bool hasColorTex)
|
|
|
|
: m_hasPatternTex1(hasPatternTex1), m_hasPatternTex2(hasPatternTex2), m_hasColorTex(hasColorTex)
|
|
|
|
{}
|
|
|
|
};
|
|
|
|
|
2017-08-08 06:03:57 +00:00
|
|
|
class CFluidPlaneShader
|
|
|
|
{
|
2017-08-10 23:13:25 +00:00
|
|
|
public:
|
2017-08-08 06:03:57 +00:00
|
|
|
struct Vertex
|
|
|
|
{
|
|
|
|
zeus::CVector3f m_pos;
|
|
|
|
zeus::CVector3f m_norm;
|
|
|
|
zeus::CVector3f m_binorm;
|
|
|
|
zeus::CVector3f m_tangent;
|
|
|
|
zeus::CColor m_color;
|
2017-08-10 23:13:25 +00:00
|
|
|
|
|
|
|
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) {}
|
|
|
|
};
|
|
|
|
|
2018-06-07 04:43:26 +00:00
|
|
|
struct PatchVertex
|
|
|
|
{
|
|
|
|
zeus::CVector4f m_pos;
|
|
|
|
float m_outerLevels[4] = {};
|
|
|
|
float m_innerLevels[4] = {};
|
|
|
|
};
|
|
|
|
|
2017-08-14 03:55:06 +00:00
|
|
|
struct RenderSetupInfo
|
|
|
|
{
|
|
|
|
zeus::CMatrix4f texMtxs[6];
|
|
|
|
zeus::CMatrix4f normMtx;
|
|
|
|
float indScale = 1.f;
|
|
|
|
zeus::CColor kColors[4];
|
|
|
|
std::vector<CLight> lights;
|
|
|
|
};
|
|
|
|
|
2017-08-10 23:13:25 +00:00
|
|
|
private:
|
2018-06-07 04:43:26 +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;
|
|
|
|
};
|
|
|
|
|
2017-08-10 23:13:25 +00:00
|
|
|
class Cache
|
|
|
|
{
|
2018-06-07 04:43:26 +00:00
|
|
|
ShaderPair m_cache[1024] = {};
|
|
|
|
ShaderPair m_doorCache[8] = {};
|
|
|
|
ShaderPair&
|
2017-08-14 03:55:06 +00:00
|
|
|
CacheSlot(const SFluidPlaneShaderInfo& info, int i) { return m_cache[i]; }
|
2018-06-07 04:43:26 +00:00
|
|
|
ShaderPair&
|
2017-08-14 03:55:06 +00:00
|
|
|
CacheSlot(const SFluidPlaneDoorShaderInfo& info, int i) { return m_doorCache[i]; }
|
2017-08-10 23:13:25 +00:00
|
|
|
static u16 MakeCacheKey(const SFluidPlaneShaderInfo& info);
|
2017-08-14 03:55:06 +00:00
|
|
|
static u16 MakeCacheKey(const SFluidPlaneDoorShaderInfo& info);
|
2017-08-10 23:13:25 +00:00
|
|
|
public:
|
2017-08-14 03:55:06 +00:00
|
|
|
template<class T>
|
2018-06-07 04:43:26 +00:00
|
|
|
ShaderPair GetOrBuildShader(const T& info);
|
2017-08-14 03:55:06 +00:00
|
|
|
void Clear();
|
2017-08-08 06:03:57 +00:00
|
|
|
};
|
2017-08-10 23:13:25 +00:00
|
|
|
static Cache _cache;
|
2017-08-08 06:03:57 +00:00
|
|
|
|
2018-06-07 04:43:26 +00:00
|
|
|
struct Ripple
|
|
|
|
{
|
|
|
|
zeus::CVector4f center; // time, distFalloff
|
|
|
|
zeus::CVector4f params; // amplitude, lookupPhase, lookupTime
|
|
|
|
};
|
|
|
|
|
2017-08-08 06:03:57 +00:00
|
|
|
struct Uniform
|
|
|
|
{
|
|
|
|
zeus::CMatrix4f m_mv;
|
|
|
|
zeus::CMatrix4f m_mvNorm;
|
|
|
|
zeus::CMatrix4f m_proj;
|
2018-06-07 04:43:26 +00:00
|
|
|
zeus::CMatrix4f m_texMtxs[6];
|
|
|
|
Ripple m_ripple[20];
|
|
|
|
zeus::CVector4f m_colorMul;
|
|
|
|
zeus::CVector4f m_pad[3]; // rippleNormResolution, Pad out to 1280 bytes
|
2017-08-08 06:03:57 +00:00
|
|
|
CModelShaders::LightingUniform m_lighting;
|
2018-06-07 04:43:26 +00:00
|
|
|
zeus::CVector3f m_pad2; // Pad out to 768 bytes
|
2017-08-08 06:03:57 +00:00
|
|
|
};
|
|
|
|
|
2018-06-07 04:43:26 +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;
|
|
|
|
boo::ObjToken<boo::ITextureS> m_rippleMap;
|
2017-11-05 06:17:12 +00:00
|
|
|
boo::ObjToken<boo::IGraphicsBufferD> m_vbo;
|
2018-06-07 04:43:26 +00:00
|
|
|
boo::ObjToken<boo::IGraphicsBufferD> m_pvbo;
|
2017-11-05 06:17:12 +00:00
|
|
|
boo::ObjToken<boo::IGraphicsBufferD> m_uniBuf;
|
2018-06-07 04:43:26 +00:00
|
|
|
BindingPair m_dataBind;
|
|
|
|
int m_lastBind = -1;
|
2017-08-08 06:03:57 +00:00
|
|
|
|
2017-12-06 03:26:15 +00:00
|
|
|
#if BOO_HAS_GL
|
2018-06-07 04:43:26 +00:00
|
|
|
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);
|
2017-12-06 03:26:15 +00:00
|
|
|
#endif
|
2017-08-08 06:03:57 +00:00
|
|
|
#if _WIN32
|
2018-06-07 04:43:26 +00:00
|
|
|
static ShaderPair BuildShader(boo::D3DDataFactory::Context& ctx,
|
|
|
|
const SFluidPlaneShaderInfo& info);
|
|
|
|
static ShaderPair BuildShader(boo::D3DDataFactory::Context& ctx,
|
|
|
|
const SFluidPlaneDoorShaderInfo& info);
|
|
|
|
BindingPair BuildBinding(boo::D3DDataFactory::Context& ctx, const ShaderPair& pipeline);
|
2017-08-08 06:03:57 +00:00
|
|
|
#endif
|
|
|
|
#if BOO_HAS_METAL
|
2018-06-07 04:43:26 +00:00
|
|
|
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);
|
2017-08-08 06:03:57 +00:00
|
|
|
#endif
|
|
|
|
#if BOO_HAS_VULKAN
|
2018-06-07 04:43:26 +00:00
|
|
|
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);
|
2017-08-08 06:03:57 +00:00
|
|
|
#endif
|
|
|
|
|
2018-05-20 22:38:56 +00:00
|
|
|
template <class F> static void _Shutdown();
|
|
|
|
|
2018-06-07 04:43:26 +00:00
|
|
|
void PrepareBinding(const ShaderPair& pipeline, u32 maxVertCount);
|
2017-08-08 06:03:57 +00:00
|
|
|
public:
|
2018-06-07 04:43:26 +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,
|
|
|
|
const boo::ObjToken<boo::ITextureS>& rippleMap,
|
2017-08-13 07:56:35 +00:00
|
|
|
bool doubleLightmapBlend, bool additive, u32 maxVertCount);
|
2018-06-07 04:43:26 +00:00
|
|
|
CFluidPlaneShader(const TLockedToken<CTexture>& patternTex1,
|
|
|
|
const TLockedToken<CTexture>& patternTex2,
|
|
|
|
const TLockedToken<CTexture>& colorTex,
|
2017-08-14 03:55:06 +00:00
|
|
|
u32 maxVertCount);
|
|
|
|
void prepareDraw(const RenderSetupInfo& info);
|
2018-06-07 04:43:26 +00:00
|
|
|
void prepareDraw(const RenderSetupInfo& info,
|
|
|
|
const zeus::CVector3f& waterCenter,
|
|
|
|
const CRippleManager& rippleManager,
|
|
|
|
const zeus::CColor& colorMul,
|
|
|
|
float rippleNormResolution);
|
|
|
|
void bindRegular()
|
|
|
|
{
|
|
|
|
if (m_lastBind != 0)
|
|
|
|
{
|
|
|
|
CGraphics::SetShaderDataBinding(m_dataBind.m_regular);
|
|
|
|
m_lastBind = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
bool bindTessellation()
|
|
|
|
{
|
|
|
|
if (m_lastBind != 1)
|
|
|
|
{
|
|
|
|
CGraphics::SetShaderDataBinding(m_dataBind.m_tessellation);
|
|
|
|
m_lastBind = 1;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
void doneDrawing() { m_lastBind = -1; }
|
|
|
|
void loadVerts(const std::vector<Vertex>& verts, const std::vector<PatchVertex>& pVerts);
|
2017-08-14 03:55:06 +00:00
|
|
|
|
2018-05-20 22:38:56 +00:00
|
|
|
static void Shutdown();
|
2017-08-08 06:03:57 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // CFLUIDPLANESHADER_HPP
|