babylon.hemisphericLight.ts 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. module BABYLON {
  2. export class HemisphericLight extends Light {
  3. @serializeAsColor3()
  4. public groundColor = new Color3(0.0, 0.0, 0.0);
  5. @serializeAsVector3()
  6. public direction: Vector3
  7. private _worldMatrix: Matrix;
  8. /**
  9. * Creates a HemisphericLight object in the scene according to the passed direction (Vector3).
  10. * The HemisphericLight simulates the ambient environment light, so the passed direction is the light reflection direction, not the incoming direction.
  11. * The HemisphericLight can't cast shadows.
  12. * Documentation : http://doc.babylonjs.com/tutorials/lights
  13. */
  14. constructor(name: string, direction: Vector3, scene: Scene) {
  15. super(name, scene);
  16. this.direction = direction || Vector3.Up();
  17. }
  18. protected _buildUniformLayout(): void {
  19. this._uniformBuffer.addUniform("vLightData", 4);
  20. this._uniformBuffer.addUniform("vLightDiffuse", 4);
  21. this._uniformBuffer.addUniform("vLightSpecular", 3);
  22. this._uniformBuffer.addUniform("vLightGround", 3);
  23. this._uniformBuffer.addUniform("shadowsInfo", 3);
  24. this._uniformBuffer.addUniform("depthValues", 2);
  25. this._uniformBuffer.create();
  26. }
  27. /**
  28. * Returns the string "HemisphericLight".
  29. */
  30. public getClassName(): string {
  31. return "HemisphericLight";
  32. }
  33. /**
  34. * Sets the HemisphericLight direction towards the passed target (Vector3).
  35. * Returns the updated direction.
  36. */
  37. public setDirectionToTarget(target: Vector3): Vector3 {
  38. this.direction = Vector3.Normalize(target.subtract(Vector3.Zero()));
  39. return this.direction;
  40. }
  41. public getShadowGenerator(): ShadowGenerator {
  42. return null;
  43. }
  44. /**
  45. * Sets the passed Effect object with the HemisphericLight normalized direction and color and the passed name (string).
  46. * Returns the HemisphericLight.
  47. */
  48. public transferToEffect(effect: Effect, lightIndex: string): HemisphericLight {
  49. var normalizeDirection = Vector3.Normalize(this.direction);
  50. this._uniformBuffer.updateFloat4("vLightData",
  51. normalizeDirection.x,
  52. normalizeDirection.y,
  53. normalizeDirection.z,
  54. 0.0,
  55. lightIndex);
  56. this._uniformBuffer.updateColor3("vLightGround", this.groundColor.scale(this.intensity), lightIndex);
  57. return this;
  58. }
  59. public _getWorldMatrix(): Matrix {
  60. if (!this._worldMatrix) {
  61. this._worldMatrix = Matrix.Identity();
  62. }
  63. return this._worldMatrix;
  64. }
  65. /**
  66. * Returns the integer 3.
  67. */
  68. public getTypeID(): number {
  69. return Light.LIGHTTYPEID_HEMISPHERICLIGHT;
  70. }
  71. }
  72. }