metaforce/Runtime/Graphics/Shaders/CModelShadersHLSL.cpp

282 lines
12 KiB
C++
Raw Normal View History

2016-04-04 02:32:57 +00:00
#include "CModelShaders.hpp"
namespace urde
{
2016-04-04 19:34:54 +00:00
static const char* LightingHLSL =
"struct Light\n"
"{\n"
" float4 pos;\n"
" float4 dir;\n"
" float4 color;\n"
" float4 linAtt;\n"
" float4 angAtt;\n"
"};\n"
2016-08-08 18:54:05 +00:00
"struct Fog\n"
"{\n"
" float4 color;\n"
" float rangeScale;\n"
" float start;\n"
"};\n"
2016-04-04 19:34:54 +00:00
"\n"
"cbuffer LightingUniform : register(b2)\n"
"{\n"
" Light lights[" _XSTR(URDE_MAX_LIGHTS) "];\n"
" float4 ambient;\n"
2016-07-21 05:21:45 +00:00
" float4 colorReg0;\n"
" float4 colorReg1;\n"
" float4 colorReg2;\n"
2017-02-10 09:00:57 +00:00
" float4 mulColor;\n"
2016-08-08 18:54:05 +00:00
" Fog fog;\n"
2016-04-04 19:34:54 +00:00
"};\n"
"\n"
"static float4 LightingFunc(float4 mvPosIn, float4 mvNormIn, in VertToFrag vtf)\n"
2016-04-04 19:34:54 +00:00
"{\n"
" float4 ret = ambient;\n"
" \n"
" for (int i=0 ; i<" _XSTR(URDE_MAX_LIGHTS) " ; ++i)\n"
" {\n"
" float3 delta = mvPosIn.xyz - lights[i].pos.xyz;\n"
" float dist = length(delta);\n"
" float angDot = saturate(dot(normalize(delta), lights[i].dir.xyz));\n"
" float att = 1.0 / (lights[i].linAtt[2] * dist * dist +\n"
" lights[i].linAtt[1] * dist +\n"
" lights[i].linAtt[0]);\n"
" float angAtt = lights[i].angAtt[2] * angDot * angDot +\n"
" lights[i].angAtt[1] * angDot +\n"
" lights[i].angAtt[0];\n"
" ret += lights[i].color * saturate(angAtt) * att * saturate(dot(normalize(-delta), mvNormIn.xyz));\n"
" }\n"
" \n"
2018-05-08 02:11:07 +00:00
" return ret;\n"
2016-04-04 19:34:54 +00:00
"}\n";
static const char* LightingShadowHLSL =
"struct Light\n"
"{\n"
" float4 pos;\n"
" float4 dir;\n"
" float4 color;\n"
" float4 linAtt;\n"
" float4 angAtt;\n"
"};\n"
"struct Fog\n"
"{\n"
" float4 color;\n"
" float rangeScale;\n"
" float start;\n"
"};\n"
"\n"
"cbuffer LightingUniform : register(b2)\n"
"{\n"
" Light lights[" _XSTR(URDE_MAX_LIGHTS) "];\n"
" float4 ambient;\n"
" float4 colorReg0;\n"
" float4 colorReg1;\n"
" float4 colorReg2;\n"
" float4 mulColor;\n"
" Fog fog;\n"
"};\n"
"\n"
"static float4 LightingShadowFunc(float4 mvPosIn, float4 mvNormIn, in VertToFrag vtf)\n"
"{\n"
" float4 ret = ambient;\n"
" \n"
2017-10-16 05:26:50 +00:00
" float3 delta = mvPosIn.xyz - lights[0].pos.xyz;\n"
" float dist = length(delta);\n"
2017-10-16 05:26:50 +00:00
" float angDot = saturate(dot(normalize(delta), lights[0].dir.xyz));\n"
" float att = 1.0 / (lights[0].linAtt[2] * dist * dist +\n"
" lights[0].linAtt[1] * dist +\n"
" lights[0].linAtt[0]);\n"
" float angAtt = lights[0].angAtt[2] * angDot * angDot +\n"
" lights[0].angAtt[1] * angDot +\n"
" lights[0].angAtt[0];\n"
" ret += lights[0].color * saturate(angAtt) * att * saturate(dot(normalize(-delta), mvNormIn.xyz)) *\n"
2017-10-17 05:51:53 +00:00
" extTex7.Sample(clampSamp, vtf.extTcgs[0]).r;\n"
" \n"
" for (int i=1 ; i<" _XSTR(URDE_MAX_LIGHTS) " ; ++i)\n"
" {\n"
" float3 delta = mvPosIn.xyz - lights[i].pos.xyz;\n"
" float dist = length(delta);\n"
" float angDot = saturate(dot(normalize(delta), lights[i].dir.xyz));\n"
" float att = 1.0 / (lights[i].linAtt[2] * dist * dist +\n"
" lights[i].linAtt[1] * dist +\n"
" lights[i].linAtt[0]);\n"
" float angAtt = lights[i].angAtt[2] * angDot * angDot +\n"
" lights[i].angAtt[1] * angDot +\n"
" lights[i].angAtt[0];\n"
" ret += lights[i].color * saturate(angAtt) * att * saturate(dot(normalize(-delta), mvNormIn.xyz));\n"
" }\n"
" \n"
2018-05-08 02:11:07 +00:00
" return ret;\n"
"}\n";
2016-08-08 18:54:05 +00:00
static const char* MainPostHLSL =
2016-08-20 04:22:13 +00:00
"static float4 MainPostFunc(in VertToFrag vtf, float4 colorIn)\n"
2016-08-08 18:54:05 +00:00
"{\n"
" float fogZ = (-vtf.mvPos.z - fog.start) * fog.rangeScale;\n"
" return lerp(fog.color, colorIn, saturate(exp2(-8.0 * fogZ)));\n"
"}\n"
"\n";
2016-08-01 04:35:42 +00:00
static const char* ThermalPostHLSL =
"cbuffer ThermalUniform : register(b2)\n"
"{\n"
2017-02-10 09:09:06 +00:00
" float4 tmulColor;\n"
2016-08-01 04:35:42 +00:00
" float4 addColor;\n"
"};\n"
2016-08-20 04:22:13 +00:00
"static float4 ThermalPostFunc(in VertToFrag vtf, float4 colorIn)\n"
2016-08-01 04:35:42 +00:00
"{\n"
2018-02-05 06:56:09 +00:00
" return float4(extTex7.Sample(samp, vtf.extTcgs[0]).rrr * tmulColor.rgb + addColor.rgb, tmulColor.a + addColor.a);\n"
2016-08-01 04:35:42 +00:00
"}\n"
"\n";
2017-03-05 07:57:12 +00:00
static const char* SolidPostHLSL =
"cbuffer SolidUniform : register(b2)\n"
"{\n"
" float4 solidColor;\n"
"};\n"
2017-03-05 23:03:23 +00:00
"static float4 SolidPostFunc(in VertToFrag vtf, float4 colorIn)\n"
2017-03-05 07:57:12 +00:00
"{\n"
" return solidColor;\n"
"}\n"
"\n";
static const char* MBShadowPostHLSL =
"cbuffer MBShadowUniform : register(b2)\n"
"{\n"
" float4 shadowUp;\n"
" float shadowId;\n"
"};\n"
2017-03-05 23:03:23 +00:00
"static float4 MBShadowPostFunc(in VertToFrag vtf, float4 colorIn)\n"
2017-03-05 07:57:12 +00:00
"{\n"
" float idTexel = extTex0.Sample(samp, vtf.extTcgs[0]).a;\n"
" float sphereTexel = extTex1.Sample(samp, vtf.extTcgs[1]).a;\n"
" float fadeTexel = extTex2.Sample(samp, vtf.extTcgs[2]).a;\n"
" float val = ((abs(idTexel - shadowId) < 0.001) ?\n"
" (dot(vtf.mvNorm.xyz, shadowUp.xyz) * shadowUp.w) : 0.0) *\n"
" sphereTexel * fadeTexel;\n"
" return float4(0.0, 0.0, 0.0, val);\n"
"}\n"
"\n";
2016-04-04 02:32:57 +00:00
hecl::Runtime::ShaderCacheExtensions
CModelShaders::GetShaderExtensionsHLSL(boo::IGraphicsDataFactory::Platform plat)
{
hecl::Runtime::ShaderCacheExtensions ext(plat);
2016-08-01 04:35:42 +00:00
/* Normal lit shading */
2017-01-30 06:08:44 +00:00
ext.registerExtensionSlot({LightingHLSL, "LightingFunc"}, {MainPostHLSL, "MainPostFunc"},
2017-01-30 04:16:20 +00:00
0, nullptr, 0, nullptr, hecl::Backend::BlendFactor::Original,
hecl::Backend::BlendFactor::Original, hecl::Backend::ZTest::Original,
2017-12-10 05:30:01 +00:00
hecl::Backend::CullMode::Backface, false, false, true);
2016-08-01 04:35:42 +00:00
/* Thermal Visor shading */
2017-01-30 06:08:44 +00:00
ext.registerExtensionSlot({}, {ThermalPostHLSL, "ThermalPostFunc"}, 0, nullptr,
2017-01-30 04:16:20 +00:00
1, ThermalTextures, hecl::Backend::BlendFactor::One,
hecl::Backend::BlendFactor::One, hecl::Backend::ZTest::Original,
2018-02-05 06:56:09 +00:00
hecl::Backend::CullMode::Backface, false, false, false, true);
2017-01-30 04:16:20 +00:00
/* Forced alpha shading */
2017-01-30 06:08:44 +00:00
ext.registerExtensionSlot({LightingHLSL, "LightingFunc"}, {MainPostHLSL, "MainPostFunc"},
2017-01-30 04:16:20 +00:00
0, nullptr, 0, nullptr, hecl::Backend::BlendFactor::SrcAlpha,
hecl::Backend::BlendFactor::InvSrcAlpha, hecl::Backend::ZTest::Original,
2017-12-10 05:30:01 +00:00
hecl::Backend::CullMode::Backface, false, false, true);
2017-01-30 04:16:20 +00:00
/* Forced additive shading */
2017-01-30 06:08:44 +00:00
ext.registerExtensionSlot({LightingHLSL, "LightingFunc"}, {MainPostHLSL, "MainPostFunc"},
0, nullptr, 0, nullptr, hecl::Backend::BlendFactor::SrcAlpha,
hecl::Backend::BlendFactor::One, hecl::Backend::ZTest::Original,
2017-12-10 05:30:01 +00:00
hecl::Backend::CullMode::Backface, true, false, true);
2016-08-01 04:35:42 +00:00
/* Solid color */
2017-03-05 07:57:12 +00:00
ext.registerExtensionSlot({}, {SolidPostHLSL, "SolidPostFunc"},
0, nullptr, 0, nullptr, hecl::Backend::BlendFactor::One,
hecl::Backend::BlendFactor::Zero, hecl::Backend::ZTest::LEqual,
2017-12-10 05:30:01 +00:00
hecl::Backend::CullMode::Backface, false, false, false);
2017-09-21 05:10:18 +00:00
/* Solid color additive */
ext.registerExtensionSlot({}, {SolidPostHLSL, "SolidPostFunc"},
0, nullptr, 0, nullptr, hecl::Backend::BlendFactor::SrcAlpha,
hecl::Backend::BlendFactor::One, hecl::Backend::ZTest::LEqual,
2017-12-10 05:30:01 +00:00
hecl::Backend::CullMode::Backface, true, false, true);
2017-09-21 05:10:18 +00:00
/* Alpha-only Solid color frontface cull, LEqual */
ext.registerExtensionSlot({}, {SolidPostHLSL, "SolidPostFunc"},
0, nullptr, 0, nullptr, hecl::Backend::BlendFactor::One,
hecl::Backend::BlendFactor::Zero, hecl::Backend::ZTest::LEqual,
2017-12-10 05:30:01 +00:00
hecl::Backend::CullMode::Frontface, false, true, false);
/* Alpha-only Solid color frontface cull, Always, No Z-write */
ext.registerExtensionSlot({}, {SolidPostHLSL, "SolidPostFunc"},
0, nullptr, 0, nullptr, hecl::Backend::BlendFactor::One,
hecl::Backend::BlendFactor::Zero, hecl::Backend::ZTest::None,
2017-12-10 05:30:01 +00:00
hecl::Backend::CullMode::Frontface, true, true, false);
/* Alpha-only Solid color backface cull, LEqual */
ext.registerExtensionSlot({}, {SolidPostHLSL, "SolidPostFunc"},
0, nullptr, 0, nullptr, hecl::Backend::BlendFactor::One,
hecl::Backend::BlendFactor::Zero, hecl::Backend::ZTest::LEqual,
2017-12-10 05:30:01 +00:00
hecl::Backend::CullMode::Backface, false, true, false);
/* Alpha-only Solid color backface cull, Greater, No Z-write */
ext.registerExtensionSlot({}, {SolidPostHLSL, "SolidPostFunc"},
0, nullptr, 0, nullptr, hecl::Backend::BlendFactor::One,
hecl::Backend::BlendFactor::Zero, hecl::Backend::ZTest::Greater,
2017-12-10 05:30:01 +00:00
hecl::Backend::CullMode::Backface, true, true, false);
2017-03-05 07:57:12 +00:00
2017-03-05 23:03:23 +00:00
/* MorphBall shadow shading */
2017-03-05 07:57:12 +00:00
ext.registerExtensionSlot({}, {MBShadowPostHLSL, "MBShadowPostFunc"},
0, nullptr, 3, BallFadeTextures,
hecl::Backend::BlendFactor::SrcAlpha,
hecl::Backend::BlendFactor::InvSrcAlpha,
hecl::Backend::ZTest::Equal,
2018-02-05 06:56:09 +00:00
hecl::Backend::CullMode::Backface, false, false, true, false, true);
2017-03-05 07:57:12 +00:00
/* World shadow shading (modified lighting) */
ext.registerExtensionSlot({LightingShadowHLSL, "LightingShadowFunc"}, {MainPostHLSL, "MainPostFunc"},
0, nullptr, 1, WorldShadowTextures, hecl::Backend::BlendFactor::Original,
hecl::Backend::BlendFactor::Original, hecl::Backend::ZTest::Original,
2017-12-10 05:30:01 +00:00
hecl::Backend::CullMode::Backface, false, false, true);
/* Forced alpha shading without culling */
ext.registerExtensionSlot({LightingHLSL, "LightingFunc"}, {MainPostHLSL, "MainPostFunc"},
0, nullptr, 0, nullptr, hecl::Backend::BlendFactor::SrcAlpha,
hecl::Backend::BlendFactor::InvSrcAlpha, hecl::Backend::ZTest::Original,
2018-01-06 06:50:42 +00:00
hecl::Backend::CullMode::None, false, false, true);
2017-12-10 05:30:01 +00:00
/* Forced additive shading without culling */
2018-01-06 06:50:42 +00:00
ext.registerExtensionSlot({LightingHLSL, "LightingFunc"}, {MainPostHLSL, "MainPostFunc"},
0, nullptr, 0, nullptr, hecl::Backend::BlendFactor::SrcAlpha,
hecl::Backend::BlendFactor::One, hecl::Backend::ZTest::Original,
hecl::Backend::CullMode::None, false, false, true);
2018-05-10 07:25:26 +00:00
/* Forced alpha shading without Z-write */
ext.registerExtensionSlot({LightingHLSL, "LightingFunc"}, {MainPostHLSL, "MainPostFunc"},
0, nullptr, 0, nullptr, hecl::Backend::BlendFactor::SrcAlpha,
hecl::Backend::BlendFactor::InvSrcAlpha, hecl::Backend::ZTest::Original,
hecl::Backend::CullMode::Original, true, false, true);
/* Forced additive shading without Z-write */
ext.registerExtensionSlot({LightingHLSL, "LightingFunc"}, {MainPostHLSL, "MainPostFunc"},
0, nullptr, 0, nullptr, hecl::Backend::BlendFactor::SrcAlpha,
hecl::Backend::BlendFactor::One, hecl::Backend::ZTest::Original,
hecl::Backend::CullMode::Original, true, false, true);
2018-01-06 06:50:42 +00:00
/* Forced alpha shading without culling or Z-write */
ext.registerExtensionSlot({LightingHLSL, "LightingFunc"}, {MainPostHLSL, "MainPostFunc"},
0, nullptr, 0, nullptr, hecl::Backend::BlendFactor::SrcAlpha,
hecl::Backend::BlendFactor::InvSrcAlpha, hecl::Backend::ZTest::Original,
hecl::Backend::CullMode::None, true, false, true);
/* Forced additive shading without culling or Z-write */
2017-12-10 05:30:01 +00:00
ext.registerExtensionSlot({LightingHLSL, "LightingFunc"}, {MainPostHLSL, "MainPostFunc"},
0, nullptr, 0, nullptr, hecl::Backend::BlendFactor::SrcAlpha,
hecl::Backend::BlendFactor::One, hecl::Backend::ZTest::Original,
hecl::Backend::CullMode::None, true, false, true);
2016-04-04 02:32:57 +00:00
return ext;
}
}