0

直接使用 WebGLRenderer 时,背景会自动清除为白色。但是,当使用 EffectComposer 时,背景会被清除为黑色。

这是一个示例:http: //jsfiddle.net/wereHamster/Lt2DX/。场景显示白色背景上的红色立方体。如果您注释掉第 41 行并取消注释第 42 行(启用 EffectComposer),画布将在黑色背景上显示一个红色立方体。

这是代码:

# A simple scene with a red cube in the center.
scene = new THREE.Scene

camera = new THREE.PerspectiveCamera 75, 200/200, 0.01, 1000
camera.position.z = 5
scene.add camera

geometry = new THREE.CubeGeometry 1, 1, 1
material = new THREE.MeshBasicMaterial { color: 0xFF0000 }
scene.add (mesh = new THREE.Mesh geometry, material)


# The barebone WebGL renderer.
renderer = new THREE.WebGLRenderer
renderer.setSize 200, 200
$('body').append renderer.domElement


# Composer with two passes, RenderPass and ShaderPass.
composer   = new THREE.EffectComposer renderer

renderPass = new THREE.RenderPass scene, camera
composer.addPass renderPass

shaderPass = new THREE.ShaderPass THREE.CopyShader
shaderPass.renderToScreen = true
composer.addPass shaderPass


# The main animation loop.
animate = ->
    requestAnimationFrame animate

    mesh.rotation.x += 0.01
    mesh.rotation.y += 0.01


    # If we use the composer to render the scene then the
    # background is black instead of white.

    renderer.render scene, camera
    #composer.render 0.1


animate()
4

1 回答 1

4

THREE.RenderPass有额外的论点

renderPass = new THREE.RenderPass scene, camera, null, new THREE.Color().setHex( 0xffffff ), 0

此外,renderer默认情况下,背景是清晰的,而不是白色的。你看到的是体色透出来。

小提琴:http: //jsfiddle.net/Lt2DX/36/

于 2013-01-21T17:43:36.377 回答