three.js SpotLightShadow

2023-02-16 17:43 更新

這在SpotLights內(nèi)部用于計(jì)算陰影。

代碼示例

//Create a WebGLRenderer and turn on shadows in the renderer
const renderer = new THREE.WebGLRenderer();
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap; // default THREE.PCFShadowMap

//Create a SpotLight and turn on shadows for the light
const light = new THREE.SpotLight( 0xffffff );
light.castShadow = true;            // default false
scene.add( light );

//Set up shadow properties for the light
light.shadow.mapSize.width = 512;  // default
light.shadow.mapSize.height = 512; // default
light.shadow.camera.near = 0.5;    // default
light.shadow.camera.far = 500      // default
light.shadow.focus = 1;            // default

//Create a sphere that cast shadows (but does not receive them)
const sphereGeometry = new THREE.SphereGeometry( 5, 32, 32 );
const sphereMaterial = new THREE.MeshStandardMaterial( { color: 0xff0000 } );
const sphere = new THREE.Mesh( sphereGeometry, sphereMaterial );
sphere.castShadow = true; //default is false
sphere.receiveShadow = false; //default
scene.add( sphere );

//Create a plane that receives shadows (but does not cast them)
const planeGeometry = new THREE.PlaneGeometry( 20, 20, 32, 32 );
const planeMaterial = new THREE.MeshStandardMaterial( { color: 0x00ff00 } )
const plane = new THREE.Mesh( planeGeometry, planeMaterial );
plane.receiveShadow = true;
scene.add( plane );

//Create a helper for the shadow camera (optional)
const helper = new THREE.CameraHelper( light.shadow.camera );
scene.add( helper );

構(gòu)造函數(shù)

構(gòu)造函數(shù)創(chuàng)建一個(gè) PerspectiveCamera : PerspectiveCamera 來(lái)管理陰影的世界視圖

屬性

有關(guān)常用屬性,請(qǐng)參閱基礎(chǔ)LightShadow類。

.camera : Camera

在光的世界里。這用于生成場(chǎng)景的深度圖;從光的角度來(lái)看,其他物體背后的物體將處于陰影中。默認(rèn)值為PerspectiveCamera,近剪裁平面為0.5。 fov將通過(guò)更新方法跟蹤擁有SpotLight的角度屬性。同樣,aspect屬性將跟蹤mapSize的方面。如果設(shè)置了燈光的距離屬性,則遠(yuǎn)剪裁平面將跟蹤該值,否則默認(rèn)為500。

.focus : Number

用于聚焦陰影相機(jī)。相機(jī)的視野設(shè)置為聚光燈視野的百分比。范圍是 [0, 1]。默認(rèn)值為 1.0。

.isSpotLightShadow : Boolean

只讀標(biāo)志,用于檢查給定對(duì)象是否屬于 SpotLightShadow 類型。

方法

有關(guān)常用方法,請(qǐng)參閱基礎(chǔ)LightShadow類。

源碼

src/lights/SpotLightShadow.js


以上內(nèi)容是否對(duì)您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號(hào)
微信公眾號(hào)

編程獅公眾號(hào)