Skip to content
For those who love graphics programming and hate shading languages
Branch: master
Clone or download
Jeremy Kross
Jeremy Kross Tweak readme.
Latest commit 95a8d69 Jul 8, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src/to_glsl initial commit Jul 9, 2019
.gitignore initial commit Jul 9, 2019
Makefile initial commit Jul 9, 2019
README.md Tweak readme. Jul 9, 2019
deps.edn initial commit Jul 9, 2019
pom.xml initial commit Jul 9, 2019

README.md

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

You can’t perform that action at this time.