From dce26961f32ac9ecde849f37ca280f41b7a86f28 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tur=C3=A1nszki=20J=C3=A1nos?= Date: Wed, 8 Nov 2023 18:28:28 +0100 Subject: [PATCH] hair particle velocity buffer fix at fadeout range --- README.md | 1 + .../shaders/hairparticle_simulateCS.hlsl | 11 +++++---- WickedEngine/wiHairParticle.cpp | 24 ++++++++++++------- WickedEngine/wiHairParticle.h | 1 + WickedEngine/wiVersion.cpp | 2 +- 5 files changed, 25 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index c017c18f19..a0bfe8af5e 100644 --- a/README.md +++ b/README.md @@ -257,6 +257,7 @@ You can specify command line arguments (without any prefix) to switch between re ### Other software using Wicked Engine - Game Guru MAX: Easy to use game creator software - Flytrap: Demoscene production by qop +- doddering: Demoscene production by qop - Your project: add your project to this readme and open a pull request
diff --git a/WickedEngine/shaders/hairparticle_simulateCS.hlsl b/WickedEngine/shaders/hairparticle_simulateCS.hlsl index 354e763aaa..071c83f80c 100644 --- a/WickedEngine/shaders/hairparticle_simulateCS.hlsl +++ b/WickedEngine/shaders/hairparticle_simulateCS.hlsl @@ -18,6 +18,7 @@ RWBuffer vertexBuffer_POS : register(u1); RWBuffer vertexBuffer_UVS : register(u2); RWBuffer culledIndexBuffer : register(u3); RWStructuredBuffer indirectBuffer : register(u4); +RWStructuredBuffer vertexBuffer_POS_RT : register(u5); [numthreads(THREADCOUNT_SIMULATEHAIR, 1, 1)] void main(uint3 DTid : SV_DispatchThreadID, uint3 Gid : SV_GroupID, uint groupIndex : SV_GroupIndex) @@ -268,13 +269,15 @@ void main(uint3 DTid : SV_DispatchThreadID, uint3 Gid : SV_GroupID, uint groupIn const float3 wind = sample_wind(rootposition, segmentID + patchPos.y); float3 position = rootposition + patchPos + wind; - if (distance_culled) - { - position = 0; - } vertexBuffer_POS[v0 + vertexID] = float4(position, asfloat(pack_unitvector(normalize(normal + wind)))); vertexBuffer_UVS[v0 + vertexID] = uv.xyxy; // a second uv set could be used here + + if (distance_culled) + { + position = 0; // We can only zero out for raytracing geometry to keep correct prevpos swapping motion vectors! + } + vertexBuffer_POS_RT[v0 + vertexID] = position; } // Frustum culling: diff --git a/WickedEngine/wiHairParticle.cpp b/WickedEngine/wiHairParticle.cpp index fa07557e70..5f0b6ea8e5 100644 --- a/WickedEngine/wiHairParticle.cpp +++ b/WickedEngine/wiHairParticle.cpp @@ -105,6 +105,7 @@ namespace wi vb_uvs.size = sizeof(MeshComponent::Vertex_UVS) * 4 * particleCount; ib_culled.size = GetFormatStride(ib_format) * 6 * particleCount; indirect_view.size = sizeof(IndirectDrawArgsIndexedInstanced); + vb_pos_raytracing.size = sizeof(float3) * 4 * particleCount; bd.size = AlignTo(AlignTo(indirect_view.size, alignment), sizeof(IndirectDrawArgsIndexedInstanced)) + // additional structured buffer alignment @@ -112,7 +113,8 @@ namespace wi AlignTo(vb_pos[0].size, alignment) + AlignTo(vb_pos[1].size, alignment) + AlignTo(vb_uvs.size, alignment) + - AlignTo(ib_culled.size, alignment) + AlignTo(ib_culled.size, alignment) + + AlignTo(AlignTo(vb_pos_raytracing.size, alignment), sizeof(float3)) ; device->CreateBuffer(&bd, nullptr, &generalBuffer); device->SetName(&generalBuffer, "HairParticleSystem::generalBuffer"); @@ -172,6 +174,14 @@ namespace wi ib_culled.descriptor_uav = device->GetDescriptorIndex(&generalBuffer, SubresourceType::UAV, ib_culled.subresource_uav); buffer_offset += ib_culled.size; + constexpr uint32_t vb_pos_raytracing_stride = sizeof(float3); + buffer_offset = AlignTo(buffer_offset, alignment); + buffer_offset = AlignTo(buffer_offset, sizeof(float3)); + vb_pos_raytracing.offset = buffer_offset; + vb_pos_raytracing.subresource_uav = device->CreateSubresource(&generalBuffer, SubresourceType::UAV, vb_pos_raytracing.offset, vb_pos_raytracing.size, nullptr, &vb_pos_raytracing_stride); + vb_pos_raytracing.descriptor_uav = device->GetDescriptorIndex(&generalBuffer, SubresourceType::UAV, vb_pos_raytracing.subresource_uav); + buffer_offset += vb_pos_raytracing.size; + primitiveBuffer = wi::renderer::GetIndexBufferForQuads(particleCount); } @@ -232,10 +242,10 @@ namespace wi geometry.triangles.index_format = GetIndexBufferFormat(primitiveBuffer.desc.format); geometry.triangles.index_count = GetParticleCount() * 6; geometry.triangles.index_offset = 0; - geometry.triangles.vertex_count = (uint32_t)(vb_pos[0].size / sizeof(MeshComponent::Vertex_POS)); + geometry.triangles.vertex_count = (uint32_t)(vb_pos_raytracing.size / sizeof(float3)); geometry.triangles.vertex_format = Format::R32G32B32_FLOAT; - geometry.triangles.vertex_stride = sizeof(MeshComponent::Vertex_POS); - geometry.triangles.vertex_byte_offset = vb_pos[0].offset; + geometry.triangles.vertex_stride = sizeof(float3); + geometry.triangles.vertex_byte_offset = vb_pos_raytracing.offset; bool success = device->CreateRaytracingAccelerationStructure(&desc, &BLAS); assert(success); @@ -272,11 +282,6 @@ namespace wi } std::swap(vb_pos[0], vb_pos[1]); - - if (BLAS.IsValid() && !BLAS.desc.bottom_level.geometries.empty()) - { - BLAS.desc.bottom_level.geometries.back().triangles.vertex_byte_offset = vb_pos[0].offset; - } } void HairParticleSystem::UpdateGPU( const UpdateGPUItem* items, @@ -371,6 +376,7 @@ namespace wi device->BindUAV(&hair.generalBuffer, 2, cmd, hair.vb_uvs.subresource_uav); device->BindUAV(&hair.generalBuffer, 3, cmd, hair.ib_culled.subresource_uav); device->BindUAV(&hair.generalBuffer, 4, cmd, hair.indirect_view.subresource_uav); + device->BindUAV(&hair.generalBuffer, 5, cmd, hair.vb_pos_raytracing.subresource_uav); if (hair.indexBuffer.IsValid()) { diff --git a/WickedEngine/wiHairParticle.h b/WickedEngine/wiHairParticle.h index d56fddf652..4321a1eace 100644 --- a/WickedEngine/wiHairParticle.h +++ b/WickedEngine/wiHairParticle.h @@ -23,6 +23,7 @@ namespace wi wi::graphics::GPUBuffer generalBuffer; wi::scene::MeshComponent::BufferView simulation_view; wi::scene::MeshComponent::BufferView vb_pos[2]; + wi::scene::MeshComponent::BufferView vb_pos_raytracing; wi::scene::MeshComponent::BufferView vb_uvs; wi::scene::MeshComponent::BufferView ib_culled; wi::scene::MeshComponent::BufferView indirect_view; diff --git a/WickedEngine/wiVersion.cpp b/WickedEngine/wiVersion.cpp index 1aa99de1b5..e55ae69ac7 100644 --- a/WickedEngine/wiVersion.cpp +++ b/WickedEngine/wiVersion.cpp @@ -9,7 +9,7 @@ namespace wi::version // minor features, major updates, breaking compatibility changes const int minor = 71; // minor bug fixes, alterations, refactors, updates - const int revision = 339; + const int revision = 340; const std::string version_string = std::to_string(major) + "." + std::to_string(minor) + "." + std::to_string(revision);