Giter VIP home page Giter VIP logo

to-glsl's Introduction

To-GLSL

Introduction

To-GLSL is a library for converting Clojure s-expressions to GLSL.

Usage

[to-glsl "0.1.0-SNAPSHOT"]

Example

(def basic-vs
  '(do
     (def-attribute vec4 vertex-position)
     (def-attribute vec2 tex-coord-attr)

     (def-uniform mat4 model-view)
     (def-uniform mat4 projection)

     (def-varying (highp vec2) tex-coord)

     (defn main (void [])
       (set! tex-coord tex-coord-attr)
       (set!
         gl/position
         (* projection model-view vertex-position)))))

(def basic-fs
  '(do
     (def-uniform sampler-2D sampler)
     (def-varying (highp vec2) tex-coord)

     (defn main (void [])
       (set! gl/frag-color (texture-2D sampler tex-coord)))))

(require '[to-glsl.core :refer [->glsl]])

(def vs-source (->glsl basic-vs))
(def fs-source (->glsl basic-fs))

Supported Language

defn

(defn add-one (void [(int x)]) (+ x 1))

becomes:

void addOne(int x) {
  x + 1;
}

Note: types must be specified

def

(def float pi 3.14159)

becomes

float pi = 3.14159;

def-varying - like def but creates a varying

def-uniform - like def but creates a uniform

def-attribute - like def but creates an attribute

set!

(set! x 5)

becomes

x = 5;

when

(when (and (= x 10) (= z 30))
  (set! y 20))

becomes

if (x == 10 && z == 30) {
  y = 20;
}

if

(set! y (if (= x 10) 20 10))

becomes

y = x == 10 ? 20 : 10;

and, or, =, +, -, /, *, bit-and, bit-or, bit-xor, bit-not, bit-shift-right, bit-shift-left - all compile into appriate infix form.

inc and dec - compile into ++ and -- repectively.

field

(field vec x)

becomes

vec.x

swizzle

(swizzle vec x z)

becomes

vec.xz

All symbols are automatically converted from kebab case into camel case.

The GLSL gl_ symbols like gl_Position and gl_FragColor can be accessed under the gl/ namespace in kebab case. i.e. gl/frag-color.

To-GLSL doesn't make any attempt to validate the provided code.

License

Copyright 2019 Jeremy Kross

Distributed under the Eclipse Public License either version 1.0 or (at your option) any later version.

to-glsl's People

Contributors

jeremykross avatar blak3mill3r avatar

Stargazers

Anton Volkov avatar  avatar Sylvain Ageneau avatar Carsten Heisterkamp avatar Joseph Kunin avatar Pankaj Doharey avatar  avatar Dima Novotochinov avatar  avatar Carl Hu avatar Alan Moore avatar Vlad Bokov avatar Ertuğrul Çetin avatar Josh Tilles avatar  avatar Sibelius Seraphini avatar Caio Oliveira avatar  avatar Chris Zheng avatar Josef Pospíšil avatar Volker Einsfeld avatar John Newman avatar dann toliver avatar Dmitri Sotnikov avatar Camilo Polymeris avatar DiGiTAL_CuRSe avatar

Watchers

Pankaj Doharey avatar James Cloos 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.