@babylonjs/core 6.5.0 → 6.6.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.
- package/Animations/animation.d.ts +4 -0
- package/Animations/animation.js +13 -1
- package/Animations/animation.js.map +1 -1
- package/Animations/runtimeAnimation.js +9 -1
- package/Animations/runtimeAnimation.js.map +1 -1
- package/Audio/sound.js +3 -1
- package/Audio/sound.js.map +1 -1
- package/Bones/boneLookController.d.ts +5 -0
- package/Bones/boneLookController.js +17 -3
- package/Bones/boneLookController.js.map +1 -1
- package/Engines/Processors/iShaderProcessor.d.ts +1 -0
- package/Engines/Processors/iShaderProcessor.js.map +1 -1
- package/Engines/Processors/shaderCodeNode.js +3 -2
- package/Engines/Processors/shaderCodeNode.js.map +1 -1
- package/Engines/Processors/shaderProcessor.d.ts +1 -0
- package/Engines/Processors/shaderProcessor.js +45 -44
- package/Engines/Processors/shaderProcessor.js.map +1 -1
- package/Engines/WebGL/webGL2ShaderProcessors.d.ts +1 -0
- package/Engines/WebGL/webGL2ShaderProcessors.js +4 -0
- package/Engines/WebGL/webGL2ShaderProcessors.js.map +1 -1
- package/Engines/WebGPU/webgpuShaderProcessorsGLSL.d.ts +1 -0
- package/Engines/WebGPU/webgpuShaderProcessorsGLSL.js +16 -7
- package/Engines/WebGPU/webgpuShaderProcessorsGLSL.js.map +1 -1
- package/Engines/engine.js +4 -4
- package/Engines/engine.js.map +1 -1
- package/Engines/thinEngine.js +10 -5
- package/Engines/thinEngine.js.map +1 -1
- package/Layers/layer.d.ts +5 -0
- package/Layers/layer.js +16 -6
- package/Layers/layer.js.map +1 -1
- package/Materials/Node/Blocks/PBR/anisotropyBlock.d.ts +4 -0
- package/Materials/Node/Blocks/PBR/anisotropyBlock.js +10 -0
- package/Materials/Node/Blocks/PBR/anisotropyBlock.js.map +1 -1
- package/Materials/PBR/pbrAnisotropicConfiguration.d.ts +26 -0
- package/Materials/PBR/pbrAnisotropicConfiguration.js +47 -0
- package/Materials/PBR/pbrAnisotropicConfiguration.js.map +1 -1
- package/Materials/Textures/multiRenderTarget.js +1 -2
- package/Materials/Textures/multiRenderTarget.js.map +1 -1
- package/Materials/Textures/renderTargetTexture.d.ts +6 -1
- package/Materials/Textures/renderTargetTexture.js.map +1 -1
- package/Meshes/Builders/textBuilder.d.ts +2 -1
- package/Meshes/Builders/textBuilder.js +14 -2
- package/Meshes/Builders/textBuilder.js.map +1 -1
- package/Misc/assetsManager.d.ts +78 -0
- package/Misc/assetsManager.js +60 -1
- package/Misc/assetsManager.js.map +1 -1
- package/Misc/filesInput.d.ts +1 -1
- package/Misc/filesInput.js +5 -5
- package/Misc/filesInput.js.map +1 -1
- package/Physics/v2/Plugins/havokPlugin.js +2 -2
- package/Physics/v2/Plugins/havokPlugin.js.map +1 -1
- package/Physics/v2/physicsAggregate.d.ts +1 -0
- package/Physics/v2/physicsAggregate.js +6 -5
- package/Physics/v2/physicsAggregate.js.map +1 -1
- package/PostProcesses/RenderPipeline/Pipelines/ssrRenderingPipeline.d.ts +10 -1
- package/PostProcesses/RenderPipeline/Pipelines/ssrRenderingPipeline.js +77 -10
- package/PostProcesses/RenderPipeline/Pipelines/ssrRenderingPipeline.js.map +1 -1
- package/Rendering/depthRenderer.js +1 -0
- package/Rendering/depthRenderer.js.map +1 -1
- package/Shaders/ShadersInclude/pbrBlockAnisotropic.js +6 -3
- package/Shaders/ShadersInclude/pbrBlockAnisotropic.js.map +1 -1
- package/Shaders/ShadersInclude/pbrHelperFunctions.js +4 -1
- package/Shaders/ShadersInclude/pbrHelperFunctions.js.map +1 -1
- package/Shaders/ShadersInclude/screenSpaceRayTrace.js +4 -1
- package/Shaders/ShadersInclude/screenSpaceRayTrace.js.map +1 -1
- package/Shaders/glowMapGeneration.fragment.js +1 -1
- package/Shaders/glowMapGeneration.fragment.js.map +1 -1
- package/Shaders/pbr.fragment.js +1 -1
- package/Shaders/pbr.fragment.js.map +1 -1
- package/Shaders/screenSpaceReflection2.fragment.d.ts +1 -0
- package/Shaders/screenSpaceReflection2.fragment.js +16 -10
- package/Shaders/screenSpaceReflection2.fragment.js.map +1 -1
- package/Shaders/screenSpaceReflection2BlurCombiner.fragment.d.ts +2 -0
- package/Shaders/screenSpaceReflection2BlurCombiner.fragment.js +13 -2
- package/Shaders/screenSpaceReflection2BlurCombiner.fragment.js.map +1 -1
- package/package.json +1 -1
- package/scene.js +18 -20
- package/scene.js.map +1 -1
|
@@ -97,6 +97,7 @@ export declare class PhysicsAggregate {
|
|
|
97
97
|
*/
|
|
98
98
|
type: PhysicsShapeType | PhysicsShape, _options?: PhysicsAggregateParameters, _scene?: Scene | undefined);
|
|
99
99
|
private _getObjectBoundingBox;
|
|
100
|
+
private _hasVertices;
|
|
100
101
|
private _addSizeOptions;
|
|
101
102
|
/**
|
|
102
103
|
* Releases the body, shape and material
|
|
@@ -75,6 +75,9 @@ export class PhysicsAggregate {
|
|
|
75
75
|
return new BoundingBox(new Vector3(-0.5, -0.5, -0.5), new Vector3(0.5, 0.5, 0.5));
|
|
76
76
|
}
|
|
77
77
|
}
|
|
78
|
+
_hasVertices(node) {
|
|
79
|
+
return (node === null || node === void 0 ? void 0 : node.getTotalVertices()) > 0;
|
|
80
|
+
}
|
|
78
81
|
_addSizeOptions() {
|
|
79
82
|
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
80
83
|
this.transformNode.computeWorldMatrix(true);
|
|
@@ -120,13 +123,11 @@ export class PhysicsAggregate {
|
|
|
120
123
|
break;
|
|
121
124
|
case PhysicsShapeType.MESH:
|
|
122
125
|
case PhysicsShapeType.CONVEX_HULL:
|
|
123
|
-
if (!this._options.mesh &&
|
|
126
|
+
if (!this._options.mesh && this._hasVertices(this.transformNode)) {
|
|
124
127
|
this._options.mesh = this.transformNode;
|
|
125
128
|
}
|
|
126
|
-
else if (!(this._options.mesh
|
|
127
|
-
|
|
128
|
-
(this._options.mesh.getClassName() === "Mesh" || this._options.mesh.getClassName() === "InstancedMesh"))) {
|
|
129
|
-
throw new Error("No valid mesh was provided for mesh or convex hull shape parameter.");
|
|
129
|
+
else if (!this._options.mesh || !this._hasVertices(this._options.mesh)) {
|
|
130
|
+
throw new Error("No valid mesh was provided for mesh or convex hull shape parameter. Please provide a mesh with valid geometry (number of vertices greater than 0).");
|
|
130
131
|
}
|
|
131
132
|
break;
|
|
132
133
|
case PhysicsShapeType.BOX:
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"physicsAggregate.js","sourceRoot":"","sources":["../../../../../lts/core/generated/Physics/v2/physicsAggregate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAE5C,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAG3C,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAC1E,OAAO,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AACjD,OAAO,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAM7E,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AA6DxD;;;;;;GAMG;AACH,MAAM,OAAO,gBAAgB;IAoBzB;IACI;;OAEG;IACI,aAA4B;IACnC;;OAEG;IACI,IAAqC,EACpC,WAAuC,EAAE,IAAI,EAAE,CAAC,EAAE,EAClD,MAAc;;QANf,kBAAa,GAAb,aAAa,CAAe;QAI5B,SAAI,GAAJ,IAAI,CAAiC;QACpC,aAAQ,GAAR,QAAQ,CAA0C;QAClD,WAAM,GAAN,MAAM,CAAQ;QAdlB,8BAAyB,GAAG,IAAI,CAAC;QAgBrC,eAAe;QACf,IAAI,CAAC,IAAI,CAAC,aAAa,EAAE;YACrB,MAAM,CAAC,KAAK,CAAC,wDAAwD,CAAC,CAAC;YACvE,OAAO;SACV;QACD,MAAM,CAAC,GAAG,aAA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,mCAAI,UAAU,CAAC,QAAQ,EAAE,CAAC;gBACzE,MAAM;SACb;IACL,CAAC;IAED;;OAEG;IACI,OAAO;QACV,IAAI,IAAI,CAAC,oBAAoB,EAAE;YAC3B,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC,mBAAmB,CAAC,MAAM,CAAC,IAAI,CAAC,oBAAoB,CAAC,CAAC;YAC9E,IAAI,CAAC,oBAAoB,GAAG,IAAI,CAAC;SACpC;QACD,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC;QACpB,IAAI,IAAI,CAAC,yBAAyB,EAAE;YAChC,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC;SACxB;IACL,CAAC;CACJ","sourcesContent":["import { PhysicsBody } from \"./physicsBody\";\r\nimport type { PhysicsMaterial } from \"./physicsMaterial\";\r\nimport { PhysicsShape } from \"./physicsShape\";\r\nimport { Logger } from \"../../Misc/logger\";\r\nimport type { Scene } from \"../../scene\";\r\nimport type { TransformNode } from \"../../Meshes/transformNode\";\r\nimport { Quaternion, TmpVectors, Vector3 } from \"../../Maths/math.vector\";\r\nimport { Scalar } from \"../../Maths/math.scalar\";\r\nimport { PhysicsMotionType, PhysicsShapeType } from \"./IPhysicsEnginePlugin\";\r\nimport type { Mesh } from \"../../Meshes/mesh\";\r\nimport type { Observer } from \"../../Misc/observable\";\r\nimport type { Nullable } from \"../../types\";\r\nimport type { Node } from \"../../node\";\r\nimport type { AbstractMesh } from \"../../Meshes/abstractMesh\";\r\nimport { BoundingBox } from \"../../Culling/boundingBox\";\r\n\r\n/**\r\n * The interface for the physics aggregate parameters\r\n */\r\nexport interface PhysicsAggregateParameters {\r\n /**\r\n * The mass of the physics aggregate\r\n */\r\n mass: number;\r\n\r\n /**\r\n * The friction of the physics aggregate\r\n */\r\n friction?: number;\r\n\r\n /**\r\n * The coefficient of restitution of the physics aggregate\r\n */\r\n restitution?: number;\r\n\r\n /**\r\n * Radius for sphere, cylinder and capsule\r\n */\r\n radius?: number;\r\n\r\n /**\r\n * Starting point for cylinder/capsule\r\n */\r\n pointA?: Vector3;\r\n\r\n /**\r\n * Ending point for cylinder/capsule\r\n */\r\n pointB?: Vector3;\r\n\r\n /**\r\n * Extents for box\r\n */\r\n extents?: Vector3;\r\n\r\n /**\r\n * Orientation for box\r\n */\r\n rotation?: Quaternion;\r\n\r\n /**\r\n * mesh local center\r\n */\r\n center?: Vector3;\r\n\r\n /**\r\n * mesh object. Used for mesh and convex hull aggregates.\r\n */\r\n mesh?: Mesh;\r\n\r\n /**\r\n * Physics engine will try to make this body sleeping and not active\r\n */\r\n startAsleep?: boolean;\r\n}\r\n/**\r\n * Helper class to create and interact with a PhysicsAggregate.\r\n * This is a transition object that works like Physics Plugin V1 Impostors.\r\n * This helper instanciate all mandatory physics objects to get a body/shape and material.\r\n * It's less efficient that handling body and shapes independently but for prototyping or\r\n * a small numbers of physics objects, it's good enough.\r\n */\r\nexport class PhysicsAggregate {\r\n /**\r\n * The body that is associated with this aggregate\r\n */\r\n public body: PhysicsBody;\r\n\r\n /**\r\n * The shape that is associated with this aggregate\r\n */\r\n public shape: PhysicsShape;\r\n\r\n /**\r\n * The material that is associated with this aggregate\r\n */\r\n public material: PhysicsMaterial;\r\n\r\n private _disposeShapeWhenDisposed = true;\r\n\r\n private _nodeDisposeObserver: Nullable<Observer<Node>>;\r\n\r\n constructor(\r\n /**\r\n * The physics-enabled object used as the physics aggregate\r\n */\r\n public transformNode: TransformNode,\r\n /**\r\n * The type of the physics aggregate\r\n */\r\n public type: PhysicsShapeType | PhysicsShape,\r\n private _options: PhysicsAggregateParameters = { mass: 0 },\r\n private _scene?: Scene\r\n ) {\r\n //sanity check!\r\n if (!this.transformNode) {\r\n Logger.Error(\"No object was provided. A physics object is obligatory\");\r\n return;\r\n }\r\n const m = transformNode as Mesh;\r\n if (this.transformNode.parent && this._options.mass !== 0 && m.hasThinInstances) {\r\n Logger.Warn(\r\n \"A physics body has been created for an object which has a parent and thin instances. Babylon physics currently works in local space so unexpected issues may occur.\"\r\n );\r\n }\r\n\r\n // Legacy support for old syntax.\r\n if (!this._scene && transformNode.getScene) {\r\n this._scene = transformNode.getScene();\r\n }\r\n\r\n if (!this._scene) {\r\n return;\r\n }\r\n\r\n //default options params\r\n this._options.mass = _options.mass === void 0 ? 0 : _options.mass;\r\n this._options.friction = _options.friction === void 0 ? 0.2 : _options.friction;\r\n this._options.restitution = _options.restitution === void 0 ? 0.2 : _options.restitution;\r\n\r\n const motionType = this._options.mass === 0 ? PhysicsMotionType.STATIC : PhysicsMotionType.DYNAMIC;\r\n const startAsleep = this._options.startAsleep ?? false;\r\n this.body = new PhysicsBody(transformNode, motionType, startAsleep, this._scene);\r\n this._addSizeOptions();\r\n if ((type as any).getClassName && (type as any).getClassName() === \"PhysicsShape\") {\r\n this.shape = type as PhysicsShape;\r\n this._disposeShapeWhenDisposed = false;\r\n } else {\r\n this.shape = new PhysicsShape({ type: type as PhysicsShapeType, parameters: this._options as any }, this._scene);\r\n }\r\n\r\n this.material = { friction: this._options.friction, restitution: this._options.restitution };\r\n this.body.shape = this.shape;\r\n this.shape.material = this.material;\r\n\r\n this.body.setMassProperties({ mass: this._options.mass });\r\n\r\n this._nodeDisposeObserver = this.transformNode.onDisposeObservable.add(() => {\r\n this.dispose();\r\n });\r\n }\r\n\r\n private _getObjectBoundingBox() {\r\n if ((this.transformNode as AbstractMesh).getRawBoundingInfo) {\r\n return (this.transformNode as AbstractMesh).getRawBoundingInfo().boundingBox;\r\n } else {\r\n return new BoundingBox(new Vector3(-0.5, -0.5, -0.5), new Vector3(0.5, 0.5, 0.5));\r\n }\r\n }\r\n\r\n private _addSizeOptions(): void {\r\n this.transformNode.computeWorldMatrix(true);\r\n const bb = this._getObjectBoundingBox();\r\n const extents = TmpVectors.Vector3[0];\r\n extents.copyFrom(bb.extendSize);\r\n extents.scaleInPlace(2);\r\n extents.multiplyInPlace(this.transformNode.scaling);\r\n\r\n const min = TmpVectors.Vector3[1];\r\n min.copyFrom(bb.minimum);\r\n min.multiplyInPlace(this.transformNode.scaling);\r\n\r\n if (!this._options.center) {\r\n const center = new Vector3();\r\n center.copyFrom(bb.center);\r\n center.multiplyInPlace(this.transformNode.scaling);\r\n this._options.center = center;\r\n }\r\n\r\n switch (this.type) {\r\n case PhysicsShapeType.SPHERE:\r\n if (!this._options.radius && Scalar.WithinEpsilon(extents.x, extents.y, 0.0001) && Scalar.WithinEpsilon(extents.x, extents.z, 0.0001)) {\r\n this._options.radius = extents.x / 2;\r\n } else if (!this._options.radius) {\r\n Logger.Warn(\"Non uniform scaling is unsupported for sphere shapes. Setting the radius to the biggest bounding box extent.\");\r\n this._options.radius = Math.max(extents.x, extents.y, extents.z) / 2;\r\n }\r\n break;\r\n case PhysicsShapeType.CAPSULE:\r\n {\r\n const capRadius = extents.x / 2;\r\n this._options.radius = this._options.radius ?? capRadius;\r\n this._options.pointA = this._options.pointA ?? new Vector3(0, min.y + capRadius, 0);\r\n this._options.pointB = this._options.pointB ?? new Vector3(0, min.y + extents.y - capRadius, 0);\r\n }\r\n break;\r\n case PhysicsShapeType.CYLINDER:\r\n {\r\n const capRadius = extents.x / 2;\r\n this._options.radius = this._options.radius ?? capRadius;\r\n this._options.pointA = this._options.pointA ?? new Vector3(0, min.y, 0);\r\n this._options.pointB = this._options.pointB ?? new Vector3(0, min.y + extents.y, 0);\r\n }\r\n break;\r\n case PhysicsShapeType.MESH:\r\n case PhysicsShapeType.CONVEX_HULL:\r\n if (!this._options.mesh && (this.transformNode.getClassName() === \"Mesh\" || this.transformNode.getClassName() === \"InstancedMesh\")) {\r\n this._options.mesh = this.transformNode as Mesh;\r\n } else if (\r\n !(\r\n this._options.mesh &&\r\n this._options.mesh.getClassName &&\r\n (this._options.mesh.getClassName() === \"Mesh\" || this._options.mesh.getClassName() === \"InstancedMesh\")\r\n )\r\n ) {\r\n throw new Error(\"No valid mesh was provided for mesh or convex hull shape parameter.\");\r\n }\r\n break;\r\n case PhysicsShapeType.BOX:\r\n this._options.extents = this._options.extents ?? new Vector3(extents.x, extents.y, extents.z);\r\n this._options.rotation = this._options.rotation ?? Quaternion.Identity();\r\n break;\r\n }\r\n }\r\n\r\n /**\r\n * Releases the body, shape and material\r\n */\r\n public dispose(): void {\r\n if (this._nodeDisposeObserver) {\r\n this.body.transformNode.onDisposeObservable.remove(this._nodeDisposeObserver);\r\n this._nodeDisposeObserver = null;\r\n }\r\n this.body.dispose();\r\n if (this._disposeShapeWhenDisposed) {\r\n this.shape.dispose();\r\n }\r\n }\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"file":"physicsAggregate.js","sourceRoot":"","sources":["../../../../../lts/core/generated/Physics/v2/physicsAggregate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAE5C,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAG3C,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAC1E,OAAO,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AACjD,OAAO,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAM7E,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AA6DxD;;;;;;GAMG;AACH,MAAM,OAAO,gBAAgB;IAoBzB;IACI;;OAEG;IACI,aAA4B;IACnC;;OAEG;IACI,IAAqC,EACpC,WAAuC,EAAE,IAAI,EAAE,CAAC,EAAE,EAClD,MAAc;;QANf,kBAAa,GAAb,aAAa,CAAe;QAI5B,SAAI,GAAJ,IAAI,CAAiC;QACpC,aAAQ,GAAR,QAAQ,CAA0C;QAClD,WAAM,GAAN,MAAM,CAAQ;QAdlB,8BAAyB,GAAG,IAAI,CAAC;QAgBrC,eAAe;QACf,IAAI,CAAC,IAAI,CAAC,aAAa,EAAE;YACrB,MAAM,CAAC,KAAK,C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AAI,UAAU,CAAC,QAAQ,EAAE,CAAC;gBACzE,MAAM;SACb;IACL,CAAC;IAED;;OAEG;IACI,OAAO;QACV,IAAI,IAAI,CAAC,oBAAoB,EAAE;YAC3B,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC,mBAAmB,CAAC,MAAM,CAAC,IAAI,CAAC,oBAAoB,CAAC,CAAC;YAC9E,IAAI,CAAC,oBAAoB,GAAG,IAAI,CAAC;SACpC;QACD,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC;QACpB,IAAI,IAAI,CAAC,yBAAyB,EAAE;YAChC,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC;SACxB;IACL,CAAC;CACJ","sourcesContent":["import { PhysicsBody } from \"./physicsBody\";\r\nimport type { PhysicsMaterial } from \"./physicsMaterial\";\r\nimport { PhysicsShape } from \"./physicsShape\";\r\nimport { Logger } from \"../../Misc/logger\";\r\nimport type { Scene } from \"../../scene\";\r\nimport type { TransformNode } from \"../../Meshes/transformNode\";\r\nimport { Quaternion, TmpVectors, Vector3 } from \"../../Maths/math.vector\";\r\nimport { Scalar } from \"../../Maths/math.scalar\";\r\nimport { PhysicsMotionType, PhysicsShapeType } from \"./IPhysicsEnginePlugin\";\r\nimport type { Mesh } from \"../../Meshes/mesh\";\r\nimport type { Observer } from \"../../Misc/observable\";\r\nimport type { Nullable } from \"../../types\";\r\nimport type { Node } from \"../../node\";\r\nimport type { AbstractMesh } from \"../../Meshes/abstractMesh\";\r\nimport { BoundingBox } from \"../../Culling/boundingBox\";\r\n\r\n/**\r\n * The interface for the physics aggregate parameters\r\n */\r\nexport interface PhysicsAggregateParameters {\r\n /**\r\n * The mass of the physics aggregate\r\n */\r\n mass: number;\r\n\r\n /**\r\n * The friction of the physics aggregate\r\n */\r\n friction?: number;\r\n\r\n /**\r\n * The coefficient of restitution of the physics aggregate\r\n */\r\n restitution?: number;\r\n\r\n /**\r\n * Radius for sphere, cylinder and capsule\r\n */\r\n radius?: number;\r\n\r\n /**\r\n * Starting point for cylinder/capsule\r\n */\r\n pointA?: Vector3;\r\n\r\n /**\r\n * Ending point for cylinder/capsule\r\n */\r\n pointB?: Vector3;\r\n\r\n /**\r\n * Extents for box\r\n */\r\n extents?: Vector3;\r\n\r\n /**\r\n * Orientation for box\r\n */\r\n rotation?: Quaternion;\r\n\r\n /**\r\n * mesh local center\r\n */\r\n center?: Vector3;\r\n\r\n /**\r\n * mesh object. Used for mesh and convex hull aggregates.\r\n */\r\n mesh?: Mesh;\r\n\r\n /**\r\n * Physics engine will try to make this body sleeping and not active\r\n */\r\n startAsleep?: boolean;\r\n}\r\n/**\r\n * Helper class to create and interact with a PhysicsAggregate.\r\n * This is a transition object that works like Physics Plugin V1 Impostors.\r\n * This helper instanciate all mandatory physics objects to get a body/shape and material.\r\n * It's less efficient that handling body and shapes independently but for prototyping or\r\n * a small numbers of physics objects, it's good enough.\r\n */\r\nexport class PhysicsAggregate {\r\n /**\r\n * The body that is associated with this aggregate\r\n */\r\n public body: PhysicsBody;\r\n\r\n /**\r\n * The shape that is associated with this aggregate\r\n */\r\n public shape: PhysicsShape;\r\n\r\n /**\r\n * The material that is associated with this aggregate\r\n */\r\n public material: PhysicsMaterial;\r\n\r\n private _disposeShapeWhenDisposed = true;\r\n\r\n private _nodeDisposeObserver: Nullable<Observer<Node>>;\r\n\r\n constructor(\r\n /**\r\n * The physics-enabled object used as the physics aggregate\r\n */\r\n public transformNode: TransformNode,\r\n /**\r\n * The type of the physics aggregate\r\n */\r\n public type: PhysicsShapeType | PhysicsShape,\r\n private _options: PhysicsAggregateParameters = { mass: 0 },\r\n private _scene?: Scene\r\n ) {\r\n //sanity check!\r\n if (!this.transformNode) {\r\n Logger.Error(\"No object was provided. A physics object is obligatory\");\r\n return;\r\n }\r\n const m = transformNode as Mesh;\r\n if (this.transformNode.parent && this._options.mass !== 0 && m.hasThinInstances) {\r\n Logger.Warn(\r\n \"A physics body has been created for an object which has a parent and thin instances. Babylon physics currently works in local space so unexpected issues may occur.\"\r\n );\r\n }\r\n\r\n // Legacy support for old syntax.\r\n if (!this._scene && transformNode.getScene) {\r\n this._scene = transformNode.getScene();\r\n }\r\n\r\n if (!this._scene) {\r\n return;\r\n }\r\n\r\n //default options params\r\n this._options.mass = _options.mass === void 0 ? 0 : _options.mass;\r\n this._options.friction = _options.friction === void 0 ? 0.2 : _options.friction;\r\n this._options.restitution = _options.restitution === void 0 ? 0.2 : _options.restitution;\r\n\r\n const motionType = this._options.mass === 0 ? PhysicsMotionType.STATIC : PhysicsMotionType.DYNAMIC;\r\n const startAsleep = this._options.startAsleep ?? false;\r\n this.body = new PhysicsBody(transformNode, motionType, startAsleep, this._scene);\r\n this._addSizeOptions();\r\n if ((type as any).getClassName && (type as any).getClassName() === \"PhysicsShape\") {\r\n this.shape = type as PhysicsShape;\r\n this._disposeShapeWhenDisposed = false;\r\n } else {\r\n this.shape = new PhysicsShape({ type: type as PhysicsShapeType, parameters: this._options as any }, this._scene);\r\n }\r\n\r\n this.material = { friction: this._options.friction, restitution: this._options.restitution };\r\n this.body.shape = this.shape;\r\n this.shape.material = this.material;\r\n\r\n this.body.setMassProperties({ mass: this._options.mass });\r\n\r\n this._nodeDisposeObserver = this.transformNode.onDisposeObservable.add(() => {\r\n this.dispose();\r\n });\r\n }\r\n\r\n private _getObjectBoundingBox() {\r\n if ((this.transformNode as AbstractMesh).getRawBoundingInfo) {\r\n return (this.transformNode as AbstractMesh).getRawBoundingInfo().boundingBox;\r\n } else {\r\n return new BoundingBox(new Vector3(-0.5, -0.5, -0.5), new Vector3(0.5, 0.5, 0.5));\r\n }\r\n }\r\n\r\n private _hasVertices(node: TransformNode): boolean {\r\n return (node as any)?.getTotalVertices() > 0;\r\n }\r\n\r\n private _addSizeOptions(): void {\r\n this.transformNode.computeWorldMatrix(true);\r\n const bb = this._getObjectBoundingBox();\r\n const extents = TmpVectors.Vector3[0];\r\n extents.copyFrom(bb.extendSize);\r\n extents.scaleInPlace(2);\r\n extents.multiplyInPlace(this.transformNode.scaling);\r\n\r\n const min = TmpVectors.Vector3[1];\r\n min.copyFrom(bb.minimum);\r\n min.multiplyInPlace(this.transformNode.scaling);\r\n\r\n if (!this._options.center) {\r\n const center = new Vector3();\r\n center.copyFrom(bb.center);\r\n center.multiplyInPlace(this.transformNode.scaling);\r\n this._options.center = center;\r\n }\r\n\r\n switch (this.type) {\r\n case PhysicsShapeType.SPHERE:\r\n if (!this._options.radius && Scalar.WithinEpsilon(extents.x, extents.y, 0.0001) && Scalar.WithinEpsilon(extents.x, extents.z, 0.0001)) {\r\n this._options.radius = extents.x / 2;\r\n } else if (!this._options.radius) {\r\n Logger.Warn(\"Non uniform scaling is unsupported for sphere shapes. Setting the radius to the biggest bounding box extent.\");\r\n this._options.radius = Math.max(extents.x, extents.y, extents.z) / 2;\r\n }\r\n break;\r\n case PhysicsShapeType.CAPSULE:\r\n {\r\n const capRadius = extents.x / 2;\r\n this._options.radius = this._options.radius ?? capRadius;\r\n this._options.pointA = this._options.pointA ?? new Vector3(0, min.y + capRadius, 0);\r\n this._options.pointB = this._options.pointB ?? new Vector3(0, min.y + extents.y - capRadius, 0);\r\n }\r\n break;\r\n case PhysicsShapeType.CYLINDER:\r\n {\r\n const capRadius = extents.x / 2;\r\n this._options.radius = this._options.radius ?? capRadius;\r\n this._options.pointA = this._options.pointA ?? new Vector3(0, min.y, 0);\r\n this._options.pointB = this._options.pointB ?? new Vector3(0, min.y + extents.y, 0);\r\n }\r\n break;\r\n case PhysicsShapeType.MESH:\r\n case PhysicsShapeType.CONVEX_HULL:\r\n if (!this._options.mesh && this._hasVertices(this.transformNode)) {\r\n this._options.mesh = this.transformNode as Mesh;\r\n } else if (!this._options.mesh || !this._hasVertices(this._options.mesh)) {\r\n throw new Error(\r\n \"No valid mesh was provided for mesh or convex hull shape parameter. Please provide a mesh with valid geometry (number of vertices greater than 0).\"\r\n );\r\n }\r\n break;\r\n case PhysicsShapeType.BOX:\r\n this._options.extents = this._options.extents ?? new Vector3(extents.x, extents.y, extents.z);\r\n this._options.rotation = this._options.rotation ?? Quaternion.Identity();\r\n break;\r\n }\r\n }\r\n\r\n /**\r\n * Releases the body, shape and material\r\n */\r\n public dispose(): void {\r\n if (this._nodeDisposeObserver) {\r\n this.body.transformNode.onDisposeObservable.remove(this._nodeDisposeObserver);\r\n this._nodeDisposeObserver = null;\r\n }\r\n this.body.dispose();\r\n if (this._disposeShapeWhenDisposed) {\r\n this.shape.dispose();\r\n }\r\n }\r\n}\r\n"]}
|
|
@@ -80,11 +80,13 @@ export declare class SSRRenderingPipeline extends PostProcessRenderPipeline {
|
|
|
80
80
|
* 1 should normally be a good value, depending on the scene you may need to use a higher value (2 or 3)
|
|
81
81
|
*/
|
|
82
82
|
selfCollisionNumSkip: number;
|
|
83
|
+
private _reflectivityThreshold;
|
|
83
84
|
/**
|
|
84
85
|
* Gets or sets the minimum value for one of the reflectivity component of the material to consider it for SSR (default: 0.04).
|
|
85
86
|
* If all r/g/b components of the reflectivity is below or equal this value, the pixel will not be considered reflective and SSR won't be applied.
|
|
86
87
|
*/
|
|
87
|
-
reflectivityThreshold: number;
|
|
88
|
+
get reflectivityThreshold(): number;
|
|
89
|
+
set reflectivityThreshold(threshold: number);
|
|
88
90
|
private _ssrDownsample;
|
|
89
91
|
/**
|
|
90
92
|
* Gets or sets the downsample factor used to reduce the size of the texture used to compute the SSR contribution (default: 0).
|
|
@@ -167,6 +169,13 @@ export declare class SSRRenderingPipeline extends PostProcessRenderPipeline {
|
|
|
167
169
|
*/
|
|
168
170
|
get clipToFrustum(): boolean;
|
|
169
171
|
set clipToFrustum(clip: boolean);
|
|
172
|
+
private _useFresnel;
|
|
173
|
+
/**
|
|
174
|
+
* Gets or sets a boolean indicating whether the blending between the current color pixel and the reflection color should be done with a Fresnel coefficient (default: false).
|
|
175
|
+
* It is more physically accurate to use the Fresnel coefficient (otherwise it uses the reflectivity of the material for blending), but it is also more expensive when you use blur (when blurDispersionStrength \> 0).
|
|
176
|
+
*/
|
|
177
|
+
get useFresnel(): boolean;
|
|
178
|
+
set useFresnel(fresnel: boolean);
|
|
170
179
|
private _enableAutomaticThicknessComputation;
|
|
171
180
|
/**
|
|
172
181
|
* Gets or sets a boolean defining if geometry thickness should be computed automatically (default: false).
|
|
@@ -43,6 +43,25 @@ export class SSRRenderingPipeline extends PostProcessRenderPipeline {
|
|
|
43
43
|
get samples() {
|
|
44
44
|
return this._samples;
|
|
45
45
|
}
|
|
46
|
+
/**
|
|
47
|
+
* Gets or sets the minimum value for one of the reflectivity component of the material to consider it for SSR (default: 0.04).
|
|
48
|
+
* If all r/g/b components of the reflectivity is below or equal this value, the pixel will not be considered reflective and SSR won't be applied.
|
|
49
|
+
*/
|
|
50
|
+
get reflectivityThreshold() {
|
|
51
|
+
return this._reflectivityThreshold;
|
|
52
|
+
}
|
|
53
|
+
set reflectivityThreshold(threshold) {
|
|
54
|
+
if (threshold === this._reflectivityThreshold) {
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
if ((threshold === 0 && this._reflectivityThreshold !== 0) || (threshold !== 0 && this._reflectivityThreshold === 0)) {
|
|
58
|
+
this._reflectivityThreshold = threshold;
|
|
59
|
+
this._buildPipeline();
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
this._reflectivityThreshold = threshold;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
46
65
|
/**
|
|
47
66
|
* Gets or sets the downsample factor used to reduce the size of the texture used to compute the SSR contribution (default: 0).
|
|
48
67
|
* Use 0 to render the SSR contribution at full resolution, 1 to render at half resolution, 2 to render at 1/3 resolution, etc.
|
|
@@ -208,6 +227,20 @@ export class SSRRenderingPipeline extends PostProcessRenderPipeline {
|
|
|
208
227
|
this._clipToFrustum = clip;
|
|
209
228
|
this._updateEffectDefines();
|
|
210
229
|
}
|
|
230
|
+
/**
|
|
231
|
+
* Gets or sets a boolean indicating whether the blending between the current color pixel and the reflection color should be done with a Fresnel coefficient (default: false).
|
|
232
|
+
* It is more physically accurate to use the Fresnel coefficient (otherwise it uses the reflectivity of the material for blending), but it is also more expensive when you use blur (when blurDispersionStrength \> 0).
|
|
233
|
+
*/
|
|
234
|
+
get useFresnel() {
|
|
235
|
+
return this._useFresnel;
|
|
236
|
+
}
|
|
237
|
+
set useFresnel(fresnel) {
|
|
238
|
+
if (this._useFresnel === fresnel) {
|
|
239
|
+
return;
|
|
240
|
+
}
|
|
241
|
+
this._useFresnel = fresnel;
|
|
242
|
+
this._buildPipeline();
|
|
243
|
+
}
|
|
211
244
|
/**
|
|
212
245
|
* Gets or sets a boolean defining if geometry thickness should be computed automatically (default: false).
|
|
213
246
|
* When enabled, a depth renderer is created which will render the back faces of the scene to a depth texture (meaning additional work for the GPU).
|
|
@@ -432,11 +465,7 @@ export class SSRRenderingPipeline extends PostProcessRenderPipeline {
|
|
|
432
465
|
* 1 should normally be a good value, depending on the scene you may need to use a higher value (2 or 3)
|
|
433
466
|
*/
|
|
434
467
|
this.selfCollisionNumSkip = 1;
|
|
435
|
-
|
|
436
|
-
* Gets or sets the minimum value for one of the reflectivity component of the material to consider it for SSR (default: 0.04).
|
|
437
|
-
* If all r/g/b components of the reflectivity is below or equal this value, the pixel will not be considered reflective and SSR won't be applied.
|
|
438
|
-
*/
|
|
439
|
-
this.reflectivityThreshold = 0.04;
|
|
468
|
+
this._reflectivityThreshold = 0.04;
|
|
440
469
|
this._ssrDownsample = 0;
|
|
441
470
|
this._blurDispersionStrength = 0.03;
|
|
442
471
|
this._blurDownsample = 0;
|
|
@@ -448,6 +477,7 @@ export class SSRRenderingPipeline extends PostProcessRenderPipeline {
|
|
|
448
477
|
this._attenuateFacingCamera = false;
|
|
449
478
|
this._attenuateBackfaceReflection = false;
|
|
450
479
|
this._clipToFrustum = true;
|
|
480
|
+
this._useFresnel = false;
|
|
451
481
|
this._enableAutomaticThicknessComputation = false;
|
|
452
482
|
this._backfaceDepthTextureDownsample = 0;
|
|
453
483
|
this._backfaceForceDepthWriteTransparentMeshes = true;
|
|
@@ -594,6 +624,12 @@ export class SSRRenderingPipeline extends PostProcessRenderPipeline {
|
|
|
594
624
|
if (this._generateOutputInGammaSpace) {
|
|
595
625
|
defines.push("#define SSR_OUTPUT_IS_GAMMA_SPACE");
|
|
596
626
|
}
|
|
627
|
+
if (this._useFresnel) {
|
|
628
|
+
defines.push("#define SSR_BLEND_WITH_FRESNEL");
|
|
629
|
+
}
|
|
630
|
+
if (this._reflectivityThreshold === 0) {
|
|
631
|
+
defines.push("#define SSR_DISABLE_REFLECTIVITY_TEST");
|
|
632
|
+
}
|
|
597
633
|
(_a = this._ssrPostProcess) === null || _a === void 0 ? void 0 : _a.updateEffect(defines.join("\n"));
|
|
598
634
|
}
|
|
599
635
|
_buildPipeline() {
|
|
@@ -622,7 +658,6 @@ export class SSRRenderingPipeline extends PostProcessRenderPipeline {
|
|
|
622
658
|
this._depthRenderer = new DepthRenderer(this._scene, undefined, undefined, undefined, 1, true, "SSRBackDepth");
|
|
623
659
|
this._depthRenderer.clearColor.r = 1e8; // "infinity": put a big value because we use the storeCameraSpaceZ mode
|
|
624
660
|
this._depthRenderer.reverseCulling = true; // we generate depth for the back faces
|
|
625
|
-
this._depthRenderer.getDepthMap().noPrePassRenderer = true; // we don't want the prepass renderer to attach to our depth buffer!
|
|
626
661
|
this._depthRenderer.forceDepthWriteTransparentMeshes = this._backfaceForceDepthWriteTransparentMeshes;
|
|
627
662
|
this._resizeDepthRenderer();
|
|
628
663
|
camera.customRenderTargets.push(this._depthRenderer.getDepthMap());
|
|
@@ -753,7 +788,7 @@ export class SSRRenderingPipeline extends PostProcessRenderPipeline {
|
|
|
753
788
|
effect.setFloat("nearPlaneZ", camera.minZ);
|
|
754
789
|
effect.setFloat("maxDistance", this.maxDistance);
|
|
755
790
|
effect.setFloat("selfCollisionNumSkip", this.selfCollisionNumSkip);
|
|
756
|
-
effect.setFloat("reflectivityThreshold", this.
|
|
791
|
+
effect.setFloat("reflectivityThreshold", this._reflectivityThreshold);
|
|
757
792
|
const textureSize = this._getTextureSize();
|
|
758
793
|
Matrix.ScalingToRef(textureSize.width, textureSize.height, 1, TmpVectors.Matrix[2]);
|
|
759
794
|
projectionMatrix.multiplyToRef(this._scene.getEngine().isWebGPU ? trsWebGPU : trs, TmpVectors.Matrix[3]);
|
|
@@ -788,6 +823,8 @@ export class SSRRenderingPipeline extends PostProcessRenderPipeline {
|
|
|
788
823
|
const height = (_b = (_a = this._blurPostProcessY) === null || _a === void 0 ? void 0 : _a.inputTexture.height) !== null && _b !== void 0 ? _b : this._scene.getEngine().getRenderHeight();
|
|
789
824
|
effect.setFloat2("texelOffsetScale", 0, this._blurDispersionStrength / height);
|
|
790
825
|
});
|
|
826
|
+
const uniformNames = ["strength", "reflectionSpecularFalloffExponent", "reflectivityThreshold"];
|
|
827
|
+
const samplerNames = ["textureSampler", "mainSampler", "reflectivitySampler"];
|
|
791
828
|
let defines = "";
|
|
792
829
|
if (this._debug) {
|
|
793
830
|
defines += "#define SSRAYTRACE_DEBUG\n";
|
|
@@ -798,7 +835,15 @@ export class SSRRenderingPipeline extends PostProcessRenderPipeline {
|
|
|
798
835
|
if (this._generateOutputInGammaSpace) {
|
|
799
836
|
defines += "#define SSR_OUTPUT_IS_GAMMA_SPACE\n";
|
|
800
837
|
}
|
|
801
|
-
|
|
838
|
+
if (this.useFresnel) {
|
|
839
|
+
defines += "#define SSR_BLEND_WITH_FRESNEL\n";
|
|
840
|
+
uniformNames.push("projection", "invProjectionMatrix");
|
|
841
|
+
samplerNames.push("depthSampler", "normalSampler");
|
|
842
|
+
}
|
|
843
|
+
if (this._reflectivityThreshold === 0) {
|
|
844
|
+
defines += "#define SSR_DISABLE_REFLECTIVITY_TEST";
|
|
845
|
+
}
|
|
846
|
+
this._blurCombinerPostProcess = new PostProcess("SSRblurCombiner", "screenSpaceReflection2BlurCombiner", uniformNames, samplerNames, this._useBlur() ? 1 / (this._blurDownsample + 1) : 1, null, 1, engine, false, defines, this._textureType);
|
|
802
847
|
this._blurCombinerPostProcess.autoClear = false;
|
|
803
848
|
this._blurCombinerPostProcess.onApplyObservable.add((effect) => {
|
|
804
849
|
var _a;
|
|
@@ -819,14 +864,33 @@ export class SSRRenderingPipeline extends PostProcessRenderPipeline {
|
|
|
819
864
|
if (geometryBufferRenderer) {
|
|
820
865
|
const roughnessIndex = geometryBufferRenderer.getTextureIndex(GeometryBufferRenderer.REFLECTIVITY_TEXTURE_TYPE);
|
|
821
866
|
effect.setTexture("reflectivitySampler", geometryBufferRenderer.getGBuffer().textures[roughnessIndex]);
|
|
867
|
+
if (this.useFresnel) {
|
|
868
|
+
effect.setTexture("normalSampler", geometryBufferRenderer.getGBuffer().textures[1]);
|
|
869
|
+
effect.setTexture("depthSampler", geometryBufferRenderer.getGBuffer().textures[0]);
|
|
870
|
+
}
|
|
822
871
|
}
|
|
823
872
|
else if (prePassRenderer) {
|
|
824
873
|
const roughnessIndex = prePassRenderer.getIndex(3);
|
|
825
874
|
effect.setTexture("reflectivitySampler", prePassRenderer.getRenderTarget().textures[roughnessIndex]);
|
|
875
|
+
if (this.useFresnel) {
|
|
876
|
+
const depthIndex = prePassRenderer.getIndex(5);
|
|
877
|
+
const normalIndex = prePassRenderer.getIndex(6);
|
|
878
|
+
effect.setTexture("normalSampler", prePassRenderer.getRenderTarget().textures[normalIndex]);
|
|
879
|
+
effect.setTexture("depthSampler", prePassRenderer.getRenderTarget().textures[depthIndex]);
|
|
880
|
+
}
|
|
826
881
|
}
|
|
827
882
|
effect.setFloat("strength", this.strength);
|
|
828
883
|
effect.setFloat("reflectionSpecularFalloffExponent", this.reflectionSpecularFalloffExponent);
|
|
829
|
-
effect.setFloat("reflectivityThreshold", this.
|
|
884
|
+
effect.setFloat("reflectivityThreshold", this._reflectivityThreshold);
|
|
885
|
+
if (this.useFresnel) {
|
|
886
|
+
const camera = this._scene.activeCamera;
|
|
887
|
+
if (camera) {
|
|
888
|
+
const projectionMatrix = camera.getProjectionMatrix();
|
|
889
|
+
projectionMatrix.invertToRef(TmpVectors.Matrix[0]);
|
|
890
|
+
effect.setMatrix("projection", projectionMatrix);
|
|
891
|
+
effect.setMatrix("invProjectionMatrix", TmpVectors.Matrix[0]);
|
|
892
|
+
}
|
|
893
|
+
}
|
|
830
894
|
});
|
|
831
895
|
}
|
|
832
896
|
/**
|
|
@@ -878,7 +942,7 @@ __decorate([
|
|
|
878
942
|
], SSRRenderingPipeline.prototype, "selfCollisionNumSkip", void 0);
|
|
879
943
|
__decorate([
|
|
880
944
|
serialize()
|
|
881
|
-
], SSRRenderingPipeline.prototype, "
|
|
945
|
+
], SSRRenderingPipeline.prototype, "_reflectivityThreshold", void 0);
|
|
882
946
|
__decorate([
|
|
883
947
|
serialize("_ssrDownsample")
|
|
884
948
|
], SSRRenderingPipeline.prototype, "_ssrDownsample", void 0);
|
|
@@ -918,6 +982,9 @@ __decorate([
|
|
|
918
982
|
__decorate([
|
|
919
983
|
serialize("clipToFrustum")
|
|
920
984
|
], SSRRenderingPipeline.prototype, "_clipToFrustum", void 0);
|
|
985
|
+
__decorate([
|
|
986
|
+
serialize("useFresnel")
|
|
987
|
+
], SSRRenderingPipeline.prototype, "_useFresnel", void 0);
|
|
921
988
|
__decorate([
|
|
922
989
|
serialize("enableAutomaticThicknessComputation")
|
|
923
990
|
], SSRRenderingPipeline.prototype, "_enableAutomaticThicknessComputation", void 0);
|