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
- ifThenElse :: ShaderType a => Bool -> a -> a -> a
- loop :: ShaderType a => Float -> a -> (Float -> a -> (a, Bool)) -> a
- true :: Bool
- false :: Bool
- store :: ShaderType a => a -> a
- texture2D :: Sampler2D -> V2 -> V4
- radians :: GenType a => a -> a
- degrees :: GenType a => a -> a
- sin :: GenType a => a -> a
- cos :: GenType a => a -> a
- tan :: GenType a => a -> a
- asin :: GenType a => a -> a
- acos :: GenType a => a -> a
- atan :: GenType a => a -> a
- atan2 :: GenType a => a -> a -> a
- exp :: GenType a => a -> a
- log :: GenType a => a -> a
- exp2 :: GenType a => a -> a
- log2 :: GenType a => a -> a
- sqrt :: GenType a => a -> a
- inversesqrt :: GenType a => a -> a
- abs :: GenType a => a -> a
- sign :: GenType a => a -> a
- floor :: GenType a => a -> a
- ceil :: GenType a => a -> a
- fract :: GenType a => a -> a
- mod :: (GenType a, GenType b) => a -> b -> a
- min :: GenType a => a -> a -> a
- max :: GenType a => a -> a -> a
- clamp :: (GenType a, GenType b) => a -> b -> b -> a
- mix :: (GenType a, GenType b) => a -> a -> b -> a
- step :: GenType a => a -> a -> a
- smoothstep :: (GenType a, GenType b) => b -> b -> a -> a
- length :: GenType a => a -> Float
- distance :: GenType a => a -> a -> Float
- dot :: GenType a => a -> a -> Float
- cross :: V3 -> V3 -> V3
- normalize :: GenType a => a -> a
- faceforward :: GenType a => a -> a -> a -> a
- reflect :: GenType a => a -> a -> a
- refract :: GenType a => a -> a -> Float -> a
- matrixCompMult :: (Matrix a, Matrix b, Matrix c) => a -> b -> c
- position :: V4
- fragColor :: 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
- fst :: (a, b) -> a
- snd :: (a, b) -> 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 FragmentShaderOutput
The RGBA color of the fragment (1.0 = #FF).
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 | |
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
ifThenElse :: ShaderType a => Bool -> a -> a -> a
Rebinded if.
:: ShaderType a | |
=> Float | Maximum number of iterations (should be as low as possible, must be an integer literal) |
-> a | Initial value |
-> (Float -> a -> (a, Bool)) | Iteration -> Old value -> (Next, Stop) |
-> a |
true :: Bool
false :: Bool
store :: ShaderType a => a -> a
Avoid executing this expression more than one time. Conditionals and loops imply it.
radians :: GenType a => a -> a
degrees :: GenType a => a -> a
sin :: GenType a => a -> a
cos :: GenType a => a -> a
tan :: GenType a => a -> a
asin :: GenType a => a -> a
acos :: GenType a => a -> a
atan :: GenType a => a -> a
atan2 :: GenType a => a -> a -> a
exp :: GenType a => a -> a
log :: GenType a => a -> a
exp2 :: GenType a => a -> a
log2 :: GenType a => a -> a
sqrt :: GenType a => a -> a
inversesqrt :: GenType a => a -> a
abs :: GenType a => a -> a
sign :: GenType a => a -> a
floor :: GenType a => a -> a
ceil :: GenType a => a -> a
fract :: GenType a => a -> a
mod :: (GenType a, GenType b) => a -> b -> a
min :: GenType a => a -> a -> a
max :: GenType a => a -> a -> a
clamp :: (GenType a, GenType b) => a -> b -> b -> a
mix :: (GenType a, GenType b) => a -> a -> b -> a
step :: GenType a => a -> a -> a
smoothstep :: (GenType a, GenType b) => b -> b -> a -> a
normalize :: GenType a => a -> a
faceforward :: GenType a => a -> a -> a -> a
reflect :: GenType a => a -> a -> a
matrixCompMult :: (Matrix a, Matrix b, Matrix c) => a -> b -> c
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
fst :: (a, b) -> a
Extract the first component of a pair.
snd :: (a, b) -> b
Extract the second component of a pair.