Skip to content

Commit 5baf147

Browse files
committed
fog visibility in GUI
1 parent e40057b commit 5baf147

File tree

3 files changed

+29
-12
lines changed

3 files changed

+29
-12
lines changed

src/scripts/Setup.js

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,16 +65,27 @@ function Setup (game) {
6565
game.params = {
6666
chunkdist: 4
6767
}
68-
game.distanceBasedFog.farnear.x = (game.params.chunkdist - 2) * 16
69-
game.distanceBasedFog.farnear.y = (game.params.chunkdist - 1) * 16
70-
gui.add(game.world.material, 'wireframe').name('Wireframe').listen()
68+
game.distanceBasedFog.updateDistance(game.params.chunkdist)
69+
gui
70+
.add(game.world.material, 'wireframe')
71+
.name('Wireframe')
72+
.listen()
7173
gui
7274
.add(game.params, 'chunkdist', 2, 10, 1)
7375
.name('Render distance')
7476
.onChange(function (val) {
75-
game.distanceBasedFog.farnear.x = (val - 2) * 16
76-
game.distanceBasedFog.farnear.y = (val - 1) * 16
77-
console.log(val)
77+
game.distanceBasedFog.updateDistance(val)
78+
})
79+
.listen()
80+
gui
81+
.add(game.distanceBasedFog, 'visible')
82+
.name('Enable fog')
83+
.onChange(function (val) {
84+
if (val) {
85+
game.distanceBasedFog.updateDistance(game.params.chunkdist)
86+
} else {
87+
game.distanceBasedFog.updateDistance(1000)
88+
}
7889
})
7990
.listen()
8091
game.eh = new EventHandler(game)

src/scripts/rendering/DistanceBasedFog.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ class DistanceBasedFog {
66
this.view = new Vector3()
77
this.farnear = new Vector2()
88
this.color = new Vector4()
9+
this.visible = true
10+
}
11+
12+
updateDistance (val) {
13+
this.farnear.x = (val - 2) * 16
14+
this.farnear.y = (val - 1) * 16
915
}
1016

1117
update () {

src/scripts/world/ChunkMesher.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -259,12 +259,12 @@ class ChunkMesher {
259259
}
260260

261261
aoColor (type) {
262-
const num = ({
263-
0: 0.7,
264-
1: 0.5,
265-
2: 0.3,
266-
3: 0.1
267-
})[type]
262+
const num = ({
263+
0: 0.9,
264+
1: 0.7,
265+
2: 0.5,
266+
3: 0.3
267+
})[type]
268268
return [num, num, num]
269269
}
270270

0 commit comments

Comments
 (0)