Initial extended shader refactor

This commit is contained in:
Jack Andersen 2016-07-30 16:06:47 -10:00
parent df4ce27240
commit 95033d3988
13 changed files with 168 additions and 164 deletions

View File

@ -334,7 +334,7 @@ void CBooRenderer::AddStaticGeometry(const std::vector<CMetroidModelInstance>* g
{ {
models.reserve(geometry->size()); models.reserve(geometry->size());
for (const CMetroidModelInstance& inst : *geometry) for (const CMetroidModelInstance& inst : *geometry)
models.push_back(inst.m_instance.get()); models.push_back(inst.m_instance);
} }
x1c_areaListItems.emplace_back(geometry, octTree, std::move(models), areaIdx); x1c_areaListItems.emplace_back(geometry, octTree, std::move(models), areaIdx);
} }
@ -545,42 +545,6 @@ void CBooRenderer::SetViewport(int l, int b, int w, int h)
CGraphics::SetScissor(l, b, w, h); CGraphics::SetScissor(l, b, w, h);
} }
void CBooRenderer::SetDepthReadWrite(bool, bool)
{
}
void CBooRenderer::SetBlendMode_AdditiveAlpha()
{
}
void CBooRenderer::SetBlendMode_AlphaBlended()
{
}
void CBooRenderer::SetBlendMode_NoColorWrite()
{
}
void CBooRenderer::SetBlendMode_ColorMultiply()
{
}
void CBooRenderer::SetBlendMode_InvertDst()
{
}
void CBooRenderer::SetBlendMode_InvertSrc()
{
}
void CBooRenderer::SetBlendMode_Replace()
{
}
void CBooRenderer::SetBlendMode_AdditiveDestColor()
{
}
void CBooRenderer::SetDebugOption(EDebugOption, int) void CBooRenderer::SetDebugOption(EDebugOption, int)
{ {
} }
@ -598,50 +562,6 @@ void CBooRenderer::EndScene()
CGraphics::EndScene(); CGraphics::EndScene();
} }
void CBooRenderer::BeginPrimitive(EPrimitiveType, int)
{
}
void CBooRenderer::BeginLines(int)
{
}
void CBooRenderer::BeginLineStrip(int)
{
}
void CBooRenderer::BeginTriangles(int)
{
}
void CBooRenderer::BeginTriangleStrip(int)
{
}
void CBooRenderer::BeginTriangleFan(int)
{
}
void CBooRenderer::PrimVertex(const zeus::CVector3f&)
{
}
void CBooRenderer::PrimNormal(const zeus::CVector3f&)
{
}
void CBooRenderer::PrimColor(float, float, float, float)
{
}
void CBooRenderer::PrimColor(const zeus::CColor&)
{
}
void CBooRenderer::EndPrimitive()
{
}
void CBooRenderer::SetAmbientColor(const zeus::CColor& color) void CBooRenderer::SetAmbientColor(const zeus::CColor& color)
{ {
CGraphics::SetAmbientColor(color); CGraphics::SetAmbientColor(color);
@ -656,12 +576,13 @@ u32 CBooRenderer::GetFPS()
return 0; return 0;
} }
void CBooRenderer::DrawSpaceWarp(const zeus::CVector3f& pt, float) void CBooRenderer::DrawSpaceWarp(const zeus::CVector3f& pt, float strength)
{ {
m_spaceWarpFilter.setStrength(strength);
m_spaceWarpFilter.draw(pt);
} }
void CBooRenderer::DrawThermalModel(const CModel&, const zeus::CColor&, const zeus::CColor&, const float*, const float*) void CBooRenderer::DrawThermalModel(const CModel& model, const zeus::CColor& mulCol, const zeus::CColor& addCol)
{ {
} }
@ -681,8 +602,11 @@ void CBooRenderer::RenderFogVolume(const zeus::CColor&, const zeus::CAABox&, con
{ {
} }
void CBooRenderer::SetThermal(bool, float, const zeus::CColor&) void CBooRenderer::SetThermal(bool thermal, float level, const zeus::CColor& color)
{ {
x318_29_thermalVisor = thermal;
x2f0_thermalVisorLevel = level;
x2f4_thermColor = color;
} }
void CBooRenderer::SetThermalColdScale(float scale) void CBooRenderer::SetThermalColdScale(float scale)

View File

@ -45,6 +45,8 @@ public:
class CBooRenderer : public IRenderer class CBooRenderer : public IRenderer
{ {
friend class CBooModel;
struct CAreaListItem struct CAreaListItem
{ {
const std::vector<CMetroidModelInstance>* x0_geometry; const std::vector<CMetroidModelInstance>* x0_geometry;
@ -99,6 +101,9 @@ class CBooRenderer : public IRenderer
zeus::CColor x2e0_ = zeus::CColor::skWhite; zeus::CColor x2e0_ = zeus::CColor::skWhite;
zeus::CVector3f x2e4_ = {0.f, 1.f, 0.f}; zeus::CVector3f x2e4_ = {0.f, 1.f, 0.f};
CSpaceWarpFilter m_spaceWarpFilter;
float x2f0_thermalVisorLevel;
zeus::CColor x2f4_thermColor; zeus::CColor x2f4_thermColor;
float x2f8_thermColdScale = 0.f; float x2f8_thermColdScale = 0.f;
CThermalColdFilter m_thermColdFilter; CThermalColdFilter m_thermColdFilter;
@ -114,7 +119,7 @@ class CBooRenderer : public IRenderer
bool x318_26_ : 1; bool x318_26_ : 1;
bool x318_27_ : 1; bool x318_27_ : 1;
bool x318_28_ : 1; bool x318_28_ : 1;
bool x318_29_ : 1; bool x318_29_thermalVisor : 1;
bool x318_30_ : 1; bool x318_30_ : 1;
bool x318_31_ : 1; bool x318_31_ : 1;
}; };
@ -153,35 +158,35 @@ public:
void SetViewportOrtho(bool, float, float); void SetViewportOrtho(bool, float, float);
void SetClippingPlanes(const zeus::CFrustum& frustum); void SetClippingPlanes(const zeus::CFrustum& frustum);
void SetViewport(int, int, int, int); void SetViewport(int, int, int, int);
void SetDepthReadWrite(bool, bool); //void SetDepthReadWrite(bool, bool);
void SetBlendMode_AdditiveAlpha(); //void SetBlendMode_AdditiveAlpha();
void SetBlendMode_AlphaBlended(); //void SetBlendMode_AlphaBlended();
void SetBlendMode_NoColorWrite(); //void SetBlendMode_NoColorWrite();
void SetBlendMode_ColorMultiply(); //void SetBlendMode_ColorMultiply();
void SetBlendMode_InvertDst(); //void SetBlendMode_InvertDst();
void SetBlendMode_InvertSrc(); //void SetBlendMode_InvertSrc();
void SetBlendMode_Replace(); //void SetBlendMode_Replace();
void SetBlendMode_AdditiveDestColor(); //void SetBlendMode_AdditiveDestColor();
void SetDebugOption(EDebugOption, int); void SetDebugOption(EDebugOption, int);
void BeginScene(); void BeginScene();
void EndScene(); void EndScene();
void BeginPrimitive(EPrimitiveType, int); //void BeginPrimitive(EPrimitiveType, int);
void BeginLines(int); //void BeginLines(int);
void BeginLineStrip(int); //void BeginLineStrip(int);
void BeginTriangles(int); //void BeginTriangles(int);
void BeginTriangleStrip(int); //void BeginTriangleStrip(int);
void BeginTriangleFan(int); //void BeginTriangleFan(int);
void PrimVertex(const zeus::CVector3f&); //void PrimVertex(const zeus::CVector3f&);
void PrimNormal(const zeus::CVector3f&); //void PrimNormal(const zeus::CVector3f&);
void PrimColor(float, float, float, float); //void PrimColor(float, float, float, float);
void PrimColor(const zeus::CColor&); //void PrimColor(const zeus::CColor&);
void EndPrimitive(); //void EndPrimitive();
void SetAmbientColor(const zeus::CColor&); void SetAmbientColor(const zeus::CColor&);
void DrawString(const char*, int, int); void DrawString(const char*, int, int);
u32 GetFPS(); u32 GetFPS();
//void CacheReflection(TReflectionCallback, void*, bool); //void CacheReflection(TReflectionCallback, void*, bool);
void DrawSpaceWarp(const zeus::CVector3f&, float); void DrawSpaceWarp(const zeus::CVector3f&, float);
void DrawThermalModel(const CModel&, const zeus::CColor&, const zeus::CColor&, const float*, const float*); void DrawThermalModel(const CModel& model, const zeus::CColor& multCol, const zeus::CColor& addCol);
void DrawXRayOutline(const CModel&, const float*, const float*); void DrawXRayOutline(const CModel&, const float*, const float*);
void SetWireframeFlags(int); void SetWireframeFlags(int);
void SetWorldFog(ERglFogMode, float, float, const zeus::CColor&); void SetWorldFog(ERglFogMode, float, float, const zeus::CColor&);

View File

@ -5,8 +5,8 @@ namespace urde
{ {
CMetroidModelInstance::CMetroidModelInstance CMetroidModelInstance::CMetroidModelInstance
(const void* modelHeader, std::unique_ptr<CBooModel>&& inst) (const void* modelHeader, CBooModel* inst)
: x0_visorFlags(hecl::SBig(*static_cast<const u32*>(modelHeader))), m_instance(std::move(inst)) : x0_visorFlags(hecl::SBig(*static_cast<const u32*>(modelHeader))), m_instance(inst)
{ {
athena::io::MemoryReader r(static_cast<const u8*>(modelHeader) + 4, INT32_MAX); athena::io::MemoryReader r(static_cast<const u8*>(modelHeader) + 4, INT32_MAX);
x4_xf.read34RowMajor(r); x4_xf.read34RowMajor(r);

View File

@ -17,9 +17,9 @@ class CMetroidModelInstance
int x0_visorFlags; int x0_visorFlags;
zeus::CTransform x4_xf; zeus::CTransform x4_xf;
zeus::CAABox x34_aabb; zeus::CAABox x34_aabb;
std::unique_ptr<CBooModel> m_instance; CBooModel* m_instance;
public: public:
CMetroidModelInstance(const void* modelHeader, std::unique_ptr<CBooModel>&& inst); CMetroidModelInstance(const void* modelHeader, CBooModel* inst);
~CMetroidModelInstance(); ~CMetroidModelInstance();
}; };

View File

@ -25,6 +25,7 @@ struct CModelFlags
u8 m_extendedShaderIdx = 0; /* 0 for shadeless, 1 for lighting, others defined in CModelShaders */ u8 m_extendedShaderIdx = 0; /* 0 for shadeless, 1 for lighting, others defined in CModelShaders */
u16 m_flags = 0; /* Flags */ u16 m_flags = 0; /* Flags */
zeus::CColor color; /* Set into kcolor slot specified by material */ zeus::CColor color; /* Set into kcolor slot specified by material */
zeus::CColor addColor;
CModelFlags() = default; CModelFlags() = default;
CModelFlags(u8 blendMode, u8 shadIdx, u16 flags, const zeus::CColor& col) CModelFlags(u8 blendMode, u8 shadIdx, u16 flags, const zeus::CColor& col)
@ -91,7 +92,7 @@ private:
{ {
static void ProcessAnimation(u8*& bufOut, const UVAnimation& anim); static void ProcessAnimation(u8*& bufOut, const UVAnimation& anim);
static void PadOutBuffer(u8*& bufStart, u8*& bufOut); static void PadOutBuffer(u8*& bufStart, u8*& bufOut);
static void Update(u8*& bufOut, const MaterialSet* matSet); static void Update(u8*& bufOut, const MaterialSet* matSet, const CModelFlags& flags);
}; };
CModelShaders::LightingUniform m_lightingData; CModelShaders::LightingUniform m_lightingData;
@ -103,7 +104,7 @@ private:
std::vector<std::vector<boo::IShaderDataBinding*>> m_shaderDataBindings; std::vector<std::vector<boo::IShaderDataBinding*>> m_shaderDataBindings;
void BuildGfxToken(); void BuildGfxToken();
void UpdateUniformData() const; void UpdateUniformData(const CModelFlags& flags) const;
void DrawAlphaSurfaces(const CModelFlags& flags) const; void DrawAlphaSurfaces(const CModelFlags& flags) const;
void DrawNormalSurfaces(const CModelFlags& flags) const; void DrawNormalSurfaces(const CModelFlags& flags) const;
void DrawSurfaces(const CModelFlags& flags) const; void DrawSurfaces(const CModelFlags& flags) const;

View File

@ -6,6 +6,8 @@
#include "hecl/Runtime.hpp" #include "hecl/Runtime.hpp"
#include "boo/graphicsdev/Metal.hpp" #include "boo/graphicsdev/Metal.hpp"
#include "Shaders/CModelShaders.hpp" #include "Shaders/CModelShaders.hpp"
#include "Graphics/CBooRenderer.hpp"
#include "GameGlobalObjects.hpp"
namespace urde namespace urde
{ {
@ -84,7 +86,7 @@ void CBooModel::BuildGfxToken()
/* Animated UV transform matrices */ /* Animated UV transform matrices */
for (const MaterialSet::Material& mat : x4_matSet->materials) for (const MaterialSet::Material& mat : x4_matSet->materials)
{ {
size_t thisSz = ROUND_UP_256(mat.uvAnims.size() * (sizeof(zeus::CMatrix4f) * 2)); size_t thisSz = ROUND_UP_256(/*mat.uvAnims.size()*/ 8 * (sizeof(zeus::CMatrix4f) * 2));
uvOffs.push_back(uniBufSize); uvOffs.push_back(uniBufSize);
uvSizes.push_back(thisSz); uvSizes.push_back(thisSz);
uniBufSize += thisSz; uniBufSize += thisSz;
@ -124,12 +126,14 @@ void CBooModel::BuildGfxToken()
const MaterialSet::Material& mat = x4_matSet->materials.at(surf.m_data.matIdx); const MaterialSet::Material& mat = x4_matSet->materials.at(surf.m_data.matIdx);
texs.clear(); texs.clear();
texs.reserve(mat.textureIdxs.size()); texs.reserve(8);
for (atUint32 idx : mat.textureIdxs) for (atUint32 idx : mat.textureIdxs)
{ {
TCachedToken<CTexture>& tex = (*x1c_textures)[idx]; TCachedToken<CTexture>& tex = (*x1c_textures)[idx];
texs.push_back(tex.GetObj()->GetBooTexture()); texs.push_back(tex.GetObj()->GetBooTexture());
} }
texs.resize(8);
texs[7] = g_Renderer->x220_sphereRamp;
if (m_skinBankCount) if (m_skinBankCount)
{ {
@ -142,16 +146,8 @@ void CBooModel::BuildGfxToken()
thisSizes[0] = 256; thisSizes[0] = 256;
} }
if (mat.uvAnims.size())
{
thisOffs[1] = uvOffs[surf.m_data.matIdx]; thisOffs[1] = uvOffs[surf.m_data.matIdx];
thisSizes[1] = uvSizes[surf.m_data.matIdx]; thisSizes[1] = uvSizes[surf.m_data.matIdx];
}
else
{
thisOffs[1] = 0;
thisSizes[1] = 0;
}
thisOffs[2] = lightOff; thisOffs[2] = lightOff;
thisSizes[2] = lightSz; thisSizes[2] = lightSz;
@ -162,11 +158,16 @@ void CBooModel::BuildGfxToken()
std::vector<boo::IShaderDataBinding*>& extendeds = m_shaderDataBindings.back(); std::vector<boo::IShaderDataBinding*>& extendeds = m_shaderDataBindings.back();
extendeds.reserve(pipelines.size()); extendeds.reserve(pipelines.size());
int idx = 0;
for (boo::IShaderPipeline* pipeline : pipelines) for (boo::IShaderPipeline* pipeline : pipelines)
{
extendeds.push_back( extendeds.push_back(
ctx.newShaderDataBinding(pipeline, m_vtxFmt, ctx.newShaderDataBinding(pipeline, m_vtxFmt,
x8_vbo, nullptr, xc_ibo, 3, bufs, stages, x8_vbo, nullptr, xc_ibo, 3, bufs, stages,
thisOffs, thisSizes, mat.textureIdxs.size(), texs.data())); thisOffs, thisSizes, (idx == 2) ? 8 : mat.textureIdxs.size(),
texs.data()));
++idx;
}
} }
return true; return true;
}); });
@ -416,19 +417,45 @@ void CBooModel::UVAnimationBuffer::PadOutBuffer(u8*& bufStart, u8*& bufOut)
bufOut = bufStart + ROUND_UP_256(bufOut - bufStart); bufOut = bufStart + ROUND_UP_256(bufOut - bufStart);
} }
void CBooModel::UVAnimationBuffer::Update(u8*& bufOut, const MaterialSet* matSet) void CBooModel::UVAnimationBuffer::Update(u8*& bufOut, const MaterialSet* matSet, const CModelFlags& flags)
{ {
u8* start = bufOut; u8* start = bufOut;
/* Special Mode0 matrix for exclusive Thermal Visor use */
std::experimental::optional<std::array<zeus::CMatrix4f, 2>> thermalMtxOut;
if (flags.m_extendedShaderIdx == 2)
{
thermalMtxOut.emplace();
zeus::CMatrix4f& texMtxOut = (*thermalMtxOut)[0];
texMtxOut = CGraphics::g_GXModelViewInvXpose.toMatrix4f();
texMtxOut.vec[3].zeroOut();
texMtxOut.vec[3].w = 1.f;
zeus::CMatrix4f& postMtxOut = (*thermalMtxOut)[1];
postMtxOut.vec[0].x = 0.5f;
postMtxOut.vec[1].y = 0.5f;
postMtxOut.vec[3].x = 0.5f;
postMtxOut.vec[3].y = 0.5f;
}
for (const MaterialSet::Material& mat : matSet->materials) for (const MaterialSet::Material& mat : matSet->materials)
{ {
if (thermalMtxOut)
{
std::array<zeus::CMatrix4f, 2>* mtxs = reinterpret_cast<std::array<zeus::CMatrix4f, 2>*>(bufOut);
mtxs[7][0] = (*thermalMtxOut)[0];
mtxs[7][1] = (*thermalMtxOut)[1];
}
u8* bufOrig = bufOut;
for (const UVAnimation& anim : mat.uvAnims) for (const UVAnimation& anim : mat.uvAnims)
ProcessAnimation(bufOut, anim); ProcessAnimation(bufOut, anim);
bufOut = bufOrig + sizeof(zeus::CMatrix4f) * 2;
PadOutBuffer(start, bufOut); PadOutBuffer(start, bufOut);
} }
} }
void CBooModel::UpdateUniformData() const void CBooModel::UpdateUniformData(const CModelFlags& flags) const
{ {
u8* dataOut = reinterpret_cast<u8*>(m_uniformBuffer->map(m_uniformDataSize)); u8* dataOut = reinterpret_cast<u8*>(m_uniformBuffer->map(m_uniformDataSize));
u8* dataCur = dataOut; u8* dataCur = dataOut;
@ -475,19 +502,28 @@ void CBooModel::UpdateUniformData() const
dataCur = dataOut + ROUND_UP_256(dataCur - dataOut); dataCur = dataOut + ROUND_UP_256(dataCur - dataOut);
} }
UVAnimationBuffer::Update(dataCur, x4_matSet); UVAnimationBuffer::Update(dataCur, x4_matSet, flags);
CModelShaders::LightingUniform& lightingOut = reinterpret_cast<CModelShaders::LightingUniform&>(*dataCur); if (flags.m_extendedShaderIdx == 2) /* Thermal Model (same as UV Mode 0) */
{
CModelShaders::ThermalUniform& thermalOut = *reinterpret_cast<CModelShaders::ThermalUniform*>(dataCur);
thermalOut.mulColor = flags.color;
thermalOut.addColor = flags.addColor;
}
else
{
CModelShaders::LightingUniform& lightingOut = *reinterpret_cast<CModelShaders::LightingUniform*>(dataCur);
lightingOut = m_lightingData; lightingOut = m_lightingData;
}
m_uniformBuffer->unmap(); m_uniformBuffer->unmap();
} }
void CBooModel::DrawAlpha(const CModelFlags& flags) const void CBooModel::DrawAlpha(const CModelFlags& flags) const
{ {
if (TryLockTextures()) if (TryLockTextures())
{ {
UpdateUniformData(); UpdateUniformData(flags);
DrawAlphaSurfaces(flags); DrawAlphaSurfaces(flags);
} }
} }
@ -496,7 +532,7 @@ void CBooModel::DrawNormal(const CModelFlags& flags) const
{ {
if (TryLockTextures()) if (TryLockTextures())
{ {
UpdateUniformData(); UpdateUniformData(flags);
DrawNormalSurfaces(flags); DrawNormalSurfaces(flags);
} }
} }
@ -505,7 +541,7 @@ void CBooModel::Draw(const CModelFlags& flags) const
{ {
if (TryLockTextures()) if (TryLockTextures())
{ {
UpdateUniformData(); UpdateUniformData(flags);
DrawSurfaces(flags); DrawSurfaces(flags);
} }
} }
@ -581,7 +617,7 @@ CModel::CModel(std::unique_ptr<u8[]>&& in, u32 /* dataLen */, IObjectStore* stor
{ {
hecl::Runtime::ShaderTag tag(mat.heclIr, hecl::Runtime::ShaderTag tag(mat.heclIr,
hmdlMeta.colorCount, hmdlMeta.uvCount, hmdlMeta.weightCount, hmdlMeta.colorCount, hmdlMeta.uvCount, hmdlMeta.weightCount,
0, mat.uvAnims.size(), boo::Primitive(hmdlMeta.topology), 0, 8, boo::Primitive(hmdlMeta.topology),
true, true, true); true, true, true);
matSet.m_shaders.push_back(CModelShaders::g_ModelShaders->buildExtendedShader(tag, mat.heclIr, "CMDL", ctx)); matSet.m_shaders.push_back(CModelShaders::g_ModelShaders->buildExtendedShader(tag, mat.heclIr, "CMDL", ctx));
} }

View File

@ -59,35 +59,35 @@ public:
virtual void SetViewportOrtho(bool, float, float)=0; virtual void SetViewportOrtho(bool, float, float)=0;
virtual void SetClippingPlanes(const zeus::CFrustum&)=0; virtual void SetClippingPlanes(const zeus::CFrustum&)=0;
virtual void SetViewport(int, int, int, int)=0; virtual void SetViewport(int, int, int, int)=0;
virtual void SetDepthReadWrite(bool, bool)=0; //virtual void SetDepthReadWrite(bool, bool)=0;
virtual void SetBlendMode_AdditiveAlpha()=0; //virtual void SetBlendMode_AdditiveAlpha()=0;
virtual void SetBlendMode_AlphaBlended()=0; //virtual void SetBlendMode_AlphaBlended()=0;
virtual void SetBlendMode_NoColorWrite()=0; //virtual void SetBlendMode_NoColorWrite()=0;
virtual void SetBlendMode_ColorMultiply()=0; //virtual void SetBlendMode_ColorMultiply()=0;
virtual void SetBlendMode_InvertDst()=0; //virtual void SetBlendMode_InvertDst()=0;
virtual void SetBlendMode_InvertSrc()=0; //virtual void SetBlendMode_InvertSrc()=0;
virtual void SetBlendMode_Replace()=0; //virtual void SetBlendMode_Replace()=0;
virtual void SetBlendMode_AdditiveDestColor()=0; //virtual void SetBlendMode_AdditiveDestColor()=0;
virtual void SetDebugOption(EDebugOption, int)=0; virtual void SetDebugOption(EDebugOption, int)=0;
virtual void BeginScene()=0; virtual void BeginScene()=0;
virtual void EndScene()=0; virtual void EndScene()=0;
virtual void BeginPrimitive(EPrimitiveType, int)=0; //virtual void BeginPrimitive(EPrimitiveType, int)=0;
virtual void BeginLines(int)=0; //virtual void BeginLines(int)=0;
virtual void BeginLineStrip(int)=0; //virtual void BeginLineStrip(int)=0;
virtual void BeginTriangles(int)=0; //virtual void BeginTriangles(int)=0;
virtual void BeginTriangleStrip(int)=0; //virtual void BeginTriangleStrip(int)=0;
virtual void BeginTriangleFan(int)=0; //virtual void BeginTriangleFan(int)=0;
virtual void PrimVertex(const zeus::CVector3f&)=0; //virtual void PrimVertex(const zeus::CVector3f&)=0;
virtual void PrimNormal(const zeus::CVector3f&)=0; //virtual void PrimNormal(const zeus::CVector3f&)=0;
virtual void PrimColor(float, float, float, float)=0; //virtual void PrimColor(float, float, float, float)=0;
virtual void PrimColor(const zeus::CColor&)=0; //virtual void PrimColor(const zeus::CColor&)=0;
virtual void EndPrimitive()=0; //virtual void EndPrimitive()=0;
virtual void SetAmbientColor(const zeus::CColor&)=0; virtual void SetAmbientColor(const zeus::CColor&)=0;
virtual void DrawString(const char*, int, int)=0; virtual void DrawString(const char*, int, int)=0;
virtual u32 GetFPS()=0; virtual u32 GetFPS()=0;
//virtual void CacheReflection(TReflectionCallback, void*, bool)=0; //virtual void CacheReflection(TReflectionCallback, void*, bool)=0;
virtual void DrawSpaceWarp(const zeus::CVector3f&, float)=0; virtual void DrawSpaceWarp(const zeus::CVector3f&, float)=0;
virtual void DrawThermalModel(const CModel&, const zeus::CColor&, const zeus::CColor&, const float*, const float*)=0; virtual void DrawThermalModel(const CModel&, const zeus::CColor&, const zeus::CColor&)=0;
virtual void DrawXRayOutline(const CModel&, const float*, const float*)=0; virtual void DrawXRayOutline(const CModel&, const float*, const float*)=0;
virtual void SetWireframeFlags(int)=0; virtual void SetWireframeFlags(int)=0;
virtual void SetWorldFog(ERglFogMode, float, float, const zeus::CColor&)=0; virtual void SetWorldFog(ERglFogMode, float, float, const zeus::CColor&)=0;

View File

@ -37,6 +37,12 @@ public:
zeus::CColor colorRegs[3]; zeus::CColor colorRegs[3];
}; };
struct ThermalUniform
{
zeus::CColor mulColor;
zeus::CColor addColor;
};
static void Initialize(const hecl::Runtime::FileStoreManager& storeMgr, static void Initialize(const hecl::Runtime::FileStoreManager& storeMgr,
boo::IGraphicsDataFactory* gfxFactory); boo::IGraphicsDataFactory* gfxFactory);

View File

@ -44,15 +44,43 @@ static const char* LightingGLSL =
" return clamp(ret, vec4(0.0,0.0,0.0,0.0), vec4(1.0,1.0,1.0,1.0));\n" " return clamp(ret, vec4(0.0,0.0,0.0,0.0), vec4(1.0,1.0,1.0,1.0));\n"
"}\n"; "}\n";
static const char* ThermalPostGLSL =
"UBINDING2 uniform ThermalUniform\n"
"{\n"
" vec4 mulColor;\n"
" vec4 addColor;\n"
"};\n"
"TBINDING7 uniform sampler2D thermalLookup;\n"
"vec4 ThermalPostFunc(vec4 colorIn)\n"
"{\n"
" return texture(thermalLookup, vtf.extTcgs[0]).rrrr * mulColor + addColor;\n"
"}\n"
"\n";
static const char* BlockNames[] = {HECL_GLSL_VERT_UNIFORM_BLOCK_NAME, static const char* BlockNames[] = {HECL_GLSL_VERT_UNIFORM_BLOCK_NAME,
HECL_GLSL_TEXMTX_UNIFORM_BLOCK_NAME, HECL_GLSL_TEXMTX_UNIFORM_BLOCK_NAME,
"LightingUniform"}; "LightingUniform"};
static const char* ThermalBlockNames[] = {HECL_GLSL_VERT_UNIFORM_BLOCK_NAME,
HECL_GLSL_TEXMTX_UNIFORM_BLOCK_NAME,
"ThermalUniform"};
static const hecl::Backend::TextureInfo ThermalTextures[] =
{
{hecl::Backend::TexGenSrc::Normal, 0, 7, true}
};
hecl::Runtime::ShaderCacheExtensions hecl::Runtime::ShaderCacheExtensions
CModelShaders::GetShaderExtensionsGLSL(boo::IGraphicsDataFactory::Platform plat) CModelShaders::GetShaderExtensionsGLSL(boo::IGraphicsDataFactory::Platform plat)
{ {
hecl::Runtime::ShaderCacheExtensions ext(plat); hecl::Runtime::ShaderCacheExtensions ext(plat);
ext.registerExtensionSlot({LightingGLSL, "LightingFunc"}, {}, 3, BlockNames);
/* Normal lit shading */
ext.registerExtensionSlot({LightingGLSL, "LightingFunc"}, {}, 3, BlockNames, 0, nullptr);
/* Thermal Visor shading */
ext.registerExtensionSlot({}, {ThermalPostGLSL, "ThermalPostFunc"}, 3, ThermalBlockNames, 1, ThermalTextures);
return ext; return ext;
} }

View File

@ -54,7 +54,7 @@ CSpaceWarpFilter::CSpaceWarpFilter()
}); });
} }
void CSpaceWarpFilter::draw(const zeus::CVector2f& pt) void CSpaceWarpFilter::draw(const zeus::CVector3f& pt)
{ {
/* Indirect coords are full-texture sampling when warp is completely in viewport */ /* Indirect coords are full-texture sampling when warp is completely in viewport */
m_uniform.m_indXf[1][1] = 1.f; m_uniform.m_indXf[1][1] = 1.f;
@ -116,8 +116,12 @@ void CSpaceWarpFilter::draw(const zeus::CVector2f& pt)
zeus::CVector2f vp{CGraphics::g_ViewportResolution.x, CGraphics::g_ViewportResolution.y}; zeus::CVector2f vp{CGraphics::g_ViewportResolution.x, CGraphics::g_ViewportResolution.y};
m_uniform.m_matrix[0][0] = clipRect.xc_width / vp.x; m_uniform.m_matrix[0][0] = clipRect.xc_width / vp.x;
m_uniform.m_matrix[1][1] = clipRect.x10_height / vp.y; m_uniform.m_matrix[1][1] = clipRect.x10_height / vp.y;
m_uniform.m_matrix[2][0] = pt.x + (1.f / vp.x); m_uniform.m_matrix[3][0] = pt.x + (1.f / vp.x);
m_uniform.m_matrix[2][1] = pt.y + (1.f / vp.y); m_uniform.m_matrix[3][1] = pt.y + (1.f / vp.y);
if (CGraphics::g_BooPlatform == boo::IGraphicsDataFactory::Platform::OGL)
m_uniform.m_matrix[3][2] = pt.z * 2.f - 1.f;
else
m_uniform.m_matrix[3][2] = pt.z;
if (clipRect.x4_left + clipRect.xc_width < CGraphics::g_ViewportResolution.x) if (clipRect.x4_left + clipRect.xc_width < CGraphics::g_ViewportResolution.x)
clipRect.xc_width += 1; clipRect.xc_width += 1;

View File

@ -33,7 +33,7 @@ class CSpaceWarpFilter
public: public:
CSpaceWarpFilter(); CSpaceWarpFilter();
void setStrength(float strength) { m_strength = strength; } void setStrength(float strength) { m_strength = strength; }
void draw(const zeus::CVector2f& pt); void draw(const zeus::CVector3f& pt);
using _CLS = CSpaceWarpFilter; using _CLS = CSpaceWarpFilter;
#include "TShaderDecl.hpp" #include "TShaderDecl.hpp"

View File

@ -26,7 +26,7 @@ BOO_GLSL_BINDING_HEAD
"SBINDING(0) out VertToFrag vtf;\n" "SBINDING(0) out VertToFrag vtf;\n"
"void main()\n" "void main()\n"
"{\n" "{\n"
" gl_Position = vec4(mat3(mainMtx) * vec3(posIn.xy, 1.0), 1.0);\n" " gl_Position = mainMtx * vec4(posIn.xy, 0.0, 1.0);\n"
" vtf.sceneUv = gl_Position.xy * vec2(0.5) + vec2(0.5);\n" " vtf.sceneUv = gl_Position.xy * vec2(0.5) + vec2(0.5);\n"
" vtf.indUv = (mat3(indMtx) * vec3(uvIn.xy, 1.0)).xy;\n" " vtf.indUv = (mat3(indMtx) * vec3(uvIn.xy, 1.0)).xy;\n"
" vtf.strength = strength.xy;\n" " vtf.strength = strength.xy;\n"

2
hecl

@ -1 +1 @@
Subproject commit a095b87ca1b3dc4f6291b6f248fcb9260e26eb92 Subproject commit 956e4874dd95c06bf7d9ebd675774143c59db4b7