diff --git a/WickedEngine/shaders/raytraceCS.hlsl b/WickedEngine/shaders/raytraceCS.hlsl index 1cb046591..85c0ac6b6 100644 --- a/WickedEngine/shaders/raytraceCS.hlsl +++ b/WickedEngine/shaders/raytraceCS.hlsl @@ -16,6 +16,7 @@ RWTexture2D output_albedo : register(u1); RWTexture2D output_normal : register(u2); RWTexture2D output_depth : register(u3); RWTexture2D output_stencil : register(u4); +RWTexture2D output_primitiveID : register(u5); [numthreads(RAYTRACING_LAUNCH_BLOCKSIZE, RAYTRACING_LAUNCH_BLOCKSIZE, 1)] void main(uint3 DTid : SV_DispatchThreadID, uint groupIndex : SV_GroupIndex) @@ -35,6 +36,9 @@ void main(uint3 DTid : SV_DispatchThreadID, uint groupIndex : SV_GroupIndex) float3 primary_albedo = 0; float3 primary_normal = 0; + // for primID post effect: + uint primary_primitiveID = 0; + // Create starting ray: RayDesc ray = CreateCameraRay(pixel, xTracePixelOffset); @@ -167,6 +171,9 @@ void main(uint3 DTid : SV_DispatchThreadID, uint groupIndex : SV_GroupIndex) surface.hit_depth = q.CommittedRayT(); if (!surface.load(prim, q.CommittedTriangleBarycentrics())) return; + + if (primary_primitiveID == 0) + primary_primitiveID = prim.pack(); #else // ray origin updated for next bounce: @@ -178,6 +185,9 @@ void main(uint3 DTid : SV_DispatchThreadID, uint groupIndex : SV_GroupIndex) if (!surface.load(hit.primitiveID, hit.bary)) return; + if (primary_primitiveID == 0) + primary_primitiveID = hit.primitiveID.pack(); + #endif // RTAPI surface.P = ray.Origin; @@ -455,5 +465,6 @@ void main(uint3 DTid : SV_DispatchThreadID, uint groupIndex : SV_GroupIndex) { output_depth[pixel] = depth; output_stencil[pixel] = stencil; + output_primitiveID[pixel] = primary_primitiveID; } } diff --git a/WickedEngine/wiRenderPath3D_PathTracing.cpp b/WickedEngine/wiRenderPath3D_PathTracing.cpp index b3c40efea..05e3fb5ae 100644 --- a/WickedEngine/wiRenderPath3D_PathTracing.cpp +++ b/WickedEngine/wiRenderPath3D_PathTracing.cpp @@ -57,6 +57,14 @@ namespace wi device->CreateTexture(&desc, nullptr, &rtMain); device->SetName(&rtMain, "rtMain"); + desc.format = wi::renderer::format_idbuffer; + desc.bind_flags = BindFlag::UNORDERED_ACCESS | BindFlag::SHADER_RESOURCE; + desc.width = internalResolution.x; + desc.height = internalResolution.y; + desc.sample_count = 1; + device->CreateTexture(&desc, nullptr, &rtPrimitiveID); + device->SetName(&rtPrimitiveID, "rtPrimitiveID"); + desc.bind_flags = BindFlag::UNORDERED_ACCESS | BindFlag::SHADER_RESOURCE | BindFlag::RENDER_TARGET; desc.format = Format::R32G32B32A32_FLOAT; desc.width = internalResolution.x; @@ -393,10 +401,16 @@ namespace wi denoiserNormal.IsValid() ? &denoiserNormal : nullptr, &traceDepth, &traceStencil, - &depthBuffer_Main + &depthBuffer_Main, + &rtPrimitiveID ); wi::profiler::EndRange(range); // Traced Scene + + if (sam == 0 && getMeshBlendEnabled() && visibility_main.IsMeshBlendVisible()) + { + wi::renderer::PostProcess_MeshBlend_EdgeProcess(meshblendResources, cmd); + } } if (getVolumeLightsEnabled() && visibility_main.IsRequestedVolumetricLights()) @@ -481,8 +495,8 @@ namespace wi // Composite other effects on top: { RenderPassImage rp[] = { + RenderPassImage::RenderTarget(&rtMain, RenderPassImage::LoadOp::CLEAR), RenderPassImage::DepthStencil(&depthBuffer_Main, RenderPassImage::LoadOp::LOAD), - RenderPassImage::RenderTarget(&rtMain, RenderPassImage::LoadOp::CLEAR) }; device->RenderPassBegin(rp, arraysize(rp), cmd); @@ -563,6 +577,12 @@ namespace wi } device->RenderPassEnd(cmd); + + if (getMeshBlendEnabled() && visibility_main.IsMeshBlendVisible()) + { + rp[0].loadop = RenderPassImage::LoadOp::LOAD; + wi::renderer::PostProcess_MeshBlend_Resolve(meshblendResources, rtMain, rp, arraysize(rp), cmd); + } } // Post processing: diff --git a/WickedEngine/wiRenderer.cpp b/WickedEngine/wiRenderer.cpp index 41f252886..e9c1c30d9 100644 --- a/WickedEngine/wiRenderer.cpp +++ b/WickedEngine/wiRenderer.cpp @@ -10621,7 +10621,8 @@ void RayTraceScene( const Texture* output_normal, const Texture* output_depth, const Texture* output_stencil, - const Texture* output_depth_stencil + const Texture* output_depth_stencil, + const Texture* output_primitiveID ) { if (!scene.TLAS.IsValid() && !scene.BVH.IsValid()) @@ -10665,6 +10666,7 @@ void RayTraceScene( &nullUAV, &nullUAV, &nullUAV, + & nullUAV, &nullUAV, }; device->BindUAVs(uavs, 0, arraysize(uavs), cmd); @@ -10687,6 +10689,11 @@ void RayTraceScene( { device->BindUAV(output_stencil, 4, cmd); } + if (output_primitiveID != nullptr) + { + device->BindUAV(output_primitiveID, 5, cmd); + PushBarrier(GPUBarrier::Image(output_primitiveID, output_primitiveID->desc.layout, ResourceState::UNORDERED_ACCESS)); + } FlushBarriers(cmd); if (accumulation_sample == 0) @@ -10713,6 +10720,11 @@ void RayTraceScene( device->ClearUAV(output_stencil, 0, cmd); PushBarrier(GPUBarrier::Memory(output_stencil)); } + if (output_primitiveID != nullptr) + { + device->ClearUAV(output_primitiveID, 0, cmd); + PushBarrier(GPUBarrier::Memory(output_primitiveID)); + } FlushBarriers(cmd); } @@ -10723,6 +10735,11 @@ void RayTraceScene( cmd ); + if (output_primitiveID != nullptr) + { + PushBarrier(GPUBarrier::Image(output_primitiveID, ResourceState::UNORDERED_ACCESS, output_primitiveID->desc.layout)); + } + PushBarrier(GPUBarrier::Image(&output, ResourceState::UNORDERED_ACCESS, output.desc.layout)); FlushBarriers(cmd); diff --git a/WickedEngine/wiRenderer.h b/WickedEngine/wiRenderer.h index 669167f15..623cb0a77 100644 --- a/WickedEngine/wiRenderer.h +++ b/WickedEngine/wiRenderer.h @@ -1055,7 +1055,8 @@ namespace wi::renderer const wi::graphics::Texture* output_normal = nullptr, const wi::graphics::Texture* output_depth = nullptr, const wi::graphics::Texture* output_stencil = nullptr, - const wi::graphics::Texture* output_depth_stencil = nullptr + const wi::graphics::Texture* output_depth_stencil = nullptr, + const wi::graphics::Texture* output_primitiveID = nullptr ); // Render the scene BVH with ray tracing to the screen void RayTraceSceneBVH(const wi::scene::Scene& scene, wi::graphics::CommandList cmd); diff --git a/WickedEngine/wiVersion.cpp b/WickedEngine/wiVersion.cpp index a00d65688..d69556e79 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 = 832; + const int revision = 833; const std::string version_string = std::to_string(major) + "." + std::to_string(minor) + "." + std::to_string(revision);