diff --git a/Runtime/Graphics/CLineRendererShadersHLSL.cpp b/Runtime/Graphics/CLineRendererShadersHLSL.cpp index 441cb2821..688bbbd41 100644 --- a/Runtime/Graphics/CLineRendererShadersHLSL.cpp +++ b/Runtime/Graphics/CLineRendererShadersHLSL.cpp @@ -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); } }; diff --git a/Runtime/Graphics/CModel.hpp b/Runtime/Graphics/CModel.hpp index fd3eb2712..142774113 100644 --- a/Runtime/Graphics/CModel.hpp +++ b/Runtime/Graphics/CModel.hpp @@ -89,7 +89,6 @@ private: /* urde addition: boo! */ boo::GraphicsDataToken m_gfxToken; - std::unique_ptr m_uniformData; size_t m_uniformDataSize = 0; boo::IGraphicsBufferD* m_uniformBuffer = nullptr; std::vector> m_shaderDataBindings; diff --git a/Runtime/Graphics/CModelBoo.cpp b/Runtime/Graphics/CModelBoo.cpp index 0ebec32cd..18fabd5d6 100644 --- a/Runtime/Graphics/CModelBoo.cpp +++ b/Runtime/Graphics/CModelBoo.cpp @@ -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(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(*dataOut); + zeus::CMatrix4f& mv = reinterpret_cast(*dataCur); mv = CGraphics::g_GXModelView.toMatrix4f(); - dataOut += sizeof(zeus::CMatrix4f); + dataCur += sizeof(zeus::CMatrix4f); } for (size_t w=0 ; w(*dataOut); + zeus::CMatrix4f& mvinv = reinterpret_cast(*dataCur); mvinv = CGraphics::g_GXModelViewInvXpose.toMatrix4f(); - dataOut += sizeof(zeus::CMatrix4f); + dataCur += sizeof(zeus::CMatrix4f); } - zeus::CMatrix4f& proj = reinterpret_cast(*dataOut); + zeus::CMatrix4f& proj = reinterpret_cast(*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(*dataOut); + zeus::CMatrix4f& mv = reinterpret_cast(*dataCur); mv = CGraphics::g_GXModelView.toMatrix4f(); - dataOut += sizeof(zeus::CMatrix4f); + dataCur += sizeof(zeus::CMatrix4f); - zeus::CMatrix4f& mvinv = reinterpret_cast(*dataOut); + zeus::CMatrix4f& mvinv = reinterpret_cast(*dataCur); mvinv = CGraphics::g_GXModelViewInvXpose.toMatrix4f(); - dataOut += sizeof(zeus::CMatrix4f); + dataCur += sizeof(zeus::CMatrix4f); - zeus::CMatrix4f& proj = reinterpret_cast(*dataOut); + zeus::CMatrix4f& proj = reinterpret_cast(*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(*dataOut); + CModelShaders::LightingUniform& lightingOut = reinterpret_cast(*dataCur); lightingOut = m_lightingData; - m_uniformBuffer->load(m_uniformData.get(), m_uniformDataSize); + m_uniformBuffer->unmap(); } void CBooModel::DrawAlpha(const CModelFlags& flags) const diff --git a/Runtime/Graphics/CModelShadersHLSL.cpp b/Runtime/Graphics/CModelShadersHLSL.cpp index 69a0a11e2..6f9829164 100644 --- a/Runtime/Graphics/CModelShadersHLSL.cpp +++ b/Runtime/Graphics/CModelShadersHLSL.cpp @@ -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; } diff --git a/Runtime/Particle/CElementGenShadersHLSL.cpp b/Runtime/Particle/CElementGenShadersHLSL.cpp index 104246fd1..beddc7663 100644 --- a/Runtime/Particle/CElementGenShadersHLSL.cpp +++ b/Runtime/Particle/CElementGenShadersHLSL.cpp @@ -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); } }; diff --git a/hecl b/hecl index 115b998e2..a50a7ac36 160000 --- a/hecl +++ b/hecl @@ -1 +1 @@ -Subproject commit 115b998e207dfaf095a987dbe0e21fb40e4f0e52 +Subproject commit a50a7ac3685ebaf5bd5c7a5c31493710a8f8f125