From 59b73420d6560bb368763504222ae6ae93fc4188 Mon Sep 17 00:00:00 2001 From: Dynamitos Date: Mon, 30 Jun 2025 21:15:14 +0200 Subject: [PATCH] Fixing ray tracing lens --- CMakeLists.txt | 3 +- CMakePresets.json | 52 ++++++++++--------- res/shaders/raytracing/ClosestHit.slang | 3 +- res/shaders/raytracing/RayGen.slang | 3 +- src/Engine/Graphics/RenderPass/BasePass.cpp | 4 +- .../Graphics/RenderPass/RayTracingPass.cpp | 1 - src/Engine/Graphics/Vulkan/Graphics.h | 10 ++-- src/Engine/Graphics/Vulkan/PipelineCache.cpp | 2 - src/Engine/MinimalEngine.h | 4 +- src/Engine/Platform/Linux/GameInterface.h | 1 - 10 files changed, 44 insertions(+), 39 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9185d2a..66cfcec 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -113,7 +113,8 @@ target_link_libraries(Benchmark PRIVATE Engine) target_include_directories(Benchmark PRIVATE src/Benchmark) if(MSVC) - add_definitions(-D_CRT_SECURE_NO_WARNINGS) + target_compile_definitions(Engine PUBLIC _CRT_SECURE_NO_WARNINGS) + target_compile_definitions(Engine PUBLIC WIN32) target_compile_options(Engine PUBLIC /Zi /MP14 /W4 /wd4505) target_compile_options(Editor PUBLIC /Zi /MP14 /W4) target_sources(Engine INTERFACE diff --git a/CMakePresets.json b/CMakePresets.json index be62230..0380302 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -7,48 +7,52 @@ }, "configurePresets": [ { - "name": "default", - "displayName": "Default (Release)", + "name": "release", + "displayName": "Release (no ASan)", "description": "Release build without sanitizers", "binaryDir": "${sourceDir}/build", - "cacheVariables": { - "CMAKE_BUILD_TYPE": "RelWithDebInfo" - } + "cacheVariables": { + "CMAKE_BUILD_TYPE": "RelWithDebInfo", + "CMAKE_INSTALL_PREFIX": "C:/Program Files/Seele" + } }, { - "name": "default-asan", - "displayName": "Default (Release + ASan)", + "name": "release-asan", + "displayName": "Release (ASan)", "description": "Release build with Address Sanitizer", "binaryDir": "${sourceDir}/build", - "cacheVariables": { - "CMAKE_BUILD_TYPE": "RelWithDebInfo", - "CMAKE_CXX_FLAGS": "-fsanitize=address -fno-omit-frame-pointer", - "CMAKE_C_FLAGS": "-fsanitize=address -fno-omit-frame-pointer", - "CMAKE_EXE_LINKER_FLAGS": "-fsanitize=address", - "CMAKE_SHARED_LINKER_FLAGS": "-fsanitize=address" - } + "cacheVariables": { + "CMAKE_BUILD_TYPE": "RelWithDebInfo", + "CMAKE_CXX_FLAGS": "-fsanitize=address -fno-omit-frame-pointer", + "CMAKE_C_FLAGS": "-fsanitize=address -fno-omit-frame-pointer", + "CMAKE_EXE_LINKER_FLAGS": "-fsanitize=address", + "CMAKE_SHARED_LINKER_FLAGS": "-fsanitize=address", + "CMAKE_INSTALL_PREFIX": "C:/Program Files/Seele" + } }, { "name": "debug", "displayName": "Debug (no ASan)", "description": "Debug build without sanitizers", "binaryDir": "${sourceDir}/build", - "cacheVariables": { - "CMAKE_BUILD_TYPE": "Debug" - } + "cacheVariables": { + "CMAKE_BUILD_TYPE": "Debug", + "CMAKE_INSTALL_PREFIX": "C:/Program Files/Seele" + } }, { "name": "debug-asan", "displayName": "Debug (ASan)", "description": "Debug build with Address Sanitizer", "binaryDir": "${sourceDir}/build", - "cacheVariables": { - "CMAKE_BUILD_TYPE": "Debug", - "CMAKE_CXX_FLAGS": "-fsanitize=address -fno-omit-frame-pointer", - "CMAKE_C_FLAGS": "-fsanitize=address -fno-omit-frame-pointer", - "CMAKE_EXE_LINKER_FLAGS": "-fsanitize=address", - "CMAKE_SHARED_LINKER_FLAGS": "-fsanitize=address" - } + "cacheVariables": { + "CMAKE_BUILD_TYPE": "Debug", + "CMAKE_CXX_FLAGS": "-fsanitize=address -fno-omit-frame-pointer", + "CMAKE_C_FLAGS": "-fsanitize=address -fno-omit-frame-pointer", + "CMAKE_EXE_LINKER_FLAGS": "-fsanitize=address", + "CMAKE_SHARED_LINKER_FLAGS": "-fsanitize=address", + "CMAKE_INSTALL_PREFIX": "C:/Program Files/Seele" + } } ] } \ No newline at end of file diff --git a/res/shaders/raytracing/ClosestHit.slang b/res/shaders/raytracing/ClosestHit.slang index 758bdf9..24ecb3f 100644 --- a/res/shaders/raytracing/ClosestHit.slang +++ b/res/shaders/raytracing/ClosestHit.slang @@ -5,6 +5,7 @@ import Scene; import RayTracingData; import VertexData; import Material; +import StaticMeshVertexData; import MATERIAL_FILE_NAME; // simplification: all BLAS only have 1 geometry @@ -194,7 +195,7 @@ void closestHit(inout RayPayload hitValue, in BuiltInTriangleIntersectionAttribu } } // Indirect Illumination: cosine-weighted importance sampling - if(hitValue.depth < 12) { + if(hitValue.depth < 1) { float r1 = 2 * PI * rnd.x, r2 = rnd.y, r2s = sqrt(r2); float3 w = normalLight_WS; float3 u = normalize(cross(abs(w.x)>0.1 ? float3(0,1,0) : float3(1,0,0), w)); diff --git a/res/shaders/raytracing/RayGen.slang b/res/shaders/raytracing/RayGen.slang index 7429aae..81d0de5 100644 --- a/res/shaders/raytracing/RayGen.slang +++ b/res/shaders/raytracing/RayGen.slang @@ -9,7 +9,6 @@ struct Ray } const static float S_O = 6.9; -const static float f = 0.035; const static float A = 0.0; struct SampleParams @@ -69,6 +68,8 @@ void raygen() float3 cx = -normalize(cross(cam.d, abs(cam.d.y) < 0.9 ? float3(0, 1, 0) : float3(0, 0, 1))), cy = cross(cam.d, cx); const float2 sdim = float2(0.036, 0.024); + float f = sdim.y / (2 * tan(70.0f * 0.5f)); + float S_I = (S_O * f) / (S_O - f); //-- sample sensor diff --git a/src/Engine/Graphics/RenderPass/BasePass.cpp b/src/Engine/Graphics/RenderPass/BasePass.cpp index 767b3cb..23643df 100644 --- a/src/Engine/Graphics/RenderPass/BasePass.cpp +++ b/src/Engine/Graphics/RenderPass/BasePass.cpp @@ -194,7 +194,7 @@ void BasePass::render() { }, .rasterizationState = { - .cullMode = twoSided ? Gfx::SE_CULL_MODE_NONE : Gfx::SE_CULL_MODE_BACK_BIT, + .cullMode = Gfx::SE_CULL_MODE_BACK_BIT, }, .colorBlend = { @@ -214,7 +214,7 @@ void BasePass::render() { }, .rasterizationState = { - .cullMode = twoSided ? Gfx::SE_CULL_MODE_NONE : Gfx::SE_CULL_MODE_BACK_BIT, + .cullMode = Gfx::SE_CULL_MODE_BACK_BIT, }, .colorBlend = { diff --git a/src/Engine/Graphics/RenderPass/RayTracingPass.cpp b/src/Engine/Graphics/RenderPass/RayTracingPass.cpp index eef43c4..737beac 100644 --- a/src/Engine/Graphics/RenderPass/RayTracingPass.cpp +++ b/src/Engine/Graphics/RenderPass/RayTracingPass.cpp @@ -216,7 +216,6 @@ void RayTracingPass::publishOutputs() { .name = "RayGenMiss", .modules = {"RayGen", "AnyHit", "Miss"}, .entryPoints = {{"raygen", "RayGen"}, {"anyhit", "AnyHit"}, {"miss", "Miss"}}, - .typeParameter = {{"IVertexData", "StaticMeshVertexData"}}, .defines = {{"RAY_TRACING", "1"}}, .rootSignature = pipelineLayout, }; diff --git a/src/Engine/Graphics/Vulkan/Graphics.h b/src/Engine/Graphics/Vulkan/Graphics.h index 62f40c8..fba72ac 100644 --- a/src/Engine/Graphics/Vulkan/Graphics.h +++ b/src/Engine/Graphics/Vulkan/Graphics.h @@ -28,6 +28,7 @@ concept unique_chainable_structs = (chainable_struct && ...) && is_unique struct StructChain; template struct StructChain> { StructChain() { + std::memset(&b, 0, sizeof(Base)); b.sType = struct_type; b.pNext = nullptr; } @@ -50,24 +51,25 @@ template struct StructChain template struct StructChain, Right...> : StructChain { StructChain() { + std::memset(&t, 0, sizeof(This)); t.sType = struct_type; t.pNext = &StructChain::template get(); } This t; - template Query& get() { + template constexpr Query& get() { if constexpr (std::same_as) return t; else return StructChain::template get(); } - template const Query& get() const { + template constexpr const Query& get() const { if constexpr (std::same_as) return t; else return StructChain::template get(); } - This& get() { return t; } - const This& get() const { return t; } + constexpr This& get() { return t; } + constexpr const This& get() const { return t; } }; class Graphics : public Gfx::Graphics { diff --git a/src/Engine/Graphics/Vulkan/PipelineCache.cpp b/src/Engine/Graphics/Vulkan/PipelineCache.cpp index 25d2850..80283eb 100644 --- a/src/Engine/Graphics/Vulkan/PipelineCache.cpp +++ b/src/Engine/Graphics/Vulkan/PipelineCache.cpp @@ -233,9 +233,7 @@ PGraphicsPipeline PipelineCache::createPipeline(Gfx::LegacyPipelineCreateInfo gf PGraphicsPipeline PipelineCache::createPipeline(Gfx::MeshPipelineCreateInfo gfxInfo) { uint32 hash = CRC::Calculate(&gfxInfo, sizeof(Gfx::MeshPipelineCreateInfo), CRC::CRC_32()); - std::cout << hash << std::endl; if (graphicsPipelines.contains(hash)) { - std::cout << "found exisiting" << std::endl; return graphicsPipelines[hash]; } PPipelineLayout layout = Gfx::PPipelineLayout(gfxInfo.pipelineLayout).cast(); diff --git a/src/Engine/MinimalEngine.h b/src/Engine/MinimalEngine.h index bd07972..023de02 100644 --- a/src/Engine/MinimalEngine.h +++ b/src/Engine/MinimalEngine.h @@ -102,8 +102,8 @@ template > class OwningPtr return *this; } ~OwningPtr() { Deleter()(pointer); } - operator RefPtr() { return RefPtr(pointer); } - operator RefPtr() const { return RefPtr(pointer); } + constexpr operator RefPtr() { return RefPtr(pointer); } + constexpr operator RefPtr() const { return RefPtr(pointer); } constexpr T* operator->() { return pointer; } constexpr const T* operator->() const { return pointer; } constexpr T* operator*() { return pointer; } diff --git a/src/Engine/Platform/Linux/GameInterface.h b/src/Engine/Platform/Linux/GameInterface.h index d55ed02..aad7edf 100644 --- a/src/Engine/Platform/Linux/GameInterface.h +++ b/src/Engine/Platform/Linux/GameInterface.h @@ -1,7 +1,6 @@ #pragma once #include "Game.h" #include "filesystem" -#include "dlfcn.h" namespace Seele { class GameInterface {