2016-04-04 02:32:57 +00:00
|
|
|
#include "CModelShaders.hpp"
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
namespace urde {
|
2018-10-07 02:59:17 +00:00
|
|
|
using namespace std::literals;
|
2016-04-04 02:32:57 +00:00
|
|
|
|
2018-10-07 02:59:17 +00:00
|
|
|
extern const hecl::Backend::Function ExtensionLightingFuncsMetal[];
|
|
|
|
extern const hecl::Backend::Function ExtensionPostFuncsMetal[];
|
|
|
|
|
2019-01-05 08:34:09 +00:00
|
|
|
#define FOG_STRUCT_METAL \
|
|
|
|
"struct Fog\n" \
|
|
|
|
"{\n" \
|
|
|
|
" float4 color;\n" \
|
2019-03-03 23:04:18 +00:00
|
|
|
" float A;\n" \
|
|
|
|
" float B;\n" \
|
|
|
|
" float C;\n" \
|
|
|
|
" int mode;\n" \
|
2019-01-05 08:34:09 +00:00
|
|
|
"};\n"
|
|
|
|
|
|
|
|
#define FOG_ALGORITHM_METAL \
|
2019-03-04 04:45:22 +00:00
|
|
|
" float fogZ;\n" \
|
|
|
|
" float fogF = saturate((lu.fog.A / (lu.fog.B - (1.0 - vtf.mvpPos.z))) - lu.fog.C);\n" \
|
2019-01-05 08:34:09 +00:00
|
|
|
" switch (lu.fog.mode)\n" \
|
|
|
|
" {\n" \
|
|
|
|
" case 2:\n" \
|
2019-03-04 04:45:22 +00:00
|
|
|
" fogZ = fogF;\n" \
|
2019-01-05 08:34:09 +00:00
|
|
|
" break;\n" \
|
|
|
|
" case 4:\n" \
|
2019-03-04 04:45:22 +00:00
|
|
|
" fogZ = 1.0 - exp2(-8.0 * fogF);\n" \
|
2019-01-05 08:34:09 +00:00
|
|
|
" break;\n" \
|
|
|
|
" case 5:\n" \
|
2019-03-04 04:45:22 +00:00
|
|
|
" fogZ = 1.0 - exp2(-8.0 * fogF * fogF);\n" \
|
2019-01-05 08:34:09 +00:00
|
|
|
" break;\n" \
|
|
|
|
" case 6:\n" \
|
2019-03-04 04:45:22 +00:00
|
|
|
" fogZ = exp2(-8.0 * (1.0 - fogF));\n" \
|
2019-01-05 08:34:09 +00:00
|
|
|
" break;\n" \
|
|
|
|
" case 7:\n" \
|
2019-03-04 04:45:22 +00:00
|
|
|
" fogF = 1.0 - fogF;\n" \
|
|
|
|
" fogZ = exp2(-8.0 * fogF * fogF);\n" \
|
2019-01-05 08:34:09 +00:00
|
|
|
" break;\n" \
|
|
|
|
" default:\n" \
|
|
|
|
" fogZ = 0.0;\n" \
|
|
|
|
" break;\n" \
|
|
|
|
" }\n" \
|
|
|
|
"#ifdef BLEND_DST_ONE\n" \
|
|
|
|
" return float4(mix(colorIn, float4(0.0), saturate(fogZ)).rgb, colorIn.a);\n" \
|
|
|
|
"#else\n" \
|
2019-03-04 04:45:22 +00:00
|
|
|
" return float4(mix(colorIn, lu.fog.color, saturate(fogZ)).rgb, colorIn.a);\n" \
|
2019-01-05 08:34:09 +00:00
|
|
|
"#endif\n"
|
|
|
|
|
2018-10-07 02:59:17 +00:00
|
|
|
static std::string_view LightingMetal =
|
2016-04-04 06:16:03 +00:00
|
|
|
"struct Light\n"
|
|
|
|
"{\n"
|
|
|
|
" float4 pos;\n"
|
|
|
|
" float4 dir;\n"
|
|
|
|
" float4 color;\n"
|
|
|
|
" float4 linAtt;\n"
|
|
|
|
" float4 angAtt;\n"
|
|
|
|
"};\n"
|
2019-01-05 08:34:09 +00:00
|
|
|
FOG_STRUCT_METAL
|
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"
|
2019-02-08 07:56:54 +00:00
|
|
|
" float4 addColor;\n"
|
2016-08-08 19:07:30 +00:00
|
|
|
" Fog fog;\n"
|
2016-04-04 06:16:03 +00:00
|
|
|
"};\n"
|
|
|
|
"\n"
|
2018-06-07 04:43:26 +00:00
|
|
|
"static float4 LightingFunc(constant LightingUniform& lu, float3 mvPosIn, float3 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"
|
2018-06-07 04:43:26 +00:00
|
|
|
" float3 delta = mvPosIn - lu.lights[i].pos.xyz;\n"
|
2016-04-04 06:16:03 +00:00
|
|
|
" 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"
|
2019-01-23 07:52:19 +00:00
|
|
|
" ret += lu.lights[i].color * angAtt * att * saturate(dot(normalize(-delta), mvNormIn));\n"
|
2016-04-04 06:16:03 +00:00
|
|
|
" }\n"
|
|
|
|
" \n"
|
2019-01-29 20:14:34 +00:00
|
|
|
" return saturate(ret);\n"
|
2018-10-07 02:59:17 +00:00
|
|
|
"}\n"sv;
|
2016-04-04 06:16:03 +00:00
|
|
|
|
2018-10-07 02:59:17 +00:00
|
|
|
static std::string_view LightingShadowMetal =
|
2017-10-01 04:26:46 +00:00
|
|
|
"struct Light\n"
|
|
|
|
"{\n"
|
|
|
|
" float4 pos;\n"
|
|
|
|
" float4 dir;\n"
|
|
|
|
" float4 color;\n"
|
|
|
|
" float4 linAtt;\n"
|
|
|
|
" float4 angAtt;\n"
|
|
|
|
"};\n"
|
2019-03-04 04:45:22 +00:00
|
|
|
FOG_STRUCT_METAL
|
2017-10-01 04:26:46 +00:00
|
|
|
"\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"
|
2019-02-08 07:56:54 +00:00
|
|
|
" float4 addColor;\n"
|
2017-10-01 04:26:46 +00:00
|
|
|
" Fog fog;\n"
|
|
|
|
"};\n"
|
|
|
|
"\n"
|
2018-06-07 04:43:26 +00:00
|
|
|
"static float4 EXTLightingShadowFunc(constant LightingUniform& lu, float3 mvPosIn, float3 mvNormIn,\n"
|
2018-01-07 05:19:49 +00:00
|
|
|
" thread VertToFrag& vtf, sampler samp, sampler clampSamp, texture2d<float> extTex7)\n"
|
2017-10-01 04:26:46 +00:00
|
|
|
"{\n"
|
|
|
|
" float4 ret = lu.ambient;\n"
|
|
|
|
" \n"
|
2018-06-07 04:43:26 +00:00
|
|
|
" float3 delta = mvPosIn - lu.lights[0].pos.xyz;\n"
|
2017-10-01 04:26:46 +00:00
|
|
|
" float dist = length(delta);\n"
|
2017-10-16 05:26:50 +00:00
|
|
|
" float angDot = saturate(dot(normalize(delta), lu.lights[0].dir.xyz));\n"
|
|
|
|
" float att = 1.0 / (lu.lights[0].linAtt[2] * dist * dist +\n"
|
|
|
|
" lu.lights[0].linAtt[1] * dist +\n"
|
|
|
|
" lu.lights[0].linAtt[0]);\n"
|
|
|
|
" float angAtt = lu.lights[0].angAtt[2] * angDot * angDot +\n"
|
|
|
|
" lu.lights[0].angAtt[1] * angDot +\n"
|
|
|
|
" lu.lights[0].angAtt[0];\n"
|
2018-06-07 04:43:26 +00:00
|
|
|
" ret += lu.lights[0].color * saturate(angAtt) * att * saturate(dot(normalize(-delta), mvNormIn)) *\n"
|
2018-01-16 06:42:28 +00:00
|
|
|
" extTex7.sample(clampSamp, vtf.extTcgs0).r;\n"
|
2017-10-01 04:26:46 +00:00
|
|
|
" \n"
|
|
|
|
" for (int i=1 ; i<" _XSTR(URDE_MAX_LIGHTS) " ; ++i)\n"
|
|
|
|
" {\n"
|
2018-06-07 04:43:26 +00:00
|
|
|
" float3 delta = mvPosIn - lu.lights[i].pos.xyz;\n"
|
2017-10-01 04:26:46 +00:00
|
|
|
" 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"
|
2018-06-07 04:43:26 +00:00
|
|
|
" ret += lu.lights[i].color * saturate(angAtt) * att * saturate(dot(normalize(-delta), mvNormIn));\n"
|
2017-10-01 04:26:46 +00:00
|
|
|
" }\n"
|
|
|
|
" \n"
|
2018-05-08 02:11:07 +00:00
|
|
|
" return ret;\n"
|
2018-10-07 02:59:17 +00:00
|
|
|
"}\n"sv;
|
2017-10-01 04:26:46 +00:00
|
|
|
|
2018-10-07 02:59:17 +00:00
|
|
|
static std::string_view MainPostMetal =
|
2018-12-08 05:30:43 +00:00
|
|
|
"float4 MainPostFunc(thread VertToFrag& vtf, constant LightingUniform& lu, float4 colorIn)\n"
|
2019-01-05 08:34:09 +00:00
|
|
|
"{\n" FOG_ALGORITHM_METAL
|
2018-12-08 05:30:43 +00:00
|
|
|
"}\n"
|
|
|
|
"\n"sv;
|
2016-08-08 19:07:30 +00:00
|
|
|
|
2018-10-07 02:59:17 +00:00
|
|
|
static std::string_view ThermalPostMetal =
|
2018-12-08 05:30:43 +00:00
|
|
|
"struct ThermalUniform\n"
|
|
|
|
"{\n"
|
|
|
|
" float4 tmulColor;\n"
|
2019-02-08 07:56:54 +00:00
|
|
|
" float4 taddColor;\n"
|
2018-12-08 05:30:43 +00:00
|
|
|
"};\n"
|
|
|
|
"static float4 EXTThermalPostFunc(thread VertToFrag& vtf, constant ThermalUniform& lu,\n"
|
|
|
|
" sampler samp, sampler clampSamp, texture2d<float> extTex7, float4 colorIn)\n"
|
|
|
|
"{\n"
|
2019-02-24 07:15:54 +00:00
|
|
|
" return extTex7.sample(samp, vtf.extTcgs0).rrrr * lu.tmulColor + lu.taddColor;\n"
|
2018-12-08 05:30:43 +00:00
|
|
|
"}\n"
|
|
|
|
"\n"sv;
|
2016-07-31 20:52:04 +00:00
|
|
|
|
2018-10-07 02:59:17 +00:00
|
|
|
static std::string_view SolidPostMetal =
|
2018-12-08 05:30:43 +00:00
|
|
|
"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"sv;
|
2017-03-05 07:57:12 +00:00
|
|
|
|
2018-10-07 02:59:17 +00:00
|
|
|
static std::string_view MBShadowPostMetal =
|
2018-12-08 05:30:43 +00:00
|
|
|
"struct MBShadowUniform\n"
|
|
|
|
"{\n"
|
|
|
|
" float4 shadowUp;\n"
|
|
|
|
" float shadowId;\n"
|
|
|
|
"};\n"
|
2019-01-05 08:34:09 +00:00
|
|
|
"static float4 EXTMBShadowPostFunc(thread VertToFrag& vtf, constant MBShadowUniform& su, sampler samp,\n"
|
|
|
|
" sampler clampSamp, texture2d<float> extTex0, texture2d<float> extTex1,\n"
|
|
|
|
" texture2d<float> extTex2, float4 colorIn)\n"
|
2018-12-08 05:30:43 +00:00
|
|
|
"{\n"
|
|
|
|
" 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"
|
|
|
|
" 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"sv;
|
2018-10-07 02:59:17 +00:00
|
|
|
|
2019-01-05 08:34:09 +00:00
|
|
|
static std::string_view DisintegratePostMetal = FOG_STRUCT_METAL
|
|
|
|
"struct DisintegrateUniform\n"
|
|
|
|
"{\n"
|
2019-02-08 07:56:54 +00:00
|
|
|
" float4 daddColor;\n"
|
2019-01-05 08:34:09 +00:00
|
|
|
" Fog fog;\n"
|
|
|
|
"};\n"
|
|
|
|
"static float4 EXTDisintegratePostFunc(thread VertToFrag& vtf, constant DisintegrateUniform& lu, sampler samp,\n"
|
|
|
|
" sampler clampSamp, texture2d<float> extTex7, float4 colorIn)\n"
|
|
|
|
"{\n"
|
2019-02-04 00:01:44 +00:00
|
|
|
" float4 texel0 = extTex7.sample(samp, vtf.extTcgs0);\n"
|
|
|
|
" float4 texel1 = extTex7.sample(samp, vtf.extTcgs1);\n"
|
2019-01-05 08:34:09 +00:00
|
|
|
" colorIn = mix(float4(0.0), texel1, texel0);\n"
|
2019-02-08 07:56:54 +00:00
|
|
|
" colorIn.rgb += lu.daddColor.rgb;\n" FOG_ALGORITHM_METAL
|
2019-01-05 08:34:09 +00:00
|
|
|
"}\n"
|
|
|
|
"\n"sv;
|
|
|
|
|
2019-02-24 07:15:54 +00:00
|
|
|
static std::string_view ThermalColdPostMetal =
|
2019-03-04 04:45:22 +00:00
|
|
|
"static float4 ThermalColdPostFunc(thread VertToFrag& vtf, float4 colorIn)\n"
|
2019-02-24 07:15:54 +00:00
|
|
|
"{\n"
|
|
|
|
" return colorIn * float4(0.75, 0.75, 0.75, 0.75);\n"
|
|
|
|
"}\n"
|
|
|
|
"\n"sv;
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
const hecl::Backend::Function ExtensionLightingFuncsMetal[] = {{},
|
|
|
|
{LightingMetal, "LightingFunc"},
|
|
|
|
{},
|
|
|
|
{LightingMetal, "LightingFunc"},
|
|
|
|
{LightingMetal, "LightingFunc"},
|
|
|
|
{},
|
|
|
|
{},
|
|
|
|
{},
|
|
|
|
{},
|
|
|
|
{},
|
|
|
|
{},
|
|
|
|
{},
|
|
|
|
{LightingShadowMetal, "EXTLightingShadowFunc"},
|
|
|
|
{LightingMetal, "LightingFunc"},
|
|
|
|
{LightingMetal, "LightingFunc"},
|
|
|
|
{LightingMetal, "LightingFunc"},
|
|
|
|
{LightingMetal, "LightingFunc"},
|
|
|
|
{LightingMetal, "LightingFunc"},
|
|
|
|
{LightingMetal, "LightingFunc"},
|
2019-01-05 08:34:09 +00:00
|
|
|
{LightingMetal, "LightingFunc"},
|
|
|
|
{},
|
2019-02-24 07:15:54 +00:00
|
|
|
{LightingMetal, "LightingFunc"},
|
2019-02-25 08:14:59 +00:00
|
|
|
{},
|
|
|
|
{LightingMetal, "LightingFunc"},};
|
2018-10-07 02:59:17 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
const hecl::Backend::Function ExtensionPostFuncsMetal[] = {
|
2018-10-07 02:59:17 +00:00
|
|
|
{},
|
|
|
|
{MainPostMetal, "MainPostFunc"},
|
2018-10-16 03:17:02 +00:00
|
|
|
{ThermalPostMetal, "EXTThermalPostFunc"},
|
2018-10-07 02:59:17 +00:00
|
|
|
{MainPostMetal, "MainPostFunc"},
|
|
|
|
{MainPostMetal, "MainPostFunc"},
|
|
|
|
{SolidPostMetal, "SolidPostFunc"},
|
|
|
|
{SolidPostMetal, "SolidPostFunc"},
|
|
|
|
{SolidPostMetal, "SolidPostFunc"},
|
|
|
|
{SolidPostMetal, "SolidPostFunc"},
|
|
|
|
{SolidPostMetal, "SolidPostFunc"},
|
|
|
|
{SolidPostMetal, "SolidPostFunc"},
|
2018-10-16 03:17:02 +00:00
|
|
|
{MBShadowPostMetal, "EXTMBShadowPostFunc"},
|
2018-10-07 02:59:17 +00:00
|
|
|
{MainPostMetal, "MainPostFunc"},
|
|
|
|
{MainPostMetal, "MainPostFunc"},
|
|
|
|
{MainPostMetal, "MainPostFunc"},
|
|
|
|
{MainPostMetal, "MainPostFunc"},
|
|
|
|
{MainPostMetal, "MainPostFunc"},
|
|
|
|
{MainPostMetal, "MainPostFunc"},
|
|
|
|
{MainPostMetal, "MainPostFunc"},
|
|
|
|
{MainPostMetal, "MainPostFunc"},
|
2019-01-05 08:34:09 +00:00
|
|
|
{DisintegratePostMetal, "EXTDisintegratePostFunc"},
|
|
|
|
{MainPostMetal, "MainPostFunc"},
|
2019-02-24 07:15:54 +00:00
|
|
|
{ThermalColdPostMetal, "ThermalColdPostFunc"},
|
2019-02-25 08:14:59 +00:00
|
|
|
{MainPostMetal, "MainPostFunc"},
|
2018-10-07 02:59:17 +00:00
|
|
|
};
|
2017-03-05 07:57:12 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
} // namespace urde
|