From 6eaf11cc02e841d7d7b896a9577bf59315e2490a Mon Sep 17 00:00:00 2001 From: Evert Prants Date: Tue, 31 Dec 2019 22:09:10 +0200 Subject: [PATCH] Reduce environment lights for older gles even further --- assets/shaders/terrain.fs | 8 ++++---- assets/shaders/terrain.vs | 6 +++--- src/engine/environment.js | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/assets/shaders/terrain.fs b/assets/shaders/terrain.fs index 0b82eb5..da14641 100644 --- a/assets/shaders/terrain.fs +++ b/assets/shaders/terrain.fs @@ -1,13 +1,13 @@ precision highp float; varying vec2 uv; -varying vec3 toLightVector[5]; +varying vec3 toLightVector[4]; varying vec3 surfaceNormal; varying vec3 toCameraVector; uniform sampler2D texture0; -uniform vec3 lightColor[5]; -uniform vec3 attenuation[5]; +uniform vec3 lightColor[4]; +uniform vec3 attenuation[4]; 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<5;i++){ + for(int i=0;i<4;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 32d5b08..6521967 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[5]; +uniform vec3 lightPosition[4]; varying vec2 uv; -varying vec3 toLightVector[5]; +varying vec3 toLightVector[4]; 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<5;i++){ + for(int i=0;i<4;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/environment.js b/src/engine/environment.js index 54f6e26..7c884f0 100644 --- a/src/engine/environment.js +++ b/src/engine/environment.js @@ -1,5 +1,5 @@ -const ENV_MAX_LIGHTS = 5 +const ENV_MAX_LIGHTS = 4 class Light { constructor (pos, color, attenuation = [1.0, 0.0, 0.0]) {