Thermal Hot GLSL filter

This commit is contained in:
Jack Andersen 2016-08-03 11:53:03 -10:00
parent 135aac5fef
commit 9222a928ef
16 changed files with 263 additions and 27 deletions

View File

@ -13,6 +13,7 @@
#include "Runtime/Graphics/CModel.hpp"
#include "Runtime/Graphics/CGraphics.hpp"
#include "Runtime/Character/CSkinRules.hpp"
#include "Graphics/CMetroidModelInstance.hpp"
#include <cstdio>
using YAMLNode = athena::io::YAMLNode;
@ -21,6 +22,7 @@ namespace urde
{
URDE_DECL_SPECIALIZE_SHADER(CThermalColdFilter)
URDE_DECL_SPECIALIZE_SHADER(CThermalHotFilter)
URDE_DECL_SPECIALIZE_SHADER(CSpaceWarpFilter)
void ViewManager::BuildTestPART(urde::IObjectStore& objStore)
@ -77,29 +79,35 @@ void ViewManager::ParticleView::draw(boo::IGraphicsCommandQueue *gfxQ)
{
CModelFlags flags;
flags.m_extendedShaderIdx = 1;
flags.m_extendedShaderIdx = 0;
//flags.m_extendedShaderIdx = 2;
//if (std::fmod(m_theta, M_PIF) < M_PIF / 2.f)
// flags.m_extendedShaderIdx = 1;
m_theta += 0.01f;
CGraphics::SetModelMatrix(zeus::CTransform::Translate(0.f, 0.f, -3.f) *
zeus::CTransform::RotateZ(m_theta) *
zeus::CTransform::Scale(1.f));
//CGraphics::SetModelMatrix(zeus::CTransform::Identity());
CGraphics::SetViewPointMatrix(zeus::lookAt(zeus::CVector3f{0.f, -10.f, 4.f}, {0.f, 0.f, 0.f}));
CGraphics::SetModelMatrix(zeus::CTransform::RotateZ(m_theta));
g_Renderer->SetWorldViewpoint(zeus::lookAt(zeus::CVector3f{0.f, -10.f, 7.f},
{0.f, 0.f, 3.f}));
boo::SWindowRect windowRect = m_vm.m_mainWindow->getWindowFrame();
float aspect = windowRect.size[0] / float(windowRect.size[1]);
CGraphics::SetPerspective(55.0, aspect, 0.1f, 1000.f);
zeus::CFrustum frustum;
frustum.updatePlanes(CGraphics::g_GXModelView, zeus::SProjPersp(55.0, aspect, 0.1f, 1000.f));
g_Renderer->SetClippingPlanes(frustum);
std::vector<CLight> lights = {CLight::BuildLocalAmbient({}, {0.05f, 0.05f, 0.05f, 1.f}),
CLight::BuildCustom({5.f, -20.f, 10.f}, {0.f, 1.f, 0.f},
{200.f, 200.f, 200.f}, 0.f, 0.f, 1.f, 1.f, 0.f, 0.f)};
//lights = {CLight::BuildLocalAmbient({}, {1.0f, 0.0f, 0.0f, 1.f})};
m_vm.m_modelTest->GetInstance().ActivateLights(lights);
//m_vm.m_modelTest->GetInstance().ActivateLights(lights);
g_Renderer->SetThermal(true, 1.f, zeus::CColor::skWhite);
g_Renderer->SetThermalColdScale(std::sin(m_theta) * 0.5f + 0.5f);
g_Renderer->DoThermalBlendCold();
flags.m_extendedShaderIdx = 2;
m_vm.m_modelTest->Draw(flags);
m_spaceWarpFilter.setStrength(std::sin(m_theta * 5.f) * 0.5f + 0.5f);
g_Renderer->DoThermalBlendHot();
//m_spaceWarpFilter.setStrength(std::sin(m_theta * 5.f) * 0.5f + 0.5f);
//m_spaceWarpFilter.draw(zeus::CVector2f{0.f, 0.f});
}
if (m_vm.m_partGen)
@ -369,6 +377,7 @@ void ViewManager::stop()
m_videoVoice.reset();
m_projManager.shutdown();
TShader<CThermalColdFilter>::Shutdown();
TShader<CThermalHotFilter>::Shutdown();
TShader<CSpaceWarpFilter>::Shutdown();
CElementGen::Shutdown();
CMoviePlayer::Shutdown();

View File

@ -83,10 +83,10 @@ void Buckets::Sort()
for (auto it = sBuckets->rbegin() ; it != sBuckets->rend() ; ++it)
{
--bucketIdx;
sBucketIndex.push_back(bucketIdx);
rstl::reserved_vector<CDrawable*, 128>& bucket = *it;
if (bucket.size())
{
sBucketIndex.push_back(bucketIdx);
std::sort(bucket.begin(), bucket.end(),
[](CDrawable* a, CDrawable* b) -> bool
{
@ -191,11 +191,14 @@ void CBooRenderer::ActivateLightsForModel(CAreaListItem* item, CBooModel& model)
}
}
model.ActivateLights(thisLights);
//model.ActivateLights(thisLights);
}
void CBooRenderer::RenderBucketItems(CAreaListItem* item)
{
CModelFlags flags;
flags.m_extendedShaderIdx = 1;
for (u16 idx : Buckets::sBucketIndex)
{
rstl::reserved_vector<CDrawable*, 128>& bucket = (*Buckets::sBuckets)[idx];
@ -208,14 +211,14 @@ void CBooRenderer::RenderBucketItems(CAreaListItem* item)
static_cast<CParticleGen*>((void*)drawable->GetData())->Render();
break;
}
case EDrawableType::Surface:
case EDrawableType::WorldSurface:
{
CBooSurface* surf = static_cast<CBooSurface*>((void*)drawable->GetData());
CBooModel* model = surf->m_parent;
if (model)
{
ActivateLightsForModel(item, *model);
model->DrawSurface(*surf, CModelFlags{});
model->DrawSurface(*surf, flags);
}
break;
}
@ -237,9 +240,11 @@ void CBooRenderer::HandleUnsortedModel(CAreaListItem* item, CBooModel& model)
{
ActivateLightsForModel(item, model);
CBooSurface* surf = model.x38_firstUnsortedSurface;
CModelFlags flags;
flags.m_extendedShaderIdx = 1;
while (surf)
{
model.DrawSurface(*surf, CModelFlags{});
model.DrawSurface(*surf, flags);
surf = surf->m_next;
}
}
@ -283,12 +288,13 @@ void CBooRenderer::LoadThermoPalette()
m_thermoPaletteTex = xc_store.GetObj("TXTR_ThermoPalette");
CTexture* thermoTexObj = m_thermoPaletteTex.GetObj();
if (thermoTexObj)
x288_thermoPalette = thermoTexObj->GetBooTexture();
x288_thermoPalette = thermoTexObj->GetPaletteTexture();
}
CBooRenderer::CBooRenderer(IObjectStore& store, IFactory& resFac)
: x8_factory(resFac), xc_store(store), x2a8_thermalRand(20)
{
g_Renderer = this;
xee_24_ = true;
m_gfxToken = CGraphics::CommitResources([&](boo::IGraphicsDataFactory::Context& ctx) -> bool
@ -298,6 +304,7 @@ CBooRenderer::CBooRenderer(IObjectStore& store, IFactory& resFac)
return true;
});
LoadThermoPalette();
m_thermHotFilter.emplace();
Buckets::Init();
}
@ -307,10 +314,10 @@ void CBooRenderer::AddWorldSurfaces(CBooModel& model)
CBooSurface* surf = model.x3c_firstSortedSurface;
while (surf)
{
const CBooModel::MaterialSet::Material& mat = model.GetMaterialByIndex(surf->selfIdx);
const CBooModel::MaterialSet::Material& mat = model.GetMaterialByIndex(surf->m_data.matIdx);
zeus::CAABox aabb = surf->GetBounds();
zeus::CVector3f pt = aabb.closestPointAlongVector(xb0_viewPlane.vec);
Buckets::Insert(pt, aabb, EDrawableType::Surface, surf, xb0_viewPlane,
Buckets::Insert(pt, aabb, EDrawableType::WorldSurface, surf, xb0_viewPlane,
mat.heclIr.m_blendDst != boo::BlendFactor::Zero);
surf = surf->m_next;
}
@ -617,7 +624,6 @@ void CBooRenderer::SetThermal(bool thermal, float level, const zeus::CColor& col
void CBooRenderer::SetThermalColdScale(float scale)
{
x2f8_thermColdScale = zeus::clamp(0.f, scale, 1.f);
m_thermColdFilter.setScale(x2f8_thermColdScale);
}
void CBooRenderer::DoThermalBlendCold()
@ -645,6 +651,7 @@ void CBooRenderer::DoThermalBlendCold()
void CBooRenderer::DoThermalBlendHot()
{
m_thermHotFilter->draw();
}
u32 CBooRenderer::GetStaticWorldDataSize()

View File

@ -6,6 +6,7 @@
#include "CDrawable.hpp"
#include "CDrawablePlaneObject.hpp"
#include "Shaders/CThermalColdFilter.hpp"
#include "Shaders/CThermalHotFilter.hpp"
#include "Shaders/CSpaceWarpFilter.hpp"
#include "CRandom16.hpp"
#include "CPVSVisSet.hpp"
@ -107,6 +108,7 @@ class CBooRenderer : public IRenderer
zeus::CColor x2f4_thermColor;
float x2f8_thermColdScale = 0.f;
CThermalColdFilter m_thermColdFilter;
std::experimental::optional<CThermalHotFilter> m_thermHotFilter;
std::vector<CLight> x304_lights;
@ -197,6 +199,8 @@ public:
void DoThermalBlendHot();
u32 GetStaticWorldDataSize();
boo::ITexture* GetThermoPalette() {return x288_thermoPalette;}
void BindMainDrawTarget() {CGraphics::g_BooMainCommandQueue->setRenderTarget(CGraphics::g_SpareTexture);}
void BindReflectionDrawTarget() {CGraphics::g_BooMainCommandQueue->setRenderTarget(x14c_reflectionTex);}
};

View File

@ -8,7 +8,7 @@ namespace urde
{
enum class EDrawableType : u16
{
Surface,
WorldSurface,
Particle,
UnsortedCallback,
SortedCallback

View File

@ -4,6 +4,12 @@
namespace urde
{
CMetroidModelInstance::CMetroidModelInstance(CBooModel* inst)
: x0_visorFlags(0), m_instance(inst)
{
x34_aabb = inst->x20_aabb;
}
CMetroidModelInstance::CMetroidModelInstance
(const void* modelHeader, CBooModel* inst)
: x0_visorFlags(hecl::SBig(*static_cast<const u32*>(modelHeader))), m_instance(inst)

View File

@ -19,6 +19,7 @@ class CMetroidModelInstance
zeus::CAABox x34_aabb;
CBooModel* m_instance;
public:
CMetroidModelInstance(CBooModel* inst);
CMetroidModelInstance(const void* modelHeader, CBooModel* inst);
~CMetroidModelInstance();
};

View File

@ -61,6 +61,7 @@ class CBooModel
{
friend class CModel;
friend class CBooRenderer;
friend class CMetroidModelInstance;
public:
using MaterialSet = DataSpec::DNAMP1::HMDLMaterialSet;
using UVAnimation = DataSpec::DNAMP1::MaterialSet::Material::UVAnimation;
@ -105,7 +106,6 @@ private:
std::vector<std::vector<boo::IShaderDataBinding*>> m_shaderDataBindings;
void BuildGfxToken();
void UpdateUniformData(const CModelFlags& flags) const;
void DrawAlphaSurfaces(const CModelFlags& flags) const;
void DrawNormalSurfaces(const CModelFlags& flags) const;
void DrawSurfaces(const CModelFlags& flags) const;
@ -125,6 +125,7 @@ public:
void RemapMaterialData(SShader& shader);
bool TryLockTextures() const;
void UnlockTextures() const;
void UpdateUniformData(const CModelFlags& flags) const;
void DrawAlpha(const CModelFlags& flags) const;
void DrawNormal(const CModelFlags& flags) const;
void Draw(const CModelFlags& flags) const;

View File

@ -50,6 +50,7 @@ public:
u16 GetHeight() const {return x6_h;}
void Load(int slot, EClampMode clamp) const;
boo::ITexture* GetBooTexture() {return m_booTex;}
boo::ITexture* GetPaletteTexture() {return m_paletteTex;}
};
CFactoryFnReturn FTextureFactory(const urde::SObjectTag& tag,

View File

@ -27,7 +27,7 @@ public:
enum class EDrawableSorting
{
SortedBuckets,
SortedCallback,
UnsortedCallback
};
enum class EDebugOption

View File

@ -12,8 +12,8 @@ class CThermalColdFilter
{
friend struct CThermalColdFilterGLDataBindingFactory;
friend struct CThermalColdFilterVulkanDataBindingFactory;
friend struct CThemalColdFilterMetalDataBindingFactory;
friend struct CThemalColdFilterD3DDataBindingFactory;
friend struct CThermalColdFilterMetalDataBindingFactory;
friend struct CThermalColdFilterD3DDataBindingFactory;
struct Uniform
{

View File

@ -76,7 +76,7 @@ static const char* FS =
URDE_DECL_SPECIALIZE_SHADER(CThermalColdFilter)
struct CThemalColdFilterD3DDataBindingFactory : TShader<CThermalColdFilter>::IDataBindingFactory
struct CThermalColdFilterD3DDataBindingFactory : TShader<CThermalColdFilter>::IDataBindingFactory
{
boo::IShaderDataBinding* BuildShaderDataBinding(boo::IGraphicsDataFactory::Context& ctx, CThermalColdFilter& filter)
{
@ -104,7 +104,7 @@ TShader<CThermalColdFilter>::IDataBindingFactory* CThermalColdFilter::Initialize
pipeOut = ctx.newShaderPipeline(VS, FS, ComPtr<ID3DBlob>(), ComPtr<ID3DBlob>(), ComPtr<ID3DBlob>(),
vtxFmtOut, boo::BlendFactor::One,
boo::BlendFactor::Zero, boo::Primitive::TriStrips, false, false, false);
return new CThemalColdFilterD3DDataBindingFactory;
return new CThermalColdFilterD3DDataBindingFactory;
}
}

View File

@ -84,7 +84,7 @@ static const char* FS =
URDE_DECL_SPECIALIZE_SHADER(CThermalColdFilter)
struct CThemalColdFilterMetalDataBindingFactory : TShader<CThermalColdFilter>::IDataBindingFactory
struct CThermalColdFilterMetalDataBindingFactory : TShader<CThermalColdFilter>::IDataBindingFactory
{
boo::IShaderDataBinding* BuildShaderDataBinding(boo::IGraphicsDataFactory::Context& ctx, CThermalColdFilter& filter)
{
@ -111,7 +111,7 @@ TShader<CThermalColdFilter>::IDataBindingFactory* CThermalColdFilter::Initialize
vtxFmtOut = ctx.newVertexFormat(2, VtxVmt);
pipeOut = ctx.newShaderPipeline(VS, FS, vtxFmtOut, CGraphics::g_ViewportSamples, boo::BlendFactor::One,
boo::BlendFactor::Zero, boo::Primitive::TriStrips, false, false, false);
return new CThemalColdFilterMetalDataBindingFactory;
return new CThermalColdFilterMetalDataBindingFactory;
}
}

View File

@ -0,0 +1,44 @@
#include "CThermalHotFilter.hpp"
#include "Graphics/CGraphics.hpp"
namespace urde
{
CThermalHotFilter::CThermalHotFilter()
{
m_token = CGraphics::g_BooFactory->commitTransaction([&](boo::IGraphicsDataFactory::Context& ctx) -> bool
{
struct Vert
{
zeus::CVector2f m_pos;
zeus::CVector2f m_uv;
} verts[4] =
{
{{-1.0, -1.0}, {0.0, 0.0}},
{{-1.0, 1.0}, {0.0, 1.0}},
{{ 1.0, -1.0}, {1.0, 0.0}},
{{ 1.0, 1.0}, {1.0, 1.0}},
};
m_vbo = ctx.newStaticBuffer(boo::BufferUse::Vertex, verts, 32, 4);
m_uniBuf = ctx.newDynamicBuffer(boo::BufferUse::Uniform, sizeof(Uniform), 1);
m_dataBind = TShader<CThermalHotFilter>::BuildShaderDataBinding(ctx, *this);
return true;
});
}
void CThermalHotFilter::draw()
{
SClipScreenRect clipRect = {};
clipRect.xc_width = CGraphics::g_ViewportResolution.x;
clipRect.x10_height = CGraphics::g_ViewportResolution.y;
CGraphics::ResolveSpareTexture(clipRect);
//m_uniBuf->load(&m_uniform, sizeof(m_uniform));
CGraphics::g_BooMainCommandQueue->setShaderDataBinding(m_dataBind);
CGraphics::g_BooMainCommandQueue->draw(0, 4);
}
URDE_SPECIALIZE_SHADER(CThermalHotFilter)
}

View File

@ -0,0 +1,41 @@
#ifndef __URDE_CTHERMALHOTFILTER_HPP__
#define __URDE_CTHERMALHOTFILTER_HPP__
#include "TShader.hpp"
#include "zeus/CMatrix4f.hpp"
#include "zeus/CColor.hpp"
namespace urde
{
class CThermalHotFilter
{
friend struct CThermalHotFilterGLDataBindingFactory;
friend struct CThermalHotFilterVulkanDataBindingFactory;
friend struct CThermalHotFilterMetalDataBindingFactory;
friend struct CThermalHotFilterD3DDataBindingFactory;
struct Uniform
{
zeus::CColor m_colorRegs[3];
};
boo::GraphicsDataToken m_token;
boo::IGraphicsBufferS* m_vbo;
boo::IGraphicsBufferD* m_uniBuf;
boo::IShaderDataBinding* m_dataBind = nullptr;
Uniform m_uniform;
public:
CThermalHotFilter();
void setColorA(const zeus::CColor& color) {m_uniform.m_colorRegs[0] = color;}
void setColorB(const zeus::CColor& color) {m_uniform.m_colorRegs[1] = color;}
void setColorC(const zeus::CColor& color) {m_uniform.m_colorRegs[2] = color;}
void draw();
using _CLS = CThermalHotFilter;
#include "TShaderDecl.hpp"
};
}
#endif // __URDE_CTHERMALHOTFILTER_HPP__

View File

@ -0,0 +1,119 @@
#include "CThermalHotFilter.hpp"
#include "Graphics/CBooRenderer.hpp"
#include "GameGlobalObjects.hpp"
namespace urde
{
static const char* VS =
"#version 330\n"
BOO_GLSL_BINDING_HEAD
"layout(location=0) in vec4 posIn;\n"
"layout(location=1) in vec4 uvIn;\n"
"\n"
"UBINDING0 uniform ThermalHotUniform\n"
"{\n"
" vec4 colorReg0;\n"
" vec4 colorReg1;\n"
" vec4 colorReg2;\n"
"};\n"
"\n"
"struct VertToFrag\n"
"{\n"
" vec2 sceneUv;\n"
"};\n"
"\n"
"SBINDING(0) out VertToFrag vtf;\n"
"void main()\n"
"{\n"
" vtf.sceneUv = uvIn.xy;\n"
" gl_Position = vec4(posIn.xyz, 1.0);\n"
"}\n";
static const char* FS =
"#version 330\n"
BOO_GLSL_BINDING_HEAD
"struct VertToFrag\n"
"{\n"
" vec2 sceneUv;\n"
"};\n"
"\n"
"SBINDING(0) in VertToFrag vtf;\n"
"layout(location=0) out vec4 colorOut;\n"
"TBINDING0 uniform sampler2D sceneTex;\n"
"TBINDING1 uniform sampler2D paletteTex;\n"
"const vec4 kRGBToYPrime = vec4(0.299, 0.587, 0.114, 0.0);\n"
"void main()\n"
"{\n"
" float sceneSample = dot(texture(sceneTex, vtf.sceneUv), kRGBToYPrime);\n"
" vec4 colorSample = texture(paletteTex, vec2(sceneSample / 17.0, 0.5));\n"
" colorOut = colorSample * sceneSample;\n"
"}\n";
URDE_DECL_SPECIALIZE_SHADER(CThermalHotFilter)
struct CThermalHotFilterGLDataBindingFactory : TShader<CThermalHotFilter>::IDataBindingFactory
{
boo::IShaderDataBinding* BuildShaderDataBinding(boo::IGraphicsDataFactory::Context& ctx, CThermalHotFilter& filter)
{
boo::GLDataFactory::Context& cctx = static_cast<boo::GLDataFactory::Context&>(ctx);
const boo::VertexElementDescriptor VtxVmt[] =
{
{filter.m_vbo, nullptr, boo::VertexSemantic::Position4},
{filter.m_vbo, nullptr, boo::VertexSemantic::UV4}
};
boo::IGraphicsBuffer* bufs[] = {filter.m_uniBuf};
boo::PipelineStage stages[] = {boo::PipelineStage::Vertex};
boo::ITexture* texs[] = {CGraphics::g_SpareTexture, g_Renderer->GetThermoPalette()};
return cctx.newShaderDataBinding(TShader<CThermalHotFilter>::m_pipeline,
ctx.newVertexFormat(2, VtxVmt), filter.m_vbo, nullptr, nullptr,
1, bufs, stages, nullptr, nullptr, 2, texs);
}
};
#if BOO_HAS_VULKAN
struct CThermalHotFilterVulkanDataBindingFactory : TShader<CThermalHotFilter>::IDataBindingFactory
{
boo::IShaderDataBinding* BuildShaderDataBinding(boo::IGraphicsDataFactory::Context& ctx, CThermalHotFilter& filter)
{
boo::VulkanDataFactory::Context& cctx = static_cast<boo::VulkanDataFactory::Context&>(ctx);
boo::IGraphicsBuffer* bufs[] = {filter.m_uniBuf};
boo::ITexture* texs[] = {CGraphics::g_SpareTexture, g_Renderer->GetThermoPalette()};
return cctx.newShaderDataBinding(TShader<CThermalHotFilter>::m_pipeline,
TShader<CThermalHotFilter>::m_vtxFmt,
filter.m_vbo, nullptr, nullptr, 1, bufs,
nullptr, nullptr, nullptr, 2, texs);
}
};
#endif
TShader<CThermalHotFilter>::IDataBindingFactory* CThermalHotFilter::Initialize(boo::GLDataFactory::Context& ctx,
boo::IShaderPipeline*& pipeOut)
{
const char* texNames[] = {"sceneTex", "paletteTex"};
const char* uniNames[] = {"ThermalHotUniform"};
pipeOut = ctx.newShaderPipeline(VS, FS, 2, texNames, 1, uniNames, boo::BlendFactor::DstAlpha,
boo::BlendFactor::InvDstAlpha, boo::Primitive::TriStrips, false, false, false);
return new CThermalHotFilterGLDataBindingFactory;
}
#if BOO_HAS_VULKAN
TShader<CThermalHotFilter>::IDataBindingFactory* CThermalHotFilter::Initialize(boo::VulkanDataFactory::Context& ctx,
boo::IShaderPipeline*& pipeOut,
boo::IVertexFormat*& vtxFmtOut)
{
const boo::VertexElementDescriptor VtxVmt[] =
{
{nullptr, nullptr, boo::VertexSemantic::Position4},
{nullptr, nullptr, boo::VertexSemantic::UV4}
};
vtxFmtOut = ctx.newVertexFormat(2, VtxVmt);
pipeOut = ctx.newShaderPipeline(VS, FS, vtxFmtOut, boo::BlendFactor::DstAlpha,
boo::BlendFactor::InvDstAlpha, boo::Primitive::TriStrips, false, false, false);
return new CThermalHotFilterVulkanDataBindingFactory;
}
#endif
}

View File

@ -1,11 +1,13 @@
#include "MP1.hpp"
#include "Graphics/Shaders/CModelShaders.hpp"
#include "Graphics/Shaders/CThermalColdFilter.hpp"
#include "Graphics/Shaders/CThermalHotFilter.hpp"
#include "Graphics/Shaders/CSpaceWarpFilter.hpp"
namespace urde
{
URDE_DECL_SPECIALIZE_SHADER(CThermalColdFilter)
URDE_DECL_SPECIALIZE_SHADER(CThermalHotFilter)
URDE_DECL_SPECIALIZE_SHADER(CSpaceWarpFilter)
namespace MP1
@ -35,6 +37,7 @@ void CMain::InitializeSubsystems(boo::IGraphicsDataFactory* factory,
CGraphics::InitializeBoo(factory, cc, renderTex);
CModelShaders::Initialize(storeMgr, factory);
TShader<CThermalColdFilter>::Initialize();
TShader<CThermalHotFilter>::Initialize();
TShader<CSpaceWarpFilter>::Initialize();
CMoviePlayer::Initialize();
CLineRenderer::Initialize();