three.js PointLightShadow

2023-02-16 17:43 更新

該類在內(nèi)部由PointLights所使用,以用于計(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 PointLight and turn on shadows for the light
const light = new THREE.PointLight( 0xffffff, 1, 100 );
light.position.set( 0, 10, 4 );
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

//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ù)

PointLightShadow( )

創(chuàng)建一個(gè)新的PointLightShadow。該方法不是直接調(diào)用的 —— 其在內(nèi)部由PointLight調(diào)用。

屬性

共有屬性請參見其基類LightShadow。

.isPointLightShadow : Boolean

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

方法

共有方法請參見其基類LightShadow。

.updateMatrices ( light : Light, viewportIndex : number) : undefined

更新渲染器內(nèi)部使用的相機(jī)和陰影矩陣。light——渲染陰影的光。viewportIndex——計(jì)算此視口的矩陣

源代碼

src/lights/PointLightShadow.js


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

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號