HLSL lighting shaders

This commit is contained in:
Jack Andersen 2016-04-04 09:34:54 -10:00
parent c26a288a8c
commit 5c1d8492db
6 changed files with 61 additions and 24 deletions

View File

@ -103,7 +103,7 @@ struct HLSLLineDataBindingFactory : 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

@ -89,7 +89,6 @@ private:
/* urde addition: boo! */
boo::GraphicsDataToken m_gfxToken;
std::unique_ptr<u8[]> m_uniformData;
size_t m_uniformDataSize = 0;
boo::IGraphicsBufferD* m_uniformBuffer = nullptr;
std::vector<std::vector<boo::IShaderDataBinding*>> m_shaderDataBindings;

View File

@ -105,7 +105,6 @@ void CBooModel::BuildGfxToken()
/* Allocate resident buffer */
m_uniformDataSize = uniBufSize;
m_uniformData.reset(new u8[uniBufSize]);
m_uniformBuffer = ctx.newDynamicBuffer(boo::BufferUse::Uniform, uniBufSize, 1);
boo::IGraphicsBuffer* bufs[] = {m_uniformBuffer, m_uniformBuffer, m_uniformBuffer};
@ -407,7 +406,8 @@ void CBooModel::UVAnimationBuffer::Update(u8*& bufOut, const MaterialSet* matSet
void CBooModel::UpdateUniformData() const
{
u8* dataOut = m_uniformData.get();
u8* dataOut = reinterpret_cast<u8*>(m_uniformBuffer->map(m_uniformDataSize));
u8* dataCur = dataOut;
if (m_skinBankCount)
{
@ -416,47 +416,47 @@ void CBooModel::UpdateUniformData() const
{
for (size_t w=0 ; w<m_weightVecCount*4 ; ++w)
{
zeus::CMatrix4f& mv = reinterpret_cast<zeus::CMatrix4f&>(*dataOut);
zeus::CMatrix4f& mv = reinterpret_cast<zeus::CMatrix4f&>(*dataCur);
mv = CGraphics::g_GXModelView.toMatrix4f();
dataOut += sizeof(zeus::CMatrix4f);
dataCur += sizeof(zeus::CMatrix4f);
}
for (size_t w=0 ; w<m_weightVecCount*4 ; ++w)
{
zeus::CMatrix4f& mvinv = reinterpret_cast<zeus::CMatrix4f&>(*dataOut);
zeus::CMatrix4f& mvinv = reinterpret_cast<zeus::CMatrix4f&>(*dataCur);
mvinv = CGraphics::g_GXModelViewInvXpose.toMatrix4f();
dataOut += sizeof(zeus::CMatrix4f);
dataCur += sizeof(zeus::CMatrix4f);
}
zeus::CMatrix4f& proj = reinterpret_cast<zeus::CMatrix4f&>(*dataOut);
zeus::CMatrix4f& proj = reinterpret_cast<zeus::CMatrix4f&>(*dataCur);
proj = CGraphics::GetPerspectiveProjectionMatrix(true);
dataOut += sizeof(zeus::CMatrix4f);
dataCur += sizeof(zeus::CMatrix4f);
dataOut = m_uniformData.get() + ROUND_UP_256(dataOut - m_uniformData.get());
dataCur = dataOut + ROUND_UP_256(dataCur - dataOut);
}
}
else
{
/* Non-Skinned */
zeus::CMatrix4f& mv = reinterpret_cast<zeus::CMatrix4f&>(*dataOut);
zeus::CMatrix4f& mv = reinterpret_cast<zeus::CMatrix4f&>(*dataCur);
mv = CGraphics::g_GXModelView.toMatrix4f();
dataOut += sizeof(zeus::CMatrix4f);
dataCur += sizeof(zeus::CMatrix4f);
zeus::CMatrix4f& mvinv = reinterpret_cast<zeus::CMatrix4f&>(*dataOut);
zeus::CMatrix4f& mvinv = reinterpret_cast<zeus::CMatrix4f&>(*dataCur);
mvinv = CGraphics::g_GXModelViewInvXpose.toMatrix4f();
dataOut += sizeof(zeus::CMatrix4f);
dataCur += sizeof(zeus::CMatrix4f);
zeus::CMatrix4f& proj = reinterpret_cast<zeus::CMatrix4f&>(*dataOut);
zeus::CMatrix4f& proj = reinterpret_cast<zeus::CMatrix4f&>(*dataCur);
proj = CGraphics::GetPerspectiveProjectionMatrix(true);
dataOut += sizeof(zeus::CMatrix4f);
dataCur += sizeof(zeus::CMatrix4f);
dataOut = m_uniformData.get() + ROUND_UP_256(dataOut - m_uniformData.get());
dataCur = dataOut + ROUND_UP_256(dataCur - dataOut);
}
UVAnimationBuffer::Update(dataOut, x4_matSet);
UVAnimationBuffer::Update(dataCur, x4_matSet);
CModelShaders::LightingUniform& lightingOut = reinterpret_cast<CModelShaders::LightingUniform&>(*dataOut);
CModelShaders::LightingUniform& lightingOut = reinterpret_cast<CModelShaders::LightingUniform&>(*dataCur);
lightingOut = m_lightingData;
m_uniformBuffer->load(m_uniformData.get(), m_uniformDataSize);
m_uniformBuffer->unmap();
}
void CBooModel::DrawAlpha(const CModelFlags& flags) const

View File

@ -3,10 +3,48 @@
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;
}

View File

@ -219,11 +219,11 @@ struct D3DElementDataBindingFactory : 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 115b998e207dfaf095a987dbe0e21fb40e4f0e52
Subproject commit a50a7ac3685ebaf5bd5c7a5c31493710a8f8f125