Hello. I’m trying to use PlaneBufferGeometry to create terrain chunks by altering vertex positions using a height map. I’d like to do this in the shader so that my scene only needs one geometry for all chunks instead of a unique geometry for each chunk.
I’ve been experimenting with the MeshPhongMaterial displacementMap and normalMap properties to enable this. Ultimately I’d like to use MeshLambertMaterial and patch in similar functionality using onBeforeCompile so it’s more performant but I’ve encountered some problems just with MeshPhongMaterial. I’ve create a test case here: https://codepen.io/kuxazoso/pen/GVYMda?editors=0010
In the test, I’ve created four meshes. The first two are examples of MeshPhongMaterial and MeshLambertMaterial with the vertex positions manually altered by looping over them and adjusting according to the height map you can see at top left. The third mesh is the one I’m currently having problems with.
The displacementMap property works as expected and displaces the vertices as desired. However, the normalMap property is not working. There are two problems. The shadows that are created are very faint, and can only really be noticed when increasing the normalScale parameter, but this results in shadows that are too dark. The perhaps more obvious problem is that the shadows are pixelated rather than smooth like in the CPU displaced examples.
The fourth mesh is my work in progress adding the displacementMap / normalMap properties into MeshLambertMaterial. Like the GPU Phong example, the normal map doesn’t have the desired effect. The shadows of the boxes are also incorrect which is what I was initially working to fix via patching the shader depth material. Obviously I’m not at that stage yet as I haven’t even managed to get the normal maps working for MeshPhongMaterial.
Many thanks for any assistance anyone can provide.