From 9b348ffe9338b073979458992ad932c14e592784 Mon Sep 17 00:00:00 2001 From: Andrey Kuzmin Date: Sat, 4 Jan 2020 17:46:18 +0100 Subject: [PATCH 1/2] Update to Elm 0.19.1 --- lessons/{lesson01.elm => Lesson01.elm} | 2 +- lessons/{lesson02.elm => Lesson02.elm} | 2 +- lessons/{lesson03.elm => Lesson03.elm} | 2 +- lessons/{lesson04.elm => Lesson04.elm} | 2 +- lessons/{lesson05.elm => Lesson05.elm} | 2 +- lessons/{lesson06.elm => Lesson06.elm} | 2 +- lessons/{lesson07.elm => Lesson07.elm} | 2 +- lessons/{lesson08.elm => Lesson08.elm} | 2 +- lessons/{lesson09.elm => Lesson09.elm} | 2 +- lessons/{lesson10.elm => Lesson10.elm} | 2 +- lessons/{lesson11.elm => Lesson11.elm} | 2 +- lessons/{lesson12.elm => Lesson12.elm} | 2 +- lessons/{lesson13.elm => Lesson13.elm} | 2 +- lessons/{lesson14.elm => Lesson14.elm} | 2 +- lessons/{lesson15.elm => Lesson15.elm} | 2 +- lessons/Makefile | 4 ++-- lessons/elm.json | 2 +- 17 files changed, 18 insertions(+), 18 deletions(-) rename lessons/{lesson01.elm => Lesson01.elm} (97%) rename lessons/{lesson02.elm => Lesson02.elm} (98%) rename lessons/{lesson03.elm => Lesson03.elm} (98%) rename lessons/{lesson04.elm => Lesson04.elm} (99%) rename lessons/{lesson05.elm => Lesson05.elm} (99%) rename lessons/{lesson06.elm => Lesson06.elm} (99%) rename lessons/{lesson07.elm => Lesson07.elm} (99%) rename lessons/{lesson08.elm => Lesson08.elm} (99%) rename lessons/{lesson09.elm => Lesson09.elm} (99%) rename lessons/{lesson10.elm => Lesson10.elm} (99%) rename lessons/{lesson11.elm => Lesson11.elm} (99%) rename lessons/{lesson12.elm => Lesson12.elm} (99%) rename lessons/{lesson13.elm => Lesson13.elm} (99%) rename lessons/{lesson14.elm => Lesson14.elm} (99%) rename lessons/{lesson15.elm => Lesson15.elm} (99%) diff --git a/lessons/lesson01.elm b/lessons/Lesson01.elm similarity index 97% rename from lessons/lesson01.elm rename to lessons/Lesson01.elm index 0eaaa9d..bad7f46 100644 --- a/lessons/lesson01.elm +++ b/lessons/Lesson01.elm @@ -1,4 +1,4 @@ -module Main exposing (main) +module Lesson01 exposing (main) -- Create a mesh with a triangle and a square diff --git a/lessons/lesson02.elm b/lessons/Lesson02.elm similarity index 98% rename from lessons/lesson02.elm rename to lessons/Lesson02.elm index 8a65791..9eacc80 100644 --- a/lessons/lesson02.elm +++ b/lessons/Lesson02.elm @@ -1,4 +1,4 @@ -module Main exposing (main) +module Lesson02 exposing (main) -- Create a mesh with a triangle and a square -- Uses varyings to interpolate colors diff --git a/lessons/lesson03.elm b/lessons/Lesson03.elm similarity index 98% rename from lessons/lesson03.elm rename to lessons/Lesson03.elm index 4dc13c9..388aa2b 100644 --- a/lessons/lesson03.elm +++ b/lessons/Lesson03.elm @@ -1,4 +1,4 @@ -module Main exposing (main) +module Lesson03 exposing (main) -- Create a mesh with a triangle and a square -- Uses varyings to interpolate colors diff --git a/lessons/lesson04.elm b/lessons/Lesson04.elm similarity index 99% rename from lessons/lesson04.elm rename to lessons/Lesson04.elm index 713720e..6a5439a 100644 --- a/lessons/lesson04.elm +++ b/lessons/Lesson04.elm @@ -1,4 +1,4 @@ -module Main exposing (main) +module Lesson04 exposing (main) -- Create a pyramid and a cube meshes diff --git a/lessons/lesson05.elm b/lessons/Lesson05.elm similarity index 99% rename from lessons/lesson05.elm rename to lessons/Lesson05.elm index 68c584a..f1e0e8a 100644 --- a/lessons/lesson05.elm +++ b/lessons/Lesson05.elm @@ -1,4 +1,4 @@ -module Main exposing (main) +module Lesson05 exposing (main) -- Rotating cube mesh with texture diff --git a/lessons/lesson06.elm b/lessons/Lesson06.elm similarity index 99% rename from lessons/lesson06.elm rename to lessons/Lesson06.elm index 05f4d55..200a1c9 100644 --- a/lessons/lesson06.elm +++ b/lessons/Lesson06.elm @@ -1,4 +1,4 @@ -module Main exposing (main) +module Lesson06 exposing (main) import Browser import Browser.Events exposing (onAnimationFrameDelta, onKeyDown, onKeyUp) diff --git a/lessons/lesson07.elm b/lessons/Lesson07.elm similarity index 99% rename from lessons/lesson07.elm rename to lessons/Lesson07.elm index 6ed97d5..9b1dc43 100644 --- a/lessons/lesson07.elm +++ b/lessons/Lesson07.elm @@ -1,4 +1,4 @@ -module Main exposing (main) +module Lesson07 exposing (main) import Browser import Browser.Events exposing (onAnimationFrameDelta, onKeyDown, onKeyUp) diff --git a/lessons/lesson08.elm b/lessons/Lesson08.elm similarity index 99% rename from lessons/lesson08.elm rename to lessons/Lesson08.elm index 88e3828..56c034b 100644 --- a/lessons/lesson08.elm +++ b/lessons/Lesson08.elm @@ -1,4 +1,4 @@ -module Main exposing (main) +module Lesson08 exposing (main) import Browser import Browser.Events exposing (onAnimationFrameDelta, onKeyDown, onKeyUp) diff --git a/lessons/lesson09.elm b/lessons/Lesson09.elm similarity index 99% rename from lessons/lesson09.elm rename to lessons/Lesson09.elm index d733587..68a449b 100644 --- a/lessons/lesson09.elm +++ b/lessons/Lesson09.elm @@ -1,4 +1,4 @@ -module Main exposing (main) +module Lesson09 exposing (main) import Array import Browser diff --git a/lessons/lesson10.elm b/lessons/Lesson10.elm similarity index 99% rename from lessons/lesson10.elm rename to lessons/Lesson10.elm index 148eeb0..2df53ff 100644 --- a/lessons/lesson10.elm +++ b/lessons/Lesson10.elm @@ -1,4 +1,4 @@ -module Main exposing (main) +module Lesson10 exposing (main) import Array import Browser diff --git a/lessons/lesson11.elm b/lessons/Lesson11.elm similarity index 99% rename from lessons/lesson11.elm rename to lessons/Lesson11.elm index 38ea748..7c60df4 100644 --- a/lessons/lesson11.elm +++ b/lessons/Lesson11.elm @@ -1,4 +1,4 @@ -module Main exposing (main) +module Lesson11 exposing (main) import Browser import Browser.Events exposing (onMouseDown, onMouseMove, onMouseUp) diff --git a/lessons/lesson12.elm b/lessons/Lesson12.elm similarity index 99% rename from lessons/lesson12.elm rename to lessons/Lesson12.elm index 9c6fcad..4351d04 100644 --- a/lessons/lesson12.elm +++ b/lessons/Lesson12.elm @@ -1,4 +1,4 @@ -module Main exposing (main) +module Lesson12 exposing (main) import Browser import Browser.Events exposing (onAnimationFrameDelta) diff --git a/lessons/lesson13.elm b/lessons/Lesson13.elm similarity index 99% rename from lessons/lesson13.elm rename to lessons/Lesson13.elm index 0dae663..fbd12cd 100644 --- a/lessons/lesson13.elm +++ b/lessons/Lesson13.elm @@ -1,4 +1,4 @@ -module Main exposing (main) +module Lesson13 exposing (main) import Browser import Browser.Events exposing (onAnimationFrameDelta) diff --git a/lessons/lesson14.elm b/lessons/Lesson14.elm similarity index 99% rename from lessons/lesson14.elm rename to lessons/Lesson14.elm index cdaeb17..ce025e1 100644 --- a/lessons/lesson14.elm +++ b/lessons/Lesson14.elm @@ -1,4 +1,4 @@ -module Main exposing (main) +module Lesson14 exposing (main) import Browser import Browser.Events exposing (onAnimationFrameDelta, onKeyDown, onKeyUp) diff --git a/lessons/lesson15.elm b/lessons/Lesson15.elm similarity index 99% rename from lessons/lesson15.elm rename to lessons/Lesson15.elm index 4ab412e..1cb9724 100644 --- a/lessons/lesson15.elm +++ b/lessons/Lesson15.elm @@ -1,4 +1,4 @@ -module Main exposing (main) +module Lesson15 exposing (main) import Array import Browser diff --git a/lessons/Makefile b/lessons/Makefile index 582a253..b8788b3 100644 --- a/lessons/Makefile +++ b/lessons/Makefile @@ -1,8 +1,8 @@ -SOURCES = lesson01.elm lesson02.elm lesson03.elm lesson04.elm lesson05.elm lesson06.elm lesson07.elm lesson08.elm lesson09.elm lesson10.elm lesson11.elm lesson12.elm lesson13.elm lesson14.elm lesson15.elm +SOURCES = $(shell find . -name "*.elm") HTMLS = $(SOURCES:.elm=.html) all: $(HTMLS) @echo Everything done, sir %.html: %.elm - elm make $< --output ../out/$@ --optimize + elm make $< --output ../out/$(shell echo $@ | tr '[:upper:]' '[:lower:]') --optimize diff --git a/lessons/elm.json b/lessons/elm.json index f4a8432..03da48f 100644 --- a/lessons/elm.json +++ b/lessons/elm.json @@ -3,7 +3,7 @@ "source-directories": [ "." ], - "elm-version": "0.19.0", + "elm-version": "0.19.1", "dependencies": { "direct": { "elm/browser": "1.0.1", From 203b33ba011cb61eabbda1d58e11f0bb34dfbc08 Mon Sep 17 00:00:00 2001 From: Andrey Kuzmin Date: Sat, 4 Jan 2020 18:10:45 +0100 Subject: [PATCH 2/2] Fix shaders to support --optimize mode --- lessons/Lesson07.elm | 17 ++++++++++++----- lessons/Lesson08.elm | 17 ++++++++++++----- lessons/Lesson11.elm | 17 ++++++++++++----- lessons/Lesson12.elm | 17 ++++++++++++----- lessons/Lesson13.elm | 35 +++++++++++++++++++++-------------- lessons/Lesson14.elm | 29 ++++++++++++++++++----------- lessons/Lesson15.elm | 29 ++++++++++++++++++----------- 7 files changed, 105 insertions(+), 56 deletions(-) diff --git a/lessons/Lesson07.elm b/lessons/Lesson07.elm index 9b1dc43..adedbbb 100644 --- a/lessons/Lesson07.elm +++ b/lessons/Lesson07.elm @@ -441,7 +441,7 @@ renderEntity mesh thetaX thetaY texture position lighting directionalColour dire [ WebGL.entity vertexShader fragmentShader mesh (uniformsCube thetaX thetaY tex position lighting directionalColour directional ambientColour) ] -uniformsCube : Float -> Float -> Texture -> Vec3 -> Bool -> Vec3 -> Vec3 -> Vec3 -> { texture : Texture, worldSpace : Mat4, perspective : Mat4, camera : Mat4, normalMatrix : Mat4, lighting : Bool, directionalColour : Vec3, ambientColour : Vec3, directional : Vec3 } +uniformsCube : Float -> Float -> Texture -> Vec3 -> Bool -> Vec3 -> Vec3 -> Vec3 -> { texture : Texture, worldSpace : Mat4, perspective : Mat4, camera : Mat4, normalMatrix : Mat4, lighting : Int, directionalColour : Vec3, ambientColour : Vec3, directional : Vec3 } uniformsCube tx ty texture displacement lighting directionalColour directional ambientColour = let worldSpace = @@ -452,13 +452,20 @@ uniformsCube tx ty texture displacement lighting directionalColour directional a perspective = makePerspective 45 1 0.1 100 + + boolToInt bool = + if bool then + 1 + + else + 0 in { texture = texture , worldSpace = worldSpace , perspective = perspective , camera = camera , normalMatrix = transpose (inverseOrthonormal worldSpace) - , lighting = lighting + , lighting = boolToInt lighting , directionalColour = directionalColour , ambientColour = ambientColour , directional = directional @@ -469,7 +476,7 @@ uniformsCube tx ty texture displacement lighting directionalColour directional a -- SHADERS -vertexShader : Shader { attr | position : Vec3, coord : Vec3, norm : Vec3 } { unif | worldSpace : Mat4, perspective : Mat4, camera : Mat4, normalMatrix : Mat4, lighting : Bool, directionalColour : Vec3, ambientColour : Vec3, directional : Vec3 } { vcoord : Vec2, lightWeighting : Vec3 } +vertexShader : Shader { attr | position : Vec3, coord : Vec3, norm : Vec3 } { unif | worldSpace : Mat4, perspective : Mat4, camera : Mat4, normalMatrix : Mat4, lighting : Int, directionalColour : Vec3, ambientColour : Vec3, directional : Vec3 } { vcoord : Vec2, lightWeighting : Vec3 } vertexShader = [glsl| @@ -483,7 +490,7 @@ vertexShader = uniform mat4 perspective; uniform mat4 normalMatrix; uniform mat4 camera; - uniform bool lighting; + uniform int lighting; uniform vec3 directionalColour; uniform vec3 directional; uniform vec3 ambientColour; @@ -495,7 +502,7 @@ vertexShader = gl_Position = perspective * camera * worldSpace * vec4(position, 1.0); vcoord = coord.xy; - if (!lighting) { + if (lighting == 0) { lightWeighting = vec3(1.0, 1.0, 1.0); } else { vec4 transformedNormal = normalMatrix * vec4(norm, 0.0); diff --git a/lessons/Lesson08.elm b/lessons/Lesson08.elm index 56c034b..5ed17ed 100644 --- a/lessons/Lesson08.elm +++ b/lessons/Lesson08.elm @@ -480,7 +480,7 @@ renderEntity mesh thetaX thetaY texture position lighting blending alpha directi [ WebGL.entityWith settings vertexShader fragmentShader mesh (uniformsCube thetaX thetaY tex position lighting alpha directionalColour directional ambientColour) ] -uniformsCube : Float -> Float -> Texture -> Vec3 -> Bool -> Float -> Vec3 -> Vec3 -> Vec3 -> { texture : Texture, worldSpace : Mat4, perspective : Mat4, camera : Mat4, normalMatrix : Mat4, lighting : Bool, alpha : Float, directionalColour : Vec3, ambientColour : Vec3, directional : Vec3 } +uniformsCube : Float -> Float -> Texture -> Vec3 -> Bool -> Float -> Vec3 -> Vec3 -> Vec3 -> { texture : Texture, worldSpace : Mat4, perspective : Mat4, camera : Mat4, normalMatrix : Mat4, lighting : Int, alpha : Float, directionalColour : Vec3, ambientColour : Vec3, directional : Vec3 } uniformsCube tx ty texture displacement lighting alpha directionalColour directional ambientColour = let worldSpace = @@ -491,13 +491,20 @@ uniformsCube tx ty texture displacement lighting alpha directionalColour directi perspective = makePerspective 45 1 0.1 100 + + boolToInt bool = + if bool then + 1 + + else + 0 in { texture = texture , worldSpace = worldSpace , perspective = perspective , camera = camera , normalMatrix = transpose (inverseOrthonormal (mul worldSpace camera)) - , lighting = lighting + , lighting = boolToInt lighting , alpha = alpha , directionalColour = directionalColour , ambientColour = ambientColour @@ -509,7 +516,7 @@ uniformsCube tx ty texture displacement lighting alpha directionalColour directi -- SHADERS -vertexShader : Shader { attr | position : Vec3, coord : Vec3, norm : Vec3 } { unif | worldSpace : Mat4, perspective : Mat4, camera : Mat4, normalMatrix : Mat4, lighting : Bool, directionalColour : Vec3, ambientColour : Vec3, directional : Vec3 } { vcoord : Vec2, lightWeighting : Vec3 } +vertexShader : Shader { attr | position : Vec3, coord : Vec3, norm : Vec3 } { unif | worldSpace : Mat4, perspective : Mat4, camera : Mat4, normalMatrix : Mat4, lighting : Int, directionalColour : Vec3, ambientColour : Vec3, directional : Vec3 } { vcoord : Vec2, lightWeighting : Vec3 } vertexShader = [glsl| @@ -523,7 +530,7 @@ vertexShader = uniform mat4 perspective; uniform mat4 normalMatrix; uniform mat4 camera; - uniform bool lighting; + uniform int lighting; uniform vec3 directionalColour; uniform vec3 directional; uniform vec3 ambientColour; @@ -535,7 +542,7 @@ vertexShader = gl_Position = perspective * camera * worldSpace * vec4(position, 1.0); vcoord = coord.xy; - if (!lighting) { + if (lighting == 0) { lightWeighting = vec3(1.0, 1.0, 1.0); } else { vec4 transformedNormal = normalMatrix * vec4(norm, 0.0); diff --git a/lessons/Lesson11.elm b/lessons/Lesson11.elm index 7c60df4..2ccf445 100644 --- a/lessons/Lesson11.elm +++ b/lessons/Lesson11.elm @@ -388,7 +388,7 @@ renderEntity mesh thetaX thetaY texture position lighting directionalColour dire [ WebGL.entity vertexShader fragmentShader mesh (uniformsShpere thetaX thetaY tex position lighting directionalColour directional ambientColour) ] -uniformsShpere : Float -> Float -> Texture -> Vec3 -> Bool -> Vec3 -> Vec3 -> Vec3 -> { texture : Texture, worldSpace : Mat4, perspective : Mat4, camera : Mat4, normalMatrix : Mat4, lighting : Bool, directionalColour : Vec3, ambientColour : Vec3, directional : Vec3 } +uniformsShpere : Float -> Float -> Texture -> Vec3 -> Bool -> Vec3 -> Vec3 -> Vec3 -> { texture : Texture, worldSpace : Mat4, perspective : Mat4, camera : Mat4, normalMatrix : Mat4, lighting : Int, directionalColour : Vec3, ambientColour : Vec3, directional : Vec3 } uniformsShpere tx ty texture displacement lighting directionalColour directional ambientColour = let worldSpace = @@ -399,13 +399,20 @@ uniformsShpere tx ty texture displacement lighting directionalColour directional perspective = makePerspective 45 1 0.1 100 + + boolToInt bool = + if bool then + 1 + + else + 0 in { texture = texture , worldSpace = worldSpace , perspective = perspective , camera = camera , normalMatrix = transpose (inverseOrthonormal (mul worldSpace camera)) - , lighting = lighting + , lighting = boolToInt lighting , directionalColour = directionalColour , ambientColour = ambientColour , directional = directional @@ -416,7 +423,7 @@ uniformsShpere tx ty texture displacement lighting directionalColour directional -- SHADERS -vertexShader : Shader { attr | position : Vec3, coord : Vec3, norm : Vec3 } { unif | worldSpace : Mat4, perspective : Mat4, camera : Mat4, normalMatrix : Mat4, lighting : Bool, directionalColour : Vec3, ambientColour : Vec3, directional : Vec3 } { vcoord : Vec2, lightWeighting : Vec3 } +vertexShader : Shader { attr | position : Vec3, coord : Vec3, norm : Vec3 } { unif | worldSpace : Mat4, perspective : Mat4, camera : Mat4, normalMatrix : Mat4, lighting : Int, directionalColour : Vec3, ambientColour : Vec3, directional : Vec3 } { vcoord : Vec2, lightWeighting : Vec3 } vertexShader = [glsl| @@ -430,7 +437,7 @@ vertexShader = uniform mat4 perspective; uniform mat4 normalMatrix; uniform mat4 camera; - uniform bool lighting; + uniform int lighting; uniform vec3 directionalColour; uniform vec3 directional; uniform vec3 ambientColour; @@ -442,7 +449,7 @@ vertexShader = gl_Position = perspective * camera * worldSpace * vec4(position, 1.0); vcoord = coord.xy; - if (!lighting) { + if (lighting == 0) { lightWeighting = vec3(1.0, 1.0, 1.0); } else { vec4 transformedNormal = normalMatrix * vec4(norm, 0.0); diff --git a/lessons/Lesson12.elm b/lessons/Lesson12.elm index 4351d04..5efdb17 100644 --- a/lessons/Lesson12.elm +++ b/lessons/Lesson12.elm @@ -384,7 +384,7 @@ renderEntity mesh theta texture position lighting pointColour point ambientColou [ WebGL.entity vertexShader fragmentShader mesh (uniformsShpere theta texture position lighting pointColour point ambientColour) ] -uniformsShpere : Float -> Texture -> Vec3 -> Bool -> Vec3 -> Vec3 -> Vec3 -> { texture : Texture, worldSpace : Mat4, perspective : Mat4, camera : Mat4, normalMatrix : Mat4, lighting : Bool, pointColour : Vec3, ambientColour : Vec3, point : Vec3 } +uniformsShpere : Float -> Texture -> Vec3 -> Bool -> Vec3 -> Vec3 -> Vec3 -> { texture : Texture, worldSpace : Mat4, perspective : Mat4, camera : Mat4, normalMatrix : Mat4, lighting : Int, pointColour : Vec3, ambientColour : Vec3, point : Vec3 } uniformsShpere tx texture displacement lighting pointColour point ambientColour = let worldSpace = @@ -395,13 +395,20 @@ uniformsShpere tx texture displacement lighting pointColour point ambientColour perspective = makePerspective 45 1 0.1 100 + + boolToInt bool = + if bool then + 1 + + else + 0 in { texture = texture , worldSpace = worldSpace , perspective = perspective , camera = camera , normalMatrix = transpose (inverseOrthonormal worldSpace) - , lighting = lighting + , lighting = boolToInt lighting , pointColour = pointColour , ambientColour = ambientColour , point = point @@ -412,7 +419,7 @@ uniformsShpere tx texture displacement lighting pointColour point ambientColour -- SHADERS -vertexShader : Shader { attr | position : Vec3, coord : Vec3, norm : Vec3 } { unif | worldSpace : Mat4, perspective : Mat4, camera : Mat4, normalMatrix : Mat4, lighting : Bool, pointColour : Vec3, ambientColour : Vec3, point : Vec3 } { vcoord : Vec2, lightWeighting : Vec3 } +vertexShader : Shader { attr | position : Vec3, coord : Vec3, norm : Vec3 } { unif | worldSpace : Mat4, perspective : Mat4, camera : Mat4, normalMatrix : Mat4, lighting : Int, pointColour : Vec3, ambientColour : Vec3, point : Vec3 } { vcoord : Vec2, lightWeighting : Vec3 } vertexShader = [glsl| @@ -426,7 +433,7 @@ vertexShader = uniform mat4 perspective; uniform mat4 normalMatrix; uniform mat4 camera; - uniform bool lighting; + uniform int lighting; uniform vec3 pointColour; uniform vec3 point; uniform vec3 ambientColour; @@ -439,7 +446,7 @@ vertexShader = gl_Position = perspective * camera * mvPosition; vcoord = coord.xy; - if (!lighting) { + if (lighting == 0) { lightWeighting = vec3(1.0, 1.0, 1.0); } else { //vec4 directional = vec4(normalize(point), 0.0); diff --git a/lessons/Lesson13.elm b/lessons/Lesson13.elm index fbd12cd..905a993 100644 --- a/lessons/Lesson13.elm +++ b/lessons/Lesson13.elm @@ -406,7 +406,7 @@ renderEntity mesh theta texture position useLighting useTextures usePerFragment WebGL.entity vertexShaderPV fragmentShaderPV mesh (uniformsShpere theta texture position useLighting useTextures pointColour point ambientColour) -uniformsShpere : Float -> Texture -> Vec3 -> Bool -> Bool -> Vec3 -> Vec3 -> Vec3 -> { texture : Texture, worldSpace : Mat4, perspective : Mat4, camera : Mat4, normalMatrix : Mat4, useLighting : Bool, useTextures : Bool, pointColour : Vec3, ambientColour : Vec3, point : Vec3 } +uniformsShpere : Float -> Texture -> Vec3 -> Bool -> Bool -> Vec3 -> Vec3 -> Vec3 -> { texture : Texture, worldSpace : Mat4, perspective : Mat4, camera : Mat4, normalMatrix : Mat4, useLighting : Int, useTextures : Int, pointColour : Vec3, ambientColour : Vec3, point : Vec3 } uniformsShpere tx texture displacement useLighting useTextures pointColour point ambientColour = let worldSpace = @@ -417,14 +417,21 @@ uniformsShpere tx texture displacement useLighting useTextures pointColour point perspective = makePerspective 45 1 0.1 100 + + boolToInt bool = + if bool then + 1 + + else + 0 in { texture = texture , worldSpace = worldSpace , perspective = perspective , camera = camera , normalMatrix = transpose (inverseOrthonormal worldSpace) - , useLighting = useLighting - , useTextures = useTextures + , useLighting = boolToInt useLighting + , useTextures = boolToInt useTextures , pointColour = pointColour , ambientColour = ambientColour , point = point @@ -464,14 +471,14 @@ vertexShaderPF = |] -fragmentShaderPF : Shader {} { unif | texture : Texture, useLighting : Bool, useTextures : Bool, ambientColour : Vec3, pointColour : Vec3, point : Vec3 } { vcoord : Vec2, vPosition : Vec3, vTransformedNormal : Vec3 } +fragmentShaderPF : Shader {} { unif | texture : Texture, useLighting : Int, useTextures : Int, ambientColour : Vec3, pointColour : Vec3, point : Vec3 } { vcoord : Vec2, vPosition : Vec3, vTransformedNormal : Vec3 } fragmentShaderPF = [glsl| precision mediump float; uniform sampler2D texture; - uniform bool useLighting; - uniform bool useTextures; + uniform int useLighting; + uniform int useTextures; uniform vec3 ambientColour; uniform vec3 pointColour; uniform vec3 point; @@ -483,7 +490,7 @@ fragmentShaderPF = void main () { vec3 lightWeighting; lightWeighting = vec3(1.0, 1.0, 1.0); - if (!useLighting) { + if (useLighting == 0) { lightWeighting = vec3(1.0, 1.0, 1.0); } else { vec3 lightDirection = normalize(point - vPosition ); @@ -492,7 +499,7 @@ fragmentShaderPF = lightWeighting = ambientColour + pointColour * directionalLightWeighting; } vec4 fragmentColor; - if (useTextures) { + if (useTextures == 1) { fragmentColor = texture2D(texture, vec2(vcoord.s, vcoord.t)); } else { fragmentColor = vec4(1.0, 1.0, 1.0, 1.0); @@ -504,7 +511,7 @@ fragmentShaderPF = |] -vertexShaderPV : Shader { attr | position : Vec3, coord : Vec3, norm : Vec3 } { unif | worldSpace : Mat4, perspective : Mat4, camera : Mat4, normalMatrix : Mat4, useLighting : Bool, pointColour : Vec3, ambientColour : Vec3, point : Vec3 } { vcoord : Vec2, lightWeighting : Vec3 } +vertexShaderPV : Shader { attr | position : Vec3, coord : Vec3, norm : Vec3 } { unif | worldSpace : Mat4, perspective : Mat4, camera : Mat4, normalMatrix : Mat4, useLighting : Int, pointColour : Vec3, ambientColour : Vec3, point : Vec3 } { vcoord : Vec2, lightWeighting : Vec3 } vertexShaderPV = [glsl| @@ -518,7 +525,7 @@ vertexShaderPV = uniform mat4 perspective; uniform mat4 normalMatrix; uniform mat4 camera; - uniform bool useLighting; + uniform int useLighting; uniform vec3 pointColour; uniform vec3 point; uniform vec3 ambientColour; @@ -531,7 +538,7 @@ vertexShaderPV = gl_Position = perspective * camera * mvPosition; vcoord = coord.xy; - if (!useLighting) { + if (useLighting == 0) { lightWeighting = vec3(1.0, 1.0, 1.0); } else { vec3 transformedNormal = vec3(normalMatrix * vec4(norm, 0.0)); @@ -543,20 +550,20 @@ vertexShaderPV = |] -fragmentShaderPV : Shader {} { unif | texture : Texture, useTextures : Bool } { vcoord : Vec2, lightWeighting : Vec3 } +fragmentShaderPV : Shader {} { unif | texture : Texture, useTextures : Int } { vcoord : Vec2, lightWeighting : Vec3 } fragmentShaderPV = [glsl| precision mediump float; uniform sampler2D texture; - uniform bool useTextures; + uniform int useTextures; varying vec2 vcoord; varying vec3 lightWeighting; void main () { vec4 fragmentColor; - if (useTextures) { + if (useTextures == 1) { fragmentColor = texture2D(texture, vec2(vcoord.s, vcoord.t)); } else { fragmentColor = vec4(1.0, 1.0, 1.0, 1.0); diff --git a/lessons/Lesson14.elm b/lessons/Lesson14.elm index ce025e1..1c581a7 100644 --- a/lessons/Lesson14.elm +++ b/lessons/Lesson14.elm @@ -411,7 +411,7 @@ renderEntity world theta shininess texture position useLighting useSpecular useT [ WebGL.entity vertexShader fragmentShader world (uniforms tex theta shininess position useLighting useSpecular useTextures specularColor specular ambientColor diffuseColor) ] -uniforms : Texture -> Float -> Float -> Vec3 -> Bool -> Bool -> Bool -> Vec3 -> Vec3 -> Vec3 -> Vec3 -> { texture : Texture, perspective : Mat4, camera : Mat4, worldSpace : Mat4, useLighting : Bool, normalMatrix : Mat4, useSpecular : Bool, useTextures : Bool, specularColor : Vec3, ambientColor : Vec3, diffuseColor : Vec3, specular : Vec3, shininess : Float } +uniforms : Texture -> Float -> Float -> Vec3 -> Bool -> Bool -> Bool -> Vec3 -> Vec3 -> Vec3 -> Vec3 -> { texture : Texture, perspective : Mat4, camera : Mat4, worldSpace : Mat4, useLighting : Int, normalMatrix : Mat4, useSpecular : Int, useTextures : Int, specularColor : Vec3, ambientColor : Vec3, diffuseColor : Vec3, specular : Vec3, shininess : Float } uniforms texture theta shininess position useLighting useSpecular useTextures specularColor specular ambientColor diffuseColor = let worldSpace = @@ -422,15 +422,22 @@ uniforms texture theta shininess position useLighting useSpecular useTextures sp perspective = makePerspective 45 1 0.1 100 + + boolToInt bool = + if bool then + 1 + + else + 0 in { texture = texture , worldSpace = worldSpace , camera = camera , perspective = perspective , normalMatrix = transpose (inverseOrthonormal worldSpace) - , useLighting = useLighting - , useSpecular = useSpecular - , useTextures = useTextures + , useLighting = boolToInt useLighting + , useSpecular = boolToInt useSpecular + , useTextures = boolToInt useTextures , specularColor = specularColor , ambientColor = ambientColor , diffuseColor = diffuseColor @@ -472,15 +479,15 @@ vertexShader = |] -fragmentShader : Shader {} { unif | texture : Texture, useSpecular : Bool, useLighting : Bool, useTextures : Bool, ambientColor : Vec3, specularColor : Vec3, diffuseColor : Vec3, specular : Vec3, shininess : Float } { vcoord : Vec2, vPosition : Vec3, vTransformedNormal : Vec3 } +fragmentShader : Shader {} { unif | texture : Texture, useSpecular : Int, useLighting : Int, useTextures : Int, ambientColor : Vec3, specularColor : Vec3, diffuseColor : Vec3, specular : Vec3, shininess : Float } { vcoord : Vec2, vPosition : Vec3, vTransformedNormal : Vec3 } fragmentShader = [glsl| precision mediump float; uniform sampler2D texture; - uniform bool useLighting; - uniform bool useSpecular; - uniform bool useTextures; + uniform int useLighting; + uniform int useSpecular; + uniform int useTextures; uniform vec3 ambientColor; uniform vec3 diffuseColor; uniform vec3 specularColor; @@ -494,7 +501,7 @@ fragmentShader = void main () { vec3 lightWeighting; lightWeighting = vec3(1.0, 1.0, 1.0); - if (!useLighting) { + if (useLighting == 0) { lightWeighting = vec3(1.0, 1.0, 1.0); } else { @@ -502,7 +509,7 @@ fragmentShader = vec3 normal = normalize(vTransformedNormal); float specularLightWeighting = 0.0; - if (useSpecular) { + if (useSpecular == 1) { vec3 eyeDirection = normalize(-vPosition.xyz); vec3 reflectionDirection = reflect(-lightDirection, normal); @@ -515,7 +522,7 @@ fragmentShader = + diffuseColor * diffuseLightWeighting; } vec4 fragmentColor; - if (useTextures) { + if (useTextures == 1) { fragmentColor = texture2D(texture, vec2(vcoord.s, vcoord.t)); } else { fragmentColor = vec4(1.0, 1.0, 1.0, 1.0); diff --git a/lessons/Lesson15.elm b/lessons/Lesson15.elm index 1cb9724..8dc1d05 100644 --- a/lessons/Lesson15.elm +++ b/lessons/Lesson15.elm @@ -387,7 +387,7 @@ renderEntity theta textures position useLighting useSpecularMap useColorMap spec [] -uniforms : Texture -> Texture -> Float -> Vec3 -> Bool -> Bool -> Bool -> Vec3 -> Vec3 -> Vec3 -> Vec3 -> { colorMap : Texture, specularMap : Texture, perspective : Mat4, camera : Mat4, worldSpace : Mat4, useLighting : Bool, normalMatrix : Mat4, useSpecularMap : Bool, useColorMap : Bool, specularColor : Vec3, ambientColor : Vec3, diffuseColor : Vec3, specular : Vec3 } +uniforms : Texture -> Texture -> Float -> Vec3 -> Bool -> Bool -> Bool -> Vec3 -> Vec3 -> Vec3 -> Vec3 -> { colorMap : Texture, specularMap : Texture, perspective : Mat4, camera : Mat4, worldSpace : Mat4, useLighting : Int, normalMatrix : Mat4, useSpecularMap : Int, useColorMap : Int, specularColor : Vec3, ambientColor : Vec3, diffuseColor : Vec3, specular : Vec3 } uniforms colorMap specularMap theta position useLighting useSpecularMap useColorMap specularColor specular ambientColor diffuseColor = let worldSpace = @@ -398,6 +398,13 @@ uniforms colorMap specularMap theta position useLighting useSpecularMap useColor perspective = makePerspective 45 1 0.1 100 + + boolToInt bool = + if bool then + 1 + + else + 0 in { colorMap = colorMap , specularMap = specularMap @@ -405,9 +412,9 @@ uniforms colorMap specularMap theta position useLighting useSpecularMap useColor , camera = camera , perspective = perspective , normalMatrix = transpose (inverseOrthonormal worldSpace) - , useLighting = useLighting - , useSpecularMap = useSpecularMap - , useColorMap = useColorMap + , useLighting = boolToInt useLighting + , useSpecularMap = boolToInt useSpecularMap + , useColorMap = boolToInt useColorMap , specularColor = specularColor , ambientColor = ambientColor , diffuseColor = diffuseColor @@ -448,16 +455,16 @@ vertexShader = |] -fragmentShader : Shader {} { unif | colorMap : Texture, specularMap : Texture, useSpecularMap : Bool, useLighting : Bool, useColorMap : Bool, ambientColor : Vec3, specularColor : Vec3, diffuseColor : Vec3, specular : Vec3 } { vcoord : Vec2, vPosition : Vec3, vTransformedNormal : Vec3 } +fragmentShader : Shader {} { unif | colorMap : Texture, specularMap : Texture, useSpecularMap : Int, useLighting : Int, useColorMap : Int, ambientColor : Vec3, specularColor : Vec3, diffuseColor : Vec3, specular : Vec3 } { vcoord : Vec2, vPosition : Vec3, vTransformedNormal : Vec3 } fragmentShader = [glsl| precision mediump float; uniform sampler2D colorMap; uniform sampler2D specularMap; - uniform bool useLighting; - uniform bool useSpecularMap; - uniform bool useColorMap; + uniform int useLighting; + uniform int useSpecularMap; + uniform int useColorMap; uniform vec3 ambientColor; uniform vec3 diffuseColor; uniform vec3 specularColor; @@ -470,7 +477,7 @@ fragmentShader = void main () { vec3 lightWeighting; lightWeighting = vec3(1.0, 1.0, 1.0); - if (!useLighting) { + if (useLighting == 0) { lightWeighting = vec3(1.0, 1.0, 1.0); } else { @@ -479,7 +486,7 @@ fragmentShader = float specularLightWeighting = 0.0; float shininess = 32.0; - if (useSpecularMap) { + if (useSpecularMap == 1) { shininess = texture2D(specularMap, vec2(vcoord.s, vcoord.t)).r * 255.0; } if (shininess < 255.0) { @@ -495,7 +502,7 @@ fragmentShader = + diffuseColor * diffuseLightWeighting; } vec4 fragmentColor; - if (useColorMap) { + if (useColorMap == 1) { fragmentColor = texture2D(colorMap, vec2(vcoord.s, vcoord.t)); } else { fragmentColor = vec4(1.0, 1.0, 1.0, 1.0);