代码之家  ›  专栏  ›  技术社区  ›  Waltari

地面阴影看起来不准确和泥泞

  •  5
  • Waltari  · 技术社区  · 6 年前

    我做了一个ThreeJS项目,在那里我动态地用Perlin噪声创建一个基础。代码如下:

    createGround() {
    
    const resolutionX = 100
    const resolutionY = 100
    const actualResolutionX = resolutionX + 1 // plane adds one vertex
    const actualResolutionY = resolutionY + 1
    
    
    const geometryPlane = new THREE.PlaneGeometry(this.sizeX, this.sizeY, resolutionX, resolutionY)
    
    const noise = perlin.generatePerlinNoise(actualResolutionX, actualResolutionY)
    
    let i = 0
    
    for (let x = 0; x < actualResolutionX; x++) {
      for (let y = 0; y < actualResolutionY; y++) {
        let h = noise[i]
        }
    
        geometryPlane.vertices[i].z = h
        i++
      }
    }
    
    geometryPlane.verticesNeedUpdate = true
    geometryPlane.computeFaceNormals()
    
    const materialPlane = new THREE.MeshStandardMaterial({
      color: 0xffff00,
      side: THREE.FrontSide,
      roughness: 1,
      metallness: 0,
    })
    
    const ground = new THREE.Mesh(geometryPlane, materialPlane)
    geometryPlane.computeVertexNormals()
    ground.name = GROUND_NAME
    ground.receiveShadow = true
    scene.add(ground)
    

    }

    我对生成的几何图形很满意,但问题是阴影看起来确实不准确。

    enter image description here

    这是我的灯代码:

    const light = new THREE.DirectionalLight(
      'white',
      1,
    
    )
    light.shadow.mapSize.width = 512 * 12 // default is 512. doesnt do anything
    light.shadow.mapSize.height = 512 * 12 // default is 512
    light.castShadow = true
    light.position.set(100, 100, 100)
    scene.add(light)
    
    light.shadowCameraVisible = true
    

    我的问题是,我如何使地面阴影看起来更准确和定义,并炫耀地面几何?

    其他代码可以在这里找到: https://github.com/Waltari10/workwork

    1 回复  |  直到 6 年前
        1
  •  0
  •   kolenda    6 年前

    考虑到你没有设置任何灯光,这个阴影看起来并没有那么糟糕。

    我想这个渲染会使用一些默认的灯光或者在考虑阴影之前添加的灯光。

    尝试添加一些方向性的光,模拟太阳的方向和颜色,看看它是否有帮助,或者告诉我们更多关于你的照明设置。

    如果已经有任何渲染阴影贴图的灯光,请检查其分辨率,可能需要将其放大。