GithubHelp home page GithubHelp logo

cankar001 / shadersystemdemo Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 8.97 MB

The ShaderSystemDemo is a prototype in C++, which can dynamically compile any shader language into any renderer api

Lua 2.36% Batchfile 0.01% Python 0.28% Shell 0.02% GLSL 0.34% C 0.37% C++ 96.28% HLSL 0.34%
opengl dx11 dx12 metal vulkan directx11 directx12 cpp17 cpp

shadersystemdemo's Introduction

ShaderSystemDemo

The ShaderSystemDemo is a prototype in C++, which can dynamically compile any shader language into any renderer api.

The demo just displays a 2D quad on the screen, but with different colors for each vertex of the quad. More complex demos might follow soon.

Getting started

To start the demo application, you just need python and Visual Studio 2022. The VS solution is automatically generated by premake.

Clone the repo

git clone https://github.com/Cankar001/ShaderSystemDemo

Generate the VS solution

cd ShaderSystemDemo/Scripts && python Setup.py

Now you should see the solution file in the root directory of the project. Just open it and build either the Debug or Release build.

Supported platforms

Windows Linux MacOS Android IOS Web
X X X X X

Supported rendering APIs

OpenGL Vulkan DirectX 11 DirectX 12 Metal
X X X

How it works

By default, the demo will use OpenGL in combination with the GLSL demo shader. If you go into the Main.cpp file, you should see this function call:

Renderer::SelectRenderingBackend(RenderingAPIType::OpenGL);

If you change the enumeration, the shader system will automatically build the shader binary for the respective rendering backend in the background, this is the current mapping:

OpenGL:

  • Shader source -> SPIRV binary
  • Reflection on the SPIRV binary
  • SPIRV binary can be used by OpenGL

Vulkan:

  • Shader source -> SPIRV binary
  • Reflection on the SPIRV binary
  • SPIRV binary can be used by Vulkan

DirectX11/DirectX12:

  • Shader source -> SPIRV binary
  • Reflection on the SPIRV binary
  • SPIRV binary -> HLSL binary
  • HLSL binary is compiled again by the DirectX11 api.

Metal:

  • Shader source -> SPIRV binary
  • Reflection on the SPIRV binary
  • SPIRV binary -> MSL binary
  • MSL binary can be used by Metal

This pipeline is applied automatically, all you have to do is to select the rendering backend in the Main.cpp file.

Using HLSL instead of GLSL

Currently the default shader language is GLSL, but the system will work with HLSL shaders as well.

The current usage looks like this:

BufferLayout flatColorShaderLayout = {
	BufferElement("a_Position", ShaderDataType::Float3, false),
	BufferElement("a_TexCoord", ShaderDataType::Float2, false),
	BufferElement("a_Color", ShaderDataType::Float4, false)
};

// This loads the GLSL shader and the system knows the language based on the file extension
s_Data->Library->Load("assets/shaders/FlatColorShader.glsl", flatColorShaderLayout, true);

// So this would load the HLSL shader version
s_Data->Library->Load("assets/shaders/FlatColorShader.hlsl", flatColorShaderLayout, true);

The above example can be found in ShaderSystem/src/Renderer/Renderer.cpp.

Future improvements

If you take a look into the Main.cpp file, there you can see that the uniform buffers and also the vertex attribute layout are hardcoded.

This will also improve in the near future, as the current implementation already does a reflection on the shader source, so in the future there shouldn't be a manual creation of uniform buffers necessary.

shadersystemdemo's People

Contributors

cankar001 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.