metaforce/Runtime/Graphics/CModelShadersMetal.cpp

53 lines
1.6 KiB
C++
Raw Normal View History

2016-04-04 02:32:57 +00:00
#include "CModelShaders.hpp"
namespace urde
{
2016-04-04 06:16:03 +00:00
static const char* LightingMetal =
"struct Light\n"
"{\n"
" float4 pos;\n"
" float4 dir;\n"
" float4 color;\n"
" float4 linAtt;\n"
" float4 angAtt;\n"
"};\n"
"\n"
"struct LightingUniform\n"
"{\n"
" Light lights[" _XSTR(URDE_MAX_LIGHTS) "];\n"
" float4 ambient;\n"
"};\n"
"\n"
"static float4 LightingFunc(constant LightingUniform& lu, float4 mvPosIn, float4 mvNormIn)\n"
"{\n"
" float4 ret = lu.ambient;\n"
" \n"
" for (int i=0 ; i<" _XSTR(URDE_MAX_LIGHTS) " ; ++i)\n"
" {\n"
" float3 delta = mvPosIn.xyz - lu.lights[i].pos.xyz;\n"
" 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"
" ret += lu.lights[i].color * saturate(angAtt) * att * saturate(dot(normalize(-delta), mvNormIn.xyz));\n"
" }\n"
" \n"
" return saturate(ret);\n"
"}\n";
2016-04-04 02:32:57 +00:00
hecl::Runtime::ShaderCacheExtensions
CModelShaders::GetShaderExtensionsMetal(boo::IGraphicsDataFactory::Platform plat)
{
2016-04-04 06:16:03 +00:00
static const char* BlockNames[] = {"LightingUniform"};
2016-04-04 02:32:57 +00:00
hecl::Runtime::ShaderCacheExtensions ext(plat);
2016-04-04 06:16:03 +00:00
ext.registerExtensionSlot({LightingMetal, "LightingFunc"}, {}, 1, BlockNames);
2016-04-04 02:32:57 +00:00
return ext;
}
}