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"
|
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)\n"
|
|
|
|
"{\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"
|
|
|
|
" return saturate(ret);\n"
|
|
|
|
"}\n";
|
|
|
|
|
2016-08-08 18:54:05 +00:00
|
|
|
static const char* MainPostHLSL =
|
|
|
|
"float4 MainPostFunc(in VertToFrag vtf, float4 colorIn)\n"
|
|
|
|
"{\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"
|
|
|
|
" float4 mulColor;\n"
|
|
|
|
" float4 addColor;\n"
|
|
|
|
"};\n"
|
|
|
|
"float4 ThermalPostFunc(in VertToFrag vtf, float4 colorIn)\n"
|
|
|
|
"{\n"
|
2016-08-03 23:16:31 +00:00
|
|
|
" return float4(extTex7.Sample(samp, vtf.extTcgs[0]).rrr * mulColor.rgb + addColor.rgb, 1.0);\n"
|
2016-08-01 04:35:42 +00:00
|
|
|
"}\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 */
|
2016-08-08 18:54:05 +00:00
|
|
|
ext.registerExtensionSlot({LightingHLSL, "LightingFunc"}, {MainPostHLSL, "MainPostFunc"}, 0, nullptr, 0, nullptr,
|
2016-08-01 04:35:42 +00:00
|
|
|
hecl::Backend::BlendFactor::Original, hecl::Backend::BlendFactor::Original);
|
|
|
|
|
|
|
|
/* Thermal Visor shading */
|
|
|
|
ext.registerExtensionSlot({}, {ThermalPostHLSL, "ThermalPostFunc"}, 0, nullptr, 1, ThermalTextures,
|
|
|
|
hecl::Backend::BlendFactor::One, hecl::Backend::BlendFactor::One);
|
|
|
|
|
2016-04-04 02:32:57 +00:00
|
|
|
return ext;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|