@woosh/meep-engine 2.33.22 → 2.33.26
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/core/bvh2/BinaryNode.js +1 -1
- package/core/bvh2/aabb3/AABB3.js +18 -0
- package/core/bvh2/aabb3/AABB3Math.js +1 -1
- package/core/bvh2/binary/2/BinaryUint32BVH.js +498 -0
- package/core/bvh2/binary/2/BinaryUint32BVH.spec.js +54 -0
- package/core/bvh2/binary/IndexedBinaryBVH.js +22 -26
- package/core/bvh2/traversal/ThreeClippingPlaneComputingBVHVisitor.js +5 -1
- package/core/bvh2/traversal/__detailed_box_volume_intersection.js +31 -11
- package/core/collection/ArrayUtils.js +1 -1
- package/core/collection/array/arrayQuickSort.js +9 -6
- package/core/collection/array/array_swap.js +22 -0
- package/core/collection/array/binarySearchHighIndex.js +1 -1
- package/core/collection/array/computeHashArray.js +22 -0
- package/core/collection/array/computeHashIntegerArray.js +15 -0
- package/core/collection/array/copyArray.js +2 -2
- package/core/collection/table/DataType2TypedArrayConstructorMapping.js +15 -0
- package/core/color/Color.js +2 -1
- package/core/function/FunctionCompiler.js +2 -1
- package/core/geom/3d/aabb/aabb3_computeDistanceAbovePlane.js +9 -33
- package/core/geom/3d/frustum/frustum3_computeNearestPointToPoint.js +10 -2
- package/core/geom/3d/line/line3_computeSegmentPointDistance_sqr.js +41 -0
- package/core/geom/3d/morton/mortonEncode_magicbits.js +2 -1
- package/core/geom/3d/morton/reinterpret_float32_as_int32.js +13 -0
- package/core/geom/3d/morton/v3_morton_encode_transformed.js +33 -0
- package/core/geom/3d/normal/hemioct/unit_hemioct.spec.js +1 -1
- package/core/geom/3d/plane/plane_computeConvex3PlaneIntersection.js +13 -14
- package/core/geom/3d/ray/ray_computeNearestPointToPoint.js +37 -0
- package/core/geom/3d/shape/AbstractShape3D.js +65 -0
- package/core/geom/3d/shape/TransformedShape3D.js +181 -0
- package/core/geom/3d/shape/TransformedShape3D.spec.js +33 -0
- package/core/geom/3d/shape/UnionShape3D.js +255 -0
- package/core/geom/3d/shape/UnitCubeShape3D.js +101 -0
- package/core/geom/3d/shape/UnitCubeShape3D.spec.js +42 -0
- package/core/geom/3d/shape/UnitSphereShape3D.js +55 -0
- package/core/geom/3d/shape/util/compute_signed_distance_gradient_by_sampling.js +48 -0
- package/core/geom/3d/shape/util/shape_to_visual_entity.js +159 -0
- package/core/geom/3d/voxel/DenseBitVolume3D.js +87 -0
- package/core/geom/3d/voxel/buildVolumeFromProjectedGeometry.js +23 -0
- package/core/geom/AABB2.js +1 -1
- package/core/geom/ConicRay.js +3 -1
- package/core/geom/LineSegment.js +0 -78
- package/core/geom/Matrix4.js +7 -8
- package/core/geom/Plane.js +14 -9
- package/core/geom/Rectangle.js +2 -1
- package/core/geom/Vector1.js +1 -1
- package/core/geom/Vector3.js +2 -1
- package/core/geom/Vector4.js +2 -1
- package/core/geom/random/randomPointInBox.js +7 -3
- package/core/geom/random/randomPointInPoint.js +6 -3
- package/core/geom/random/randomPointInSphere.js +9 -5
- package/core/geom/random/randomPointOnBox.js +7 -3
- package/core/geom/random/randomPointOnSphere.js +6 -3
- package/core/geom/v3_length.js +8 -3
- package/core/graph/graph_k_means_cluster.js +1 -1
- package/core/json/resolvePathByArray.js +2 -2
- package/core/math/MathUtils.js +0 -354
- package/core/math/MathUtils.spec.js +7 -1
- package/core/math/gaussian.js +9 -0
- package/core/math/hash/computeHashFloat.js +17 -0
- package/core/math/hash/computeHashFloatArray.js +34 -0
- package/core/math/hash/computeObjectHash.js +54 -0
- package/core/math/intersects1D.js +19 -0
- package/core/math/interval/NumericInterval.js +2 -2
- package/core/math/isValueBetween.js +10 -0
- package/core/math/isValueBetweenInclusive.js +10 -0
- package/core/math/noise/curl_noise_3dt.js +1 -1
- package/core/math/noise/sdnoise.js +10 -10
- package/core/math/overlap1D.js +19 -0
- package/core/math/pingpong.js +17 -0
- package/core/math/random/makeRangedRandom.js +19 -0
- package/core/math/random/randomFloatBetween.js +14 -0
- package/core/math/random/randomFromArray.js +19 -0
- package/core/math/random/randomGaussian.js +15 -0
- package/core/math/random/randomIntegerBetween.js +14 -0
- package/core/math/random/roundFair.js +15 -0
- package/core/math/separation1D.js +21 -0
- package/core/math/solveQuadratic.js +25 -0
- package/core/model/BoundedValue.js +1 -1
- package/core/model/node-graph/node/NodeInstancePortReference.js +1 -1
- package/core/model/node-graph/node/Port.js +1 -1
- package/core/model/reactive/evaluation/MultiPredicateEvaluator.spec.js +3 -1
- package/core/model/reactive/model/ReactiveBinaryExpression.js +1 -1
- package/core/model/reactive/model/terminal/ReactiveLiteralNumber.js +1 -1
- package/core/model/reactive/model/terminal/ReactiveReference.js +1 -1
- package/core/model/reactive/model/util/createRandomReactiveExpression.js +1 -1
- package/core/model/stat/LinearModifier.js +1 -1
- package/core/primitives/array/computeIntegerArrayHash.js +1 -1
- package/{engine/graphics/render/forward_plus/materials → core/primitives/strings}/insert_after.js +3 -0
- package/core/primitives/strings/insert_after_or_replace.js +27 -0
- package/editor/process/symbolic/makeHelperBoxGeometry.js +44 -0
- package/editor/view/ecs/EntityEditor.js +2 -2
- package/editor/view/ecs/components/particles/ParticleEmitterController.js +2 -2
- package/engine/EngineHarness.js +1 -0
- package/engine/animation/AnimationUtils.js +5 -5
- package/engine/animation/curve/AnimationCurve.js +72 -0
- package/engine/animation/curve/Keyframe.js +27 -0
- package/engine/animation/keyed2/AnimationTrack.js +27 -3
- package/engine/asset/Asset.js +1 -1
- package/engine/asset/loaders/GLTFAssetLoader.d.ts +1 -1
- package/engine/asset/loaders/GLTFAssetLoader.js +10 -0
- package/engine/asset/loaders/image/ImageRGBADataAsset.js +8 -1
- package/engine/asset/loaders/material/computeImageBitmapEquality.js +11 -0
- package/engine/asset/loaders/material/computeImageBitmapHash.js +22 -28
- package/engine/asset/loaders/material/computeMaterialHash.js +3 -1
- package/engine/asset/loaders/material/computeTextureHash.js +2 -1
- package/engine/ecs/EntityBuilder.js +25 -5
- package/engine/ecs/animation/Animation.js +2 -1
- package/engine/ecs/animation/InverseKinematics.js +2 -1
- package/engine/ecs/attachment/AttachmentBinding.js +8 -0
- package/engine/ecs/attachment/AttachmentSystem.js +4 -0
- package/engine/ecs/attachment/TransformAttachmentBinding.js +14 -44
- package/engine/ecs/components/Tag.js +27 -6
- package/engine/ecs/dynamic_actions/DynamicActorSystem.js +2 -1
- package/engine/ecs/dynamic_actions/DynamicRuleDescriptionTable.spec.js +3 -5
- package/engine/ecs/dynamic_actions/actions/definition/WeightedRandomActionDescription.js +1 -1
- package/engine/ecs/evaluation/complex/PointFitnessGaussianBlur.js +1 -1
- package/engine/ecs/foliage/ecs/Foliage2.js +1 -1
- package/engine/ecs/fow/FogOfWar.js +4 -0
- package/engine/ecs/fow/FogOfWarSystem.js +2 -0
- package/engine/ecs/fow/shader/FogOfWarRenderer.js +1 -1
- package/engine/ecs/gui/GUIElement.js +1 -1
- package/engine/ecs/gui/hud/HeadsUpDisplay.js +1 -1
- package/engine/ecs/gui/hud/HeadsUpDisplaySystem.js +2 -0
- package/engine/ecs/gui/position/ViewportPosition.js +2 -1
- package/engine/ecs/system/AbstractContextSystem.js +1 -1
- package/engine/ecs/systems/RangedAttackSystem.js +1 -1
- package/engine/ecs/systems/SteeringSystem.js +1 -1
- package/engine/ecs/systems/TagSystem.js +17 -0
- package/engine/ecs/terrain/tiles/TerrainTileManager.js +1 -1
- package/engine/ecs/tooltip/TooltipComponent.js +15 -0
- package/engine/ecs/transform/Transform.js +19 -6
- package/engine/ecs/util/hideEntityGracefully.js +18 -0
- package/engine/graphics/GraphicsEngine.js +11 -23
- package/engine/graphics/camera/testClippingPlaneComputation.js +2 -2
- package/engine/graphics/composit/CompositLayer.js +17 -4
- package/engine/graphics/composit/CompositingStages.js +8 -0
- package/engine/graphics/composit/LayerCompositer.js +35 -6
- package/engine/graphics/ecs/animation/animator/AnimationClip.js +2 -1
- package/engine/graphics/ecs/animation/animator/AnimationClipDefinition.js +2 -1
- package/engine/graphics/ecs/animation/animator/AnimationNotification.js +2 -1
- package/engine/graphics/ecs/animation/animator/AnimationNotificationDefinition.js +2 -1
- package/engine/graphics/ecs/animation/animator/graph/AnimationGraph.js +2 -1
- package/engine/graphics/ecs/animation/animator/graph/definition/AnimationGraphDefinition.js +2 -1
- package/engine/graphics/ecs/animation/animator/graph/definition/AnimationStateDefinition.js +1 -1
- package/engine/graphics/ecs/animation/animator/graph/definition/AnimationTransitionDefinition.js +2 -1
- package/engine/graphics/ecs/camera/CameraClippingPlaneComputer.js +1 -1
- package/engine/graphics/ecs/highlight/HighlightDefinition.js +2 -1
- package/engine/graphics/ecs/highlight/plugin/OutlineRenderPlugin.js +11 -7
- package/engine/graphics/ecs/light/Light.d.ts +1 -1
- package/engine/graphics/ecs/light/Light.js +5 -0
- package/engine/graphics/ecs/light/binding/three/ThreeLightBinding.js +5 -1
- package/engine/graphics/ecs/mesh/Mesh.js +2 -1
- package/engine/graphics/ecs/mesh-v2/DrawMode.js +5 -0
- package/engine/graphics/ecs/mesh-v2/ShadedGeometry.d.ts +13 -0
- package/engine/graphics/ecs/mesh-v2/ShadedGeometry.js +32 -18
- package/engine/graphics/ecs/mesh-v2/ShadedGeometrySystem.d.ts +6 -0
- package/engine/graphics/ecs/path/testPathDisplaySystem.js +98 -98
- package/engine/graphics/ecs/trail2d/Trail2D.js +17 -4
- package/engine/graphics/ecs/trail2d/Trail2DSystem.d.ts +2 -3
- package/engine/graphics/ecs/trail2d/Trail2DSystem.js +34 -118
- package/engine/graphics/geometry/AttributeSpec.js +105 -0
- package/engine/graphics/{micron/format/MicronVertexDataSpec.js → geometry/VertexDataSpec.js} +56 -25
- package/engine/graphics/micron/build/buildMicronGeometryFromBufferGeometry.js +7 -7
- package/engine/graphics/micron/build/fill_patch_geometry_data.js +1 -1
- package/engine/graphics/micron/buildPatchwork.js +1 -1
- package/engine/graphics/micron/format/MicronGeometry.js +3 -3
- package/engine/graphics/micron/format/serialization/MicronGeometryBinarySerializationAdapter.js +2 -2
- package/engine/graphics/micron/format/serialization/deserialize_attribute_spec.js +1 -1
- package/engine/graphics/micron/format/serialization/serialize_attribute_spec.js +1 -1
- package/engine/graphics/micron/render/PatchCacheKey.js +1 -1
- package/engine/graphics/micron/render/instanced/AttributeDataTexture.js +5 -5
- package/engine/graphics/micron/render/v1/ThreeVirtualGeometryAdapter.js +1 -1
- package/engine/graphics/particles/ParticleEmitterLibrary.js +3 -0
- package/engine/graphics/particles/ecs/{ParticleEmitterSystem2.js → ParticleEmitterSystem.js} +17 -9
- package/engine/graphics/particles/particular/engine/ParticularEngine.js +12 -4
- package/engine/graphics/particles/particular/engine/emitter/PARTICULAR_PARTICLE_SPECIFICATION.js +84 -0
- package/engine/graphics/particles/particular/engine/emitter/ParticleEmitter.js +106 -169
- package/engine/graphics/particles/particular/engine/emitter/ParticleEmitterFlag.js +5 -0
- package/engine/graphics/particles/particular/engine/emitter/ParticleLayer.js +14 -3
- package/engine/graphics/particles/particular/engine/emitter/ParticlePool.js +141 -14
- package/engine/graphics/particles/particular/engine/emitter/ParticlePool.spec.js +8 -7
- package/engine/graphics/particles/particular/engine/emitter/computeEmissionFunction.js +37 -0
- package/engine/graphics/particles/particular/engine/emitter/distance_to_camera.js +25 -0
- package/engine/graphics/particles/particular/engine/emitter/serde/ParameterLookupTableSerializationAdapter.js +8 -2
- package/engine/graphics/particles/particular/engine/parameter/ParameterLookupTable.js +2 -1
- package/engine/graphics/particles/particular/engine/parameter/ParameterTrack.js +1 -1
- package/engine/graphics/particles/particular/engine/parameter/ParticleParameter.js +1 -1
- package/engine/graphics/particles/particular/engine/renderers/billboard/BILLBOARD_PARTICLE_SPECIFICATION.js +24 -0
- package/engine/graphics/particles/particular/engine/renderers/billboard/ParticleBillboardMaterial.js +262 -71
- package/engine/graphics/particles/particular/engine/renderers/billboard/prototypeBillboardRenderer.js +9 -9
- package/engine/graphics/particles/particular/engine/shader/ShaderManager.js +80 -46
- package/engine/graphics/particles/particular/engine/shader/debugAtlas.js +14 -0
- package/engine/graphics/particles/particular/engine/simulator/SimulationStepApplyForce.js +2 -5
- package/engine/graphics/particles/particular/engine/simulator/SimulationStepCurlNoiseAcceleration.js +2 -6
- package/engine/graphics/particles/particular/engine/simulator/SimulationStepCurlNoiseVelocity.js +2 -7
- package/engine/graphics/particles/particular/engine/simulator/SimulationStepFixedPhysics.js +2 -5
- package/engine/graphics/particles/particular/engine/simulator/update_parameters.js +1 -1
- package/engine/graphics/particles/particular/engine/utils/distributeParticlesOnObject3D.js +1 -1
- package/engine/graphics/particles/particular/engine/utils/distrubuteParticlesOnMesh.js +1 -1
- package/engine/graphics/particles/particular/engine/utils/volume/AttributeValue.js +141 -0
- package/engine/graphics/particles/particular/engine/utils/volume/ParticleVolume.js +478 -0
- package/engine/graphics/particles/particular/engine/utils/volume/lut_to_sampler.js +27 -0
- package/engine/graphics/particles/particular/engine/utils/volume/prototypeParticleVolume.js +935 -0
- package/engine/graphics/particles/particular/group/Operation.js +18 -0
- package/engine/graphics/particles/particular/group/OperationType.js +9 -0
- package/engine/graphics/particles/particular/group/ParticleAttribute.js +2 -1
- package/engine/graphics/particles/particular/group/ParticleAttributeType.js +11 -0
- package/engine/graphics/particles/particular/group/ParticleDataType.js +10 -0
- package/engine/graphics/particles/particular/group/ParticleGroup.js +7 -245
- package/engine/graphics/particles/particular/group/ParticleGroup.spec.js +3 -1
- package/engine/graphics/particles/particular/group/ParticleSpecification.js +21 -14
- package/engine/graphics/particles/particular/group/itemSizeFromAttributeType.js +20 -0
- package/engine/graphics/particles/particular/group/optimizeCommandQueue.js +162 -0
- package/engine/graphics/particles/particular/group/typedArrayConstructorFromDataType.js +19 -0
- package/engine/graphics/render/buffer/buffers/prototypeNormalFrameBuffer.js +2 -2
- package/engine/graphics/render/buffer/simple-fx/ao/AmbientOcclusionPostProcessEffect.js +13 -7
- package/engine/graphics/render/buffer/slot/parameter/ProgramValueSlotParameter.js +2 -1
- package/engine/graphics/render/buffer/slot/parameter/ProgramValueSlotParameterSet.js +1 -1
- package/engine/graphics/render/forward_plus/LightManager.js +126 -95
- package/engine/graphics/render/forward_plus/PointLight.js +9 -0
- package/engine/graphics/render/forward_plus/PointLightData.js +1 -1
- package/engine/graphics/render/forward_plus/SpotLight.js +9 -0
- package/engine/graphics/render/forward_plus/cluster/compute_light_data_hash_0.js +2 -2
- package/engine/graphics/render/forward_plus/computeFrustumCorners.js +14 -32
- package/engine/graphics/render/forward_plus/materials/FP_INJECTION_POINT_ACCUMULATION.js +1 -0
- package/engine/graphics/render/forward_plus/materials/FP_SHADER_CHUNK_ACCUMULATION.js +32 -0
- package/engine/graphics/render/forward_plus/materials/FP_SHADER_CHUNK_DECODE_PARS.js +51 -0
- package/engine/graphics/render/forward_plus/materials/FP_SHADER_CHUNK_PREAMBLE.js +25 -0
- package/engine/graphics/render/forward_plus/materials/fp_build_fragment_shader.js +31 -120
- package/engine/graphics/render/forward_plus/materials/fp_build_vertex_lighting_shared.js +35 -0
- package/engine/graphics/render/forward_plus/materials/fp_build_vertex_shader.js +4 -5
- package/engine/graphics/render/forward_plus/plugin/ForwardPlusRenderingPlugin.js +1 -1
- package/engine/graphics/render/forward_plus/plugin/MaterialTransformer.js +10 -3
- package/engine/graphics/render/forward_plus/plugin/ptototypeFPPlugin.js +595 -60
- package/engine/graphics/render/forward_plus/prototypeLightManager.js +256 -136
- package/engine/graphics/render/forward_plus/query/analytical_triplanar_corner_mapping.js +8 -0
- package/engine/graphics/render/forward_plus/query/cube_mapping.js +38 -0
- package/engine/graphics/render/forward_plus/query/detailed_sphere_frustum_intersection_test.js +86 -0
- package/engine/graphics/render/forward_plus/query/point_light_inside_volume.js +73 -0
- package/engine/graphics/render/forward_plus/query/query_bvh_frustum_from_objects.js +131 -0
- package/engine/graphics/render/forward_plus/query/query_bvh_frustum_from_texture.js +129 -0
- package/engine/graphics/render/forward_plus/query/spot_light_inside_volume.js +33 -0
- package/engine/graphics/render/forward_plus/read_frustum_corner.js +14 -0
- package/engine/graphics/render/forward_plus/testClusterEquality.js +22 -0
- package/engine/graphics/render/layers/RenderLayerUtils.js +7 -4
- package/engine/graphics/render/visibility/IncrementalDeltaSet.js +11 -0
- package/engine/graphics/render/visibility/hiz/prototypeHiZ.js +2 -2
- package/engine/graphics/shaders/TerrainShader.js +4 -5
- package/engine/graphics/shadows/ShadowMapRenderer.js +8 -2
- package/engine/graphics/texture/atlas/AtlasPatch.js +7 -2
- package/engine/graphics/texture/atlas/TextureAtlas.js +2 -2
- package/engine/graphics/texture/sampler/HarmonicDiffusionGrid.spec.js +1 -1
- package/engine/graphics/texture/sampler/SampleTraverser.js +1 -1
- package/engine/graphics/texture/sampler/Sampler2D.js +8 -7
- package/engine/graphics/texture/sampler/distanceField.spec.js +1 -1
- package/engine/graphics/texture/sampler/scaleSampler2D.js +7 -10
- package/engine/graphics/trail/x/RibbonMaterialX.js +3 -3
- package/engine/graphics/trail/x/RibbonX.js +17 -2
- package/engine/graphics/trail/x/RibbonXPlugin.js +51 -1
- package/engine/graphics/util/composeMatrix4.js +33 -23
- package/engine/graphics/util/decompose_matrix_4_array.js +61 -0
- package/engine/grid/components/GridObstacle.js +3 -10
- package/engine/intelligence/behavior/ecs/BehaviorComponent.js +30 -14
- package/engine/intelligence/behavior/selector/WeightedElement.js +2 -1
- package/engine/intelligence/optimization/RandomOptimizer.js +1 -1
- package/engine/knowledge/database/StaticKnowledgeDataTable.js +6 -1
- package/engine/navigation/ecs/components/Path.js +1 -6
- package/engine/navigation/grid/FastBinaryHeap.spec.js +1 -1
- package/engine/reference/v2/Reference.js +6 -0
- package/engine/sound/ecs/emitter/SoundEmitter.js +2 -1
- package/engine/sound/ecs/emitter/SoundTrack.js +2 -1
- package/engine/sound/material/concrete/RandomSoundMaterial.js +1 -1
- package/engine/ui/notification/notificationGenerator.js +1 -1
- package/generation/filtering/numeric/complex/CellFilterGaussianBlur.js +1 -1
- package/generation/grid/generation/GridTaskExecuteRuleTimes.js +2 -1
- package/generation/markers/actions/MarkerNodeActionSelectRandom.js +1 -1
- package/generation/markers/transform/MarkerNodeTransformerRecordUniqueRandomEnum.js +1 -1
- package/generation/placement/action/random/CellActionSelectRandom.js +1 -1
- package/generation/theme/ThemeEngine.js +2 -2
- package/misc/makeMaterialIconCached.js +2 -2
- package/package.json +3 -3
- package/view/View.js +4 -2
- package/view/elements/image/HTMLElementCacheKey.js +2 -1
- package/view/elements/radial/RadialText.js +2 -1
- package/view/minimap/gl/MinimapMarkersGL.js +6 -100
- package/view/minimap/gl/buildMaterial.js +94 -0
- package/engine/graphics/micron/format/MicronGeometryBufferAttributeSpec.js +0 -71
- package/engine/graphics/render/forward_plus/queryBVH_Frustum.js +0 -345
package/engine/graphics/particles/particular/engine/renderers/billboard/ParticleBillboardMaterial.js
CHANGED
|
@@ -1,28 +1,141 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
AddEquation,
|
|
3
|
+
CustomBlending,
|
|
4
|
+
GLSL3,
|
|
5
|
+
Matrix4,
|
|
6
|
+
OneFactor,
|
|
7
|
+
OneMinusSrcAlphaFactor,
|
|
8
|
+
ShaderMaterial,
|
|
9
|
+
UniformsLib,
|
|
10
|
+
UniformsUtils
|
|
11
|
+
} from "three";
|
|
2
12
|
import { Vector2 as ThreeVector2 } from "three/src/math/Vector2.js";
|
|
3
|
-
import { ParticleSpecification } from "../../../group/ParticleSpecification.js";
|
|
4
|
-
import { ParticleAttribute } from "../../../group/ParticleAttribute.js";
|
|
5
|
-
import { ParticleAttributeType, ParticleDataType } from "../../../group/ParticleGroup.js";
|
|
6
|
-
|
|
7
|
-
export const BILLBOARD_PARTICLE_SPECIFICATION = new ParticleSpecification();
|
|
8
|
-
|
|
9
|
-
BILLBOARD_PARTICLE_SPECIFICATION.add(new ParticleAttribute('position', ParticleAttributeType.Vector3, ParticleDataType.Float32));
|
|
10
|
-
BILLBOARD_PARTICLE_SPECIFICATION.add(new ParticleAttribute('atlasPatch', ParticleAttributeType.Vector4, ParticleDataType.Float32));
|
|
11
|
-
BILLBOARD_PARTICLE_SPECIFICATION.add(new ParticleAttribute('size', ParticleAttributeType.Scalar, ParticleDataType.Float32));
|
|
12
|
-
BILLBOARD_PARTICLE_SPECIFICATION.add(new ParticleAttribute('velocity', ParticleAttributeType.Vector3, ParticleDataType.Float32));
|
|
13
|
-
BILLBOARD_PARTICLE_SPECIFICATION.add(new ParticleAttribute('rotation', ParticleAttributeType.Scalar, ParticleDataType.Float32));
|
|
14
|
-
BILLBOARD_PARTICLE_SPECIFICATION.add(new ParticleAttribute('color', ParticleAttributeType.Vector4, ParticleDataType.Float32));
|
|
15
|
-
BILLBOARD_PARTICLE_SPECIFICATION.add(new ParticleAttribute('blending', ParticleAttributeType.Scalar, ParticleDataType.Uint8));
|
|
16
|
-
|
|
17
|
-
export const BILLBOARD_PARTICLE_ATTRIBUTE_POSITION = 0;
|
|
18
|
-
export const BILLBOARD_PARTICLE_ATTRIBUTE_UV = 1;
|
|
19
|
-
export const BILLBOARD_PARTICLE_ATTRIBUTE_SIZE = 2;
|
|
20
|
-
export const BILLBOARD_PARTICLE_ATTRIBUTE_VELOCITY = 3;
|
|
21
|
-
export const BILLBOARD_PARTICLE_ATTRIBUTE_COLOR = 5;
|
|
22
|
-
export const BILLBOARD_PARTICLE_ATTRIBUTE_BLEND = 6;
|
|
23
13
|
|
|
24
14
|
const DEPTH_ERROR_MARGIN = 0.0001;
|
|
25
15
|
|
|
16
|
+
const CHUNK_LAMBERT_LIGHTING = `
|
|
17
|
+
vec3 diffuse = vec3( 1.0 );
|
|
18
|
+
|
|
19
|
+
GeometricContext geometry;
|
|
20
|
+
geometry.position = mvPosition.xyz;
|
|
21
|
+
geometry.normal = normalize( transformedNormal );
|
|
22
|
+
geometry.viewDir = ( isOrthographic ) ? vec3( 0, 0, 1 ) : normalize( -mvPosition.xyz );
|
|
23
|
+
|
|
24
|
+
GeometricContext backGeometry;
|
|
25
|
+
backGeometry.position = geometry.position;
|
|
26
|
+
backGeometry.normal = -geometry.normal;
|
|
27
|
+
backGeometry.viewDir = geometry.viewDir;
|
|
28
|
+
|
|
29
|
+
vLightFront = vec3( 0.0 );
|
|
30
|
+
vIndirectFront = vec3( 0.0 );
|
|
31
|
+
#ifdef DOUBLE_SIDED
|
|
32
|
+
vLightBack = vec3( 0.0 );
|
|
33
|
+
vIndirectBack = vec3( 0.0 );
|
|
34
|
+
#endif
|
|
35
|
+
|
|
36
|
+
IncidentLight directLight;
|
|
37
|
+
float dotNL;
|
|
38
|
+
vec3 directLightColor_Diffuse;
|
|
39
|
+
|
|
40
|
+
vIndirectFront += getAmbientLightIrradiance( ambientLightColor );
|
|
41
|
+
|
|
42
|
+
vIndirectFront += getLightProbeIrradiance( lightProbe, geometry.normal );
|
|
43
|
+
|
|
44
|
+
#ifdef DOUBLE_SIDED
|
|
45
|
+
|
|
46
|
+
vIndirectBack += getAmbientLightIrradiance( ambientLightColor );
|
|
47
|
+
|
|
48
|
+
vIndirectBack += getLightProbeIrradiance( lightProbe, backGeometry.normal );
|
|
49
|
+
|
|
50
|
+
#endif
|
|
51
|
+
|
|
52
|
+
#if NUM_POINT_LIGHTS > 0
|
|
53
|
+
|
|
54
|
+
#pragma unroll_loop_start
|
|
55
|
+
for ( int i = 0; i < NUM_POINT_LIGHTS; i ++ ) {
|
|
56
|
+
|
|
57
|
+
getPointLightInfo( pointLights[ i ], geometry, directLight );
|
|
58
|
+
|
|
59
|
+
dotNL = dot( geometry.normal, directLight.direction );
|
|
60
|
+
directLightColor_Diffuse = directLight.color;
|
|
61
|
+
|
|
62
|
+
vLightFront += saturate( dotNL ) * directLightColor_Diffuse;
|
|
63
|
+
|
|
64
|
+
#ifdef DOUBLE_SIDED
|
|
65
|
+
|
|
66
|
+
vLightBack += saturate( - dotNL ) * directLightColor_Diffuse;
|
|
67
|
+
|
|
68
|
+
#endif
|
|
69
|
+
|
|
70
|
+
}
|
|
71
|
+
#pragma unroll_loop_end
|
|
72
|
+
|
|
73
|
+
#endif
|
|
74
|
+
|
|
75
|
+
#if NUM_SPOT_LIGHTS > 0
|
|
76
|
+
|
|
77
|
+
#pragma unroll_loop_start
|
|
78
|
+
for ( int i = 0; i < NUM_SPOT_LIGHTS; i ++ ) {
|
|
79
|
+
|
|
80
|
+
getSpotLightInfo( spotLights[ i ], geometry, directLight );
|
|
81
|
+
|
|
82
|
+
dotNL = dot( geometry.normal, directLight.direction );
|
|
83
|
+
directLightColor_Diffuse = directLight.color;
|
|
84
|
+
|
|
85
|
+
vLightFront += saturate( dotNL ) * directLightColor_Diffuse;
|
|
86
|
+
|
|
87
|
+
#ifdef DOUBLE_SIDED
|
|
88
|
+
|
|
89
|
+
vLightBack += saturate( - dotNL ) * directLightColor_Diffuse;
|
|
90
|
+
|
|
91
|
+
#endif
|
|
92
|
+
}
|
|
93
|
+
#pragma unroll_loop_end
|
|
94
|
+
|
|
95
|
+
#endif
|
|
96
|
+
|
|
97
|
+
#if NUM_DIR_LIGHTS > 0
|
|
98
|
+
|
|
99
|
+
#pragma unroll_loop_start
|
|
100
|
+
for ( int i = 0; i < NUM_DIR_LIGHTS; i ++ ) {
|
|
101
|
+
|
|
102
|
+
getDirectionalLightInfo( directionalLights[ i ], geometry, directLight );
|
|
103
|
+
|
|
104
|
+
dotNL = dot( geometry.normal, directLight.direction );
|
|
105
|
+
directLightColor_Diffuse = directLight.color;
|
|
106
|
+
|
|
107
|
+
vLightFront += saturate( dotNL ) * directLightColor_Diffuse;
|
|
108
|
+
|
|
109
|
+
#ifdef DOUBLE_SIDED
|
|
110
|
+
|
|
111
|
+
vLightBack += saturate( - dotNL ) * directLightColor_Diffuse;
|
|
112
|
+
|
|
113
|
+
#endif
|
|
114
|
+
|
|
115
|
+
}
|
|
116
|
+
#pragma unroll_loop_end
|
|
117
|
+
|
|
118
|
+
#endif
|
|
119
|
+
|
|
120
|
+
#if NUM_HEMI_LIGHTS > 0
|
|
121
|
+
|
|
122
|
+
#pragma unroll_loop_start
|
|
123
|
+
for ( int i = 0; i < NUM_HEMI_LIGHTS; i ++ ) {
|
|
124
|
+
|
|
125
|
+
vIndirectFront += getHemisphereLightIrradiance( hemisphereLights[ i ], geometry.normal );
|
|
126
|
+
|
|
127
|
+
#ifdef DOUBLE_SIDED
|
|
128
|
+
|
|
129
|
+
vIndirectBack += getHemisphereLightIrradiance( hemisphereLights[ i ], backGeometry.normal );
|
|
130
|
+
|
|
131
|
+
#endif
|
|
132
|
+
|
|
133
|
+
}
|
|
134
|
+
#pragma unroll_loop_end
|
|
135
|
+
|
|
136
|
+
#endif
|
|
137
|
+
`;
|
|
138
|
+
|
|
26
139
|
function make_vertex_shader() {
|
|
27
140
|
return `
|
|
28
141
|
uniform float cameraNear;
|
|
@@ -43,6 +156,29 @@ function make_vertex_shader() {
|
|
|
43
156
|
varying vec2 vRotationMultiplier;
|
|
44
157
|
varying float vBlending;
|
|
45
158
|
|
|
159
|
+
|
|
160
|
+
#if defined(LIGHTS_ENABLED)
|
|
161
|
+
#include <common>
|
|
162
|
+
#include <bsdfs>
|
|
163
|
+
#include <lights_pars_begin>
|
|
164
|
+
|
|
165
|
+
struct LambertMaterial {
|
|
166
|
+
vec3 diffuseColor;
|
|
167
|
+
};
|
|
168
|
+
|
|
169
|
+
void RE_Direct_Lambert( const in IncidentLight directLight, const in GeometricContext geometry, const in LambertMaterial material, inout ReflectedLight reflectedLight ) {
|
|
170
|
+
vec3 irradiance = directLight.color;
|
|
171
|
+
reflectedLight.directDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
void RE_IndirectDiffuse_Lambert( const in vec3 irradiance, const in GeometricContext geometry, const in LambertMaterial material, inout ReflectedLight reflectedLight ) {
|
|
175
|
+
reflectedLight.indirectDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
#define RE_Direct RE_Direct_Lambert
|
|
179
|
+
#define RE_IndirectDiffuse RE_IndirectDiffuse_Lambert
|
|
180
|
+
#endif
|
|
181
|
+
|
|
46
182
|
void main() {
|
|
47
183
|
|
|
48
184
|
vColor = color;
|
|
@@ -52,9 +188,20 @@ function make_vertex_shader() {
|
|
|
52
188
|
|
|
53
189
|
mat4 modelViewProjectionMatrix = projectionMatrix * modelViewMatrix;
|
|
54
190
|
|
|
191
|
+
vec3 transformed = position;
|
|
192
|
+
|
|
55
193
|
vec4 position4 = vec4( position, 1.0 );
|
|
56
|
-
|
|
194
|
+
|
|
195
|
+
#if defined(LIGHTS_ENABLED)
|
|
196
|
+
vec4 mvPosition = modelViewMatrix * position4;
|
|
197
|
+
vec3 vViewPosition = -mvPosition.xyz;
|
|
198
|
+
|
|
199
|
+
vec3 transformedNormal = vec3(0.0,0.0,1.0);
|
|
200
|
+
#else
|
|
201
|
+
#endif
|
|
202
|
+
|
|
57
203
|
gl_Position = modelViewProjectionMatrix * position4;
|
|
204
|
+
|
|
58
205
|
|
|
59
206
|
float rotationGlobal = rotation;
|
|
60
207
|
|
|
@@ -79,18 +226,48 @@ function make_vertex_shader() {
|
|
|
79
226
|
|
|
80
227
|
vRotationMultiplier = vec2( cos(rotationGlobal),sin(rotationGlobal) );
|
|
81
228
|
|
|
82
|
-
float radius = vSize
|
|
229
|
+
float radius = vSize * 0.5;
|
|
83
230
|
|
|
231
|
+
float projected_radius = resolution.y * projectionMatrix[1][1] * radius / gl_Position.w;;
|
|
232
|
+
|
|
84
233
|
#ifdef DEPTH_SOFT_ENABLED
|
|
85
234
|
|
|
86
|
-
vFadeDistance =
|
|
235
|
+
vFadeDistance = 1.0 / radius;
|
|
87
236
|
|
|
88
237
|
#endif
|
|
89
|
-
|
|
90
|
-
gl_PointSize =
|
|
238
|
+
|
|
239
|
+
gl_PointSize = projected_radius;
|
|
240
|
+
|
|
241
|
+
#if defined(LIGHTS_ENABLED)
|
|
242
|
+
vec3 vLightFront;
|
|
243
|
+
vec3 vIndirectFront;
|
|
244
|
+
|
|
245
|
+
#include <worldpos_vertex>
|
|
246
|
+
${CHUNK_LAMBERT_LIGHTING}
|
|
247
|
+
|
|
248
|
+
LambertMaterial material = LambertMaterial(vColor.rgb);
|
|
249
|
+
|
|
250
|
+
ReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );
|
|
251
|
+
vec3 totalEmissiveRadiance = vec3(0.0);
|
|
252
|
+
|
|
253
|
+
reflectedLight.indirectDiffuse += vIndirectFront;
|
|
254
|
+
reflectedLight.indirectDiffuse *= BRDF_Lambert( vColor.rgb );
|
|
255
|
+
|
|
256
|
+
reflectedLight.directDiffuse = vLightFront;
|
|
257
|
+
reflectedLight.directDiffuse *= BRDF_Lambert( vColor.rgb ); // shadowmask goes here
|
|
258
|
+
|
|
259
|
+
//@injection_point FORWARD_PLUS:accumulation
|
|
260
|
+
|
|
261
|
+
vec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + totalEmissiveRadiance;
|
|
262
|
+
|
|
263
|
+
vColor.rgb = outgoingLight;
|
|
264
|
+
#endif
|
|
265
|
+
|
|
91
266
|
}`;
|
|
92
267
|
}
|
|
93
268
|
|
|
269
|
+
//${CHUNK_LAMBERT_LIGHTING}
|
|
270
|
+
//#include <lights_lambert_vertex>
|
|
94
271
|
function make_fragment_shader() {
|
|
95
272
|
return `
|
|
96
273
|
uniform sampler2D tSpriteAtlas;
|
|
@@ -108,6 +285,9 @@ function make_fragment_shader() {
|
|
|
108
285
|
varying vec2 vRotationMultiplier;
|
|
109
286
|
varying float vBlending;
|
|
110
287
|
|
|
288
|
+
|
|
289
|
+
out highp vec4 pc_fragColor;
|
|
290
|
+
|
|
111
291
|
float depthToLinear( float z ) {
|
|
112
292
|
float f = cameraFar;
|
|
113
293
|
float n = cameraNear;
|
|
@@ -183,7 +363,7 @@ function make_fragment_shader() {
|
|
|
183
363
|
discard;
|
|
184
364
|
}
|
|
185
365
|
|
|
186
|
-
vec4 texel = spriteColor *vColor;
|
|
366
|
+
vec4 texel = spriteColor * vColor;
|
|
187
367
|
|
|
188
368
|
// premultiply alpha
|
|
189
369
|
texel.xyz *= texel.a;
|
|
@@ -200,68 +380,78 @@ function make_fragment_shader() {
|
|
|
200
380
|
|
|
201
381
|
#endif
|
|
202
382
|
|
|
203
|
-
|
|
383
|
+
pc_fragColor = texel;
|
|
204
384
|
|
|
205
385
|
}`;
|
|
206
386
|
}
|
|
207
387
|
|
|
208
|
-
|
|
209
|
-
NOTES:
|
|
210
|
-
- To implement per-particle blend modes, we need to have access to what we're blending on to, that is - the color buffer
|
|
211
|
-
Having the color buffer - we can do just about any kind of a blend
|
|
212
|
-
|
|
213
|
-
- Support animation by adding animation sprite sheet to the main sprite atlas, record resolution of the sheet (in frames X,Y) and interpolate over tiles based on some parameter
|
|
388
|
+
/**
|
|
389
|
+
* NOTES:
|
|
390
|
+
* - To implement per-particle blend modes, we need to have access to what we're blending on to, that is - the color buffer
|
|
391
|
+
* Having the color buffer - we can do just about any kind of a blend
|
|
392
|
+
*
|
|
393
|
+
* - Support animation by adding animation sprite sheet to the main sprite atlas, record resolution of the sheet (in frames X,Y) and interpolate over tiles based on some parameter
|
|
394
|
+
* @param {boolean} [lights]
|
|
214
395
|
*/
|
|
215
|
-
export function make_particle_billboard_shader() {
|
|
396
|
+
export function make_particle_billboard_shader({ lights = false } = {}) {
|
|
397
|
+
let uniforms = {
|
|
398
|
+
tSpriteAtlas: {
|
|
399
|
+
type: 't',
|
|
400
|
+
value: null
|
|
401
|
+
},
|
|
402
|
+
cameraNear: {
|
|
403
|
+
type: 'f',
|
|
404
|
+
value: 1,
|
|
405
|
+
},
|
|
406
|
+
cameraFar: {
|
|
407
|
+
type: 'f',
|
|
408
|
+
value: 1,
|
|
409
|
+
},
|
|
410
|
+
tDepth: {
|
|
411
|
+
type: 't',
|
|
412
|
+
value: null
|
|
413
|
+
},
|
|
414
|
+
tColor: {
|
|
415
|
+
type: 't',
|
|
416
|
+
value: null
|
|
417
|
+
},
|
|
418
|
+
modelViewMatrix: {
|
|
419
|
+
type: 'm4',
|
|
420
|
+
value: new Matrix4()
|
|
421
|
+
},
|
|
422
|
+
projectionMatrix: {
|
|
423
|
+
type: 'm4',
|
|
424
|
+
value: new Matrix4()
|
|
425
|
+
},
|
|
426
|
+
resolution: {
|
|
427
|
+
type: 'v2',
|
|
428
|
+
value: new ThreeVector2()
|
|
429
|
+
}
|
|
430
|
+
};
|
|
431
|
+
|
|
432
|
+
if (lights) {
|
|
433
|
+
// mix in light uniforms
|
|
434
|
+
uniforms = Object.assign(uniforms, UniformsUtils.clone(UniformsLib.lights));
|
|
435
|
+
}
|
|
436
|
+
|
|
216
437
|
const shader = new ShaderMaterial({
|
|
217
438
|
defines: {
|
|
218
439
|
DEPTH_READ_ENABLED: true,
|
|
219
440
|
DEPTH_SOFT_ENABLED: true,
|
|
220
441
|
ALIGN_DIRECTION_ENABLED: false,
|
|
442
|
+
LIGHTS_ENABLED: lights,
|
|
443
|
+
LIGHTING_VERTEX_ONLY: true
|
|
221
444
|
},
|
|
222
|
-
uniforms:
|
|
223
|
-
tSpriteAtlas: {
|
|
224
|
-
type: 't',
|
|
225
|
-
value: null
|
|
226
|
-
},
|
|
227
|
-
cameraNear: {
|
|
228
|
-
type: 'f',
|
|
229
|
-
value: 1,
|
|
230
|
-
},
|
|
231
|
-
cameraFar: {
|
|
232
|
-
type: 'f',
|
|
233
|
-
value: 1,
|
|
234
|
-
},
|
|
235
|
-
tDepth: {
|
|
236
|
-
type: 't',
|
|
237
|
-
value: null
|
|
238
|
-
},
|
|
239
|
-
tColor: {
|
|
240
|
-
type: 't',
|
|
241
|
-
value: null
|
|
242
|
-
},
|
|
243
|
-
modelViewMatrix: {
|
|
244
|
-
type: 'm4',
|
|
245
|
-
value: new Matrix4()
|
|
246
|
-
},
|
|
247
|
-
projectionMatrix: {
|
|
248
|
-
type: 'm4',
|
|
249
|
-
value: new Matrix4()
|
|
250
|
-
},
|
|
251
|
-
resolution: {
|
|
252
|
-
type: 'v2',
|
|
253
|
-
value: new ThreeVector2()
|
|
254
|
-
}
|
|
255
|
-
},
|
|
445
|
+
uniforms: uniforms,
|
|
256
446
|
vertexShader: make_vertex_shader(),
|
|
257
447
|
fragmentShader: make_fragment_shader(),
|
|
258
448
|
blending: CustomBlending,
|
|
259
|
-
lights:
|
|
449
|
+
lights: lights,
|
|
260
450
|
depthTest: true,
|
|
261
451
|
depthWrite: false,
|
|
262
452
|
transparent: true,
|
|
263
453
|
vertexColors: false,
|
|
264
|
-
glslVersion:
|
|
454
|
+
glslVersion: GLSL3
|
|
265
455
|
});
|
|
266
456
|
|
|
267
457
|
shader.blending = CustomBlending;
|
|
@@ -269,5 +459,6 @@ export function make_particle_billboard_shader() {
|
|
|
269
459
|
shader.blendSrc = OneFactor;
|
|
270
460
|
shader.blendDst = OneMinusSrcAlphaFactor;
|
|
271
461
|
|
|
462
|
+
|
|
272
463
|
return shader;
|
|
273
464
|
}
|
|
@@ -1,14 +1,6 @@
|
|
|
1
1
|
import { EngineHarness } from "../../../../../../EngineHarness.js";
|
|
2
2
|
import { ParticlePool } from "../../emitter/ParticlePool.js";
|
|
3
|
-
import {
|
|
4
|
-
BILLBOARD_PARTICLE_ATTRIBUTE_BLEND,
|
|
5
|
-
BILLBOARD_PARTICLE_ATTRIBUTE_COLOR,
|
|
6
|
-
BILLBOARD_PARTICLE_ATTRIBUTE_POSITION,
|
|
7
|
-
BILLBOARD_PARTICLE_ATTRIBUTE_SIZE,
|
|
8
|
-
BILLBOARD_PARTICLE_ATTRIBUTE_UV,
|
|
9
|
-
BILLBOARD_PARTICLE_SPECIFICATION,
|
|
10
|
-
make_particle_billboard_shader
|
|
11
|
-
} from "./ParticleBillboardMaterial.js";
|
|
3
|
+
import { make_particle_billboard_shader } from "./ParticleBillboardMaterial.js";
|
|
12
4
|
import { DataTexture, LinearFilter, LinearMipMapLinearFilter, Matrix4, Points } from "three";
|
|
13
5
|
import { ManagedAtlas } from "../../../../../texture/atlas/ManagedTextureAtlas.js";
|
|
14
6
|
import { writeSample2DDataToDataTexture } from "../../../../../texture/sampler/writeSampler2DDataToDataTexture.js";
|
|
@@ -21,6 +13,14 @@ import Mesh from "../../../../../ecs/mesh/Mesh.js";
|
|
|
21
13
|
import Vector3 from "../../../../../../../core/geom/Vector3.js";
|
|
22
14
|
import { RenderPassType } from "../../../../../render/RenderPassType.js";
|
|
23
15
|
import { StandardFrameBuffers } from "../../../../../StandardFrameBuffers.js";
|
|
16
|
+
import {
|
|
17
|
+
BILLBOARD_PARTICLE_ATTRIBUTE_BLEND,
|
|
18
|
+
BILLBOARD_PARTICLE_ATTRIBUTE_COLOR,
|
|
19
|
+
BILLBOARD_PARTICLE_ATTRIBUTE_POSITION,
|
|
20
|
+
BILLBOARD_PARTICLE_ATTRIBUTE_SIZE,
|
|
21
|
+
BILLBOARD_PARTICLE_ATTRIBUTE_UV,
|
|
22
|
+
BILLBOARD_PARTICLE_SPECIFICATION
|
|
23
|
+
} from "./BILLBOARD_PARTICLE_SPECIFICATION.js";
|
|
24
24
|
|
|
25
25
|
|
|
26
26
|
const engineHarness = new EngineHarness();
|
|
@@ -6,17 +6,22 @@ import {
|
|
|
6
6
|
LinearMipMapLinearFilter,
|
|
7
7
|
Matrix4,
|
|
8
8
|
RGBAFormat,
|
|
9
|
-
UnsignedByteType
|
|
9
|
+
UnsignedByteType,
|
|
10
|
+
Vector2 as ThreeVector2
|
|
10
11
|
} from "three";
|
|
11
12
|
import Vector2 from "../../../../../../core/geom/Vector2.js";
|
|
12
13
|
import { HashMap } from "../../../../../../core/collection/HashMap.js";
|
|
13
14
|
import { ParticleEmitterFlag } from "../emitter/ParticleEmitterFlag.js";
|
|
14
15
|
import { writeSample2DDataToDataTexture } from "../../../../texture/sampler/writeSampler2DDataToDataTexture.js";
|
|
15
|
-
import { TextureAtlasDebugger } from "../../../../texture/atlas/TextureAtlasDebugger.js";
|
|
16
16
|
import { MaterialRecord } from "./MaterialRecord.js";
|
|
17
17
|
import { make_particle_billboard_shader } from "../renderers/billboard/ParticleBillboardMaterial.js";
|
|
18
18
|
|
|
19
|
-
const EMITTER_MATERIAL_FLAGS =
|
|
19
|
+
const EMITTER_MATERIAL_FLAGS =
|
|
20
|
+
ParticleEmitterFlag.DepthSoftDisabled
|
|
21
|
+
| ParticleEmitterFlag.DepthReadDisabled
|
|
22
|
+
| ParticleEmitterFlag.AlignOnVelocity
|
|
23
|
+
| ParticleEmitterFlag.Lit
|
|
24
|
+
;
|
|
20
25
|
|
|
21
26
|
/**
|
|
22
27
|
*
|
|
@@ -82,21 +87,21 @@ function buildDataTexture(
|
|
|
82
87
|
return result;
|
|
83
88
|
}
|
|
84
89
|
|
|
85
|
-
function debugAtlas(atlas, options) {
|
|
86
|
-
|
|
87
|
-
const spriteAtlasDebugger = new TextureAtlasDebugger(atlas, options);
|
|
88
|
-
|
|
89
|
-
spriteAtlasDebugger.vAtlasContent.link();
|
|
90
|
-
document.body.appendChild(spriteAtlasDebugger.vAtlasContent.el);
|
|
91
|
-
}
|
|
92
|
-
|
|
93
90
|
export class ShaderManager {
|
|
94
91
|
/**
|
|
95
92
|
*
|
|
96
93
|
* @param {AssetManager} assetManager
|
|
94
|
+
* @param {MaterialManager} material_manager
|
|
97
95
|
* @constructor
|
|
98
96
|
*/
|
|
99
|
-
constructor(assetManager) {
|
|
97
|
+
constructor(assetManager, material_manager) {
|
|
98
|
+
/**
|
|
99
|
+
*
|
|
100
|
+
* @type {MaterialManager}
|
|
101
|
+
* @private
|
|
102
|
+
*/
|
|
103
|
+
this.__material_manager = material_manager;
|
|
104
|
+
|
|
100
105
|
/**
|
|
101
106
|
*
|
|
102
107
|
* @type {ManagedAtlas}
|
|
@@ -159,6 +164,34 @@ export class ShaderManager {
|
|
|
159
164
|
//watch atlas updates
|
|
160
165
|
this.spriteAtlas.atlas.on.painted.add(this.updateSpriteTexture, this);
|
|
161
166
|
|
|
167
|
+
/**
|
|
168
|
+
* Common shader uniforms, inherited by every material and updated centrally (here)
|
|
169
|
+
* @private
|
|
170
|
+
*/
|
|
171
|
+
this.__common_uniforms = {
|
|
172
|
+
tSpriteAtlas: {
|
|
173
|
+
value: this.spriteTexture
|
|
174
|
+
},
|
|
175
|
+
tDepth: {
|
|
176
|
+
value: null
|
|
177
|
+
},
|
|
178
|
+
resolution: {
|
|
179
|
+
value: new ThreeVector2()
|
|
180
|
+
},
|
|
181
|
+
projectionMatrix: {
|
|
182
|
+
value: null
|
|
183
|
+
},
|
|
184
|
+
modelViewMatrix: {
|
|
185
|
+
value: null
|
|
186
|
+
},
|
|
187
|
+
cameraNear: {
|
|
188
|
+
value: 0
|
|
189
|
+
},
|
|
190
|
+
cameraFar: {
|
|
191
|
+
value: 0
|
|
192
|
+
}
|
|
193
|
+
};
|
|
194
|
+
|
|
162
195
|
// debugAtlas(this.parameterSheet.atlas, { scale: new Vector2(16, 16) });
|
|
163
196
|
// debugAtlas(this.spriteAtlas.atlas, { scale: new Vector2(0.5, 0.5) });
|
|
164
197
|
}
|
|
@@ -184,8 +217,6 @@ export class ShaderManager {
|
|
|
184
217
|
writeSample2DDataToDataTexture(atlas, dataTexture);
|
|
185
218
|
|
|
186
219
|
this.materialMap.forEach(function (entry) {
|
|
187
|
-
const material = entry.material;
|
|
188
|
-
material.uniforms.tSpriteAtlas.value = dataTexture;
|
|
189
220
|
|
|
190
221
|
entry.emitters.forEach(function (emitter) {
|
|
191
222
|
//mark sprites for an update
|
|
@@ -202,19 +233,24 @@ export class ShaderManager {
|
|
|
202
233
|
* @param {ParticleEmitter} emitter
|
|
203
234
|
*/
|
|
204
235
|
buildMaterial(emitter) {
|
|
205
|
-
const
|
|
236
|
+
const lights_enabled = emitter.getFlag(ParticleEmitterFlag.Lit);
|
|
206
237
|
|
|
207
|
-
shader
|
|
208
|
-
shader.uniforms.tDepth.value = this.depthTexture;
|
|
209
|
-
shader.uniforms.resolution.value.set(this.viewportSize.x, this.viewportSize.y)
|
|
238
|
+
const shader = make_particle_billboard_shader({ lights: lights_enabled });
|
|
210
239
|
|
|
211
|
-
shader.
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
};
|
|
240
|
+
shader.uniforms = Object.assign(shader.uniforms, this.__common_uniforms);
|
|
241
|
+
|
|
242
|
+
// write defines
|
|
243
|
+
const defs = shader.defines;
|
|
216
244
|
|
|
217
|
-
|
|
245
|
+
defs.DEPTH_READ_ENABLED = !emitter.getFlag(ParticleEmitterFlag.DepthReadDisabled);
|
|
246
|
+
defs.DEPTH_SOFT_ENABLED = !emitter.getFlag(ParticleEmitterFlag.DepthSoftDisabled);
|
|
247
|
+
defs.ALIGN_DIRECTION_ENABLED = emitter.getFlag(ParticleEmitterFlag.AlignOnVelocity);
|
|
248
|
+
|
|
249
|
+
const ref = this.__material_manager.obtain(shader);
|
|
250
|
+
|
|
251
|
+
// TODO track referecen and release it eventually
|
|
252
|
+
|
|
253
|
+
return ref.getValue();
|
|
218
254
|
}
|
|
219
255
|
|
|
220
256
|
/**
|
|
@@ -225,7 +261,12 @@ export class ShaderManager {
|
|
|
225
261
|
const spriteAtlas = this.spriteAtlas;
|
|
226
262
|
|
|
227
263
|
// load sprites
|
|
228
|
-
emitter.layers
|
|
264
|
+
const particle_layers = emitter.layers;
|
|
265
|
+
const layer_count = particle_layers.length;
|
|
266
|
+
|
|
267
|
+
for (let i = 0; i < layer_count; i++) {
|
|
268
|
+
const layer = particle_layers.get(i);
|
|
269
|
+
|
|
229
270
|
const patchPromise = spriteAtlas.acquire(layer.imageURL);
|
|
230
271
|
|
|
231
272
|
patchPromise.then(function (patch) {
|
|
@@ -233,7 +274,7 @@ export class ShaderManager {
|
|
|
233
274
|
}, (e) => {
|
|
234
275
|
console.warn(`Failed to load sprite '${layer.imageURL}':`, e);
|
|
235
276
|
});
|
|
236
|
-
}
|
|
277
|
+
}
|
|
237
278
|
|
|
238
279
|
// obtain material
|
|
239
280
|
let material, entry;
|
|
@@ -312,10 +353,12 @@ export class ShaderManager {
|
|
|
312
353
|
const spriteAtlas = this.spriteAtlas;
|
|
313
354
|
|
|
314
355
|
//release sprites
|
|
315
|
-
emitter.layers
|
|
356
|
+
const particle_layers = emitter.layers;
|
|
357
|
+
const layer_count = particle_layers.length;
|
|
358
|
+
for (let i = 0; i < layer_count; i++) {
|
|
359
|
+
const layer = particle_layers.get(i);
|
|
316
360
|
spriteAtlas.release(layer.imageURL);
|
|
317
|
-
}
|
|
318
|
-
|
|
361
|
+
}
|
|
319
362
|
|
|
320
363
|
if (entry.count <= 0) {
|
|
321
364
|
//last usage removed
|
|
@@ -348,15 +391,12 @@ export class ShaderManager {
|
|
|
348
391
|
const cameraNear = camera.near;
|
|
349
392
|
const cameraFar = camera.far;
|
|
350
393
|
|
|
351
|
-
|
|
352
|
-
this.materialMap.forEach(function (entry) {
|
|
353
|
-
const uniforms = entry.material.uniforms;
|
|
394
|
+
const uniforms = this.__common_uniforms;
|
|
354
395
|
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
});
|
|
396
|
+
uniforms.projectionMatrix.value = projectionMatrix;
|
|
397
|
+
uniforms.modelViewMatrix.value = modelViewMatrix;
|
|
398
|
+
uniforms.cameraNear.value = cameraNear;
|
|
399
|
+
uniforms.cameraFar.value = cameraFar;
|
|
360
400
|
}
|
|
361
401
|
|
|
362
402
|
/**
|
|
@@ -366,11 +406,8 @@ export class ShaderManager {
|
|
|
366
406
|
setDepthTexture(texture) {
|
|
367
407
|
this.depthTexture = texture;
|
|
368
408
|
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
const material = entry.material;
|
|
372
|
-
material.uniforms.tDepth.value = texture;
|
|
373
|
-
});
|
|
409
|
+
this.__common_uniforms.tDepth.value = texture;
|
|
410
|
+
|
|
374
411
|
}
|
|
375
412
|
|
|
376
413
|
/**
|
|
@@ -381,10 +418,7 @@ export class ShaderManager {
|
|
|
381
418
|
setViewportSize(x, y) {
|
|
382
419
|
this.viewportSize.set(x, y);
|
|
383
420
|
|
|
384
|
-
|
|
385
|
-
this.materialMap.forEach(function (entry) {
|
|
386
|
-
entry.material.uniforms.resolution.value.set(x, y);
|
|
387
|
-
});
|
|
421
|
+
this.__common_uniforms.resolution.value.set(x, y);
|
|
388
422
|
}
|
|
389
423
|
}
|
|
390
424
|
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { TextureAtlasDebugger } from "../../../../texture/atlas/TextureAtlasDebugger.js";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
*
|
|
5
|
+
* @param {TextureAtlas} atlas
|
|
6
|
+
* @param {*} options
|
|
7
|
+
*/
|
|
8
|
+
function debugAtlas(atlas, options) {
|
|
9
|
+
|
|
10
|
+
const spriteAtlasDebugger = new TextureAtlasDebugger(atlas, options);
|
|
11
|
+
|
|
12
|
+
spriteAtlasDebugger.vAtlasContent.link();
|
|
13
|
+
document.body.appendChild(spriteAtlasDebugger.vAtlasContent.el);
|
|
14
|
+
}
|