Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
856 views
in Technique[技术] by (71.8m points)

three.js - Weird effect when using receiveShadow

I'm trying to get receiveShadow to work on a cube. Not only it doesn't work, but when I set cube.receiveShadow = true, the light on the cube shows weird dark borders (links to images below).

There's no other object and I've pretty much only have a cube, a plane, and a spotlight in the scene.

    let geometry = new THREE.BoxGeometry(5,5,5);
    let material = new THREE.MeshLambertMaterial({color: 0x11bb22});
    let cube = new THREE.Mesh(geometry, material);
    cube.castShadow = true;
    //cube.receiveShadow = true
    scene.add(cube);

    light = new THREE.SpotLight(0xffffff, 2, 100, Math.PI/4, 0.1, 0);
    light.position.y = 10;
    light.castShadow = true;
    light.shadow.bias = 0.001;
    light.shadow.mapSize.width = 2048;
    light.shadow.mapSize.height = 2048;
    scene.add(light);

    renderer = new THREE.WebGLRenderer();
    renderer.shadowMap.enabled = true;
    renderer.shadowMap.type = THREE.PCFShadowMap;
    renderer.setSize(window.innerWidth, window.innerHeight);
    document.body.appendChild(renderer.domElement);

With castShadow=false
With castShadow=true

Thanks!

question from:https://stackoverflow.com/questions/65845187/weird-effect-when-using-receiveshadow

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Thanks, setting the bias to 0 did the trick. both 0.001 and -0.001 cause weird effects where the shadow does not look realistic.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...