From 0eee41e5ce47160799406476d30279eded0a7318 Mon Sep 17 00:00:00 2001 From: gbrochar Date: Mon, 23 Nov 2020 20:40:51 +0100 Subject: [PATCH] phong --- src/client/main.ts | 36 ++++++++++++++++++++++++++++++++---- 1 file changed, 32 insertions(+), 4 deletions(-) diff --git a/src/client/main.ts b/src/client/main.ts index 84aac98..5d4134b 100644 --- a/src/client/main.ts +++ b/src/client/main.ts @@ -54,11 +54,33 @@ function main() { varying lowp vec4 vNormal; varying lowp vec3 vPosition; - void main() { - vec3 n = normalize(vec3(-5., 10., -5.)); - float diffuse = max(dot(vNormal.xyz, n), 0.); + vec3 extremize(vec3 v, float n) { + if (v.x > n / 2.) + v.x = n; + else + v.x = 0.; + if (v.y > n / 2.) + v.y = n; + else + v.y = 0.; + if (v.z > n / 2.) + v.z = n; + else + v.z = 0.; + return v; + } - gl_FragColor = vec4((vec3(1.) * diffuse * 0.8) + (vec3(1.) * 0.2), 1.0); + void main() { + vec3 n = normalize(vec3(-500., 1000., 500.) - vPosition); + float diffuse = max(dot(vNormal.xyz, n), 0.); + float specular = pow( + max(dot( + reflect(n, vNormal.xyz), + normalize(vec3(0., 0., -50.) - vPosition)), + 0.), 10.); + vec3 tmp = extremize(mod(vPosition.xyz + vec3(100.), vec3(3.)), 3.); + float texture = (tmp.x + tmp.y + tmp.z) / 9.; + gl_FragColor = vec4((vec3(1.) * diffuse * 0.8) + (texture * 0.2) + (specular * vec3(1.)), 1.0); }`; /* eslint-enable */ @@ -312,6 +334,12 @@ function drawScene(gl: any, // the center of the scene. const viewMatrix = mat4.create(); + + mat4.translate( + viewMatrix, + viewMatrix, + [Math.cos(squareRotation) * 5, Math.sin(squareRotation) * 5, 0]); + mat4.translate( viewMatrix, viewMatrix,