Safe Haskell | None |
---|---|
Language | Haskell2010 |
An example of shader variable:
newtype Transform2 = Transform2 M3
deriving (Typeable,-- This have a name in the shader.
ShaderType, -- This is a type in the GPU (3x3 matrix).
UniformCPU CM3) -- This can be used as an uniform
and you can set it using a CPU
3x3 matrix
(FWGL.Vector.M3
).
An example of vertex shader:
vertexShader :: VertexShader
-- The types of the uniforms:
'[Transform2, View2, Depth]
-- The types of the attributes:
'[Position2, UV]
-- The types of the varying (outputs), excluding VertexShaderOutput
.
'[UV]
vertexShader
-- Set of uniforms:
(Transform2 trans :- View2 view :- Depth z :- N)
-- Set of attributes:
(Position2 (V2 x y) :- uv@(UV _) :- N) =
-- Matrix and vector multiplication:
let V3 x' y' _ = view * trans * V3 x y 1
-- Set of outputs:
in Vertex (V4 x' y' z 1) -- Vertex position.
:- uv :- N
Required extensions:
{-# LANGUAGE DataKinds, RebindableSyntax, DeriveDataTypeable, GeneralizedNewtypeDeriving, GADTs #-}
- type Shader gs is os = STList gs -> STList is -> STList os
- type VertexShader g i o = Shader g i (VertexShaderOutput : o)
- type FragmentShader g i = Shader g i (FragmentShaderOutput : [])
- newtype VertexShaderOutput = Vertex V4
- newtype FragmentShaderOutput = Fragment V4
- class Typeable a
- class AllTypeable xs
- class ShaderType t
- class Typeable g => UniformCPU c g | g -> c
- class Typeable g => AttributeCPU c g | g -> c
- data Float
- data Sampler2D
- data V2 = V2 Float Float
- data V3 = V3 Float Float Float
- data V4 = V4 Float Float Float Float
- data M2 = M2 V2 V2
- data M3 = M3 V3 V3 V3
- data M4 = M4 V4 V4 V4 V4
- type CFloat = Float
- type CSampler2D = ActiveTexture
- type CV2 = V2
- type CV3 = V3
- type CV4 = V4
- type CM2 = M2
- type CM3 = M3
- type CM4 = M4
- negate :: Float -> Float
- fromInteger :: Integer -> Float
- fromRational :: Rational -> Float
- (*) :: (Mul a b c, ShaderType a, ShaderType b, ShaderType c) => a -> b -> c
- (/) :: (Mul a b c, ShaderType a, ShaderType b, ShaderType c) => a -> b -> c
- (+) :: (Sum a, ShaderType a) => a -> a -> a
- (-) :: (Sum a, ShaderType a) => a -> a -> a
- (^) :: (ShaderType a, ShaderType b) => a -> b -> a
- (&&) :: Bool -> Bool -> Bool
- (||) :: Bool -> Bool -> Bool
- (==) :: ShaderType a => a -> a -> Bool
- (>=) :: ShaderType a => a -> a -> Bool
- (<=) :: ShaderType a => a -> a -> Bool
- (<) :: ShaderType a => a -> a -> Bool
- (>) :: ShaderType a => a -> a -> Bool
- abs :: Float -> Float
- sign :: Float -> Float
- sqrt :: Float -> Float
- texture2D :: Sampler2D -> V2 -> V4
- data STList :: [*] -> * where
- (.) :: (b -> c) -> (a -> b) -> a -> c
- id :: a -> a
- const :: a -> b -> a
- flip :: (a -> b -> c) -> b -> a -> c
- ($) :: (a -> b) -> a -> b
Documentation
type Shader gs is os = STList gs -> STList is -> STList os
A function from a (heterogeneous) set of uniforms and a set of inputs (attributes or varyings) to a set of outputs (varyings).
type VertexShader g i o = Shader g i (VertexShaderOutput : o)
A Shader
with a VertexShaderOutput
output.
type FragmentShader g i = Shader g i (FragmentShaderOutput : [])
A Shader
with only a FragmentShaderOutput
output.
newtype VertexShaderOutput
The position of the vertex.
newtype FragmentShaderOutput
The RGBA color of the fragment (1.0 = #FF).
class Typeable a
The class Typeable
allows a concrete representation of a type to
be calculated.
class AllTypeable xs
AllTypeable ([] *) | |
(Typeable * x, AllTypeable xs) => AllTypeable ((:) * x xs) |
class ShaderType t
A type in the GPU.
class Typeable g => UniformCPU c g | g -> c
CPU types convertible to GPU types (as uniforms).
GLES => UniformCPU Float Float | |
GLES => UniformCPU M4 M4 | |
GLES => UniformCPU M3 M3 | |
GLES => UniformCPU M2 M2 | |
GLES => UniformCPU V4 V4 | |
GLES => UniformCPU V3 V3 | |
GLES => UniformCPU V2 V2 | |
GLES => UniformCPU ActiveTexture Sampler2D | |
GLES => UniformCPU CM4 View3 | |
GLES => UniformCPU CM4 Transform3 | |
GLES => UniformCPU CM3 View2 | |
GLES => UniformCPU CM3 Transform2 | |
GLES => UniformCPU CSampler2D Image | |
GLES => UniformCPU CSampler2D Texture2 | |
GLES => UniformCPU CFloat Depth |
class Typeable g => AttributeCPU c g | g -> c
CPU types convertible to GPU types (as attributes).
GLES => AttributeCPU Float Float | |
GLES => AttributeCPU V4 V4 | |
GLES => AttributeCPU V3 V3 | |
GLES => AttributeCPU V2 V2 | |
GLES => AttributeCPU CV3 Normal3 | |
GLES => AttributeCPU CV3 Position3 | |
GLES => AttributeCPU CV2 UV | |
GLES => AttributeCPU CV2 Position2 | |
GLES => AttributeCPU CV2 UV |
data Float
A GPU float.
Sum Float | |
ShaderType Float | |
Typeable * Float | |
GLES => AttributeCPU Float Float | |
GLES => UniformCPU Float Float | |
Mul M4 Float M4 | |
Mul M3 Float M3 | |
Mul M2 Float M2 | |
Mul V4 Float V4 | |
Mul V3 Float V3 | |
Mul V2 Float V2 | |
Mul Float M4 M4 | |
Mul Float M3 M3 | |
Mul Float M2 M2 | |
Mul Float V4 V4 | |
Mul Float V3 V3 | |
Mul Float V2 V2 | |
Mul Float Float Float |
data Sampler2D
A GPU sampler (sampler2D in GLSL).
data V3
A GPU 3D vector.
data V4
A GPU 4D vector.
data M2
A GPU 2x2 matrix.
data M3
A GPU 3x3 matrix.
data M4
A GPU 4x4 matrix.
type CSampler2D = ActiveTexture
Samplers in the CPU.
fromInteger :: Integer -> Float
fromRational :: Rational -> Float
(*) :: (Mul a b c, ShaderType a, ShaderType b, ShaderType c) => a -> b -> c infixl 7
(/) :: (Mul a b c, ShaderType a, ShaderType b, ShaderType c) => a -> b -> c infixl 7
(+) :: (Sum a, ShaderType a) => a -> a -> a infixl 6
(-) :: (Sum a, ShaderType a) => a -> a -> a infixl 6
(^) :: (ShaderType a, ShaderType b) => a -> b -> a infixr 8
(&&) :: Bool -> Bool -> Bool infixr 3
(||) :: Bool -> Bool -> Bool infixr 2
(==) :: ShaderType a => a -> a -> Bool infix 4
(>=) :: ShaderType a => a -> a -> Bool infix 4
(<=) :: ShaderType a => a -> a -> Bool infix 4
(<) :: ShaderType a => a -> a -> Bool infix 4
(>) :: ShaderType a => a -> a -> Bool infix 4
data STList :: [*] -> * where
An heterogeneous set of ShaderType
s and Typeable
s.
(.) :: (b -> c) -> (a -> b) -> a -> c infixr 9
Function composition.
id :: a -> a
Identity function.
const :: a -> b -> a
Constant function.
flip :: (a -> b -> c) -> b -> a -> c
takes its (first) two arguments in the reverse order of flip
ff
.
($) :: (a -> b) -> a -> b infixr 0
Application operator. This operator is redundant, since ordinary
application (f x)
means the same as (f
. However, $
x)$
has
low, right-associative binding precedence, so it sometimes allows
parentheses to be omitted; for example:
f $ g $ h x = f (g (h x))
It is also useful in higher-order situations, such as
,
or map
($
0) xs
.zipWith
($
) fs xs