Implement Metal lighting shader

This commit is contained in:
Jack Andersen 2016-04-03 20:16:03 -10:00
parent 408ce2ca8b
commit 9f0e9a808b
10 changed files with 57 additions and 13 deletions

View File

@ -118,7 +118,7 @@ struct OGLLineDataBindingFactory : CLineRendererShaders::IDataBindingFactory
boo::IGraphicsBuffer* uniforms[] = {renderer.m_uniformBuf};
renderer.m_shaderBind = ctx.newShaderDataBinding(pipeline, vtxFmt, renderer.m_vertBuf,
nullptr, nullptr, 1, uniforms,
nullptr, nullptr, 1, uniforms, nullptr,
texCount, textures);
}
};

View File

@ -117,7 +117,7 @@ struct MetalLineDataBindingFactory : CLineRendererShaders::IDataBindingFactory
boo::IGraphicsBuffer* uniforms[] = {renderer.m_uniformBuf};
renderer.m_shaderBind = ctx.newShaderDataBinding(pipeline, nullptr, renderer.m_vertBuf,
nullptr, nullptr, 1, uniforms,
nullptr, nullptr, 1, uniforms, nullptr,
texCount, textures);
}
};

View File

@ -4,6 +4,7 @@
#include "Graphics/CLight.hpp"
#include "hecl/HMDLMeta.hpp"
#include "hecl/Runtime.hpp"
#include "boo/graphicsdev/Metal.hpp"
#include "CModelShaders.hpp"
namespace urde
@ -117,6 +118,10 @@ void CBooModel::BuildGfxToken()
size_t thisOffs[3];
size_t thisSizes[3];
static const boo::PipelineStage stages[3] = {boo::PipelineStage::Vertex,
boo::PipelineStage::Vertex,
boo::PipelineStage::Fragment};
/* Enumerate surfaces and build data bindings */
for (const CBooSurface& surf : *x0_surfaces)
{
@ -164,7 +169,7 @@ void CBooModel::BuildGfxToken()
for (boo::IShaderPipeline* pipeline : pipelines)
extendeds.push_back(
ctx.newShaderDataBinding(pipeline, m_vtxFmt,
x8_vbo, nullptr, xc_ibo, 3, bufs,
x8_vbo, nullptr, xc_ibo, 3, bufs, stages,
thisOffs, thisSizes, mat.textureIdxs.size(), texs.data()));
}
return true;

View File

@ -3,10 +3,49 @@
namespace urde
{
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";
hecl::Runtime::ShaderCacheExtensions
CModelShaders::GetShaderExtensionsMetal(boo::IGraphicsDataFactory::Platform plat)
{
static const char* BlockNames[] = {"LightingUniform"};
hecl::Runtime::ShaderCacheExtensions ext(plat);
ext.registerExtensionSlot({LightingMetal, "LightingFunc"}, {}, 1, BlockNames);
return ext;
}

View File

@ -457,7 +457,7 @@ CMoviePlayer::CMoviePlayer(const char* path, float preLoadSeconds, bool loop, bo
{
boo::ITexture* texs[] = {set.Y[j], set.U, set.V};
set.binding[j] = ctx.newShaderDataBinding(YUVShaderPipeline, vtxFmt, m_vertBuf,
nullptr, nullptr, 1, bufs, 3, texs);
nullptr, nullptr, 1, bufs, nullptr, 3, texs);
}
}
else
@ -476,7 +476,7 @@ CMoviePlayer::CMoviePlayer(const char* path, float preLoadSeconds, bool loop, bo
boo::IGraphicsBuffer* bufs[] = {m_blockBuf};
boo::ITexture* texs[] = {set.Y[0], set.U, set.V};
set.binding[0] = ctx.newShaderDataBinding(YUVShaderPipeline, vtxFmt, m_vertBuf,
nullptr, nullptr, 1, bufs, 3, texs);
nullptr, nullptr, 1, bufs, nullptr, 3, texs);
}
if (xf4_25_hasAudio)
set.audioBuf.reset(new s16[x28_thpHead.maxAudioSamples * 2]);

View File

@ -95,7 +95,7 @@ void CTextRenderBuffer::CommitResources()
boo::ITexture* texs[] = {chs.m_font.GetObj()->GetTexture()->GetBooTexture()};
chs.m_dataBinding = ctx.newShaderDataBinding(g_TextShaderPipeline, vFmt,
nullptr, chs.m_instBuf, nullptr,
1, uniforms, 1, texs);
1, uniforms, nullptr, 1, texs);
}
for (BooImage& img : m_images)
@ -126,7 +126,7 @@ void CTextRenderBuffer::CommitResources()
boo::ITexture* texs[] = {tex->GetBooTexture()};
img.m_dataBinding.push_back(ctx.newShaderDataBinding(g_TextImageShaderPipeline, vFmt,
nullptr, img.m_instBuf, nullptr,
1, uniforms, 1, texs));
1, uniforms, nullptr, 1, texs));
}
}
return true;

View File

@ -259,11 +259,11 @@ struct OGLElementDataBindingFactory : CElementGenShaders::IDataBindingFactory
if (regPipeline)
gen.m_normalDataBind = ctx.newShaderDataBinding(regPipeline, vtxFmt, nullptr,
gen.m_instBuf, nullptr, 1, uniforms,
texCount, textures);
nullptr, texCount, textures);
if (redToAlphaPipeline)
gen.m_redToAlphaDataBind = ctx.newShaderDataBinding(redToAlphaPipeline, vtxFmt, nullptr,
gen.m_instBuf, nullptr, 1, uniforms,
texCount, textures);
nullptr, texCount, textures);
}
};

View File

@ -240,11 +240,11 @@ struct MetalElementDataBindingFactory : CElementGenShaders::IDataBindingFactory
if (regPipeline)
gen.m_normalDataBind = ctx.newShaderDataBinding(regPipeline, nullptr, nullptr,
gen.m_instBuf, nullptr, 1, uniforms,
texCount, textures);
nullptr, texCount, textures);
if (redToAlphaPipeline)
gen.m_redToAlphaDataBind = ctx.newShaderDataBinding(redToAlphaPipeline, nullptr, nullptr,
gen.m_instBuf, nullptr, 1, uniforms,
texCount, textures);
nullptr, texCount, textures);
}
};

2
hecl

@ -1 +1 @@
Subproject commit d5f9da3914d0ae1f4b4a4d8d0fddde160e406a6e
Subproject commit 6050696cf9752c9a239f16920c216356649d5ed3

@ -1 +1 @@
Subproject commit d49a33ec1b936052ff1b4d02586748d59a27c174
Subproject commit a8ae3714d2983d9faa9123151d71259c1fb9e111