GithubHelp home page GithubHelp logo

supernovaengine / supershader Goto Github PK

View Code? Open in Web Editor NEW
3.0 2.0 1.0 8.35 MB

Cross-compiler command line tool that converts GLSL code to other GLSL versions, HLSL and MSL

License: MIT License

CMake 0.47% Makefile 0.07% C 1.88% Shell 0.38% Python 0.37% C++ 54.15% GLSL 38.77% JavaScript 2.82% HLSL 0.01% Yacc 1.04% Assembly 0.01% Swift 0.02%
glsl mlsl msl toolset spirv-cross glslang transcompiler shader

supershader's Introduction

Supershader: Cross-compiler for shader language

Supershader is a command line tool that converts GLSL code to other GLSL versions, HLSL and MSL.

It is used in Supernova engine as shader creation tool.

Build

  1. Download glslang external libs (SPIRV-Tools)
cd libs/glslang/
python update_glslang_sources.py
  1. Supershader uses CMake
cmake -S $SOURCE_DIR -B $BUILD_DIR

cmake --build $BUILD_DIR --config Release
# "Release" (for --config) could also be "Debug", "MinSizeRel", or "RelWithDebInfo"

Usage

./supershader --vert=shader.vert --frag=shader.frag ---defines "USE_UV=1; HAS_TEXTURE" --lang glsl330 --output shaderoutput

Arguments

    -h, --help                show this help message and exit
    -v, --vert=<str>          vertex shader input file
    -f, --frag=<str>          fragment shader input file
    -l, --lang=<str>          <see below> shader language output
    -o, --output=<str>        output file template (extension is ignored)
    -t, --output-type=<str>   output in json or binary shader format
    -I, --include-dir=<str>   include search directory
    -D, --defines=<str>       preprocessor definitions, seperated by ';'
    -L, --list-includes       print included files

Current supported shader stages:

  • Vertex shader (--vert)
  • Fragment shader (--frag)

Current supported shader langs:

  • glsl330: desktop (default)
  • glsl100: GLES2 / WebGL
  • glsl300es: GLES3 / WebGL2
  • hlsl4: D3D11
  • hlsl5: D3D11
  • msl12macos: Metal for MacOS
  • msl21macos: Metal for MacOS
  • msl12ios: Metal for iOS
  • msl21ios: Metal for iOS

Output format types:

  • json
  • binary (SBS file)

Output

For default Supershader output format is json with reflection info and bare shader output:

./supershader --vert=shader.vert --frag=shader.frag --output shaderoutput  --lang glsl330
  • Output: shaderoutput_glsl.json, shaderoutput_vs.glsl, shaderoutput_fs.glsl

With --output-type=binary argument we have .sbs binary file:

./supershader --vert=shader.vert --frag=shader.frag --output shaderoutput  --lang glsl330 --output-type=binary
  • Output: shaderoutput.sbs

SBS file format

Inspired by septag file format: sgs-file.h

Each block header is 8 bytes ( uint32_t fourcc code + uint32_t for size).

  • SBS block
    • struct sbs_chunk
    • STAG blocks: defines each shader stage (vs or fs)
      • struct sbs_stage
      • [CODE or DATA] block: actual code or binary (byte-code) data for the shader stage
      • REFL block: Reflection data for the shader stage
      • struct sbs_chunk_refl: reflection data header
      • struct sbs_refl_input[]: array of vertex-shader input attributes (see sbs_chunk_refl for number of inputs)
      • struct sbs_refl_texture[]: array of texture objects (see sbs_chunk_refl for number of textures)
      • struct sbs_refl_sampler[]: array of sampler objects (see sbs_chunk_refl for number of samplers)
      • struct sbs_refl_texture_sampler[]: array of texture-sampler pair objects (see sbs_chunk_refl for number of pairs)
      • struct sbs_refl_uniformblock[]: array of uniform blocks objects (see sbs_chunk_refl for number of uniform blocks)
        • struct sbs_refl_uniform[]: array of uniform objects (see sbs_refl_uniformblock.num_uniforms for number of uniforms)

Updates

1.5

  • Storage buffer support
  • New sbs file version

1.4

  • Changed json to be default output type format
  • Created sampler and texture-sampler pair blocks
  • Input and output shaders validation

1.3

  • Changed json and sbs file spec to support uniform blocks with float and int types inside
  • Changed sbs file spec to support uniforms

1.2

  • Option to disable optimization
  • Fixed optimization errors

1.1

  • Full Metal support
  • Shader lang defines

1.0

  • First version

Inspired by

External libraries

supershader's People

Contributors

eduardodoria avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  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.