Skip to content
Permalink
Browse files

face normals

  • Loading branch information...
sxywu committed Dec 18, 2018
1 parent 3a0e285 commit fbdc2c24e20696941b694d7f4caaeb07aabf2126
Showing with 18 additions and 13 deletions.
  1. +6 −3 assets/shader.frag
  2. +2 −0 assets/shader.vert
  3. +10 −10 components/World.vue
@@ -1,5 +1,6 @@
uniform float colorType;
varying vec2 vUv;
varying vec3 vNormal;
// for noise
#pragma glslify: noise = require('glsl-noise/simplex/3d');
#pragma glslify: hsl2rgb = require('glsl-hsl2rgb');
@@ -12,11 +13,13 @@ void main() {
vec3 color = vec3(0.0);

vec3 pct = vec3(vUv, 1.0);

pct.r = 1.0;
pct.g = sin(vUv.y) * 1.5;
pct.b = sin(vUv.y * 1.0);
// pct.g = sin(vUv.y) * 1.0;
pct.g = sin(vUv.y * 1.2);
pct.b = sin(vUv.y * 1.5);

color = mix(colorA, colorB, pct);
color += vNormal.x * 0.2 + vNormal.y * 0.2 + vNormal.z * 0.1;
gl_FragColor = vec4(color, 1.0);
}
@@ -1,6 +1,8 @@
varying vec2 vUv;
varying vec3 vNormal;

void main() {
vUv = uv;
vNormal = normal;
gl_Position = projectionMatrix * modelViewMatrix * vec4(position.xyz, 1.0);
}
@@ -88,10 +88,15 @@ export default {
},
createMesh: function(numFaces, color) {
const geometry = new THREE.SphereGeometry( 1, numFaces, 4 )
// const material = new THREE.MeshPhongMaterial({
// color: color,
// flatShading: true
// })
// jitter vertices
_.each(geometry.vertices, v => {
v.x += _.random(-0.1, 0.1)
v.y += _.random(-0.1, 0.1)
v.z += _.random(-0.1, 0.1)
})
geometry.computeFlatVertexNormals()
const material = new THREE.ShaderMaterial({
flatShading: true,
vertexShader,
@@ -102,12 +107,7 @@ export default {
},
})
// jitter vertices
_.each(geometry.vertices, v => {
v.x += _.random(-0.1, 0.1)
v.y += _.random(-0.1, 0.1)
v.z += _.random(-0.1, 0.1)
})
return new THREE.Mesh(geometry, material)
}
}

0 comments on commit fbdc2c2

Please sign in to comment.
You can’t perform that action at this time.