Zinggi/elm-2d-game/4.0.0

NOTE: the latest version is 4.1.0

Game.TwoD.Shaders

Standard shaders for WebGL rendering.

You don't need this module, unless you want to write your own vertex or fragment shader and a shader from here already provides one half.

Or if you're using WebGL directly.

Vertex shaders

Shader
Vertex
{ a | transform : Mat4, cameraProj : Mat4 }
{ vcoord : Vec2 }

The most basic shader, renders a basic shape. Since it doesn't even pass along the texture coordinates, it's only use is to create a colored shape.

Shader
Vertex
{ u | transform : Mat4, cameraProj : Mat4 }
{ vcoord : Vec2 }

A simple shader that passes the texture coordinates along for the fragment shader. Can be generally used if the fragment shader needs to display texture(s).

Shader
Vertex
{ u
| cameraPos : Vec2
, cameraSize : Vec2
, scrollSpeed : Vec2
, z : Float
, offset : Vec2
}
{ vcoord : Vec2 }

A shader that scrolls it's texture when the camera moves, but at not at the same speed. Good for background images.

Fragment shaders

Shader
{}
{ u | texture : Texture, tileWH : Vec2 }
{ vcoord : Vec2 }

Display a tiled texture. TileWH specifies how many times the texture should be tiled.

Shader
{}
{ u
| texture : Texture
, bottomLeft : Vec2
, topRight : Vec2
, numberOfFrames : Int
, duration : Float
, time : Float
}
{ vcoord : Vec2 }

A shader to render spritesheet animations. It assumes that the animation frames are in one horizontal line

Shader
{}
{ u
| texture : Texture
, bottomLeft : Vec2
, topRight : Vec2
, numberOfFrames : Int
, currentFrame : Int
}
{ vcoord : Vec2 }

Same as the shader above, but controlled via frame number instead of time

fragUniColor : Shader {} { u | color : Vec3 } { vcoord : Vec2 }

A very simple shader, coloring the whole area in a single color

fragUniColorCircle : Shader {} { u | color : Vec3 } { vcoord : Vec2 }

A fragment Shader for rendering a single colored circle

fragUniColorRing : Shader {} { u | color : Vec3 } { vcoord : Vec2 }

A fragment Shader for rendering a transparent circle with a colored border


useful helper functions

colorToRGBAVector : Color -> Vec4
colorToRGBVector : Color -> Vec3
makeTransform : Float3 -> Float -> Float2 -> Float2 -> Mat4

Creates a transformation matrix usually used in the fragment shader.

makeTransform ( x, y, z ) rotation ( w, h ) ( px, py )