fixed hair particle system raytracing; other improvements;
This commit is contained in:
@@ -70,12 +70,15 @@ void wiEmittedParticle::CreateSelfBuffers()
|
||||
bd.Stride = sizeof(Particle);
|
||||
bd.Size = bd.Stride * MAX_PARTICLES;
|
||||
device->CreateBuffer(&bd, nullptr, &particleBuffer);
|
||||
device->SetName(&particleBuffer, "particleBuffer");
|
||||
|
||||
// Alive index lists (double buffered):
|
||||
bd.Stride = sizeof(uint32_t);
|
||||
bd.Size = bd.Stride * MAX_PARTICLES;
|
||||
device->CreateBuffer(&bd, nullptr, &aliveList[0]);
|
||||
device->SetName(&aliveList[0], "aliveList[0]");
|
||||
device->CreateBuffer(&bd, nullptr, &aliveList[1]);
|
||||
device->SetName(&aliveList[1], "aliveList[1]");
|
||||
|
||||
// Dead index list:
|
||||
std::vector<uint32_t> indices(MAX_PARTICLES);
|
||||
@@ -84,6 +87,7 @@ void wiEmittedParticle::CreateSelfBuffers()
|
||||
indices[i] = i;
|
||||
}
|
||||
device->CreateBuffer(&bd, indices.data(), &deadList);
|
||||
device->SetName(&deadList, "deadList");
|
||||
}
|
||||
|
||||
if (IsSorted() && distanceBuffer.desc.Size < MAX_PARTICLES * sizeof(float))
|
||||
@@ -98,6 +102,7 @@ void wiEmittedParticle::CreateSelfBuffers()
|
||||
std::vector<float> distances(MAX_PARTICLES);
|
||||
std::fill(distances.begin(), distances.end(), 0.0f);
|
||||
device->CreateBuffer(&bd, distances.data(), &distanceBuffer);
|
||||
device->SetName(&distanceBuffer, "distanceBuffer");
|
||||
}
|
||||
|
||||
if (IsSPHEnabled())
|
||||
@@ -113,11 +118,13 @@ void wiEmittedParticle::CreateSelfBuffers()
|
||||
bd.Stride = sizeof(float); // really, it is uint, but sorting is performing comparisons on floats, so whateva
|
||||
bd.Size = bd.Stride * MAX_PARTICLES;
|
||||
device->CreateBuffer(&bd, nullptr, &sphPartitionCellIndices);
|
||||
device->SetName(&sphPartitionCellIndices, "sphPartitionCellIndices");
|
||||
|
||||
// Density buffer (for SPH simulation):
|
||||
bd.Stride = sizeof(float);
|
||||
bd.Size = bd.Stride * MAX_PARTICLES;
|
||||
device->CreateBuffer(&bd, nullptr, &densityBuffer);
|
||||
device->SetName(&densityBuffer, "densityBuffer");
|
||||
}
|
||||
|
||||
if (sphPartitionCellOffsets.desc.Size < SPH_PARTITION_BUCKET_COUNT * sizeof(uint32_t))
|
||||
@@ -126,6 +133,7 @@ void wiEmittedParticle::CreateSelfBuffers()
|
||||
bd.Stride = sizeof(uint32_t);
|
||||
bd.Size = bd.Stride * SPH_PARTITION_BUCKET_COUNT;
|
||||
device->CreateBuffer(&bd, nullptr, &sphPartitionCellOffsets);
|
||||
device->SetName(&sphPartitionCellOffsets, "sphPartitionCellOffsets");
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -152,6 +160,7 @@ void wiEmittedParticle::CreateSelfBuffers()
|
||||
bd.Stride = sizeof(counters);
|
||||
bd.MiscFlags = RESOURCE_MISC_BUFFER_RAW;
|
||||
device->CreateBuffer(&bd, &counters, &counterBuffer);
|
||||
device->SetName(&counterBuffer, "counterBuffer");
|
||||
}
|
||||
|
||||
if(!indirectBuffers.IsValid())
|
||||
@@ -167,6 +176,7 @@ void wiEmittedParticle::CreateSelfBuffers()
|
||||
sizeof(wiGraphics::IndirectDispatchArgs) +
|
||||
sizeof(wiGraphics::IndirectDrawArgsInstanced);
|
||||
device->CreateBuffer(&bd, nullptr, &indirectBuffers);
|
||||
device->SetName(&indirectBuffers, "indirectBuffers");
|
||||
|
||||
// Constant buffer:
|
||||
bd.Usage = USAGE_DEFAULT;
|
||||
@@ -174,6 +184,7 @@ void wiEmittedParticle::CreateSelfBuffers()
|
||||
bd.BindFlags = BIND_CONSTANT_BUFFER;
|
||||
bd.MiscFlags = RESOURCE_MISC_NONE;
|
||||
device->CreateBuffer(&bd, nullptr, &constantBuffer);
|
||||
device->SetName(&constantBuffer, "constantBuffer");
|
||||
|
||||
// Debug information CPU-readback buffer:
|
||||
{
|
||||
@@ -184,6 +195,7 @@ void wiEmittedParticle::CreateSelfBuffers()
|
||||
for (int i = 0; i < arraysize(statisticsReadbackBuffer); ++i)
|
||||
{
|
||||
device->CreateBuffer(&debugBufDesc, nullptr, &statisticsReadbackBuffer[i]);
|
||||
device->SetName(&statisticsReadbackBuffer[i], "statisticsReadbackBuffer");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ void wiHairParticle::UpdateCPU(const TransformComponent& transform, const MeshCo
|
||||
|
||||
GraphicsDevice* device = wiRenderer::GetDevice();
|
||||
|
||||
if (_flags & REBUILD_BUFFERS || !cb.IsValid() || (strandCount * segmentCount) != simulationBuffer.GetDesc().Size / sizeof(PatchSimulationData))
|
||||
if (_flags & REBUILD_BUFFERS || !constantBuffer.IsValid() || (strandCount * segmentCount) != simulationBuffer.GetDesc().Size / sizeof(PatchSimulationData))
|
||||
{
|
||||
_flags &= ~REBUILD_BUFFERS;
|
||||
regenerate_frame = true;
|
||||
@@ -111,7 +111,8 @@ void wiHairParticle::UpdateCPU(const TransformComponent& transform, const MeshCo
|
||||
bd.Size = sizeof(HairParticleCB);
|
||||
bd.BindFlags = BIND_CONSTANT_BUFFER;
|
||||
bd.MiscFlags = RESOURCE_MISC_NONE;
|
||||
device->CreateBuffer(&bd, nullptr, &cb);
|
||||
device->CreateBuffer(&bd, nullptr, &constantBuffer);
|
||||
device->SetName(&constantBuffer, "constantBuffer");
|
||||
|
||||
if (vertex_lengths.size() != mesh.vertex_positions.size())
|
||||
{
|
||||
@@ -221,7 +222,7 @@ void wiHairParticle::UpdateGPU(uint32_t instanceIndex, uint32_t materialIndex, c
|
||||
}
|
||||
|
||||
GraphicsDevice* device = wiRenderer::GetDevice();
|
||||
device->EventBegin("HairParticle - UpdateRenderData", cmd);
|
||||
device->EventBegin("HairParticle - UpdateGPU", cmd);
|
||||
|
||||
TextureDesc desc;
|
||||
if (material.textures[MaterialComponent::BASECOLORMAP].resource != nullptr)
|
||||
@@ -250,7 +251,7 @@ void wiHairParticle::UpdateGPU(uint32_t instanceIndex, uint32_t materialIndex, c
|
||||
hcb.xHairAspect = (float)std::max(1u, desc.Width) / (float)std::max(1u, desc.Height);
|
||||
hcb.xHairLayerMask = layerMask;
|
||||
hcb.xHairInstanceIndex = instanceIndex;
|
||||
device->UpdateBuffer(&cb, &hcb, cmd);
|
||||
device->UpdateBuffer(&constantBuffer, &hcb, cmd);
|
||||
|
||||
ShaderMeshSubset subset;
|
||||
subset.init();
|
||||
@@ -260,7 +261,7 @@ void wiHairParticle::UpdateGPU(uint32_t instanceIndex, uint32_t materialIndex, c
|
||||
|
||||
{
|
||||
GPUBarrier barriers[] = {
|
||||
GPUBarrier::Buffer(&cb, RESOURCE_STATE_COPY_DST, RESOURCE_STATE_CONSTANT_BUFFER),
|
||||
GPUBarrier::Buffer(&constantBuffer, RESOURCE_STATE_COPY_DST, RESOURCE_STATE_CONSTANT_BUFFER),
|
||||
GPUBarrier::Buffer(&subsetBuffer, RESOURCE_STATE_COPY_DST, RESOURCE_STATE_SHADER_RESOURCE),
|
||||
};
|
||||
device->Barrier(barriers, arraysize(barriers), cmd);
|
||||
@@ -269,7 +270,7 @@ void wiHairParticle::UpdateGPU(uint32_t instanceIndex, uint32_t materialIndex, c
|
||||
// Simulate:
|
||||
{
|
||||
device->BindComputeShader(&cs_simulate, cmd);
|
||||
device->BindConstantBuffer(&cb, CB_GETBINDSLOT(HairParticleCB), cmd);
|
||||
device->BindConstantBuffer(&constantBuffer, CB_GETBINDSLOT(HairParticleCB), cmd);
|
||||
|
||||
const GPUResource* uavs[] = {
|
||||
&simulationBuffer,
|
||||
@@ -309,7 +310,7 @@ void wiHairParticle::UpdateGPU(uint32_t instanceIndex, uint32_t materialIndex, c
|
||||
device->Dispatch(1, 1, 1, cmd);
|
||||
|
||||
GPUBarrier barriers[] = {
|
||||
GPUBarrier::Memory(),
|
||||
GPUBarrier::Memory(&indirectBuffer),
|
||||
GPUBarrier::Buffer(&indirectBuffer, RESOURCE_STATE_UNORDERED_ACCESS, RESOURCE_STATE_INDIRECT_ARGUMENT),
|
||||
GPUBarrier::Buffer(&vertexBuffer_POS[0], RESOURCE_STATE_UNORDERED_ACCESS, RESOURCE_STATE_SHADER_RESOURCE),
|
||||
GPUBarrier::Buffer(&vertexBuffer_TEX, RESOURCE_STATE_UNORDERED_ACCESS, RESOURCE_STATE_SHADER_RESOURCE),
|
||||
@@ -327,7 +328,7 @@ void wiHairParticle::UpdateGPU(uint32_t instanceIndex, uint32_t materialIndex, c
|
||||
|
||||
void wiHairParticle::Draw(const MaterialComponent& material, RENDERPASS renderPass, CommandList cmd) const
|
||||
{
|
||||
if (strandCount == 0 || !cb.IsValid())
|
||||
if (strandCount == 0 || !constantBuffer.IsValid())
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -356,7 +357,7 @@ void wiHairParticle::Draw(const MaterialComponent& material, RENDERPASS renderPa
|
||||
}
|
||||
}
|
||||
|
||||
device->BindConstantBuffer(&cb, CB_GETBINDSLOT(HairParticleCB), cmd);
|
||||
device->BindConstantBuffer(&constantBuffer, CB_GETBINDSLOT(HairParticleCB), cmd);
|
||||
device->BindResource(&primitiveBuffer, 0, cmd);
|
||||
|
||||
device->BindIndexBuffer(&culledIndexBuffer, INDEXFORMAT_32BIT, 0, cmd);
|
||||
|
||||
@@ -16,7 +16,7 @@ namespace wiScene
|
||||
class wiHairParticle
|
||||
{
|
||||
public:
|
||||
wiGraphics::GPUBuffer cb;
|
||||
wiGraphics::GPUBuffer constantBuffer;
|
||||
wiGraphics::GPUBuffer simulationBuffer;
|
||||
wiGraphics::GPUBuffer vertexBuffer_POS[2];
|
||||
wiGraphics::GPUBuffer vertexBuffer_TEX;
|
||||
|
||||
@@ -723,6 +723,7 @@ namespace wiScene
|
||||
}
|
||||
void MeshComponent::WriteShaderMesh(ShaderMesh* dest) const
|
||||
{
|
||||
dest->init();
|
||||
GraphicsDevice* device = wiRenderer::GetDevice();
|
||||
dest->ib = device->GetDescriptorIndex(&indexBuffer, SRV);
|
||||
if (streamoutBuffer_POS.IsValid())
|
||||
@@ -754,11 +755,12 @@ namespace wiScene
|
||||
dest->aabb_max = aabb._max;
|
||||
dest->tessellation_factor = tessellationFactor;
|
||||
|
||||
dest->flags = 0;
|
||||
uint flags = 0;
|
||||
if (IsDoubleSided())
|
||||
{
|
||||
dest->flags |= SHADERMESH_FLAG_DOUBLE_SIDED;
|
||||
flags |= SHADERMESH_FLAG_DOUBLE_SIDED;
|
||||
}
|
||||
dest->flags = flags; // ensure that this memory is not read, so bitwise ORs also not performed with it!
|
||||
|
||||
}
|
||||
void MeshComponent::ComputeNormals(COMPUTE_NORMALS compute)
|
||||
@@ -3613,12 +3615,13 @@ namespace wiScene
|
||||
|
||||
size_t meshIndex = meshes.GetCount() + args.jobIndex;
|
||||
ShaderMesh& mesh = meshArrayMapped[meshIndex];
|
||||
mesh.init();
|
||||
mesh.ib = device->GetDescriptorIndex(&hair.primitiveBuffer, SRV);
|
||||
mesh.vb_pos_nor_wind = device->GetDescriptorIndex(&hair.vertexBuffer_POS[0], SRV);
|
||||
mesh.vb_pre = device->GetDescriptorIndex(&hair.vertexBuffer_POS[1], SRV);
|
||||
mesh.vb_uv0 = device->GetDescriptorIndex(&hair.vertexBuffer_TEX, SRV);
|
||||
mesh.subsetbuffer = device->GetDescriptorIndex(&hair.subsetBuffer, SRV);
|
||||
mesh.flags |= SHADERMESH_FLAG_DOUBLE_SIDED;
|
||||
mesh.flags = SHADERMESH_FLAG_DOUBLE_SIDED;
|
||||
|
||||
size_t instanceIndex = objects.GetCount() + args.jobIndex;
|
||||
ShaderMeshInstance& inst = instanceArrayMapped[instanceIndex];
|
||||
|
||||
@@ -9,7 +9,7 @@ namespace wiVersion
|
||||
// minor features, major updates, breaking compatibility changes
|
||||
const int minor = 57;
|
||||
// minor bug fixes, alterations, refactors, updates
|
||||
const int revision = 40;
|
||||
const int revision = 41;
|
||||
|
||||
const std::string version_string = std::to_string(major) + "." + std::to_string(minor) + "." + std::to_string(revision);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user