ShadowMapViewer constructor
ShadowMapViewer(
- Light light,
- num innerWidth,
- num innerHeight
)
Implementation
ShadowMapViewer(this.light, this.innerWidth, this.innerHeight) {
//Holds the initial position and dimension of the HUD
frame = {"x": 10, "y": 10, "width": 256, "height": 256};
camera = OrthographicCamera(innerWidth / -2, innerWidth / 2, innerHeight / 2, innerHeight / -2, 1, 10);
camera.position.set(0, 0, 2);
scene = Scene();
// scene.background = Color.fromHex(0xff00ff);
//HUD for shadow map
var shader = unpackDepthRGBAShader;
uniforms = UniformsUtils.clone(shader["uniforms"]);
var material = ShaderMaterial(
{"uniforms": uniforms, "vertexShader": shader["vertexShader"], "fragmentShader": shader["fragmentShader"]});
var plane = PlaneGeometry(frame["width"]!, frame["height"]!);
mesh = Mesh(plane, material);
scene.add(mesh);
//Label for light's name
// var labelCanvas, labelMesh;
// if ( doRenderLabel ) {
// labelCanvas = document.createElement( 'canvas' );
// var context = labelCanvas.getContext( '2d' );
// context.font = 'Bold 20px Arial';
// var labelWidth = context.measureText( light.name ).width;
// labelCanvas.width = labelWidth;
// labelCanvas.height = 25; //25 to account for g, p, etc.
// context.font = 'Bold 20px Arial';
// context.fillStyle = 'rgba( 255, 0, 0, 1 )';
// context.fillText( light.name, 0, 20 );
// var labelTexture = new Texture( labelCanvas );
// labelTexture.magFilter = LinearFilter;
// labelTexture.minFilter = LinearFilter;
// labelTexture.needsUpdate = true;
// var labelMaterial = new MeshBasicMaterial( { map: labelTexture, side: DoubleSide } );
// labelMaterial.transparent = true;
// var labelPlane = new PlaneGeometry( labelCanvas.width, labelCanvas.height );
// labelMesh = new Mesh( labelPlane, labelMaterial );
// scene.add( labelMesh );
// }
// Set the size of the displayed shadow map on the HUD
size = {"width": frame["width"]!, "height": frame["height"]!};
// size = {
// width: frame.width,
// height: frame.height,
// set: function ( width, height ) {
// width = width;
// height = height;
// mesh.scale.set( width / frame.width, height / frame.height, 1 );
// //Reset the position as it is off when we scale stuff
// resetPosition();
// }
// };
// Set the position of the displayed shadow map on the HUD
position = {"x": frame["x"]!, "y": frame["y"]!};
// position = {
// x: frame.x,
// y: frame.y,
// set: function ( x, y ) {
// this.x = x;
// this.y = y;
// var width = scope.size.width;
// var height = scope.size.height;
// mesh.position.set( - window.innerWidth / 2 + width / 2 + this.x, window.innerHeight / 2 - height / 2 - this.y, 0 );
// if ( doRenderLabel ) labelMesh.position.set( mesh.position.x, mesh.position.y - scope.size.height / 2 + labelCanvas.height / 2, 0 );
// }
// };
//Force an update to set position/size
update();
}