@@ -166,6 +166,8 @@ public:
|
||||
|
||||
// Binds the shared per-view constant buffer at slot 1 (see ViewData in MaterialCommon.hlsl)
|
||||
void BindViewData();
|
||||
// Binds the shared per-draw constant buffer at slot 2 (see DrawData in MaterialCommon.hlsl)
|
||||
void BindDrawData();
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -84,6 +84,27 @@ void IMaterial::BindParameters::BindViewData()
|
||||
GPUContext->BindCB(1, PerViewConstants);
|
||||
}
|
||||
|
||||
void IMaterial::BindParameters::BindDrawData()
|
||||
{
|
||||
// Write draw call to the object buffer
|
||||
auto& objectBuffer = RenderContext.List->TempObjectBuffer;
|
||||
objectBuffer.Clear();
|
||||
ShaderObjectData objData;
|
||||
objData.Store(*DrawCall);
|
||||
objectBuffer.Write(objData);
|
||||
objectBuffer.Flush(GPUContext);
|
||||
ObjectBuffer = objectBuffer.GetBuffer()->View();
|
||||
|
||||
// Setup data
|
||||
MaterialShaderDataPerDraw perDraw;
|
||||
perDraw.DrawPadding = Float3::Zero;
|
||||
perDraw.DrawObjectIndex = 0;
|
||||
|
||||
// Update constants
|
||||
GPUContext->UpdateCB(PerDrawConstants, &perDraw);
|
||||
GPUContext->BindCB(2, PerDrawConstants);
|
||||
}
|
||||
|
||||
GPUPipelineState* MaterialShader::PipelineStateCache::InitPS(CullMode mode, bool wireframe)
|
||||
{
|
||||
Desc.CullMode = mode;
|
||||
|
||||
@@ -111,6 +111,7 @@ void Skybox::ApplySky(GPUContext* context, RenderContext& renderContext, const M
|
||||
drawCall.PerInstanceRandom = GetPerInstanceRandom();
|
||||
MaterialBase::BindParameters bindParams(context, renderContext, drawCall);
|
||||
bindParams.BindViewData();
|
||||
bindParams.BindDrawData();
|
||||
|
||||
// Check if use custom material
|
||||
if (CustomMaterial)
|
||||
|
||||
@@ -443,6 +443,7 @@ RenderList::RenderList(const SpawnParams& params)
|
||||
, Fog(nullptr)
|
||||
, Blendable(32)
|
||||
, ObjectBuffer(0, PixelFormat::R32G32B32A32_Float, false, TEXT("Object Bufffer"))
|
||||
, TempObjectBuffer(0, PixelFormat::R32G32B32A32_Float, false, TEXT("Object Bufffer"))
|
||||
, _instanceBuffer(0, sizeof(ShaderObjectDrawInstanceData), TEXT("Instance Buffer"))
|
||||
{
|
||||
}
|
||||
@@ -477,6 +478,7 @@ void RenderList::Clear()
|
||||
Blendable.Clear();
|
||||
_instanceBuffer.Clear();
|
||||
ObjectBuffer.Clear();
|
||||
TempObjectBuffer.Clear();
|
||||
}
|
||||
|
||||
struct PackedSortKey
|
||||
|
||||
@@ -419,6 +419,11 @@ public:
|
||||
/// </summary>
|
||||
DynamicTypedBuffer ObjectBuffer;
|
||||
|
||||
/// <summary>
|
||||
/// Temporary objects buffer that contains ShaderObjectData for each DrawCall reused during scene rendering (eg. by skybox).
|
||||
/// </summary>
|
||||
DynamicTypedBuffer TempObjectBuffer;
|
||||
|
||||
private:
|
||||
DynamicVertexBuffer _instanceBuffer;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user