Skip to content

Commit

Permalink
feat: ibl
Browse files Browse the repository at this point in the history
  • Loading branch information
doodlum committed Dec 28, 2024
1 parent 080f9a5 commit 7a9c81e
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 32 deletions.
23 changes: 17 additions & 6 deletions src/Brixelizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,12 +198,23 @@ void Brixelizer::CreatedWrappedResource(D3D11_TEXTURE2D_DESC a_texDesc, Brixeliz
}

if (a_texDesc.BindFlags & D3D11_BIND_UNORDERED_ACCESS) {
D3D11_UNORDERED_ACCESS_VIEW_DESC uavDesc = {};
uavDesc.Format = a_texDesc.Format;
uavDesc.ViewDimension = D3D11_UAV_DIMENSION_TEXTURE2D;
uavDesc.Texture2D.MipSlice = 0;

DX::ThrowIfFailed(d3d11Device->CreateUnorderedAccessView(a_resource.resource11, &uavDesc, &a_resource.uav));
if (a_texDesc.ArraySize > 1)
{
D3D11_UNORDERED_ACCESS_VIEW_DESC uavDesc = {};
uavDesc.Format = a_texDesc.Format;
uavDesc.ViewDimension = D3D11_UAV_DIMENSION_TEXTURE2DARRAY;
uavDesc.Texture2DArray.FirstArraySlice = 0;
uavDesc.Texture2DArray.ArraySize = a_texDesc.ArraySize;

DX::ThrowIfFailed(d3d11Device->CreateUnorderedAccessView(a_resource.resource11, &uavDesc, &a_resource.uav));
} else {
D3D11_UNORDERED_ACCESS_VIEW_DESC uavDesc = {};
uavDesc.Format = a_texDesc.Format;
uavDesc.ViewDimension = D3D11_UAV_DIMENSION_TEXTURE2D;
uavDesc.Texture2D.MipSlice = 0;

DX::ThrowIfFailed(d3d11Device->CreateUnorderedAccessView(a_resource.resource11, &uavDesc, &a_resource.uav));
}
}

//{
Expand Down
37 changes: 12 additions & 25 deletions src/Brixelizer/BrixelizerGIContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,30 +40,11 @@ void BrixelizerGIContext::CreateMiscTextures()
Brixelizer::CreatedWrappedResource(texDesc, specularGi);
Brixelizer::CreatedWrappedResource(texDesc, roughness);

{
D3D12_RESOURCE_DESC textureDesc = {};
textureDesc.Dimension = D3D12_RESOURCE_DIMENSION_TEXTURE2D;
textureDesc.Alignment = 0;
textureDesc.Width = 512;
textureDesc.Height = 512;
textureDesc.DepthOrArraySize = 6;
textureDesc.MipLevels = 1;
textureDesc.Format = DXGI_FORMAT_R16G16B16A16_FLOAT;
textureDesc.SampleDesc.Count = 1;
textureDesc.SampleDesc.Quality = 0;
textureDesc.Flags = D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET | D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS;
textureDesc.Layout = D3D12_TEXTURE_LAYOUT_UNKNOWN;

// Create the texture resource (cubemap)
CD3DX12_HEAP_PROPERTIES heapProps(D3D12_HEAP_TYPE_DEFAULT);
Brixelizer::GetSingleton()->d3d12Device->CreateCommittedResource(
&heapProps,
D3D12_HEAP_FLAG_NONE,
&textureDesc,
D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE,
nullptr,
IID_PPV_ARGS(&environmentMap));
}
texDesc.ArraySize = 6;
texDesc.Width = 128;
texDesc.Height = 128;

Brixelizer::CreatedWrappedResource(texDesc, environmentMap);
}

HRESULT UploadDDSTexture(
Expand Down Expand Up @@ -240,11 +221,15 @@ void BrixelizerGIContext::CopyHistoryResources()
auto& context = State::GetSingleton()->context;

auto renderer = RE::BSGraphics::Renderer::GetSingleton();

auto& main = renderer->GetRuntimeData().renderTargets[Deferred::GetSingleton()->forwardRenderTargets[0]];

context->CopyResource(historyDepth.resource11, depth.resource11);
context->CopyResource(historyNormal.resource11, normal.resource11);
context->CopyResource(prevLitOutput.resource11, main.texture);

auto& cubemap = renderer->GetRendererData().cubemapRenderTargets[RE::RENDER_TARGETS_CUBEMAP::kREFLECTIONS];
context->CopyResource(environmentMap.resource11, cubemap.texture);
}

void BrixelizerGIContext::UpdateBrixelizerGIContext(ID3D12GraphicsCommandList* cmdList)
Expand Down Expand Up @@ -311,7 +296,9 @@ void BrixelizerGIContext::UpdateBrixelizerGIContext(ID3D12GraphicsCommandList* c
giDispatchDesc.prevLitOutput = ffxGetResourceDX12(prevLitOutput.resource.get(), ffxGetResourceDescriptionDX12(prevLitOutput.resource.get()), L"PrevLitOutput");

giDispatchDesc.noiseTexture = ffxGetResourceDX12(noiseTextures[noiseIndex].get(), ffxGetResourceDescriptionDX12(noiseTextures[noiseIndex].get()), L"Noise");
giDispatchDesc.environmentMap = ffxGetResourceDX12(environmentMap.get(), ffxGetResourceDescriptionDX12(environmentMap.get()), L"EnvironmentMap");

giDispatchDesc.environmentMap = ffxGetResourceDX12(environmentMap.resource.get(), ffxGetResourceDescriptionDX12(environmentMap.resource.get()), L"EnvironmentMap");
giDispatchDesc.environmentMap.description.type = FFX_RESOURCE_TYPE_TEXTURE_CUBE;

giDispatchDesc.sdfAtlas = ffxGetResourceDX12(brixelizerContext->sdfAtlas.get(), ffxGetResourceDescriptionDX12(brixelizerContext->sdfAtlas.get()), nullptr, FFX_RESOURCE_STATE_COMPUTE_READ);
giDispatchDesc.bricksAABBs = ffxGetResourceDX12(brixelizerContext->brickAABBs.get(), ffxGetResourceDescriptionDX12(brixelizerContext->brickAABBs.get()), nullptr, FFX_RESOURCE_STATE_COMPUTE_READ);
Expand Down
2 changes: 1 addition & 1 deletion src/Brixelizer/BrixelizerGIContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ class BrixelizerGIContext
Brixelizer::WrappedResource historyNormal;
Brixelizer::WrappedResource prevLitOutput;
Brixelizer::WrappedResource roughness;
Brixelizer::WrappedResource environmentMap;

winrt::com_ptr<ID3D12Resource> environmentMap;
winrt::com_ptr<ID3D12Resource> noiseTextures[16];

float environmentIntensity = 0.1f;
Expand Down

0 comments on commit 7a9c81e

Please sign in to comment.