From 428943ac4ca17ca84486ce1d90d65b2dfe367e99 Mon Sep 17 00:00:00 2001 From: turanszkij Date: Sun, 26 Feb 2017 19:45:12 +0100 Subject: [PATCH] updated voxel radiance compute --- WickedEngine/voxelRadianceCS.hlsl | 42 +++++++++++++++++++++++++++++-- WickedEngine/wiEnums.h | 1 + WickedEngine/wiRenderer.cpp | 18 ++++++++++--- 3 files changed, 56 insertions(+), 5 deletions(-) diff --git a/WickedEngine/voxelRadianceCS.hlsl b/WickedEngine/voxelRadianceCS.hlsl index 1c895934b..92b44cb3f 100644 --- a/WickedEngine/voxelRadianceCS.hlsl +++ b/WickedEngine/voxelRadianceCS.hlsl @@ -5,14 +5,52 @@ RWTEXTURE3D(output, float4, 0); groupshared float4 accumulation[4 * 4 * 4]; +static const float3 SAMPLES[16] = { + float3(0.355512, -0.709318, -0.102371), + float3(0.534186, 0.71511, -0.115167), + float3(-0.87866, 0.157139, -0.115167), + float3(0.140679, -0.475516, -0.0639818), + float3(-0.0796121, 0.158842, -0.677075), + float3(-0.0759516, -0.101676, -0.483625), + float3(0.12493, -0.0223423, -0.483625), + float3(-0.0720074, 0.243395, -0.967251), + float3(-0.207641, 0.414286, 0.187755), + float3(-0.277332, -0.371262, 0.187755), + float3(0.63864, -0.114214, 0.262857), + float3(-0.184051, 0.622119, 0.262857), + float3(0.110007, -0.219486, 0.435574), + float3(0.235085, 0.314707, 0.696918), + float3(-0.290012, 0.0518654, 0.522688), + float3(0.0975089, -0.329594, 0.609803) +}; + [numthreads(4, 4, 4)] void main( uint3 DTid : SV_DispatchThreadID, uint GroupIndex : SV_GroupIndex ) { // TODO! - float4 current = input[DTid]; + float3 dim; + input.GetDimensions(dim.x, dim.y, dim.z); + float3 uvw = DTid / dim; - output[DTid] = current; + float occ = 0; + uint count = 0; + for (uint i = 0; i < 16; ++i) + { + for (uint j = 1; j < 6; ++j) + { + float3 tex = uvw + j * SAMPLES[i] / dim; + occ += input.SampleLevel(sampler_linear_clamp, tex, 0).a; + + count++; + } + } + + output[DTid] = float4(input[DTid].rgb, occ / count); + + //float4 current = input[DTid]; + + //output[DTid] = current; //accumulation[GroupIndex] = current; diff --git a/WickedEngine/wiEnums.h b/WickedEngine/wiEnums.h index ccae7804e..ddcb84807 100644 --- a/WickedEngine/wiEnums.h +++ b/WickedEngine/wiEnums.h @@ -248,6 +248,7 @@ enum RSTYPES RSTYPE_SHADOW_DOUBLESIDED, RSTYPE_OCCLUDEE, RSTYPE_VOXELIZE, + RSTYPE_SKY, RSTYPE_LAST }; // depth-stencil states diff --git a/WickedEngine/wiRenderer.cpp b/WickedEngine/wiRenderer.cpp index 3d2e06bd5..43d15b909 100644 --- a/WickedEngine/wiRenderer.cpp +++ b/WickedEngine/wiRenderer.cpp @@ -1013,6 +1013,18 @@ void wiRenderer::SetUpStates() rs.AntialiasedLineEnable = false; GetDevice()->CreateRasterizerState(&rs, rasterizers[RSTYPE_VOXELIZE]); + rs.FillMode = FILL_SOLID; + rs.CullMode = CULL_FRONT; + rs.FrontCounterClockwise = true; + rs.DepthBias = 0; + rs.DepthBiasClamp = 0; + rs.SlopeScaledDepthBias = 0; + rs.DepthClipEnable = false; + rs.ScissorEnable = false; + rs.MultisampleEnable = false; + rs.AntialiasedLineEnable = false; + GetDevice()->CreateRasterizerState(&rs, rasterizers[RSTYPE_SKY]); + for (int i = 0; i < DSSTYPE_LAST; ++i) { depthStencils[i] = new DepthStencilState; @@ -3707,7 +3719,7 @@ void wiRenderer::DrawSky(GRAPHICSTHREAD threadID) GetDevice()->EventBegin("DrawSky", threadID); GetDevice()->BindPrimitiveTopology(TRIANGLELIST,threadID); - GetDevice()->BindRasterizerState(rasterizers[RSTYPE_BACK],threadID); + GetDevice()->BindRasterizerState(rasterizers[RSTYPE_SKY],threadID); GetDevice()->BindDepthStencilState(depthStencils[DSSTYPE_DEPTHREAD],STENCILREF_SKY,threadID); GetDevice()->BindBlendState(blendStates[BSTYPE_OPAQUE],threadID); @@ -3727,7 +3739,7 @@ void wiRenderer::DrawSun(GRAPHICSTHREAD threadID) GetDevice()->EventBegin("DrawSun", threadID); GetDevice()->BindPrimitiveTopology(TRIANGLELIST, threadID); - GetDevice()->BindRasterizerState(rasterizers[RSTYPE_BACK], threadID); + GetDevice()->BindRasterizerState(rasterizers[RSTYPE_SKY], threadID); GetDevice()->BindDepthStencilState(depthStencils[DSSTYPE_DEPTHREAD], STENCILREF_SKY, threadID); GetDevice()->BindBlendState(blendStates[BSTYPE_ADDITIVE], threadID); @@ -3865,7 +3877,7 @@ void wiRenderer::RefreshEnvProbes(GRAPHICSTHREAD threadID) // sky { GetDevice()->BindPrimitiveTopology(TRIANGLELIST, threadID); - GetDevice()->BindRasterizerState(rasterizers[RSTYPE_BACK], threadID); + GetDevice()->BindRasterizerState(rasterizers[RSTYPE_SKY], threadID); GetDevice()->BindDepthStencilState(depthStencils[DSSTYPE_DEPTHREAD], STENCILREF_SKY, threadID); GetDevice()->BindBlendState(blendStates[BSTYPE_OPAQUE], threadID);