implement shading
This commit is contained in:
@@ -43,13 +43,18 @@ window.BlockRenderer = class {
|
||||
let textureIndex = typeId;
|
||||
let minU = (textureIndex % 16) / 16.0;
|
||||
let maxU = minU + (16 / 256);
|
||||
let minV = parseInt(textureIndex / 16); // TODO Math.round
|
||||
let minV = Math.round(textureIndex / 16);
|
||||
let maxV = minV + (16 / 256);
|
||||
|
||||
// Flip V
|
||||
minV = 1 - minV;
|
||||
maxV = 1 - maxV;
|
||||
|
||||
// Classic lightning
|
||||
let brightness = 0.9 / 15.0 * 15 + 0.1;
|
||||
let color = brightness * face.getShading();
|
||||
this.tessellator.setColor(color, color, color);
|
||||
|
||||
if (face === EnumBlockFace.BOTTOM) {
|
||||
this.addBlockCorner(world, face, minX, minY, maxZ, minU, maxV);
|
||||
this.addBlockCorner(world, face, minX, minY, minZ, minU, minV);
|
||||
|
||||
@@ -2,8 +2,10 @@ window.Tessellator = class {
|
||||
|
||||
constructor() {
|
||||
this.material = new THREE.MeshBasicMaterial({
|
||||
vertexColors: THREE.VertexColors,
|
||||
color: 0xffffff,
|
||||
side: THREE.BackSide
|
||||
side: THREE.BackSide,
|
||||
overdraw: 1
|
||||
});
|
||||
}
|
||||
|
||||
@@ -15,6 +17,13 @@ window.Tessellator = class {
|
||||
this.addedVertices = 0;
|
||||
this.vertices = [];
|
||||
this.uv = [];
|
||||
this.colors = [];
|
||||
}
|
||||
|
||||
setColor(red, green, blue) {
|
||||
this.red = red;
|
||||
this.green = green;
|
||||
this.blue = blue;
|
||||
}
|
||||
|
||||
addVertexWithUV(x, y, z, u, v) {
|
||||
@@ -28,11 +37,17 @@ window.Tessellator = class {
|
||||
// Add UV
|
||||
this.uv.push(u);
|
||||
this.uv.push(v);
|
||||
|
||||
// Add colors
|
||||
this.colors.push(this.red);
|
||||
this.colors.push(this.green);
|
||||
this.colors.push(this.blue);
|
||||
}
|
||||
|
||||
draw(group) {
|
||||
let geometry = new THREE.BufferGeometry();
|
||||
geometry.setAttribute('position', new THREE.BufferAttribute(new Float32Array(this.vertices), 3));
|
||||
geometry.addAttribute('color', new THREE.BufferAttribute(new Float32Array(this.colors), 3));
|
||||
geometry.setAttribute('uv', new THREE.BufferAttribute(new Float32Array(this.uv), 2));
|
||||
geometry.setIndex(new THREE.BufferAttribute(new Uint32Array([0, 2, 1, 0, 3, 2]), 1));
|
||||
|
||||
|
||||
@@ -6,6 +6,22 @@ window.EnumBlockFace = class {
|
||||
this.z = z;
|
||||
}
|
||||
|
||||
getShading() {
|
||||
return this.isXAxis() ? 0.6 : this.isYAxis() ? 1.0 : 0.8;
|
||||
}
|
||||
|
||||
isXAxis() {
|
||||
return this.x !== 0;
|
||||
}
|
||||
|
||||
isYAxis() {
|
||||
return this.y !== 0;
|
||||
}
|
||||
|
||||
isZAxis() {
|
||||
return this.z !== 0;
|
||||
}
|
||||
|
||||
static values() {
|
||||
return [
|
||||
EnumBlockFace.TOP,
|
||||
|
||||
Reference in New Issue
Block a user