Skip to content

πŸŒ‹πŸ––πŸ½ PBR, IBL, Clustered Forward Shading, Path Tracing, Shadow Mapping, and more!

License

Notifications You must be signed in to change notification settings

azer89/HelloVulkan

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸŒ‹Hello EngineπŸ––πŸ½

A 3D rendering engine built from scratch using Vulkan API and C++.


Features

  • Clustered Forward Shading for efficient light culling.
  • Physically-Based Rendering (PBR) with Cook-Torrance microfacet and Image-Based Lighting (IBL).
  • Hardware-Accelerated Path Tracing that can simulate indirect shading, reflections, and soft shadow.
  • Bindless techniques using Indirect Draw, Descriptor Indexing, and Buffer Device Address.
  • Compute-Based Frustum Culling.
  • Compute-Based Skinning for skeletal animation.
  • Shadow Maps with Poisson Disk or PCF.
  • Screen Space Ambient Occlusion (SSAO).
  • Multisample anti-aliasing (MSAA).
  • Tonemap postprocessing.
  • Automatic runtime compilation from GLSL to SPIR-V using glslang.
  • Lightweight abstraction layer on top of Vulkan for faster development.
  • Additional features: skybox, infinite grid, line rendering, and ImGui / ImGuizmo.

Engine Overview

Inspired by GPU-driven rendering, the engine leverages several modern GPU features. First, bindless textures is achieved by utilizing descriptor Indexing. This enables the storage of all scene textures inside an unbounded array, which allows texture descriptors to be bound once at the start of a frame.

Next, the engine takes advantage of indirect draw API. The CPU prepares indirect draw commands and stores them in an indirect buffer. These draw commands are then sorted by material type. This allows the rendering process to be divided into separate render passes based on material type. Currently, there are two passes: opaque and transparent.

Finally, the engine leverages bindless concept using buffer device addresses, allowing shaders to directly access buffers without creating descriptors.

bindless_shadow_mapping_1

Hardware-Accelerated Path Tracing

The path tracing process begins with building acceleration structures containing multiple geometries. After creating a raytracing pipeline, the ray simulation requires several shaders. Ray generation shader is responsible to generate rays, and add the hit color into an accumulator image. The final rendering is obtained by averaging the accumulator image. The next one is Closest hit shader that determines the color when a ray intersects an object and can also scatter the ray for further bounces. Optionally, Any hit shader is used to discard a ray hit in order to render transparent materials such as foliage textures.

hardware_raytracing hardware_raytracing

Clustered Forward Shading

The technique consists of two steps that are executed in compute shaders. The first step is to subdivide the view frustum into AABB clusters. The next step is light culling, where it calculates lights that intersect the clusters. This step removes lights that are too far from a fragment, leading to reduced light iteration in the final fragment shader.

Preliminary testing using a 3070M graphics card shows the technique can render a PBR Sponza scene in 2560x1600 resolution with over 1000 dynamic lights at 60-100 FPS. If too many lights end up inside the view frustum, especially when zooming out, there may be a drop in frame rate, but still much faster than a naive forward shading.

vulkan_cluster_forward.mp4

Compute-Based Frustum Culling

Since the engine uses indirect draw, frustum culling can now be done entirely on the compute shader by modifying draw commands within an indirect buffer. If an object's AABB falls outside the camera frustum, the compute shader will deactivate the draw command for that object. Consequently, the CPU is unaware of the number of objects actually drawn. Using Tracy profiler, an intersection test with 10,000 AABBs only takes less than 25 microseconds (0.025 milliseconds).

The left image below shows a rendering of all objects inside the frustum. The right image shows visualizations of AABBs as translucent boxes and the frustum drawn as orange lines.

frustum_culling

Compute-Based Skinning

The compute-based skinning approach is much simpler than the traditional vertex shader skinning. This is because the skinning computation is done only once using a compute shader at the beginning of the frame. The resulting skinned vertices are then stored in a buffer, which are then read in subsequent render passes like shadow mapping, SSAO, and lighting. Consequently, there is no need to modify existing pipelines and no extra shader permutations.

compute_skinning.mp4


Cascade Shadow Maps

The left image below is a rendering that uses four cascade shadow maps, resulting in sharper shadows. The right image above showcases the individual cascades with color coding. Poisson disk sampling helps to reduce projective aliasing artifacts, but can create more noticeable seams between cascades with excessive blurring.

cascade_shadow_mapping


Build


Credit