Skip to content

Commit

Permalink
PointLightShadow: Convert to ES6 class
Browse files Browse the repository at this point in the history
  • Loading branch information
mrdoob committed Feb 9, 2021
1 parent bb5cfde commit b9dd2b6
Showing 1 changed file with 57 additions and 60 deletions.
117 changes: 57 additions & 60 deletions src/lights/PointLightShadow.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,67 +4,65 @@ import { Vector2 } from '../math/Vector2.js';
import { Vector3 } from '../math/Vector3.js';
import { Vector4 } from '../math/Vector4.js';

function PointLightShadow() {

LightShadow.call( this, new PerspectiveCamera( 90, 1, 0.5, 500 ) );

this._frameExtents = new Vector2( 4, 2 );

this._viewportCount = 6;

this._viewports = [
// These viewports map a cube-map onto a 2D texture with the
// following orientation:
//
// xzXZ
// y Y
//
// X - Positive x direction
// x - Negative x direction
// Y - Positive y direction
// y - Negative y direction
// Z - Positive z direction
// z - Negative z direction

// positive X
new Vector4( 2, 1, 1, 1 ),
// negative X
new Vector4( 0, 1, 1, 1 ),
// positive Z
new Vector4( 3, 1, 1, 1 ),
// negative Z
new Vector4( 1, 1, 1, 1 ),
// positive Y
new Vector4( 3, 0, 1, 1 ),
// negative Y
new Vector4( 1, 0, 1, 1 )
];

this._cubeDirections = [
new Vector3( 1, 0, 0 ), new Vector3( - 1, 0, 0 ), new Vector3( 0, 0, 1 ),
new Vector3( 0, 0, - 1 ), new Vector3( 0, 1, 0 ), new Vector3( 0, - 1, 0 )
];

this._cubeUps = [
new Vector3( 0, 1, 0 ), new Vector3( 0, 1, 0 ), new Vector3( 0, 1, 0 ),
new Vector3( 0, 1, 0 ), new Vector3( 0, 0, 1 ), new Vector3( 0, 0, - 1 )
];
class PointLightShadow extends LightShadow {

constructor() {

super( new PerspectiveCamera( 90, 1, 0.5, 500 ) );

Object.defineProperty( this, 'isPointLightShadow', { value: true } );

this._frameExtents = new Vector2( 4, 2 );

this._viewportCount = 6;

this._viewports = [
// These viewports map a cube-map onto a 2D texture with the
// following orientation:
//
// xzXZ
// y Y
//
// X - Positive x direction
// x - Negative x direction
// Y - Positive y direction
// y - Negative y direction
// Z - Positive z direction
// z - Negative z direction

// positive X
new Vector4( 2, 1, 1, 1 ),
// negative X
new Vector4( 0, 1, 1, 1 ),
// positive Z
new Vector4( 3, 1, 1, 1 ),
// negative Z
new Vector4( 1, 1, 1, 1 ),
// positive Y
new Vector4( 3, 0, 1, 1 ),
// negative Y
new Vector4( 1, 0, 1, 1 )
];

this._cubeDirections = [
new Vector3( 1, 0, 0 ), new Vector3( - 1, 0, 0 ), new Vector3( 0, 0, 1 ),
new Vector3( 0, 0, - 1 ), new Vector3( 0, 1, 0 ), new Vector3( 0, - 1, 0 )
];

this._cubeUps = [
new Vector3( 0, 1, 0 ), new Vector3( 0, 1, 0 ), new Vector3( 0, 1, 0 ),
new Vector3( 0, 1, 0 ), new Vector3( 0, 0, 1 ), new Vector3( 0, 0, - 1 )
];

}

PointLightShadow.prototype = Object.assign( Object.create( LightShadow.prototype ), {

constructor: PointLightShadow,

isPointLightShadow: true,
}

updateMatrices: function ( light, viewportIndex = 0 ) {
updateMatrices( light, viewportIndex = 0 ) {

const camera = this.camera,
shadowMatrix = this.matrix,
lightPositionWorld = this._lightPositionWorld,
lookTarget = this._lookTarget,
projScreenMatrix = this._projScreenMatrix;
const camera = this.camera;
const shadowMatrix = this.matrix;
const lightPositionWorld = this._lightPositionWorld;
const lookTarget = this._lookTarget;
const projScreenMatrix = this._projScreenMatrix;

lightPositionWorld.setFromMatrixPosition( light.matrixWorld );
camera.position.copy( lightPositionWorld );
Expand All @@ -82,7 +80,6 @@ PointLightShadow.prototype = Object.assign( Object.create( LightShadow.prototype

}

} );

}

export { PointLightShadow };

0 comments on commit b9dd2b6

Please sign in to comment.