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 ExtensionLightingFuncsHLSL[];
|
|
|
|
extern const hecl::Backend::Function ExtensionPostFuncsHLSL[];
|
|
|
|
|
2019-01-05 08:34:09 +00:00
|
|
|
#define FOG_STRUCT_HLSL \
|
|
|
|
"struct Fog\n" \
|
|
|
|
"{\n" \
|
|
|
|
" int mode;\n" \
|
|
|
|
" float4 color;\n" \
|
|
|
|
" float rangeScale;\n" \
|
|
|
|
" float start;\n" \
|
|
|
|
"};\n"
|
|
|
|
|
|
|
|
#define FOG_ALGORITHM_HLSL \
|
|
|
|
" float fogZ, temp;\n" \
|
|
|
|
" switch (fog.mode)\n" \
|
|
|
|
" {\n" \
|
|
|
|
" case 2:\n" \
|
|
|
|
" fogZ = (-vtf.mvPos.z - fog.start) * fog.rangeScale;\n" \
|
|
|
|
" break;\n" \
|
|
|
|
" case 4:\n" \
|
|
|
|
" fogZ = 1.0 - exp2(-8.0 * (-vtf.mvPos.z - fog.start) * fog.rangeScale);\n" \
|
|
|
|
" break;\n" \
|
|
|
|
" case 5:\n" \
|
|
|
|
" temp = (-vtf.mvPos.z - fog.start) * fog.rangeScale;\n" \
|
|
|
|
" fogZ = 1.0 - exp2(-8.0 * temp * temp);\n" \
|
|
|
|
" break;\n" \
|
|
|
|
" case 6:\n" \
|
|
|
|
" fogZ = exp2(-8.0 * (fog.start + vtf.mvPos.z) * fog.rangeScale);\n" \
|
|
|
|
" break;\n" \
|
|
|
|
" case 7:\n" \
|
|
|
|
" temp = (fog.start + vtf.mvPos.z) * fog.rangeScale;\n" \
|
|
|
|
" fogZ = exp2(-8.0 * temp * temp);\n" \
|
|
|
|
" break;\n" \
|
|
|
|
" default:\n" \
|
|
|
|
" fogZ = 0.0;\n" \
|
|
|
|
" break;\n" \
|
|
|
|
" }\n" \
|
|
|
|
"#ifdef BLEND_DST_ONE\n" \
|
|
|
|
" return float4(lerp(colorIn, float4(0.0, 0.0, 0.0, 0.0), saturate(fogZ)).rgb, colorIn.a);\n" \
|
|
|
|
"#else\n" \
|
|
|
|
" return float4(lerp(colorIn, fog.color, saturate(fogZ)).rgb, colorIn.a);\n" \
|
|
|
|
"#endif\n"
|
|
|
|
|
2018-10-07 02:59:17 +00:00
|
|
|
static std::string_view LightingHLSL =
|
2016-04-04 19:34:54 +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_HLSL
|
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"
|
2018-06-07 04:43:26 +00:00
|
|
|
"static float4 LightingFunc(float3 mvPosIn, float3 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"
|
2018-06-07 04:43:26 +00:00
|
|
|
" float3 delta = mvPosIn - lights[i].pos.xyz;\n"
|
2016-04-04 19:34:54 +00:00
|
|
|
" 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"
|
2019-01-23 07:52:19 +00:00
|
|
|
" ret += lights[i].color * angAtt * att * saturate(dot(normalize(-delta), mvNormIn));\n"
|
2016-04-04 19:34:54 +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;
|
2016-04-04 19:34:54 +00:00
|
|
|
|
2018-10-07 02:59:17 +00:00
|
|
|
static std::string_view LightingShadowHLSL =
|
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"
|
|
|
|
"struct Fog\n"
|
|
|
|
"{\n"
|
2018-06-07 04:43:26 +00:00
|
|
|
" int mode;\n"
|
2017-10-01 04:26:46 +00:00
|
|
|
" 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"
|
2018-06-07 04:43:26 +00:00
|
|
|
"static float4 LightingShadowFunc(float3 mvPosIn, float3 mvNormIn, in VertToFrag vtf)\n"
|
2017-10-01 04:26:46 +00:00
|
|
|
"{\n"
|
|
|
|
" float4 ret = ambient;\n"
|
|
|
|
" \n"
|
2018-06-07 04:43:26 +00:00
|
|
|
" float3 delta = mvPosIn - 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), 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"
|
2018-06-07 04:43:26 +00:00
|
|
|
" ret += lights[0].color * saturate(angAtt) * att * saturate(dot(normalize(-delta), mvNormIn)) *\n"
|
2017-10-17 05:51:53 +00:00
|
|
|
" extTex7.Sample(clampSamp, vtf.extTcgs[0]).r;\n"
|
2017-10-01 04:26:46 +00:00
|
|
|
" \n"
|
2017-10-01 04:31:04 +00:00
|
|
|
" for (int i=1 ; i<" _XSTR(URDE_MAX_LIGHTS) " ; ++i)\n"
|
2017-10-01 04:26:46 +00:00
|
|
|
" {\n"
|
2018-06-07 04:43:26 +00:00
|
|
|
" float3 delta = mvPosIn - lights[i].pos.xyz;\n"
|
2017-10-01 04:26:46 +00:00
|
|
|
" 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"
|
2018-06-07 04:43:26 +00:00
|
|
|
" ret += 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 MainPostHLSL =
|
2018-12-08 05:30:43 +00:00
|
|
|
"static float4 MainPostFunc(in VertToFrag vtf, float4 colorIn)\n"
|
2019-01-05 08:34:09 +00:00
|
|
|
"{\n" FOG_ALGORITHM_HLSL
|
2018-12-08 05:30:43 +00:00
|
|
|
"}\n"
|
|
|
|
"\n"sv;
|
2016-08-08 18:54:05 +00:00
|
|
|
|
2018-10-07 02:59:17 +00:00
|
|
|
static std::string_view ThermalPostHLSL =
|
2018-12-08 05:30:43 +00:00
|
|
|
"cbuffer ThermalUniform : register(b2)\n"
|
|
|
|
"{\n"
|
|
|
|
" float4 tmulColor;\n"
|
|
|
|
" float4 addColor;\n"
|
|
|
|
"};\n"
|
|
|
|
"static float4 ThermalPostFunc(in VertToFrag vtf, float4 colorIn)\n"
|
|
|
|
"{\n"
|
|
|
|
" return float4(extTex7.Sample(samp, vtf.extTcgs[0]).rrr * tmulColor.rgb + addColor.rgb, tmulColor.a + "
|
|
|
|
"addColor.a);\n"
|
|
|
|
"}\n"
|
|
|
|
"\n"sv;
|
2016-08-01 04:35:42 +00:00
|
|
|
|
2018-10-07 02:59:17 +00:00
|
|
|
static std::string_view SolidPostHLSL =
|
2018-12-08 05:30:43 +00:00
|
|
|
"cbuffer SolidUniform : register(b2)\n"
|
|
|
|
"{\n"
|
|
|
|
" float4 solidColor;\n"
|
|
|
|
"};\n"
|
|
|
|
"static float4 SolidPostFunc(in VertToFrag vtf, float4 colorIn)\n"
|
|
|
|
"{\n"
|
|
|
|
" return 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 MBShadowPostHLSL =
|
2018-12-08 05:30:43 +00:00
|
|
|
"cbuffer MBShadowUniform : register(b2)\n"
|
|
|
|
"{\n"
|
|
|
|
" float4 shadowUp;\n"
|
|
|
|
" float shadowId;\n"
|
|
|
|
"};\n"
|
|
|
|
"static float4 MBShadowPostFunc(in VertToFrag vtf, float4 colorIn)\n"
|
|
|
|
"{\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"sv;
|
2017-03-05 07:57:12 +00:00
|
|
|
|
2019-01-05 08:34:09 +00:00
|
|
|
static std::string_view DisintegratePostHLSL = FOG_STRUCT_HLSL
|
|
|
|
"cbuffer DisintegrateUniform : register(b2)\n"
|
|
|
|
"{\n"
|
|
|
|
" float4 addColor;\n"
|
|
|
|
" Fog fog;\n"
|
|
|
|
"};\n"
|
|
|
|
"float4 DisintegratePostFunc(float4 colorIn)\n"
|
|
|
|
"{\n"
|
|
|
|
" float4 texel0 = extTex7.Sample(samp, vtf.extTcgs[0]);\n"
|
|
|
|
" float4 texel1 = extTex7.Sample(samp, vtf.extTcgs[1]);\n"
|
|
|
|
" colorIn = mix(float4(0.0), texel1, texel0);\n"
|
|
|
|
" colorIn.rgb += addColor.rgb;\n" FOG_ALGORITHM_HLSL
|
|
|
|
"}\n"
|
|
|
|
"\n"sv;
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
const hecl::Backend::Function ExtensionLightingFuncsHLSL[] = {{},
|
|
|
|
{LightingHLSL, "LightingFunc"},
|
|
|
|
{},
|
|
|
|
{LightingHLSL, "LightingFunc"},
|
|
|
|
{LightingHLSL, "LightingFunc"},
|
|
|
|
{},
|
|
|
|
{},
|
|
|
|
{},
|
|
|
|
{},
|
|
|
|
{},
|
|
|
|
{},
|
|
|
|
{},
|
|
|
|
{LightingShadowHLSL, "LightingShadowFunc"},
|
|
|
|
{LightingHLSL, "LightingFunc"},
|
|
|
|
{LightingHLSL, "LightingFunc"},
|
|
|
|
{LightingHLSL, "LightingFunc"},
|
|
|
|
{LightingHLSL, "LightingFunc"},
|
|
|
|
{LightingHLSL, "LightingFunc"},
|
|
|
|
{LightingHLSL, "LightingFunc"},
|
2019-01-05 08:34:09 +00:00
|
|
|
{LightingHLSL, "LightingFunc"},
|
|
|
|
{},
|
2018-12-08 05:30:43 +00:00
|
|
|
{LightingHLSL, "LightingFunc"}};
|
2018-10-07 02:59:17 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
const hecl::Backend::Function ExtensionPostFuncsHLSL[] = {
|
2018-10-07 02:59:17 +00:00
|
|
|
{},
|
|
|
|
{MainPostHLSL, "MainPostFunc"},
|
|
|
|
{ThermalPostHLSL, "ThermalPostFunc"},
|
|
|
|
{MainPostHLSL, "MainPostFunc"},
|
|
|
|
{MainPostHLSL, "MainPostFunc"},
|
|
|
|
{SolidPostHLSL, "SolidPostFunc"},
|
|
|
|
{SolidPostHLSL, "SolidPostFunc"},
|
|
|
|
{SolidPostHLSL, "SolidPostFunc"},
|
|
|
|
{SolidPostHLSL, "SolidPostFunc"},
|
|
|
|
{SolidPostHLSL, "SolidPostFunc"},
|
|
|
|
{SolidPostHLSL, "SolidPostFunc"},
|
|
|
|
{MBShadowPostHLSL, "MBShadowPostFunc"},
|
|
|
|
{MainPostHLSL, "MainPostFunc"},
|
|
|
|
{MainPostHLSL, "MainPostFunc"},
|
|
|
|
{MainPostHLSL, "MainPostFunc"},
|
|
|
|
{MainPostHLSL, "MainPostFunc"},
|
|
|
|
{MainPostHLSL, "MainPostFunc"},
|
|
|
|
{MainPostHLSL, "MainPostFunc"},
|
|
|
|
{MainPostHLSL, "MainPostFunc"},
|
|
|
|
{MainPostHLSL, "MainPostFunc"},
|
2019-01-05 08:34:09 +00:00
|
|
|
{DisintegratePostHLSL, "DisintegratePostFunc"},
|
|
|
|
{MainPostHLSL, "MainPostFunc"},
|
2018-10-07 02:59:17 +00:00
|
|
|
};
|
2016-04-04 02:32:57 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
} // namespace urde
|