@babylonjs/core 5.51.0 → 5.53.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (107) hide show
  1. package/Animations/animatable.d.ts +5 -3
  2. package/Animations/animatable.js +11 -8
  3. package/Animations/animatable.js.map +1 -1
  4. package/Animations/animationGroup.js +3 -1
  5. package/Animations/animationGroup.js.map +1 -1
  6. package/Animations/runtimeAnimation.d.ts +1 -0
  7. package/Animations/runtimeAnimation.js +1 -0
  8. package/Animations/runtimeAnimation.js.map +1 -1
  9. package/Collisions/pickingInfo.d.ts +2 -1
  10. package/Collisions/pickingInfo.js +4 -3
  11. package/Collisions/pickingInfo.js.map +1 -1
  12. package/DeviceInput/eventFactory.js +4 -0
  13. package/DeviceInput/eventFactory.js.map +1 -1
  14. package/DeviceInput/webDeviceInputSystem.js +17 -9
  15. package/DeviceInput/webDeviceInputSystem.js.map +1 -1
  16. package/Engines/engine.d.ts +2 -0
  17. package/Engines/engine.js +5 -0
  18. package/Engines/engine.js.map +1 -1
  19. package/Engines/thinEngine.js +3 -3
  20. package/Engines/thinEngine.js.map +1 -1
  21. package/Inputs/scene.inputManager.js +5 -12
  22. package/Inputs/scene.inputManager.js.map +1 -1
  23. package/Materials/Node/Blocks/Dual/sceneDepthBlock.d.ts +4 -0
  24. package/Materials/Node/Blocks/Dual/sceneDepthBlock.js +37 -2
  25. package/Materials/Node/Blocks/Dual/sceneDepthBlock.js.map +1 -1
  26. package/Materials/Node/nodeMaterialDecorator.d.ts +1 -1
  27. package/Materials/Node/nodeMaterialDecorator.js.map +1 -1
  28. package/Materials/PBR/pbrMaterial.js +1 -0
  29. package/Materials/PBR/pbrMaterial.js.map +1 -1
  30. package/Materials/Textures/Filtering/hdrFiltering.js +4 -0
  31. package/Materials/Textures/Filtering/hdrFiltering.js.map +1 -1
  32. package/Materials/Textures/cubeTexture.js +7 -1
  33. package/Materials/Textures/cubeTexture.js.map +1 -1
  34. package/Materials/materialPluginBase.d.ts +3 -2
  35. package/Materials/materialPluginBase.js.map +1 -1
  36. package/Materials/materialPluginManager.js +13 -3
  37. package/Materials/materialPluginManager.js.map +1 -1
  38. package/Materials/uniformBuffer.d.ts +2 -0
  39. package/Materials/uniformBuffer.js +4 -0
  40. package/Materials/uniformBuffer.js.map +1 -1
  41. package/Maths/math.frustum.d.ts +8 -1
  42. package/Maths/math.frustum.js +14 -0
  43. package/Maths/math.frustum.js.map +1 -1
  44. package/Meshes/instancedMesh.d.ts +2 -1
  45. package/Meshes/instancedMesh.js +3 -2
  46. package/Meshes/instancedMesh.js.map +1 -1
  47. package/Meshes/mesh.d.ts +10 -5
  48. package/Meshes/mesh.js +40 -16
  49. package/Meshes/mesh.js.map +1 -1
  50. package/Misc/environmentTextureTools.js +7 -0
  51. package/Misc/environmentTextureTools.js.map +1 -1
  52. package/Misc/filesInput.d.ts +5 -2
  53. package/Misc/filesInput.js +39 -20
  54. package/Misc/filesInput.js.map +1 -1
  55. package/Misc/observable.js +3 -0
  56. package/Misc/observable.js.map +1 -1
  57. package/Misc/sceneOptimizer.js +3 -0
  58. package/Misc/sceneOptimizer.js.map +1 -1
  59. package/Misc/virtualJoystick.js +2 -2
  60. package/Misc/virtualJoystick.js.map +1 -1
  61. package/Particles/gpuParticleSystem.js +18 -14
  62. package/Particles/gpuParticleSystem.js.map +1 -1
  63. package/Physics/v2/IPhysicsEnginePlugin.d.ts +126 -19
  64. package/Physics/v2/IPhysicsEnginePlugin.js +6 -0
  65. package/Physics/v2/IPhysicsEnginePlugin.js.map +1 -1
  66. package/Physics/v2/physicsAggregate.d.ts +7 -1
  67. package/Physics/v2/physicsAggregate.js +23 -9
  68. package/Physics/v2/physicsAggregate.js.map +1 -1
  69. package/Physics/v2/physicsBody.d.ts +50 -31
  70. package/Physics/v2/physicsBody.js +75 -34
  71. package/Physics/v2/physicsBody.js.map +1 -1
  72. package/Physics/v2/physicsConstraint.d.ts +6 -6
  73. package/Physics/v2/physicsConstraint.js +6 -6
  74. package/Physics/v2/physicsConstraint.js.map +1 -1
  75. package/Physics/v2/physicsEngineComponent.d.ts +10 -0
  76. package/Physics/v2/physicsEngineComponent.js +27 -0
  77. package/Physics/v2/physicsEngineComponent.js.map +1 -1
  78. package/Physics/v2/physicsMaterial.d.ts +52 -46
  79. package/Physics/v2/physicsMaterial.js +23 -80
  80. package/Physics/v2/physicsMaterial.js.map +1 -1
  81. package/Physics/v2/physicsShape.d.ts +34 -9
  82. package/Physics/v2/physicsShape.js +59 -8
  83. package/Physics/v2/physicsShape.js.map +1 -1
  84. package/PostProcesses/RenderPipeline/Pipelines/ssao2RenderingPipeline.d.ts +59 -13
  85. package/PostProcesses/RenderPipeline/Pipelines/ssao2RenderingPipeline.js +131 -54
  86. package/PostProcesses/RenderPipeline/Pipelines/ssao2RenderingPipeline.js.map +1 -1
  87. package/Rendering/depthRenderer.js +1 -1
  88. package/Rendering/depthRenderer.js.map +1 -1
  89. package/Rendering/depthRendererSceneComponent.d.ts +2 -1
  90. package/Rendering/depthRendererSceneComponent.js +2 -2
  91. package/Rendering/depthRendererSceneComponent.js.map +1 -1
  92. package/Shaders/sprites.fragment.js +6 -1
  93. package/Shaders/sprites.fragment.js.map +1 -1
  94. package/Shaders/ssao2.fragment.js +0 -2
  95. package/Shaders/ssao2.fragment.js.map +1 -1
  96. package/Sprites/spriteManager.d.ts +7 -0
  97. package/Sprites/spriteManager.js +27 -0
  98. package/Sprites/spriteManager.js.map +1 -1
  99. package/Sprites/spriteRenderer.d.ts +8 -0
  100. package/Sprites/spriteRenderer.js +42 -19
  101. package/Sprites/spriteRenderer.js.map +1 -1
  102. package/XR/features/WebXRControllerTeleportation.d.ts +9 -0
  103. package/XR/features/WebXRControllerTeleportation.js +28 -4
  104. package/XR/features/WebXRControllerTeleportation.js.map +1 -1
  105. package/assetContainer.js +1 -1
  106. package/assetContainer.js.map +1 -1
  107. package/package.json +1 -1
@@ -1,4 +1,5 @@
1
1
  import { ShapeType } from "./IPhysicsEnginePlugin.js";
2
+ import { Vector3, Quaternion } from "../../Maths/math.vector.js";
2
3
  /**
3
4
  * PhysicsShape class.
4
5
  * This class is useful for creating a physics shape that can be used in a physics engine.
@@ -59,41 +60,42 @@ export class PhysicsShape {
59
60
  *
60
61
  * @param layer
61
62
  */
62
- setFilterLayer(layer) {
63
+ set filterLayer(layer) {
63
64
  this._physicsPlugin.setFilterLayer(this, layer);
64
65
  }
65
66
  /**
66
67
  *
67
68
  * @returns
68
69
  */
69
- getFilterLayer() {
70
+ get filterLayer() {
70
71
  return this._physicsPlugin.getFilterLayer(this);
71
72
  }
72
73
  /**
73
74
  *
74
- * @param materialId
75
+ * @param material
75
76
  */
76
- setMaterial(material) {
77
+ set material(material) {
77
78
  this._physicsPlugin.setMaterial(this, material);
79
+ this._material = material;
78
80
  }
79
81
  /**
80
82
  *
81
83
  * @returns
82
84
  */
83
- getMaterial() {
84
- return this._physicsPlugin.getMaterial(this);
85
+ get material() {
86
+ return this._material;
85
87
  }
86
88
  /**
87
89
  *
88
90
  * @param density
89
91
  */
90
- setDensity(density) {
92
+ set density(density) {
91
93
  this._physicsPlugin.setDensity(this, density);
92
94
  }
93
95
  /**
94
96
  *
95
97
  */
96
- getDensity() {
98
+ get density() {
97
99
  return this._physicsPlugin.getDensity(this);
98
100
  }
99
101
  /**
@@ -145,6 +147,18 @@ export class PhysicsShapeSphere extends PhysicsShape {
145
147
  constructor(center, radius, scene) {
146
148
  super({ type: ShapeType.SPHERE, parameters: { center: center, radius: radius } }, scene);
147
149
  }
150
+ /**
151
+ *
152
+ * @param mesh
153
+ * @returns PhysicsShapeSphere
154
+ */
155
+ static FromMesh(mesh) {
156
+ const bounds = mesh.getBoundingInfo();
157
+ //<todo.eoin We don't use bounding sphere because the results seem to be wrong
158
+ const centerLocal = bounds.boundingBox.center;
159
+ const radius = bounds.boundingBox.extendSize.x;
160
+ return new PhysicsShapeSphere(centerLocal, radius, mesh.getScene());
161
+ }
148
162
  }
149
163
  /**
150
164
  * Helper object to create a capsule shape
@@ -160,6 +174,19 @@ export class PhysicsShapeCapsule extends PhysicsShape {
160
174
  constructor(pointA, pointB, radius, scene) {
161
175
  super({ type: ShapeType.CAPSULE, parameters: { pointA: pointA, pointB: pointB, radius: radius } }, scene);
162
176
  }
177
+ /**
178
+ * Derive an approximate capsule from the transform node. Note, this is
179
+ * not the optimal bounding capsule.
180
+ * @param TransformNode node Node from which to derive a cylinder shape
181
+ */
182
+ static FromMesh(mesh) {
183
+ const boundsLocal = mesh.getBoundingInfo();
184
+ const radius = boundsLocal.boundingBox.extendSize.x;
185
+ const pointFromCenter = new Vector3(0, boundsLocal.boundingBox.extendSize.y - radius, 0);
186
+ const pointA = boundsLocal.boundingBox.center.add(pointFromCenter);
187
+ const pointB = boundsLocal.boundingBox.center.subtract(pointFromCenter);
188
+ return new PhysicsShapeCapsule(pointA, pointB, radius, mesh.getScene());
189
+ }
163
190
  }
164
191
  /**
165
192
  * Helper object to create a cylinder shape
@@ -175,6 +202,19 @@ export class PhysicsShapeCylinder extends PhysicsShape {
175
202
  constructor(pointA, pointB, radius, scene) {
176
203
  super({ type: ShapeType.CYLINDER, parameters: { pointA: pointA, pointB: pointB, radius: radius } }, scene);
177
204
  }
205
+ /**
206
+ * Derive an approximate cylinder from the transform node. Note, this is
207
+ * not the optimal bounding cylinder.
208
+ * @param TransformNode node Node from which to derive a cylinder shape
209
+ */
210
+ static FromMesh(mesh) {
211
+ const boundsLocal = mesh.getBoundingInfo();
212
+ const radius = boundsLocal.boundingBox.extendSize.x;
213
+ const pointFromCenter = new Vector3(0, boundsLocal.boundingBox.extendSize.y, 0);
214
+ const pointA = boundsLocal.boundingBox.center.add(pointFromCenter);
215
+ const pointB = boundsLocal.boundingBox.center.subtract(pointFromCenter);
216
+ return new PhysicsShapeCylinder(pointA, pointB, radius, mesh.getScene());
217
+ }
178
218
  }
179
219
  /**
180
220
  * Helper object to create a box shape
@@ -190,6 +230,17 @@ export class PhysicsShapeBox extends PhysicsShape {
190
230
  constructor(center, rotation, extents, scene) {
191
231
  super({ type: ShapeType.BOX, parameters: { center: center, rotation: rotation, extents: extents } }, scene);
192
232
  }
233
+ /**
234
+ *
235
+ * @param mesh
236
+ * @returns PhysicsShapeBox
237
+ */
238
+ static FromMesh(mesh) {
239
+ const bounds = mesh.getBoundingInfo();
240
+ const centerLocal = bounds.boundingBox.center;
241
+ const extents = bounds.boundingBox.extendSize.scale(2.0); //<todo.eoin extendSize seems to really be half-extents?
242
+ return new PhysicsShapeBox(centerLocal, Quaternion.Identity(), extents, mesh.getScene());
243
+ }
193
244
  }
194
245
  /**
195
246
  * Helper object to create a convex hull shape
@@ -1 +1 @@
1
- {"version":3,"file":"physicsShape.js","sourceRoot":"","sources":["../../../../../lts/core/generated/Physics/v2/physicsShape.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AA0BnD;;;;GAIG;AACH,MAAM,OAAO,YAAY;IAYrB;;;;;;;;;;;;OAYG;IACH,YAAY,OAA2B,EAAE,KAAY;;QAxBrD;;WAEG;QACI,gBAAW,GAAQ,SAAS,CAAC;QAsBhC,IAAI,CAAC,KAAK,EAAE;YACR,OAAO;SACV;QACD,MAAM,aAAa,GAAG,KAAK,CAAC,gBAAgB,EAAE,CAAC;QAC/C,IAAI,CAAC,aAAa,EAAE;YAChB,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAC;SACnD;QACD,IAAI,aAAa,CAAC,gBAAgB,EAAE,IAAI,CAAC,EAAE;YACvC,MAAM,IAAI,KAAK,CAAC,kDAAkD,CAAC,CAAC;SACvE;QACD,MAAM,aAAa,GAAG,aAAa,CAAC,gBAAgB,EAAE,CAAC;QACvD,IAAI,CAAC,aAAa,EAAE;YAChB,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAC;SACnD;QACD,IAAI,CAAC,cAAc,GAAG,aAAuC,CAAC;QAE9D,IAAI,OAAO,CAAC,UAAU,KAAK,SAAS,IAAI,O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,EAAE,SAAS,CAAC,SAAS,EAAE,UAAU,EAAE,EAAE,EAAE,EAAE,KAAK,CAAC,CAAC;IAChE,CAAC;CACJ","sourcesContent":["import type { TransformNode } from \"../../Meshes/transformNode\";\r\nimport type { BoundingBox } from \"../../Culling/boundingBox\";\r\nimport { ShapeType } from \"./IPhysicsEnginePlugin\";\r\nimport type { IPhysicsEnginePluginV2, PhysicsShapeParameters } from \"./IPhysicsEnginePlugin\";\r\nimport type { PhysicsMaterial } from \"./physicsMaterial\";\r\nimport type { Vector3 } from \"../../Maths/math.vector\";\r\nimport type { Quaternion } from \"../../Maths/math.vector\";\r\nimport type { Mesh } from \"../../Meshes/mesh\";\r\nimport type { Scene } from \"../../scene\";\r\n\r\n/**\r\n * Options for creating a physics shape\r\n */\r\nexport interface PhysicShapeOptions {\r\n /**\r\n * The type of the shape. This can be one of the following: SPHERE, BOX, CAPSULE, CYLINDER, CONVEX_HULL, MESH, HEIGHTFIELD, CONTAINER\r\n */\r\n type?: ShapeType;\r\n /**\r\n * The parameters of the shape. Varies depending of the shape type.\r\n */\r\n parameters?: PhysicsShapeParameters;\r\n /**\r\n * Reference to an already existing physics shape in the plugin.\r\n */\r\n pluginData?: any;\r\n}\r\n\r\n/**\r\n * PhysicsShape class.\r\n * This class is useful for creating a physics shape that can be used in a physics engine.\r\n * A Physic Shape determine how collision are computed. It must be attached to a body.\r\n */\r\nexport class PhysicsShape {\r\n /**\r\n * V2 Physics plugin private data for single shape\r\n */\r\n public _pluginData: any = undefined;\r\n /**\r\n * The V2 plugin used to create and manage this Physics Body\r\n */\r\n private _physicsPlugin: IPhysicsEnginePluginV2;\r\n\r\n private _type: ShapeType;\r\n\r\n /**\r\n * Constructs a new physics shape.\r\n * @param options The options for the physics shape. These are:\r\n * * type: The type of the shape. This can be one of the following: SPHERE, BOX, CAPSULE, CYLINDER, CONVEX_HULL, MESH, HEIGHTFIELD, CONTAINER\r\n * * parameters: The parameters of the shape.\r\n * * pluginData: The plugin data of the shape. This is used if you already have a reference to the object on the plugin side.\r\n * You need to specify either type or pluginData.\r\n * @param scene The scene the shape belongs to.\r\n *\r\n * This code is useful for creating a new physics shape with the given type, options, and scene.\r\n * It also checks that the physics engine and plugin version are correct.\r\n * If not, it throws an error. This ensures that the shape is created with the correct parameters and is compatible with the physics engine.\r\n */\r\n constructor(options: PhysicShapeOptions, scene: Scene) {\r\n if (!scene) {\r\n return;\r\n }\r\n const physicsEngine = scene.getPhysicsEngine();\r\n if (!physicsEngine) {\r\n throw new Error(\"No Physics Engine available.\");\r\n }\r\n if (physicsEngine.getPluginVersion() != 2) {\r\n throw new Error(\"Plugin version is incorrect. Expected version 2.\");\r\n }\r\n const physicsPlugin = physicsEngine.getPhysicsPlugin();\r\n if (!physicsPlugin) {\r\n throw new Error(\"No Physics Plugin available.\");\r\n }\r\n this._physicsPlugin = physicsPlugin as IPhysicsEnginePluginV2;\r\n\r\n if (options.pluginData !== undefined && options.pluginData !== null) {\r\n this._pluginData = options.pluginData;\r\n this._type = this._physicsPlugin.getShapeType(this);\r\n } else if (options.type !== undefined && options.type !== null) {\r\n this._type = options.type;\r\n const parameters = options.parameters ?? {};\r\n this._physicsPlugin.initShape(this, options.type, parameters);\r\n }\r\n }\r\n\r\n /**\r\n *\r\n */\r\n public get type(): ShapeType {\r\n return this._type;\r\n }\r\n\r\n /**\r\n *\r\n * @param layer\r\n */\r\n public setFilterLayer(layer: number): void {\r\n this._physicsPlugin.setFilterLayer(this, layer);\r\n }\r\n\r\n /**\r\n *\r\n * @returns\r\n */\r\n public getFilterLayer(): number {\r\n return this._physicsPlugin.getFilterLayer(this);\r\n }\r\n\r\n /**\r\n *\r\n * @param materialId\r\n */\r\n public setMaterial(material: PhysicsMaterial): void {\r\n this._physicsPlugin.setMaterial(this, material);\r\n }\r\n\r\n /**\r\n *\r\n * @returns\r\n */\r\n public getMaterial(): PhysicsMaterial | undefined {\r\n return this._physicsPlugin.getMaterial(this);\r\n }\r\n\r\n /**\r\n *\r\n * @param density\r\n */\r\n public setDensity(density: number): void {\r\n this._physicsPlugin.setDensity(this, density);\r\n }\r\n\r\n /**\r\n *\r\n */\r\n public getDensity(): number {\r\n return this._physicsPlugin.getDensity(this);\r\n }\r\n\r\n /**\r\n *\r\n * @param newChild\r\n * @param childTransform\r\n */\r\n public addChild(newChild: PhysicsShape, childTransform: TransformNode): void {\r\n this._physicsPlugin.addChild(this, newChild, childTransform);\r\n }\r\n\r\n /**\r\n *\r\n * @param childIndex\r\n */\r\n public removeChild(childIndex: number): void {\r\n this._physicsPlugin.removeChild(this, childIndex);\r\n }\r\n\r\n /**\r\n *\r\n * @returns\r\n */\r\n public getNumChildren(): number {\r\n return this._physicsPlugin.getNumChildren(this);\r\n }\r\n\r\n /**\r\n *\r\n */\r\n public getBoundingBox(): BoundingBox {\r\n return this._physicsPlugin.getBoundingBox(this);\r\n }\r\n\r\n /**\r\n *\r\n */\r\n public dispose() {\r\n this._physicsPlugin.disposeShape(this);\r\n }\r\n}\r\n\r\n/**\r\n * Helper object to create a sphere shape\r\n */\r\nexport class PhysicsShapeSphere extends PhysicsShape {\r\n /** @internal */\r\n /**\r\n * Constructor for the Sphere Shape\r\n * @param center local center of the sphere\r\n * @param radius radius\r\n * @param scene scene to attach to\r\n */\r\n constructor(center: Vector3, radius: number, scene: Scene) {\r\n super({ type: ShapeType.SPHERE, parameters: { center: center, radius: radius } }, scene);\r\n }\r\n}\r\n\r\n/**\r\n * Helper object to create a capsule shape\r\n */\r\nexport class PhysicsShapeCapsule extends PhysicsShape {\r\n /**\r\n *\r\n * @param pointA Starting point that defines the capsule segment\r\n * @param pointB ending point of that same segment\r\n * @param radius radius\r\n * @param scene scene to attach to\r\n */\r\n constructor(pointA: Vector3, pointB: Vector3, radius: number, scene: Scene) {\r\n super({ type: ShapeType.CAPSULE, parameters: { pointA: pointA, pointB: pointB, radius: radius } }, scene);\r\n }\r\n}\r\n\r\n/**\r\n * Helper object to create a cylinder shape\r\n */\r\nexport class PhysicsShapeCylinder extends PhysicsShape {\r\n /**\r\n *\r\n * @param pointA Starting point that defines the cylinder segment\r\n * @param pointB ending point of that same segment\r\n * @param radius radius\r\n * @param scene scene to attach to\r\n */\r\n constructor(pointA: Vector3, pointB: Vector3, radius: number, scene: Scene) {\r\n super({ type: ShapeType.CYLINDER, parameters: { pointA: pointA, pointB: pointB, radius: radius } }, scene);\r\n }\r\n}\r\n\r\n/**\r\n * Helper object to create a box shape\r\n */\r\nexport class PhysicsShapeBox extends PhysicsShape {\r\n /**\r\n *\r\n * @param center local center of the sphere\r\n * @param rotation local orientation\r\n * @param extents size of the box in each direction\r\n * @param scene scene to attach to\r\n */\r\n constructor(center: Vector3, rotation: Quaternion, extents: Vector3, scene: Scene) {\r\n super({ type: ShapeType.BOX, parameters: { center: center, rotation: rotation, extents: extents } }, scene);\r\n }\r\n}\r\n\r\n/**\r\n * Helper object to create a convex hull shape\r\n */\r\nexport class PhysicsShapeConvexHull extends PhysicsShape {\r\n /**\r\n *\r\n * @param mesh the mesh to be used as topology infos for the convex hull\r\n * @param scene scene to attach to\r\n */\r\n constructor(mesh: Mesh, scene: Scene) {\r\n super({ type: ShapeType.CONVEX_HULL, parameters: { mesh: mesh } }, scene);\r\n }\r\n}\r\n\r\n/**\r\n * Helper object to create a mesh shape\r\n */\r\nexport class PhysicsShapeMesh extends PhysicsShape {\r\n /**\r\n *\r\n * @param mesh the mesh topology that will be used to create the shape\r\n * @param scene scene to attach to\r\n */\r\n constructor(mesh: Mesh, scene: Scene) {\r\n super({ type: ShapeType.MESH, parameters: { mesh: mesh } }, scene);\r\n }\r\n}\r\n\r\n/**\r\n * A shape container holds a variable number of shapes. Use AddChild to append to newly created parent container.\r\n */\r\nexport class PhysicsShapeContainer extends PhysicsShape {\r\n /**\r\n * Constructor of the Shape container\r\n * @param scene scene to attach to\r\n */\r\n constructor(scene: Scene) {\r\n super({ type: ShapeType.CONTAINER, parameters: {} }, scene);\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"physicsShape.js","sour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EAAE,IAAI,EAAE,IAAI,EAAE,EAAE,EAAE,KAAK,CAAC,CAAC;IAC9E,CAAC;CACJ;AAED;;GAEG;AACH,MAAM,OAAO,gBAAiB,SAAQ,YAAY;IAC9C;;;;OAIG;IACH,YAAY,IAAU,EAAE,KAAY;QAChC,KAAK,CAAC,EAAE,IAAI,EAAE,SAAS,CAAC,IAAI,EAAE,UAAU,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE,EAAE,KAAK,CAAC,CAAC;IACvE,CAAC;CACJ;AAED;;GAEG;AACH,MAAM,OAAO,qBAAsB,SAAQ,YAAY;IACnD;;;OAGG;IACH,YAAY,KAAY;QACpB,KAAK,CAAC,EAAE,IAAI,EAAE,SAAS,CAAC,SAAS,EAAE,UAAU,EAAE,EAAE,EAAE,EAAE,KAAK,CAAC,CAAC;IAChE,CAAC;CACJ","sourcesContent":["import type { TransformNode } from \"../../Meshes/transformNode\";\r\nimport type { AbstractMesh } from \"../../Meshes/abstractMesh\";\r\nimport type { BoundingBox } from \"../../Culling/boundingBox\";\r\nimport { ShapeType } from \"./IPhysicsEnginePlugin\";\r\nimport type { IPhysicsEnginePluginV2, PhysicsShapeParameters } from \"./IPhysicsEnginePlugin\";\r\nimport type { PhysicsMaterial } from \"./physicsMaterial\";\r\nimport { Vector3, Quaternion } from \"../../Maths/math.vector\";\r\n\r\nimport type { Mesh } from \"../../Meshes/mesh\";\r\nimport type { Scene } from \"../../scene\";\r\n\r\n/**\r\n * Options for creating a physics shape\r\n */\r\nexport interface PhysicShapeOptions {\r\n /**\r\n * The type of the shape. This can be one of the following: SPHERE, BOX, CAPSULE, CYLINDER, CONVEX_HULL, MESH, HEIGHTFIELD, CONTAINER\r\n */\r\n type?: ShapeType;\r\n /**\r\n * The parameters of the shape. Varies depending of the shape type.\r\n */\r\n parameters?: PhysicsShapeParameters;\r\n /**\r\n * Reference to an already existing physics shape in the plugin.\r\n */\r\n pluginData?: any;\r\n}\r\n\r\n/**\r\n * PhysicsShape class.\r\n * This class is useful for creating a physics shape that can be used in a physics engine.\r\n * A Physic Shape determine how collision are computed. It must be attached to a body.\r\n */\r\nexport class PhysicsShape {\r\n /**\r\n * V2 Physics plugin private data for single shape\r\n */\r\n public _pluginData: any = undefined;\r\n /**\r\n * The V2 plugin used to create and manage this Physics Body\r\n */\r\n private _physicsPlugin: IPhysicsEnginePluginV2;\r\n\r\n private _type: ShapeType;\r\n\r\n private _material: PhysicsMaterial;\r\n\r\n /**\r\n * Constructs a new physics shape.\r\n * @param options The options for the physics shape. These are:\r\n * * type: The type of the shape. This can be one of the following: SPHERE, BOX, CAPSULE, CYLINDER, CONVEX_HULL, MESH, HEIGHTFIELD, CONTAINER\r\n * * parameters: The parameters of the shape.\r\n * * pluginData: The plugin data of the shape. This is used if you already have a reference to the object on the plugin side.\r\n * You need to specify either type or pluginData.\r\n * @param scene The scene the shape belongs to.\r\n *\r\n * This code is useful for creating a new physics shape with the given type, options, and scene.\r\n * It also checks that the physics engine and plugin version are correct.\r\n * If not, it throws an error. This ensures that the shape is created with the correct parameters and is compatible with the physics engine.\r\n */\r\n constructor(options: PhysicShapeOptions, scene: Scene) {\r\n if (!scene) {\r\n return;\r\n }\r\n const physicsEngine = scene.getPhysicsEngine();\r\n if (!physicsEngine) {\r\n throw new Error(\"No Physics Engine available.\");\r\n }\r\n if (physicsEngine.getPluginVersion() != 2) {\r\n throw new Error(\"Plugin version is incorrect. Expected version 2.\");\r\n }\r\n const physicsPlugin = physicsEngine.getPhysicsPlugin();\r\n if (!physicsPlugin) {\r\n throw new Error(\"No Physics Plugin available.\");\r\n }\r\n this._physicsPlugin = physicsPlugin as IPhysicsEnginePluginV2;\r\n\r\n if (options.pluginData !== undefined && options.pluginData !== null) {\r\n this._pluginData = options.pluginData;\r\n this._type = this._physicsPlugin.getShapeType(this);\r\n } else if (options.type !== undefined && options.type !== null) {\r\n this._type = options.type;\r\n const parameters = options.parameters ?? {};\r\n this._physicsPlugin.initShape(this, options.type, parameters);\r\n }\r\n }\r\n\r\n /**\r\n *\r\n */\r\n public get type(): ShapeType {\r\n return this._type;\r\n }\r\n\r\n /**\r\n *\r\n * @param layer\r\n */\r\n public set filterLayer(layer: number) {\r\n this._physicsPlugin.setFilterLayer(this, layer);\r\n }\r\n\r\n /**\r\n *\r\n * @returns\r\n */\r\n public get filterLayer(): number {\r\n return this._physicsPlugin.getFilterLayer(this);\r\n }\r\n\r\n /**\r\n *\r\n * @param material\r\n */\r\n public set material(material: PhysicsMaterial) {\r\n this._physicsPlugin.setMaterial(this, material);\r\n this._material = material;\r\n }\r\n\r\n /**\r\n *\r\n * @returns\r\n */\r\n public get material(): PhysicsMaterial {\r\n return this._material;\r\n }\r\n\r\n /**\r\n *\r\n * @param density\r\n */\r\n public set density(density: number) {\r\n this._physicsPlugin.setDensity(this, density);\r\n }\r\n\r\n /**\r\n *\r\n */\r\n public get density(): number {\r\n return this._physicsPlugin.getDensity(this);\r\n }\r\n\r\n /**\r\n *\r\n * @param newChild\r\n * @param childTransform\r\n */\r\n public addChild(newChild: PhysicsShape, childTransform: TransformNode): void {\r\n this._physicsPlugin.addChild(this, newChild, childTransform);\r\n }\r\n\r\n /**\r\n *\r\n * @param childIndex\r\n */\r\n public removeChild(childIndex: number): void {\r\n this._physicsPlugin.removeChild(this, childIndex);\r\n }\r\n\r\n /**\r\n *\r\n * @returns\r\n */\r\n public getNumChildren(): number {\r\n return this._physicsPlugin.getNumChildren(this);\r\n }\r\n\r\n /**\r\n *\r\n */\r\n public getBoundingBox(): BoundingBox {\r\n return this._physicsPlugin.getBoundingBox(this);\r\n }\r\n\r\n /**\r\n *\r\n */\r\n public dispose() {\r\n this._physicsPlugin.disposeShape(this);\r\n }\r\n}\r\n\r\n/**\r\n * Helper object to create a sphere shape\r\n */\r\nexport class PhysicsShapeSphere extends PhysicsShape {\r\n /** @internal */\r\n /**\r\n * Constructor for the Sphere Shape\r\n * @param center local center of the sphere\r\n * @param radius radius\r\n * @param scene scene to attach to\r\n */\r\n constructor(center: Vector3, radius: number, scene: Scene) {\r\n super({ type: ShapeType.SPHERE, parameters: { center: center, radius: radius } }, scene);\r\n }\r\n\r\n /**\r\n *\r\n * @param mesh\r\n * @returns PhysicsShapeSphere\r\n */\r\n static FromMesh(mesh: AbstractMesh) {\r\n const bounds = mesh.getBoundingInfo();\r\n //<todo.eoin We don't use bounding sphere because the results seem to be wrong\r\n const centerLocal = bounds.boundingBox.center;\r\n const radius = bounds.boundingBox.extendSize.x;\r\n return new PhysicsShapeSphere(centerLocal, radius, mesh.getScene());\r\n }\r\n}\r\n\r\n/**\r\n * Helper object to create a capsule shape\r\n */\r\nexport class PhysicsShapeCapsule extends PhysicsShape {\r\n /**\r\n *\r\n * @param pointA Starting point that defines the capsule segment\r\n * @param pointB ending point of that same segment\r\n * @param radius radius\r\n * @param scene scene to attach to\r\n */\r\n constructor(pointA: Vector3, pointB: Vector3, radius: number, scene: Scene) {\r\n super({ type: ShapeType.CAPSULE, parameters: { pointA: pointA, pointB: pointB, radius: radius } }, scene);\r\n }\r\n\r\n /**\r\n * Derive an approximate capsule from the transform node. Note, this is\r\n * not the optimal bounding capsule.\r\n * @param TransformNode node Node from which to derive a cylinder shape\r\n */\r\n static FromMesh(mesh: AbstractMesh): PhysicsShapeCapsule {\r\n const boundsLocal = mesh.getBoundingInfo();\r\n const radius = boundsLocal.boundingBox.extendSize.x;\r\n const pointFromCenter = new Vector3(0, boundsLocal.boundingBox.extendSize.y - radius, 0);\r\n const pointA = boundsLocal.boundingBox.center.add(pointFromCenter);\r\n const pointB = boundsLocal.boundingBox.center.subtract(pointFromCenter);\r\n return new PhysicsShapeCapsule(pointA, pointB, radius, mesh.getScene());\r\n }\r\n}\r\n\r\n/**\r\n * Helper object to create a cylinder shape\r\n */\r\nexport class PhysicsShapeCylinder extends PhysicsShape {\r\n /**\r\n *\r\n * @param pointA Starting point that defines the cylinder segment\r\n * @param pointB ending point of that same segment\r\n * @param radius radius\r\n * @param scene scene to attach to\r\n */\r\n constructor(pointA: Vector3, pointB: Vector3, radius: number, scene: Scene) {\r\n super({ type: ShapeType.CYLINDER, parameters: { pointA: pointA, pointB: pointB, radius: radius } }, scene);\r\n }\r\n\r\n /**\r\n * Derive an approximate cylinder from the transform node. Note, this is\r\n * not the optimal bounding cylinder.\r\n * @param TransformNode node Node from which to derive a cylinder shape\r\n */\r\n static FromMesh(mesh: AbstractMesh): PhysicsShapeCylinder {\r\n const boundsLocal = mesh.getBoundingInfo();\r\n const radius = boundsLocal.boundingBox.extendSize.x;\r\n const pointFromCenter = new Vector3(0, boundsLocal.boundingBox.extendSize.y, 0);\r\n const pointA = boundsLocal.boundingBox.center.add(pointFromCenter);\r\n const pointB = boundsLocal.boundingBox.center.subtract(pointFromCenter);\r\n return new PhysicsShapeCylinder(pointA, pointB, radius, mesh.getScene());\r\n }\r\n}\r\n\r\n/**\r\n * Helper object to create a box shape\r\n */\r\nexport class PhysicsShapeBox extends PhysicsShape {\r\n /**\r\n *\r\n * @param center local center of the sphere\r\n * @param rotation local orientation\r\n * @param extents size of the box in each direction\r\n * @param scene scene to attach to\r\n */\r\n constructor(center: Vector3, rotation: Quaternion, extents: Vector3, scene: Scene) {\r\n super({ type: ShapeType.BOX, parameters: { center: center, rotation: rotation, extents: extents } }, scene);\r\n }\r\n\r\n /**\r\n *\r\n * @param mesh\r\n * @returns PhysicsShapeBox\r\n */\r\n static FromMesh(mesh: AbstractMesh): PhysicsShapeBox {\r\n const bounds = mesh.getBoundingInfo();\r\n const centerLocal = bounds.boundingBox.center;\r\n const extents = bounds.boundingBox.extendSize.scale(2.0); //<todo.eoin extendSize seems to really be half-extents?\r\n return new PhysicsShapeBox(centerLocal, Quaternion.Identity(), extents, mesh.getScene());\r\n }\r\n}\r\n\r\n/**\r\n * Helper object to create a convex hull shape\r\n */\r\nexport class PhysicsShapeConvexHull extends PhysicsShape {\r\n /**\r\n *\r\n * @param mesh the mesh to be used as topology infos for the convex hull\r\n * @param scene scene to attach to\r\n */\r\n constructor(mesh: Mesh, scene: Scene) {\r\n super({ type: ShapeType.CONVEX_HULL, parameters: { mesh: mesh } }, scene);\r\n }\r\n}\r\n\r\n/**\r\n * Helper object to create a mesh shape\r\n */\r\nexport class PhysicsShapeMesh extends PhysicsShape {\r\n /**\r\n *\r\n * @param mesh the mesh topology that will be used to create the shape\r\n * @param scene scene to attach to\r\n */\r\n constructor(mesh: Mesh, scene: Scene) {\r\n super({ type: ShapeType.MESH, parameters: { mesh: mesh } }, scene);\r\n }\r\n}\r\n\r\n/**\r\n * A shape container holds a variable number of shapes. Use AddChild to append to newly created parent container.\r\n */\r\nexport class PhysicsShapeContainer extends PhysicsShape {\r\n /**\r\n * Constructor of the Shape container\r\n * @param scene scene to attach to\r\n */\r\n constructor(scene: Scene) {\r\n super({ type: ShapeType.CONTAINER, parameters: {} }, scene);\r\n }\r\n}\r\n"]}
@@ -42,23 +42,31 @@ export declare class SSAO2RenderingPipeline extends PostProcessRenderPipeline {
42
42
  */
43
43
  maxZ: number;
44
44
  /**
45
- * In order to save performances, SSAO radius is clamped on close geometry. This ratio changes by how much
45
+ * In order to save performances, SSAO radius is clamped on close geometry. This ratio changes by how much.
46
46
  */
47
47
  minZAspect: number;
48
+ private _epsilon;
49
+ /**
50
+ * Used in SSAO calculations to compensate for accuracy issues with depth values. Default 0.02.
51
+ *
52
+ * Normally you do not need to change this value, but you can experiment with it if you get a lot of in false self-occlusion on flat surfaces when using fewer than 16 samples. Useful range is normally [0..0.1] but higher values is allowed.
53
+ */
54
+ set epsilon(n: number);
55
+ get epsilon(): number;
48
56
  private _samples;
49
57
  /**
50
- * Number of samples used for the SSAO calculations. Default value is 8
58
+ * Number of samples used for the SSAO calculations. Default value is 8.
51
59
  */
52
60
  set samples(n: number);
53
61
  get samples(): number;
54
62
  private _textureSamples;
55
63
  /**
56
- * Number of samples to use for antialiasing
64
+ * Number of samples to use for antialiasing.
57
65
  */
58
66
  set textureSamples(n: number);
59
67
  get textureSamples(): number;
60
68
  /**
61
- * Force rendering the geometry through geometry buffer
69
+ * Force rendering the geometry through geometry buffer.
62
70
  */
63
71
  private _forceGeometryBuffer;
64
72
  private get _geometryBufferRenderer();
@@ -67,29 +75,64 @@ export declare class SSAO2RenderingPipeline extends PostProcessRenderPipeline {
67
75
  * Ratio object used for SSAO ratio and blur ratio
68
76
  */
69
77
  private _ratio;
78
+ private _textureType;
70
79
  /**
71
80
  * Dynamically generated sphere sampler.
72
81
  */
73
82
  private _sampleSphere;
74
83
  /**
75
- * Blur filter offsets
84
+ * The radius around the analyzed pixel used by the SSAO post-process. Default value is 2.0
85
+ */
86
+ radius: number;
87
+ /**
88
+ * The base color of the SSAO post-process
89
+ * The final result is "base + ssao" between [0, 1]
90
+ */
91
+ base: number;
92
+ private _bypassBlur;
93
+ /**
94
+ * Skips the denoising (blur) stage of the SSAO calculations.
95
+ *
96
+ * Useful to temporarily set while experimenting with the other SSAO2 settings.
76
97
  */
77
- private _samplerOffsets;
98
+ set bypassBlur(b: boolean);
99
+ get bypassBlur(): boolean;
78
100
  private _expensiveBlur;
79
101
  /**
80
- * If bilateral blur should be used
102
+ * Enables the configurable bilateral denoising (blurring) filter. Default is true.
103
+ * Set to false to instead use a legacy bilateral filter that can't be configured.
104
+ *
105
+ * The denoising filter runs after the SSAO calculations and is a very important step. Both options results in a so called bilateral being used, but the "expensive" one can be
106
+ * configured in several ways to fit your scene.
81
107
  */
82
108
  set expensiveBlur(b: boolean);
83
109
  get expensiveBlur(): boolean;
84
110
  /**
85
- * The radius around the analyzed pixel used by the SSAO post-process. Default value is 2.0
111
+ * The number of samples the bilateral filter uses in both dimensions when denoising the SSAO calculations. Default value is 16.
112
+ *
113
+ * A higher value should result in smoother shadows but will use more processing time in the shaders.
114
+ *
115
+ * A high value can cause the shadows to get to blurry or create visible artifacts (bands) near sharp details in the geometry. The artifacts can sometimes be mitigated by increasing the bilateralSoften setting.
86
116
  */
87
- radius: number;
117
+ bilateralSamples: number;
88
118
  /**
89
- * The base color of the SSAO post-process
90
- * The final result is "base + ssao" between [0, 1]
119
+ * Controls the shape of the denoising kernel used by the bilateral filter. Default value is 0.
120
+ *
121
+ * By default the bilateral filter acts like a box-filter, treating all samples on the same depth with equal weights. This is effective to maximize the denoising effect given a limited set of samples. However, it also often results in visible ghosting around sharp shadow regions and can spread out lines over large areas so they are no longer visible.
122
+ *
123
+ * Increasing this setting will make the filter pay less attention to samples further away from the center sample, reducing many artifacts but at the same time increasing noise.
124
+ *
125
+ * Useful value range is [0..1].
91
126
  */
92
- base: number;
127
+ bilateralSoften: number;
128
+ /**
129
+ * How forgiving the bilateral denoiser should be when rejecting samples. Default value is 0.
130
+ *
131
+ * A higher value results in the bilateral filter being more forgiving and thus doing a better job at denoising slanted and curved surfaces, but can lead to shadows spreading out around corners or between objects that are close to each other depth wise.
132
+ *
133
+ * Useful value range is normally [0..1], but higher values are allowed.
134
+ */
135
+ bilateralTolerance: number;
93
136
  /**
94
137
  * Support test.
95
138
  */
@@ -125,9 +168,12 @@ export declare class SSAO2RenderingPipeline extends PostProcessRenderPipeline {
125
168
  * @param disableGeometryBufferRenderer
126
169
  */
127
170
  dispose(disableGeometryBufferRenderer?: boolean): void;
128
- private _createBlurPostProcess;
129
171
  /** @internal */
130
172
  _rebuild(): void;
173
+ private _getSamplersForBlur;
174
+ private _getDefinesForBlur;
175
+ private _createBlurPostProcess;
176
+ private _createBlurFilter;
131
177
  private _bits;
132
178
  private _radicalInverse_VdC;
133
179
  private _hammersley;
@@ -22,7 +22,19 @@ import "../../../Shaders/ssaoCombine.fragment.js";
22
22
  */
23
23
  export class SSAO2RenderingPipeline extends PostProcessRenderPipeline {
24
24
  /**
25
- * Number of samples used for the SSAO calculations. Default value is 8
25
+ * Used in SSAO calculations to compensate for accuracy issues with depth values. Default 0.02.
26
+ *
27
+ * Normally you do not need to change this value, but you can experiment with it if you get a lot of in false self-occlusion on flat surfaces when using fewer than 16 samples. Useful range is normally [0..0.1] but higher values is allowed.
28
+ */
29
+ set epsilon(n) {
30
+ this._epsilon = n;
31
+ this._ssaoPostProcess.updateEffect(this._getDefinesForSSAO());
32
+ }
33
+ get epsilon() {
34
+ return this._epsilon;
35
+ }
36
+ /**
37
+ * Number of samples used for the SSAO calculations. Default value is 8.
26
38
  */
27
39
  set samples(n) {
28
40
  this._samples = n;
@@ -33,7 +45,7 @@ export class SSAO2RenderingPipeline extends PostProcessRenderPipeline {
33
45
  return this._samples;
34
46
  }
35
47
  /**
36
- * Number of samples to use for antialiasing
48
+ * Number of samples to use for antialiasing.
37
49
  */
38
50
  set textureSamples(n) {
39
51
  this._textureSamples = n;
@@ -60,12 +72,31 @@ export class SSAO2RenderingPipeline extends PostProcessRenderPipeline {
60
72
  return this._scene.prePassRenderer;
61
73
  }
62
74
  /**
63
- * If bilateral blur should be used
75
+ * Skips the denoising (blur) stage of the SSAO calculations.
76
+ *
77
+ * Useful to temporarily set while experimenting with the other SSAO2 settings.
78
+ */
79
+ set bypassBlur(b) {
80
+ const defines = this._getDefinesForBlur(this.expensiveBlur, b);
81
+ const samplers = this._getSamplersForBlur(b);
82
+ this._blurHPostProcess.updateEffect(defines.h, null, samplers);
83
+ this._blurVPostProcess.updateEffect(defines.v, null, samplers);
84
+ this._bypassBlur = b;
85
+ }
86
+ get bypassBlur() {
87
+ return this._bypassBlur;
88
+ }
89
+ /**
90
+ * Enables the configurable bilateral denoising (blurring) filter. Default is true.
91
+ * Set to false to instead use a legacy bilateral filter that can't be configured.
92
+ *
93
+ * The denoising filter runs after the SSAO calculations and is a very important step. Both options results in a so called bilateral being used, but the "expensive" one can be
94
+ * configured in several ways to fit your scene.
64
95
  */
65
96
  set expensiveBlur(b) {
66
- const expensive = b ? "#define EXPENSIVE\n" : "";
67
- this._blurHPostProcess.updateEffect(`#define BILATERAL_BLUR\n#define BILATERAL_BLUR_H\n#define SAMPLES 16\n${expensive}`, null, ["textureSampler", "depthSampler"]);
68
- this._blurVPostProcess.updateEffect(`#define BILATERAL_BLUR\n#define SAMPLES 16\n${expensive}`, null, ["textureSampler", "depthSampler"]);
97
+ const defines = this._getDefinesForBlur(b, this._bypassBlur);
98
+ this._blurHPostProcess.updateEffect(defines.h);
99
+ this._blurVPostProcess.updateEffect(defines.v);
69
100
  this._expensiveBlur = b;
70
101
  }
71
102
  get expensiveBlur() {
@@ -133,16 +164,16 @@ export class SSAO2RenderingPipeline extends PostProcessRenderPipeline {
133
164
  */
134
165
  this.maxZ = 100.0;
135
166
  /**
136
- * In order to save performances, SSAO radius is clamped on close geometry. This ratio changes by how much
167
+ * In order to save performances, SSAO radius is clamped on close geometry. This ratio changes by how much.
137
168
  */
138
169
  this.minZAspect = 0.2;
170
+ this._epsilon = 0.02;
139
171
  this._samples = 8;
140
172
  this._textureSamples = 1;
141
173
  /**
142
- * Force rendering the geometry through geometry buffer
174
+ * Force rendering the geometry through geometry buffer.
143
175
  */
144
176
  this._forceGeometryBuffer = false;
145
- this._expensiveBlur = true;
146
177
  /**
147
178
  * The radius around the analyzed pixel used by the SSAO post-process. Default value is 2.0
148
179
  */
@@ -152,9 +183,38 @@ export class SSAO2RenderingPipeline extends PostProcessRenderPipeline {
152
183
  * The final result is "base + ssao" between [0, 1]
153
184
  */
154
185
  this.base = 0;
186
+ this._bypassBlur = false;
187
+ this._expensiveBlur = true;
188
+ /**
189
+ * The number of samples the bilateral filter uses in both dimensions when denoising the SSAO calculations. Default value is 16.
190
+ *
191
+ * A higher value should result in smoother shadows but will use more processing time in the shaders.
192
+ *
193
+ * A high value can cause the shadows to get to blurry or create visible artifacts (bands) near sharp details in the geometry. The artifacts can sometimes be mitigated by increasing the bilateralSoften setting.
194
+ */
195
+ this.bilateralSamples = 16;
196
+ /**
197
+ * Controls the shape of the denoising kernel used by the bilateral filter. Default value is 0.
198
+ *
199
+ * By default the bilateral filter acts like a box-filter, treating all samples on the same depth with equal weights. This is effective to maximize the denoising effect given a limited set of samples. However, it also often results in visible ghosting around sharp shadow regions and can spread out lines over large areas so they are no longer visible.
200
+ *
201
+ * Increasing this setting will make the filter pay less attention to samples further away from the center sample, reducing many artifacts but at the same time increasing noise.
202
+ *
203
+ * Useful value range is [0..1].
204
+ */
205
+ this.bilateralSoften = 0;
206
+ /**
207
+ * How forgiving the bilateral denoiser should be when rejecting samples. Default value is 0.
208
+ *
209
+ * A higher value results in the bilateral filter being more forgiving and thus doing a better job at denoising slanted and curved surfaces, but can lead to shadows spreading out around corners or between objects that are close to each other depth wise.
210
+ *
211
+ * Useful value range is normally [0..1], but higher values are allowed.
212
+ */
213
+ this.bilateralTolerance = 0;
155
214
  this._bits = new Uint32Array(1);
156
215
  this._scene = scene;
157
216
  this._ratio = ratio;
217
+ this._textureType = textureType;
158
218
  this._forceGeometryBuffer = forceGeometryBuffer;
159
219
  if (!this.isSupported) {
160
220
  Logger.Error("The current engine does not support SSAO 2.");
@@ -170,11 +230,11 @@ export class SSAO2RenderingPipeline extends PostProcessRenderPipeline {
170
230
  scene.enablePrePassRenderer();
171
231
  }
172
232
  this._createRandomTexture();
173
- this._originalColorPostProcess = new PassPostProcess("SSAOOriginalSceneColor", 1.0, null, Texture.BILINEAR_SAMPLINGMODE, scene.getEngine(), undefined, textureType);
233
+ this._originalColorPostProcess = new PassPostProcess("SSAOOriginalSceneColor", 1.0, null, Texture.BILINEAR_SAMPLINGMODE, scene.getEngine(), undefined, this._textureType);
174
234
  this._originalColorPostProcess.samples = this.textureSamples;
175
235
  this._createSSAOPostProcess(1.0, textureType);
176
- this._createBlurPostProcess(ssaoRatio, blurRatio, textureType);
177
- this._createSSAOCombinePostProcess(blurRatio, textureType);
236
+ this._createBlurPostProcess(ssaoRatio, blurRatio, this._textureType);
237
+ this._createSSAOCombinePostProcess(blurRatio, this._textureType);
178
238
  // Set up pipeline
179
239
  this.addEffect(new PostProcessRenderEffect(scene.getEngine(), this.SSAOOriginalSceneColorEffect, () => {
180
240
  return this._originalColorPostProcess;
@@ -226,52 +286,50 @@ export class SSAO2RenderingPipeline extends PostProcessRenderPipeline {
226
286
  super.dispose();
227
287
  }
228
288
  // Private Methods
229
- _createBlurPostProcess(ssaoRatio, blurRatio, textureType) {
230
- this._samplerOffsets = [];
231
- const expensive = this.expensiveBlur;
232
- for (let i = -8; i < 8; i++) {
233
- this._samplerOffsets.push(i * 2 + 0.5);
289
+ /** @internal */
290
+ _rebuild() {
291
+ super._rebuild();
292
+ }
293
+ _getSamplersForBlur(disabled) {
294
+ return disabled ? ["textureSampler"] : ["textureSampler", "depthSampler"];
295
+ }
296
+ _getDefinesForBlur(bilateral, disabled) {
297
+ let define = "#define BLUR\n";
298
+ if (disabled) {
299
+ define += "#define BLUR_BYPASS\n";
234
300
  }
235
- this._blurHPostProcess = new PostProcess("BlurH", "ssao2", ["outSize", "samplerOffsets", "near", "far", "radius"], ["depthSampler"], ssaoRatio, null, Texture.TRILINEAR_SAMPLINGMODE, this._scene.getEngine(), false, "#define BILATERAL_BLUR\n#define BILATERAL_BLUR_H\n#define SAMPLES 16\n#define EXPENSIVE " + (expensive ? "1" : "0") + "\n", textureType);
236
- this._blurHPostProcess.onApply = (effect) => {
237
- if (!this._scene.activeCamera) {
238
- return;
239
- }
240
- effect.setFloat("outSize", this._ssaoCombinePostProcess.width > 0 ? this._ssaoCombinePostProcess.width : this._originalColorPostProcess.width);
241
- effect.setFloat("near", this._scene.activeCamera.minZ);
242
- effect.setFloat("far", this._scene.activeCamera.maxZ);
243
- effect.setFloat("radius", this.radius);
244
- if (this._geometryBufferRenderer) {
245
- effect.setTexture("depthSampler", this._geometryBufferRenderer.getGBuffer().textures[0]);
246
- }
247
- else if (this._prePassRenderer) {
248
- effect.setTexture("depthSampler", this._prePassRenderer.getRenderTarget().textures[this._prePassRenderer.getIndex(5)]);
249
- }
250
- effect.setArray("samplerOffsets", this._samplerOffsets);
251
- };
252
- this._blurVPostProcess = new PostProcess("BlurV", "ssao2", ["outSize", "samplerOffsets", "near", "far", "radius"], ["depthSampler"], blurRatio, null, Texture.TRILINEAR_SAMPLINGMODE, this._scene.getEngine(), false, "#define BILATERAL_BLUR\n#define BILATERAL_BLUR_V\n#define SAMPLES 16\n#define EXPENSIVE " + (expensive ? "1" : "0") + "\n", textureType);
253
- this._blurVPostProcess.onApply = (effect) => {
301
+ if (!bilateral) {
302
+ define += "#define BLUR_LEGACY\n";
303
+ }
304
+ return { h: define + "#define BLUR_H\n", v: define };
305
+ }
306
+ _createBlurPostProcess(ssaoRatio, blurRatio, textureType) {
307
+ const defines = this._getDefinesForBlur(this.expensiveBlur, this.bypassBlur);
308
+ const samplers = this._getSamplersForBlur(this.bypassBlur);
309
+ this._blurHPostProcess = this._createBlurFilter("BlurH", samplers, ssaoRatio, defines.h, textureType, true);
310
+ this._blurVPostProcess = this._createBlurFilter("BlurV", samplers, blurRatio, defines.v, textureType, false);
311
+ }
312
+ _createBlurFilter(name, samplers, ratio, defines, textureType, horizontal) {
313
+ const blurFilter = new PostProcess(name, "ssao2", ["outSize", "samples", "soften", "tolerance"], samplers, ratio, null, Texture.BILINEAR_SAMPLINGMODE, this._scene.getEngine(), false, defines, textureType);
314
+ blurFilter.onApply = (effect) => {
254
315
  if (!this._scene.activeCamera) {
255
316
  return;
256
317
  }
257
- effect.setFloat("outSize", this._ssaoCombinePostProcess.height > 0 ? this._ssaoCombinePostProcess.height : this._originalColorPostProcess.height);
258
- effect.setFloat("near", this._scene.activeCamera.minZ);
259
- effect.setFloat("far", this._scene.activeCamera.maxZ);
260
- effect.setFloat("radius", this.radius);
318
+ const ssaoCombineSize = horizontal ? this._ssaoCombinePostProcess.width : this._ssaoCombinePostProcess.height;
319
+ const originalColorSize = horizontal ? this._originalColorPostProcess.width : this._originalColorPostProcess.height;
320
+ effect.setFloat("outSize", ssaoCombineSize > 0 ? ssaoCombineSize : originalColorSize);
321
+ effect.setInt("samples", this.bilateralSamples);
322
+ effect.setFloat("soften", this.bilateralSoften);
323
+ effect.setFloat("tolerance", this.bilateralTolerance);
261
324
  if (this._geometryBufferRenderer) {
262
325
  effect.setTexture("depthSampler", this._geometryBufferRenderer.getGBuffer().textures[0]);
263
326
  }
264
327
  else if (this._prePassRenderer) {
265
328
  effect.setTexture("depthSampler", this._prePassRenderer.getRenderTarget().textures[this._prePassRenderer.getIndex(5)]);
266
329
  }
267
- effect.setArray("samplerOffsets", this._samplerOffsets);
268
330
  };
269
- this._blurHPostProcess.samples = this.textureSamples;
270
- this._blurVPostProcess.samples = this.textureSamples;
271
- }
272
- /** @internal */
273
- _rebuild() {
274
- super._rebuild();
331
+ blurFilter.samples = this.textureSamples;
332
+ return blurFilter;
275
333
  }
276
334
  //Van der Corput radical inverse
277
335
  _radicalInverse_VdC(i) {
@@ -312,7 +370,7 @@ export class SSAO2RenderingPipeline extends PostProcessRenderPipeline {
312
370
  return result;
313
371
  }
314
372
  _getDefinesForSSAO() {
315
- const defines = "#define SAMPLES " + this.samples + "\n#define SSAO";
373
+ const defines = `#define SSAO\n#define SAMPLES ${this.samples}\n#define EPSILON ${this.epsilon.toFixed(4)}`;
316
374
  return defines;
317
375
  }
318
376
  _createSSAOPostProcess(ratio, textureType) {
@@ -329,7 +387,6 @@ export class SSAO2RenderingPipeline extends PostProcessRenderPipeline {
329
387
  "range",
330
388
  "projection",
331
389
  "near",
332
- "far",
333
390
  "texelSize",
334
391
  "xViewport",
335
392
  "yViewport",
@@ -352,7 +409,6 @@ export class SSAO2RenderingPipeline extends PostProcessRenderPipeline {
352
409
  effect.setFloat("minZAspect", this.minZAspect);
353
410
  effect.setFloat("base", this.base);
354
411
  effect.setFloat("near", this._scene.activeCamera.minZ);
355
- effect.setFloat("far", this._scene.activeCamera.maxZ);
356
412
  if (this._scene.activeCamera.mode === Camera.PERSPECTIVE_CAMERA) {
357
413
  effect.setMatrix3x3("depthProjection", SSAO2RenderingPipeline.PERSPECTIVE_DEPTH_PROJECTION);
358
414
  effect.setFloat("xViewport", Math.tan(this._scene.activeCamera.fov / 2) * this._scene.getEngine().getAspectRatio(this._scene.activeCamera, true));
@@ -396,7 +452,7 @@ export class SSAO2RenderingPipeline extends PostProcessRenderPipeline {
396
452
  }
397
453
  _createRandomTexture() {
398
454
  const size = 128;
399
- this._randomTexture = new DynamicTexture("SSAORandomTexture", size, this._scene, false, Texture.TRILINEAR_SAMPLINGMODE);
455
+ this._randomTexture = new DynamicTexture("SSAORandomTexture", size, this._scene, false, Texture.BILINEAR_SAMPLINGMODE);
400
456
  this._randomTexture.wrapU = Texture.WRAP_ADDRESSMODE;
401
457
  this._randomTexture.wrapV = Texture.WRAP_ADDRESSMODE;
402
458
  const context = this._randomTexture.getContext();
@@ -436,7 +492,7 @@ export class SSAO2RenderingPipeline extends PostProcessRenderPipeline {
436
492
  * @returns An instantiated pipeline from the serialized object.
437
493
  */
438
494
  static Parse(source, scene, rootUrl) {
439
- return SerializationHelper.Parse(() => new SSAO2RenderingPipeline(source._name, scene, source._ratio), source, scene, rootUrl);
495
+ return SerializationHelper.Parse(() => new SSAO2RenderingPipeline(source._name, scene, source._ratio, undefined, source._forceGeometryBuffer, source._textureType), source, scene, rootUrl);
440
496
  }
441
497
  }
442
498
  SSAO2RenderingPipeline.ORTHO_DEPTH_PROJECTION = [1, 0, 0, 0, 1, 0, 0, 0, 1];
@@ -450,23 +506,44 @@ __decorate([
450
506
  __decorate([
451
507
  serialize()
452
508
  ], SSAO2RenderingPipeline.prototype, "minZAspect", void 0);
509
+ __decorate([
510
+ serialize("epsilon")
511
+ ], SSAO2RenderingPipeline.prototype, "_epsilon", void 0);
453
512
  __decorate([
454
513
  serialize("samples")
455
514
  ], SSAO2RenderingPipeline.prototype, "_samples", void 0);
456
515
  __decorate([
457
516
  serialize("textureSamples")
458
517
  ], SSAO2RenderingPipeline.prototype, "_textureSamples", void 0);
518
+ __decorate([
519
+ serialize()
520
+ ], SSAO2RenderingPipeline.prototype, "_forceGeometryBuffer", void 0);
459
521
  __decorate([
460
522
  serialize()
461
523
  ], SSAO2RenderingPipeline.prototype, "_ratio", void 0);
462
524
  __decorate([
463
- serialize("expensiveBlur")
464
- ], SSAO2RenderingPipeline.prototype, "_expensiveBlur", void 0);
525
+ serialize()
526
+ ], SSAO2RenderingPipeline.prototype, "_textureType", void 0);
465
527
  __decorate([
466
528
  serialize()
467
529
  ], SSAO2RenderingPipeline.prototype, "radius", void 0);
468
530
  __decorate([
469
531
  serialize()
470
532
  ], SSAO2RenderingPipeline.prototype, "base", void 0);
533
+ __decorate([
534
+ serialize("bypassBlur")
535
+ ], SSAO2RenderingPipeline.prototype, "_bypassBlur", void 0);
536
+ __decorate([
537
+ serialize("expensiveBlur")
538
+ ], SSAO2RenderingPipeline.prototype, "_expensiveBlur", void 0);
539
+ __decorate([
540
+ serialize()
541
+ ], SSAO2RenderingPipeline.prototype, "bilateralSamples", void 0);
542
+ __decorate([
543
+ serialize()
544
+ ], SSAO2RenderingPipeline.prototype, "bilateralSoften", void 0);
545
+ __decorate([
546
+ serialize()
547
+ ], SSAO2RenderingPipeline.prototype, "bilateralTolerance", void 0);
471
548
  RegisterClass("BABYLON.SSAO2RenderingPipeline", SSAO2RenderingPipeline);
472
549
  //# sourceMappingURL=ssao2RenderingPipeline.js.map