From e60b92397b7efd535bb63585660a245dc414ccdc Mon Sep 17 00:00:00 2001
From: "geoffrey.menetrey" <geoffrey.menetrey@etu.hesge.ch>
Date: Fri, 27 Nov 2020 14:42:32 +0100
Subject: [PATCH] =?UTF-8?q?lumi=C3=A8re=20sp=C3=A9culaire=20calcul=C3=A9?=
 =?UTF-8?q?=20dans=20le=20fragment=20shader?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 lab3/src/debug.log |  1 +
 lab3/src/lab3.js   | 40 +++++++++++++++++++++++++++-------------
 2 files changed, 28 insertions(+), 13 deletions(-)

diff --git a/lab3/src/debug.log b/lab3/src/debug.log
index 15b0c93..813e154 100644
--- a/lab3/src/debug.log
+++ b/lab3/src/debug.log
@@ -1,2 +1,3 @@
 [1120/133929.315:ERROR:directory_reader_win.cc(43)] FindFirstFile: Le chemin d�acc�s sp�cifi� est introuvable. (0x3)
 [1126/175840.510:ERROR:directory_reader_win.cc(43)] FindFirstFile: Le chemin d�acc�s sp�cifi� est introuvable. (0x3)
+[1127/141033.333:ERROR:directory_reader_win.cc(43)] FindFirstFile: Le chemin d�acc�s sp�cifi� est introuvable. (0x3)
diff --git a/lab3/src/lab3.js b/lab3/src/lab3.js
index 2976682..b5b4295 100644
--- a/lab3/src/lab3.js
+++ b/lab3/src/lab3.js
@@ -116,30 +116,44 @@ var VSHADER_SOURCE_PONCTUAL =
 
   'uniform mat4 u_MvpMatrix;\n' +
   'uniform mat4 u_ModelMatrix;\n' +   
-  'uniform mat4 u_NormalMatrix;\n' +
+  'uniform mat4 u_NormalMatrix;\n' + 
 
-  'uniform vec3 u_LightColor;\n' +     
-  'uniform vec3 u_LightPosition;\n' +  
-  'uniform vec3 u_AmbientLight;\n' +  
+  'uniform vec3 u_AmbientLight;\n' + 
+
+  'varying vec3 normal;\n' + 
+  'varying vec4 vertexPosition;\n' + 
+  'varying vec3 ambient;\n' + 
 
   'varying vec4 v_Color;\n' +
+
   'void main() {\n' +
   '  gl_Position = u_MvpMatrix * a_Position;\n' +
-  '  vec3 normal = normalize(vec3(u_NormalMatrix * a_Normal));\n' +
-  '  vec4 vertexPosition = u_ModelMatrix * a_Position;\n' +
-  '  vec3 lightDirection = normalize(u_LightPosition - vec3(vertexPosition));\n' +
-  '  float nDotL = max(dot(normal, lightDirection), 0.0);\n' +
-  '  vec3 diffuse = u_LightColor * a_Color.rgb * nDotL;\n' +
-  '  v_Color = vec4(diffuse, a_Color.a);\n' + 
+  '  normal = normalize(vec3(u_NormalMatrix * a_Normal));\n' +
+  '  vertexPosition = u_ModelMatrix * a_Position;\n' +
+
+  '  ambient = u_AmbientLight * a_Color.xyz;\n' +
+
+  '  v_Color = a_Color;\n' +
   '}\n';
 
 var FSHADER_SOURCE_PONCTUAL =
-  '#ifdef GL_ES\n' +
   'precision mediump float;\n' +
-  '#endif\n' +
+
+  'uniform vec3 u_LightColor;\n' +     
+  'uniform vec3 u_LightPosition;\n' +  
+
   'varying vec4 v_Color;\n' +
+  'varying vec3 normal;\n' + 
+  'varying vec4 vertexPosition;\n' + 
+  'varying vec3 ambient;\n' +
+
   'void main() {\n' +
-  '  gl_FragColor = v_Color;\n' +
+
+  '  vec3 lightDirection = normalize(u_LightPosition - vec3(vertexPosition));\n' +
+  '  float nDotL = max(dot(normal, lightDirection), 0.0);\n' +
+  '  vec3 diffuse = u_LightColor * v_Color.rgb * nDotL;\n' +
+
+  '  gl_FragColor = vec4(diffuse + ambient, v_Color.a);\n' +
   '}\n';
 
 function initElements(){
-- 
GitLab