mirror of https://github.com/AxioDL/metaforce.git
HLSL extension shaders
This commit is contained in:
parent
d737ed7b34
commit
1c64605261
|
@ -16,7 +16,7 @@ zeus::CTransform CMappableObject::AdjustTransformForType()
|
||||||
zeus::CTransform scale;
|
zeus::CTransform scale;
|
||||||
scale.scaleBy(1.5);
|
scale.scaleBy(1.5);
|
||||||
zeus::CTransform orientation;
|
zeus::CTransform orientation;
|
||||||
orientation.origin = {-1.4*doorCenterX, 0.0f, 0.0f};
|
orientation.origin = {-1.4f*doorCenterX, 0.0f, 0.0f};
|
||||||
zeus::CTransform tmp3 = x10_ * orientation;
|
zeus::CTransform tmp3 = x10_ * orientation;
|
||||||
orientation.rotateLocalZ(zeus::degToRad(90.0f));
|
orientation.rotateLocalZ(zeus::degToRad(90.0f));
|
||||||
return tmp3 * scale;
|
return tmp3 * scale;
|
||||||
|
|
|
@ -1,3 +1,6 @@
|
||||||
|
#if _WIN32
|
||||||
|
#include <D3Dcommon.h>
|
||||||
|
#endif
|
||||||
#include "Graphics/CModel.hpp"
|
#include "Graphics/CModel.hpp"
|
||||||
#include "Graphics/CTexture.hpp"
|
#include "Graphics/CTexture.hpp"
|
||||||
#include "Graphics/CGraphics.hpp"
|
#include "Graphics/CGraphics.hpp"
|
||||||
|
|
|
@ -43,11 +43,31 @@ static const char* LightingHLSL =
|
||||||
" return saturate(ret);\n"
|
" return saturate(ret);\n"
|
||||||
"}\n";
|
"}\n";
|
||||||
|
|
||||||
|
static const char* ThermalPostHLSL =
|
||||||
|
"cbuffer ThermalUniform : register(b2)\n"
|
||||||
|
"{\n"
|
||||||
|
" float4 mulColor;\n"
|
||||||
|
" float4 addColor;\n"
|
||||||
|
"};\n"
|
||||||
|
"float4 ThermalPostFunc(in VertToFrag vtf, float4 colorIn)\n"
|
||||||
|
"{\n"
|
||||||
|
" return extTex7.Sample(samp, vtf.extTcgs[0]).rrrr * mulColor + addColor;\n"
|
||||||
|
"}\n"
|
||||||
|
"\n";
|
||||||
|
|
||||||
hecl::Runtime::ShaderCacheExtensions
|
hecl::Runtime::ShaderCacheExtensions
|
||||||
CModelShaders::GetShaderExtensionsHLSL(boo::IGraphicsDataFactory::Platform plat)
|
CModelShaders::GetShaderExtensionsHLSL(boo::IGraphicsDataFactory::Platform plat)
|
||||||
{
|
{
|
||||||
hecl::Runtime::ShaderCacheExtensions ext(plat);
|
hecl::Runtime::ShaderCacheExtensions ext(plat);
|
||||||
ext.registerExtensionSlot({LightingHLSL, "LightingFunc"}, {}, 0, nullptr);
|
|
||||||
|
/* Normal lit shading */
|
||||||
|
ext.registerExtensionSlot({LightingHLSL, "LightingFunc"}, {}, 0, nullptr, 0, nullptr,
|
||||||
|
hecl::Backend::BlendFactor::Original, hecl::Backend::BlendFactor::Original);
|
||||||
|
|
||||||
|
/* Thermal Visor shading */
|
||||||
|
ext.registerExtensionSlot({}, {ThermalPostHLSL, "ThermalPostFunc"}, 0, nullptr, 1, ThermalTextures,
|
||||||
|
hecl::Backend::BlendFactor::One, hecl::Backend::BlendFactor::One);
|
||||||
|
|
||||||
return ext;
|
return ext;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -113,7 +113,7 @@ void CSpaceWarpFilter::draw(const zeus::CVector3f& pt)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Transform UV coordinates of rectangle within viewport and sampled scene texels (clamped to viewport bounds) */
|
/* Transform UV coordinates of rectangle within viewport and sampled scene texels (clamped to viewport bounds) */
|
||||||
zeus::CVector2f vp{CGraphics::g_ViewportResolution.x, CGraphics::g_ViewportResolution.y};
|
zeus::CVector2f vp{float(CGraphics::g_ViewportResolution.x), float(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[3][0] = pt.x + (1.f / vp.x);
|
m_uniform.m_matrix[3][0] = pt.x + (1.f / vp.x);
|
||||||
|
|
|
@ -13,6 +13,7 @@ class CSpaceWarpFilter
|
||||||
friend struct CSpaceWarpFilterGLDataBindingFactory;
|
friend struct CSpaceWarpFilterGLDataBindingFactory;
|
||||||
friend struct CSpaceWarpFilterVulkanDataBindingFactory;
|
friend struct CSpaceWarpFilterVulkanDataBindingFactory;
|
||||||
friend struct CSpaceWarpFilterMetalDataBindingFactory;
|
friend struct CSpaceWarpFilterMetalDataBindingFactory;
|
||||||
|
friend struct CSpaceWarpFilterD3DDataBindingFactory;
|
||||||
|
|
||||||
struct Uniform
|
struct Uniform
|
||||||
{
|
{
|
||||||
|
|
|
@ -0,0 +1,89 @@
|
||||||
|
#include "CSpaceWarpFilter.hpp"
|
||||||
|
|
||||||
|
namespace urde
|
||||||
|
{
|
||||||
|
|
||||||
|
static const char* VS =
|
||||||
|
"struct VertData\n"
|
||||||
|
"{\n"
|
||||||
|
" float4 posIn : POSITION;\n"
|
||||||
|
" float4 uvIn : UV;\n"
|
||||||
|
"};\n"
|
||||||
|
"cbuffer SpaceWarpUniform : register(b0)\n"
|
||||||
|
"{\n"
|
||||||
|
" float4x4 mainMtx;\n"
|
||||||
|
" float4x4 indMtx;\n"
|
||||||
|
" float4 strength;\n"
|
||||||
|
"};\n"
|
||||||
|
"\n"
|
||||||
|
"struct VertToFrag\n"
|
||||||
|
"{\n"
|
||||||
|
" float4 position : SV_Position;\n"
|
||||||
|
" float2 sceneUv : SCENEUV;\n"
|
||||||
|
" float2 indUv : INDV;\n"
|
||||||
|
" float2 strength : STRENGTH;\n"
|
||||||
|
"};\n"
|
||||||
|
"\n"
|
||||||
|
"VertToFrag main(in VertData v)\n"
|
||||||
|
"{\n"
|
||||||
|
" VertToFrag vtf;\n"
|
||||||
|
" vtf.position = mul(mainMtx, float4(v.posIn.xy, 0.0, 1.0));\n"
|
||||||
|
" vtf.sceneUv = vtf.position.xy * float2(0.5, 0.5) + float2(0.5, 0.5);\n"
|
||||||
|
" vtf.sceneUv.y = -vtf.sceneUv.y;\n"
|
||||||
|
" vtf.indUv = mul(float3x3(indMtx[0].xyz, indMtx[1].xyz, indMtx[2].xyz), float3(v.uvIn.xy, 1.0)).xy;\n"
|
||||||
|
" vtf.indUv.y = -vtf.indUv.y;\n"
|
||||||
|
" vtf.strength = strength.xy;\n"
|
||||||
|
" return vtf;\n"
|
||||||
|
"}\n";
|
||||||
|
|
||||||
|
static const char* FS =
|
||||||
|
"Texture2D sceneTex : register(t0);\n"
|
||||||
|
"Texture2D indTex : register(t1);\n"
|
||||||
|
"SamplerState samp : register(s0);\n"
|
||||||
|
"struct VertToFrag\n"
|
||||||
|
"{\n"
|
||||||
|
" float4 position : SV_Position;\n"
|
||||||
|
" float2 sceneUv : SCENEUV;\n"
|
||||||
|
" float2 indUv : INDV;\n"
|
||||||
|
" float2 strength : STRENGTH;\n"
|
||||||
|
"};\n"
|
||||||
|
"\n"
|
||||||
|
"float4 main(in VertToFrag vtf) : SV_Target0\n"
|
||||||
|
"{\n"
|
||||||
|
" return sceneTex.Sample(samp, vtf.sceneUv + (indTex.Sample(samp, vtf.indUv).xy * float2(2.0, 2.0) - float2(1.0 - 1.0 / 256.0, 1.0 - 1.0 / 256.0)) * vtf.strength.xy);\n"
|
||||||
|
"}\n";
|
||||||
|
|
||||||
|
URDE_DECL_SPECIALIZE_SHADER(CSpaceWarpFilter)
|
||||||
|
|
||||||
|
struct CSpaceWarpFilterD3DDataBindingFactory : TShader<CSpaceWarpFilter>::IDataBindingFactory
|
||||||
|
{
|
||||||
|
boo::IShaderDataBinding* BuildShaderDataBinding(boo::IGraphicsDataFactory::Context& ctx, CSpaceWarpFilter& filter)
|
||||||
|
{
|
||||||
|
boo::ID3DDataFactory::Context& cctx = static_cast<boo::ID3DDataFactory::Context&>(ctx);
|
||||||
|
|
||||||
|
boo::IGraphicsBuffer* bufs[] = {filter.m_uniBuf};
|
||||||
|
boo::ITexture* texs[] = {CGraphics::g_SpareTexture, filter.m_warpTex};
|
||||||
|
return cctx.newShaderDataBinding(TShader<CSpaceWarpFilter>::m_pipeline,
|
||||||
|
TShader<CSpaceWarpFilter>::m_vtxFmt,
|
||||||
|
filter.m_vbo, nullptr, nullptr, 1, bufs,
|
||||||
|
nullptr, nullptr, nullptr, 2, texs);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
TShader<CSpaceWarpFilter>::IDataBindingFactory* CSpaceWarpFilter::Initialize(boo::ID3DDataFactory::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, ComPtr<ID3DBlob>(), ComPtr<ID3DBlob>(), ComPtr<ID3DBlob>(),
|
||||||
|
vtxFmtOut, boo::BlendFactor::One,
|
||||||
|
boo::BlendFactor::Zero, boo::Primitive::TriStrips, false, false, false);
|
||||||
|
return new CSpaceWarpFilterD3DDataBindingFactory;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -13,6 +13,7 @@ class CThermalColdFilter
|
||||||
friend struct CThermalColdFilterGLDataBindingFactory;
|
friend struct CThermalColdFilterGLDataBindingFactory;
|
||||||
friend struct CThermalColdFilterVulkanDataBindingFactory;
|
friend struct CThermalColdFilterVulkanDataBindingFactory;
|
||||||
friend struct CThemalColdFilterMetalDataBindingFactory;
|
friend struct CThemalColdFilterMetalDataBindingFactory;
|
||||||
|
friend struct CThemalColdFilterD3DDataBindingFactory;
|
||||||
|
|
||||||
struct Uniform
|
struct Uniform
|
||||||
{
|
{
|
||||||
|
|
|
@ -3,11 +3,108 @@
|
||||||
namespace urde
|
namespace urde
|
||||||
{
|
{
|
||||||
|
|
||||||
|
static const char* VS =
|
||||||
|
"struct VertData\n"
|
||||||
|
"{\n"
|
||||||
|
" float4 posIn : POSITION;\n"
|
||||||
|
" float4 uvIn : UV;\n"
|
||||||
|
"};\n"
|
||||||
|
"\n"
|
||||||
|
"cbuffer ThermalColdUniform : register(b0)\n"
|
||||||
|
"{\n"
|
||||||
|
" float4x4 shiftMtx;\n"
|
||||||
|
" float4x4 indMtx;\n"
|
||||||
|
" float4 shiftScale;\n"
|
||||||
|
" float4 colorReg0;\n"
|
||||||
|
" float4 colorReg1;\n"
|
||||||
|
" float4 colorReg2;\n"
|
||||||
|
"};\n"
|
||||||
|
"\n"
|
||||||
|
"struct VertToFrag\n"
|
||||||
|
"{\n"
|
||||||
|
" float4 position : SV_Position;\n"
|
||||||
|
" float3x3 indMtx : INDMTX;\n"
|
||||||
|
" float4 colorReg0 : COLORREG0;\n"
|
||||||
|
" float4 colorReg1 : COLORREG1;\n"
|
||||||
|
" float4 colorReg2 : COLORREG2;\n"
|
||||||
|
" float2 sceneUv : SCENEUV;\n"
|
||||||
|
" float2 shiftUv : SHIFTUV;\n"
|
||||||
|
" float2 shiftScale : SHIFTSCALE;\n"
|
||||||
|
"};\n"
|
||||||
|
"\n"
|
||||||
|
"VertToFrag main(in VertData v)\n"
|
||||||
|
"{\n"
|
||||||
|
" VertToFrag vtf;\n"
|
||||||
|
" vtf.indMtx = float3x3(indMtx[0].xyz, indMtx[1].xyz, indMtx[2].xyz);\n"
|
||||||
|
" vtf.colorReg0 = colorReg0;\n"
|
||||||
|
" vtf.colorReg1 = colorReg1;\n"
|
||||||
|
" vtf.colorReg2 = colorReg2;\n"
|
||||||
|
" vtf.sceneUv = v.uvIn.xy;\n"
|
||||||
|
" vtf.shiftUv = (mul(float3x3(shiftMtx[0].xyz, shiftMtx[1].xyz, shiftMtx[2].xyz), v.uvIn.xyz)).xy;\n"
|
||||||
|
" vtf.shiftScale = shiftScale.xy;\n"
|
||||||
|
" vtf.position = float4(v.posIn.xyz, 1.0);\n"
|
||||||
|
" return vtf;\n"
|
||||||
|
"}\n";
|
||||||
|
|
||||||
|
static const char* FS =
|
||||||
|
"Texture2D sceneTex : register(t0);\n"
|
||||||
|
"Texture2D shiftTex : register(t1);\n"
|
||||||
|
"SamplerState samp : register(s0);\n"
|
||||||
|
"struct VertToFrag\n"
|
||||||
|
"{\n"
|
||||||
|
" float4 position : SV_Position;\n"
|
||||||
|
" float3x3 indMtx : INDMTX;\n"
|
||||||
|
" float4 colorReg0 : COLORREG0;\n"
|
||||||
|
" float4 colorReg1 : COLORREG1;\n"
|
||||||
|
" float4 colorReg2 : COLORREG2;\n"
|
||||||
|
" float2 sceneUv : SCENEUV;\n"
|
||||||
|
" float2 shiftUv : SHIFTUV;\n"
|
||||||
|
" float2 shiftScale : SHIFTSCALE;\n"
|
||||||
|
"};\n"
|
||||||
|
"\n"
|
||||||
|
"static const float4 kRGBToYPrime = {0.299, 0.587, 0.114, 0.0};\n"
|
||||||
|
"float4 main(in VertToFrag vtf) : SV_Target0\n"
|
||||||
|
"{\n"
|
||||||
|
" float2 shiftCoordTexel = shiftTex.Sample(samp, vtf.shiftUv).xy;\n"
|
||||||
|
" float2 shiftCoord = vtf.sceneUv + shiftCoordTexel * vtf.shiftScale;\n"
|
||||||
|
" float shiftScene0 = dot(sceneTex.Sample(samp, shiftCoord), kRGBToYPrime);\n"
|
||||||
|
" float shiftScene1 = dot(sceneTex.Sample(samp, shiftCoord + float2(vtf.shiftScale.x / 8.0, 0.0)), kRGBToYPrime);\n"
|
||||||
|
" float2 indCoord = (mul(vtf.indMtx, float3(shiftScene0 - 0.5, shiftScene1 - 0.5, 1.0))).xy;\n"
|
||||||
|
" float indScene = dot(sceneTex.Sample(samp, vtf.sceneUv + indCoord), kRGBToYPrime);\n"
|
||||||
|
" return vtf.colorReg0 * indScene + vtf.colorReg1 * shiftScene0 + vtf.colorReg2;\n"
|
||||||
|
"}\n";
|
||||||
|
|
||||||
|
URDE_DECL_SPECIALIZE_SHADER(CThermalColdFilter)
|
||||||
|
|
||||||
|
struct CThemalColdFilterD3DDataBindingFactory : TShader<CThermalColdFilter>::IDataBindingFactory
|
||||||
|
{
|
||||||
|
boo::IShaderDataBinding* BuildShaderDataBinding(boo::IGraphicsDataFactory::Context& ctx, CThermalColdFilter& filter)
|
||||||
|
{
|
||||||
|
boo::ID3DDataFactory::Context& cctx = static_cast<boo::ID3DDataFactory::Context&>(ctx);
|
||||||
|
|
||||||
|
boo::IGraphicsBuffer* bufs[] = {filter.m_uniBuf};
|
||||||
|
boo::ITexture* texs[] = {CGraphics::g_SpareTexture, filter.m_shiftTex};
|
||||||
|
return cctx.newShaderDataBinding(TShader<CThermalColdFilter>::m_pipeline,
|
||||||
|
TShader<CThermalColdFilter>::m_vtxFmt,
|
||||||
|
filter.m_vbo, nullptr, nullptr, 1, bufs,
|
||||||
|
nullptr, nullptr, nullptr, 2, texs);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
TShader<CThermalColdFilter>::IDataBindingFactory* CThermalColdFilter::Initialize(boo::ID3DDataFactory::Context& ctx,
|
TShader<CThermalColdFilter>::IDataBindingFactory* CThermalColdFilter::Initialize(boo::ID3DDataFactory::Context& ctx,
|
||||||
boo::IShaderPipeline*& pipeOut,
|
boo::IShaderPipeline*& pipeOut,
|
||||||
boo::IVertexFormat*& vtxFmtOut)
|
boo::IVertexFormat*& vtxFmtOut)
|
||||||
{
|
{
|
||||||
return nullptr;
|
const boo::VertexElementDescriptor VtxVmt[] =
|
||||||
|
{
|
||||||
|
{nullptr, nullptr, boo::VertexSemantic::Position4},
|
||||||
|
{nullptr, nullptr, boo::VertexSemantic::UV4}
|
||||||
|
};
|
||||||
|
vtxFmtOut = ctx.newVertexFormat(2, VtxVmt);
|
||||||
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,6 @@
|
||||||
|
#if _WIN32
|
||||||
|
#include <D3Dcommon.h>
|
||||||
|
#endif
|
||||||
#include "CGameArea.hpp"
|
#include "CGameArea.hpp"
|
||||||
#include "GameGlobalObjects.hpp"
|
#include "GameGlobalObjects.hpp"
|
||||||
#include "Graphics/CBooRenderer.hpp"
|
#include "Graphics/CBooRenderer.hpp"
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
#include "CSimplePool.hpp"
|
#include "CSimplePool.hpp"
|
||||||
#include "CStateManager.hpp"
|
#include "CStateManager.hpp"
|
||||||
#include "CInGameTweakManagerBase.hpp"
|
#include "CInGameTweakManagerBase.hpp"
|
||||||
|
#include "Audio/CAudioGroupSet.hpp"
|
||||||
|
|
||||||
namespace urde
|
namespace urde
|
||||||
{
|
{
|
||||||
|
|
2
hecl
2
hecl
|
@ -1 +1 @@
|
||||||
Subproject commit cc98390bdb08dd2a83c6b2a6b7c92dc6c4e20fac
|
Subproject commit 8830763583627a50b755d1e9ef4a02ec76c91c6f
|
2
kabufuda
2
kabufuda
|
@ -1 +1 @@
|
||||||
Subproject commit d242e2deb63b2fc6da526e7245d4dfa487731af4
|
Subproject commit d0791ebd2172d2adb85ab5bc32bbbb3a6d40f29f
|
Loading…
Reference in New Issue