Skip to content

Commit 7c8e010

Browse files
committed
fix(terrain): revert shader shadow-chunk injection (broke compilation, terrain disappeared)
The <shadowmap_pars_*> + <lights_pars_begin> chunks combined with custom ShaderMaterial caused shader compile failure on the live build, hiding all terrain geometry. Reverted both shader and material to pre-shadow state. Player shadow on terrain remains a TODO and needs a different approach (likely EffectComposer or a fully custom shadow sample without chunk-include side effects).
1 parent 8883536 commit 7c8e010

2 files changed

Lines changed: 14 additions & 30 deletions

File tree

client/TerrainMaterial.js

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,23 +25,21 @@ export const TERRAIN_DEFAULTS = {
2525
}
2626

2727
export function createTerrainMaterial(sceneConfig) {
28-
const customUniforms = {
29-
sunDir: { value: new THREE.Vector3(21, 50, 20).normalize() },
30-
sunColor: { value: new THREE.Color(sceneConfig?.sunColor ?? 0xffffff) },
31-
sunIntensity: { value: sceneConfig?.sunIntensity ?? 1.5 },
32-
ambientColor: { value: new THREE.Color(sceneConfig?.ambientColor ?? 0xfff4d6) },
33-
ambientIntensity: { value: sceneConfig?.ambientIntensity ?? 0.3 },
34-
fogColor: { value: new THREE.Color(sceneConfig?.fogColor ?? 0x87ceeb) },
35-
fogNear: { value: sceneConfig?.fogNear ?? 80 },
36-
fogFar: { value: sceneConfig?.fogFar ?? 200 },
37-
waterline: { value: sceneConfig?.waterline ?? 0 },
38-
waterlineBand: { value: sceneConfig?.waterlineBand ?? 6 },
39-
heightScale: { value: sceneConfig?._heightScale ?? 2.8 },
40-
}
4128
return new THREE.ShaderMaterial({
4229
vertexShader: VERT_SHADER,
4330
fragmentShader: FRAG_SHADER,
44-
uniforms: THREE.UniformsUtils.merge([THREE.UniformsLib.common, THREE.UniformsLib.lights, customUniforms]),
45-
lights: true,
31+
uniforms: {
32+
sunDir: { value: new THREE.Vector3(21, 50, 20).normalize() },
33+
sunColor: { value: new THREE.Color(sceneConfig?.sunColor ?? 0xffffff) },
34+
sunIntensity: { value: sceneConfig?.sunIntensity ?? 1.5 },
35+
ambientColor: { value: new THREE.Color(sceneConfig?.ambientColor ?? 0xfff4d6) },
36+
ambientIntensity: { value: sceneConfig?.ambientIntensity ?? 0.3 },
37+
fogColor: { value: new THREE.Color(sceneConfig?.fogColor ?? 0x87ceeb) },
38+
fogNear: { value: sceneConfig?.fogNear ?? 80 },
39+
fogFar: { value: sceneConfig?.fogFar ?? 200 },
40+
waterline: { value: sceneConfig?.waterline ?? 0 },
41+
waterlineBand: { value: sceneConfig?.waterlineBand ?? 6 },
42+
heightScale: { value: sceneConfig?._heightScale ?? 2.8 },
43+
},
4644
})
4745
}

client/TerrainShaders.js

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
export const VERT_SHADER = `
2-
#include <common>
3-
#include <shadowmap_pars_vertex>
42
attribute vec3 vColor;
53
attribute float water;
64
varying vec3 v_Color;
@@ -17,17 +15,10 @@ void main() {
1715
vec4 mvPos = modelViewMatrix * vec4(position, 1.0);
1816
vViewPosition = -mvPos.xyz;
1917
gl_Position = projectionMatrix * mvPos;
20-
vec4 worldPosition = vec4(v_Position, 1.0);
21-
vec3 transformedNormal = normalize(normalMatrix * normal);
22-
#include <shadowmap_vertex>
2318
}
2419
`
2520

2621
export const FRAG_SHADER = `
27-
#include <common>
28-
#include <packing>
29-
#include <lights_pars_begin>
30-
#include <shadowmap_pars_fragment>
3122
varying vec3 v_Color;
3223
varying float v_Water;
3324
varying vec3 v_Position;
@@ -100,13 +91,8 @@ void main() {
10091
10192
vec3 N = normalize(v_Normal);
10293
float diff = max(dot(N, normalize(sunDir)), 0.0);
103-
float shadow = 1.0;
104-
#if NUM_DIR_LIGHT_SHADOWS > 0
105-
DirectionalLightShadow ds = directionalLightShadows[0];
106-
shadow = getShadow(directionalShadowMap[0], ds.shadowMapSize, ds.shadowBias, ds.shadowRadius, vDirectionalShadowCoord[0]);
107-
#endif
10894
vec3 ambient = ambientColor * ambientIntensity;
109-
vec3 diffuse = sunColor * sunIntensity * diff * shadow;
95+
vec3 diffuse = sunColor * sunIntensity * diff;
11096
vec3 color = albedo * (ambient + diffuse);
11197
11298
float dist = length(vViewPosition);

0 commit comments

Comments
 (0)