Safe Haskell | None |
---|---|
Language | Haskell2010 |
An example of shader variable:
data Transform2 = Transform2 Mat3 deriving Generic
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:
{--}
- type Shader gs is os = SVList gs -> SVList is -> SVList os
- type VertexShader g i o = Shader g i (VertexShaderOutput ': o)
- type FragmentShader g i = Shader g i (FragmentShaderOutput ': '[])
- data VertexShaderOutput = Vertex Vec4
- data FragmentShaderOutput
- = Fragment0
- | Fragment Vec4
- | Fragment2 Vec4 Vec4
- | Fragment3 Vec4 Vec4 Vec4
- | Fragment4 Vec4 Vec4 Vec4 Vec4
- | Fragment5 Vec4 Vec4 Vec4 Vec4 Vec4
- | Fragment6 Vec4 Vec4 Vec4 Vec4 Vec4 Vec4
- | Fragment7 Vec4 Vec4 Vec4 Vec4 Vec4 Vec4 Vec4
- | Fragment8 Vec4 Vec4 Vec4 Vec4 Vec4 Vec4 Vec4 Vec4
- | Fragment9 Vec4 Vec4 Vec4 Vec4 Vec4 Vec4 Vec4 Vec4 Vec4
- | Fragment10 Vec4 Vec4 Vec4 Vec4 Vec4 Vec4 Vec4 Vec4 Vec4 Vec4
- | Fragment11 Vec4 Vec4 Vec4 Vec4 Vec4 Vec4 Vec4 Vec4 Vec4 Vec4 Vec4
- | Fragment12 Vec4 Vec4 Vec4 Vec4 Vec4 Vec4 Vec4 Vec4 Vec4 Vec4 Vec4 Vec4
- | Fragment13 Vec4 Vec4 Vec4 Vec4 Vec4 Vec4 Vec4 Vec4 Vec4 Vec4 Vec4 Vec4 Vec4
- | Fragment14 Vec4 Vec4 Vec4 Vec4 Vec4 Vec4 Vec4 Vec4 Vec4 Vec4 Vec4 Vec4 Vec4 Vec4
- | Fragment15 Vec4 Vec4 Vec4 Vec4 Vec4 Vec4 Vec4 Vec4 Vec4 Vec4 Vec4 Vec4 Vec4 Vec4 Vec4
- | Fragment16 Vec4 Vec4 Vec4 Vec4 Vec4 Vec4 Vec4 Vec4 Vec4 Vec4 Vec4 Vec4 Vec4 Vec4 Vec4 Vec4
- type ShaderVars = Set ShaderVar
- type VOShaderVars o = (ShaderVars o, ShaderVars (VertexShaderOutput ': o))
- class Generic g => Uniform s g
- class Generic g => Attribute s g
- class Generic a
- data SVList :: [*] -> * 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
- 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 where ...
- data CompList count
- class ToCompList x n | x -> n
- (#) :: (ToCompList x xn, ToCompList y yn) => x -> y -> CompList (xn + yn)
- class ToVec2 t where
- vec2 :: ToVec2 t => t -> Vec2
- class ToVec3 t where
- vec3 :: ToVec3 t => t -> Vec3
- class ToVec4 t where
- vec4 :: ToVec4 t => t -> Vec4
- class ToBVec2 t where
- bvec2 :: ToBVec2 t => t -> BVec2
- class ToBVec3 t where
- bvec3 :: ToBVec3 t => t -> BVec3
- class ToBVec4 t where
- bvec4 :: ToBVec4 t => t -> BVec4
- class ToIVec2 t where
- ivec2 :: ToIVec2 t => t -> IVec2
- class ToIVec3 t where
- ivec3 :: ToIVec3 t => t -> IVec3
- class ToIVec4 t where
- ivec4 :: ToIVec4 t => t -> IVec4
- class ToMat2 t where
- mat2 :: ToMat2 t => t -> Mat2
- class ToMat3 t where
- mat3 :: ToMat3 t => t -> Mat3
- class ToMat4 t where
- mat4 :: ToMat4 t => t -> Mat4
- (*) :: (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
- fragData :: Array 16 Vec4
- fragCoord :: Vec4
- fragFrontFacing :: Bool
Types
type Shader gs is os = SVList gs -> SVList is -> SVList os Source #
A function from a set of uniforms and a set of inputs (attributes or varyings) to a set of outputs (varyings). It can be used to represent a reusable piece of shader code, other than actual shaders.
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.
data VertexShaderOutput Source #
The position of the vertex.
data FragmentShaderOutput Source #
The RGBA color of the fragment (1.0 = #FF), or the data of the draw buffers.
type ShaderVars = Set ShaderVar Source #
A type-level set of ShaderVar
s.
type VOShaderVars o = (ShaderVars o, ShaderVars (VertexShaderOutput ': o)) Source #
ShaderVars
for the output of VartexShader
.
Representable types of kind *. This class is derivable in GHC with the DeriveGeneric flag on.
GPU types
A GPU float.
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 3D integer vector.
A GPU 4D integer vector.
Functions
store :: ShaderType a => a -> a Source #
Avoid evaluating the expression of the argument more than one time. Conditionals and loops imply it.
Math functions
inversesqrt :: GenType a => 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
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 where ... 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 #
toCompList
((<=) 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).
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 #
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
const x
is a unary function which evaluates to x
for all inputs.
For instance,
>>>
map (const 42) [0..3]
[42,42,42,42]
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
Variables
fragFrontFacing :: Bool Source #
If the fragment belongs to a front-facing primitive (only works in the fragment shader).