From 18c5ed06be9c65c1fe6eb4e8f0ce207b894edb80 Mon Sep 17 00:00:00 2001 From: turanszkij Date: Thu, 16 Mar 2017 21:53:15 +0100 Subject: [PATCH] minor voxel radiance update --- WickedEngine/RendererWindow.cpp | 2 +- WickedEngine/voxelConeTracingHF.hlsli | 4 ++-- .../voxelRadianceSecondaryBounceCS.hlsl | 4 +--- WickedEngine/voxelSceneCopyClearCS.hlsl | 18 ++++++------------ 4 files changed, 10 insertions(+), 18 deletions(-) diff --git a/WickedEngine/RendererWindow.cpp b/WickedEngine/RendererWindow.cpp index 3eb0e40c8..5d01f6c2e 100644 --- a/WickedEngine/RendererWindow.cpp +++ b/WickedEngine/RendererWindow.cpp @@ -67,7 +67,7 @@ RendererWindow::RendererWindow(Renderable3DComponent* component) voxelRadianceSecondaryBounceCheckBox->SetCheck(wiRenderer::GetVoxelRadianceSecondaryBounceEnabled()); rendererWindow->AddWidget(voxelRadianceSecondaryBounceCheckBox); - voxelRadianceVoxelSizeSlider = new wiSlider(0.25, 10, 1, 39, "Voxel GI Voxel Size: "); + voxelRadianceVoxelSizeSlider = new wiSlider(0.125, 10, 1, 79, "Voxel GI Voxel Size: "); voxelRadianceVoxelSizeSlider->SetTooltip("Adjust the voxel size for Voxel GI calculations."); voxelRadianceVoxelSizeSlider->SetSize(XMFLOAT2(100, 30)); voxelRadianceVoxelSizeSlider->SetPos(XMFLOAT2(x, y += 30)); diff --git a/WickedEngine/voxelConeTracingHF.hlsli b/WickedEngine/voxelConeTracingHF.hlsli index 475f3c74b..b6f9c2346 100644 --- a/WickedEngine/voxelConeTracingHF.hlsli +++ b/WickedEngine/voxelConeTracingHF.hlsli @@ -76,7 +76,7 @@ inline float4 ConeTraceReflection(in Texture3D voxels, in float3 uvw, in float4 accumulation = 0; float3 tc = uvw + coneVec; float rayLengthCorrection = 1 - saturate(dot(N, V)); - coneVec *= lerp(g_xWorld_VoxelRadianceDataSize * 0.5f, g_xWorld_VoxelRadianceDataSize * 40, pow8(rayLengthCorrection)); + coneVec *= lerp(g_xWorld_VoxelRadianceDataSize, g_xWorld_VoxelRadianceDataSize * 40, pow8(rayLengthCorrection)); uint i = 0; while(accumulation.a < 1 && !any(tc - saturate(tc))) @@ -85,7 +85,7 @@ inline float4 ConeTraceReflection(in Texture3D voxels, in float3 uvw, in tc += coneVec * (1 + mip); - float4 sam = voxels.SampleLevel(sampler_linear_clamp, tc, mip); + float4 sam = voxels.SampleLevel(sampler_point_clamp, tc, mip); accumulation.a += sam.a; accumulation.rgb += sam.rgb * sam.a; diff --git a/WickedEngine/voxelRadianceSecondaryBounceCS.hlsl b/WickedEngine/voxelRadianceSecondaryBounceCS.hlsl index 1275efef2..b1e8708c9 100644 --- a/WickedEngine/voxelRadianceSecondaryBounceCS.hlsl +++ b/WickedEngine/voxelRadianceSecondaryBounceCS.hlsl @@ -11,7 +11,7 @@ RWTEXTURE3D(output, float4, 0); [numthreads(1024, 1, 1)] void main( uint3 DTid : SV_DispatchThreadID ) { - uint3 writecoord = to3D(DTid.x, g_xWorld_VoxelRadianceDataRes); + const uint3 writecoord = to3D(DTid.x, g_xWorld_VoxelRadianceDataRes); float4 emission = input_emission[writecoord]; @@ -24,8 +24,6 @@ void main( uint3 DTid : SV_DispatchThreadID ) float4 radiance = ConeTraceRadiance(input_emission, uvw, N); output[writecoord] = emission + float4(radiance.rgb, 0); - //output[writecoord] = float4(radiance.rgb, 1); - //output[writecoord] = float4(N, 1); } else { diff --git a/WickedEngine/voxelSceneCopyClearCS.hlsl b/WickedEngine/voxelSceneCopyClearCS.hlsl index 3f421efd9..c06fb96e3 100644 --- a/WickedEngine/voxelSceneCopyClearCS.hlsl +++ b/WickedEngine/voxelSceneCopyClearCS.hlsl @@ -4,33 +4,27 @@ #define TEMPORAL_SMOOTHING RWSTRUCTUREDBUFFER(input_output, VoxelType, 0); -globallycoherent RWTEXTURE3D(output_emission, float4, 1); +RWTEXTURE3D(output_emission, float4, 1); [numthreads(1024, 1, 1)] void main( uint3 DTid : SV_DispatchThreadID ) { VoxelType voxel = input_output[DTid.x]; - float4 color = DecodeColor(voxel.colorMask); + const float4 color = DecodeColor(voxel.colorMask); - uint3 writecoord = to3D(DTid.x, g_xWorld_VoxelRadianceDataRes); - -//#ifdef TEMPORAL_SMOOTHING -// uint3 loadPrev = writecoord + floor((g_xWorld_VoxelRadianceDataCenter - g_xWorld_VoxelRadianceDataInterpolatedCenter) * float3(1,-1,1)); -// loadPrev = clamp(loadPrev, 0, g_xWorld_VoxelRadianceDataRes); -// float4 colorPrev = output_emission[loadPrev]; -// DeviceMemoryBarrier(); -//#endif + const uint3 writecoord = to3D(DTid.x, g_xWorld_VoxelRadianceDataRes); [branch] if (color.a > 0) { #ifdef TEMPORAL_SMOOTHING - //output_emission[writecoord] = lerp(output_emission[writecoord], float4(color.rgb, 1), 0.1); - + // Blend voxels with the previous frame's data to avoid popping artifacts for dynamic objects: [branch] if (g_xColor.z > 0) { + // Do not perform the blend if an offset happened to the voxel grid's center. + // The offset is not accounted for in the blend operation which can introduce severe light leaking. output_emission[writecoord] = float4(color.rgb, 1); } else