commit 3eb560a01ae5fece08d888ad93857d6328b82df2
parent abff0262de87600fb6afed3dce773a1cc78979f6
Author: Martin Kloeckner <mjkloeckner@gmail.com>
Date: Fri, 5 Jul 2024 12:32:53 -0300
fix terrain material not working on Windows
Diffstat:
3 files changed, 16 insertions(+), 6 deletions(-)
diff --git a/tp/src/scene.js b/tp/src/scene.js
@@ -464,12 +464,17 @@ function buildTerrain() {
fragmentShader: fragmentShader,
side: THREE.DoubleSide,
});
- terrainMaterial.needsUpdate = true;
-
terrain = new THREE.Mesh(terrainGeometry, terrainMaterial);
- terrain.position.set(0, amplitudeBottom, 0);
+
+ terrainMaterial.onBeforeRender = (renderer, scene, camera, geometry, terrain) => {
+ let m = terrain.matrixWorld.clone();
+ m = m.transpose().invert();
+ terrain.material.uniforms.worldNormalMatrix.value = m;
+ };
+ terrainMaterial.needsUpdate = true;
scene.add(terrain);
+ terrain.position.set(0, amplitudeBottom, 0);
objects.push(terrain);
console.log('Generating water');
diff --git a/tp/src/standalone/terrain.js b/tp/src/standalone/terrain.js
@@ -301,9 +301,16 @@ function buildScene() {
fragmentShader: fragmentShader,
side: THREE.DoubleSide,
});
+ terrain = new THREE.Mesh(terrainGeometry, terrainMaterial);
+
+ terrainMaterial.onBeforeRender = (renderer, scene, camera, geometry, terrain) => {
+ let m = terrain.matrixWorld.clone();
+ m = m.transpose().invert();
+ terrain.material.uniforms.worldNormalMatrix.value = m;
+ };
terrainMaterial.needsUpdate = true;
+ scene.add(terrain);
- terrain = new THREE.Mesh(terrainGeometry, terrainMaterial);
terrain.position.set(0, amplitudeBottom, 0);
scene.add(terrain);
diff --git a/tp/src/terrain.js b/tp/src/terrain.js
@@ -1,8 +1,6 @@
import * as THREE from 'three';
import { vertexShader, fragmentShader } from '/assets/shaders.js';
-let terrainMaterial, terrainGeometry, terrain;
-
const widthSegments = 100;
const heightSegments = 100;
const amplitude = 8;