hylogen: Purely functional GLSL embedded in Haskell

[ graphics, library, mit ] [ Propose Tags ]

Purely functional GLSL embedded in Haskell


[Skip to Readme]

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

  • No Candidates
Versions [RSS] 0.1.0.0, 0.1.0.1, 0.1.0.2, 0.1.0.3, 0.1.0.4, 0.1.0.5, 0.1.0.6, 0.1.0.8, 0.1.0.10, 0.1.0.11, 0.1.0.12, 0.1.1.0, 0.1.1.1, 0.1.1.2, 0.1.1.3, 0.1.2.0, 0.1.2.1, 0.1.2.2, 0.1.2.3, 0.1.3.0, 0.1.3.1, 0.1.3.2, 0.1.4.0, 0.1.4.1, 0.1.5.0, 0.1.5.1
Dependencies base (>=4.8 && <5), data-reify, vector-space [details]
License MIT
Author Sean Lee
Maintainer freshdried@gmail.com
Category Graphics
Home page https://github.com/sleexyz/hylogen
Uploaded by sleexyz at 2016-06-10T05:39:16Z
Distributions NixOS:0.1.5.1
Reverse Dependencies 1 direct, 0 indirect [details]
Downloads 15908 total (61 in the last 30 days)
Rating 2.25 (votes: 2) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs uploaded by user
Build status unknown [no reports yet]

Readme for hylogen-0.1.4.1

[back to package description]

H Y L O G E N Hackage Status Join the chat at https://gitter.im/sleexyz/hylogen

Hylogen is a purely functional shader language embedded in Haskell that compiles to GLSL. It functions as a powerful alternative to GLSL by leveraging many features of Haskell, including:

Type inference - Write more concise code by allowing Haskell to infer the types of your expressions.

  • GLSL: vec4 foo = vec4(3.0);
  • Hylogen: foo = 3

Higher-order functions - Use your standard Haskell goodies: map, foldl/foldr, $, ., &, etc, or write your own!

Modules - Split up complex shaders into multiple files. Write your own high level libraries and import them as modules.

Hylide is a livecoding WebGL renderer built for Hylogen. It features hot-reloading, audio-reactivity and texture backbuffering. However, Hylogen is a general purpose shader language; it can be used anywhere GLSL is used.


Demo Reel

Changelog - NEW: Hylogen/Hylide split in Hylogen 0.1.4

Hylogen is in alpha! Feature requests, questions, and discussion welcome on github issues


Install

  1. Install the Haskell Platform
  2. cabal update && cabal install hylogen hylide

Example

Here's a simple Hylogen shader to be used with Hylide, saved as Example.hs:


module Example where
import Hylogen.WithHylide

output :: Program
output = toProgram color

color :: Vec4
color = vec4 (a, a, a, 1)
  where
    k = 20
    f = (*k) . sin . (/k)
    a = sum [ cos (x_ uvN * f time + x_ mouse )
            , sin (y_ uvN * f time + y_ mouse )
            ]

Run Hylide:

$ hylide Example.hs

Now go to localhost:5678 in your browser. You'll see a live rendering of the corresponding generated GLSL:

void main() {
    float _7 = uvN.x;
    float _10 = (time / 20.0);
    float _9 = sin(_10);
    float _8 = (_9 * 20.0);
    float _6 = (_7 * _8);
    float _11 = mouse.x;
    float _5 = (_6 + _11);
    float _4 = cos(_5);
    float _3 = (0.0 + _4);
    float _15 = uvN.y;
    float _18 = (time / 20.0);
    float _17 = sin(_18);
    float _16 = (_17 * 20.0);
    float _14 = (_15 * _16);
    float _19 = mouse.y;
    float _13 = (_14 + _19);
    float _12 = sin(_13);
    float _2 = (_3 + _12);
    vec4 _1 = vec4(_2, _2, _2, 1.0);

    gl_FragColor = _1;
}

Hylide will recompile on changes to the Haskell source, sending generated GLSL to the WebGL client via websockets.

References

  • The_Force by Shawn Lawson. Initial inspiration for Hylogen/Hylide. Live-coding of audio-reactive shaders!
  • data-reify by Andy Gill, to keep intermediate AST representations from exploding by preserving the GHC heap's internal sharing

Conceived of at the Recurse Center :)