ShaderMaterial fog parameter does not work

前端 未结 2 783
[愿得一人]
[愿得一人] 2020-12-16 07:18

I\'m having troubles enabling scene Fog in THREE.ShaderMaterial. Currently the fog only affects other geometries, but the Skydome that is created using THREE.Sh

2条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-16 07:31

    If you want to use fog with your custom ShaderMaterial, you need to be sure to specify the required fog uniforms. For example,

    var uniforms = {
        topColor:    { type: "c", value: new THREE.Color( 0x0077ff ) },
        bottomColor: { type: "c", value: new THREE.Color( 0xffffff ) },
        offset:      { type: "f", value: 33 },
        exponent:    { type: "f", value: 0.6 },
        fogColor:    { type: "c", value: scene.fog.color },
        fogNear:     { type: "f", value: scene.fog.near },
        fogFar:      { type: "f", value: scene.fog.far }
    }
    
    var skyMat = new THREE.ShaderMaterial( {
        vertexShader: vertexShader,
        fragmentShader: fragmentShader,
        uniforms: uniforms,
        side: THREE.BackSide,
        fog: true
    } );
    

    Also specify fogDensity if you decide to use it. You will also have to incorporate the fog logic into your shader.

    three.js r.59

提交回复
热议问题