Skip to content

Commit a617883

Browse files
committed
feat: sky
1 parent 6a60f6c commit a617883

File tree

11 files changed

+501
-202
lines changed

11 files changed

+501
-202
lines changed

client/App.svelte

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
<script lang="ts">
22
import QS from 'query-string';
33
4-
import { WORLD_LIST } from '../shared';
5-
64
import Button from './components/button.svelte';
75
import { Engine } from './core';
86
import { Helper } from './utils';
@@ -34,6 +32,7 @@
3432
return await response.json();
3533
})();
3634
}
35+
3736
</script>
3837

3938
<main>
@@ -42,7 +41,7 @@
4241
<img src="https://i.imgur.com/ro6oLCL.png" id="crosshair" alt="+" />
4342
{#if !locked}
4443
<div id="pause-menu">
45-
<div on:click={() => engine.lock()} />
44+
<div />
4645
<h2>Game menu</h2>
4746
<Button on:click={() => engine.lock()}>Back to Game</Button>
4847
<Button on:click={() => (window.location.href = window.location.href.split('?')[0])}>Quit to Title</Button>
@@ -195,4 +194,5 @@
195194
.selected {
196195
border-color: rgba(173, 173, 173, 0.74) !important;
197196
}
197+
198198
</style>

client/core/debug.ts

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,19 @@ import { Helper } from '../utils';
77

88
import { Engine } from '.';
99

10+
type FormatterType = (input: any) => string;
11+
1012
class Debug {
1113
public gui: dat.GUI;
1214
public stats: Stats;
1315
public dataWrapper: HTMLDivElement;
14-
public dataEntires: { ele: HTMLParagraphElement; obj: any; attribute: string; name: string }[] = [];
16+
public dataEntries: {
17+
ele: HTMLParagraphElement;
18+
obj: any;
19+
attribute: string;
20+
name: string;
21+
formatter: FormatterType;
22+
}[] = [];
1523
public chunkHighlight: Mesh;
1624
public atlasTest: Mesh;
1725

@@ -131,23 +139,14 @@ class Debug {
131139
})
132140
.name('Render radius');
133141
worldFolder.add(world.options, 'requestRadius', 1, 20, 1).name('Request radius');
134-
worldFolder.add(world.uSunlightIntensity, 'value', 0, 1, 0.01).name('Sunlight intensity');
135-
136-
worldFolder
137-
.add(world.sky.options, 'domeOffset', 200, 2000, 10)
138-
.onChange((value) => (world.sky.shadingMaterial.uniforms.offset.value = value))
139-
.name('Done offset');
140-
worldFolder.add(world.sky.boxMesh.rotation, 'x', 0, Math.PI * 2, 0.01).name('Sky box rotation');
141-
worldFolder
142-
.addColor(world.sky.options, 'topColor')
143-
.onChange((value) => world.sky.setTopColor(value))
144-
.name('Top color');
145142
worldFolder
146-
.addColor(world.sky.options, 'bottomColor')
147-
.onChange((value) => world.sky.setBottomColor(value))
148-
.name('Bottom color');
143+
.add(world.sky.tracker, 'time', 0, 2400, 10)
144+
.onChange((value) => world.sky.setTime(value))
145+
.name('Time value');
146+
worldFolder.add(world.sky.tracker, 'speed', 0, 20, 0.01).name('Time speed');
149147

150148
this.registerDisplay('chunk', world, 'camChunkPosStr');
149+
this.registerDisplay('time', world.sky.tracker, 'time', (num) => num.toFixed(0));
151150

152151
// PLAYER
153152
const playerFolder = this.gui.addFolder('Player');
@@ -192,9 +191,9 @@ class Debug {
192191
};
193192

194193
tick = () => {
195-
for (const { ele, name, attribute, obj } of this.dataEntires) {
194+
for (const { ele, name, attribute, obj, formatter } of this.dataEntries) {
196195
const newValue = obj[attribute];
197-
ele.innerHTML = `${name}: ${newValue}`;
196+
ele.innerHTML = `${name}: ${formatter(newValue)}`;
198197
}
199198

200199
const { camChunkPosStr } = this.engine.world;
@@ -207,15 +206,16 @@ class Debug {
207206
);
208207
};
209208

210-
registerDisplay(name: string, object: any, attribute: string) {
209+
registerDisplay(name: string, object: any, attribute: string, formatter: FormatterType = (str) => str) {
211210
const wrapper = this.makeDataEntry();
212211
const newEntry = {
213212
ele: wrapper,
214213
obj: object,
215214
name,
215+
formatter,
216216
attribute,
217217
};
218-
this.dataEntires.push(newEntry);
218+
this.dataEntries.push(newEntry);
219219
this.dataWrapper.appendChild(wrapper);
220220
}
221221
}

client/core/rendering.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ class Rendering extends EventEmitter {
3232
public composer: EffectComposer;
3333
public fxaa: ShaderPass;
3434
public noColorMateria;
35+
public fogNearColor: Color;
36+
public fogFarColor: Color;
3537
public fogUniforms: { [key: string]: { value: number | Color } };
3638

3739
constructor(public engine: Engine, public options: RenderingOptionsType) {
@@ -71,9 +73,11 @@ class Rendering extends EventEmitter {
7173

7274
// fog
7375
const { renderRadius, chunkSize, dimension } = this.engine.config.world;
76+
this.fogNearColor = new Color(fogNearColor);
77+
this.fogFarColor = new Color(fogColor);
7478
this.fogUniforms = {
75-
uFogColor: { value: new Color(fogColor) },
76-
uFogNearColor: { value: new Color(fogNearColor) },
79+
uFogColor: { value: this.fogNearColor },
80+
uFogNearColor: { value: this.fogFarColor },
7781
uFogNear: { value: renderRadius * 0.5 * chunkSize * dimension },
7882
uFogFar: { value: renderRadius * chunkSize * dimension },
7983
};

client/core/world.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ class World extends EventEmitter {
4141

4242
this.sky = new Sky(engine.rendering);
4343
this.clouds = new Clouds(engine.rendering);
44+
45+
engine.on('ready', () => {
46+
this.setRenderRadius(Math.max(window.navigator.hardwareConcurrency, 6));
47+
});
4448
}
4549

4650
tick() {
@@ -323,7 +327,7 @@ class World extends EventEmitter {
323327

324328
private animateSky() {
325329
const { delta } = this.engine.clock;
326-
this.sky.tick(delta);
330+
this.sky.tick();
327331
this.clouds.tick(delta);
328332
}
329333
}

client/libs/clouds.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ const defaultCloudsOptions: CloudsOptionsType = {
5050
lerpFactor: 0.6,
5151
fogFarFactor: 3,
5252
color: '#eee',
53-
alpha: 0.6,
53+
alpha: 0.8,
5454
};
5555

5656
class Clouds {
@@ -110,12 +110,13 @@ class Clouds {
110110
tick = (delta: number) => {
111111
if (!this.initialized) return;
112112

113-
const { speed, lerpFactor, width, count, dimensions } = this.options;
113+
const { speed } = this.rendering.engine.world.sky.tracker;
114+
const { lerpFactor, width, count, dimensions } = this.options;
114115

115116
this.meshes.forEach((mesh) => {
116117
const newPosition = mesh.position.clone();
117118

118-
newPosition.z -= speed * delta;
119+
newPosition.z -= speed * delta * 400;
119120
mesh.position.lerp(newPosition, lerpFactor);
120121

121122
if (mesh.position.z <= -(width * count * dimensions[2]) / 2) {

client/libs/shaders/clouds/fragment.glsl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,4 @@ void main() {
2727
float depth = gl_FragCoord.z / gl_FragCoord.w;
2828
float fogFactor = smoothstep(uFogNear, uFogFar, depth);
2929
gl_FragColor.rgb = mix(gl_FragColor.rgb, mix(uFogNearColor, uFogColor, fogFactor), fogFactor);
30-
3130
}

0 commit comments

Comments
 (0)