2016-04-04 02:32:57 +00:00
|
|
|
#include "CModelShaders.hpp"
|
|
|
|
|
|
|
|
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[];
|
|
|
|
|
|
|
|
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"
|
2016-08-08 18:54:05 +00:00
|
|
|
"struct Fog\n"
|
|
|
|
"{\n"
|
2018-06-07 04:43:26 +00:00
|
|
|
" int mode;\n"
|
2016-08-08 18:54:05 +00:00
|
|
|
" 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"
|
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"
|
2018-06-07 04:43:26 +00:00
|
|
|
" ret += lights[i].color * saturate(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 =
|
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"
|
2018-05-27 04:22:38 +00:00
|
|
|
" 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"
|
|
|
|
" return lerp(colorIn, fog.color, saturate(fogZ));\n"
|
2016-08-08 18:54:05 +00:00
|
|
|
"}\n"
|
2018-10-07 02:59:17 +00:00
|
|
|
"\n"sv;
|
2016-08-08 18:54:05 +00:00
|
|
|
|
2018-10-07 02:59:17 +00:00
|
|
|
static std::string_view ThermalPostHLSL =
|
2016-08-01 04:35:42 +00:00
|
|
|
"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"
|
2018-10-07 02:59:17 +00:00
|
|
|
"\n"sv;
|
2016-08-01 04:35:42 +00:00
|
|
|
|
2018-10-07 02:59:17 +00:00
|
|
|
static std::string_view SolidPostHLSL =
|
2017-03-05 07:57:12 +00:00
|
|
|
"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"
|
2018-10-07 02:59:17 +00:00
|
|
|
"\n"sv;
|
2017-03-05 07:57:12 +00:00
|
|
|
|
2018-10-07 02:59:17 +00:00
|
|
|
static std::string_view MBShadowPostHLSL =
|
2017-03-05 07:57:12 +00:00
|
|
|
"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"
|
2018-10-07 02:59:17 +00:00
|
|
|
"\n"sv;
|
2017-03-05 07:57:12 +00:00
|
|
|
|
2018-10-07 02:59:17 +00:00
|
|
|
const hecl::Backend::Function ExtensionLightingFuncsHLSL[] =
|
2016-04-04 02:32:57 +00:00
|
|
|
{
|
2018-10-07 02:59:17 +00:00
|
|
|
{},
|
|
|
|
{LightingHLSL, "LightingFunc"},
|
|
|
|
{},
|
|
|
|
{LightingHLSL, "LightingFunc"},
|
|
|
|
{LightingHLSL, "LightingFunc"},
|
|
|
|
{},
|
|
|
|
{},
|
|
|
|
{},
|
|
|
|
{},
|
|
|
|
{},
|
|
|
|
{},
|
|
|
|
{},
|
|
|
|
{LightingShadowHLSL, "LightingShadowFunc"},
|
|
|
|
{LightingHLSL, "LightingFunc"},
|
|
|
|
{LightingHLSL, "LightingFunc"},
|
|
|
|
{LightingHLSL, "LightingFunc"},
|
|
|
|
{LightingHLSL, "LightingFunc"},
|
|
|
|
{LightingHLSL, "LightingFunc"},
|
|
|
|
{LightingHLSL, "LightingFunc"},
|
|
|
|
{LightingHLSL, "LightingFunc"}
|
|
|
|
};
|
|
|
|
|
|
|
|
const hecl::Backend::Function ExtensionPostFuncsHLSL[] =
|
|
|
|
{
|
|
|
|
{},
|
|
|
|
{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"},
|
|
|
|
};
|
2016-04-04 02:32:57 +00:00
|
|
|
|
|
|
|
}
|