Zinggi/elm-2d-game/1.0.0

NOTE: this package is not compatible with Elm 0.19.1

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

vertColoredRect : Shader Vertex { a | transform : Mat4, cameraProj : Mat4 } {}

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

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

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

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


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 )