2016-04-04 02:32:57 +00:00
|
|
|
#include "CModelShaders.hpp"
|
|
|
|
|
|
|
|
namespace urde
|
|
|
|
{
|
|
|
|
|
2016-04-04 06:16:03 +00:00
|
|
|
static const char* LightingMetal =
|
|
|
|
"struct Light\n"
|
|
|
|
"{\n"
|
|
|
|
" float4 pos;\n"
|
|
|
|
" float4 dir;\n"
|
|
|
|
" float4 color;\n"
|
|
|
|
" float4 linAtt;\n"
|
|
|
|
" float4 angAtt;\n"
|
|
|
|
"};\n"
|
2016-08-08 19:07:30 +00:00
|
|
|
"struct Fog\n"
|
|
|
|
"{\n"
|
|
|
|
" float4 color;\n"
|
|
|
|
" float rangeScale;\n"
|
|
|
|
" float start;\n"
|
|
|
|
"};\n"
|
2016-04-04 06:16:03 +00:00
|
|
|
"\n"
|
|
|
|
"struct LightingUniform\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 19:07:30 +00:00
|
|
|
" Fog fog;\n"
|
2016-04-04 06:16:03 +00:00
|
|
|
"};\n"
|
|
|
|
"\n"
|
2017-10-01 04:26:46 +00:00
|
|
|
"static float4 LightingFunc(constant LightingUniform& lu, float4 mvPosIn, float4 mvNormIn, thread VertToFrag& vtf)\n"
|
2016-04-04 06:16:03 +00:00
|
|
|
"{\n"
|
|
|
|
" float4 ret = lu.ambient;\n"
|
|
|
|
" \n"
|
|
|
|
" for (int i=0 ; i<" _XSTR(URDE_MAX_LIGHTS) " ; ++i)\n"
|
|
|
|
" {\n"
|
|
|
|
" float3 delta = mvPosIn.xyz - lu.lights[i].pos.xyz;\n"
|
|
|
|
" float dist = length(delta);\n"
|
|
|
|
" float angDot = saturate(dot(normalize(delta), lu.lights[i].dir.xyz));\n"
|
|
|
|
" float att = 1.0 / (lu.lights[i].linAtt[2] * dist * dist +\n"
|
|
|
|
" lu.lights[i].linAtt[1] * dist +\n"
|
|
|
|
" lu.lights[i].linAtt[0]);\n"
|
|
|
|
" float angAtt = lu.lights[i].angAtt[2] * angDot * angDot +\n"
|
|
|
|
" lu.lights[i].angAtt[1] * angDot +\n"
|
|
|
|
" lu.lights[i].angAtt[0];\n"
|
|
|
|
" ret += lu.lights[i].color * saturate(angAtt) * att * saturate(dot(normalize(-delta), mvNormIn.xyz));\n"
|
|
|
|
" }\n"
|
|
|
|
" \n"
|
|
|
|
" return saturate(ret);\n"
|
|
|
|
"}\n";
|
|
|
|
|
2017-10-01 04:26:46 +00:00
|
|
|
static const char* LightingShadowMetal =
|
|
|
|
"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"
|
|
|
|
"struct LightingUniform\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 EXTLightingShadowFunc(constant LightingUniform& lu, float4 mvPosIn, float4 mvNormIn,\n"
|
|
|
|
" thread VertToFrag& vtf, texture2d<float> extTex0)\n"
|
|
|
|
"{\n"
|
|
|
|
" float4 ret = lu.ambient;\n"
|
|
|
|
" \n"
|
|
|
|
" float3 delta = mvPosIn.xyz - lu.lights[i].pos.xyz;\n"
|
|
|
|
" float dist = length(delta);\n"
|
|
|
|
" float angDot = saturate(dot(normalize(delta), lu.lights[i].dir.xyz));\n"
|
|
|
|
" float att = 1.0 / (lu.lights[i].linAtt[2] * dist * dist +\n"
|
|
|
|
" lu.lights[i].linAtt[1] * dist +\n"
|
|
|
|
" lu.lights[i].linAtt[0]);\n"
|
|
|
|
" float angAtt = lu.lights[i].angAtt[2] * angDot * angDot +\n"
|
|
|
|
" lu.lights[i].angAtt[1] * angDot +\n"
|
|
|
|
" lu.lights[i].angAtt[0];\n"
|
|
|
|
" ret += lu.lights[i].color * saturate(angAtt) * att * saturate(dot(normalize(-delta), mvNormIn.xyz)) *\n"
|
|
|
|
" extTex0.sample(clampSamp, vtf.extTcgs0);\n"
|
|
|
|
" \n"
|
|
|
|
" for (int i=1 ; i<" _XSTR(URDE_MAX_LIGHTS) " ; ++i)\n"
|
|
|
|
" {\n"
|
|
|
|
" float3 delta = mvPosIn.xyz - lu.lights[i].pos.xyz;\n"
|
|
|
|
" float dist = length(delta);\n"
|
|
|
|
" float angDot = saturate(dot(normalize(delta), lu.lights[i].dir.xyz));\n"
|
|
|
|
" float att = 1.0 / (lu.lights[i].linAtt[2] * dist * dist +\n"
|
|
|
|
" lu.lights[i].linAtt[1] * dist +\n"
|
|
|
|
" lu.lights[i].linAtt[0]);\n"
|
|
|
|
" float angAtt = lu.lights[i].angAtt[2] * angDot * angDot +\n"
|
|
|
|
" lu.lights[i].angAtt[1] * angDot +\n"
|
|
|
|
" lu.lights[i].angAtt[0];\n"
|
|
|
|
" ret += lu.lights[i].color * saturate(angAtt) * att * saturate(dot(normalize(-delta), mvNormIn.xyz));\n"
|
|
|
|
" }\n"
|
|
|
|
" \n"
|
|
|
|
" return saturate(ret);\n"
|
|
|
|
"}\n";
|
|
|
|
|
2016-08-08 19:07:30 +00:00
|
|
|
static const char* MainPostMetal =
|
|
|
|
"float4 MainPostFunc(thread VertToFrag& vtf, constant LightingUniform& lu, float4 colorIn)\n"
|
|
|
|
"{\n"
|
|
|
|
" float fogZ = (-vtf.mvPos.z - lu.fog.start) * lu.fog.rangeScale;\n"
|
|
|
|
" return mix(lu.fog.color, colorIn, saturate(exp2(-8.0 * fogZ)));\n"
|
|
|
|
"}\n"
|
|
|
|
"\n";
|
|
|
|
|
2016-07-31 20:52:04 +00:00
|
|
|
static const char* ThermalPostMetal =
|
|
|
|
"struct ThermalUniform\n"
|
|
|
|
"{\n"
|
2017-02-10 09:09:06 +00:00
|
|
|
" float4 tmulColor;\n"
|
2016-07-31 20:52:04 +00:00
|
|
|
" float4 addColor;\n"
|
|
|
|
"};\n"
|
2017-03-05 23:03:23 +00:00
|
|
|
"static float4 ThermalPostFunc(thread VertToFrag& vtf, constant ThermalUniform& lu, texture2d<float> extTex7, float4 colorIn)\n"
|
2016-07-31 20:52:04 +00:00
|
|
|
"{\n"
|
2017-03-05 23:03:23 +00:00
|
|
|
" return float4(extTex7.sample(samp, vtf.extTcgs0).rrr * lu.tmulColor.rgb + lu.addColor.rgb, 1.0);\n"
|
2016-07-31 20:52:04 +00:00
|
|
|
"}\n"
|
|
|
|
"\n";
|
|
|
|
|
2017-03-05 07:57:12 +00:00
|
|
|
static const char* SolidPostMetal =
|
|
|
|
"struct SolidUniform\n"
|
|
|
|
"{\n"
|
|
|
|
" float4 solidColor;\n"
|
|
|
|
"};\n"
|
|
|
|
"static float4 SolidPostFunc(thread VertToFrag& vtf, constant SolidUniform& lu, float4 colorIn)\n"
|
|
|
|
"{\n"
|
|
|
|
" return lu.solidColor;\n"
|
|
|
|
"}\n"
|
|
|
|
"\n";
|
|
|
|
|
|
|
|
static const char* MBShadowPostMetal =
|
2017-03-05 23:35:50 +00:00
|
|
|
"struct MBShadowUniform\n"
|
2017-03-05 07:57:12 +00:00
|
|
|
"{\n"
|
2017-03-05 23:35:50 +00:00
|
|
|
" float4 shadowUp;\n"
|
2017-03-05 07:57:12 +00:00
|
|
|
" float shadowId;\n"
|
|
|
|
"};\n"
|
|
|
|
"static float4 MBShadowPostFunc(thread VertToFrag& vtf, constant MBShadowUniform& su,\n"
|
2017-03-05 23:03:23 +00:00
|
|
|
" texture2d<float> extTex0, texture2d<float> extTex1, texture2d<float> extTex2, float4 colorIn)\n"
|
2017-03-05 07:57:12 +00:00
|
|
|
"{\n"
|
2017-03-05 23:03:23 +00:00
|
|
|
" float idTexel = extTex0.sample(samp, vtf.extTcgs0).a;\n"
|
|
|
|
" float sphereTexel = extTex1.sample(samp, vtf.extTcgs1).a;\n"
|
|
|
|
" float fadeTexel = extTex2.sample(samp, vtf.extTcgs2).a;\n"
|
2017-03-05 07:57:12 +00:00
|
|
|
" float val = ((fabs(idTexel - su.shadowId) < 0.001) ?\n"
|
|
|
|
" (dot(vtf.mvNorm.xyz, su.shadowUp.xyz) * su.shadowUp.w) : 0.0) *\n"
|
|
|
|
" sphereTexel * fadeTexel;\n"
|
|
|
|
" return float4(0.0, 0.0, 0.0, val);\n"
|
|
|
|
"}\n"
|
|
|
|
"\n";
|
|
|
|
|
2016-04-15 03:26:01 +00:00
|
|
|
static const char* BlockNames[] = {"LightingUniform"};
|
2016-07-31 20:52:04 +00:00
|
|
|
static const char* ThermalBlockNames[] = {"ThermalUniform"};
|
2017-03-05 07:57:12 +00:00
|
|
|
static const char* SolidBlockNames[] = {"SolidUniform"};
|
|
|
|
static const char* MBShadowBlockNames[] = {"MBShadowUniform"};
|
2016-04-15 03:26:01 +00:00
|
|
|
|
2016-04-04 02:32:57 +00:00
|
|
|
hecl::Runtime::ShaderCacheExtensions
|
|
|
|
CModelShaders::GetShaderExtensionsMetal(boo::IGraphicsDataFactory::Platform plat)
|
|
|
|
{
|
|
|
|
hecl::Runtime::ShaderCacheExtensions ext(plat);
|
2016-07-31 20:52:04 +00:00
|
|
|
|
|
|
|
/* Normal lit shading */
|
2017-01-30 04:16:20 +00:00
|
|
|
ext.registerExtensionSlot({LightingMetal, "LightingFunc"}, {MainPostMetal, "MainPostFunc"},
|
|
|
|
1, BlockNames, 0, nullptr, hecl::Backend::BlendFactor::Original,
|
2017-03-14 07:03:58 +00:00
|
|
|
hecl::Backend::BlendFactor::Original, hecl::Backend::ZTest::Original,
|
|
|
|
false, false, false, true);
|
2016-07-31 20:52:04 +00:00
|
|
|
|
|
|
|
/* Thermal Visor shading */
|
2017-01-30 04:16:20 +00:00
|
|
|
ext.registerExtensionSlot({}, {ThermalPostMetal, "ThermalPostFunc"}, 1, ThermalBlockNames,
|
|
|
|
1, ThermalTextures, hecl::Backend::BlendFactor::One,
|
2017-03-14 07:03:58 +00:00
|
|
|
hecl::Backend::BlendFactor::One, hecl::Backend::ZTest::Original,
|
|
|
|
false, false, false, true);
|
2017-01-30 04:16:20 +00:00
|
|
|
|
|
|
|
/* Forced alpha shading */
|
|
|
|
ext.registerExtensionSlot({LightingMetal, "LightingFunc"}, {MainPostMetal, "MainPostFunc"},
|
|
|
|
1, BlockNames, 0, nullptr, hecl::Backend::BlendFactor::SrcAlpha,
|
2017-03-14 07:03:58 +00:00
|
|
|
hecl::Backend::BlendFactor::InvSrcAlpha, hecl::Backend::ZTest::Original,
|
|
|
|
false, false, false, true);
|
2017-01-30 04:16:20 +00:00
|
|
|
|
|
|
|
/* Forced additive shading */
|
|
|
|
ext.registerExtensionSlot({LightingMetal, "LightingFunc"}, {MainPostMetal, "MainPostFunc"},
|
|
|
|
1, BlockNames, 0, nullptr, hecl::Backend::BlendFactor::One,
|
2017-03-14 07:03:58 +00:00
|
|
|
hecl::Backend::BlendFactor::One, hecl::Backend::ZTest::Original,
|
|
|
|
false, false, false, true);
|
2016-07-31 20:52:04 +00:00
|
|
|
|
2017-03-14 07:03:58 +00:00
|
|
|
/* Solid color */
|
2017-03-05 07:57:12 +00:00
|
|
|
ext.registerExtensionSlot({}, {SolidPostMetal, "SolidPostFunc"},
|
|
|
|
1, SolidBlockNames, 0, nullptr, hecl::Backend::BlendFactor::One,
|
2017-03-14 07:03:58 +00:00
|
|
|
hecl::Backend::BlendFactor::Zero, hecl::Backend::ZTest::LEqual,
|
|
|
|
false, false, false, false);
|
|
|
|
|
2017-09-21 05:10:18 +00:00
|
|
|
/* Solid color additive */
|
|
|
|
ext.registerExtensionSlot({}, {SolidPostMetal, "SolidPostFunc"},
|
|
|
|
1, SolidBlockNames, 0, nullptr, hecl::Backend::BlendFactor::SrcAlpha,
|
|
|
|
hecl::Backend::BlendFactor::One, hecl::Backend::ZTest::LEqual,
|
|
|
|
false, true, false, true);
|
|
|
|
|
2017-03-14 07:03:58 +00:00
|
|
|
/* Alpha-only Solid color frontface cull, LEqual */
|
|
|
|
ext.registerExtensionSlot({}, {SolidPostMetal, "SolidPostFunc"},
|
|
|
|
1, SolidBlockNames, 0, nullptr, hecl::Backend::BlendFactor::Zero,
|
|
|
|
hecl::Backend::BlendFactor::One, hecl::Backend::ZTest::LEqual,
|
|
|
|
true, false, true, false);
|
|
|
|
|
|
|
|
/* Alpha-only Solid color frontface cull, Always, No Z-write */
|
|
|
|
ext.registerExtensionSlot({}, {SolidPostMetal, "SolidPostFunc"},
|
|
|
|
1, SolidBlockNames, 0, nullptr, hecl::Backend::BlendFactor::Zero,
|
|
|
|
hecl::Backend::BlendFactor::One, hecl::Backend::ZTest::None,
|
|
|
|
true, true, true, false);
|
|
|
|
|
|
|
|
/* Alpha-only Solid color backface cull, LEqual */
|
|
|
|
ext.registerExtensionSlot({}, {SolidPostMetal, "SolidPostFunc"},
|
|
|
|
1, SolidBlockNames, 0, nullptr, hecl::Backend::BlendFactor::Zero,
|
|
|
|
hecl::Backend::BlendFactor::One, hecl::Backend::ZTest::LEqual,
|
|
|
|
false, false, true, false);
|
|
|
|
|
|
|
|
/* Alpha-only Solid color backface cull, Greater, No Z-write */
|
|
|
|
ext.registerExtensionSlot({}, {SolidPostMetal, "SolidPostFunc"},
|
|
|
|
1, SolidBlockNames, 0, nullptr, hecl::Backend::BlendFactor::Zero,
|
|
|
|
hecl::Backend::BlendFactor::One, hecl::Backend::ZTest::Greater,
|
|
|
|
false, true, true, false);
|
2017-03-05 07:57:12 +00:00
|
|
|
|
|
|
|
/* MorphBall shadow shading */
|
|
|
|
ext.registerExtensionSlot({}, {MBShadowPostMetal, "MBShadowPostFunc"},
|
|
|
|
1, MBShadowBlockNames, 3, BallFadeTextures,
|
|
|
|
hecl::Backend::BlendFactor::SrcAlpha,
|
2017-03-14 07:03:58 +00:00
|
|
|
hecl::Backend::BlendFactor::InvSrcAlpha,
|
|
|
|
hecl::Backend::ZTest::Equal,
|
|
|
|
false, false, false, true);
|
2017-03-05 07:57:12 +00:00
|
|
|
|
2017-10-01 04:26:46 +00:00
|
|
|
/* World shadow shading (modified lighting) */
|
|
|
|
ext.registerExtensionSlot({LightingShadowMetal, "EXTLightingShadowFunc"}, {MainPostMetal, "MainPostFunc"},
|
|
|
|
1, BlockNames, 1, WorldShadowTextures, hecl::Backend::BlendFactor::Original,
|
|
|
|
hecl::Backend::BlendFactor::Original, hecl::Backend::ZTest::Original,
|
|
|
|
false, false, false, true);
|
|
|
|
|
2016-04-04 02:32:57 +00:00
|
|
|
return ext;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|