Skip to content

Commit

Permalink
Added a Reference Image feature to quickly compare the results of dif…
Browse files Browse the repository at this point in the history
…ferent rendering techniques.
  • Loading branch information
apanteleev committed Mar 30, 2023
1 parent 6c0b258 commit 7b448c6
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/RenderTargets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,10 @@ RenderTargets::RenderTargets(nvrhi::IDevice* device, int2 size)
desc.debugName = "ResolvedColor";
ResolvedColor = device->createTexture(desc);

desc.format = nvrhi::Format::RGBA16_FLOAT;
desc.debugName = "ReferenceColor";
ReferenceColor = device->createTexture(desc);

GBufferFramebuffer = std::make_shared<engine::FramebufferFactory>(device);
GBufferFramebuffer->DepthTarget = DeviceDepth;
GBufferFramebuffer->RenderTargets = {
Expand Down
1 change: 1 addition & 0 deletions src/RenderTargets.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ class RenderTargets
nvrhi::TextureHandle PrevSpecularConfidence;

nvrhi::TextureHandle DebugColor;
nvrhi::TextureHandle ReferenceColor;

std::shared_ptr<donut::engine::FramebufferFactory> LdrFramebuffer;
std::shared_ptr<donut::engine::FramebufferFactory> ResolvedFramebuffer;
Expand Down
30 changes: 29 additions & 1 deletion src/UserInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -761,6 +761,33 @@ void UserInterface::PostProcessSettings()
ImGui::TextDisabled("// %d frame(s)", m_ui.numAccumulatedFrames);
}

// Reference image UI
{
ImGui::Separator();
ImGui::TextUnformatted("Reference Image:");
ShowHelpMarker(
"Allows you to store the current rendering output into a texture, "
"and later show this texture side-by-side with new rendering output "
"or toggle between the two for comparison. Most useful with the "
"Accumulation mode above."
);
if (ImGui::Button("Store"))
m_ui.storeReferenceImage = true;
if (m_ui.referenceImageCaptured)
{
ImGui::SameLine();
if (ImGui::Button("Toggle"))
{
if (m_ui.referenceImageSplit == 0.f)
m_ui.referenceImageSplit = 1.f;
else
m_ui.referenceImageSplit = 0.f;
}
ImGui::SameLine(160.f);
ImGui::SliderFloat("Split Display", &m_ui.referenceImageSplit, 0.f, 1.f, "%.2f");
}
ImGui::Separator();
}

#ifdef WITH_DLSS
if (m_ui.dlssAvailable)
Expand All @@ -772,11 +799,12 @@ void UserInterface::PostProcessSettings()
m_ui.resetAccumulation |= ImGui::Checkbox("Apply Textures in Compositing", (bool*)&m_ui.enableTextures);

ImGui::Checkbox("Tone mapping", (bool*)&m_ui.enableToneMapping);
ImGui::SameLine();
ImGui::SameLine(160.f);
ImGui::SliderFloat("Exposure bias", &m_ui.exposureBias, -4.f, 2.f);

ImGui::Checkbox("Bloom", (bool*)&m_ui.enableBloom);

ImGui::Separator();
ImGui::PushItemWidth(150.f);
ImGui::Combo("Visualization", (int*)&m_ui.visualizationMode,
"None\0"
Expand Down
3 changes: 3 additions & 0 deletions src/UserInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,9 @@ struct UIData
uint32_t visualizationMode = 0; // See the VIS_MODE_XXX constants in ShaderParameters.h
uint32_t debugRenderOutputBuffer = 0; // See DebugRenderOutput enum above

bool storeReferenceImage = false;
bool referenceImageCaptured = false;
float referenceImageSplit = 0.f;

GBufferSettings gbufferSettings;
LightingPasses::RenderSettings lightingSettings;
Expand Down
31 changes: 31 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1353,6 +1353,37 @@ class SceneRenderer : public app::ApplicationBase
m_BloomPass->Render(m_CommandList, m_RenderTargets->ResolvedFramebuffer, m_UpscaledView, bloomSource, 32.f, 0.005f);
}

// Reference image functionality:
{
// When the camera is moved, discard the previously stored image, if any, and disable its display.
if (!cameraIsStatic)
{
m_ui.referenceImageCaptured = false;
m_ui.referenceImageSplit = 0.f;
}

// When the user clicks the "Store" button, copy the ResolvedColor texture into ReferenceColor.
if (m_ui.storeReferenceImage)
{
m_CommandList->copyTexture(m_RenderTargets->ReferenceColor, nvrhi::TextureSlice(), m_RenderTargets->ResolvedColor, nvrhi::TextureSlice());
m_ui.storeReferenceImage = false;
m_ui.referenceImageCaptured = true;
}

// When the "Split Display" parameter is nonzero, show a portion of the previously stored
// ReferenceColor texture on the left side of the screen by copying it into the ResolvedColor texture.
if (m_ui.referenceImageSplit > 0.f)
{
engine::BlitParameters blitParams;
blitParams.sourceTexture = m_RenderTargets->ReferenceColor;
blitParams.sourceBox.m_maxs = float2(m_ui.referenceImageSplit, 1.f);
blitParams.targetFramebuffer = m_RenderTargets->ResolvedFramebuffer->GetFramebuffer(nvrhi::AllSubresources);
blitParams.targetBox = blitParams.sourceBox;
blitParams.sampler = engine::BlitSampler::Point;
m_CommonPasses->BlitTexture(m_CommandList, blitParams, &m_BindingCache);
}
}

if(m_ui.enableToneMapping)
{ // Tone mapping
render::ToneMappingParameters ToneMappingParams;
Expand Down

0 comments on commit 7b448c6

Please sign in to comment.