使PNG图像铸造阴影

发布于 2025-02-10 02:10:13 字数 2226 浏览 1 评论 0原文

我试图让我的乌云在带有地球质地的球体上铸造阴影。

云是比地球球更大的球体上的PNG质地。 IST的目标是实现或多或少逼真的影子铸造。

我在地球材料上使用接收 true castshadow:true在云层材料上。
但是我不确定PNG图像是否可以像我想要的那样投射阴影。

同样,渲染器确实有:

renderer.shadowMapEnabled = true
renderer.shadowMapType = THREE.PCFSoftShadowMap

现在看起来像这样:

这是我的代码:

// Objects
const earthGeometry = new THREE.SphereGeometry(1, 32, 32);
const cloudGeometry = new THREE.SphereGeometry(1.03, 32, 32);


// Materials
const earthMaterial = new THREE.MeshStandardMaterial({
    opacity: .8,
    depthWrite: false,
    map: earthTexture,
    bumpMap: bumpMap,
    bumpScale: .05,
    specMap: specMap,
    specular: new THREE.Color("grey"),
    receiveShadow: true
})

const cloudMaterial = new THREE.MeshStandardMaterial({
    map: cloudTexture,
    transparent: true,
    castShadow: true
})


// Mesh
const earth = new THREE.Mesh(earthGeometry, earthMaterial)
const clouds = new THREE.Mesh(cloudGeometry, cloudMaterial)

scene.add(earth, clouds)


// Lights
const directionalLight = new THREE.DirectionalLight("#ffffff", 1)
directionalLight.position.set(3, 0, 0)
directionalLight.castShadow = true;
directionalLight.shadowDarkness = .3;


scene.add(directionalLight)

const ambientLight = new THREE.AmbientLight("#ffffff", .20)
scene.add(ambientLight)


/**
 * Renderer
 */
const renderer = new THREE.WebGLRenderer({
    canvas: canvas,
    alpha: true
})
renderer.setSize(sizes.width, sizes.height)
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2))
renderer.shadowMapEnabled = true
renderer.shadowMapType = THREE.PCFSoftShadowMap


/**
 * Animate
 */

const clock = new THREE.Clock()

const tick = () => {
    const elapsedTime = clock.getElapsedTime()

    // Update objects
    earth.rotation.y = elapsedTime * 0.02
    clouds.rotation.y = elapsedTime * 0.03

    // Update Orbital Controls
    controls.update()

    // Render
    renderer.render(scene, camera)

    // Call tick again on the next frame
    window.requestAnimationFrame(tick)
}

tick()

i am trying to let my clouds cast a Shadow on a Sphere with an Earth texture.

The clouds are a png texture on a sphere with a bigger radius than the earth Sphere.
The goal ist to achieve a more or less realistic shadow casting.

I am using receiveShadow: true on my earth material and castShadow: true on the clouds Material.

But i am not sure if a png image can cast a shadow like i want it to.

Also the renderer does have:

renderer.shadowMapEnabled = true
renderer.shadowMapType = THREE.PCFSoftShadowMap

Right now it looks like this:
enter image description here

This is my code right now:

// Objects
const earthGeometry = new THREE.SphereGeometry(1, 32, 32);
const cloudGeometry = new THREE.SphereGeometry(1.03, 32, 32);


// Materials
const earthMaterial = new THREE.MeshStandardMaterial({
    opacity: .8,
    depthWrite: false,
    map: earthTexture,
    bumpMap: bumpMap,
    bumpScale: .05,
    specMap: specMap,
    specular: new THREE.Color("grey"),
    receiveShadow: true
})

const cloudMaterial = new THREE.MeshStandardMaterial({
    map: cloudTexture,
    transparent: true,
    castShadow: true
})


// Mesh
const earth = new THREE.Mesh(earthGeometry, earthMaterial)
const clouds = new THREE.Mesh(cloudGeometry, cloudMaterial)

scene.add(earth, clouds)


// Lights
const directionalLight = new THREE.DirectionalLight("#ffffff", 1)
directionalLight.position.set(3, 0, 0)
directionalLight.castShadow = true;
directionalLight.shadowDarkness = .3;


scene.add(directionalLight)

const ambientLight = new THREE.AmbientLight("#ffffff", .20)
scene.add(ambientLight)


/**
 * Renderer
 */
const renderer = new THREE.WebGLRenderer({
    canvas: canvas,
    alpha: true
})
renderer.setSize(sizes.width, sizes.height)
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2))
renderer.shadowMapEnabled = true
renderer.shadowMapType = THREE.PCFSoftShadowMap


/**
 * Animate
 */

const clock = new THREE.Clock()

const tick = () => {
    const elapsedTime = clock.getElapsedTime()

    // Update objects
    earth.rotation.y = elapsedTime * 0.02
    clouds.rotation.y = elapsedTime * 0.03

    // Update Orbital Controls
    controls.update()

    // Render
    renderer.render(scene, camera)

    // Call tick again on the next frame
    window.requestAnimationFrame(tick)
}

tick()

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文