Giter Club home page Giter Club logo

hylogen's Introduction

H Y L O G E N

An embedding of GLSL in Haskell.

H Y L I D E

A live coding environment for writing shaders with Hylogen.



Install

Build from source, using Stack:

  1. Install stack
  2. git clone https://github.com/sleexyz/hylogen.git
  3. cd hylogen
  4. stack build

This is the recommended method of using Hylogen, because using Stack you can share your projects and be confident that others will be using the same version of Hylogen as you. To install it to your system so it can be used anywhere, not just inside the hylogen folder, use stack install instead of stack build.

Hylogen can also be installed to your system using the Haskell Platform:

  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 (available in the examples/ directory):

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:

$ stack exec hylide Example.hs

If Hylide was installed using the haskell platform, you can omit stack exec:

$ 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 over websockets.

References

  • The_Force by Shawn Lawson. This was the initial inspiration for Hylide.
  • data-reify for type-safe observable sharing.

Conceived of at the Recurse Center :)

hylogen's People

Contributors

austinvhuang avatar gitter-badger avatar sleexyz avatar vivid-synth avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

hylogen's Issues

Monad DSL

A few things are inexpressible in the pure DSL:

  • rolled for loops: the cost of parsing unrolled loops grows linearly, so currently your compile times actually grow with higher iteration counts :(
  • custom uniforms
  • GLSL functions

In general we want to generate code that is concise as possible to minimize compile times of the generated GLSL

Should Vec1 uniforms really be polymorphic?

Pros:

  • kinda intuitive
  • no need to import Data.VectorSpace for scalar multiplication
  • ergonomic (the alternative, *^, is a terrible to type)

Cons:

  • type-wise confusing
  • inconsistent; the programmer might get used to "scalar multiplication" via polymorphism, when it only works on global uniforms

custom texture management?

We've implemented the primitive for a backbuffer.

Now how do we do it for arbitrary images?
specify textures in a local folder?

Typesafe polymorphic unswizzling

Right now: only one way to make Vec4 from HyloPrims:

Vec4 :: (Vec1, Vec1, Vec1, Vec1) -> Vec4

Desired: More ways:

Vec4 :: (Vec3, Vec1) -> Vec4
...
etc

Add tutorials

Language

  • getting started
  • copy
  • swizzling/unswizzling

Applications with Hylide

  • audio reactivity!
  • texture-backbuffering
  • signed-distance fields

Use it in your own project

  • defining your own uniforms

Allow custom uniforms

Have hylogen the language generate programs other than those for the hylogen server

implement enum for Veccables

non trivial, this might involve making changes to the AST for a specific Numeric form.
mainly for syntactic niceities

Matricies

hmmm.....

bug is that we need matricies!

Add audio

And clean up javascript code?

via Per-uniform dependency injection

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.