GithubHelp home page GithubHelp logo

just-feeshy / crossshader Goto Github PK

View Code? Open in Web Editor NEW

This project forked from alaingalvan/crossshader

0.0 0.0 0.0 769 KB

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

Home Page: https://alain.xyz/libraries/crossshader

License: MIT License

JavaScript 3.02% C++ 49.75% TypeScript 8.90% CMake 32.08% GLSL 6.25%

crossshader's Introduction

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.

crossshader's People

Contributors

alaingalvan avatar just-feeshy 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.