• Stars
    star
    279
  • Rank 147,967 (Top 3 %)
  • Language
    C++
  • License
    MIT License
  • Created about 6 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

⚔️ A tool for cross compiling shaders. Convert between GLSL, HLSL, Metal Shader Language, or older versions of GLSL.

Logo

⚔️ CrossShader

Npm Package cmake-img License Travis Tests Dependency Status

A cross compiler for shader languages. Convert between SPIR-V, GLSL / GLSL ES, HLSL, Metal Shader Language, or older versions of a given language. Cross Shader wraps DirectX Shader Compiler, glslang, Mozilla Naga and SPIRV-Cross, exposing a simpler interface to transpile shaders.

Installation

Node.js Installation

npm i cross-shader -S

Using this module will require Node 8.x or above, or a browser that supports WebAssembly.

C++ Installation

First add the repo as a submodule in your dependencies folder such as external/:

cd external
git submodule add https://github.com/alaingalvan/crossshader.git

Then in your CMakeLists.txt file, include the following:

# ⬇ Add your dependency:
add_subdirectories(external/crossshader)

# 🔗 Link CrossShader to your project:
target_link_libraries(
    ${PROJECT_NAME}
    CrossShader
)

Usage

This library exposes a single function compile(...) and its config structs/enums, and returns either the output string, or throws an exception if there's an error compiling, with the error message exposed in the exception object.

Node.js Example

TypeScript types are included, refer to cross-shader.d.ts for more details.

Similar to other WebAssembly modules, importing the module gives you a promise to the compiled WebAssembly binary:

import xsdr from "cross-shader";

xsdr.then(({ compile, ShaderFormat, ShaderStage }) => {
  const ioptions = {
    format: ShaderFormat.GLSL,
    stage: ShaderStage.Vertex,
    es: false,
    glslVersion: 450,
  };

  const ooptions = {
    format: ShaderFormat.GLSL,
    es: true,
    glslVersion: 100,
  };

  let outputString = compile(inputString, ioptions, ooptions);
});

C++ Example

Refer to src/CrossShader/CrossShader.h for more details.

#include "CrossShader/CrossShader.h"

void main()
{
  xsdr::InputOptions ioptions;
  ioptions.format = xsdr::ShaderFormat::GLSL;
  ioptions.stage = xsdr::ShaderStage::Vertex;
  ioptions.es = false;
  ioptions.glslVersion = 110;

  xsdr::OutputOptions ooptions;
  ooptions.format = xsdr::ShaderFormat::GLSL;
  ooptions.es = true;
  ooptions.glslVersion = 100;

  std::string out = xsdr::compile(vertSource, ioptions, ooptions);
}

Development

Be sure to have:

And type the following in any folder:

# 🐑 Clone the repo
git clone https://github.com/alaingalvan/crossshader.git --recurse-submodules

# 💿 go inside the folder
cd crossshader

# 👯 If you forget to `recurse-submodules` you can always run:
git submodule update --init

From there we'll need to set up our build files. Be sure to have the following installed:

Then type the following in your terminal from the repo folder:

# 🖼️ To build your Visual Studio solution on Windows x64
cmake . -B build/vs -A x64

# 🍎 To build your XCode project on Mac OS
cmake .. -B build/xcode -G Xcode

# 🐧 To build your MakeFile on Linux
cmake -B build/make ..

# 🔨 Build on any platform:
cmake --build .

Whenever you add new files to the project, run cmake .. from your solution/project folder, and if you edit the CMakeLists.txt file be sure to delete the generated files and run Cmake again.

WebAssembly

Note: if you're on Windows, I would highly recommend using the Windows Subsystem for Linux.

First, install the latest version of Emscripten via the Emscripten SDK. Make sure to add it's Emscripten installation to your PATH, then:

# ⚠️ Possible dependencies you might need:
sudo apt-get update
sudo apt-get install cmake build-essential llvm

# 🏃 Then run the following:
emcmake cmake . -B build/wasm
emmake make CrossShader -j

License

CrossShader is licensed as either MIT or Apache-2.0, whichever you would prefer.

More Repositories

1

CrossWindow

💻📱 A cross platform system abstraction library written in C++ for managing windows and performing OS tasks.
C++
620
star
2

webgpu-seed

🔺🌱 An example on how to render a hello triangle with WebGPU.
TypeScript
296
star
3

directx12-seed

✖🌱 A DirectX 12 starter repo that you could use to get the ball rolling.
C++
127
star
4

image-editor-effects

💎 A WebGL example of image adjustment / effects shaders found in Photoshop, other image editors and game engines.
TypeScript
96
star
5

a-trip-through-the-graphics-pipeline-book

📕 A clone of @rygorous series of posts on the graphics pipeline.
84
star
6

CrossWindow-Graphics

A header only library to simplify creating 🌋 Vulkan / ⚪ OpenGL / 🌐 WebGL / ❎DirectX / 🤖 Metal data structures with CrossWindow.
C++
79
star
7

vulkan-seed

🌋🌱 A Vulkan starter repo that you could use to get the ball rolling.
C++
75
star
8

CrossWindow-Demos

🥪 Examples of how to use CrossWindow for things like rendering graphics, listening to events, etc.
C++
66
star
9

webgl-seed

🌐🌱 A starter repo for building WebGL applications.
TypeScript
48
star
10

raw-vulkan

🔥 Experiments building Vulkan applications, libraries, and abstractions.
C++
45
star
11

GPU-Zen-2-Baker

🥧 An OpenGL 4.x example of GPU Zen 2's ray casting techniques for baked texture generation chapter.
CMake
41
star
12

metal-seed

🤖🌱 An Apple Metal starter repo that you could use to get the ball rolling.
Objective-C++
38
star
13

opengl-seed

⚪🌱A modern OpenGL starter repo that you could use to get the ball rolling.
C++
33
star
14

fig-standing-desk

🗜️ A custom standing desk that you can control from the command line.
Rust
16
star
15

strange-attractors

⤴️ Algorithms to generate strange attractors such as Lorenz, Burgers, etc.
Python
15
star
16

foil

✨ A portfolio CMS library designed for engineers, artists, technical artists, musicians, and bloggers looking to showcase a portfolio of front-end experiments, games, art, articles, and more.
Rust
11
star
17

PxWar

🚀 A bullethell game built with TypeScript and Canvas.
TypeScript
6
star
18

opengl-seed-wasm

🌐⚪ An example of of the opengl-seed example compiled to WebAssembly.
HTML
6
star
19

ora

💡 A game where you're a blur of light trying to escape an encroaching darkness made for the 2012 GameMaker Steam Workshop.
Game Maker Language
4
star
20

alaingalvan

⁉ About Alain Galvan, Graphics Software Engineer.
3
star
21

crosswindow-imgui

🖌️ An optional library wrapping ImGui and providing bindings for CrossWindow events.
C++
3
star
22

alainxyz-comments

🔮 Utterances powered comments for the Alain.xyz blog.
2
star
23

conan-vulkan-sdk

Conan package for the Vulkan SDK.
Python
2
star
24

guardian

👼 A real time monster based role playing game (RPG) I made for GameMaker's 2010 summer competition.
Game Maker Language
2
star
25

foil-starters

🌠 A monorepo of all available starters for the foil CMS.
SCSS
1
star