Working ambient light in Abgabe 4

This commit is contained in:
Julian Brammer 2023-12-07 15:38:00 +01:00
parent ff748e7326
commit 97888b6a17
4 changed files with 15 additions and 8 deletions

Binary file not shown.

View File

@ -74,7 +74,7 @@ class Object3D {
}
}
asd;
class Island extends Object3D {
constructor() {
// DONE: Setze Material für Insel

View File

@ -4,8 +4,7 @@
<meta charset="utf-8" />
<title>WebGL Example</title>
<script id="vertex-shader" type="x-shader/x-vertex">
#version 300 es
<script id="vertex-shader" type="x-shader/x-vertex">#version 300 es
in vec4 vPosition;
// TODO: Nimm Normalen als Attribut entgegen
@ -20,6 +19,10 @@
// TODO: Nimm alle Koeffizienten und Intensitäten, sowie den Exponenten als Uniform-Variablen entgegen
uniform vec3 Ia;
uniform vec3 ka;
uniform vec3 Id;
uniform vec3 kd;
uniform vec3 Is;
uniform vec3 ks;
uniform float specExp;
// TODO: Definiere alle Konstanten c_1, c_2, c_3
@ -62,8 +65,7 @@
gl_Position = projectionMatrix * position;
}
</script>
<script id="fragment-shader" type="x-shader/x-fragment">
#version 300 es
<script id="fragment-shader" type="x-shader/x-fragment">#version 300 es
precision mediump float;
in vec3 vfColor;

View File

@ -47,12 +47,12 @@ function main() {
normalLoc = gl.getAttribLocation(program, "vNormal");
lightPositionLoc = gl.getUniformLocation(program, "lightPosition");
IaLoc = gl.getUniformLocation(program, "Ia");
IdLoc = gl.getUniformLocation(program, "Id");
IsLoc = gl.getUniformLocation(program, "Is");
kaLoc = gl.getUniformLocation(program, "ka");
IdLoc = gl.getUniformLocation(program, "Id");
kdLoc = gl.getUniformLocation(program, "kd");
IsLoc = gl.getUniformLocation(program, "Is");
ksLoc = gl.getUniformLocation(program, "ks");
specularExponentLoc = gl.getUniformLocation(program, "specExp");
specularExpLoc = gl.getUniformLocation(program, "specExp");
eye = vec3.fromValues(0.0, 0.3, 4.0);
target = vec3.fromValues(0.0, 0.3, 0.0);
@ -69,6 +69,11 @@ function main() {
gl.uniform3fv(IdLoc, [0.8, 0.8, 0.8]);
gl.uniform3fv(IsLoc, [0.7, 0.7, 0.7]);
gl.uniform3fv(kaLoc, [0.5, 0.5, 0.5]);
gl.uniform3fv(kdLoc, [0.5, 0.5, 0.5]);
gl.uniform3fv(ksLoc, [0.5, 0.5, 0.5]);
document.addEventListener("keydown", keydown);
document.addEventListener("keyup", keyup);
document.addEventListener("mousemove", changeView);