Home

Awesome

Vulkan Cookbook

This is the code repository for Vulkan Cookbook, published by Packt. All the example workflows that are mentioned in the book are present in the package.

About the Book

Vulkan is the next generation graphics API released by the Khronos group. It is expected to be the successor to OpenGL and OpenGL ES, which it shares some similarities with such as its cross-platform capabilities, programmable pipeline stages, or nomenclature. Vulkan is a low-level API that gives developers much more control over the hardware, but also adds new responsibilities such as explicit memory and resources management. With it, though, Vulkan is expected to be much faster.

Related Books

Suggestions and Feedback

Click here if you have any feedback or suggestions.

<hr>

Credits

Special thanks for authors and developers of the following projects and resources:

<hr>

Please note!

Currently only Windows operating system is supported. Linux version is being prepared and should be ready soon.

<hr>

Samples

Chapter 11 - Lighting

<img src="./Samples/Source%20Files/11%20Lighting/01-Rendering_a_geometry_with_vertex_diffuse_lighting/screenshot.png" width="150px" align="right">

Sample showing how to implement a diffuse lighting algorithm calculated only at geometry's verices using vertex shaders.<br> <b>Left mouse button:</b> rotate the scene

<img src="./Samples/Source%20Files/11%20Lighting/02-Rendering_a_geometry_with_fragment_specular_lighting/screenshot.png" width="150px" align="right">

This sample present the Phong specular lighting algorithm implemented on vertex and fragment shaders.<br> <b>Left mouse button:</b> rotate the scene

<img src="./Samples/Source%20Files/11%20Lighting/03-Rendering_a_normal_mapped_geometry/screenshot.png" width="150px" align="right">

Here a normal mapping technique is presented and the model is lit using the specular lighting algorithm.<br> <b>Left mouse button:</b> rotate the scene

<img src="./Samples/Source%20Files/11%20Lighting/04-Rendering_a_reflective_and_refractive_geometry_using_cubemaps/screenshot.png" width="150px" align="right">

Sample presenting how to use cubemaps to render a transparent geometry that both reflects and refracts environment.<br> <b>Left mouse button:</b> rotate the scene

<img src="./Samples/Source%20Files/11%20Lighting/05-Adding_shadows_to_the_scene/screenshot.png" width="150px" align="right">

In this sample a basic shadow mapping algorithm is shown. In the first render pass a shadow map is generated. In the second render pass a scene is rendered and the data from the shadow map is used to check, whether the geometry is lit or covered in shadow.<br> <b>Left mouse button:</b> rotate the scene<br> <b>Right mouse button:</b> move the light

Chapter 12 - Advanced Rendering Techniques

<img src="./Samples/Source%20Files/12%20Advanced%20Rendering%20Techniques/01-Drawing_a_skybox/screenshot.png" width="150px" align="right">

Here it is shown how to draw a skybox, which simulates background - objects seen in a distance and/or a sky.<br> <b>Left mouse button:</b> look around

<img src="./Samples/Source%20Files/12%20Advanced%20Rendering%20Techniques/02-Drawing_bilboards_using_geometry_shaders/screenshot.png" width="150px" align="right">

This sample presents a way of drawing sprites or bilboards - flat, textured quads that are always facing the camera.<br> <b>Left mouse button:</b> rotate the scene

<img src="./Samples/Source%20Files/12%20Advanced%20Rendering%20Techniques/03-Drawing_particles_using_compute_and_graphics_pipelines/screenshot.png" width="150px" align="right">

Here an example of rendering particles is shown. Compute shaders are used to calculate positions of all particles in the system. Particles are rendered as flat bilboards (sprites).<br> <b>Left mouse button:</b> rotate the scene

<img src="./Samples/Source%20Files/12%20Advanced%20Rendering%20Techniques/04-Rendering_a_tesselated_terrain/screenshot.png" width="150px" align="right">

This code sample shows one of the ways to draw a terrain. A complete graphics pipeline with all five programmable stages is used that tessellates the terrain near the camera to improve its complexity, with level of details faiding away with increasing distance from the camera, and with a flat shading lighting algorithm.<br> <b>Left mouse button:</b> rotate the scene<br> <b>Mouse wheel:</b> zoom in / zoom out

<img src="./Samples/Source%20Files/12%20Advanced%20Rendering%20Techniques/05-Rendering_a_fullscreen_quad_for_postprocessing/screenshot.png" width="150px" align="right">

Sample presenting a fast and easy way to prepare an image postprocessing phase in a graphics pipeline - by using a fullscreen quad drawn already in a clip space. An edge detection algorithm is shown as on of the examples of postprocessing techniques.

<img src="./Samples/Source%20Files/12%20Advanced%20Rendering%20Techniques/06-Using_input_attachment_for_color_correction_postprocess_effect/screenshot.png" width="150px" align="right">

In this code another postprocessing technique is shown that uses one of the Vulkan's specific features - input attachments, which allow reading data from render targets (attachments) in the same render pass.<br> <b>Left mouse button:</b> rotate the scene

Other

<img src="./Samples/Source%20Files/Other/01-Creating_Logical_Device/screenshot.png" width="150px" align="right">

Code sample that shows basic Vulkan setup - instance creation, physical device enumeration and logical device creation.

<img src="./Samples/Source%20Files/Other/02-Creating_Swapchain/screenshot.png" width="150px" align="right">

Here a swapchain object is created, which allows us to render a scene directly to an application's window.

<img src="./Samples/Source%20Files/Other/03-Using_Render_Passes/screenshot.png" width="150px" align="right">

This example shows how to preapre a basic render pass - a description of attachments (render targets) needed to render a geometry.

<img src="./Samples/Source%20Files/Other/04-Using_Graphics_Pipeline/screenshot.png" width="150px" align="right">

Sample showing how to create a graphics pipeline, setup its multiple parameters and use it to draw a scene.

<img src="./Samples/Source%20Files/Other/05-Using_Combined_Image_Samplers/screenshot.png" width="150px" align="right">

Here descriptor sets are introduced. They are required to setup an interface between application and a pipeline and to provide images (textures) to shaders.

<img src="./Samples/Source%20Files/Other/06-Using_Uniform_Buffers/screenshot.png" width="150px" align="right">

Another example of using descriptor sets, but this time it presented how to prepare transformation matrices and provide them to shaders.

<img src="./Samples/Source%20Files/Other/07-Using_Push_Constants/screenshot.png" width="150px" align="right">

This code sample presents a very fast and easy way to provide data to shaders - push constants. Though the provided data may not be too big, they are ideal for performing frequent updates.

<img src="./Samples/Source%20Files/Other/08-Using_Tessellation_Shaders/screenshot.png" width="150px" align="right">

Here we can see how to create a graphics pipeline with tessellation control and evaluation shaders enabled responsible for increasing the complexity of a rendered geometry.

<img src="./Samples/Source%20Files/Other/09-Using_Geometry_Shaders/screenshot.png" width="150px" align="right">

Sample presenting how to use geometry shaders and generate new primitives instead of those drawn in an application.

<img src="./Samples/Source%20Files/Other/10-Using_Compute_Shaders/screenshot.png" width="150px" align="right">

This code sample shows how to create a compute pipeline - the second type of pipelines supported in the Vulkan API. It allows us to perform mathematical computations.

<img src="./Samples/Source%20Files/Other/11-Drawing_Vertex_Normals/screenshot.png" width="150px" align="right">

Here a commonly used debugging technique is presented that uses geometry shaders to display normal vectors provided by the application.

<img src="./Samples/Source%20Files/Other/12-Using_Depth_Attachments/screenshot.png" width="150px" align="right">

In this example we can see how to setup a render pass, framebufer and a graphics pipeline to use depth attachment and enable depth test during drawing.

<img src="./Samples/Source%20Files/Other/13-Enabling_Alpha_Blending/screenshot.png" width="150px" align="right">

This code sample shows how to enable alpha blending (transparency) in a graphics pipeline.<br> <b>Left mouse button:</b> disable/enable blending<br>

<img src="./Samples/Source%20Files/Other/14-Drawing_Single_Fullscreen_Triangle_For_Postprocessing/screenshot.png" width="150px" align="right">

This sample shows an alternative for performing a postprocessing with a quad (two triangles). Here a single triangle covering the whole screen is used to apply a grayscale effect.<br>

<hr>

Recipes Library

Chapter 01 - Instance and Devices

Chapter 02 - Image Presentation

Chapter 03 - Command Buffers and Synchronization

Chapter 04 - Resources and Memory

Chapter 05 - Descriptor Sets

Chapter 06 - Render Passes and Framebuffers

Chapter 08 - Graphics and Compute Pipelines

Chapter 09 - Command Recording and Drawing

Chapter 10 - Helper Recipes

Download a free PDF

<i>If you have already purchased a print or Kindle version of this book, you can get a DRM-free PDF version at no cost.<br>Simply click on the link to claim your free PDF.</i>

<p align="center"> <a href="https://packt.link/free-ebook/9781786468154">https://packt.link/free-ebook/9781786468154 </a> </p>