Skip to content

Commit 9a7099f

Browse files
committed
fix fog not applying to players
1 parent d7d965d commit 9a7099f

File tree

2 files changed

+6
-17
lines changed

2 files changed

+6
-17
lines changed

src/scripts/DistanceBasedFog.js

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -34,23 +34,10 @@ class DistanceBasedFog {
3434
shader.fragmentShader = shader.fragmentShader.replace(
3535
"gl_FragColor = vec4( outgoingLight, diffuseColor.a );",
3636
[
37-
"float dist=length(u_viewPos-vViewPosition);",
38-
"float fogAmount = smoothstep(u_farnear.x, u_farnear.y, dist);",
39-
"gl_FragColor = vec4( outgoingLight, diffuseColor.a );",
40-
"gl_FragColor = mix(gl_FragColor,u_fogColor,max(0.1,fogAmount));",
41-
].join("\n")
42-
);
43-
shader.vertexShader = [
44-
"uniform float time;",
45-
"uniform mat4 u_worldView;",
46-
"attribute vec4 a_position;",
47-
shader.vertexShader,
48-
].join("\n");
49-
shader.vertexShader = shader.vertexShader.replace(
50-
"#include <fog_vertex>",
51-
[
52-
"vec4 vViewPosition4 = modelViewMatrix * vec4(position, 1);",
53-
"vViewPosition = vViewPosition4.xyz;",
37+
"float dist = length(u_viewPos - vViewPosition);",
38+
"float fogFactor = smoothstep(u_farnear.x, u_farnear.y, dist);",
39+
"gl_FragColor = vec4(outgoingLight, diffuseColor.a );",
40+
"gl_FragColor = mix(gl_FragColor, u_fogColor, max(0.1, fogFactor));",
5441
].join("\n")
5542
);
5643
};

src/scripts/Setup.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ async function Setup(game) {
5757
game.chat = new Chat(game);
5858
game.inv_bar = new InventoryBar(game);
5959
game.distanceBasedFog.addShaderToMaterial(game.world.material);
60+
game.distanceBasedFog.addShaderToMaterial(game.ent.mobMaterial);
61+
game.distanceBasedFog.addShaderToMaterial(game.ent.playerMaterial);
6062
const gui = new dat.GUI();
6163
game.params = {
6264
chunkdist: 3,

0 commit comments

Comments
 (0)