Git Product home page Git Product logo

arcadia-gamma's Introduction

gamma

Join the chat at https://gitter.im/kovasb/gamma

Gamma is a substrate for graphics software, such as games and data visualization tools. It presents a simple, composable language for representing GLSL shaders.

Benefits:

  • Decouple, simplify, abstract shader code
  • Release graphics pipeline from rigid demands of shaders
  • Create composable, multiplatform shader libraries
  • Quickly build higher-level GL libraries

Technically, Gamma is an EDSL that hosts GLSL within Clojurescript. It is inspired by Carlos Scheidegger's Lux and Conal Elliot's Vertigo and Pan. Gamma targets the WebGL subset of the OpenGL ES 1.0 Shading Language. Gamma can be used a la carte to compile shader source, without adopting Clojure/Clojurescript for your runtime application.

Gamma is very early alpha.

Installation

Add the following to your project.clj's :dependencies

[kovasb/gamma "0.0-135"]

Be sure to use clojurescript 0.0-3292 or above:

[org.clojure/clojurescript "0.0-3292"]

"Hello Triangle" Tutorial

See the batteries-included Hello Triangle example project for how to set up your project, and how to invoke the generated shader so that a triangle appears on screen.

Lets use Gamma at the REPL to create a minimum shader program for drawing a red triangle.

(require '[gamma.api :as g])
(require '[gamma.program :as p])
;; shader input attribute will be a vec2 of x,y coordinates
(def vertex-position (g/attribute "a_VertexPosition" :vec2))

;; vertex shader turns input into a vec4, and assigns it to gl_Position
(def vertex-shader {(g/gl-position) (g/vec4 vertex-position 0 1)})

;; fragment shader assigns the rgba value for red to gl_FragColor 
(def fragment-shader {(g/gl-frag-color) (g/vec4 1 0 0 1)})

;; compile Gamma into a GLSL program string 
(def hello-triangle 
  (p/program 
    {:vertex-shader vertex-shader 
     :fragment-shader fragment-shader}))

Thats it! hello-triangle now contains the GLSL for this shader, and other useful information such as a description of its inputs.

;; print vertex shader glsl
(println (:glsl (:vertex-shader hello-triangle)))
=> 
"attribute vec2 a_VertexPosition;
void main(void){
 gl_Position = vec4(a_VertexPosition, 0, 1);
}"

;; print fragment shader glsl
(println (:glsl (:fragment-shader hello-triangle)))
=>
"void main(void){
 gl_FragColor = vec4(1, 0, 0, 1);
}"

;; get shader inputs 
(:inputs hello-triangle)
=> #{{:tag :variable, :name "a_VertexPosition", :type :vec2, :storage :attribute}}

License

Copyright © 2015 Kovas Boguta

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

arcadia-gamma's People

Contributors

kovasb avatar sgrove avatar jlongster avatar gitter-badger avatar timsgardner 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.