Skip to content

Commit ba2092b

Browse files
committed
Introduce shaders to improve rendering, add night and rework the ui
1 parent a0ae675 commit ba2092b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+1660
-606
lines changed

BlueMapCore/src/main/java/de/bluecolored/bluemap/core/render/hires/blockmodel/LiquidModelBuilder.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,11 @@ private void createElementFace(ExtendedModel model, Direction faceDir, Vector3f
216216
float blockLight = bl.getBlockLightLevel();
217217
float sunLight = bl.getSunLightLevel();
218218

219+
if (faceDir == Direction.UP) {
220+
blockLight = block.getBlockLightLevel();
221+
sunLight = block.getSunLightLevel();
222+
}
223+
219224
f1.setC1(color);
220225
f1.setC2(color);
221226
f1.setC3(color);
Lines changed: 12 additions & 0 deletions
Loading
Lines changed: 13 additions & 0 deletions
Loading
-4.43 KB
Binary file not shown.
-4.5 KB
Binary file not shown.
-4.5 KB
Binary file not shown.
-4.5 KB
Binary file not shown.
-4.43 KB
Binary file not shown.
-4.5 KB
Binary file not shown.

BlueMapCore/src/main/webroot/js/libs/BlueMap.js

Lines changed: 51 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -24,31 +24,24 @@
2424
*/
2525
import $ from 'jquery';
2626
import {
27-
AmbientLight,
2827
BackSide,
2928
BufferGeometryLoader,
3029
ClampToEdgeWrapping,
31-
CubeGeometry,
32-
DirectionalLight,
30+
SphereGeometry,
3331
FileLoader,
3432
FrontSide,
3533
Mesh,
36-
MeshBasicMaterial,
3734
NearestFilter,
38-
NearestMipmapLinearFilter,
35+
NearestMipMapLinearFilter,
3936
PerspectiveCamera,
4037
Scene,
38+
ShaderMaterial,
4139
Texture,
42-
TextureLoader,
4340
VertexColors,
44-
WebGLRenderer, ShaderMaterial,
41+
WebGLRenderer,
4542
} from 'three';
4643

47-
import Compass from './modules/Compass.js';
48-
import Info from './modules/Info.js';
49-
import MapMenu from './modules/MapMenu.js';
50-
import Position from './modules/Position.js';
51-
import Settings from './modules/Settings.js';
44+
import UI from './ui/UI.js';
5245

5346
import Controls from './Controls.js';
5447
import TileManager from './TileManager.js';
@@ -57,22 +50,29 @@ import HIRES_VERTEX_SHADER from './shaders/HiresVertexShader.js';
5750
import HIRES_FRAGMENT_SHADER from './shaders/HiresFragmentShader.js';
5851
import LOWRES_VERTEX_SHADER from './shaders/LowresVertexShader.js';
5952
import LOWRES_FRAGMENT_SHADER from './shaders/LowresFragmentShader.js';
53+
import SKY_VERTEX_SHADER from './shaders/SkyVertexShader.js';
54+
import SKY_FRAGMENT_SHADER from './shaders/SkyFragmentShader.js';
6055

6156
import { stringToImage, pathFromCoords } from './utils.js';
6257

63-
import SKYBOX_NORTH from '../../assets/skybox/north.png';
64-
import SKYBOX_SOUTH from '../../assets/skybox/south.png';
65-
import SKYBOX_EAST from '../../assets/skybox/east.png';
66-
import SKYBOX_WEST from '../../assets/skybox/west.png';
67-
import SKYBOX_UP from '../../assets/skybox/up.png';
68-
import SKYBOX_DOWN from '../../assets/skybox/down.png';
69-
7058
export default class BlueMap {
7159
constructor(element, dataRoot) {
72-
this.element = element;
60+
this.element = $('<div class="bluemap-container"></div>').appendTo(element)[0];
7361
this.dataRoot = dataRoot;
7462

75-
this.loadingNoticeElement = $('<div id="bluemap-loading" class="box">loading...</div>').appendTo($(this.element));
63+
this.hiresViewDistance = 160;
64+
this.lowresViewDistance = 3200;
65+
this.targetSunLightStrength = 1;
66+
this.sunLightStrength = {
67+
value: this.targetSunLightStrength
68+
};
69+
this.mobSpawnOverlay = {
70+
value: false
71+
};
72+
73+
this.ui = new UI(this);
74+
75+
this.loadingNoticeElement = $('<div>loading...</div>').appendTo($(this.element));
7676
window.onerror = this.onLoadError;
7777

7878
this.fileLoader = new FileLoader();
@@ -88,26 +88,18 @@ export default class BlueMap {
8888
await this.loadHiresMaterial();
8989
await this.loadLowresMaterial();
9090

91-
this.changeMap(this.map);
91+
this.changeMap(this.maps[0]);
9292

93-
this.initModules();
93+
this.ui.load();
9494
this.start();
9595
}).catch(error => {
9696
this.onLoadError(error.toString());
97-
console.error(error);
9897
});
9998
}
10099

101-
initModules() {
102-
this.modules = {};
103-
this.modules.compass = new Compass(this);
104-
this.modules.position = new Position(this);
105-
this.modules.mapMenu = new MapMenu(this);
106-
this.modules.info = new Info(this);
107-
this.modules.settings = new Settings(this);
108-
}
109-
110100
changeMap(map) {
101+
if (this.map === map) return;
102+
111103
if (this.hiresTileManager !== undefined) this.hiresTileManager.close();
112104
if (this.lowresTileManager !== undefined) this.lowresTileManager.close();
113105

@@ -118,16 +110,14 @@ export default class BlueMap {
118110
z: this.settings[this.map]["startPos"]["z"]
119111
};
120112

121-
this.targetSunLightStrength = 1;
122-
123113
this.controls.setTileSize(this.settings[this.map]['hires']['tileSize']);
124114
this.controls.resetPosition();
125115
this.controls.targetPosition.set(startPos.x, this.controls.targetPosition.y, startPos.z);
126116
this.controls.position.copy(this.controls.targetPosition);
127117

128118
this.lowresTileManager = new TileManager(
129119
this,
130-
this.settings[this.map]['lowres']['viewDistance'],
120+
this.lowresViewDistance,
131121
this.loadLowresTile,
132122
this.lowresScene,
133123
this.settings[this.map]['lowres']['tileSize'],
@@ -136,7 +126,7 @@ export default class BlueMap {
136126

137127
this.hiresTileManager = new TileManager(
138128
this,
139-
this.settings[this.map]['hires']['viewDistance'],
129+
this.hiresViewDistance,
140130
this.loadHiresTile,
141131
this.hiresScene,
142132
this.settings[this.map]['hires']['tileSize'],
@@ -233,9 +223,9 @@ export default class BlueMap {
233223
if (this.controls.update()) this.updateFrame = true;
234224

235225
//update lighting
236-
let targetLight = 1;
237-
if (this.camera.position.y < 400){
238-
targetLight = this.targetSunLightStrength;
226+
let targetLight = this.targetSunLightStrength;
227+
if (this.camera.position.y > 400){
228+
targetLight = Math.max(targetLight, 0.5);
239229
}
240230
if (Math.abs(targetLight - this.sunLightStrength.value) > 0.01) {
241231
this.sunLightStrength.value += (targetLight - this.sunLightStrength.value) * 0.1;
@@ -295,7 +285,6 @@ export default class BlueMap {
295285
return sort;
296286
});
297287

298-
this.map = this.maps[0];
299288
resolve();
300289
});
301290
});
@@ -305,11 +294,6 @@ export default class BlueMap {
305294
this.updateFrame = true;
306295
this.quality = 1;
307296

308-
this.targetSunLightStrength = 1;
309-
this.sunLightStrength = {
310-
value: this.targetSunLightStrength
311-
};
312-
313297
this.renderer = new WebGLRenderer({
314298
alpha: true,
315299
antialias: true,
@@ -331,40 +315,22 @@ export default class BlueMap {
331315
this.lowresScene = new Scene();
332316
this.hiresScene = new Scene();
333317

334-
this.element.append(this.renderer.domElement);
318+
$(this.renderer.domElement).addClass("map-canvas").appendTo(this.element);
335319
this.handleContainerResize();
336320

337321
$(window).resize(this.handleContainerResize);
338322
}
339323

340324
createSkybox() {
341-
let geometry = new CubeGeometry(10, 10, 10);
342-
let material = [
343-
new MeshBasicMaterial({
344-
map: new TextureLoader().load(SKYBOX_SOUTH),
345-
side: BackSide
346-
}),
347-
new MeshBasicMaterial({
348-
map: new TextureLoader().load(SKYBOX_NORTH),
349-
side: BackSide
350-
}),
351-
new MeshBasicMaterial({
352-
map: new TextureLoader().load(SKYBOX_UP),
353-
side: BackSide
354-
}),
355-
new MeshBasicMaterial({
356-
map: new TextureLoader().load(SKYBOX_DOWN),
357-
side: BackSide
358-
}),
359-
new MeshBasicMaterial({
360-
map: new TextureLoader().load(SKYBOX_EAST),
361-
side: BackSide
362-
}),
363-
new MeshBasicMaterial({
364-
map: new TextureLoader().load(SKYBOX_WEST),
365-
side: BackSide
366-
})
367-
];
325+
let geometry = new SphereGeometry(10, 10, 10);
326+
let material = new ShaderMaterial({
327+
uniforms: {
328+
sunlightStrength: this.sunLightStrength
329+
},
330+
vertexShader: SKY_VERTEX_SHADER,
331+
fragmentShader: SKY_FRAGMENT_SHADER,
332+
side: BackSide
333+
});
368334
return new Mesh(geometry, material);
369335
}
370336

@@ -385,7 +351,7 @@ export default class BlueMap {
385351
texture.anisotropy = 1;
386352
texture.generateMipmaps = opaque || transparent;
387353
texture.magFilter = NearestFilter;
388-
texture.minFilter = texture.generateMipmaps ? NearestMipmapLinearFilter : NearestFilter;
354+
texture.minFilter = texture.generateMipmaps ? NearestMipMapLinearFilter : NearestFilter;
389355
texture.wrapS = ClampToEdgeWrapping;
390356
texture.wrapT = ClampToEdgeWrapping;
391357
texture.flipY = false;
@@ -397,7 +363,8 @@ export default class BlueMap {
397363
type: 't',
398364
value: texture
399365
},
400-
sunlightStrength: this.sunLightStrength
366+
sunlightStrength: this.sunLightStrength,
367+
mobSpawnOverlay: this.mobSpawnOverlay
401368
};
402369

403370
let material = new ShaderMaterial({
@@ -423,12 +390,10 @@ export default class BlueMap {
423390
}
424391

425392
async loadLowresMaterial() {
426-
let uniforms = {
427-
sunlightStrength: this.sunLightStrength
428-
};
429-
430393
this.lowresMaterial = new ShaderMaterial({
431-
uniforms: uniforms,
394+
uniforms: {
395+
sunlightStrength: this.sunLightStrength
396+
},
432397
vertexShader: LOWRES_VERTEX_SHADER,
433398
fragmentShader: LOWRES_FRAGMENT_SHADER,
434399
transparent: false,
@@ -486,7 +451,7 @@ export default class BlueMap {
486451
this.loadingNoticeElement.remove();
487452

488453
this.toggleAlert(undefined, `
489-
<div style="max-width: 500px">
454+
<div style="max-width: 50rem">
490455
<h1>Error</h1>
491456
<p style="color: red; font-family: monospace">${message}</p>
492457
</div>
@@ -496,14 +461,14 @@ export default class BlueMap {
496461
// ###### UI ######
497462

498463
toggleAlert(id, content) {
499-
let alertBox = $('#alert-box');
464+
let alertBox = $(this.element).find('.alert-box');
500465
if (alertBox.length === 0){
501-
alertBox = $('<div id="alert-box"></div>').appendTo(this.element);
466+
alertBox = $('<div class="alert-box"></div>').appendTo(this.ui.hud);
502467
}
503468

504469
let displayAlert = () => {
505-
let alert = $(`<div class="alert box" data-alert-id="${id}" style="display: none;"><div class="alert-close-button"></div>${content}</div>`).appendTo(alertBox);
506-
alert.find('.alert-close-button').click(() => {
470+
let alert = $(`<div class="alert" data-alert-id="${id}" style="display: none;"><div class="close-button"></div>${content}</div>`).appendTo(alertBox);
471+
alert.find('.close-button').click(() => {
507472
alert.stop().fadeOut(200, () => alert.remove());
508473
});
509474
alert.stop().fadeIn(200);

0 commit comments

Comments
 (0)