`FragmentStream`

s implement the `Functor`

class, which provides the
`fmap`

method that you can use to manipulate those streams. This corresponds to writing and using
fragment shaders, but in a much more modular way. You may for instance apply `fmap`

several times in a sequence, effectively creating complex shaders.

Instances are also provided for the `Monoid`

class, so several streams (of the same type) can be
concatenated. The order is preserved, meaning that the fragments in stream `a`

in `a `

will be
drawn before the fragments in `mappend`

b`b`

.

All atomic values except textures in fragment streams uses the `Fragment`

type constructor.
Composite types are created by composing the atomic `Fragment`

types, rather than wrapping the
composite type in the `Fragment`

type constructors.

`Fragment`

instances for are provided for most of Prelude's numerical classes. Since `Eq`

, `Ord`

and `Show`

are prerequisites for these classes, instances are provided for them too, even though
their methods all will generate errors if used (except `min`

and `max`

). Use the instances of
`EqB`

, `OrdB`

and `IfB`

from the Boolean package if you want to compare `Fragment`

values.
Hyperbolic trigonometrical functions aren't provided either.

Rewrite rule specializations are provided for the Vec package functions `norm`

, `normalize`

,
`dot`

and `cross`

on vectors of `Fragment`

`Float`

, so the use of these functions (and others
from that package that is defined in terms of them) are highly encouraged.

- data FragmentStream a
- data Fragment a
- dFdx :: Fragment Float -> Fragment Float
- dFdy :: Fragment Float -> Fragment Float
- fwidth :: Fragment Float -> Fragment Float
- filterFragments :: (a -> Fragment Bool) -> FragmentStream a -> FragmentStream a
- class GPU a => VertexOutput a where
- type FragmentInput a
- toFragment :: a -> Rasterizer (FragmentInput a)

- data Rasterizer a
- type VertexPosition = Vec4 (Vertex Float)
- rasterizeFront :: VertexOutput a => PrimitiveStream p (VertexPosition, a) -> FragmentStream (FragmentInput a)
- rasterizeBack :: VertexOutput a => PrimitiveStream Triangle (VertexPosition, a) -> FragmentStream (FragmentInput a)
- rasterizeFrontAndBack :: VertexOutput a => PrimitiveStream Triangle (VertexPosition, a) -> FragmentStream (Fragment Bool, FragmentInput a)

# Data types

data FragmentStream a Source

A stream of fragments on the GPU, parameterized on the fragments type
(built up of atoms of type `Fragment`

).

Eq (Fragment a) | |

Floating (Fragment Float) | |

Fractional (Fragment Float) | |

Num (Fragment Float) | |

Num (Fragment Int) | |

Ord (Fragment Float) | |

Ord (Fragment Int) | |

Show (Fragment a) | |

Boolean (Fragment Bool) | |

Convert (Fragment Float) | |

Convert (Fragment Int) | |

Real' (Fragment Float) | |

GPU (Fragment Bool) | |

GPU (Fragment Float) | |

GPU (Fragment Int) | |

IfB (Fragment Bool) (Fragment Bool) | |

IfB (Fragment Bool) (Fragment Float) | |

IfB (Fragment Bool) (Fragment Int) | |

Eq a => EqB (Fragment Bool) (Fragment a) | |

Ord a => OrdB (Fragment Bool) (Fragment a) |

# Various fragment functions

dFdx :: Fragment Float -> Fragment FloatSource

The derivative in x using local differencing of the rasterized value.

dFdy :: Fragment Float -> Fragment FloatSource

The derivative in y using local differencing of the rasterized value.

fwidth :: Fragment Float -> Fragment FloatSource

The sum of the absolute derivative in x and y using local differencing of the rasterized value.

filterFragments :: (a -> Fragment Bool) -> FragmentStream a -> FragmentStream aSource

Filters out fragments in a stream where the provided function returns `true`

.

# Creating fragment streams

class GPU a => VertexOutput a whereSource

The context of types that can be rasterized from vertices in `PrimitiveStream`

s to fragments in `FragmentStream`

s.
Create your own instances in terms of the existing ones, e.g. convert your vertex data to `Vertex`

`Float`

s,
turn them into `Fragment`

`Float`

s with `toFragment`

and then convert them to your fragment data representation.

type FragmentInput a Source

The corresponding type in the `FragmentStream`

after rasterization.

toFragment :: a -> Rasterizer (FragmentInput a)Source

Turns a vertex value into a fragment value in the `Rasterizer`

monad.

VertexOutput () | |

VertexOutput (Vertex Float) | |

(VertexOutput a, VertexOutput b) => VertexOutput (a, b) | |

(VertexOutput a, VertexOutput b) => VertexOutput (:. a b) | |

(VertexOutput a, VertexOutput b, VertexOutput c) => VertexOutput (a, b, c) | |

(VertexOutput a, VertexOutput b, VertexOutput c, VertexOutput d) => VertexOutput (a, b, c, d) |

data Rasterizer a Source

A monad in which vertex data gets converted to fragment data.
Use `toFragment`

in the existing instances of `VertexOutput`

to operate in this monad.

type VertexPosition = Vec4 (Vertex Float)Source

When using the `rasterize`

functions, give the vertices positions in canonical view space, i.e. where `x`

, `y`

and `z`

is in the interval `[-1, 1]`

. These aren't interpolated back to the fragments by default, so you
must duplicate these positions into the vertices interpolated values if you need them in the fragments (which is very unusual).

:: VertexOutput a | |

=> PrimitiveStream p (VertexPosition, a) | The primitive stream with vertices containing canonical view coordinates and data to be interpolated. |

-> FragmentStream (FragmentInput a) | The resulting fragment stream with fragments containing the interpolated values. |

Rasterize front side of all types of primitives with vertices containing canonical view coordinates into fragments.

:: VertexOutput a | |

=> PrimitiveStream Triangle (VertexPosition, a) | The primitive stream with vertices containing canonical view coordinates and data to be interpolated. |

-> FragmentStream (FragmentInput a) | The resulting fragment stream with fragments containing the interpolated values. |

Rasterize back side of triangles with vertices containing canonical view coordinates into fragments.

:: VertexOutput a | |

=> PrimitiveStream Triangle (VertexPosition, a) | The primitive stream with vertices containing canonical view coordinates and data to be interpolated. |

-> FragmentStream (Fragment Bool, FragmentInput a) | The resulting fragment stream with fragments containing a bool saying if the primitive was front facing and the interpolated values. |

Rasterize both sides of triangles with vertices containing canonical view coordinates into fragments, also returning the primitives side in the fragments.