prePassConfiguration.js 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /**
  2. * Configuration needed for prepass-capable materials
  3. */
  4. export class PrePassConfiguration {
  5. constructor() {
  6. /**
  7. * Previous world matrices of meshes carrying this material
  8. * Used for computing velocity
  9. */
  10. this.previousWorldMatrices = {};
  11. /**
  12. * Previous bones of meshes carrying this material
  13. * Used for computing velocity
  14. */
  15. this.previousBones = {};
  16. }
  17. /**
  18. * Add the required uniforms to the current list.
  19. * @param uniforms defines the current uniform list.
  20. */
  21. static AddUniforms(uniforms) {
  22. uniforms.push("previousWorld", "previousViewProjection", "mPreviousBones");
  23. }
  24. /**
  25. * Add the required samplers to the current list.
  26. * @param samplers defines the current sampler list.
  27. */
  28. // eslint-disable-next-line @typescript-eslint/no-unused-vars
  29. static AddSamplers(samplers) {
  30. // pass
  31. }
  32. /**
  33. * Binds the material data.
  34. * @param effect defines the effect to update
  35. * @param scene defines the scene the material belongs to.
  36. * @param mesh The mesh
  37. * @param world World matrix of this mesh
  38. * @param isFrozen Is the material frozen
  39. */
  40. // eslint-disable-next-line @typescript-eslint/no-unused-vars
  41. bindForSubMesh(effect, scene, mesh, world, isFrozen) {
  42. if (scene.prePassRenderer && scene.prePassRenderer.enabled && scene.prePassRenderer.currentRTisSceneRT) {
  43. if (scene.prePassRenderer.getIndex(2) !== -1) {
  44. if (!this.previousWorldMatrices[mesh.uniqueId]) {
  45. this.previousWorldMatrices[mesh.uniqueId] = world.clone();
  46. }
  47. if (!this.previousViewProjection) {
  48. this.previousViewProjection = scene.getTransformMatrix().clone();
  49. this.currentViewProjection = scene.getTransformMatrix().clone();
  50. }
  51. const engine = scene.getEngine();
  52. if (this.currentViewProjection.updateFlag !== scene.getTransformMatrix().updateFlag) {
  53. // First update of the prepass configuration for this rendering pass
  54. this._lastUpdateFrameId = engine.frameId;
  55. this.previousViewProjection.copyFrom(this.currentViewProjection);
  56. this.currentViewProjection.copyFrom(scene.getTransformMatrix());
  57. }
  58. else if (this._lastUpdateFrameId !== engine.frameId) {
  59. // The scene transformation did not change from the previous frame (so no camera motion), we must update previousViewProjection accordingly
  60. this._lastUpdateFrameId = engine.frameId;
  61. this.previousViewProjection.copyFrom(this.currentViewProjection);
  62. }
  63. effect.setMatrix("previousWorld", this.previousWorldMatrices[mesh.uniqueId]);
  64. effect.setMatrix("previousViewProjection", this.previousViewProjection);
  65. this.previousWorldMatrices[mesh.uniqueId] = world.clone();
  66. }
  67. }
  68. }
  69. }
  70. //# sourceMappingURL=prePassConfiguration.js.map