diff --git a/.eslintrc.json b/.eslintrc.json deleted file mode 100644 index e881414..0000000 --- a/.eslintrc.json +++ /dev/null @@ -1,41 +0,0 @@ -{ - "env": { - "browser": true - }, - "extends": "eslint:recommended", - "rules": { - "indent": [ "error", 2, { "SwitchCase": 1 } ], - "space-infix-ops": [ "error" ], - "linebreak-style": [ "error", "unix" ], - "comma-style": [ "error", "last" ], - "brace-style": [ "error", "1tbs", { "allowSingleLine": true } ], - "curly": "error", - "quotes": [ "error", "single" ], - "semi": [ "error", "always" ], - "space-before-function-paren": [ "error", {"anonymous": "always", "named": "never"} ], - "keyword-spacing": [ "error", { "before": true, "after": true } ], - "space-before-blocks": [ "error", "always" ], - "key-spacing": [ "error", { "beforeColon": false, "afterColon": true, "mode": "strict" } ], - "semi-spacing": [ "error", {"before": false, "after": true} ], - "comma-spacing": [ "error", { "before": false, "after": true } ], - "comma-dangle": ["error", "never"], - "camelcase": "error", - "eqeqeq": "error" - }, - "globals" : { - "_elm_community$webgl$Native_Texture": true, - "_elm_community$webgl$Native_WebGL": true, - "_elm_community$webgl$Native_Settings": true, - "_elm_lang$virtual_dom$Native_VirtualDom": false, - "_elm_lang$core$Native_Utils": false, - "_elm_lang$core$Native_Scheduler": false, - "F2": false, - "F3": false, - "F4": false, - "F5": false, - "F6": false, - "Float32Array": false, - "Int32Array": false, - "Uint16Array": false - } -} diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md deleted file mode 100644 index e0465a0..0000000 --- a/CONTRIBUTING.md +++ /dev/null @@ -1,14 +0,0 @@ -# Contributing to elm-community/webgl - -This repository is kept for maintenance and does not accept most feature requests. In particular, [#6](https://github.com/elm-community/elm-webgl/issues/6) requires that all -changes be PATCH-level, meaning that the API cannot be modified. - -Any contribution should: -* Compile using `elm make` -* Be recognized as a PATCH change using `elm package diff` -* Not introduce mutable variables -* Justify why the change is needed and why it won't break anything already here -* JavaScript code should be validated using `eslint src` -* Elm code should be formatted with `elm-format` - -Documentation improvements are welcome. diff --git a/examples/.gitignore b/examples/.gitignore deleted file mode 100644 index 0ae95bc..0000000 --- a/examples/.gitignore +++ /dev/null @@ -1 +0,0 @@ -elm.js diff --git a/examples/crate.elm b/examples/crate.elm deleted file mode 100644 index 0dbc90e..0000000 --- a/examples/crate.elm +++ /dev/null @@ -1,304 +0,0 @@ -module Main exposing (main) - -{- - This example was inspired by https://open.gl/depthstencils - It demonstrates how to use the stencil buffer. --} - -import AnimationFrame -import Html exposing (Html) -import Html.Attributes exposing (width, height, style) -import Math.Matrix4 as Mat4 exposing (Mat4) -import Math.Vector2 as Vec2 exposing (Vec2, vec2) -import Math.Vector3 as Vec3 exposing (Vec3, vec3) -import Task -import Time exposing (Time) -import WebGL exposing (Mesh, Shader, Entity) -import WebGL.Settings.Blend as Blend -import WebGL.Settings.DepthTest as DepthTest -import WebGL.Settings.StencilTest as StencilTest -import WebGL.Texture as Texture exposing (Error, Texture) - - -type alias Model = - { texture : Maybe Texture - , theta : Float - } - - -type Msg - = TextureLoaded (Result Error Texture) - | Animate Time - - -update : Msg -> Model -> ( Model, Cmd Msg ) -update action model = - case action of - TextureLoaded textureResult -> - ( { model | texture = Result.toMaybe textureResult }, Cmd.none ) - - Animate dt -> - ( { model | theta = model.theta + dt / 10000 }, Cmd.none ) - - -init : ( Model, Cmd Msg ) -init = - ( { texture = Nothing, theta = 0 } - , Task.attempt TextureLoaded (Texture.load "texture/wood-crate.jpg") - ) - - -main : Program Never Model Msg -main = - Html.program - { init = init - , view = view - , subscriptions = (\model -> AnimationFrame.diffs Animate) - , update = update - } - - - --- View - - -view : Model -> Html Msg -view { texture, theta } = - WebGL.toHtmlWith - [ WebGL.alpha True - , WebGL.antialias - , WebGL.depth 1 - , WebGL.stencil 0 - ] - [ width 400 - , height 400 - , style [ ( "display", "block" ) ] - ] - (texture - |> Maybe.map (scene (perspective theta)) - |> Maybe.withDefault [] - ) - - -perspective : Float -> Mat4 -perspective angle = - List.foldr Mat4.mul - Mat4.identity - [ Mat4.makePerspective 45 1 0.01 100 - , Mat4.makeLookAt (vec3 0 3 8) (vec3 0 0 0) (vec3 0 1 0) - , Mat4.makeRotate (3 * angle) (vec3 0 1 0) - ] - - -scene : Mat4 -> Texture -> List Entity -scene camera texture = - [ WebGL.entity - crateVertex - crateFragment - crateMesh - { texture = texture - , perspective = camera - } - , WebGL.entityWith - [ DepthTest.less - { write = False - , near = 0 - , far = 1 - } - , StencilTest.test - { ref = 1 - , mask = 0xFF - , test = StencilTest.always - , fail = StencilTest.keep - , zfail = StencilTest.keep - , zpass = StencilTest.replace - , writeMask = 0xFF - } - ] - floorVertex - floorFragment - floorMesh - { texture = texture - , perspective = camera - } - , WebGL.entityWith - [ StencilTest.test - { ref = 1 - , mask = 0xFF - , test = StencilTest.equal - , fail = StencilTest.keep - , zfail = StencilTest.keep - , zpass = StencilTest.keep - , writeMask = 0 - } - , DepthTest.default - , Blend.custom - { r = 0 - , g = 0 - , b = 0 - , a = 0.5 - , color = Blend.customAdd Blend.constantAlpha Blend.zero - , alpha = Blend.customAdd Blend.one Blend.zero - } - ] - crateVertex - crateFragment - crateMesh - { texture = texture - , perspective = - Mat4.mul camera (Mat4.makeScale (vec3 1 -1 1)) - } - ] - - - --- Meshes - - -type alias Vertex = - { position : Vec3 - , coord : Vec2 - } - - -crateMesh : Mesh Vertex -crateMesh = - [ ( 0, 0 ), ( 90, 0 ), ( 180, 0 ), ( 270, 0 ), ( 0, 90 ), ( 0, 270 ) ] - |> List.concatMap rotatedFace - |> WebGL.triangles - - -rotatedFace : ( Float, Float ) -> List ( Vertex, Vertex, Vertex ) -rotatedFace ( angleXZ, angleYZ ) = - let - transformMat = - List.foldr Mat4.mul - Mat4.identity - [ Mat4.makeTranslate (vec3 0 1 0) - , Mat4.makeRotate (degrees angleXZ) Vec3.j - , Mat4.makeRotate (degrees angleYZ) Vec3.i - , Mat4.makeTranslate (vec3 0 0 1) - ] - - transform vertex = - { vertex - | position = - Mat4.transform - transformMat - vertex.position - } - - transformTriangle ( a, b, c ) = - ( transform a, transform b, transform c ) - in - List.map transformTriangle square - - -square : List ( Vertex, Vertex, Vertex ) -square = - let - topLeft = - { position = vec3 -1 1 0, coord = vec2 0 1 } - - topRight = - { position = vec3 1 1 0, coord = vec2 1 1 } - - bottomLeft = - { position = vec3 -1 -1 0, coord = vec2 0 0 } - - bottomRight = - { position = vec3 1 -1 0, coord = vec2 1 0 } - in - [ ( topLeft, topRight, bottomLeft ) - , ( bottomLeft, topRight, bottomRight ) - ] - - -floorMesh : Mesh { position : Vec3 } -floorMesh = - let - topLeft = - { position = vec3 -2 0 -2 } - - topRight = - { position = vec3 2 0 -2 } - - bottomLeft = - { position = vec3 -2 0 2 } - - bottomRight = - { position = vec3 2 0 2 } - in - WebGL.triangles - [ ( topLeft, topRight, bottomLeft ) - , ( bottomLeft, topRight, bottomRight ) - ] - - - --- Shaders - - -type alias Uniforms = - { perspective : Mat4 - , texture : Texture - } - - -crateVertex : Shader Vertex Uniforms { vcoord : Vec2 } -crateVertex = - [glsl| - - attribute vec3 position; - attribute vec2 coord; - uniform mat4 perspective; - varying vec2 vcoord; - - void main () { - gl_Position = perspective * vec4(position, 1.0); - vcoord = coord; - } - - |] - - -crateFragment : Shader {} { u | texture : Texture } { vcoord : Vec2 } -crateFragment = - [glsl| - - precision mediump float; - uniform sampler2D texture; - varying vec2 vcoord; - - void main () { - gl_FragColor = texture2D(texture, vcoord); - } - - |] - - -floorVertex : Shader { position : Vec3 } Uniforms {} -floorVertex = - [glsl| - - attribute vec3 position; - uniform mat4 perspective; - - void main () { - gl_Position = perspective * vec4(position, 1.0); - } - - |] - - -floorFragment : Shader attributes Uniforms {} -floorFragment = - [glsl| - - precision mediump float; - - void main () { - gl_FragColor = vec4(0.0, 0.0, 0.0, 1.0); - } - - |] diff --git a/examples/cube.elm b/examples/cube.elm deleted file mode 100644 index 17eb0ad..0000000 --- a/examples/cube.elm +++ /dev/null @@ -1,164 +0,0 @@ -module Main exposing (main) - -{- - Rotating cube with colored sides. --} - -import AnimationFrame -import Color exposing (Color) -import Html exposing (Html) -import Html.Attributes exposing (width, height, style) -import Math.Matrix4 as Mat4 exposing (Mat4) -import Math.Vector3 as Vec3 exposing (vec3, Vec3) -import Time exposing (Time) -import WebGL exposing (Mesh, Shader) - - -main : Program Never Float Time -main = - Html.program - { init = ( 0, Cmd.none ) - , view = view - , subscriptions = (\_ -> AnimationFrame.diffs Basics.identity) - , update = (\dt theta -> ( theta + dt / 5000, Cmd.none )) - } - - -view : Float -> Html Time -view theta = - WebGL.toHtml - [ width 400 - , height 400 - , style [ ( "display", "block" ) ] - ] - [ WebGL.entity - vertexShader - fragmentShader - cubeMesh - (uniforms theta) - ] - - -type alias Uniforms = - { rotation : Mat4 - , perspective : Mat4 - , camera : Mat4 - , shade : Float - } - - -uniforms : Float -> Uniforms -uniforms theta = - { rotation = - Mat4.mul - (Mat4.makeRotate (3 * theta) (vec3 0 1 0)) - (Mat4.makeRotate (2 * theta) (vec3 1 0 0)) - , perspective = Mat4.makePerspective 45 1 0.01 100 - , camera = Mat4.makeLookAt (vec3 0 0 5) (vec3 0 0 0) (vec3 0 1 0) - , shade = 0.8 - } - - - --- Mesh - - -type alias Vertex = - { color : Vec3 - , position : Vec3 - } - - -cubeMesh : Mesh Vertex -cubeMesh = - let - rft = - vec3 1 1 1 - - lft = - vec3 -1 1 1 - - lbt = - vec3 -1 -1 1 - - rbt = - vec3 1 -1 1 - - rbb = - vec3 1 -1 -1 - - rfb = - vec3 1 1 -1 - - lfb = - vec3 -1 1 -1 - - lbb = - vec3 -1 -1 -1 - in - [ face Color.green rft rfb rbb rbt - , face Color.blue rft rfb lfb lft - , face Color.yellow rft lft lbt rbt - , face Color.red rfb lfb lbb rbb - , face Color.purple lft lfb lbb lbt - , face Color.orange rbt rbb lbb lbt - ] - |> List.concat - |> WebGL.triangles - - -face : Color -> Vec3 -> Vec3 -> Vec3 -> Vec3 -> List ( Vertex, Vertex, Vertex ) -face rawColor a b c d = - let - color = - let - c = - Color.toRgb rawColor - in - vec3 - (toFloat c.red / 255) - (toFloat c.green / 255) - (toFloat c.blue / 255) - - vertex position = - Vertex color position - in - [ ( vertex a, vertex b, vertex c ) - , ( vertex c, vertex d, vertex a ) - ] - - - --- Shaders - - -vertexShader : Shader Vertex Uniforms { vcolor : Vec3 } -vertexShader = - [glsl| - - attribute vec3 position; - attribute vec3 color; - uniform mat4 perspective; - uniform mat4 camera; - uniform mat4 rotation; - varying vec3 vcolor; - void main () { - gl_Position = perspective * camera * rotation * vec4(position, 1.0); - vcolor = color; - } - - |] - - -fragmentShader : Shader {} Uniforms { vcolor : Vec3 } -fragmentShader = - [glsl| - - precision mediump float; - uniform float shade; - varying vec3 vcolor; - void main () { - gl_FragColor = shade * vec4(vcolor, 1.0); - } - - |] diff --git a/examples/elm-package.json b/examples/elm-package.json deleted file mode 100644 index 4f0a76a..0000000 --- a/examples/elm-package.json +++ /dev/null @@ -1,22 +0,0 @@ -{ - "version": "1.0.0", - "summary": "Examples", - "repository": "https://github.com/elm-community/webgl.git", - "license": "BSD3", - "source-directories": [ - ".", - "../src" - ], - "exposed-modules": [], - "native-modules": true, - "dependencies": { - "elm-community/linear-algebra": "1.0.0 <= v < 2.0.0", - "elm-lang/animation-frame": "1.0.1 <= v < 2.0.0", - "elm-lang/core": "5.0.0 <= v < 6.0.0", - "elm-lang/html": "2.0.0 <= v < 3.0.0", - "elm-lang/keyboard": "1.0.1 <= v < 2.0.0", - "elm-lang/mouse": "1.0.1 <= v < 2.0.0", - "elm-lang/window": "1.0.1 <= v < 2.0.0" - }, - "elm-version": "0.18.0 <= v < 0.19.0" -} diff --git a/examples/first-person.elm b/examples/first-person.elm deleted file mode 100644 index eed4b28..0000000 --- a/examples/first-person.elm +++ /dev/null @@ -1,350 +0,0 @@ -module Main exposing (main) - -{- - Try adding the ability to crouch or to land on top of the crate. --} - -import AnimationFrame -import Html exposing (Html, text, div) -import Html.Attributes exposing (width, height, style) -import Keyboard -import Math.Matrix4 as Mat4 exposing (Mat4) -import Math.Vector2 as Vec2 exposing (Vec2, vec2) -import Math.Vector3 as Vec3 exposing (Vec3, vec3) -import Task exposing (Task) -import Time exposing (Time) -import WebGL exposing (Mesh, Shader, Entity) -import WebGL.Texture as Texture exposing (Texture, Error) -import Window - - -type alias Model = - { texture : Maybe Texture - , keys : Keys - , size : Window.Size - , person : Person - } - - -type alias Person = - { position : Vec3 - , velocity : Vec3 - } - - -type Msg - = TextureLoaded (Result Error Texture) - | KeyChange Bool Keyboard.KeyCode - | Animate Time - | Resize Window.Size - - -type alias Keys = - { left : Bool - , right : Bool - , up : Bool - , down : Bool - , space : Bool - } - - -main : Program Never Model Msg -main = - Html.program - { init = init - , view = view - , subscriptions = subscriptions - , update = update - } - - -eyeLevel : Float -eyeLevel = - 2 - - -init : ( Model, Cmd Msg ) -init = - ( { texture = Nothing - , person = Person (vec3 0 eyeLevel -10) (vec3 0 0 0) - , keys = Keys False False False False False - , size = Window.Size 0 0 - } - , Cmd.batch - [ Task.attempt TextureLoaded (Texture.load "texture/wood-crate.jpg") - , Task.perform Resize Window.size - ] - ) - - -subscriptions : Model -> Sub Msg -subscriptions _ = - Sub.batch - [ AnimationFrame.diffs Animate - , Keyboard.downs (KeyChange True) - , Keyboard.ups (KeyChange False) - , Window.resizes Resize - ] - - -update : Msg -> Model -> ( Model, Cmd Msg ) -update action model = - case action of - TextureLoaded textureResult -> - ( { model | texture = Result.toMaybe textureResult }, Cmd.none ) - - KeyChange on code -> - ( { model | keys = keyFunc on code model.keys }, Cmd.none ) - - Resize size -> - ( { model | size = size }, Cmd.none ) - - Animate dt -> - ( { model - | person = - model.person - |> move model.keys - |> gravity (dt / 500) - |> physics (dt / 500) - } - , Cmd.none - ) - - -keyFunc : Bool -> Keyboard.KeyCode -> Keys -> Keys -keyFunc on keyCode keys = - case keyCode of - 32 -> - { keys | space = on } - - 37 -> - { keys | left = on } - - 39 -> - { keys | right = on } - - 38 -> - { keys | up = on } - - 40 -> - { keys | down = on } - - _ -> - keys - - -move : Keys -> Person -> Person -move { left, right, up, down, space } person = - let - direction a b = - if a == b then - 0 - else if a then - 1 - else - -1 - - vy = - if space then - 2 - else - Vec3.getY person.velocity - in - if Vec3.getY person.position <= eyeLevel then - { person - | velocity = - vec3 (direction left right) vy (direction up down) - } - else - person - - -physics : Float -> Person -> Person -physics dt person = - let - position = - Vec3.add person.position (Vec3.scale dt person.velocity) - in - { person - | position = - if Vec3.getY position < eyeLevel then - Vec3.setY eyeLevel position - else - position - } - - -gravity : Float -> Person -> Person -gravity dt person = - if Vec3.getY person.position > eyeLevel then - { person - | velocity = - Vec3.setY - (Vec3.getY person.velocity - 2 * dt) - person.velocity - } - else - person - - - --- View - - -view : Model -> Html Msg -view { size, person, texture } = - div - [ style - [ ( "width", toString size.width ++ "px" ) - , ( "height", toString size.height ++ "px" ) - , ( "position", "relative" ) - ] - ] - [ WebGL.toHtmlWith - [ WebGL.depth 1 - , WebGL.antialias - ] - [ width size.width - , height size.height - , style [ ( "display", "block" ) ] - ] - (texture - |> Maybe.map (scene size person) - |> Maybe.withDefault [] - ) - , div - [ style - [ ( "position", "absolute" ) - , ( "font-family", "monospace" ) - , ( "color", "white" ) - , ( "text-align", "center" ) - , ( "left", "20px" ) - , ( "right", "20px" ) - , ( "top", "20px" ) - ] - ] - [ text message ] - ] - - -message : String -message = - "Walk around with a first person perspective.\n" - ++ "Arrows keys to move, space bar to jump." - - -scene : Window.Size -> Person -> Texture -> List Entity -scene { width, height } person texture = - let - perspective = - Mat4.mul - (Mat4.makePerspective 45 (toFloat width / toFloat height) 0.01 100) - (Mat4.makeLookAt person.position (Vec3.add person.position Vec3.k) Vec3.j) - in - [ WebGL.entity - vertexShader - fragmentShader - crate - { texture = texture - , perspective = perspective - } - ] - - - --- Mesh - - -type alias Vertex = - { position : Vec3 - , coord : Vec2 - } - - -crate : Mesh Vertex -crate = - [ ( 0, 0 ), ( 90, 0 ), ( 180, 0 ), ( 270, 0 ), ( 0, 90 ), ( 0, -90 ) ] - |> List.concatMap rotatedSquare - |> WebGL.triangles - - -rotatedSquare : ( Float, Float ) -> List ( Vertex, Vertex, Vertex ) -rotatedSquare ( angleXZ, angleYZ ) = - let - transformMat = - Mat4.mul - (Mat4.makeRotate (degrees angleXZ) Vec3.j) - (Mat4.makeRotate (degrees angleYZ) Vec3.i) - - transform vertex = - { vertex - | position = - Mat4.transform transformMat vertex.position - } - - transformTriangle ( a, b, c ) = - ( transform a, transform b, transform c ) - in - List.map transformTriangle square - - -square : List ( Vertex, Vertex, Vertex ) -square = - let - topLeft = - Vertex (vec3 -1 1 1) (vec2 0 1) - - topRight = - Vertex (vec3 1 1 1) (vec2 1 1) - - bottomLeft = - Vertex (vec3 -1 -1 1) (vec2 0 0) - - bottomRight = - Vertex (vec3 1 -1 1) (vec2 1 0) - in - [ ( topLeft, topRight, bottomLeft ) - , ( bottomLeft, topRight, bottomRight ) - ] - - - --- Shaders - - -type alias Uniforms = - { texture : Texture - , perspective : Mat4 - } - - -vertexShader : Shader Vertex Uniforms { vcoord : Vec2 } -vertexShader = - [glsl| - - attribute vec3 position; - attribute vec2 coord; - uniform mat4 perspective; - varying vec2 vcoord; - - void main () { - gl_Position = perspective * vec4(position, 1.0); - vcoord = coord; - } - - |] - - -fragmentShader : Shader {} Uniforms { vcoord : Vec2 } -fragmentShader = - [glsl| - - precision mediump float; - uniform sampler2D texture; - varying vec2 vcoord; - - void main () { - gl_FragColor = texture2D(texture, vcoord); - } - - |] diff --git a/examples/intersection.elm b/examples/intersection.elm deleted file mode 100644 index 059e780..0000000 --- a/examples/intersection.elm +++ /dev/null @@ -1,146 +0,0 @@ -module Main exposing (main) - -{- - Draws a red and a green triangles, where the green triangle is only - visible in the intercection with the red triangle. - A green outline marks a hidden area of the green triangle. - - This example helps to understand the separate stencil test. --} - -import Html exposing (Html) -import Html.Attributes exposing (width, height, style) -import Math.Vector3 as Vec3 exposing (Vec3, vec3) -import WebGL exposing (Shader, Mesh) -import WebGL.Settings exposing (Setting) -import WebGL.Settings.StencilTest as StencilTest - - -main : Html () -main = - WebGL.toHtmlWith - [ WebGL.stencil 0 ] - [ width 400 - , height 400 - , style [ ( "display", "block" ) ] - ] - [ WebGL.entityWith - [ stencilTest ] - vertexShader - fragmentShader - redAndGreenTriangles - {} - , WebGL.entity - vertexShader - fragmentShader - greenOutline - {} - ] - - -{-| Rendering with the following setting will write 1's to the stencil buffer -for all front-facing triangles, and then test the subsequent back-facing -triangles against the stencil buffer, so they be rendered only for the areas -that are marked with 1's in the stencil buffer. - -`StencilTest.testSeparate` takes two options, one for front-, and another for -back-facing triangles: - -* The front-facing stencil test always passes, and replaces the stencil buffer - with 1. -* The back-facing stencil test only passes when the value in the stencil buffer - is equal to 1. It does not modify the stencil buffer. --} -stencilTest : Setting -stencilTest = - StencilTest.testSeparate - { ref = 1 - , mask = 0xFF - , writeMask = 0xFF - } - { test = StencilTest.always - , fail = StencilTest.keep - , zfail = StencilTest.keep - , zpass = StencilTest.replace - } - { test = StencilTest.equal - , fail = StencilTest.keep - , zfail = StencilTest.keep - , zpass = StencilTest.keep - } - - - --- Mesh - - -type alias Vertex = - { position : Vec3 - , color : Vec3 - } - - -redAndGreenTriangles : Mesh Vertex -redAndGreenTriangles = - let - -- the red triangle is front-facing - redTriangle = - ( Vertex (vec3 -1 0.5 0) (vec3 1 0 0) - , Vertex (vec3 0 -0.5 0) (vec3 1 0 0) - , Vertex (vec3 1 0.5 0) (vec3 1 0 0) - ) - - -- the green triangle is back-facing - greenTriangle = - ( Vertex (vec3 -1 -0.5 0) (vec3 0 1 0) - , Vertex (vec3 0 0.5 0) (vec3 0 1 0) - , Vertex (vec3 1 -0.5 0) (vec3 0 1 0) - ) - in - WebGL.triangles - [ redTriangle - , greenTriangle - ] - - -greenOutline : Mesh Vertex -greenOutline = - WebGL.lineLoop - [ Vertex (vec3 -1 -0.5 0) (vec3 0 1 0) - , Vertex (vec3 0 0.5 0) (vec3 0 1 0) - , Vertex (vec3 1 -0.5 0) (vec3 0 1 0) - ] - - - --- Shaders - - -vertexShader : Shader Vertex {} { vcolor : Vec3 } -vertexShader = - [glsl| - - attribute vec3 position; - attribute vec3 color; - varying vec3 vcolor; - - void main () { - gl_Position = vec4(position, 1.0); - vcolor = color; - } - - |] - - -fragmentShader : Shader {} {} { vcolor : Vec3 } -fragmentShader = - [glsl| - - precision mediump float; - varying vec3 vcolor; - - void main () { - gl_FragColor = vec4(vcolor, 1.0); - } - - |] diff --git a/examples/screenshots/crate.jpg b/examples/screenshots/crate.jpg deleted file mode 100644 index 56490ad..0000000 Binary files a/examples/screenshots/crate.jpg and /dev/null differ diff --git a/examples/screenshots/cube.jpg b/examples/screenshots/cube.jpg deleted file mode 100644 index 4240c2d..0000000 Binary files a/examples/screenshots/cube.jpg and /dev/null differ diff --git a/examples/screenshots/first-person.jpg b/examples/screenshots/first-person.jpg deleted file mode 100644 index 2e44b1c..0000000 Binary files a/examples/screenshots/first-person.jpg and /dev/null differ diff --git a/examples/screenshots/thwomp.jpg b/examples/screenshots/thwomp.jpg deleted file mode 100644 index 872f23c..0000000 Binary files a/examples/screenshots/thwomp.jpg and /dev/null differ diff --git a/examples/screenshots/triangle.jpg b/examples/screenshots/triangle.jpg deleted file mode 100644 index ee51b31..0000000 Binary files a/examples/screenshots/triangle.jpg and /dev/null differ diff --git a/examples/texture/thwomp-face.jpg b/examples/texture/thwomp-face.jpg deleted file mode 100644 index c5a8961..0000000 Binary files a/examples/texture/thwomp-face.jpg and /dev/null differ diff --git a/examples/texture/thwomp-side.jpg b/examples/texture/thwomp-side.jpg deleted file mode 100644 index a775982..0000000 Binary files a/examples/texture/thwomp-side.jpg and /dev/null differ diff --git a/examples/texture/wood-crate.jpg b/examples/texture/wood-crate.jpg deleted file mode 100644 index b9ba73c..0000000 Binary files a/examples/texture/wood-crate.jpg and /dev/null differ diff --git a/examples/thwomp.elm b/examples/thwomp.elm deleted file mode 100644 index ba6910c..0000000 --- a/examples/thwomp.elm +++ /dev/null @@ -1,265 +0,0 @@ -module Main exposing (main) - -{- - Thanks to The PaperNES Guy for the texture: - http://the-papernes-guy.deviantart.com/art/Thwomps-Thwomps-Thwomps-186879685 --} - -import Html exposing (Html, text) -import Html.Attributes exposing (width, height, style) -import Math.Matrix4 as Mat4 exposing (Mat4) -import Math.Vector2 as Vec2 exposing (Vec2, vec2) -import Math.Vector3 as Vec3 exposing (Vec3, vec3) -import Mouse -import Task exposing (Task) -import WebGL exposing (Mesh, Shader, Entity) -import WebGL.Texture as Texture exposing (Texture, defaultOptions, Error) -import Window - - -type alias Model = - { size : Window.Size - , position : Mouse.Position - , textures : Maybe ( Texture, Texture ) - } - - -type Action - = TexturesError Error - | TexturesLoaded ( Texture, Texture ) - | Resize Window.Size - | MouseMove Mouse.Position - - -main : Program Never Model Action -main = - Html.program - { init = init - , view = view - , subscriptions = subscriptions - , update = update - } - - -init : ( Model, Cmd Action ) -init = - ( { size = Window.Size 0 0 - , position = Mouse.Position 0 0 - , textures = Nothing - } - , Cmd.batch - [ Task.perform Resize Window.size - , fetchTextures - ] - ) - - -subscriptions : Model -> Sub Action -subscriptions _ = - Sub.batch - [ Window.resizes Resize - , Mouse.moves MouseMove - ] - - -update : Action -> Model -> ( Model, Cmd Action ) -update action model = - case action of - TexturesError err -> - ( model, Cmd.none ) - - TexturesLoaded textures -> - ( { model | textures = Just textures }, Cmd.none ) - - Resize size -> - ( { model | size = size }, Cmd.none ) - - MouseMove position -> - ( { model | position = position }, Cmd.none ) - - -fetchTextures : Cmd Action -fetchTextures = - [ "texture/thwomp-face.jpg" - , "texture/thwomp-side.jpg" - ] - |> List.map - (Texture.loadWith - { defaultOptions - | magnify = Texture.nearest - , minify = Texture.nearest - } - ) - |> Task.sequence - |> Task.andThen - (\textures -> - case textures of - face :: side :: _ -> - Task.succeed ( face, side ) - - _ -> - Task.fail Texture.LoadError - ) - |> Task.attempt - (\result -> - case result of - Err error -> - TexturesError error - - Ok textures -> - TexturesLoaded textures - ) - - - --- Meshes - - -type alias Vertex = - { position : Vec3 - , coord : Vec2 - } - - -faceMesh : Mesh Vertex -faceMesh = - WebGL.triangles square - - -sidesMesh : Mesh Vertex -sidesMesh = - [ ( 90, 0 ), ( 180, 0 ), ( 270, 0 ), ( 0, 90 ), ( 0, 270 ) ] - |> List.concatMap rotatedSquare - |> WebGL.triangles - - -rotatedSquare : ( Float, Float ) -> List ( Vertex, Vertex, Vertex ) -rotatedSquare ( angleXZ, angleYZ ) = - let - transformMat = - Mat4.mul - (Mat4.makeRotate (degrees angleXZ) Vec3.j) - (Mat4.makeRotate (degrees angleYZ) Vec3.i) - - transform vertex = - { vertex - | position = - Mat4.transform transformMat vertex.position - } - - transformTriangle ( a, b, c ) = - ( transform a, transform b, transform c ) - in - List.map transformTriangle square - - -square : List ( Vertex, Vertex, Vertex ) -square = - let - topLeft = - Vertex (vec3 -1 1 1) (vec2 0 1) - - topRight = - Vertex (vec3 1 1 1) (vec2 1 1) - - bottomLeft = - Vertex (vec3 -1 -1 1) (vec2 0 0) - - bottomRight = - Vertex (vec3 1 -1 1) (vec2 1 0) - in - [ ( topLeft, topRight, bottomLeft ) - , ( bottomLeft, topRight, bottomRight ) - ] - - - --- VIEW - - -view : Model -> Html Action -view { textures, size, position } = - case textures of - Just ( faceTexture, sideTexture ) -> - WebGL.toHtml - [ width size.width - , height size.height - , style [ ( "display", "block" ) ] - ] - [ toEntity faceMesh faceTexture size position - , toEntity sidesMesh sideTexture size position - ] - - Nothing -> - text "Loading textures..." - - -toEntity : Mesh Vertex -> Texture -> Window.Size -> Mouse.Position -> Entity -toEntity mesh texture { width, height } { x, y } = - WebGL.entity - vertexShader - fragmentShader - mesh - { texture = texture - , perspective = - perspective - (toFloat width) - (toFloat height) - (toFloat x) - (toFloat y) - } - - -perspective : Float -> Float -> Float -> Float -> Mat4 -perspective width height x y = - let - eye = - vec3 (0.5 - x / width) -(0.5 - y / height) 1 - |> Vec3.normalize - |> Vec3.scale 6 - in - Mat4.mul - (Mat4.makePerspective 45 (width / height) 0.01 100) - (Mat4.makeLookAt eye (vec3 0 0 0) Vec3.j) - - - --- SHADERS - - -type alias Uniforms = - { perspective : Mat4 - , texture : Texture - } - - -vertexShader : Shader Vertex Uniforms { vcoord : Vec2 } -vertexShader = - [glsl| - - attribute vec3 position; - attribute vec2 coord; - uniform mat4 perspective; - varying vec2 vcoord; - - void main () { - gl_Position = perspective * vec4(position, 1.0); - vcoord = coord.xy; - } - - |] - - -fragmentShader : Shader {} Uniforms { vcoord : Vec2 } -fragmentShader = - [glsl| - - precision mediump float; - uniform sampler2D texture; - varying vec2 vcoord; - - void main () { - gl_FragColor = texture2D(texture, vcoord); - } - - |] diff --git a/examples/triangle.elm b/examples/triangle.elm deleted file mode 100644 index 166ab37..0000000 --- a/examples/triangle.elm +++ /dev/null @@ -1,104 +0,0 @@ -module Main exposing (main) - -{- - Rotating triangle, that is a "hello world" of the WebGL --} - -import AnimationFrame -import Html exposing (Html) -import Html.Attributes exposing (width, height, style) -import Math.Matrix4 as Mat4 exposing (Mat4) -import Math.Vector3 as Vec3 exposing (vec3, Vec3) -import Time exposing (Time) -import WebGL exposing (Mesh, Shader) - - -main : Program Never Time Time -main = - Html.program - { init = ( 0, Cmd.none ) - , view = view - , subscriptions = (\model -> AnimationFrame.diffs Basics.identity) - , update = (\elapsed currentTime -> ( elapsed + currentTime, Cmd.none )) - } - - -view : Float -> Html msg -view t = - WebGL.toHtml - [ width 400 - , height 400 - , style [ ( "display", "block" ) ] - ] - [ WebGL.entity - vertexShader - fragmentShader - mesh - { perspective = perspective (t / 1000) } - ] - - -perspective : Float -> Mat4 -perspective t = - Mat4.mul - (Mat4.makePerspective 45 1 0.01 100) - (Mat4.makeLookAt (vec3 (4 * cos t) 0 (4 * sin t)) (vec3 0 0 0) (vec3 0 1 0)) - - - --- Mesh - - -type alias Vertex = - { position : Vec3 - , color : Vec3 - } - - -mesh : Mesh Vertex -mesh = - WebGL.triangles - [ ( Vertex (vec3 0 0 0) (vec3 1 0 0) - , Vertex (vec3 1 1 0) (vec3 0 1 0) - , Vertex (vec3 1 -1 0) (vec3 0 0 1) - ) - ] - - - --- Shaders - - -type alias Uniforms = - { perspective : Mat4 } - - -vertexShader : Shader Vertex Uniforms { vcolor : Vec3 } -vertexShader = - [glsl| - - attribute vec3 position; - attribute vec3 color; - uniform mat4 perspective; - varying vec3 vcolor; - - void main () { - gl_Position = perspective * vec4(position, 1.0); - vcolor = color; - } - - |] - - -fragmentShader : Shader {} Uniforms { vcolor : Vec3 } -fragmentShader = - [glsl| - - precision mediump float; - varying vec3 vcolor; - - void main () { - gl_FragColor = vec4(vcolor, 1.0); - } - - |] diff --git a/gh-pages.sh b/gh-pages.sh deleted file mode 100755 index 5d6ba2a..0000000 --- a/gh-pages.sh +++ /dev/null @@ -1,26 +0,0 @@ -#!/bin/bash -set -e - -rm -rf gh-pages || exit 0; - -mkdir -p gh-pages/examples - -# compile JS using Elm -cd examples -for i in crate cube first-person thwomp triangle; do - elm make $i.elm --yes --output ../gh-pages/examples/$i.html -done - -# copy the textures -cp -R texture ../gh-pages/examples -cp -R screenshots ../gh-pages/examples - -# configure domain -cd ../gh-pages -echo "webgl.elm-community.org" >> CNAME - -# init branch and commit -git init -git add . -git commit -m "Deploying to GH Pages" -git push --force "git@github.com:elm-community/webgl.git" master:gh-pages diff --git a/pipeline.png b/pipeline.png deleted file mode 100644 index ef3f2fa..0000000 Binary files a/pipeline.png and /dev/null differ diff --git a/release.sh b/release.sh deleted file mode 100755 index e8d33d9..0000000 --- a/release.sh +++ /dev/null @@ -1,25 +0,0 @@ -#!/bin/bash -set -euxo pipefail - -rm -rf release || exit 0; - -elm-package bump - -version=$(grep -m1 version elm-package.json | awk -F: '{ print $2 }' | sed 's/[", ]//g') - -git commit -a -m "Bump to $version" -git push - -cleanup="examples gh-pages.sh pipeline.png CONTRIBUTING.md .eslintrc.json release.sh" -last_commit=$(git rev-parse HEAD) - -git clone --reference . git@github.com:elm-community/webgl.git release -( - cd release - git checkout $last_commit - git rm -rf --ignore-unmatch $cleanup - git commit -m "Cleanup and release $version" - git tag -a $version -m "Release $version" - git push origin $version - elm-package publish -)