|
@@ -28,8 +28,6 @@
|
|
|
#include "Window.h"
|
|
#include "Window.h"
|
|
|
#include "World3D.h"
|
|
#include "World3D.h"
|
|
|
|
|
|
|
|
-#define DEFAULT_MAX_TRANSPARENT_HITS 5
|
|
|
|
|
-
|
|
|
|
|
using namespace Framework;
|
|
using namespace Framework;
|
|
|
|
|
|
|
|
class DX12RenderingData : public Framework::ReferenceCounter
|
|
class DX12RenderingData : public Framework::ReferenceCounter
|
|
@@ -215,8 +213,6 @@ void Framework::DirectX12::renderKamera(
|
|
|
}
|
|
}
|
|
|
directCommandQueue->zCommandList()->RSSetViewports(
|
|
directCommandQueue->zCommandList()->RSSetViewports(
|
|
|
1, (D3D12_VIEWPORT*)zKamera->zViewPort());
|
|
1, (D3D12_VIEWPORT*)zKamera->zViewPort());
|
|
|
- Mat4<float> identity = Mat4<float>::identity();
|
|
|
|
|
-
|
|
|
|
|
World3D* w = zKamera->zWorld();
|
|
World3D* w = zKamera->zWorld();
|
|
|
if (w->getId() < 0)
|
|
if (w->getId() < 0)
|
|
|
{
|
|
{
|
|
@@ -251,15 +247,52 @@ void Framework::DirectX12::renderKamera(
|
|
|
DX12ShaderBindingTable* sbt = worldShaderBindingTables[w->getId()];
|
|
DX12ShaderBindingTable* sbt = worldShaderBindingTables[w->getId()];
|
|
|
tlas->startUpdate();
|
|
tlas->startUpdate();
|
|
|
sbt->startUpdate();
|
|
sbt->startUpdate();
|
|
|
- int objectIndex = 0;
|
|
|
|
|
- int instanceIndex = 0;
|
|
|
|
|
// descriptor heaps must be set before filling the shader binding table with
|
|
// descriptor heaps must be set before filling the shader binding table with
|
|
|
// hit groups
|
|
// hit groups
|
|
|
sbt->setGlobalDescriptorHeap(globalDescriptorHeap);
|
|
sbt->setGlobalDescriptorHeap(globalDescriptorHeap);
|
|
|
sbt->setTextureDescriptorHeap(textureDescriptorHeap);
|
|
sbt->setTextureDescriptorHeap(textureDescriptorHeap);
|
|
|
sbt->setSamplerDescriptorHeap(samplerDescriptorHeap);
|
|
sbt->setSamplerDescriptorHeap(samplerDescriptorHeap);
|
|
|
- w->render([this, &tlas, &objectIndex, &instanceIndex, &identity, &sbt](
|
|
|
|
|
- Model3D* obj) {
|
|
|
|
|
|
|
+ int objectIndex = 0;
|
|
|
|
|
+ renderWorld(w, tlas, sbt, objectIndex);
|
|
|
|
|
+ tlas->endUpdate();
|
|
|
|
|
+ settings.inverseProjection = zKamera->getInverseProjectionMatrix();
|
|
|
|
|
+ settings.inverseView = zKamera->getInverseViewMatrix();
|
|
|
|
|
+ settings.minDistance = zKamera->getMinDistance();
|
|
|
|
|
+ settings.maxDistance = zKamera->getMaxDistance();
|
|
|
|
|
+ settings.useRays = 1;
|
|
|
|
|
+ settings.renderGui = (int)guiVisible;
|
|
|
|
|
+ rayGenSettingsBuffer->setData(&settings, 1);
|
|
|
|
|
+ rayGenSettingsBuffer->copyToGPU(sizeof(settings));
|
|
|
|
|
+ if (defaultRayGenerationShaderFunction)
|
|
|
|
|
+ {
|
|
|
|
|
+ globalDescriptorHeap->updateTextureInput(
|
|
|
|
|
+ 0, DX12_SHADER_REGISTER_U_UNORDERED_ACCESS, zTarget);
|
|
|
|
|
+ globalDescriptorHeap->updateTLASInput(
|
|
|
|
|
+ 3, DX12_SHADER_REGISTER_T_SHADER_RESOURCE, tlas);
|
|
|
|
|
+ }
|
|
|
|
|
+ sbt->endUpdate(device, directCommandQueue);
|
|
|
|
|
+ ID3D12DescriptorHeap* heaps[] = {globalDescriptorHeap->zDescriptorHeap(),
|
|
|
|
|
+ samplerDescriptorHeap->zDescriptorHeap()};
|
|
|
|
|
+ directCommandQueue->zCommandList()->SetDescriptorHeaps(2, heaps);
|
|
|
|
|
+
|
|
|
|
|
+ D3D12_DISPATCH_RAYS_DESC desc;
|
|
|
|
|
+ sbt->fillDispatchRaysDesc(&desc);
|
|
|
|
|
+ desc.Width = zTarget->zImage()->getWidth();
|
|
|
|
|
+ desc.Height = zTarget->zImage()->getHeight();
|
|
|
|
|
+ desc.Depth = 1;
|
|
|
|
|
+ directCommandQueue->zCommandList()->SetPipelineState1(
|
|
|
|
|
+ pipeline->zPipelineState());
|
|
|
|
|
+ directCommandQueue->zCommandList()->DispatchRays(&desc);
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+void Framework::DirectX12::renderWorld(World3D* zWorld,
|
|
|
|
|
+ DX12TLAS* zTLAS,
|
|
|
|
|
+ DX12ShaderBindingTable* zSBT,
|
|
|
|
|
+ int& objectIndex)
|
|
|
|
|
+{
|
|
|
|
|
+ Mat4<float> identity = Mat4<float>::identity();
|
|
|
|
|
+ zWorld->render([this, &zTLAS, &objectIndex, &identity, &zSBT](
|
|
|
|
|
+ Model3D* obj) {
|
|
|
DX12RenderingData* renderingData
|
|
DX12RenderingData* renderingData
|
|
|
= dynamic_cast<DX12RenderingData*>(obj->zRenderingData());
|
|
= dynamic_cast<DX12RenderingData*>(obj->zRenderingData());
|
|
|
if (!renderingData)
|
|
if (!renderingData)
|
|
@@ -295,12 +328,13 @@ void Framework::DirectX12::renderKamera(
|
|
|
renderingData->lastBlasCount = blasModel->getBufferCount();
|
|
renderingData->lastBlasCount = blasModel->getBufferCount();
|
|
|
}
|
|
}
|
|
|
ArrayIterator<int> boneIds = blasModel->zBoneIds()->begin();
|
|
ArrayIterator<int> boneIds = blasModel->zBoneIds()->begin();
|
|
|
- instanceIndex = 0;
|
|
|
|
|
|
|
+ int instanceIndex = 0;
|
|
|
for (const DX12BLAS* blas : *blasModel->zBLAS())
|
|
for (const DX12BLAS* blas : *blasModel->zBLAS())
|
|
|
{
|
|
{
|
|
|
if (changed)
|
|
if (changed)
|
|
|
{
|
|
{
|
|
|
- D3D12_RAYTRACING_INSTANCE_DESC* desc = tlas->nextInstanceDesc();
|
|
|
|
|
|
|
+ D3D12_RAYTRACING_INSTANCE_DESC* desc
|
|
|
|
|
+ = zTLAS->nextInstanceDesc();
|
|
|
desc->InstanceID = objectIndex;
|
|
desc->InstanceID = objectIndex;
|
|
|
desc->InstanceContributionToHitGroupIndex = objectIndex;
|
|
desc->InstanceContributionToHitGroupIndex = objectIndex;
|
|
|
desc->Flags = D3D12_RAYTRACING_INSTANCE_FLAG_NONE;
|
|
desc->Flags = D3D12_RAYTRACING_INSTANCE_FLAG_NONE;
|
|
@@ -313,10 +347,10 @@ void Framework::DirectX12::renderKamera(
|
|
|
}
|
|
}
|
|
|
else
|
|
else
|
|
|
{
|
|
{
|
|
|
- tlas->nextInstanceDesc();
|
|
|
|
|
|
|
+ zTLAS->nextInstanceDesc();
|
|
|
}
|
|
}
|
|
|
boneIds++;
|
|
boneIds++;
|
|
|
- fillShaderBindingTable(sbt,
|
|
|
|
|
|
|
+ fillShaderBindingTable(zSBT,
|
|
|
obj,
|
|
obj,
|
|
|
objectIndex,
|
|
objectIndex,
|
|
|
blas,
|
|
blas,
|
|
@@ -325,35 +359,6 @@ void Framework::DirectX12::renderKamera(
|
|
|
objectIndex++;
|
|
objectIndex++;
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
- tlas->endUpdate();
|
|
|
|
|
- settings.inverseProjection = zKamera->getInverseProjectionMatrix();
|
|
|
|
|
- settings.inverseView = zKamera->getInverseViewMatrix();
|
|
|
|
|
- settings.minDistance = zKamera->getMinDistance();
|
|
|
|
|
- settings.maxDistance = zKamera->getMaxDistance();
|
|
|
|
|
- settings.useRays = 1;
|
|
|
|
|
- settings.renderGui = (int)guiVisible;
|
|
|
|
|
- rayGenSettingsBuffer->setData(&settings, 1);
|
|
|
|
|
- rayGenSettingsBuffer->copyToGPU(sizeof(settings));
|
|
|
|
|
- if (defaultRayGenerationShaderFunction)
|
|
|
|
|
- {
|
|
|
|
|
- globalDescriptorHeap->updateTextureInput(
|
|
|
|
|
- 0, DX12_SHADER_REGISTER_U_UNORDERED_ACCESS, zTarget);
|
|
|
|
|
- globalDescriptorHeap->updateTLASInput(
|
|
|
|
|
- 3, DX12_SHADER_REGISTER_T_SHADER_RESOURCE, tlas);
|
|
|
|
|
- }
|
|
|
|
|
- sbt->endUpdate(device, directCommandQueue);
|
|
|
|
|
- ID3D12DescriptorHeap* heaps[] = {globalDescriptorHeap->zDescriptorHeap(),
|
|
|
|
|
- samplerDescriptorHeap->zDescriptorHeap()};
|
|
|
|
|
- directCommandQueue->zCommandList()->SetDescriptorHeaps(2, heaps);
|
|
|
|
|
-
|
|
|
|
|
- D3D12_DISPATCH_RAYS_DESC desc;
|
|
|
|
|
- sbt->fillDispatchRaysDesc(&desc);
|
|
|
|
|
- desc.Width = zTarget->zImage()->getWidth();
|
|
|
|
|
- desc.Height = zTarget->zImage()->getHeight();
|
|
|
|
|
- desc.Depth = 1;
|
|
|
|
|
- directCommandQueue->zCommandList()->SetPipelineState1(
|
|
|
|
|
- pipeline->zPipelineState());
|
|
|
|
|
- directCommandQueue->zCommandList()->DispatchRays(&desc);
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
void Framework::DirectX12::initializePipeline()
|
|
void Framework::DirectX12::initializePipeline()
|