babylon.pointLight.ts 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. module BABYLON {
  2. export class PointLight extends Light implements IShadowLight {
  3. private _worldMatrix: Matrix;
  4. public transformedPosition: Vector3;
  5. constructor(name: string, public position: Vector3, scene: Scene) {
  6. super(name, scene);
  7. }
  8. public getAbsolutePosition(): Vector3 {
  9. return this.transformedPosition ? this.transformedPosition : this.position;
  10. }
  11. public computeTransformedPosition(): boolean {
  12. if (this.parent && this.parent.getWorldMatrix) {
  13. if (!this.transformedPosition) {
  14. this.transformedPosition = Vector3.Zero();
  15. }
  16. Vector3.TransformCoordinatesToRef(this.position, this.parent.getWorldMatrix(), this.transformedPosition);
  17. return true;
  18. }
  19. return false;
  20. }
  21. public transferToEffect(effect: Effect, positionUniformName: string): void {
  22. if (this.parent && this.parent.getWorldMatrix) {
  23. this.computeTransformedPosition();
  24. effect.setFloat4(positionUniformName, this.transformedPosition.x, this.transformedPosition.y, this.transformedPosition.z, 0);
  25. return;
  26. }
  27. effect.setFloat4(positionUniformName, this.position.x, this.position.y, this.position.z, 0);
  28. }
  29. public needCube(): boolean {
  30. return true;
  31. }
  32. public supportsVSM(): boolean {
  33. return false;
  34. }
  35. public needRefreshPerFrame(): boolean {
  36. return false;
  37. }
  38. public getShadowDirection(faceIndex?: number): Vector3 {
  39. switch (faceIndex) {
  40. case 0:
  41. return new Vector3(1, 0, 0);
  42. case 1:
  43. return new Vector3(-1, 0, 0);
  44. case 2:
  45. return new Vector3(0, -1, 0);
  46. case 3:
  47. return new Vector3(0, 1, 0);
  48. case 4:
  49. return new Vector3(0, 0, 1);
  50. case 5:
  51. return new Vector3(0, 0, -1);
  52. }
  53. return Vector3.Zero();
  54. }
  55. public setShadowProjectionMatrix(matrix: Matrix, viewMatrix: Matrix, renderList: Array<AbstractMesh>): void {
  56. var activeCamera = this.getScene().activeCamera;
  57. Matrix.PerspectiveFovLHToRef(Math.PI / 2, 1.0, activeCamera.minZ, activeCamera.maxZ, matrix);
  58. }
  59. public _getWorldMatrix(): Matrix {
  60. if (!this._worldMatrix) {
  61. this._worldMatrix = Matrix.Identity();
  62. }
  63. Matrix.TranslationToRef(this.position.x, this.position.y, this.position.z, this._worldMatrix);
  64. return this._worldMatrix;
  65. }
  66. }
  67. }