我正在使用 Three.js 將置換貼圖應(yīng)用于一個(gè)簡(jiǎn)單的平面。位移應(yīng)用成功,但光照錯(cuò)誤,好像所有法線都保持不變。結(jié)果是具有正確形狀的表面被照亮,就好像它是平坦的一樣。置換貼圖:結(jié)果:如何解決此問(wèn)題以正確更改照明?這是相關(guān)的代碼:// shortened from actual code - please excuse any small typosvar renderer = new THREE.WebGLRenderer();renderer.setSize(500, 250);var scene = new THREE.Scene();var light = new THREE.DirectionalLight(0xffffff, 1);light.position.set(100, 100, 100);var ambient = new THREE.AmbientLight(0xffffff, 0.2);scene.add(light);scene.add(ambient);var camera = new THREE.PerspectiveCamera(60, 2, 1, 20000);var geometry = new THREE.PlaneBufferGeometry(100, 100, 1000, 1000);geometry.rotateX(-Math.PI / 2);var material = new THREE.MeshPhongMaterial();var textureLoader = new THREE.TextureLoader();var texture = textureLoader.load('circlemap.png');material.displacementScale = 20;material.displacementMap = texture;var mesh = new THREE.Mesh(geometry, material);scene.add(mesh);// ... laterrenderer.render(scene, camera)
三.js 置換貼圖不影響光照,只影響頂點(diǎn)
ABOUTYOU
2022-10-08 10:16:33