Source: objects/lights/LightShadow.js

  1. import { Camera } from '../camera/Camera.js';
  2. import { Matrix4 } from '../../math/Matrix4.js';
  3. import { Vector2 } from '../../math/Vector2.js';
  4. /**
  5. * Serves as a base class for the other shadow classes.
  6. * @constructor
  7. * @hideconstructor
  8. * @abstract
  9. * @memberof zen3d
  10. */
  11. function LightShadow() {
  12. /**
  13. * The light's view of the world.
  14. * This is used to generate a depth map of the scene; objects behind other objects from the light's perspective will be in shadow.
  15. * @type {zen3d.Camera}
  16. */
  17. this.camera = new Camera();
  18. /**
  19. * Model to shadow camera space, to compute location and depth in shadow map. Stored in a {@link zen3d.Matrix4}.
  20. * This is computed internally during rendering.
  21. * @type {zen3d.Matrix4}
  22. */
  23. this.matrix = new Matrix4();
  24. /**
  25. * Shadow map bias, how much to add or subtract from the normalized depth when deciding whether a surface is in shadow.
  26. * Very tiny adjustments here (in the order of 0.0001) may help reduce artefacts in shadows.
  27. * @type {number}
  28. * @default 0
  29. */
  30. this.bias = 0;
  31. /**
  32. * Setting this to values greater than 1 will blur the edges of the shadow.
  33. * High values will cause unwanted banding effects in the shadows - a greater mapSize will allow for a higher value to be used here before these effects become visible.
  34. * Note that this has no effect if the {@link @zen3d.Object3D#shadowType} is set to PCF or PCSS.
  35. * @type {number}
  36. * @default 2
  37. */
  38. this.radius = 2;
  39. /**
  40. * Shadow camera near.
  41. * @type {number}
  42. * @default 1
  43. */
  44. this.cameraNear = 1;
  45. /**
  46. * Shadow camera far.
  47. * @type {number}
  48. * @default 500
  49. */
  50. this.cameraFar = 500;
  51. /**
  52. * A {@link zen3d.Vector2} defining the width and height of the shadow map.
  53. * Higher values give better quality shadows at the cost of computation time.
  54. * Values must be powers of 2.
  55. * @type {zen3d.Vector2}
  56. * @default zen3d.Vector2(512, 512)
  57. */
  58. this.mapSize = new Vector2(512, 512);
  59. /**
  60. * Enables automatic updates of the light's shadow.
  61. * If you do not require dynamic lighting / shadows, you may set this to false.
  62. * @type {boolean}
  63. * @default true
  64. */
  65. this.autoUpdate = true;
  66. /**
  67. * When set to true, shadow maps will be updated in the next ShadowMapPass.render call.
  68. * If you have set .autoUpdate to false, you will need to set this property to true and then make a ShadowMapPass.render call to update the light's shadow.
  69. * @type {boolean}
  70. * @default false
  71. */
  72. this.needsUpdate = false;
  73. this.renderTarget = null;
  74. this.map = null;
  75. }
  76. Object.assign(LightShadow.prototype, /** @lends zen3d.LightShadow.prototype */{
  77. update: function(light, face) {
  78. },
  79. copy: function(source) {
  80. this.camera.copy(source.camera);
  81. this.matrix.copy(source.matrix);
  82. this.bias = source.bias;
  83. this.radius = source.radius;
  84. this.cameraNear = source.cameraNear;
  85. this.cameraFar = source.cameraFar;
  86. this.mapSize.copy(source.mapSize);
  87. return this;
  88. },
  89. clone: function() {
  90. return new this.constructor().copy(this);
  91. }
  92. });
  93. export { LightShadow };