Safe Haskell | None |
---|---|
Language | Haskell2010 |
An example of shader variable:
newtype Transform2 = Transform2 Mat3
deriving (Typeable,
ShaderType, -- This is a type in the GPU (3x3 matrix).
UniformCPU CMat3) -- This can be used as an uniform
-- and you can set it using a CPU
-- 3x3 matrix
-- (FWGL.Vector.Mat3
)
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 (Vec2 x y) :- uv@(UV _) :- N) =
-- Matrix and vector multiplication:
let Vec3 x' y' _ = view * trans * Vec3 x y 1
-- Set of outputs:
in Vertex (Vec4 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 Vec4
- newtype FragmentShaderOutput = Fragment Vec4
- 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 STList :: [*] -> * where
- data Bool
- data Float
- data Int
- data Sampler2D
- data SamplerCube
- data Vec2 = Vec2 Float Float
- data Vec3 = Vec3 Float Float Float
- data Vec4 = Vec4 Float Float Float Float
- data BVec2 = BVec2 Bool Bool
- data BVec3 = BVec3 Bool Bool Bool
- data BVec4 = BVec4 Bool Bool Bool Bool
- data IVec2 = IVec2 Int Int
- data IVec3 = IVec3 Int Int Int
- data IVec4 = IVec4 Int Int Int Int
- data Mat2 = Mat2 Vec2 Vec2
- data Mat3 = Mat3 Vec3 Vec3 Vec3
- data Mat4 = Mat4 Vec4 Vec4 Vec4 Vec4
- data Array n t
- type CInt = Int32
- type CBool = Int32
- type CFloat = Float
- type CSampler2D = ActiveTexture
- type CSamplerCube = ActiveTexture
- type CVec2 = Vec2
- type CVec3 = Vec3
- type CVec4 = Vec4
- type CIVec2 = IVec2
- type CIVec3 = IVec3
- type CIVec4 = IVec4
- type CBVec2 = IVec2
- type CBVec3 = IVec3
- type CBVec4 = IVec4
- type CMat2 = Mat2
- type CMat3 = Mat3
- type CMat4 = Mat4
- type CArray a = [a]
- toGPUBool :: Bool -> Int32
- loop :: ShaderType a => Int -> a -> (Int -> a -> (a, Bool)) -> a
- store :: ShaderType a => a -> a
- texture2D :: Sampler2D -> Vec2 -> Vec4
- texture2DBias :: Sampler2D -> Vec2 -> Float -> Vec4
- texture2DProj :: Sampler2D -> Vec3 -> Vec4
- texture2DProjBias :: Sampler2D -> Vec3 -> Float -> Vec4
- texture2DProj4 :: Sampler2D -> Vec4 -> Vec4
- texture2DProjBias4 :: Sampler2D -> Vec4 -> Float -> Vec4
- texture2DLod :: Sampler2D -> Vec2 -> Float -> Vec4
- texture2DProjLod :: Sampler2D -> Vec3 -> Float -> Vec4
- texture2DProjLod4 :: Sampler2D -> Vec4 -> Float -> Vec4
- arrayLength :: (ShaderType t, KnownNat n) => Array n t -> Int
- 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 :: GenTypeFloat a b => a -> b -> a
- min :: GenTypeFloat a b => a -> b -> a
- max :: GenTypeFloat a b => a -> b -> a
- clamp :: GenTypeFloat a b => a -> b -> b -> a
- mix :: GenTypeFloat a b => a -> a -> b -> a
- step :: GenTypeFloat a b => b -> a -> a
- smoothstep :: GenTypeFloat a b => b -> b -> a -> a
- length :: GenType a => a -> Float
- distance :: GenType a => a -> a -> Float
- dot :: GenType a => a -> a -> Float
- cross :: Vec3 -> Vec3 -> Vec3
- 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
- class ShaderType a => VecOrd a
- class ShaderType a => VecEq a
- lessThan :: VecOrd a => a -> a -> Bool
- lessThanEqual :: VecOrd a => a -> a -> Bool
- greaterThan :: VecOrd a => a -> a -> Bool
- greaterThanEqual :: VecOrd a => a -> a -> Bool
- equal :: VecEq a => a -> a -> Bool
- notEqual :: VecEq a => a -> a -> Bool
- class ShaderType a => BoolVector a
- anyB :: BoolVector a => a -> Bool
- allB :: BoolVector a => a -> Bool
- notB :: BoolVector a => a -> Bool
- true :: Bool
- false :: Bool
- class ShaderType t => ToBool t
- bool :: ToBool t => t -> Bool
- class ShaderType t => ToInt t
- int :: ToInt t => t -> Int
- class ShaderType t => ToFloat t
- float :: ToFloat t => t -> Float
- type family Components t :: Nat
- data CompList count
- class ToCompList x n | x -> n
- (#) :: (ToCompList x xn, ToCompList y yn) => x -> y -> CompList (xn + yn)
- class ToVec2 t where
- class ToVec3 t where
- class ToVec4 t where
- class ToBVec2 t where
- class ToBVec3 t where
- class ToBVec4 t where
- class ToIVec2 t where
- class ToIVec3 t where
- class ToIVec4 t where
- class ToMat2 t where
- class ToMat3 t where
- class ToMat4 t where
- (*) :: (Mul aBase bBase a b c, ShaderType a, ShaderType b, ShaderType c) => a -> b -> c
- (/) :: (Arithmetic aBase bBase a b c, ShaderType a, ShaderType b, ShaderType c) => a -> b -> c
- (+) :: (Arithmetic aBase bBase a b c, ShaderType a, ShaderType b, ShaderType c) => a -> b -> c
- (-) :: (Arithmetic aBase bBase a b c, ShaderType a, ShaderType b, ShaderType c) => a -> b -> c
- (^) :: (ShaderType a, GenType a) => a -> a -> 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
- (!) :: (ShaderType t, KnownNat n) => Array n t -> Int -> t
- fromInteger :: Num a => Integer -> a
- fromRational :: Rational -> Float
- ifThenElse :: ShaderType a => Bool -> a -> a -> a
- negate :: GenType a => a -> a
- (.) :: (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
- position :: Vec4
- fragColor :: Vec4
- fragCoord :: Vec4
- fragFrontFacing :: Bool
Types
type Shader gs is os = STList gs -> STList is -> STList os Source
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) Source
A Shader
with a VertexShaderOutput
output.
type FragmentShader g i = Shader g i (FragmentShaderOutput : `[]`) Source
A Shader
with only a FragmentShaderOutput
output.
newtype VertexShaderOutput Source
The position of the vertex.
newtype FragmentShaderOutput Source
The RGBA color of the fragment (1.0 = #FF).
class AllTypeable xs Source
AllTypeable ([] *) Source | |
(Typeable * x, AllTypeable xs) => AllTypeable ((:) * x xs) Source |
class ShaderType t Source
A type in the GPU.
class Typeable g => UniformCPU c g | g -> c Source
CPU types convertible to GPU types (as uniforms).
class Typeable g => AttributeCPU c g | g -> c Source
CPU types convertible to GPU types (as attributes).
GLES => AttributeCPU Float Float Source | |
GLES => AttributeCPU Int32 Int Source | |
GLES => AttributeCPU Int32 Bool Source | |
GLES => AttributeCPU Vec2 Vec2 Source | |
GLES => AttributeCPU Vec3 Vec3 Source | |
GLES => AttributeCPU Vec4 Vec4 Source | |
GLES => AttributeCPU IVec4 BVec4 Source | |
GLES => AttributeCPU IVec4 IVec4 Source | |
GLES => AttributeCPU IVec3 BVec3 Source | |
GLES => AttributeCPU IVec3 IVec3 Source | |
GLES => AttributeCPU IVec2 BVec2 Source | |
GLES => AttributeCPU IVec2 IVec2 Source | |
GLES => AttributeCPU CVec3 Normal3 Source | |
GLES => AttributeCPU CVec3 Position3 Source | |
GLES => AttributeCPU CVec2 UV Source | |
GLES => AttributeCPU CVec2 Position2 Source | |
GLES => AttributeCPU CVec2 UV Source |
data STList :: [*] -> * where Source
An heterogeneous set of ShaderType
s and Typeable
s.
GPU types
A GPU boolean.
A GPU float.
A GPU integer.
A GPU 2D texture handle.
data SamplerCube Source
A GPU cube texture handler.
A GPU 2D float vector.
NB: This is a different type from Data.Vect.Float.Vec2
.
A GPU 3D float vector.
A GPU 4D float vector.
A GPU 2D boolean vector.
A GPU 3D boolean vector.
A GPU 4D boolean vector.
A GPU 2D integer vector.
A GPU 3D integer vector.
A GPU 4D integer vector.
A GPU 2x2 float matrix.
A GPU 3x3 float matrix.
A GPU 4x4 float matrix.
A GPU array.
(Typeable Nat n, GLES) => UniformCPU [Float] (Array n Float) Source | |
(Typeable Nat n, GLES) => UniformCPU [Int32] (Array n Int) Source | |
(Typeable Nat n, GLES) => UniformCPU [Int32] (Array n Bool) Source | |
(Typeable Nat n, GLES) => UniformCPU [Vec2] (Array n Vec2) Source | |
(Typeable Nat n, GLES) => UniformCPU [Vec3] (Array n Vec3) Source | |
(Typeable Nat n, GLES) => UniformCPU [Vec4] (Array n Vec4) Source | |
(Typeable Nat n, GLES) => UniformCPU [IVec4] (Array n BVec4) Source | |
(Typeable Nat n, GLES) => UniformCPU [IVec4] (Array n IVec4) Source | |
(Typeable Nat n, GLES) => UniformCPU [IVec3] (Array n BVec3) Source | |
(Typeable Nat n, GLES) => UniformCPU [IVec3] (Array n IVec3) Source | |
(Typeable Nat n, GLES) => UniformCPU [IVec2] (Array n BVec2) Source | |
(Typeable Nat n, GLES) => UniformCPU [IVec2] (Array n IVec2) Source | |
(ShaderType t, KnownNat n) => ShaderType (Array n t) Source |
CPU types
type CSampler2D = ActiveTexture Source
Samplers in the CPU.
type CSamplerCube = ActiveTexture Source
Samplers in the CPU.
Functions
:: ShaderType a | |
=> Int | Maximum number of iterations (should be as low as possible, must be an integer literal) |
-> a | Initial value |
-> (Int -> a -> (a, Bool)) | Iteration -> Old value -> (Next, Stop) |
-> a |
store :: ShaderType a => a -> a Source
Avoid executing this expression more than one time. Conditionals and loops imply it.
texture2DProj :: Sampler2D -> Vec3 -> Vec4 Source
texture2DProj4 :: Sampler2D -> Vec4 -> Vec4 Source
arrayLength :: (ShaderType t, KnownNat n) => Array n t -> Int Source
Math functions
inversesqrt :: GenType a => a -> a Source
mod :: GenTypeFloat a b => a -> b -> a Source
min :: GenTypeFloat a b => a -> b -> a Source
max :: GenTypeFloat a b => a -> b -> a Source
clamp :: GenTypeFloat a b => a -> b -> b -> a Source
mix :: GenTypeFloat a b => a -> a -> b -> a Source
step :: GenTypeFloat a b => b -> a -> a Source
smoothstep :: GenTypeFloat a b => b -> b -> a -> a Source
faceforward :: GenType a => a -> a -> a -> a Source
matrixCompMult :: (Matrix a, Matrix b, Matrix c) => a -> b -> c Source
Vector relational functions
class ShaderType a => VecOrd a Source
class ShaderType a => VecEq a Source
lessThanEqual :: VecOrd a => a -> a -> Bool Source
greaterThan :: VecOrd a => a -> a -> Bool Source
greaterThanEqual :: VecOrd a => a -> a -> Bool Source
class ShaderType a => BoolVector a Source
anyB :: BoolVector a => a -> Bool Source
allB :: BoolVector a => a -> Bool Source
notB :: BoolVector a => a -> Bool Source
Constructors
type family Components t :: Nat Source
Components Int = 1 | |
Components Float = 1 | |
Components Bool = 1 | |
Components Vec2 = 2 | |
Components IVec2 = 2 | |
Components BVec2 = 2 | |
Components Vec3 = 3 | |
Components IVec3 = 3 | |
Components BVec3 = 3 | |
Components Vec4 = 4 | |
Components IVec4 = 4 | |
Components BVec4 = 4 | |
Components Mat2 = 4 | |
Components Mat3 = 9 | |
Components Mat4 = 16 | |
Components x = 0 |
Useful type for constructing vectors and matrices from scalars, vectors and matrices.
ToCompList (CompList n) n Source |
class ToCompList x n | x -> n Source
((<=) 1 n, ShaderType t, (~) Nat n (Components t)) => ToCompList t n Source | |
ToCompList (CompList n) n Source |
(#) :: (ToCompList x xn, ToCompList y yn) => x -> y -> CompList (xn + yn) infixr 5 Source
You can call *vec* and mat* with a single scalar or with a CompList
containing enough components. This function helps you create CompList
s.
Examples:
vec2 0 mat2 $ Vec2 2 4 # Vec2 1 3 vec4 $ mat2 (0 # 1 # vec2 2) # 9 -- 9 is discarded mat4 $ 5 # vec2 5 # Vec3 1 2 3 # Mat2 (vec2 0) (Vec2 1 2) # mat3 0 vec4 $ 1 # vec2 0 -- Not enough components, fails with "Couldn't match type -- ‘'Prelude.False’ with 'Prelude.True’" (because -- Components Vec4 <=? 3 ~ False).
((<=) (Components Vec2) n, ToCompList t n) => ToVec2 t Source | |
ToVec2 Float Source |
((<=) (Components Vec3) n, ToCompList t n) => ToVec3 t Source | |
ToVec3 Float Source |
((<=) (Components Vec4) n, ToCompList t n) => ToVec4 t Source | |
ToVec4 Float Source |
((<=) (Components BVec2) n, ToCompList t n) => ToBVec2 t Source | |
ToBVec2 Float Source |
((<=) (Components BVec3) n, ToCompList t n) => ToBVec3 t Source | |
ToBVec3 Float Source |
((<=) (Components BVec4) n, ToCompList t n) => ToBVec4 t Source | |
ToBVec4 Float Source |
((<=) (Components IVec2) n, ToCompList t n) => ToIVec2 t Source | |
ToIVec2 Float Source |
((<=) (Components IVec3) n, ToCompList t n) => ToIVec3 t Source | |
ToIVec3 Float Source |
((<=) (Components IVec4) n, ToCompList t n) => ToIVec4 t Source | |
ToIVec4 Float Source |
((<=) (Components Mat2) n, ToCompList t n) => ToMat2 t Source | |
ToMat2 Float Source |
((<=) (Components Mat3) n, ToCompList t n) => ToMat3 t Source | |
ToMat3 Float Source |
((<=) (Components Mat4) n, ToCompList t n) => ToMat4 t Source | |
ToMat4 Float Source |
Operators
(*) :: (Mul aBase bBase a b c, ShaderType a, ShaderType b, ShaderType c) => a -> b -> c infixl 7 Source
(/) :: (Arithmetic aBase bBase a b c, ShaderType a, ShaderType b, ShaderType c) => a -> b -> c infixl 7 Source
(+) :: (Arithmetic aBase bBase a b c, ShaderType a, ShaderType b, ShaderType c) => a -> b -> c infixl 6 Source
(-) :: (Arithmetic aBase bBase a b c, ShaderType a, ShaderType b, ShaderType c) => a -> b -> c infixl 6 Source
(^) :: (ShaderType a, GenType a) => a -> a -> a infixr 8 Source
(==) :: ShaderType a => a -> a -> Bool infix 4 Source
(>=) :: ShaderType a => a -> a -> Bool infix 4 Source
(<=) :: ShaderType a => a -> a -> Bool infix 4 Source
(<) :: ShaderType a => a -> a -> Bool infix 4 Source
(>) :: ShaderType a => a -> a -> Bool infix 4 Source
Rebinding functions
fromInteger :: Num a => Integer -> a Source
fromRational :: Rational -> Float Source
ifThenElse :: ShaderType a => Bool -> a -> a -> a Source
Rebound if. You don't need to use this function, with -XRebindableSyntax.
Prelude functions
(.) :: (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.
Variables
fragFrontFacing :: Bool Source
If the fragment belongs to a front-facing primitive (only works in the fragment shader).