Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
gameknife committed Oct 6, 2024
2 parents ecf4997 + 0cc51b8 commit f3a2ec5
Show file tree
Hide file tree
Showing 13 changed files with 46 additions and 60 deletions.
Binary file modified assets/models/qx50.glb
Binary file not shown.
19 changes: 11 additions & 8 deletions assets/shaders/Accumulate.comp
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@ void main() {

vec4 src = imageLoad(NewSourceImage, ipos);

bool isEvenFrame = Camera.TotalFrames % 2 == 0;
bool isEvenFrame = Camera.TotalFrames % 2 == 0 ? true : false;

bool useHistory = true;
vec4 final = src;
vec2 motion = imageLoad(MotionVectorImage, ipos).rg;
ivec2 previpos = ivec2( floor(ipos + motion) );
const bool inside = all(lessThan(previpos, ivec2(Camera.ViewportRect.xy + Camera.ViewportRect.zw))) && all(greaterThanEqual(previpos, ivec2(Camera.ViewportRect.xy)));
const bool check = length(motion) > 0.01;
const bool inside = all(lessThan(previpos, ivec2(Camera.ViewportRect.xy + Camera.ViewportRect.zw))) && all(greaterThanEqual(previpos, ivec2(Camera.ViewportRect.xy) + ivec2(-1,-1)));
const bool check = length(motion) > 0.01 ? true : false;
// fetch visibility to validate the history
uint current_primitive_index = isEvenFrame ? imageLoad(VisibilityBuffer, ipos).r : imageLoad(Visibility1Buffer, ipos).r;
if(Camera.TotalFrames == 0 || !inside)
Expand Down Expand Up @@ -127,14 +127,17 @@ void main() {
imageStore(AccumulateImage, ipos, final);
}

uint realInstanceId = FetchPrimitiveIndex(current_primitive_index);
if(realInstanceId == Camera.SelectedId)
if(Camera.ShowEdge)
{
if( EdgeDetect(current_primitive_index, isEvenFrame, ipos ) )
uint realInstanceId = FetchPrimitiveIndex(current_primitive_index);
if(realInstanceId == Camera.SelectedId)
{
//final.rgb = vec3(1,0.05,0) * Camera.PaperWhiteNit;
if( EdgeDetect(current_primitive_index, isEvenFrame, ipos ) )
{
final.rgb = vec3(1,1,0.05) * Camera.PaperWhiteNit;
}
}
}

imageStore(OutImage, ipos, vec4( final.rgb, 1.0 ));
}
30 changes: 0 additions & 30 deletions assets/shaders/Compose.comp

This file was deleted.

1 change: 1 addition & 0 deletions assets/shaders/common/UniformBufferObject.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ struct UniformBufferObject
uint AdaptiveSteps;
glbool TAA;
uint SelectedId;
glbool ShowEdge;

float BFSigma;
float BFSigmaLum;
Expand Down
2 changes: 1 addition & 1 deletion src/Options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Options::Options(const int argc, const char* argv[])
("bounces", value<uint32_t>(&Bounces)->default_value(4), "The general limit number of bounces per ray.")
("max-bounces", value<uint32_t>(&MaxBounces)->default_value(10), "The maximum bounces per ray.")
("temporal", value<uint32_t>(&Temporal)->default_value(32), "The number of temporal frames.")
("denoiser", bool_switch(&Denoiser)->default_value(true), "Use Denoiser.")
("nodenoiser", bool_switch(&NoDenoiser)->default_value(false), "Not Use Denoiser.")
("adaptivesample", bool_switch(&AdaptiveSample)->default_value(false), "use adaptive sample to improve render quality.")

;
Expand Down
2 changes: 1 addition & 1 deletion src/Options.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class Options final
bool Benchmark{};
bool SaveFile{};
bool RenderDoc{};
bool Denoiser{};
bool NoDenoiser{};
bool ForceSDR{};
std::string locale{};

Expand Down
17 changes: 11 additions & 6 deletions src/Runtime/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,15 +134,15 @@ UserSettings CreateUserSettings(const Options& options)
userSettings.UseCheckerBoardRendering = false;
userSettings.TemporalFrames = options.Benchmark ? 256 : options.Temporal;

userSettings.Denoiser = options.Denoiser;
userSettings.Denoiser = options.Benchmark ? false : !options.NoDenoiser;

userSettings.PaperWhiteNit = 600.f;

userSettings.SunRotation = 0.5f;
userSettings.SunLuminance = 500.f;
userSettings.SkyIntensity = 100.f;

userSettings.AutoFocus = false;
userSettings.RequestRayCast = false;

userSettings.DenoiseSigma = 0.5f;
userSettings.DenoiseSigmaLum = 10.0f;
Expand Down Expand Up @@ -341,7 +341,7 @@ Assets::UniformBufferObject NextRendererApplication::GetUniformBufferObject(cons
Assets::RayCastResult rayResult {};
renderer_->GetLastRaycastResult(rayResult);

if( userSettings_.AutoFocus )
if( userSettings_.RequestRayCast )
{
if(rayResult.Hitted )
{
Expand All @@ -354,7 +354,7 @@ Assets::UniformBufferObject NextRendererApplication::GetUniformBufferObject(cons
}

// only active one frame
userSettings_.AutoFocus = false;
userSettings_.RequestRayCast = false;
}

userSettings_.HitResult = rayResult;
Expand Down Expand Up @@ -399,6 +399,11 @@ Assets::UniformBufferObject NextRendererApplication::GetUniformBufferObject(cons
ubo.BFSigmaNormal = userSettings_.DenoiseSigmaNormal;
ubo.BFSize = userSettings_.Denoiser ? userSettings_.DenoiseSize : 0;

#if WITH_EDITOR
ubo.ShowEdge = true;
#endif


// Other Setup
renderer_->supportDenoiser_ = userSettings_.Denoiser;
renderer_->visualDebug_ = userSettings_.ShowVisualDebug;
Expand Down Expand Up @@ -504,7 +509,7 @@ void NextRendererApplication::OnRendererPostRender(VkCommandBuffer commandBuffer

//Renderer::visualDebug_ = userSettings_.ShowVisualDebug;

userInterface_->Render(commandBuffer, imageIndex, stats, renderer_->GpuTimer(), scene_.get());
userInterface_->Render(commandBuffer, renderer_->SwapChain(), imageIndex, stats, renderer_->GpuTimer(), scene_.get());
}

void NextRendererApplication::OnKey(int key, int scancode, int action, int mods)
Expand Down Expand Up @@ -593,7 +598,7 @@ void NextRendererApplication::OnMouseButton(const int button, const int action,
{
if( glm::distance(pressMousePos_, mousePos_) < 1.0f )
{
userSettings_.AutoFocus = true;
userSettings_.RequestRayCast = true;
}
}
#endif
Expand Down
7 changes: 2 additions & 5 deletions src/Runtime/UserInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ UserInterface::UserInterface(
const Vulkan::DepthBuffer& depthBuffer,
UserSettings& userSettings,
Vulkan::RenderImage& viewportImage) :
swapChain_(swapChain),
userSettings_(userSettings)

{
Expand Down Expand Up @@ -197,8 +196,6 @@ UserInterface::UserInterface(
const auto scaleFactor = window.ContentScale();
#endif


//ImGui::StyleColorsDark();
MainWindowStyle();
ImGui::GetStyle().ScaleAllSizes(scaleFactor);

Expand Down Expand Up @@ -398,7 +395,7 @@ void UserInterface::ToolbarUI()
ImGui::End();
}

void UserInterface::Render(VkCommandBuffer commandBuffer, uint32_t imageIdx, const Statistics& statistics, Vulkan::VulkanGpuTimer* gpuTimer, Assets::Scene* scene)
void UserInterface::Render(VkCommandBuffer commandBuffer, const Vulkan::SwapChain& swapChain, uint32_t imageIdx, const Statistics& statistics, Vulkan::VulkanGpuTimer* gpuTimer, Assets::Scene* scene)
{
GUserInterface = this;

Expand Down Expand Up @@ -427,7 +424,7 @@ void UserInterface::Render(VkCommandBuffer commandBuffer, uint32_t imageIdx, con
ImGuiID id = DockSpaceUI();
ToolbarUI();
ImGuiDockNode* node = ImGui::DockBuilderGetCentralNode(id);
swapChain_.UpdateEditorViewport(Utilities::Math::floorToInt(node->Pos.x - viewport->Pos.x), Utilities::Math::floorToInt(node->Pos.y - viewport->Pos.y), Utilities::Math::ceilToInt(node->Size.x), Utilities::Math::ceilToInt(node->Size.y));
swapChain.UpdateEditorViewport(Utilities::Math::floorToInt(node->Pos.x - viewport->Pos.x), Utilities::Math::floorToInt(node->Pos.y - viewport->Pos.y), Utilities::Math::ceilToInt(node->Size.x), Utilities::Math::ceilToInt(node->Size.y));
MainWindowGUI(*editorGUI_, scene, statistics, id, firstRun);
#else
DrawSettings();
Expand Down
3 changes: 1 addition & 2 deletions src/Runtime/UserInterface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class UserInterface final
Vulkan::RenderImage& viewportImage);
~UserInterface();

void Render(VkCommandBuffer commandBuffer, uint32_t imageIdx, const Statistics& statistics, Vulkan::VulkanGpuTimer* gpuTimer, Assets::Scene* scene);
void Render(VkCommandBuffer commandBuffer, const Vulkan::SwapChain& swapChain, uint32_t imageIdx, const Statistics& statistics, Vulkan::VulkanGpuTimer* gpuTimer, Assets::Scene* scene);

bool WantsToCaptureKeyboard() const;
bool WantsToCaptureMouse() const;
Expand All @@ -85,7 +85,6 @@ class UserInterface final
ImGuiID DockSpaceUI();
void ToolbarUI();

const Vulkan::SwapChain& swapChain_;
void DrawSettings();
void DrawOverlay(const Statistics& statistics, Vulkan::VulkanGpuTimer* gpuTimer);
void DrawIndicator(uint32_t frameCount);
Expand Down
2 changes: 1 addition & 1 deletion src/Runtime/UserSettings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ struct UserSettings final
float RawFieldOfView;
float Aperture;
float FocusDistance;
bool AutoFocus;
bool RequestRayCast;

float SkyRotation;
float SunRotation;
Expand Down
8 changes: 5 additions & 3 deletions src/Vulkan/RayQuery/RayQueryRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ namespace Vulkan::RayTracing
vkCmdBindPipeline(commandBuffer, VK_PIPELINE_BIND_POINT_COMPUTE, accumulatePipeline_->Handle());
vkCmdBindDescriptorSets(commandBuffer, VK_PIPELINE_BIND_POINT_COMPUTE,
accumulatePipeline_->PipelineLayout().Handle(), 0, 1, DescriptorSets, 0, nullptr);
vkCmdDispatch(commandBuffer, SwapChain().RenderExtent().width / 8, SwapChain().RenderExtent().height / 4, 1);
vkCmdDispatch(commandBuffer, Utilities::Math::GetSafeDispatchCount(SwapChain().RenderExtent().width, 8), Utilities::Math::GetSafeDispatchCount(SwapChain().RenderExtent().width, 4), 1);
}

{
Expand Down Expand Up @@ -221,7 +221,7 @@ namespace Vulkan::RayTracing
vkCmdBindPipeline(commandBuffer, VK_PIPELINE_BIND_POINT_COMPUTE, composePipelineNonDenoiser_->Handle());
vkCmdBindDescriptorSets(commandBuffer, VK_PIPELINE_BIND_POINT_COMPUTE,
composePipelineNonDenoiser_->PipelineLayout().Handle(), 0, 1, DescriptorSets, 0, nullptr);
vkCmdDispatch(commandBuffer, SwapChain().RenderExtent().width / 16, SwapChain().RenderExtent().height / 16, 1);
vkCmdDispatch(commandBuffer, Utilities::Math::GetSafeDispatchCount(SwapChain().RenderExtent().width, 16), Utilities::Math::GetSafeDispatchCount(SwapChain().RenderExtent().width, 16), 1);
}

ImageMemoryBarrier::Insert(commandBuffer, SwapChain().Images()[imageIndex], subresourceRange,
Expand Down Expand Up @@ -264,6 +264,7 @@ namespace Vulkan::RayTracing
}

#if !ANDROID
if(supportRayCast_)
{
SCOPED_GPU_TIMER("raycast");

Expand All @@ -273,7 +274,7 @@ namespace Vulkan::RayTracing
raycastPipeline_->PipelineLayout().Handle(), 0, 1, DescriptorSets, 0, nullptr);
vkCmdDispatch(commandBuffer, 1, 1, 1);
}

#if WITH_OIDN
if (supportDenoiser_)
{
VkImageSubresourceRange subresourceRange = {};
Expand Down Expand Up @@ -307,6 +308,7 @@ namespace Vulkan::RayTracing
VK_IMAGE_LAYOUT_GENERAL);
}
#endif
#endif


}
Expand Down
14 changes: 11 additions & 3 deletions src/Vulkan/RayTracing/RayTraceBaseRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ namespace Vulkan::RayTracing
const bool enableValidationLayers) :
Vulkan::VulkanBaseRenderer(window, presentMode, enableValidationLayers)
{
supportRayCast_ = true;
}

RayTraceBaseRenderer::~RayTraceBaseRenderer()
Expand Down Expand Up @@ -150,9 +151,16 @@ namespace Vulkan::RayTracing
{
VulkanBaseRenderer::AfterRenderCmd();

rayCastBuffer_->SetContext(cameraCenterCastContext_);
rayCastBuffer_->SyncWithGPU();
cameraCenterCastResult_ = rayCastBuffer_->GetResult();
if(supportRayCast_)
{
rayCastBuffer_->SetContext(cameraCenterCastContext_);
rayCastBuffer_->SyncWithGPU();
cameraCenterCastResult_ = rayCastBuffer_->GetResult();
}
else
{
cameraCenterCastResult_ = Assets::RayCastResult();
}
}


Expand Down
1 change: 1 addition & 0 deletions src/Vulkan/VulkanBaseRenderer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,7 @@ namespace Vulkan
bool checkerboxRendering_{};
bool supportRayTracing_ {};
bool supportDenoiser_ {};
bool supportRayCast_ {};
int frameCount_{};
bool forceSDR_{};
bool visualDebug_{};
Expand Down

0 comments on commit f3a2ec5

Please sign in to comment.