Skip to content

Commit df55df1

Browse files
author
Luigi De Rosa
committed
Add basic lighning and fix meta viewport
1 parent fe7be6c commit df55df1

File tree

5 files changed

+24
-10
lines changed

5 files changed

+24
-10
lines changed

package-lock.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
"orbit-controls-es6": "^2.0.0",
3131
"parcel-bundler": "^1.12.3",
3232
"resource-loader": "^2.2.4",
33-
"three": "^0.104.0"
33+
"three": "^0.105.1"
3434
},
3535
"dependencies": {}
3636
}

src/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<html>
22
<head>
33
<title>Developers in Vicenza</title>
4+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
45
<style>
56
html, body {
67
margin: 0;

src/js/cube/cube.frag

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ uniform vec3 color; // ms({ value: '#ff0000' })
55
uniform float xAlpha; // ms({ value: 0, step: 0.01, range: [0, 1] })
66

77
varying vec2 vUv;
8-
varying float vDelay;
8+
varying vec3 vNormal;
9+
// varying float vDelay;
910

1011
void main(){
1112
// float alpha = step(xAlpha, vUv.x);
@@ -19,6 +20,11 @@ void main(){
1920
if (vUv.x > xAlpha){
2021
discard;
2122
}
23+
24+
vec3 L = vec3(0.4);
25+
float force = max(dot(normalize(vNormal),L), 0.0);
26+
27+
color *= smoothstep(-0.8, 1.0, force);
2228

2329
gl_FragColor = vec4(color, 1.);
2430
}

src/js/cube/cube.vert

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,20 @@ precision highp float;
33
attribute vec3 position;
44
attribute vec3 offset;
55
attribute vec2 uv;
6-
attribute float delay;
6+
attribute vec3 normal;
7+
// attribute float delay;
78

89
uniform mat4 modelViewMatrix;
910
uniform mat4 projectionMatrix;
11+
uniform mat3 normalMatrix;
1012
uniform float uSpeed; // ms({ value: 0.0, step: 0.001, range: [-10, 10] })
1113
uniform float uForce; // ms({ value: 0.0, step: 0.001, range: [-10, 10] })
1214
uniform float uRotation; // ms({ value: -0.35, step: 0.001, range: [-1, 1] })
1315
uniform float uTime;
1416

1517
varying vec2 vUv;
16-
varying float vDelay;
18+
// varying float vDelay;
19+
varying vec3 vNormal;
1720

1821
mat3 rotateX(float theta){
1922
float c=cos(theta);
@@ -41,16 +44,20 @@ mat3 rotateZ(float theta){
4144
void main(){
4245
vUv=uv;
4346
vUv=clamp(vUv,0.,.999);
44-
vDelay=delay;
47+
// vDelay=delay;
48+
vNormal = normal * normalMatrix;
4549

4650
vec3 pos=position;
4751
vec3 pivot=vec3(0.,0.,0.);
4852

4953
float force=pos.x*uForce;
5054

5155
pos.xyz+=pivot;
52-
pos=pos*rotateX(force+uTime * 3.0);
53-
// vNormal = vNormal * rotateX(-(force + speed));
56+
57+
float angle = force + uTime * 3.0;
58+
59+
pos= pos * rotateX(angle);
60+
vNormal = vNormal * rotateX(-angle);
5461
pos.xyz-=pivot;
5562

5663
// pos=pos*rotateZ(uRotation);

0 commit comments

Comments
 (0)