Examples and demos for the new Vulkan API

Overview

Vulkan Kotlin examples and demos

A comprehensive collection of open source Kotlin examples for Vulkan®, the new graphics and compute API from Khronos, based on the excellent examples of Sascha Willems

The expressiveness of Kotlin meets the power of Vulkan, thanks to VK².

Examples

Basics

01a - Triangle Verbose

Basic and verbose example for getting a colored triangle rendered to the screen using Vulkan. This is meant as a starting point for learning Vulkan from the ground up. A huge part of the code is boilerplate that is abstracted away in later examples. Also, there is no type safety through inline classes.

01b - Triangle

Boilerplate code gone, 1/3 less code, strictly type safety for free thanks to inline classes.

02 - Pipelines

Using pipeline state objects (pso) that bake state information (rasterization states, culling modes, etc.) along with the shaders into a single object, making it easy for an implementation to optimize usage (compared to OpenGL's dynamic state machine). Also demonstrates the use of pipeline derivatives.

03 - Descriptor sets

Descriptors are used to pass data to shader binding points. Sets up descriptor sets, layouts, pools, creates a single pipeline based on the set layout and renders multiple objects with different descriptor sets.

04 - Dynamic uniform buffers

Dynamic uniform buffers are used for rendering multiple objects with multiple matrices stored in a single uniform buffer object. Individual matrices are dynamically addressed upon descriptor binding time, minimizing the number of required descriptor sets.

05 - Push constants

Uses push constants, small blocks of uniform data stored within a command buffer, to pass data to a shader without the need for uniform buffers.

06 - Specialization constants

Uses SPIR-V specialization constants to create multiple pipelines with different lighting paths from a single "uber" shader.

07 - Texture mapping

Loads a 2D texture from disk (including all mip levels), uses staging to upload it into video memory and samples from it using combined image samplers.

08 - Cubemap textures Only sphere model

Loads a cube map texture from disk containing six different faces. All faces and mip levels are uploaded into video memory and the cubemap is sampled once as a skybox (for the background) and as a source for reflections (for a 3D model).

09 - Texture arrays

Loads a 2D texture array containing multiple 2D texture slices (each with it's own mip chain) and renders multiple meshes each sampling from a different layer of the texture. 2D texture arrays don't do any interpolation between the slices.

10 - 3D textures

Generates a 3D texture on the cpu (using perlin noise), uploads it to the device and samples it to render an animation. 3D textures store volumetric data and interpolate in all three dimensions.

11 - Model rendering

Loads a 3D model and texture maps from a common file format (using assimp), uploads the vertex and index buffer data to video memory, sets up a matching vertex layout and renders the 3D model.

12 - Sub passes TOFINISH

Uses sub passes and input attachments to write and read back data from framebuffer attachments (same location only) in single render pass. This is used to implement deferred render composition with added forward transparency in a single pass.

13 - Offscreen rendering TODO

Basic offscreen rendering in two passes. First pass renders the mirrored scene to a separate framebuffer with color and depth attachments, second pass samples from that color attachment for rendering a mirror surface.

14 - CPU particle system TOFINISH

Implements a simple CPU based particle system. Particle data is stored in host memory, updated on the CPU per-frame and synchronized with the device before it's rendered using pre-multiplied alpha.

15 - Stencil buffer TODO

Uses the stencil buffer and it's compare functionality for rendering a 3D model with dynamic outlines.

Advanced TODO

Performance

01 - Multi threaded command buffer generation

Multi threaded parallel command buffer generation. Instead of prebuilding and reusing the same command buffers this sample uses multiple hardware threads to demonstrate parallel per-frame recreation of secondary command buffers that are executed and submitted in a primary buffer once all threads have finished.

Deferred TODO

Compute shader

01 - Image processing

Uses a compute shader along with a separate compute queue to apply different convolution kernels (and effects) on an input image in realtime.

02 - GPU particle system TOFIX

Attraction based 2D GPU particle system using compute shaders. Particle data is stored in a shader storage buffer and only modified on the GPU using memory barriers for synchronizing compute particle updates with graphics pipeline vertex access.

03 - N-body simulation TOFIX

N-body simulation based particle system with multiple attractors and particle-to-particle interaction using two passes separating particle movement calculation and final integration. Shared compute shader memory is used to speed up compute calculations.

04 - Ray tracing TODO

Simple GPU ray tracer with shadows and reflections using a compute shader. No scene geometry is rendered in the graphics pass.

05 - Cloth simulation TODO

Mass-spring based cloth system on the GPU using a compute shader to calculate and integrate spring forces, also implementing basic collision with a fixed scene object.

06 - Cull and LOD TODO

Purely GPU based frustum visibility culling and level-of-detail system. A compute shader is used to modify draw commands stored in an indirect draw commands buffer to toggle model visibility and select it's level-of-detail based on camera distance, no calculations have to be done on and synced with the CPU.

Credits:

  • Sascha, awesome repo (except for avoiding using glfw)
  • Spasi, for assisting (and tolerating) my continuous boring questions :), also the tip about the buffer came from him
  • Kai, for his first Hello Triangle in java
  • Ulrik, for some tips and the glsl -> spir-v converter
You might also like...
Checks for app updates and automatically updates the current app if the new one in local storage have a different version

Silent Android App Update Sample This sample shows how to update Android app silently without user confirmation with a device owner app. It works on A

New style for app design Online Sunglasses Shop App UI made in Jetpack Compose.😉😎
New style for app design Online Sunglasses Shop App UI made in Jetpack Compose.😉😎

JetSunglassUI-Android New style for app design Online Sunglasses Shop App UI made in Jetpack Compose. 😉 😎 (Navigation Components, Dagger-Hilt, Mater

This is our new version of chatkit

ChatKitV4 (This read me is under develop) This is our new version of chatkit. Here we seprate Core Logic and UI sections. You can use it as seprate mo

CodeLab for the workshop: A Composable New World
CodeLab for the workshop: A Composable New World

A Composable New World! Compose is here! 🙌 I've created a codelab where you can follow step by step the development of android application using Comp

Kotlin Tutorials for new learners.

Kotlin Programming Tutorial for Beginners Learn Kotlin Programming, its basics and Fundamentals from scratch. Topics to be covered Overview Course int

Aagent-new-service-parent - A Springboot Rest Webservice Project that can be deployed to a Docker container

Webservice in a Docker Container A Springboot Rest Webservice Project that can b

Template to accelerate the creation of new apps using Spring Boot 3, MongoDB & GraphQL.

Template to accelerate the creation of new apps using Spring Boot 3, MongoDB & GraphQL.

HelloKMM - Hello World in Kotlin Multiplatform Mobile (new empty project)
HelloKMM - Hello World in Kotlin Multiplatform Mobile (new empty project)

Hello KMM! Hello World in Kotlin Multiplatform Mobile (new empty project) Gettin

An e-commerce app which provide a new platform to order food items from various restaurants
An e-commerce app which provide a new platform to order food items from various restaurants

Food_App_Internshala An e-commerce app which provide a new platform to order food items from various restaurants. Splash and Login Page Opening of the

Owner
Everything related to java and opengl: tools, libraries, bindings, tutorials and more..
null
Getting started Kotlin - Examples and explanations

Getting started Kotlin I'm learning Kotlin, so I have been updating it with examples and explanations about the language that I'm using at work. Proje

Jean Jacques Nascimento Barros 2 Apr 25, 2022
Kotlin Examples Problems

Kotlin Examples Problems --->>> Repo: Getting Started Kotlin <<<--- --->>> Repo Kotlin Koans <<<--- --->>> Repo: GameBoy Emulator Enviroment <<<--- --

Victor Bolinches 22 Oct 3, 2022
Examples of Getting Started vídeos

Getting Started Kotlin Learn the basics of getting started with kotlin --->>> Repo: Kotlin Koans <<<--- --->>> Repo: Problems Kotlin <<<--- --->>> Rep

Victor Bolinches 41 Dec 4, 2022
Kotlin Unit Testing Examples

Kotlin Unit Testing Examples Table of Contents Application Gradle, Kotlin & Groovy Junit4 Junit5 KotlinTest Spek Mockito Mockito-Kotlin Mockk Strikt T

Jarosław 110 Dec 11, 2022
kotlin koans examples

Kotlin Koans Build --->>> Repo: Getting Started Kotlin <<<--- --->>> Repo: Problems Kotlin <<<--- --->>> Repo: GameBoy Emulator Enviroment <<<--- --->

Victor Bolinches 121 Oct 3, 2022
101 examples for Kotlin Programming language.

This is a collection of runnable console applications that highlights the features of Kotlin programming language. The use of console application enab

Dody Gunawinata 192 Dec 1, 2022
Full stack examples of how to use Hotwire JS in Kotlin services

hotwire-kt A collection of Kotlin examples using the Hotwire JS framework to build interactive web apps with a Kotlin Armeria server backend. Using Ho

Andrew (Paradi) Alexander 9 Dec 14, 2022
Examples for using Kotlin at a basic level for Android application development.

Kotlin Android Jetpack Basics Ejemplos para usar Kotlin a nivel básico para el desarrollo de aplicaciones Android. Kotlin Android Jetpack Basics Acerc

José Luis González Sánchez 2 Jun 28, 2022
A coding examples project about Kotlin Programming language. 🇰

Kotlin Tutorial ????‍?? What is Kotlin ❓ Kotlin is a new programming language, developed by JetBrains. Jetbrains is a popular software development com

Mustajab Ikram 4 Oct 11, 2022
A sandbox where I will experiment with new techniques, concepts, and technologies.

A sandbox where I will experiment with new techniques, concepts, and technologies. Here you will find some DDD, CQRS, Clean Architecture, Event-Driven Architecture, Serverless, Microservices, RabbitMQ, gRPC, SOLID, Design Patterns, and more.

Jefferson Didi Silva 6 Nov 15, 2022