Fix Skybox rendering regression

#2943
This commit is contained in:
Wojtek Figat
2024-09-24 23:01:13 +02:00
parent c8eed098ba
commit 2ad9c7f4d5
5 changed files with 31 additions and 0 deletions

View File

@@ -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>

View File

@@ -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;

View File

@@ -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)

View File

@@ -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

View File

@@ -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;