Skip to content

schell/gristle

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

gristle

This is the spiritial successor to ixshader. It was started at BayHac2018 and I hope to use it as the bottom layer of rendering in gelatin.

Table of Contents

  1. Prerequisites
  2. Installation
  3. Usage
  4. Contribuitors

Prerequisites

In order to run this you need to have installed

  • Haskell
  • Stack
  • SDL2
    • [for linux] sudo apt install libsdl2-dev

Installation

  • clone this repo
    • git clone https://github.com/schell/gristle.git
  • enter the directory
    • cd gristle
  • install the project
    • ghc Setup.hs
    • stack install

Usage

stack install generates two commands:

gristle-exe

and

gristle-example-exe
  • gristle-exe runs the code written in gristle/app/Main.hs. Right now that code generates the glsl code for the haskell shader and outputs it on the terminal.

  • gristle-example-exe runs the code written in gristle-example/app/Main.hs. Right now it runs a color gradient shader in a window.

window with gristle example running

see

{-# LANGUAGE DataKinds #-}
module Main where

import Gristle

vertex
  :: Value (In (Vec 2 Float))
  -> Value (In (Vec 4 Float))
  -> Value (Uniform (Mat 4 4))
  -> Value (Out (Vec 4 Float))
  -> GLSL ()
vertex position _ _ outColor = do
  let (x, y) = decomp $ readAttrib position
      pos4   = vec4 x y 0.0 1.0
  outColor .= pos4

fragment :: Value (In (Vec 4 Float)) -> Value (Out (Vec 4 Float)) -> GLSL ()
fragment inColor outColor = outColor .= readAttrib inColor

-- | A demonstration of using Haskell's type system to generate glsl shaders.
--
-- >>> main
-- -------------------- vertex
-- in vec2 a;
-- in vec4 b;
-- uniform mat4 c;
-- out vec4 d;
-- void main () {
--   d = vec4(a[0], a[1], 0.0, 1.0);
-- }
-- <BLANKLINE>
-- -------------------- fragment
-- in vec4 a;
-- out vec4 b;
-- void main () {
--   b = a;
-- }
-- <BLANKLINE>
main :: IO ()
main = putStr $ unlines [ replicate 20 '-' ++ " vertex"
                        , glsl $ shader vertex
                        , replicate 20 '-' ++ " fragment"
                        , glsl $ shader fragment
                        ]

Contribuitors

About

Like ixshader but ergonomic

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published