#include "CModelShaders.hpp" namespace urde { static const char* LightingHLSL = "struct Light\n" "{\n" " float4 pos;\n" " float4 dir;\n" " float4 color;\n" " float4 linAtt;\n" " float4 angAtt;\n" "};\n" "\n" "cbuffer LightingUniform : register(b2)\n" "{\n" " Light lights[" _XSTR(URDE_MAX_LIGHTS) "];\n" " float4 ambient;\n" "};\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"; hecl::Runtime::ShaderCacheExtensions CModelShaders::GetShaderExtensionsHLSL(boo::IGraphicsDataFactory::Platform plat) { hecl::Runtime::ShaderCacheExtensions ext(plat); ext.registerExtensionSlot({LightingHLSL, "LightingFunc"}, {}, 0, nullptr); return ext; } }