From fa72bdc92a02fa0bf6a8326cd976a839d16c1bfa Mon Sep 17 00:00:00 2001 From: Evert Prants Date: Tue, 31 Dec 2019 21:36:25 +0200 Subject: [PATCH] Reduce environment lights for older gles, invert camera x axis --- assets/shaders/terrain.fs | 8 ++++---- assets/shaders/terrain.vs | 6 +++--- src/engine/camera.js | 2 +- src/engine/environment.js | 2 +- src/engine/screen.js | 2 +- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/assets/shaders/terrain.fs b/assets/shaders/terrain.fs index 18ba9aa..0b82eb5 100644 --- a/assets/shaders/terrain.fs +++ b/assets/shaders/terrain.fs @@ -1,13 +1,13 @@ precision highp float; varying vec2 uv; -varying vec3 toLightVector[8]; +varying vec3 toLightVector[5]; varying vec3 surfaceNormal; varying vec3 toCameraVector; uniform sampler2D texture0; -uniform vec3 lightColor[8]; -uniform vec3 attenuation[8]; +uniform vec3 lightColor[5]; +uniform vec3 attenuation[5]; void main() { float reflectivity = 0.0; @@ -19,7 +19,7 @@ void main() { vec3 totalDiffuse = vec3(0.0); vec3 totalSpecular = vec3(0.0); - for(int i=0;i<8;i++){ + for(int i=0;i<5;i++){ float distance = length(toLightVector[i]); float attFactor = attenuation[i].x + (attenuation[i].y * distance) + (attenuation[i].z * distance * distance); vec3 unitLightVector = normalize(toLightVector[i]); diff --git a/assets/shaders/terrain.vs b/assets/shaders/terrain.vs index 226155d..32d5b08 100644 --- a/assets/shaders/terrain.vs +++ b/assets/shaders/terrain.vs @@ -7,10 +7,10 @@ attribute vec2 aTexCoords; uniform mat4 uModelMatrix; uniform mat4 uViewMatrix; uniform mat4 uProjectionMatrix; -uniform vec3 lightPosition[8]; +uniform vec3 lightPosition[5]; varying vec2 uv; -varying vec3 toLightVector[8]; +varying vec3 toLightVector[5]; varying vec3 surfaceNormal; varying vec3 toCameraVector; @@ -60,7 +60,7 @@ void main() { gl_Position = uProjectionMatrix * uViewMatrix * worldPosition; uv = aTexCoords; surfaceNormal = (uModelMatrix * vec4(aNormal,0.0)).xyz; - for(int i=0;i<8;i++){ + for(int i=0;i<5;i++){ toLightVector[i] = lightPosition[i] - worldPosition.xyz; } toCameraVector = (inverse(uViewMatrix) * vec4(0.0,0.0,0.0,1.0)).xyz - worldPosition.xyz; diff --git a/src/engine/camera.js b/src/engine/camera.js index 97a83af..b0da3db 100644 --- a/src/engine/camera.js +++ b/src/engine/camera.js @@ -57,7 +57,7 @@ class Camera extends Node { } processMouseMove (offset, constrain = true) { - let fst = vec2.fromValues(offset.x * this.sensitivity, offset.y * this.sensitivity) + let fst = vec2.fromValues(offset.x * -this.sensitivity, offset.y * this.sensitivity) this.rotation[0] += glMatrix.toRadian(fst[0]) this.rotation[1] += glMatrix.toRadian(fst[1]) diff --git a/src/engine/environment.js b/src/engine/environment.js index b92eabe..54f6e26 100644 --- a/src/engine/environment.js +++ b/src/engine/environment.js @@ -1,5 +1,5 @@ -const ENV_MAX_LIGHTS = 8 +const ENV_MAX_LIGHTS = 5 class Light { constructor (pos, color, attenuation = [1.0, 0.0, 0.0]) { diff --git a/src/engine/screen.js b/src/engine/screen.js index 4928241..14adc24 100644 --- a/src/engine/screen.js +++ b/src/engine/screen.js @@ -29,7 +29,7 @@ class Screen { } loadExtensions () { - this._gl.drawBuffers = this._gl.getExtension('WEBGL_draw_buffers') + // this._gl.drawBuffers = this._gl.getExtension('WEBGL_draw_buffers') this._gl.getExtension('WEBGL_depth_texture') this._gl.getExtension('OES_texture_float') }