All Projects → LukasBanana → Xshadercompiler

LukasBanana / Xshadercompiler

Licence: other
Shader cross compiler to translate HLSL (Shader Model 4 and 5) to GLSL

Programming Languages

c
50402 projects - #5 most used programming language
cpp
1120 projects
csharp
926 projects
cpp11
221 projects

Labels

Projects that are alternatives of or similar to Xshadercompiler

Shaderc Rs
Rust bindings for the shaderc library.
Stars: ✭ 143 (-56.27%)
Mutual labels:  glsl, hlsl
Shadered
Lightweight, cross-platform & full-featured shader IDE
Stars: ✭ 3,247 (+892.97%)
Mutual labels:  glsl, hlsl
Glslang
Khronos-reference front end for GLSL/ESSL, partial front end for HLSL, and a SPIR-V generator.
Stars: ✭ 2,034 (+522.02%)
Mutual labels:  glsl, hlsl
Cs2x
Transpiles a C# subset to non .NET languages and runtimes. (Powered by Roslyn)
Stars: ✭ 97 (-70.34%)
Mutual labels:  glsl, hlsl
Glslcc
GLSL cross-compiler tool (GLSL->HLSL, MSL, GLES2, GLES3, GLSLv3), using SPIRV-cross and glslang
Stars: ✭ 320 (-2.14%)
Mutual labels:  glsl, hlsl
Crossshader
⚔️ A tool for cross compiling shaders. Convert between GLSL, HLSL, Metal Shader Language, or older versions of GLSL.
Stars: ✭ 113 (-65.44%)
Mutual labels:  glsl, hlsl
Spirv Vm
Virtual machine for executing SPIR-V
Stars: ✭ 173 (-47.09%)
Mutual labels:  glsl, hlsl
Bonzomatic
Live shader coding tool and Shader Showdown workhorse
Stars: ✭ 829 (+153.52%)
Mutual labels:  glsl, hlsl
ada
A general porpose OpenGL app library
Stars: ✭ 105 (-67.89%)
Mutual labels:  glsl, hlsl
ShaderWriter
Library used to write shaders from C++, and export them in either GLSL, HLSL or SPIR-V.
Stars: ✭ 171 (-47.71%)
Mutual labels:  glsl, hlsl
3d Game Shaders For Beginners
🎮 A step-by-step guide to implementing SSAO, depth of field, lighting, normal mapping, and more for your 3D game.
Stars: ✭ 11,698 (+3477.37%)
Mutual labels:  glsl, hlsl
CPP-Programming
Various C/C++ examples. DirectX, OpenGL, CUDA, Vulkan, OpenCL.
Stars: ✭ 30 (-90.83%)
Mutual labels:  glsl, hlsl
Shaderconductor
ShaderConductor is a tool designed for cross-compiling HLSL to other shading languages
Stars: ✭ 1,146 (+250.46%)
Mutual labels:  glsl, hlsl
Krafix
GLSL cross-compiler based on glslang and SPIRV-Cross
Stars: ✭ 124 (-62.08%)
Mutual labels:  glsl, hlsl
Shaderc
A collection of tools, libraries, and tests for Vulkan shader compilation.
Stars: ✭ 1,016 (+210.7%)
Mutual labels:  glsl, hlsl
Reshade
A generic post-processing injector for games and video software.
Stars: ✭ 2,285 (+598.78%)
Mutual labels:  glsl, hlsl
Slang
Making it easier to work with shaders
Stars: ✭ 627 (+91.74%)
Mutual labels:  glsl, hlsl
Imguicolortextedit
Colorizing text editor for ImGui
Stars: ✭ 772 (+136.09%)
Mutual labels:  glsl, hlsl
Pmfx Shader
Cross platform shader system for HLSL, GLSL, Metal and SPIR-V.
Stars: ✭ 245 (-25.08%)
Mutual labels:  glsl, hlsl
inline-spirv-rs
Compile GLSL/HLSL/WGSL and inline SPIR-V right inside your crate.
Stars: ✭ 21 (-93.58%)
Mutual labels:  glsl, hlsl

Build status

XShaderCompiler ("Cross Shader Compiler")

Features

  • Cross compiles HLSL shader code (Shader Model 4 and 5) into GLSL
  • Simple to integrate into other projects
  • Low overhead translation (i.e. avoidance of unnecessary wrapper functions)
  • Dead code removal
  • Code reflection
  • Meaningful report output
  • Commentary preserving
  • Written in C++11

Language Bindings

  • C Wrapper (ISO C99)
  • C# Wrapper

License

3-Clause BSD License

Documentation

Progress

Version: 0.11 Alpha (Do not use in production code!)

See the TODO.md file for more information.

 Feature  Progress  Remarks
Vertex Shader ~80% Few language features are still left
Tessellation Control Shader ~20% InputPatch and patch-constant-function translation in progress
Tessellation Evaluation Shader ~20% OutputPatch translation in progress
Geometry Shader ~60% Code generation is incomplete
Fragment Shader ~80% Few language features are still left
Compute Shader ~80% Few language features are still left

Offline Compiler

The following command line translates the "Example.hlsl" file with the vertex shader entry point "VS", and the fragment shader entry point "PS":

xsc -E VS -T vert Example.hlsl -E PS -T frag Example.hlsl

The result are two GLSL shader files: "Example.VS.vert" and "Example.PS.frag".

Library Usage (C++)

#include <Xsc/Xsc.h>
#include <fstream>
#include <iostream>

int main()
{
    // Input file stream (use std::stringstream for in-code shaders).
    auto inputStream = std::make_shared<std::ifstream>("Example.hlsl");

    // Output file stream (GLSL vertex shader)
    std::ofstream outputStream("Example.VS.vert");

    // Fill the shader input descriptor structure
    Xsc::ShaderInput inputDesc;
    inputDesc.sourceCode     = inputStream;
    inputDesc.shaderVersion  = Xsc::InputShaderVersion::HLSL5;
    inputDesc.entryPoint     = "VS";
    inputDesc.shaderTarget   = Xsc::ShaderTarget::VertexShader;

    // Fill the shader output descriptor structure
    // Use outputDesc.options, outputDesc.formatting, and outputDesc.nameMangling for more settings
    Xsc::ShaderOutput outputDesc;
    outputDesc.sourceCode = &outputStream;

    // Optional output log (can also be a custom class)
    Xsc::StdLog log;

    // Optional shader reflection data (for shader code feedback)
    Xsc::Reflection::ReflectionData reflectData;

    // Translate HLSL code into GLSL
    try
    {
        bool result = Xsc::CompileShader(inputDesc, outputDesc, &log, &reflectData);
    }
    catch (const std::exception& e)
    {
        std::cerr << e.what() << std::endl;
    }

    return 0;
}

Library Usage (C#)

using System;
using System.IO;

namespace Example
{
    class Program
    {
        static void Main()
        {
            // Create instance of the XShaderCompiler
            var compiler = new XscCompiler();

            // Fill the shader input descriptor structure
            var inputDesc = new XscCompiler.ShaderInput();
            inputDesc.SourceCode     = File.ReadAllText("Example.hlsl");
            inputDesc.ShaderVersion  = XscCompiler.InputShaderVersion.HLSL5;
            inputDesc.EntryPoint     = "VS";
            inputDesc.Target         = XscCompiler.ShaderTarget.VertexShader;

            // Fill the shader output descriptor structure
            // Use outputDesc.Options, outputDesc.Formatting, and outputDesc.MameMangling for more settings
            var outputDesc = new XscCompiler.ShaderOutput();

            // Optional output log (can also be a custom class)
            var log = compiler.StandardLog;

            // Optional shader reflection data (for shader code feedback)
            var reflectData = new XscCompiler.ReflectionData();

            // Translate HLSL code into GLSL
            try
            {
                bool result = compiler.CompileShader(inputDesc, outputDesc, log, reflectData);

                if (result)
                {
                    // Write output shader code
                    File.WriteAllText("Example.VS.vert", outputDesc.SourceCode);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }
    }
}

Real-time Debugger

A real-time debugger with UI is provided. Although this debugger is mainly used for developement of the compiler itself, it can also be used for a quick translation overview, to see how language constructs are being cross compiled.

Example of the real-time debugger (requires wxWidgets 3.1.0 or later):

docu/xsc_debugger_example_02.png

Language Differences

Here is a brief outline of High-Level differences between HLSL and GLSL, which XShaderCompiler is able to translate properly:

 Feature  HLSL  GLSL
Separation of Textures and Samplers Yes Only for Vulkan
Structure Inheritance Yes No
Nested Structures Yes No
Anonymous Structures Yes No
Structure Member Functions Yes No
Default Parameters Yes No
Object-Oriented Intrinsics Yes No
Multiple Entry Points Yes No
Type Aliasing Yes No
L-Values of Input Semantics Yes No
Implicit Type Conversion Extensive Restricted
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].