Skip to content

ravi688/VulkanRenderer

Repository files navigation

MSYS2 Ubuntu

Spectrum-VulkanRenderer-Small

Spectrum Graphics Engine

SGE (formerly Vulkan Renderer) is a cross platform 2D and 3D graphics engine primarly designed for high quality text rendering, and 2D/3D geometry rendering. For now it is based on Vulkan API, and in future, more API backends will be implemented, such as DirectX 12.

Buy Me A Coffee

Features

Multipass Rendering

  1. Render Pass Pool to avoid pass duplication
  2. Sorting Render Passes using Topological Sort to minimize multiple runs of the same render pass.

Render Queues

  1. Background Render Queue

  2. Geometry Render Queue

  3. Overlay Render Queue

  4. General Purpose Render Queues

Render Textures (Hybrid render textures)

A camera can render its depth and color output to a user supplied textures - both at the same time.

  1. Depth Render Texture
    One can redirect the depth render output of a camera to a depth render texture

  2. Color Render Texture
    One can redirect the color render output of a camrea to a color render texture

  3. Depth Cube Render Texture (Shadow map for point lights)
    One can redirect the depth render output of 360 view (6 faces of a cube) to a cube depth render texture - which can further be used as a shadow map for point lights.

  4. Color Cube Render Texture (Environment map for reflection effects)
    One can redirect the color render output of 360 view (6 faces of a cube) to a cube color render texture - which can further be used as a environment reflection map.

Textures and Cubemaps

  1. Normal Map

  2. Albedo Map

  3. Skybox & Reflection cubemap

Camera System

  1. Multiple Cameras

  2. Render Target switching

  3. Orthographic and Perspective Projection

  4. Split rendering

Lights

  1. Directional lights

  2. Point lights

  3. Spot lights

Meshes

  1. Support for ASCII STL, BINARY STL

  2. Support for ASCII OBJ

  3. Mesh Trangulation and Quadrangulation

  4. Tangent Vector Generation

Text Mesh Rendering

  1. Glyph pool to avoid glyph mesh duplication

  2. High performance internal data structure to frequently update the text data

  3. Text Mesh batching

Bitmap Text Rendering

  1. Glyph Bitmap Atlas to avoid glyph bitmap duplication
  2. Text Layout Callback to customize the placement of glyphs.

Materials

  1. String to fast integer handles for constant lookup

Shaders

  1. Multiple Render passes and Subpasses (fully control over the input and output attachments)

  2. Custom attachments configuration

  3. Fixed Function pipeline configuration for each pass

Tested on

  1. Windows 11 64 bit
  2. Windows 10 64 bit
  3. Linux Mint 64 bit + Nvidia Geforce GTX 1650
  4. Nvidia GeForce GTX 1650 4 GB (VRAM) Discrete Mobile GPU + 8 GB of Main Memory (RAM)
  5. AMD Radeon(TM) Graphics 512 MB (VRAM) Integratred Mobile GPU + 8 GB of Main Memory (RAM)
  6. AMD Vega 8 Graphics 512 MB (VRAM) Integrated Mobile GPU + 12 GB of Main Memory (RAM)

Getting Started

Requirements for building on Windows

  1. Msys2

  2. Vulkan SDK

  3. MINGW 11.2.0 (tested on this, but might also work with previous versions), you can check if it is already installed in your machine by running

    $ gcc --version
    

    OR

    $ g++ --version
    

    If this isn't already installed, run the following in MSYS2 MinGW shell

    $ pacman -S gcc
    
  4. GNU Make 4.3, you can check if it is already installed, though it already comes with mingw64 binutils package, by running

    $ make --version
    

    If this isn't already installed, run the following in MSYS2 MinGW shell

    $ pacman -S make
    
  5. Git version 2.35.1, git must be installed in your machine, you can check if it is already installed by running

    $ git --version
    

    If this isn't already installed, run the following in MSYS2 MinGW shell

    $ pacman -S git
    
  6. glslc, glslc can be installed as follows, run the following in MSYS2 MinGW shell

    $ pacman -S mingw-w64-x86_64-shaderc
    

Requirements for building on Linux (Debian)

  1. Vulkan Tools

    $ sudo apt-get install vulkan-tools
    
  2. Vulkan SDK

    • Download vulkan sdk for linux (debian) from https://www.lunarg.com/vulkan-sdk/
    • Extract the archive by tar -xvf <archive name>
    • Change directoy into the extracted folder, usually name as version number 1.x.x.x
    • Export SDK environment variables, source ./setup-env.sh
    • Or you may also just install vulkan-sdk via apt, sudo apt-get install vulkan-sdk
  3. GCC 11.2.0 (tested on this, but might also work with previous versions), you can check if it is already installed in your machine by running

    $ gcc --version
    

    OR

    $ g++ --version
    

    If this isn't already installed, run the following in the terminal

    $ sudo apt-get install gcc
    

    You might also need to install build-essentials in case you encounter any standar library header inclusion errors:

    $ sudo apt-get update
    $ sudo apt-get install build-essentials
    
  4. GNU Make 4.3, you can check if it is already installed, though it already comes with mingw64 binutils package, by running

    $ make --version
    

    If this isn't already installed, run the following in the terminal

    $ sudo apt-get install make
    
  5. Git version 2.35.1, git must be installed in your machine, you can check if it is already installed by running

    $ git --version
    

    If this isn't already installed, run the following in the terminal

    $ sudo apt-get install git
    
  6. You might also need to install the followings:

    $ sudo apt-get install libz-dev
    $ sudo apt-get install libpng-dev
    $ sudo apt-get install libbrotli-dev
    

Runtime requirements

  1. Windows 64 bit
  2. GPU supporting vulkan api (integrated or discrete)
  3. Main memory (RAM) - No data as of now
  4. Disk space - No data as of now
  5. Better to have Vulkan LunarG SDK installed for additional debugging and vulkan configuration (validation layers), but it is not a requirement because the static library and headers are already included in the repository and would be updated as new updates will come in future.

Building steps

  1. Clone the repository by running the following command

    $ git clone https://github.com/ravi688/VulkanRenderer.git
    
  2. Change the working directory to VulkanRenderer and setup all the dependency git submodules by running the following command

    $ cd VulkanRenderer
    $ make -s setup
    
  3. Start building by running the following command

    $ make -s build
    

    OR

    $ make -s build-debug
    

    For release mode

    $ make -s build-release
    

Building executable manually (Optional)

  1. Change the working directory to VulkanRenderer and build the main executable by running the following command

    $ make -s debug
    
  2. Now run the main executable by running the following command

    $ ./main
    

Test Run (Optional)

There are several tests which you can try running by just passing arguments:

$ cd <build directory>
$ ./main CUBE

The above set of commands would launch a window in which a white cube will be spinning. If you want to see all the possible test cases, you may launch the execution without any arguments and it would just print the list of possible test cases:

$ ./main
supported tests:
        DEPTH_RENDER_TEXTURE
        DEPTH_RENDER_TEXTURE_LOAD
        ENVIRONMENT_REFLECTIONS
        ENVIRONMENT_REFLECTIONS_LOAD
        DEPTH_CUBE_RENDER_TEXTURE
        DEPTH_CUBE_RENDER_TEXTURE_LOAD
        POINT_LIGHT_SHADOWS
        POINT_LIGHT_SHADOWS_LOAD
        SPOT_LIGHT
        SPOT_LIGHT_LOAD
        CUBE
        TEXTURE_SAMPLING
        TEXTURE_SAMPLING_ALPHA_CHANNEL
        TEXT_MESH
        BITMAP_TEXT
        TID_14_CASE_1
        TID_14_CASE_2
        TID_14_CASE_3
        TID_28_CASE_1
        TID_28_CASE_2
        TID_28_CASE_3
        TID_28_CASE_4
        TID_42_CASE_1
        TID_43_CASE_1
        TID_43_CASE_2
        TID_43_CASE_3
        TID_43_CASE_4
        TID_48_CASE_1
        TID_48_CASE_2
        TID_48_CASE_3
        TID_48_CASE_4
        TID_48_CASE_5

Cleaning everything (Optional)

  1. Change the working directory to VulkanRenderer and run the following command

    $ make -s clean
    

Documentation

The full documentation will be available very soon, however, for now you can have a look at the Wiki.

Shader Description Language Example

#sl version 2022 // shader language version
#sb version 2022 // shader binary version, i.e. in which binary encoding to compile to

Shader
{
	[NoParse] // mandatory for legacy reasons
	Properties
	{
		vertex fragment [MATERIAL_SET, MATERIAL_PROPERTIES_BINDING] uniform Parameters
		{
			vec4 color;
		} parameters;

		// for sampling a 2D texture, you may add the following line
		// fragment [MATERIAL_SET, TEXTURE_BINDING0] uniform Sampler2D myTexture;
	}

	[NoParse] // mandatory for legacy reasons
	Layout // this where we can define vertex buffer layouts
	{
		per_vertex [POSITION_BINDING, POSITION_LOCATION] vec3 position;
		per_vertex [NORMAL_BINDING, NORMAL_LOCATION] vec3 normal;
	}

	RenderPass
	{
		SubPass
		{
			[NoParse] // mandatory for legacy reasons
			GraphicsPipeline
			{
				colorBlend
				{
					// the pipeline for this subpass requires a color attachment, so mention it here
					attachment { }
				}

				// the pipeline for this subpass requires interaction with depth buffers, so mention it here too
				depthStencil
				{
					depthWriteEnable = true,
					depthTestEnable = true
				}
			}

			[NoParse] // mandatory for legacy reasons
			GLSL // this is where actual GLSL shader will be written in
			{
				// vertex shader
				#stage vertex

				#version 450
				#include <v3d.h>
				
				layout(set = CAMERA_SET, binding = CAMERA_PROPERTIES_BINDING) uniform CameraInfo cameraInfo;
				layout(set = OBJECT_SET, binding = TRANSFORM_BINDING) uniform ObjectInfo objectInfo;
				
				
				layout(location = POSITION_LOCATION) in vec3 position;
				layout(location = NORMAL_LOCATION) in vec3 normal;
				
				layout(location = 0) out vec3 _normal;
				
				void main()
				{
					vec4 clipPos = cameraInfo.projection * cameraInfo.view * objectInfo.transform * vec4(position, 1);
					clipPos.y = -clipPos.y;
					gl_Position = clipPos;
					_normal = normalize((objectInfo.normal * vec4(normal, 0)).xyz);
				}

				// fragment shader
				#stage fragment

				#version 450
				#include <v3d.h>
				
				layout(set = GLOBAL_SET, binding = LIGHT_BINDING) uniform DirectionalLight lightInfo;
				
				layout(set = MATERIAL_SET, binding = MATERIAL_PROPERTIES_BINDING) uniform Parameters
				{
					vec4 color;
				} parameters;
				
				layout(location = 0) in vec3 _normal;
				
				layout(location = 0) out vec4 color;
				
				void main()
				{
					float dp = 0.5 * dot(-_normal, lightInfo.direction) + 0.5;
					color = parameters.color * dp * vec4(lightInfo.color, 1);
				}
			}
		}
	}
}

Screenshots and video clips

Point Lights

IMAGE ALT TEXT HERE

Spot Lights

IMAGE ALT TEXT HERE

Render Textures

IMAGE ALT TEXT HERE

Skybox Rendering

IMAGE ALT TEXT HERE

Mesh Rendering

IMAGE ALT TEXT HERE

Specular Shading

IMAGE ALT TEXT HERE

Diffuse Shading

IMAGE ALT TEXT HERE

Color Blending and Text Rendering

IMAGE ALT TEXT HERE

Flat Shading

IMAGE ALT TEXT HERE

About Me