Skip to content
This repository was archived by the owner on Jan 24, 2020. It is now read-only.

Commit c58632f

Browse files
author
Avaer Kazmer
committed
Add room grid
1 parent 9aff891 commit c58632f

File tree

1 file changed

+58
-3
lines changed

1 file changed

+58
-3
lines changed

index.html

Lines changed: 58 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1612,8 +1612,8 @@
16121612
d = abs(vWorldPos.z - distance2);
16131613
}
16141614
1615-
gl_FragColor = vec4(0.11055276381909548, 0.27638190954773867, 0.4103852596314908, 1.0) * (4.0 - pow(d, 3.0)) * 0.5;
1616-
// gl_FragColor = max(gl_FragColor, vec4(0.2));
1615+
gl_FragColor = vec4(0.11055276381909548, 0.27638190954773867, 0.4103852596314908, 1.0) * (4.0 - pow(d, 3.0)) * 0.5; // 0x42a5f5
1616+
// gl_FragColor = max(gl_FragCoor, vec4(0.2));
16171617
if (gl_FragColor.a >= 1.9) {
16181618
gl_FragColor.rgb *= 3.0;
16191619
} else if (gl_FragColor.a <= 0.1) {
@@ -1622,7 +1622,6 @@
16221622
}
16231623
`;
16241624
const material = new THREE.ShaderMaterial({
1625-
// color: 0x42a5f5,
16261625
uniforms: {
16271626
uTime: {
16281627
type: 'f',
@@ -1638,6 +1637,62 @@
16381637
})();
16391638
scene.add(gridMesh);
16401639

1640+
const roomMesh = (() => {
1641+
const geometry = new THREE.BoxBufferGeometry(16, 8, 16).applyMatrix(new THREE.Matrix4().makeTranslation(0, 8/2, 0));
1642+
const uvs = geometry.attributes.uv.array;
1643+
for (let i = 0; i < uvs.length; i += 2) {
1644+
uvs[i+0] *= 8;
1645+
uvs[i+1] *= 8;
1646+
}
1647+
const roomVsh = `
1648+
// varying vec3 vWorldPos;
1649+
varying vec2 vUv;
1650+
void main() {
1651+
gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.);
1652+
vUv = uv;
1653+
// vWorldPos = abs(position);
1654+
}
1655+
`;
1656+
const roomFsh = `
1657+
// uniform sampler2D uTex;
1658+
uniform vec3 uColor;
1659+
varying vec3 vWorldPos;
1660+
varying vec2 vUv;
1661+
void main() {
1662+
vec2 uv = fract(vUv);
1663+
/* float diff = uv.x;
1664+
diff = min(diff, abs(uv.x - 1.0));
1665+
diff = min(diff, uv.y);
1666+
diff = min(diff, abs(uv.y - 1.0));
1667+
if (diff <= 0.01) { */
1668+
if ((uv.x <= 0.01 || uv.x >= 0.99) || (uv.y <= 0.01 || uv.y >= 0.99)) {
1669+
// gl_FragColor = vec4(uColor * (1.0 - min(diff/0.02, 1.0)), 0.5);
1670+
gl_FragColor = vec4(uColor, 0.5);
1671+
// } else if (abs(abs(uv.x - 0.5) - abs(uv.y - 0.5)) <= 0.01) {
1672+
} else if (abs(uv.x - uv.y) <= 0.01) {
1673+
gl_FragColor = vec4(0.2, 0.2, 0.2, 0.5);
1674+
} else {
1675+
gl_FragColor = vec4(0.1, 0.1, 0.1, 0.5);
1676+
}
1677+
}
1678+
`;
1679+
const material = new THREE.ShaderMaterial({
1680+
uniforms: {
1681+
uColor: {
1682+
type: 'c',
1683+
value: new THREE.Color(0xffee58),
1684+
},
1685+
},
1686+
vertexShader: roomVsh,
1687+
fragmentShader: roomFsh,
1688+
side: THREE.DoubleSide,
1689+
transparent: true,
1690+
});
1691+
const mesh = new THREE.Mesh(geometry, material);
1692+
return mesh;
1693+
})();
1694+
scene.add(roomMesh);
1695+
16411696
// rig
16421697

16431698
let focusedTab = null;

0 commit comments

Comments
 (0)