Preface
The Vulkan 3D Graphics Rendering Cookbook is a practical, all-in-one guide to mastering modern graphics rendering techniques and algorithms using C++ and Vulkan 1.3. You'll begin by setting up your Vulkan development environment, then move on to key aspects of graphics programming, such as working with graphics debugging tools, creating physically-based rendering pipelines, and handling large geometric data.
As you progress, the book walks you through building a 3D rendering engine step by step, presenting a series of small, self-contained recipes. Each recipe allows you to incrementally expand your codebase while integrating various 3D graphics techniques into a cohesive project. Along the way, you'll explore essential rendering methods, including glTF 2.0 shading model, image-based techniques, and GPU-driven rendering. You'll also learn how to manage large datasets for 3D rendering, apply optimization techniques, and develop high-performance, feature-rich graphics applications. By the end of the book, you'll have the skills to create fast and flexible 3D rendering frameworks and a solid understanding of best practices in modern Vulkan development. Rather than focusing on individual Vulkan API features in isolation, this book emphasizes integrating multiple Vulkan capabilities to create fully realized rendering demos. Throughout, we'll use Vulkan 1.3 along with the bindless rendering approach. To do this, we introduce LightweightVK https://github.com/corporateshark/lightweightvk, a standalone framework designed for Vulkan development, which we'll explore in depth as we progress.
Who this book is for
We expect our readers to have a solid understanding of real-time 3D graphics based on older rendering APIs. The first few chapters will cover what you need to get started with Vulkan, but we won't dwell on the basics for long. Instead, we'll quickly move on to more advanced topics. If you're familiar with OpenGL 4 or OpenGL ES 3 and want to explore modern rendering techniques and migration paths to current rendering APIs, this book is likely a great fit for you. While graphics programming may seem like an easy and fun entry point into software development, it actually requires mastering many advanced programming concepts. Readers should have a strong grasp of modern C++ and some foundational math skills, such as basic linear algebra and computational geometry.
What this book covers
This book is structured into distinct chapters, each focusing on a specific aspect of 3D rendering. As you progress, you'll gradually build a set of versatile 3D graphics demos, starting with the fundamentals, then exploring more complex techniques, and finally incorporating advanced rendering methods into your code.
Chapter 1, Establishing a Build Environment, guides you through setting up a Vulkan 1.3 development environment. You'll learn which tools and dependencies are needed to work with the book's source code and how to configure them. This chapter also introduces essential Vulkan recipes, including compiling Vulkan shaders from GLSL at runtime.
Chapter 2, Getting Started with Vulkan, introduces the fundamental components of the Vulkan API, including instance and device creation, swapchain management, debugging setup, and command buffer usage. You'll also learn how to create Vulkan rendering pipelines and explore a collection of recipes for quickly building minimal graphical applications from scratch using open-source libraries like GLFW, GLM, STB, and LightweightVK.
Chapter 3, Working with Vulkan Objects, explores handling various buffers and textures in Vulkan, as well as organizing a staging buffer. You'll learn how to wrap low-level Vulkan objects into user-friendly abstractions and get introduced to descriptor indexing.
Chapter 4, Adding User Interaction and Productivity Tools, focuses on debugging, profiling, and user interaction mechanisms. You'll learn various techniques for debugging and profiling graphical applications, starting with on-screen counters and graphs, then exploring open-source instrumenting profiler capabilities, and finally implementing helper classes for interactive application debugging.
Chapter 5, Working with Geometry Data, covers handling geometry in a modern 3D rendering pipeline and introduces concepts like Level-of-Detail (LOD) and tessellation. You'll also explore GLSL techniques for implementing various utility functions for geometry rendering, and introduce you to Vulkan compute shaders.
Chapter 6, Physically Based Rendering Using the glTF 2.0 Shading Model, introduces the glTF 2.0 physically based shading model and its implementation using GLSL in Vulkan. You'll explore various data preprocessing techniques, including the precalculation of Bidirectional Reflectance Distribution Function (BRDF) look-up tables and irradiance maps, with all necessary tooling built from scratch.
Chapter 7, Advanced PBR Extensions, explores advanced glTF PBR extensions from Khronos that extend the base metallic-roughness model. You'll learn how to integrate each of these extensions into GLSL shader code.
Chapter 8, Graphics Rendering Pipeline, goes the representation of complex 3D scene data with multiple dependencies and cross-references. You'll learn how to apply performance-oriented techniques, such as data-oriented design, to build a high-performance 3D rendering system. This chapter marks the beginning of real 3D engine design, demonstrating how to scale a scene graph approach to develop a practical graphics engine.
Chapter 9, glTF Animations, introduces a framework for supporting glTF animations in your rendering code. You'll learn the fundamentals of node-based animations, skeletal animations, morph targets, and animation blending.
Chapter 10, Image-Based Techniques, presents a series of recipes for enhancing rendering realism using image-based techniques, such as screen space ambient occlusion, high dynamic range rendering with light adaptation, and projective shadow mapping.
Chapter 11, Advanced Rendering Techniques and Optimizations, dives deeper into constructing GPU-driven rendering pipelines, multi-threaded resources loading, and other advanced techniques for feature-rich graphics applications. The book concludes by integrating various recipes and techniques into a single application.
To get the most out of this book
You'll need a machine that supports Vulkan 1.3 with the latest GPU drivers. All code examples in this book have been tested with Vulkan SDK 1.4.304.1, using Visual Studio 2022 on Windows 10 and 11, and GCC 12 on Ubuntu. While macOS is not officially supported, its users should be able to run some very first demos from this book.
Download the example code files
The code bundle for the book is hosted on GitHub at https://github.com/PacktPublishing/3D-Graphics-Rendering-Cookbook-Second-Edition. We also have other code bundles from our rich catalog of books and videos available at https://github.com/PacktPublishing/. Check them out!
Download the color images
We also provide a PDF file that has color images of the screenshots/diagrams used in this book. You can download it here: https://static.packt-cdn.com/downloads/9781803248110_ColorImages.pdf.
Conventions used
There are a number of text conventions used throughout this book.
CodeInText
: Indicates code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles. For example: "In OpenGL, presenting an offscreen buffer to the visible area of a window is done using system-dependent functions, such as wglSwapBuffers()
on Windows, eglSwapBuffers()
on OpenGL ES embedded systems, glXSwapBuffers()
on Linux, or automatically on macOS. Vulkan, however, gives us much more fine-grained control."
A block of code is set as follows:
while (!glfwWindowShouldClose(window)) { glfwPollEvents(); glfwGetFramebufferSize(window, &width, &height); if (!width || !height) continue; lvk::ICommandBuffer& buf = ctx->acquireCommandBuffer(); ctx->submit(buf, ctx->getCurrentSwapchainTexture()); }
Bold: Indicates a new term, an important word, or words that you see on the screen. For instance, words in menus or dialog boxes appear in the text like this. For example: "Here, we use the SPIRV-Reflect library to introspect the SPIR-V code and retrieve the size of the push constants from it."
Warnings or important notes appear like this.
Tips and tricks appear like this.
Get in touch
Feedback from our readers is always welcome.
General feedback: Email feedback@packtpub.com
and mention the book's title in the subject of your message. If you have questions about any aspect of this book, please email us at questions@packtpub.com
.
Errata: Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you have found a mistake in this book, we would be grateful if you reported this to us. Please visit...