Skip to content

Add ray-query hard shadow: TLAS/BLAS, descriptors and shader path#7

Open
fl0a1e wants to merge 1 commit intomasterfrom
codex/implement-directional-light-hard-shadows
Open

Add ray-query hard shadow: TLAS/BLAS, descriptors and shader path#7
fl0a1e wants to merge 1 commit intomasterfrom
codex/implement-directional-light-hard-shadows

Conversation

@fl0a1e
Copy link
Copy Markdown
Owner

@fl0a1e fl0a1e commented Apr 22, 2026

Motivation

  • Provide a minimal, non-intrusive path to compute hard shadows for the directional light using Vulkan Ray Query and acceleration structures.
  • Enable required device extensions/features (buffer device address, acceleration structures, ray query) and build a static TLAS from the existing scene geometry for shader ray queries.

Description

  • Enable device extensions in instance/device setup (GlfwGeneral.hpp) and enable the feature chain (VkPhysicalDeviceRayQueryFeaturesKHRVkPhysicalDeviceAccelerationStructureFeaturesKHRVkPhysicalDeviceBufferDeviceAddressFeatures) by attaching to VkDeviceCreateInfo::pNext (vkBase.h).
  • Add a lightweight AS builder module RayTracingAS.hpp/.cpp that builds per-mesh BLAS and a single TLAS (static build, no per-frame updates) and exposes SceneAS::Tlas().
  • Integrate TLAS into the lighting pass by adding a TLAS binding (binding = 9, VK_DESCRIPTOR_TYPE_ACCELERATION_STRUCTURE_KHR) to the lighting descriptor set layout/pool and updating UpdateLightingDescriptorSet() to write the TLAS while preserving all existing gbuffer/shadow/light bindings (main.cpp).
  • Make geometry buffers shader-device-address capable and allocate with device-address flags so AS build can use device addresses, and add vertexCount tracking for BLAS inputs (main.cpp).
  • Add CreateRayTracingAS() and call it after scene resources are created, and destroy the AS on exit (main.cpp).
  • Shader changes in shaders/lighting.ps.hlsl: add [[vk::binding(9, 0)]] RaytracingAccelerationStructure sceneTLAS;, implement a RayQuery-based hard shadow function with a normal bias to avoid self-shadow acne, and guard it behind USE_RAYQUERY_SHADOW to allow A/B testing and fallback to the original shadow-map path.
  • Add new files to the VS project and filters (easy_vulkan.vcxproj / .filters).

Testing

  • Ran repository checks including git diff --check and git status which passed locally after edits and the change was committed (add ray query hard shadow path).
  • Verified source-level integration via text search/inspection of modified files to ensure descriptor, feature, and shader wiring are present.
  • Attempted to build with msbuild easy_vulkan.sln /p:Configuration=Debug /p:Platform=x64 but the container does not provide msbuild, so a full Visual Studio build could not be executed here; please build and run the project in Visual Studio 2022+ with the Vulkan SDK to validate runtime behavior and shader compilation.

Codex Task

@fl0a1e fl0a1e self-assigned this Apr 22, 2026
@fl0a1e fl0a1e marked this pull request as ready for review April 22, 2026 14:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant