implement fog and improve render quality
This commit is contained in:
@@ -3,10 +3,10 @@ window.Tessellator = class {
|
|||||||
constructor() {
|
constructor() {
|
||||||
this.material = new THREE.MeshBasicMaterial({
|
this.material = new THREE.MeshBasicMaterial({
|
||||||
vertexColors: THREE.VertexColors,
|
vertexColors: THREE.VertexColors,
|
||||||
color: 0xffffff,
|
|
||||||
side: THREE.BackSide,
|
side: THREE.BackSide,
|
||||||
overdraw: 1
|
transparent: true
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bindTexture(texture) {
|
bindTexture(texture) {
|
||||||
@@ -47,7 +47,7 @@ window.Tessellator = class {
|
|||||||
draw(group) {
|
draw(group) {
|
||||||
let geometry = new THREE.BufferGeometry();
|
let geometry = new THREE.BufferGeometry();
|
||||||
geometry.setAttribute('position', new THREE.BufferAttribute(new Float32Array(this.vertices), 3));
|
geometry.setAttribute('position', new THREE.BufferAttribute(new Float32Array(this.vertices), 3));
|
||||||
geometry.addAttribute('color', new THREE.BufferAttribute(new Float32Array(this.colors), 3));
|
geometry.setAttribute('color', new THREE.BufferAttribute(new Float32Array(this.colors), 3));
|
||||||
geometry.setAttribute('uv', new THREE.BufferAttribute(new Float32Array(this.uv), 2));
|
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));
|
geometry.setIndex(new THREE.BufferAttribute(new Uint32Array([0, 2, 1, 0, 3, 2]), 1));
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
window.WorldRenderer = class {
|
window.WorldRenderer = class {
|
||||||
|
|
||||||
|
static RENDER_DISTANCE = 4;
|
||||||
|
|
||||||
constructor(minecraft) {
|
constructor(minecraft) {
|
||||||
this.minecraft = minecraft;
|
this.minecraft = minecraft;
|
||||||
|
|
||||||
@@ -19,10 +21,10 @@ window.WorldRenderer = class {
|
|||||||
this.canvasElement = document.createElement('canvas')
|
this.canvasElement = document.createElement('canvas')
|
||||||
this.webRenderer = this.supportWebGL ? new THREE.WebGLRenderer({
|
this.webRenderer = this.supportWebGL ? new THREE.WebGLRenderer({
|
||||||
canvas: this.canvasElement,
|
canvas: this.canvasElement,
|
||||||
antialias: true
|
antialias: false
|
||||||
}) : new THREE.CanvasRenderer({
|
}) : new THREE.CanvasRenderer({
|
||||||
canvas: this.canvasElement,
|
canvas: this.canvasElement,
|
||||||
antialias: true
|
antialias: false
|
||||||
});
|
});
|
||||||
|
|
||||||
// Settings
|
// Settings
|
||||||
@@ -32,14 +34,10 @@ window.WorldRenderer = class {
|
|||||||
this.webRenderer.setClearColor(0x000000, 0);
|
this.webRenderer.setClearColor(0x000000, 0);
|
||||||
this.webRenderer.clear();
|
this.webRenderer.clear();
|
||||||
|
|
||||||
// Add lights
|
|
||||||
const nightLight = new THREE.AmbientLight(0x888888, 1.0);
|
|
||||||
this.scene.add(nightLight);
|
|
||||||
|
|
||||||
// Load terrain
|
// Load terrain
|
||||||
this.terrainTexture = new THREE.TextureLoader().load( 'src/resources/terrain.png' );
|
this.terrainTexture = new THREE.TextureLoader().load('src/resources/terrain.png');
|
||||||
this.terrainTexture.magFilter = THREE.NearestFilter;
|
this.terrainTexture.magFilter = THREE.NearestFilter;
|
||||||
this.terrainTexture.minFilter = THREE.LinearFilter;
|
this.terrainTexture.minFilter = THREE.NearestFilter;
|
||||||
|
|
||||||
// Block Renderer
|
// Block Renderer
|
||||||
this.blockRenderer = new BlockRenderer(this);
|
this.blockRenderer = new BlockRenderer(this);
|
||||||
@@ -72,6 +70,21 @@ window.WorldRenderer = class {
|
|||||||
// Update FOV
|
// Update FOV
|
||||||
this.camera.fov = 85 + player.getFOVModifier();
|
this.camera.fov = 85 + player.getFOVModifier();
|
||||||
this.camera.updateProjectionMatrix();
|
this.camera.updateProjectionMatrix();
|
||||||
|
|
||||||
|
// Setup fog
|
||||||
|
this.setupFog();
|
||||||
|
}
|
||||||
|
|
||||||
|
setupFog(inWater) {
|
||||||
|
if (inWater) {
|
||||||
|
|
||||||
|
} else {
|
||||||
|
let viewDistance = WorldRenderer.RENDER_DISTANCE * ChunkSection.SIZE;
|
||||||
|
|
||||||
|
let color = new THREE.Color(0x9299ff);
|
||||||
|
this.scene.background = color;
|
||||||
|
this.scene.fog = new THREE.Fog(color, 0.0025, viewDistance);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
renderChunks(renderer, partialTicks) {
|
renderChunks(renderer, partialTicks) {
|
||||||
|
|||||||
Reference in New Issue
Block a user