https://github.com/schell/gristle
Like ixshader but ergonomic
https://github.com/schell/gristle
Last synced: about 2 months ago
JSON representation
Like ixshader but ergonomic
- Host: GitHub
- URL: https://github.com/schell/gristle
- Owner: schell
- Created: 2018-04-28T21:42:34.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2020-09-27T05:48:45.000Z (over 4 years ago)
- Last Synced: 2025-02-27T11:05:21.186Z (2 months ago)
- Language: Haskell
- Size: 56.6 KB
- Stars: 9
- Watchers: 4
- Forks: 1
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# gristle
This is the spiritial successor to [ixshader](https://github.com/schell/ixshader).
It was started at [BayHac2018](https://wiki.haskell.org/BayHac2018) and I hope to
use it as the bottom layer of rendering in [gelatin](https://github.com/schell/gelatin).# Table of Contents
1. [Prerequisites](#prerequisites)
2. [Installation](#installation)
3. [Usage](#usage)
4. [Contribuitors](#contribuitors)# Prerequisites
In order to run this you need to have installed
* Haskell
* Stack
* [Instructions](https://docs.haskellstack.org/en/stable/README/)
* 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.
## see
```haskell
{-# LANGUAGE DataKinds #-}
module Main whereimport 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 .= pos4fragment :: 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);
-- }
--
-- -------------------- fragment
-- in vec4 a;
-- out vec4 b;
-- void main () {
-- b = a;
-- }
--
main :: IO ()
main = putStr $ unlines [ replicate 20 '-' ++ " vertex"
, glsl $ shader vertex
, replicate 20 '-' ++ " fragment"
, glsl $ shader fragment
]
```# Contribuitors
* [Schell Carl Scivally](https://github.com/schell)
* [Karen Palacio](https://github.com/karen-pal/)