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.
In order to run this you need to have installed
- Haskell
- Stack
- SDL2
- [for linux]
sudo apt install libsdl2-dev
- [for linux]
- clone this repo
git clone https://github.com/schell/gristle.git
- enter the directory
cd gristle
- install the project
ghc Setup.hs
stack install
stack install
generates two commands:
gristle-exe
and
gristle-example-exe
-
gristle-exe
runs the code written ingristle/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 ingristle-example/app/Main.hs
. Right now it runs a color gradient shader in a window.
{-# 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
]