single pass scene voxelization

This commit is contained in:
turanszkij
2017-02-26 21:22:16 +01:00
parent 428943ac4c
commit 8d445eaf83
17 changed files with 194 additions and 63 deletions
+12
View File
@@ -58,6 +58,16 @@ RendererWindow::RendererWindow(Renderable3DComponent* component)
voxelRadianceDebugCheckBox->SetCheck(wiRenderer::GetToDrawVoxelHelper());
rendererWindow->AddWidget(voxelRadianceDebugCheckBox);
voxelRadianceVoxelSizeSlider = new wiSlider(0.25, 10, 1, 39, "Voxel Radiance Voxel Size: ");
voxelRadianceVoxelSizeSlider->SetTooltip("Adjust the voxel size for voxel radiance calculations.");
voxelRadianceVoxelSizeSlider->SetSize(XMFLOAT2(100, 30));
voxelRadianceVoxelSizeSlider->SetPos(XMFLOAT2(x, y += 30));
voxelRadianceVoxelSizeSlider->SetValue(wiRenderer::GetVoxelRadianceVoxelSize());
voxelRadianceVoxelSizeSlider->OnSlide([&](wiEventArgs args) {
wiRenderer::SetVoxelRadianceVoxelSize(args.fValue);
});
rendererWindow->AddWidget(voxelRadianceVoxelSizeSlider);
partitionBoxesCheckBox = new wiCheckBox("SPTree visualizer: ");
partitionBoxesCheckBox->SetTooltip("Visualize the world space partitioning tree as boxes");
partitionBoxesCheckBox->SetPos(XMFLOAT2(x, y += step));
@@ -151,6 +161,7 @@ RendererWindow::RendererWindow(Renderable3DComponent* component)
speedMultiplierSlider->SetTooltip("Adjust the global speed (time multiplier)");
speedMultiplierSlider->SetSize(XMFLOAT2(100, 30));
speedMultiplierSlider->SetPos(XMFLOAT2(x, y += 30));
speedMultiplierSlider->SetValue(wiRenderer::GetGameSpeed());
speedMultiplierSlider->OnSlide([&](wiEventArgs args) {
wiRenderer::SetGameSpeed(args.fValue);
});
@@ -280,6 +291,7 @@ RendererWindow::~RendererWindow()
SAFE_DELETE(occlusionCullingCheckBox);
SAFE_DELETE(voxelRadianceCheckBox);
SAFE_DELETE(voxelRadianceDebugCheckBox);
SAFE_DELETE(voxelRadianceVoxelSizeSlider);
SAFE_DELETE(partitionBoxesCheckBox);
SAFE_DELETE(boneLinesCheckBox);
SAFE_DELETE(wireFrameCheckBox);
+1
View File
@@ -21,6 +21,7 @@ public:
wiCheckBox* occlusionCullingCheckBox;
wiCheckBox* voxelRadianceCheckBox;
wiCheckBox* voxelRadianceDebugCheckBox;
wiSlider* voxelRadianceVoxelSizeSlider;
wiCheckBox* partitionBoxesCheckBox;
wiCheckBox* boneLinesCheckBox;
wiCheckBox* wireFrameCheckBox;
+6
View File
@@ -0,0 +1,6 @@
#ifndef _WICKEDENGINE_SHADERINTEROP_H_
#define _WICKEDENGINE_SHADERINTEROP_H_
#define SCENE_VOXELIZATION_RESOLUTION 32
#endif
+22
View File
@@ -379,6 +379,16 @@
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Domain</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">Domain</ShaderType>
</FxCompile>
<FxCompile Include="objectGS_voxelizer.hlsl">
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Geometry</ShaderType>
<ShaderModel Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">4.0</ShaderModel>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">Geometry</ShaderType>
<ShaderModel Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">4.0</ShaderModel>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Geometry</ShaderType>
<ShaderModel Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">4.0</ShaderModel>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">Geometry</ShaderType>
<ShaderModel Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">4.0</ShaderModel>
</FxCompile>
<FxCompile Include="objectHS.hlsl">
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Hull</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">Hull</ShaderType>
@@ -575,6 +585,12 @@
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Pixel</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">Pixel</ShaderType>
</FxCompile>
<FxCompile Include="objectPS_voxelizer.hlsl">
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Pixel</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">Pixel</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Pixel</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">Pixel</ShaderType>
</FxCompile>
<FxCompile Include="objectVS.hlsl">
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Vertex</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">Vertex</ShaderType>
@@ -587,6 +603,12 @@
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Vertex</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">Vertex</ShaderType>
</FxCompile>
<FxCompile Include="objectVS_voxelizer.hlsl">
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Vertex</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">Vertex</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Vertex</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">Vertex</ShaderType>
</FxCompile>
<FxCompile Include="outlinePS.hlsl">
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Pixel</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">Pixel</ShaderType>
@@ -519,6 +519,15 @@
<FxCompile Include="voxelPS.hlsl">
<Filter>PS</Filter>
</FxCompile>
<FxCompile Include="objectGS_voxelizer.hlsl">
<Filter>GS</Filter>
</FxCompile>
<FxCompile Include="objectVS_voxelizer.hlsl">
<Filter>VS</Filter>
</FxCompile>
<FxCompile Include="objectPS_voxelizer.hlsl">
<Filter>PS</Filter>
</FxCompile>
</ItemGroup>
<ItemGroup>
<Filter Include="PS">
@@ -233,6 +233,7 @@
<ClInclude Include="$(MSBuildThisFileDirectory)DeferredRenderableComponent_BindLua.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)ForwardRenderableComponent.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)ForwardRenderableComponent_BindLua.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)ShaderInterop.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)TiledForwardRenderableComponent.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)TiledForwardRenderableComponent_BindLua.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)wiArchive.h" />
@@ -1089,6 +1089,9 @@
<ClInclude Include="$(MSBuildThisFileDirectory)wiProfiler.h">
<Filter>ENGINE\Helpers</Filter>
</ClInclude>
<ClInclude Include="$(MSBuildThisFileDirectory)ShaderInterop.h">
<Filter>ENGINE\Graphics\GPUMapping</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="$(MSBuildThisFileDirectory)LUA\lapi.c">
+1
View File
@@ -1,5 +1,6 @@
#ifndef _SHADER_GLOBALS_
#define _SHADER_GLOBALS_
#include "ShaderInterop.h"
#include "ConstantBufferMapping.h"
#include "SamplerMapping.h"
#include "ResourceMapping.h"
+40
View File
@@ -0,0 +1,40 @@
#include "globals.hlsli"
CBUFFER(voxelCamBuffer, 0)
{
float4x4 xVoxelCam[SCENE_VOXELIZATION_RESOLUTION];
}
struct GSInput
{
float4 pos : SV_POSITION;
float2 tex : TEXCOORD;
};
struct GSOutput
{
float4 pos : SV_POSITION;
float2 tex : TEXCOORD;
uint RTIndex : SV_RenderTargetArrayIndex;
};
[maxvertexcount(3 * SCENE_VOXELIZATION_RESOLUTION)]
void main(
triangle GSInput input[3],
inout TriangleStream< GSOutput > output
)
{
for (uint i = 0; i < SCENE_VOXELIZATION_RESOLUTION; i++)
{
GSOutput element;
element.RTIndex = i;
for (uint j = 0; j < 3; ++j)
{
element.tex = input[j].tex;
element.pos = mul(float4(input[j].pos.xyz, 1), xVoxelCam[i]);
output.Append(element);
}
output.RestartStrip();
}
}
+1 -1
View File
@@ -119,7 +119,7 @@ inline void VoxelRadiance(in float3 P, inout float ao)
float3 uvw = diff * float3(0.5f, -0.5f, 0.5f) + 0.5f;
float4 radiance = texture_voxelradiance.SampleLevel(sampler_linear_clamp, uvw, 0);
diff = abs(diff);
float blend = pow(saturate(max(diff.x, max(diff.y, diff.z))), 4);
float blend = pow(saturate(max(diff.x, max(diff.y, diff.z))), 8);
ao *= lerp(1 - radiance.a, 1, blend);
}
+6
View File
@@ -0,0 +1,6 @@
#include "objectHF.hlsli"
float4 main(float4 pos : SV_POSITION, float2 tex : TEXCOORD, uint RTIndex : SV_RenderTargetArrayIndex) : SV_TARGET
{
return DEGAMMA(xBaseColorMap.Sample(sampler_linear_clamp, tex));
}
+20
View File
@@ -0,0 +1,20 @@
#include "objectHF.hlsli"
struct VSOut
{
float4 pos : SV_POSITION;
float2 tex : TEXCOORD;
};
VSOut main(Input input)
{
VSOut Out = (VSOut)0;
float4x4 WORLD = MakeWorldMatrixFromInstance(input);
Out.pos = mul(input.pos, WORLD);
Out.tex = input.tex.xy;
return Out;
}
+17 -17
View File
@@ -29,28 +29,28 @@ void main( uint3 DTid : SV_DispatchThreadID, uint GroupIndex : SV_GroupIndex )
{
// TODO!
float3 dim;
input.GetDimensions(dim.x, dim.y, dim.z);
float3 uvw = DTid / dim;
//float3 dim;
//input.GetDimensions(dim.x, dim.y, dim.z);
//float3 uvw = DTid / dim;
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;
//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++;
}
}
// count++;
// }
//}
output[DTid] = float4(input[DTid].rgb, occ / count);
//output[DTid] = occ / count;
//float4 current = input[DTid];
float4 current = input[DTid];
//output[DTid] = current;
output[DTid] = current;
//accumulation[GroupIndex] = current;
+4
View File
@@ -74,6 +74,7 @@ enum CBTYPES
CBTYPE_API,
CBTYPE_TESSELLATION,
CBTYPE_DISPATCHPARAMS,
CBTYPE_VOXELIZER,
CBTYPE_LAST
};
@@ -124,6 +125,7 @@ enum VSTYPES
VSTYPE_ENVMAP_SKY,
VSTYPE_SPHERE,
VSTYPE_CUBE,
VSTYPE_VOXELIZER,
VSTYPE_VOXEL,
VSTYPE_LAST
};
@@ -188,6 +190,7 @@ enum PSTYPES
PSTYPE_ENVMAP_SKY,
PSTYPE_CUBEMAP,
PSTYPE_CAPTUREIMPOSTOR,
PSTYPE_VOXELIZER,
PSTYPE_VOXEL,
PSTYPE_LAST
};
@@ -198,6 +201,7 @@ enum GSTYPES
GSTYPE_STREAMOUT,
GSTYPE_ENVMAP,
GSTYPE_ENVMAP_SKY,
GSTYPE_VOXELIZER,
GSTYPE_LAST
};
// hull shaders
+47 -44
View File
@@ -1,4 +1,5 @@
#include "wiRenderer.h"
#include "ShaderInterop.h"
#include "wiFrameRate.h"
#include "wiHairParticle.h"
#include "wiEmittedParticle.h"
@@ -57,6 +58,7 @@ float wiRenderer::GameSpeed=1,wiRenderer::overrideGameSpeed=1;
bool wiRenderer::debugLightCulling = false;
bool wiRenderer::occlusionCulling = true;
bool wiRenderer::voxelRadiance = false;
float wiRenderer::voxelRadianceVoxelSize = 1.0f;
int wiRenderer::visibleCount;
wiRenderTarget wiRenderer::normalMapRT, wiRenderer::imagesRT, wiRenderer::imagesRTAdd;
Camera *wiRenderer::cam = nullptr, *wiRenderer::refCam = nullptr, *wiRenderer::prevFrameCam = nullptr;
@@ -564,6 +566,9 @@ void wiRenderer::LoadBuffers()
bd.ByteWidth = sizeof(DispatchParamsCB);
GetDevice()->CreateBuffer(&bd, nullptr, constantBuffers[CBTYPE_DISPATCHPARAMS]);
bd.ByteWidth = sizeof(XMMATRIX) * SCENE_VOXELIZATION_RESOLUTION;
GetDevice()->CreateBuffer(&bd, nullptr, constantBuffers[CBTYPE_VOXELIZER]);
@@ -589,8 +594,6 @@ void wiRenderer::LoadBuffers()
bd.MiscFlags = RESOURCE_MISC_BUFFER_STRUCTURED;
bd.StructureByteStride = sizeof(LightArrayType);
GetDevice()->CreateBuffer(&bd, nullptr, resourceBuffers[RBTYPE_LIGHTARRAY]);
}
void wiRenderer::LoadShaders()
@@ -701,6 +704,7 @@ void wiRenderer::LoadShaders()
vertexShaders[VSTYPE_SHADOW] = static_cast<VertexShaderInfo*>(wiResourceManager::GetShaderManager()->add(SHADERPATH + "shadowVS.cso", wiResourceManager::VERTEXSHADER))->vertexShader;
vertexShaders[VSTYPE_SHADOWCUBEMAPRENDER] = static_cast<VertexShaderInfo*>(wiResourceManager::GetShaderManager()->add(SHADERPATH + "cubeShadowVS.cso", wiResourceManager::VERTEXSHADER))->vertexShader;
vertexShaders[VSTYPE_WATER] = static_cast<VertexShaderInfo*>(wiResourceManager::GetShaderManager()->add(SHADERPATH + "waterVS.cso", wiResourceManager::VERTEXSHADER))->vertexShader;
vertexShaders[VSTYPE_VOXELIZER] = static_cast<VertexShaderInfo*>(wiResourceManager::GetShaderManager()->add(SHADERPATH + "objectVS_voxelizer.cso", wiResourceManager::VERTEXSHADER))->vertexShader;
vertexShaders[VSTYPE_VOXEL] = static_cast<VertexShaderInfo*>(wiResourceManager::GetShaderManager()->add(SHADERPATH + "voxelVS.cso", wiResourceManager::VERTEXSHADER))->vertexShader;
@@ -762,12 +766,14 @@ void wiRenderer::LoadShaders()
pixelShaders[PSTYPE_SHADOW] = static_cast<PixelShader*>(wiResourceManager::GetShaderManager()->add(SHADERPATH + "shadowPS.cso", wiResourceManager::PIXELSHADER));
pixelShaders[PSTYPE_SHADOWCUBEMAPRENDER] = static_cast<PixelShader*>(wiResourceManager::GetShaderManager()->add(SHADERPATH + "cubeShadowPS.cso", wiResourceManager::PIXELSHADER));
pixelShaders[PSTYPE_TRAIL] = static_cast<PixelShader*>(wiResourceManager::GetShaderManager()->add(SHADERPATH + "trailPS.cso", wiResourceManager::PIXELSHADER));
pixelShaders[PSTYPE_VOXELIZER] = static_cast<PixelShader*>(wiResourceManager::GetShaderManager()->add(SHADERPATH + "objectPS_voxelizer.cso", wiResourceManager::PIXELSHADER));
pixelShaders[PSTYPE_VOXEL] = static_cast<PixelShader*>(wiResourceManager::GetShaderManager()->add(SHADERPATH + "voxelPS.cso", wiResourceManager::PIXELSHADER));
geometryShaders[GSTYPE_ENVMAP] = static_cast<GeometryShader*>(wiResourceManager::GetShaderManager()->add(SHADERPATH + "envMapGS.cso", wiResourceManager::GEOMETRYSHADER));
geometryShaders[GSTYPE_ENVMAP_SKY] = static_cast<GeometryShader*>(wiResourceManager::GetShaderManager()->add(SHADERPATH + "envMap_skyGS.cso", wiResourceManager::GEOMETRYSHADER));
geometryShaders[GSTYPE_SHADOWCUBEMAPRENDER] = static_cast<GeometryShader*>(wiResourceManager::GetShaderManager()->add(SHADERPATH + "cubeShadowGS.cso", wiResourceManager::GEOMETRYSHADER));
geometryShaders[GSTYPE_VOXELIZER] = static_cast<GeometryShader*>(wiResourceManager::GetShaderManager()->add(SHADERPATH + "objectGS_voxelizer.cso", wiResourceManager::GEOMETRYSHADER));
computeShaders[CSTYPE_LUMINANCE_PASS1] = static_cast<ComputeShader*>(wiResourceManager::GetShaderManager()->add(SHADERPATH + "luminancePass1CS.cso", wiResourceManager::COMPUTESHADER));
@@ -2357,8 +2363,7 @@ void wiRenderer::DrawDebugVoxels(Camera* camera, GRAPHICSTHREAD threadID)
GetDevice()->UpdateBuffer(constantBuffers[CBTYPE_MISC], &sb, threadID);
Texture3DDesc desc = ((Texture3D*)textures[TEXTYPE_3D_VOXELRADIANCE])->GetDesc();
GetDevice()->DrawInstanced(36, desc.Width * desc.Height * desc.Depth, threadID); // cube
GetDevice()->DrawInstanced(36, voxelSceneData.res * voxelSceneData.res * voxelSceneData.res, threadID); // cube
GetDevice()->EventEnd(threadID);
@@ -3275,6 +3280,9 @@ PSTYPES GetPSTYPE(SHADERTYPE shaderType, const Material* const material)
case SHADERTYPE_ALPHATESTONLY:
realPS = PSTYPE_ALPHATESTONLY;
break;
case SHADERTYPE_VOXELIZE:
realPS = PSTYPE_VOXELIZER;
break;
default:
realPS = PSTYPE_TEXTUREONLY;
break;
@@ -3332,7 +3340,12 @@ void wiRenderer::RenderMeshes(const XMFLOAT3& eye, const CulledCollection& culle
GetDevice()->BindPrimitiveTopology(TRIANGLELIST, threadID);
GetDevice()->BindVertexLayout(vertexLayouts[VLTYPE_EFFECT], threadID);
if (shaderType == SHADERTYPE_SHADOW)
if (shaderType == SHADERTYPE_VOXELIZE)
{
GetDevice()->BindVS(vertexShaders[VSTYPE_VOXELIZER], threadID);
GetDevice()->BindGS(geometryShaders[GSTYPE_VOXELIZER], threadID);
}
else if (shaderType == SHADERTYPE_SHADOW)
{
GetDevice()->BindVS(vertexShaders[VSTYPE_SHADOW], threadID);
}
@@ -3914,19 +3927,16 @@ void wiRenderer::VoxelizeScene(GRAPHICSTHREAD threadID)
return;
}
GetDevice()->EventBegin("Voxelize Scene", threadID);
wiProfiler::GetInstance().BeginRange("Voxelize Scene", wiProfiler::DOMAIN_GPU, threadID);
static const int res = 64;
static const float voxelsize = 1.0f;
voxelSceneData.res = res;
voxelSceneData.res = SCENE_VOXELIZATION_RESOLUTION;
voxelSceneData.voxelsize = voxelRadianceVoxelSize;
if (textures[TEXTYPE_3D_VOXELSCENE] == nullptr)
{
Texture3DDesc desc;
ZeroMemory(&desc, sizeof(desc));
desc.Width = res;
desc.Height = res;
desc.Depth = res;
desc.Width = voxelSceneData.res;
desc.Height = voxelSceneData.res;
desc.Depth = voxelSceneData.res;
desc.MipLevels = 1;
desc.Format = FORMAT_R8G8B8A8_UNORM;
desc.BindFlags = BIND_RENDER_TARGET | BIND_SHADER_RESOURCE;
@@ -3935,7 +3945,6 @@ void wiRenderer::VoxelizeScene(GRAPHICSTHREAD threadID)
desc.MiscFlags = 0;
textures[TEXTYPE_3D_VOXELSCENE] = new Texture3D;
textures[TEXTYPE_3D_VOXELSCENE]->RequestIndepententRenderTargetArraySlices(true);
HRESULT hr = GetDevice()->CreateTexture3D(&desc, nullptr, (Texture3D**)&textures[TEXTYPE_3D_VOXELSCENE]);
assert(SUCCEEDED(hr));
}
@@ -3944,11 +3953,11 @@ void wiRenderer::VoxelizeScene(GRAPHICSTHREAD threadID)
CulledCollection culledRenderer;
AABB bbox;
XMFLOAT3 extents = XMFLOAT3(res * voxelsize, res * voxelsize, res * voxelsize);
const float f = 0.5f / voxelsize;
XMFLOAT3 extents = XMFLOAT3(voxelSceneData.res * voxelSceneData.voxelsize, voxelSceneData.res * voxelSceneData.voxelsize, voxelSceneData.res * voxelSceneData.voxelsize);
const float f = 0.5f / voxelSceneData.voxelsize;
XMFLOAT3 center = XMFLOAT3(floorf(cam->translation.x * f) / f, floorf(cam->translation.y * f) / f, floorf(cam->translation.z * f) / f);
bbox.createFromHalfWidth(center, extents);
if (spTree != nullptr)
if (spTree != nullptr && (wiMath::Distance(center,voxelSceneData.center) > 0.1f || GetToDrawVoxelHelper() )) // debug voxel helper forces the render every time to help graphics debugging!
{
spTree->getVisible(bbox, culledObjects);
@@ -3957,51 +3966,45 @@ void wiRenderer::VoxelizeScene(GRAPHICSTHREAD threadID)
culledRenderer[((Object*)object)->mesh].push_front((Object*)object);
}
GetDevice()->EventBegin("Voxelize Scene", threadID);
wiProfiler::GetInstance().BeginRange("Voxelize Scene", wiProfiler::DOMAIN_GPU, threadID);
ViewPort VP;
VP.TopLeftX = 0;
VP.TopLeftY = 0;
VP.Width = (float)res;
VP.Height = (float)res;
VP.Width = (float)voxelSceneData.res;
VP.Height = (float)voxelSceneData.res;
VP.MinDepth = 0.0f;
VP.MaxDepth = 1.0f;
GetDevice()->BindViewports(1, &VP, threadID);
GetDevice()->BindBlendState(blendStates[BSTYPE_OPAQUE], threadID);
Camera savedCam = *cam;
for (int i = 0; i < res; ++i)
XMMATRIX voxelizerCams[SCENE_VOXELIZATION_RESOLUTION];
for (int i = 0; i < voxelSceneData.res; ++i)
{
GetDevice()->BindRenderTargets(1, &textures[TEXTYPE_3D_VOXELSCENE], nullptr, threadID, i);
static const float color[] = { 0,0,0,0 };
GetDevice()->ClearRenderTarget(textures[TEXTYPE_3D_VOXELSCENE], color, threadID, i);
cam->Clear();
cam->Translate(bbox.getCenter());
XMMATRIX view = XMMatrixLookToLH(XMLoadFloat3(&center), XMVectorSet(0, 0, 1, 0), XMVectorSet(0, 1, 0, 0));
XMStoreFloat4x4(&cam->View, view);
XMMATRIX projection = XMMatrixOrthographicOffCenterLH(-extents.x, extents.x, -extents.y, extents.y, -extents.z + i * voxelsize * 2, -extents.z + (i + 1) * voxelsize * 2);
XMStoreFloat4x4(&cam->Projection, projection);
XMStoreFloat4x4(&cam->VP, XMMatrixMultiply(view, projection));
XMMATRIX projection = XMMatrixOrthographicOffCenterLH(-extents.x, extents.x, -extents.y, extents.y, -extents.z + i * voxelSceneData.voxelsize * 2, -extents.z + (i + 1) * voxelSceneData.voxelsize * 2);
UpdateCameraCB(cam, threadID);
RenderMeshes(cam->translation, culledRenderer, SHADERTYPE_VOXELIZE, RENDERTYPE_OPAQUE, threadID);
voxelizerCams[i] = XMMatrixTranspose(view*projection);
}
GetDevice()->UpdateBuffer(constantBuffers[CBTYPE_VOXELIZER], voxelizerCams, threadID, sizeof(voxelizerCams));
GetDevice()->BindConstantBufferGS(constantBuffers[CBTYPE_VOXELIZER], 0, threadID);
GetDevice()->BindRenderTargets(1, &textures[TEXTYPE_3D_VOXELSCENE], nullptr, threadID);
static const float color[] = { 0,0,0,0 };
GetDevice()->ClearRenderTarget(textures[TEXTYPE_3D_VOXELSCENE], color, threadID);
RenderMeshes(center, culledRenderer, SHADERTYPE_VOXELIZE, RENDERTYPE_OPAQUE, threadID);
GetDevice()->BindRenderTargets(0, nullptr, nullptr, threadID);
*cam = savedCam;
UpdateCameraCB(cam, threadID);
wiProfiler::GetInstance().EndRange(threadID);
GetDevice()->EventEnd();
voxelSceneData.voxelsize = voxelsize;
voxelSceneData.center = center;
}
wiProfiler::GetInstance().EndRange(threadID);
GetDevice()->EventEnd();
}
void wiRenderer::ComputeTiledLightCulling(GRAPHICSTHREAD threadID)
+3
View File
@@ -296,6 +296,7 @@ protected:
static bool debugLightCulling;
static bool occlusionCulling;
static bool voxelRadiance;
static float voxelRadianceVoxelSize;
struct VoxelizedSceneData
{
@@ -347,6 +348,8 @@ public:
static bool GetOcclusionCullingEnabled() { return occlusionCulling; }
static void SetVoxelRadianceEnabled(bool enabled) { voxelRadiance = enabled; }
static bool GetVoxelRadianceEnabled() { return voxelRadiance; }
static void SetVoxelRadianceVoxelSize(float enabled) { voxelRadianceVoxelSize = enabled; }
static float GetVoxelRadianceVoxelSize() { return voxelRadianceVoxelSize; }
static bool IsRequestedReflectionRendering() { return requestReflectionRendering; }
static wiGraphicsTypes::Texture2D* GetColorGrading(){return colorGrading;};
static void SetColorGrading(wiGraphicsTypes::Texture2D* tex){colorGrading=tex;};
+1 -1
View File
@@ -7,7 +7,7 @@ namespace wiVersion
// minor features, major updates
const int minor = 10;
// minor bug fixes, alterations, refactors, updates
const int revision = 0;
const int revision = 2;
long GetVersion()