"use strict";
{
const webgl = {
init() {
this.elem = document.createElement("canvas");
document.body.appendChild(this.elem);
const options = { alpha: false };
const gl = this.gl = this.elem.getContext('webgl', options) || this.elem.getContext('experimental-webgl', options);
this.vertexShader = gl.createShader(gl.VERTEX_SHADER);
gl.shaderSource(
this.vertexShader,
`
uniform mat4 camProj, camView, modelMatrix;
attribute vec3 aPosition, aNormal, aColor;
varying vec3 vWPosition, vPosition, vNormal, vColor;
void main(void) {
vec4 mpos = modelMatrix * vec4(aPosition, 1.0);
vec4 wpos = camView * mpos;
vPosition = wpos.xyz;
vWPosition = mpos.xyz;
vNormal = aNormal;
vColor = aColor;
gl_Position = camProj * wpos;
}
`
);
this.fragmentShader = gl.createShader(gl.FRAGMENT_SHADER);
gl.shaderSource(
this.fragmentShader,
`
precision highp float;
varying vec3 vWPosition, vPosition, vNormal, vColor;
const vec3 lightPos = vec3(0.0, 0.0, -2.5);
const vec3 lightColor = vec3(1.3, 1.3, 0.9);
const vec3 ambientFar = vec3(0.05, 0.1, 0.6);