x_ite 5.0.2 → 6.0.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/.vscode/settings.json +12 -5
- package/.vscode/tasks.json +21 -0
- package/Makefile +10 -15
- package/README.md +6 -11
- package/build/bin/dist.pl +0 -6
- package/build/bin/version.pl +1 -4
- package/dist/assets/components/annotation.js +2 -2
- package/dist/assets/components/annotation.min.js +1 -1
- package/dist/assets/components/cad-geometry.js +2 -2
- package/dist/assets/components/cad-geometry.min.js +1 -1
- package/dist/assets/components/cube-map-texturing.js +6 -19
- package/dist/assets/components/cube-map-texturing.min.js +1 -1
- package/dist/assets/components/dis.js +2 -2
- package/dist/assets/components/dis.min.js +1 -1
- package/dist/assets/components/event-utilities.js +3 -3
- package/dist/assets/components/event-utilities.min.js +1 -1
- package/dist/assets/components/geometry2d.js +4 -4
- package/dist/assets/components/geometry2d.min.js +1 -1
- package/dist/assets/components/geospatial.js +32 -1685
- package/dist/assets/components/geospatial.min.js +1 -1
- package/dist/assets/components/h-anim.js +70 -77
- package/dist/assets/components/h-anim.min.js +1 -1
- package/dist/assets/components/key-device-sensor.js +3 -3
- package/dist/assets/components/key-device-sensor.min.js +1 -1
- package/dist/assets/components/layout.js +38 -52
- package/dist/assets/components/layout.min.js +1 -1
- package/dist/assets/components/nurbs.js +277 -194
- package/dist/assets/components/nurbs.min.js +1 -1
- package/dist/assets/components/particle-systems.js +1918 -1658
- package/dist/assets/components/particle-systems.min.js +1 -1
- package/dist/assets/components/picking.js +33 -41
- package/dist/assets/components/picking.min.js +1 -1
- package/dist/assets/components/projective-texture-mapping.js +72 -86
- package/dist/assets/components/projective-texture-mapping.min.js +1 -1
- package/dist/assets/components/rigid-body-physics.js +36 -57
- package/dist/assets/components/rigid-body-physics.min.js +1 -1
- package/dist/assets/components/scripting.js +2 -2
- package/dist/assets/components/scripting.min.js +1 -1
- package/dist/assets/components/texturing-3d.js +26 -75
- package/dist/assets/components/texturing-3d.min.js +3 -3
- package/dist/assets/components/volume-rendering.js +10 -10
- package/dist/assets/components/volume-rendering.min.js +1 -1
- package/dist/assets/components/x_ite.js +2 -2
- package/dist/assets/components/x_ite.min.js +1 -1
- package/dist/assets/linetype/1.png +0 -0
- package/dist/assets/linetype/10.png +0 -0
- package/dist/assets/linetype/11.png +0 -0
- package/dist/assets/linetype/12.png +0 -0
- package/dist/assets/linetype/13.png +0 -0
- package/dist/assets/linetype/14.png +0 -0
- package/dist/assets/linetype/15.png +0 -0
- package/dist/assets/linetype/16.png +0 -0
- package/dist/assets/linetype/2.png +0 -0
- package/dist/assets/linetype/3.png +0 -0
- package/dist/assets/linetype/4.png +0 -0
- package/dist/assets/linetype/5.png +0 -0
- package/dist/assets/linetype/6.png +0 -0
- package/dist/assets/linetype/7.png +0 -0
- package/dist/assets/linetype/8.png +0 -0
- package/dist/assets/linetype/9.png +0 -0
- package/dist/assets/shaders/webgl1/Line.fs +0 -21
- package/dist/assets/shaders/webgl1/Line.vs +0 -10
- package/dist/assets/shaders/webgl1/PBR.vs +1 -1
- package/dist/assets/shaders/webgl2/Depth.vs +29 -1
- package/dist/assets/shaders/webgl2/Gouraud.vs +31 -3
- package/dist/assets/shaders/webgl2/Line.fs +24 -12
- package/dist/assets/shaders/webgl2/Line.vs +36 -11
- package/dist/assets/shaders/webgl2/LineTransform.fs +4 -0
- package/dist/assets/shaders/webgl2/LineTransform.vs +57 -0
- package/dist/assets/shaders/webgl2/PBR.vs +35 -7
- package/dist/assets/shaders/webgl2/Phong.vs +31 -3
- package/dist/assets/shaders/webgl2/Point.vs +29 -1
- package/dist/assets/shaders/webgl2/Unlit.vs +31 -3
- package/dist/example.html +6 -6
- package/dist/x_ite.css +180 -208
- package/dist/x_ite.js +16477 -16629
- package/dist/x_ite.min.js +17 -17
- package/dist/x_ite.zip +0 -0
- package/docs/404.md +6 -0
- package/docs/Accessing-the-External-Browser.md +20 -14
- package/docs/Browser-Support.md +6 -0
- package/docs/Custom-Shaders.md +17 -24
- package/docs/Features.md +7 -1
- package/docs/Gemfile +44 -0
- package/docs/Gemfile.lock +122 -0
- package/docs/Glossary.md +6 -0
- package/docs/How-To-Configure-Your-Web-Server.md +6 -0
- package/docs/Supported-Nodes.md +9 -1
- package/docs/What's-New.md +31 -0
- package/docs/XHTML-DOM-Integration.md +6 -0
- package/docs/_config.yml +1 -1
- package/docs/assets/css/main.scss +26 -0
- package/docs/index.md +38 -46
- package/docs/reference/Browser-Services.md +9 -3
- package/docs/reference/Constants-Services.md +6 -0
- package/docs/reference/ECMAScript-Object-and-Function-Definitions.md +6 -0
- package/docs/reference/Field-Services-and-Objects.md +6 -0
- package/docs/reference/Prototype-Services.md +6 -0
- package/docs/reference/Route-Services.md +6 -0
- package/docs/reference/Scene-Services.md +8 -2
- package/docs/reference/Script-Node-Authoring-Interface.md +7 -1
- package/docs/tutorials/Adding-backgrounds.md +6 -0
- package/docs/tutorials/Adding-fog.md +6 -0
- package/docs/tutorials/Adding-sound.md +6 -0
- package/docs/tutorials/Animating-transforms.md +6 -0
- package/docs/tutorials/Basic-Nodes.md +6 -0
- package/docs/tutorials/Building-a-X3D-world.md +6 -0
- package/docs/tutorials/Building-elevation-grids.md +6 -0
- package/docs/tutorials/Building-extruded-shapes.md +6 -0
- package/docs/tutorials/Building-primitive-shapes.md +6 -0
- package/docs/tutorials/Building-shapes-out-of-points,-lines,-and-faces.md +6 -0
- package/docs/tutorials/Controlling-appearance-with-materials.md +6 -0
- package/docs/tutorials/Controlling-color-on-coordinate-based-geometry.md +6 -0
- package/docs/tutorials/Controlling-detail.md +6 -0
- package/docs/tutorials/Controlling-how-textures-are-mapped.md +6 -0
- package/docs/tutorials/Controlling-navigation.md +6 -0
- package/docs/tutorials/Controlling-shading-on-coordinate-based-geometry.md +6 -0
- package/docs/tutorials/Controlling-the-viewpoint.md +6 -0
- package/docs/tutorials/Creating-new-node-types.md +6 -0
- package/docs/tutorials/Grouping-nodes.md +6 -0
- package/docs/tutorials/Hello,-World!.md +6 -0
- package/docs/tutorials/Improving-Performance.md +6 -0
- package/docs/tutorials/Increasing-Rendering-Speed.md +6 -0
- package/docs/tutorials/Introducing-X3D.md +6 -0
- package/docs/tutorials/Introducing-animation.md +6 -0
- package/docs/tutorials/Introducing-script-use.md +6 -0
- package/docs/tutorials/Lighting-your-world.md +6 -0
- package/docs/tutorials/Mapping-textures.md +6 -0
- package/docs/tutorials/Naming-nodes.md +6 -0
- package/docs/tutorials/Providing-information-about-your-world.md +6 -0
- package/docs/tutorials/Sensing-the-viewer.md +6 -0
- package/docs/tutorials/Sensing-viewer-actions.md +6 -0
- package/docs/tutorials/Transforming-Shapes.md +6 -0
- package/docs/tutorials/Writing-program-scripts-with-ECMAScript.md +6 -0
- package/docs/tutorials/index.md +6 -0
- package/package.json +6 -7
- package/src/assets/components/geometry2d.js +1 -1
- package/src/assets/components/key-device-sensor.js +1 -1
- package/src/assets/components/layout.js +1 -1
- package/src/assets/components/particle-systems.js +1 -1
- package/src/assets/components/volume-rendering.js +1 -1
- package/src/assets/linetype/1.png +0 -0
- package/src/assets/linetype/10.png +0 -0
- package/src/assets/linetype/11.png +0 -0
- package/src/assets/linetype/12.png +0 -0
- package/src/assets/linetype/13.png +0 -0
- package/src/assets/linetype/14.png +0 -0
- package/src/assets/linetype/15.png +0 -0
- package/src/assets/linetype/16.png +0 -0
- package/src/assets/linetype/2.png +0 -0
- package/src/assets/linetype/3.png +0 -0
- package/src/assets/linetype/4.png +0 -0
- package/src/assets/linetype/5.png +0 -0
- package/src/assets/linetype/6.png +0 -0
- package/src/assets/linetype/7.png +0 -0
- package/src/assets/linetype/8.png +0 -0
- package/src/assets/linetype/9.png +0 -0
- package/src/assets/shaders/Types.glsl +1 -9
- package/src/assets/shaders/webgl1/Line.fs +3 -28
- package/src/assets/shaders/webgl1/Line.vs +5 -19
- package/src/assets/shaders/webgl1/PBR.vs +1 -1
- package/src/assets/shaders/webgl1/Point.vs +2 -3
- package/src/assets/shaders/webgl2/Depth.vs +4 -1
- package/src/assets/shaders/webgl2/Gouraud.vs +5 -3
- package/src/assets/shaders/webgl2/Line.fs +11 -17
- package/src/assets/shaders/webgl2/Line.vs +16 -20
- package/src/assets/shaders/webgl2/LineTransform.fs +6 -0
- package/src/assets/shaders/webgl2/LineTransform.vs +77 -0
- package/src/assets/shaders/webgl2/PBR.vs +10 -7
- package/src/assets/shaders/webgl2/Phong.vs +6 -3
- package/src/assets/shaders/webgl2/Point.vs +6 -6
- package/src/assets/shaders/webgl2/Unlit.vs +6 -3
- package/src/assets/shaders/webgl2/include/Line2.glsl +20 -0
- package/src/assets/shaders/webgl2/include/Particle.glsl +36 -0
- package/src/example.html +6 -6
- package/src/standard/Math/Algorithm.js +12 -28
- package/src/standard/Math/Geometry/Plane3.js +0 -2
- package/src/standard/Math/Geometry/ViewVolume.js +88 -83
- package/src/standard/Math/Numbers/Color3.js +6 -0
- package/src/standard/Math/Numbers/Color4.js +7 -0
- package/src/standard/Math/Numbers/Complex.js +5 -0
- package/src/standard/Math/Numbers/Matrix2.js +20 -2
- package/src/standard/Math/Numbers/Matrix3.js +129 -110
- package/src/standard/Math/Numbers/Matrix4.js +138 -119
- package/src/standard/Math/Numbers/Quaternion.js +7 -0
- package/src/standard/Math/Numbers/Rotation4.js +7 -0
- package/src/standard/Math/Numbers/Vector2.js +8 -5
- package/src/standard/Math/Numbers/Vector3.js +16 -10
- package/src/standard/Math/Numbers/Vector4.js +12 -7
- package/src/standard/Math/Utility/BVH.js +45 -17
- package/src/tests.js +6 -1
- package/src/x_ite/Base/X3DBaseNode.js +22 -11
- package/src/x_ite/Base/X3DField.js +1 -1
- package/src/x_ite/Browser/Core/BrowserOptions.js +2 -2
- package/src/x_ite/Browser/Core/BrowserTimings.js +4 -2
- package/src/x_ite/Browser/Core/Context.js +185 -0
- package/src/x_ite/Browser/Core/ContextMenu.js +299 -193
- package/src/x_ite/Browser/Core/Notification.js +1 -0
- package/src/x_ite/Browser/Core/X3DCoreContext.js +35 -146
- package/src/x_ite/Browser/Layout/ScreenText.js +11 -4
- package/src/x_ite/Browser/Layout/X3DLayoutContext.js +4 -15
- package/src/x_ite/Browser/Navigation/ExamineViewer.js +12 -19
- package/src/x_ite/Browser/Navigation/LookAtViewer.js +0 -3
- package/src/x_ite/Browser/Navigation/PlaneViewer.js +0 -3
- package/src/x_ite/Browser/Navigation/X3DFlyViewer.js +14 -7
- package/src/x_ite/Browser/Navigation/X3DViewer.js +12 -20
- package/src/x_ite/Browser/Networking/X3DNetworkingContext.js +11 -7
- package/src/x_ite/Browser/ParticleSystems/BVH.glsl +183 -0
- package/src/x_ite/Browser/ParticleSystems/Box3.glsl +47 -0
- package/src/x_ite/Browser/ParticleSystems/GeometryTypes.js +66 -0
- package/src/x_ite/Browser/ParticleSystems/Line3.glsl +55 -0
- package/src/x_ite/Browser/ParticleSystems/Plane3.glsl +160 -0
- package/src/x_ite/Browser/PointingDeviceSensor/PointingDevice.js +27 -3
- package/src/x_ite/Browser/PointingDeviceSensor/X3DPointingDeviceSensorContext.js +37 -37
- package/src/x_ite/Browser/Rendering/X3DRenderingContext.js +19 -13
- package/src/x_ite/Browser/Shaders/Shader.js +33 -12
- package/src/x_ite/Browser/Shaders/ShaderSource.js +6 -0
- package/src/x_ite/Browser/Shaders/ShaderTest.js +16 -10
- package/src/x_ite/Browser/Shape/X3DShapeContext.js +50 -9
- package/src/x_ite/Browser/Text/X3DTextContext.js +4 -13
- package/src/x_ite/Browser/Texturing/X3DTexturingContext.js +23 -33
- package/src/x_ite/Browser/Texturing3D/DICOMParser.js +2 -2
- package/src/x_ite/Browser/Time/X3DTimeContext.js +3 -1
- package/src/x_ite/Browser/VERSION.js +1 -1
- package/src/x_ite/Browser/X3DBrowser.js +7 -6
- package/src/x_ite/Browser/X3DBrowserContext.js +35 -10
- package/src/x_ite/Components/Core/X3DNode.js +4 -0
- package/src/x_ite/Components/Core/X3DPrototypeInstance.js +0 -2
- package/src/x_ite/Components/CubeMapTexturing/ComposedCubeMapTexture.js +3 -4
- package/src/x_ite/Components/CubeMapTexturing/GeneratedCubeMapTexture.js +1 -12
- package/src/x_ite/Components/CubeMapTexturing/ImageCubeMapTexture.js +0 -1
- package/src/x_ite/Components/EnvironmentalEffects/TextureBackground.js +1 -1
- package/src/x_ite/Components/EnvironmentalEffects/X3DBackgroundNode.js +76 -77
- package/src/x_ite/Components/EnvironmentalEffects/X3DFogObject.js +2 -9
- package/src/x_ite/Components/EnvironmentalSensor/ProximitySensor.js +51 -65
- package/src/x_ite/Components/EventUtilities/X3DSequencerNode.js +1 -1
- package/src/x_ite/Components/Followers/X3DChaserNode.js +18 -32
- package/src/x_ite/Components/Followers/X3DDamperNode.js +1 -6
- package/src/x_ite/Components/Geometry2D/TriangleSet2D.js +1 -1
- package/src/x_ite/Components/Geometry3D/ElevationGrid.js +12 -4
- package/src/x_ite/Components/Geometry3D/IndexedFaceSet.js +4 -4
- package/src/x_ite/Components/Geospatial/GeoCoordinate.js +10 -27
- package/src/x_ite/Components/Geospatial/GeoPositionInterpolator.js +5 -10
- package/src/x_ite/Components/Geospatial/GeoTouchSensor.js +9 -16
- package/src/x_ite/Components/Geospatial/GeoTransform.js +6 -18
- package/src/x_ite/Components/Geospatial/X3DGeospatialObject.js +20 -27
- package/src/x_ite/Components/Grouping/X3DGroupingNode.js +8 -8
- package/src/x_ite/Components/Grouping/X3DTransformNode.js +0 -4
- package/src/x_ite/Components/HAnim/HAnimHumanoid.js +68 -75
- package/src/x_ite/Components/Interpolation/OrientationInterpolator.js +4 -11
- package/src/x_ite/Components/Interpolation/X3DInterpolatorNode.js +1 -1
- package/src/x_ite/Components/Layout/LayoutGroup.js +4 -9
- package/src/x_ite/Components/Layout/ScreenFontStyle.js +1 -1
- package/src/x_ite/Components/Layout/ScreenGroup.js +18 -23
- package/src/x_ite/Components/Lighting/DirectionalLight.js +28 -36
- package/src/x_ite/Components/Lighting/PointLight.js +32 -47
- package/src/x_ite/Components/Lighting/SpotLight.js +33 -48
- package/src/x_ite/Components/Navigation/Billboard.js +49 -56
- package/src/x_ite/Components/Navigation/LOD.js +1 -1
- package/src/x_ite/Components/Navigation/X3DViewpointNode.js +82 -111
- package/src/x_ite/Components/Networking/Anchor.js +10 -4
- package/src/x_ite/Components/ParticleSystems/BoundedPhysicsModel.js +6 -6
- package/src/x_ite/Components/ParticleSystems/ConeEmitter.js +44 -36
- package/src/x_ite/Components/ParticleSystems/ExplosionEmitter.js +26 -17
- package/src/x_ite/Components/ParticleSystems/ForcePhysicsModel.js +20 -7
- package/src/x_ite/Components/ParticleSystems/ParticleSystem.js +461 -876
- package/src/x_ite/Components/ParticleSystems/PointEmitter.js +39 -35
- package/src/x_ite/Components/ParticleSystems/PolylineEmitter.js +112 -128
- package/src/x_ite/Components/ParticleSystems/SurfaceEmitter.js +105 -112
- package/src/x_ite/Components/ParticleSystems/VolumeEmitter.js +138 -176
- package/src/x_ite/Components/ParticleSystems/WindPhysicsModel.js +16 -11
- package/src/x_ite/Components/ParticleSystems/X3DParticleEmitterNode.js +807 -217
- package/src/x_ite/Components/Picking/LinePickSensor.js +31 -39
- package/src/x_ite/Components/PointingDeviceSensor/CylinderSensor.js +90 -107
- package/src/x_ite/Components/PointingDeviceSensor/PlaneSensor.js +48 -55
- package/src/x_ite/Components/PointingDeviceSensor/SphereSensor.js +53 -70
- package/src/x_ite/Components/PointingDeviceSensor/TouchSensor.js +8 -15
- package/src/x_ite/Components/ProjectiveTextureMapping/TextureProjectorParallel.js +43 -50
- package/src/x_ite/Components/ProjectiveTextureMapping/TextureProjectorPerspective.js +32 -39
- package/src/x_ite/Components/Rendering/ClipPlane.js +3 -11
- package/src/x_ite/Components/Rendering/Color.js +12 -37
- package/src/x_ite/Components/Rendering/ColorRGBA.js +13 -38
- package/src/x_ite/Components/Rendering/IndexedLineSet.js +12 -4
- package/src/x_ite/Components/Rendering/LineSet.js +21 -13
- package/src/x_ite/Components/Rendering/PointSet.js +21 -13
- package/src/x_ite/Components/Rendering/X3DColorNode.js +13 -0
- package/src/x_ite/Components/Rendering/X3DComposedGeometryNode.js +13 -5
- package/src/x_ite/Components/Rendering/X3DGeometryNode.js +248 -325
- package/src/x_ite/Components/Rendering/X3DLineGeometryNode.js +305 -134
- package/src/x_ite/Components/Rendering/X3DPointGeometryNode.js +99 -122
- package/src/x_ite/Components/RigidBodyPhysics/DoubleAxisHingeJoint.js +24 -38
- package/src/x_ite/Components/RigidBodyPhysics/SingleAxisHingeJoint.js +10 -17
- package/src/x_ite/Components/Shaders/ComposedShader.js +35 -75
- package/src/x_ite/Components/Shaders/FloatVertexAttribute.js +5 -15
- package/src/x_ite/Components/Shaders/Matrix3VertexAttribute.js +7 -24
- package/src/x_ite/Components/Shaders/Matrix4VertexAttribute.js +7 -24
- package/src/x_ite/Components/Shaders/ShaderPart.js +1 -10
- package/src/x_ite/Components/Shaders/X3DProgrammableShaderObject.js +219 -209
- package/src/x_ite/Components/Shaders/X3DShaderNode.js +1 -1
- package/src/x_ite/Components/Shaders/X3DVertexAttributeNode.js +23 -1
- package/src/x_ite/Components/Shape/Appearance.js +12 -0
- package/src/x_ite/Components/Shape/FillProperties.js +12 -1
- package/src/x_ite/Components/Shape/LineProperties.js +33 -1
- package/src/x_ite/Components/Shape/PointProperties.js +23 -1
- package/src/x_ite/Components/Shape/Shape.js +27 -34
- package/src/x_ite/Components/Sound/Sound.js +30 -40
- package/src/x_ite/Components/Text/Text.js +6 -20
- package/src/x_ite/Components/Texturing/TextureCoordinate.js +5 -26
- package/src/x_ite/Components/Texturing/TextureProperties.js +4 -4
- package/src/x_ite/Components/Texturing/X3DSingleTextureCoordinateNode.js +21 -0
- package/src/x_ite/Components/Texturing/X3DSingleTextureNode.js +5 -4
- package/src/x_ite/Components/Texturing/X3DTexture2DNode.js +24 -33
- package/src/x_ite/Components/Texturing3D/TextureCoordinate3D.js +5 -26
- package/src/x_ite/Components/Texturing3D/TextureCoordinate4D.js +5 -26
- package/src/x_ite/Components/Texturing3D/X3DTexture3DNode.js +12 -19
- package/src/x_ite/Components/VolumeRendering/X3DVolumeDataNode.js +7 -7
- package/src/x_ite/Components.js +2 -2
- package/src/x_ite/Fallback.js +9 -3
- package/src/x_ite/Fields/SFColor.js +4 -0
- package/src/x_ite/Fields/SFColorRGBA.js +4 -0
- package/src/x_ite/Fields/SFMatrixPrototypeTemplate.js +4 -0
- package/src/x_ite/Fields/SFRotation.js +4 -0
- package/src/x_ite/Fields/SFString.js +4 -0
- package/src/x_ite/Fields/SFVecPrototypeTemplate.js +4 -0
- package/src/x_ite/Parser/XMLParser.js +1 -1
- package/src/x_ite/Rendering/TextureBuffer.js +43 -36
- package/src/x_ite/Rendering/VertexArray.js +101 -0
- package/src/x_ite/Rendering/X3DRenderObject.js +123 -144
- package/src/x_ite/X3D.js +32 -26
- package/src/x_ite.config.js +0 -5
- package/src/x_ite.css +200 -162
- package/src/x_ite.html +26 -10
- package/src/x_ite.js +42 -0
- package/x_ite.min.html +26 -10
- package/dist/assets/hatching/0.png +0 -0
- package/dist/assets/linetype/0.png +0 -0
- package/src/assets/hatching/0.png +0 -0
- package/src/assets/linetype/0.png +0 -0
- package/src/spinner.css +0 -67
- package/src/x_ite/Browser/Shape/LineStipples.xcf +0 -0
|
@@ -49,41 +49,23 @@
|
|
|
49
49
|
|
|
50
50
|
define ([
|
|
51
51
|
"x_ite/Components/Core/X3DNode",
|
|
52
|
+
"x_ite/Browser/ParticleSystems/GeometryTypes",
|
|
52
53
|
"x_ite/Base/X3DConstants",
|
|
53
|
-
"
|
|
54
|
-
"
|
|
55
|
-
"
|
|
56
|
-
"
|
|
57
|
-
"standard/Math/Algorithm",
|
|
58
|
-
"standard/Math/Algorithms/QuickSort",
|
|
54
|
+
"text!x_ite/Browser/ParticleSystems/Line3.glsl",
|
|
55
|
+
"text!x_ite/Browser/ParticleSystems/Plane3.glsl",
|
|
56
|
+
"text!x_ite/Browser/ParticleSystems/Box3.glsl",
|
|
57
|
+
"text!x_ite/Browser/ParticleSystems/BVH.glsl",
|
|
59
58
|
],
|
|
60
59
|
function (X3DNode,
|
|
60
|
+
GeometryTypes,
|
|
61
61
|
X3DConstants,
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
Algorithm,
|
|
67
|
-
QuickSort)
|
|
62
|
+
Line3Source,
|
|
63
|
+
Plane3Source,
|
|
64
|
+
Box3Source,
|
|
65
|
+
BVHSource)
|
|
68
66
|
{
|
|
69
67
|
"use strict";
|
|
70
68
|
|
|
71
|
-
var
|
|
72
|
-
normal = new Vector3 (0, 0, 0),
|
|
73
|
-
fromPosition = new Vector3 (0, 0, 0),
|
|
74
|
-
line = new Line3 (Vector3 .Zero, Vector3 .zAxis),
|
|
75
|
-
plane = new Plane3 (Vector3 .Zero, Vector3 .zAxis);
|
|
76
|
-
|
|
77
|
-
function PlaneCompare (a, b)
|
|
78
|
-
{
|
|
79
|
-
return plane .getDistanceToPoint (a) < plane .getDistanceToPoint (b);
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
function PlaneCompareValue (a, b)
|
|
83
|
-
{
|
|
84
|
-
return a < plane .getDistanceToPoint (b);
|
|
85
|
-
}
|
|
86
|
-
|
|
87
69
|
function X3DParticleEmitterNode (executionContext)
|
|
88
70
|
{
|
|
89
71
|
X3DNode .call (this, executionContext);
|
|
@@ -94,10 +76,23 @@ function (X3DNode,
|
|
|
94
76
|
this ._mass .setUnit ("mass");
|
|
95
77
|
this ._surfaceArea .setUnit ("area");
|
|
96
78
|
|
|
97
|
-
this .
|
|
98
|
-
this .
|
|
99
|
-
this .
|
|
100
|
-
this .
|
|
79
|
+
this .samplers = [ ];
|
|
80
|
+
this .uniforms = { };
|
|
81
|
+
this .functions = [ ];
|
|
82
|
+
this .program = null;
|
|
83
|
+
|
|
84
|
+
this .addSampler ("forces");
|
|
85
|
+
this .addSampler ("boundedVolume");
|
|
86
|
+
this .addSampler ("colorRamp");
|
|
87
|
+
this .addSampler ("texCoordRamp");
|
|
88
|
+
|
|
89
|
+
this .addUniform ("speed", "uniform float speed;");
|
|
90
|
+
this .addUniform ("variation", "uniform float variation;");
|
|
91
|
+
|
|
92
|
+
this .addFunction (Line3Source);
|
|
93
|
+
this .addFunction (Plane3Source);
|
|
94
|
+
this .addFunction (Box3Source);
|
|
95
|
+
this .addFunction (BVHSource);
|
|
101
96
|
}
|
|
102
97
|
|
|
103
98
|
X3DParticleEmitterNode .prototype = Object .assign (Object .create (X3DNode .prototype),
|
|
@@ -107,26 +102,28 @@ function (X3DNode,
|
|
|
107
102
|
{
|
|
108
103
|
X3DNode .prototype .initialize .call (this);
|
|
109
104
|
|
|
110
|
-
this .
|
|
105
|
+
const gl = this .getBrowser () .getContext ();
|
|
106
|
+
|
|
107
|
+
if (gl .getVersion () < 2)
|
|
108
|
+
return;
|
|
109
|
+
|
|
110
|
+
// Create program.
|
|
111
|
+
|
|
112
|
+
this .program = this .createProgram ();
|
|
113
|
+
this .transformFeedback = gl .createTransformFeedback ();
|
|
114
|
+
|
|
115
|
+
// Initialize fields.
|
|
116
|
+
|
|
117
|
+
this ._on .addInterest ("set_on__", this);
|
|
118
|
+
this ._speed .addInterest ("set_speed__", this);
|
|
111
119
|
this ._variation .addInterest ("set_variation__", this);
|
|
112
|
-
this ._mass .addInterest ("set_mass__",
|
|
120
|
+
this ._mass .addInterest ("set_mass__", this);
|
|
113
121
|
|
|
122
|
+
this .set_on__ ();
|
|
114
123
|
this .set_speed__ ();
|
|
115
124
|
this .set_variation__ ();
|
|
116
125
|
this .set_mass__ ();
|
|
117
126
|
},
|
|
118
|
-
set_speed__: function ()
|
|
119
|
-
{
|
|
120
|
-
this .speed = this ._speed .getValue ();
|
|
121
|
-
},
|
|
122
|
-
set_variation__: function ()
|
|
123
|
-
{
|
|
124
|
-
this .variation = this ._variation .getValue ();
|
|
125
|
-
},
|
|
126
|
-
set_mass__: function ()
|
|
127
|
-
{
|
|
128
|
-
this .mass = this ._mass .getValue ();
|
|
129
|
-
},
|
|
130
127
|
isExplosive: function ()
|
|
131
128
|
{
|
|
132
129
|
return false;
|
|
@@ -135,28 +132,21 @@ function (X3DNode,
|
|
|
135
132
|
{
|
|
136
133
|
return this .mass;
|
|
137
134
|
},
|
|
138
|
-
|
|
135
|
+
set_on__: function ()
|
|
139
136
|
{
|
|
140
|
-
|
|
141
|
-
v = particleLifetime * lifetimeVariation,
|
|
142
|
-
min = Math .max (0, particleLifetime - v),
|
|
143
|
-
max = particleLifetime + v;
|
|
144
|
-
|
|
145
|
-
return Math .random () * (max - min) + min;
|
|
137
|
+
this .on = this ._on .getValue ();
|
|
146
138
|
},
|
|
147
|
-
|
|
139
|
+
set_speed__: function ()
|
|
148
140
|
{
|
|
149
|
-
|
|
150
|
-
speed = this .speed,
|
|
151
|
-
v = speed * this .variation,
|
|
152
|
-
min = Math .max (0, speed - v),
|
|
153
|
-
max = speed + v;
|
|
154
|
-
|
|
155
|
-
return Math .random () * (max - min) + min;
|
|
141
|
+
this .setUniform ("uniform1f", "speed", this ._speed .getValue ());
|
|
156
142
|
},
|
|
157
|
-
|
|
143
|
+
set_variation__: function ()
|
|
158
144
|
{
|
|
159
|
-
|
|
145
|
+
this .setUniform ("uniform1f", "variation", this ._variation .getValue ());
|
|
146
|
+
},
|
|
147
|
+
set_mass__: function ()
|
|
148
|
+
{
|
|
149
|
+
this .mass = this ._mass .getValue ();
|
|
160
150
|
},
|
|
161
151
|
getRandomValue: function (min, max)
|
|
162
152
|
{
|
|
@@ -164,7 +154,7 @@ function (X3DNode,
|
|
|
164
154
|
},
|
|
165
155
|
getRandomNormal: function (normal)
|
|
166
156
|
{
|
|
167
|
-
|
|
157
|
+
const
|
|
168
158
|
theta = this .getRandomValue (-1, 1) * Math .PI,
|
|
169
159
|
cphi = this .getRandomValue (-1, 1),
|
|
170
160
|
phi = Math .acos (cphi),
|
|
@@ -174,234 +164,834 @@ function (X3DNode,
|
|
|
174
164
|
Math .cos (theta) * r,
|
|
175
165
|
cphi);
|
|
176
166
|
},
|
|
177
|
-
|
|
167
|
+
animate: function (particleSystem, deltaTime)
|
|
178
168
|
{
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
169
|
+
const
|
|
170
|
+
browser = this .getBrowser (),
|
|
171
|
+
gl = browser .getContext (),
|
|
172
|
+
inputParticles = particleSystem .inputParticles,
|
|
173
|
+
particleStride = particleSystem .particleStride,
|
|
174
|
+
particleOffsets = particleSystem .particleOffsets,
|
|
175
|
+
program = this .program;
|
|
184
176
|
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
177
|
+
// Start
|
|
178
|
+
|
|
179
|
+
gl .useProgram (program);
|
|
180
|
+
|
|
181
|
+
// Uniforms
|
|
182
|
+
|
|
183
|
+
gl .uniform1i (program .randomSeed, Math .random () * 0xffffffff);
|
|
184
|
+
gl .uniform1i (program .geometryType, particleSystem .geometryType);
|
|
185
|
+
gl .uniform1i (program .createParticles, particleSystem .createParticles && this .on);
|
|
186
|
+
gl .uniform1f (program .particleLifetime, particleSystem .particleLifetime);
|
|
187
|
+
gl .uniform1f (program .lifetimeVariation, particleSystem .lifetimeVariation);
|
|
188
|
+
gl .uniform1f (program .deltaTime, deltaTime);
|
|
189
|
+
gl .uniform2f (program .particleSize, particleSystem ._particleSize .x, particleSystem ._particleSize .y);
|
|
190
|
+
|
|
191
|
+
// Forces
|
|
192
|
+
|
|
193
|
+
gl .uniform1i (program .numForces, particleSystem .numForces);
|
|
194
|
+
|
|
195
|
+
if (particleSystem .numForces)
|
|
196
|
+
{
|
|
197
|
+
gl .activeTexture (gl .TEXTURE0 + program .forcesTextureUnit);
|
|
198
|
+
gl .bindTexture (gl .TEXTURE_2D, particleSystem .forcesTexture);
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
// Bounded Physics
|
|
202
|
+
|
|
203
|
+
if (particleSystem .boundedHierarchyRoot < 0)
|
|
204
|
+
{
|
|
205
|
+
gl .uniform1i (program .boundedHierarchyRoot, -1);
|
|
206
|
+
}
|
|
207
|
+
else
|
|
208
|
+
{
|
|
209
|
+
gl .uniform1i (program .boundedVerticesIndex, particleSystem .boundedVerticesIndex);
|
|
210
|
+
gl .uniform1i (program .boundedNormalsIndex, particleSystem .boundedNormalsIndex);
|
|
211
|
+
gl .uniform1i (program .boundedHierarchyIndex, particleSystem .boundedHierarchyIndex);
|
|
212
|
+
gl .uniform1i (program .boundedHierarchyRoot, particleSystem .boundedHierarchyRoot);
|
|
213
|
+
|
|
214
|
+
gl .activeTexture (gl .TEXTURE0 + program .boundedVolumeTextureUnit);
|
|
215
|
+
gl .bindTexture (gl .TEXTURE_2D, particleSystem .boundedTexture);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
// Colors
|
|
219
|
+
|
|
220
|
+
gl .uniform1i (program .numColors, particleSystem .numColors);
|
|
221
|
+
|
|
222
|
+
if (particleSystem .numColors)
|
|
223
|
+
{
|
|
224
|
+
gl .activeTexture (gl .TEXTURE0 + program .colorRampTextureUnit);
|
|
225
|
+
gl .bindTexture (gl .TEXTURE_2D, particleSystem .colorRampTexture);
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
// TexCoords
|
|
229
|
+
|
|
230
|
+
gl .uniform1i (program .numTexCoords, particleSystem .numTexCoords);
|
|
231
|
+
|
|
232
|
+
if (particleSystem .numTexCoords)
|
|
233
|
+
{
|
|
234
|
+
gl .uniform1i (program .texCoordCount, particleSystem .texCoordCount);
|
|
235
|
+
|
|
236
|
+
gl .activeTexture (gl .TEXTURE0 + program .texCoordRampTextureUnit);
|
|
237
|
+
gl .bindTexture (gl .TEXTURE_2D, particleSystem .texCoordRampTexture);
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
// Other textures
|
|
241
|
+
|
|
242
|
+
this .activateTextures (gl, program);
|
|
243
|
+
|
|
244
|
+
// Input attributes
|
|
245
|
+
|
|
246
|
+
if (inputParticles .emitterArrayObject .enable (gl, program))
|
|
247
|
+
{
|
|
248
|
+
for (const [i, attribute] of program .inputs)
|
|
249
|
+
{
|
|
250
|
+
gl .bindBuffer (gl .ARRAY_BUFFER, inputParticles);
|
|
251
|
+
gl .enableVertexAttribArray (attribute);
|
|
252
|
+
gl .vertexAttribPointer (attribute, 4, gl .FLOAT, false, particleStride, particleOffsets [i]);
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
gl .bindBuffer (gl .ARRAY_BUFFER, null);
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
// Transform particles.
|
|
259
|
+
|
|
260
|
+
gl .bindTransformFeedback (gl .TRANSFORM_FEEDBACK, this .transformFeedback);
|
|
261
|
+
gl .bindBufferBase (gl .TRANSFORM_FEEDBACK_BUFFER, 0, particleSystem .outputParticles);
|
|
262
|
+
gl .enable (gl .RASTERIZER_DISCARD);
|
|
263
|
+
gl .beginTransformFeedback (gl .POINTS);
|
|
264
|
+
gl .drawArrays (gl .POINTS, 0, particleSystem .numParticles);
|
|
265
|
+
gl .endTransformFeedback ();
|
|
266
|
+
gl .disable (gl .RASTERIZER_DISCARD);
|
|
267
|
+
gl .bindTransformFeedback (gl .TRANSFORM_FEEDBACK, null);
|
|
268
|
+
|
|
269
|
+
// DEBUG
|
|
270
|
+
|
|
271
|
+
// const data = new Float32Array (particleSystem .numParticles * (particleStride / 4));
|
|
272
|
+
// gl .bindBuffer (gl .ARRAY_BUFFER, particleSystem .outputParticles);
|
|
273
|
+
// gl .getBufferSubData (gl .ARRAY_BUFFER, 0, data);
|
|
274
|
+
// console .log (data .slice (0, particleStride / 4));
|
|
188
275
|
},
|
|
189
|
-
|
|
276
|
+
addSampler: function (name)
|
|
190
277
|
{
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
return rotation .multVecRot (this .getRandomNormalWithAngle (angle, normal));
|
|
278
|
+
this .samplers .push (name);
|
|
194
279
|
},
|
|
195
|
-
|
|
280
|
+
addUniform: function (name, uniform)
|
|
196
281
|
{
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
282
|
+
this .uniforms [name] = uniform;
|
|
283
|
+
},
|
|
284
|
+
setUniform: function (func, name, value1, value2, value3)
|
|
285
|
+
{
|
|
286
|
+
const
|
|
287
|
+
gl = this .getBrowser () .getContext (),
|
|
288
|
+
program = this .program;
|
|
202
289
|
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
cphi);
|
|
290
|
+
gl .useProgram (program);
|
|
291
|
+
gl [func] (program [name], value1, value2, value3);
|
|
206
292
|
},
|
|
207
|
-
|
|
293
|
+
addFunction: function (func)
|
|
208
294
|
{
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
295
|
+
this .functions .push (func);
|
|
296
|
+
},
|
|
297
|
+
createProgram: function ()
|
|
298
|
+
{
|
|
299
|
+
const
|
|
300
|
+
browser = this .getBrowser (),
|
|
301
|
+
gl = browser .getContext ();
|
|
302
|
+
|
|
303
|
+
const vertexShaderSource = /* glsl */ `#version 300 es
|
|
304
|
+
|
|
305
|
+
precision highp float;
|
|
306
|
+
precision highp int;
|
|
307
|
+
precision highp sampler2D;
|
|
308
|
+
|
|
309
|
+
uniform int randomSeed;
|
|
310
|
+
uniform int geometryType;
|
|
311
|
+
uniform bool createParticles;
|
|
312
|
+
uniform float particleLifetime;
|
|
313
|
+
uniform float lifetimeVariation;
|
|
314
|
+
uniform float deltaTime;
|
|
315
|
+
uniform vec2 particleSize;
|
|
316
|
+
|
|
317
|
+
uniform int numForces;
|
|
318
|
+
uniform sampler2D forces;
|
|
319
|
+
|
|
320
|
+
uniform int boundedVerticesIndex;
|
|
321
|
+
uniform int boundedNormalsIndex;
|
|
322
|
+
uniform int boundedHierarchyIndex;
|
|
323
|
+
uniform int boundedHierarchyRoot;
|
|
324
|
+
uniform sampler2D boundedVolume;
|
|
325
|
+
|
|
326
|
+
uniform int numColors;
|
|
327
|
+
uniform sampler2D colorRamp;
|
|
328
|
+
|
|
329
|
+
uniform int texCoordCount;
|
|
330
|
+
uniform int numTexCoords;
|
|
331
|
+
uniform sampler2D texCoordRamp;
|
|
332
|
+
|
|
333
|
+
${Object .values (this .uniforms) .join ("\n")}
|
|
334
|
+
|
|
335
|
+
in vec4 input0;
|
|
336
|
+
in vec4 input2;
|
|
337
|
+
in vec4 input6;
|
|
338
|
+
|
|
339
|
+
out vec4 output0;
|
|
340
|
+
out vec4 output1;
|
|
341
|
+
out vec4 output2;
|
|
342
|
+
|
|
343
|
+
out vec4 output3;
|
|
344
|
+
out vec4 output4;
|
|
345
|
+
out vec4 output5;
|
|
346
|
+
out vec4 output6;
|
|
347
|
+
|
|
348
|
+
// Constants
|
|
349
|
+
|
|
350
|
+
${Object .entries (GeometryTypes) .map (([k, v]) => `#define ${k} ${v}`) .join ("\n")}
|
|
351
|
+
|
|
352
|
+
const int ARRAY_SIZE = 32;
|
|
353
|
+
const float M_PI = 3.14159265359;
|
|
354
|
+
|
|
355
|
+
uniform float NaN;
|
|
356
|
+
|
|
357
|
+
// Texture
|
|
358
|
+
|
|
359
|
+
vec4
|
|
360
|
+
texelFetch (const in sampler2D sampler, const in int index, const in int lod)
|
|
230
361
|
{
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
362
|
+
int x = textureSize (sampler, lod) .x;
|
|
363
|
+
ivec2 p = ivec2 (index % x, index / x);
|
|
364
|
+
vec4 t = texelFetch (sampler, p, lod);
|
|
234
365
|
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
// Create new particle or hide particle.
|
|
366
|
+
return t;
|
|
367
|
+
}
|
|
238
368
|
|
|
239
|
-
|
|
240
|
-
particle .elapsedTime = 0;
|
|
369
|
+
// Math
|
|
241
370
|
|
|
242
|
-
|
|
371
|
+
// Save normalize, that will not divide by zero.
|
|
372
|
+
vec3
|
|
373
|
+
save_normalize (const in vec3 vector)
|
|
374
|
+
{
|
|
375
|
+
float l = length (vector);
|
|
376
|
+
|
|
377
|
+
if (l == 0.0)
|
|
378
|
+
return vec3 (0.0);
|
|
379
|
+
|
|
380
|
+
return vector / l;
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
// Quaternion
|
|
384
|
+
|
|
385
|
+
vec4
|
|
386
|
+
Quaternion (const in vec3 fromVector, const in vec3 toVector)
|
|
387
|
+
{
|
|
388
|
+
vec3 from = save_normalize (fromVector);
|
|
389
|
+
vec3 to = save_normalize (toVector);
|
|
390
|
+
|
|
391
|
+
float cos_angle = dot (from, to);
|
|
392
|
+
vec3 cross_vec = cross (from, to);
|
|
393
|
+
float cross_len = length (cross_vec);
|
|
394
|
+
|
|
395
|
+
if (cross_len == 0.0)
|
|
396
|
+
{
|
|
397
|
+
if (cos_angle > 0.0)
|
|
243
398
|
{
|
|
244
|
-
|
|
245
|
-
this .getRandomPosition (particle .position);
|
|
246
|
-
this .getRandomVelocity (particle .velocity);
|
|
399
|
+
return vec4 (0.0, 0.0, 0.0, 1.0);
|
|
247
400
|
}
|
|
248
401
|
else
|
|
249
|
-
|
|
402
|
+
{
|
|
403
|
+
vec3 t = cross (from, vec3 (1.0, 0.0, 0.0));
|
|
404
|
+
|
|
405
|
+
if (dot (t, t) == 0.0)
|
|
406
|
+
t = cross (from, vec3 (0.0, 1.0, 0.0));
|
|
407
|
+
|
|
408
|
+
t = save_normalize (t);
|
|
409
|
+
|
|
410
|
+
return vec4 (t, 0.0);
|
|
411
|
+
}
|
|
250
412
|
}
|
|
251
413
|
else
|
|
252
414
|
{
|
|
253
|
-
|
|
415
|
+
float s = sqrt (abs (1.0 - cos_angle) * 0.5);
|
|
416
|
+
|
|
417
|
+
cross_vec = save_normalize (cross_vec);
|
|
418
|
+
|
|
419
|
+
return vec4 (cross_vec * s, sqrt (abs (1.0 + cos_angle) * 0.5));
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
vec3
|
|
424
|
+
multVecQuat (const in vec3 v, const in vec4 q)
|
|
425
|
+
{
|
|
426
|
+
float a = q .w * q .w - q .x * q .x - q .y * q .y - q .z * q .z;
|
|
427
|
+
float b = 2.0 * (v .x * q .x + v .y * q .y + v .z * q .z);
|
|
428
|
+
float c = 2.0 * q .w;
|
|
429
|
+
vec3 r = a * v .xyz + b * q .xyz + c * (q .yzx * v .zxy - q .zxy * v .yzx);
|
|
430
|
+
|
|
431
|
+
return r;
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
mat3
|
|
435
|
+
Matrix3 (const in vec4 quaternion)
|
|
436
|
+
{
|
|
437
|
+
float x = quaternion .x;
|
|
438
|
+
float y = quaternion .y;
|
|
439
|
+
float z = quaternion .z;
|
|
440
|
+
float w = quaternion .w;
|
|
441
|
+
float A = y * y;
|
|
442
|
+
float B = z * z;
|
|
443
|
+
float C = x * y;
|
|
444
|
+
float D = z * w;
|
|
445
|
+
float E = z * x;
|
|
446
|
+
float F = y * w;
|
|
447
|
+
float G = x * x;
|
|
448
|
+
float H = y * z;
|
|
449
|
+
float I = x * w;
|
|
450
|
+
|
|
451
|
+
return mat3 (1.0 - 2.0 * (A + B),
|
|
452
|
+
2.0 * (C + D),
|
|
453
|
+
2.0 * (E - F),
|
|
454
|
+
2.0 * (C - D),
|
|
455
|
+
1.0 - 2.0 * (B + G),
|
|
456
|
+
2.0 * (H + I),
|
|
457
|
+
2.0 * (E + F),
|
|
458
|
+
2.0 * (H - I),
|
|
459
|
+
1.0 - 2.0 * (A + G));
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
/* Random number generation */
|
|
463
|
+
|
|
464
|
+
uint seed = 1u;
|
|
465
|
+
|
|
466
|
+
void
|
|
467
|
+
srand (const in int value)
|
|
468
|
+
{
|
|
469
|
+
seed = uint (value);
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
// Return a uniform distributed random floating point number in the interval [0, 1].
|
|
473
|
+
float
|
|
474
|
+
random ()
|
|
475
|
+
{
|
|
476
|
+
seed = seed * 1103515245u + 12345u;
|
|
477
|
+
|
|
478
|
+
return float (seed) / 4294967295.0;
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
float
|
|
482
|
+
getRandomValue (const in float min, const in float max)
|
|
483
|
+
{
|
|
484
|
+
return min + random () * (max - min);
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
float
|
|
488
|
+
getRandomLifetime ()
|
|
489
|
+
{
|
|
490
|
+
float v = particleLifetime * lifetimeVariation;
|
|
491
|
+
float min_ = max (0.0, particleLifetime - v);
|
|
492
|
+
float max_ = particleLifetime + v;
|
|
254
493
|
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
494
|
+
return getRandomValue (min_, max_);
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
float
|
|
498
|
+
getRandomSpeed ()
|
|
499
|
+
{
|
|
500
|
+
float v = speed * variation;
|
|
501
|
+
float min_ = max (0.0, speed - v);
|
|
502
|
+
float max_ = speed + v;
|
|
503
|
+
|
|
504
|
+
return getRandomValue (min_, max_);
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
vec3
|
|
508
|
+
getRandomNormal ()
|
|
509
|
+
{
|
|
510
|
+
float theta = getRandomValue (-M_PI, M_PI);
|
|
511
|
+
float cphi = getRandomValue (-1.0, 1.0);
|
|
512
|
+
float r = sqrt (1.0 - cphi * cphi); // sin (acos (cphi));
|
|
513
|
+
|
|
514
|
+
return vec3 (sin (theta) * r, cos (theta) * r, cphi);
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
vec3
|
|
518
|
+
getRandomNormalWithAngle (const in float angle)
|
|
519
|
+
{
|
|
520
|
+
float theta = getRandomValue (-M_PI, M_PI);
|
|
521
|
+
float cphi = getRandomValue (cos (angle), 1.0);
|
|
522
|
+
float r = sqrt (1.0 - cphi * cphi); // sin (acos (cphi));
|
|
523
|
+
|
|
524
|
+
return vec3 (sin (theta) * r, cos (theta) * r, cphi);
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
vec3
|
|
528
|
+
getRandomNormalWithDirectionAndAngle (const in vec3 direction, const in float angle)
|
|
529
|
+
{
|
|
530
|
+
vec4 rotation = Quaternion (vec3 (0.0, 0.0, 1.0), direction);
|
|
531
|
+
vec3 normal = getRandomNormalWithAngle (angle);
|
|
258
532
|
|
|
259
|
-
|
|
533
|
+
return multVecQuat (normal, rotation);
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
vec3
|
|
537
|
+
getRandomSurfaceNormal (const in vec3 direction)
|
|
538
|
+
{
|
|
539
|
+
float theta = getRandomValue (-M_PI, M_PI);
|
|
540
|
+
float cphi = pow (random (), 1.0 / 3.0);
|
|
541
|
+
float r = sqrt (1.0 - cphi * cphi); // sin (acos (cphi));
|
|
542
|
+
vec3 normal = vec3 (sin (theta) * r, cos (theta) * r, cphi);
|
|
543
|
+
vec4 rotation = Quaternion (vec3 (0.0, 0.0, 1.0), direction);
|
|
544
|
+
|
|
545
|
+
return multVecQuat (normal, rotation);
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
vec3
|
|
549
|
+
getRandomSphericalVelocity ()
|
|
550
|
+
{
|
|
551
|
+
vec3 normal = getRandomNormal ();
|
|
552
|
+
float speed = getRandomSpeed ();
|
|
553
|
+
|
|
554
|
+
return normal * speed;
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
// Algorithms
|
|
558
|
+
|
|
559
|
+
int
|
|
560
|
+
upperBound (const in sampler2D sampler, in int count, const in float value)
|
|
561
|
+
{
|
|
562
|
+
int first = 0;
|
|
563
|
+
int step = 0;
|
|
564
|
+
|
|
565
|
+
while (count > 0)
|
|
566
|
+
{
|
|
567
|
+
int index = first;
|
|
568
|
+
|
|
569
|
+
step = count >> 1;
|
|
570
|
+
|
|
571
|
+
index += step;
|
|
572
|
+
|
|
573
|
+
if (value < texelFetch (sampler, index, 0) .x)
|
|
260
574
|
{
|
|
261
|
-
|
|
575
|
+
count = step;
|
|
262
576
|
}
|
|
577
|
+
else
|
|
578
|
+
{
|
|
579
|
+
first = ++ index;
|
|
580
|
+
count -= step + 1;
|
|
581
|
+
}
|
|
582
|
+
}
|
|
263
583
|
|
|
264
|
-
|
|
584
|
+
return first;
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
void
|
|
588
|
+
interpolate (const in sampler2D sampler, const in int count, const in float fraction, out int index0, out int index1, out float weight)
|
|
589
|
+
{
|
|
590
|
+
// Determine index0, index1 and weight.
|
|
591
|
+
|
|
592
|
+
if (count == 1 || fraction <= texelFetch (sampler, 0, 0) .x)
|
|
593
|
+
{
|
|
594
|
+
index0 = 0;
|
|
595
|
+
index1 = 0;
|
|
596
|
+
weight = 0.0;
|
|
597
|
+
}
|
|
598
|
+
else if (fraction >= texelFetch (sampler, count - 1, 0) .x)
|
|
599
|
+
{
|
|
600
|
+
index0 = count - 2;
|
|
601
|
+
index1 = count - 1;
|
|
602
|
+
weight = 1.0;
|
|
603
|
+
}
|
|
604
|
+
else
|
|
605
|
+
{
|
|
606
|
+
int index = upperBound (sampler, count, fraction);
|
|
607
|
+
|
|
608
|
+
if (index < count)
|
|
265
609
|
{
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
fromPosition .z = position .z;
|
|
610
|
+
index1 = index;
|
|
611
|
+
index0 = index - 1;
|
|
269
612
|
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
position .z += velocity .z * deltaTime;
|
|
613
|
+
float key0 = texelFetch (sampler, index0, 0) .x;
|
|
614
|
+
float key1 = texelFetch (sampler, index1, 0) .x;
|
|
273
615
|
|
|
274
|
-
|
|
616
|
+
weight = clamp ((fraction - key0) / (key1 - key0), 0.0, 1.0);
|
|
275
617
|
}
|
|
276
618
|
else
|
|
277
619
|
{
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
620
|
+
index0 = 0;
|
|
621
|
+
index1 = 0;
|
|
622
|
+
weight = 0.0;
|
|
281
623
|
}
|
|
624
|
+
}
|
|
625
|
+
}
|
|
626
|
+
|
|
627
|
+
void
|
|
628
|
+
interpolate (const in sampler2D sampler, const in int count, const in float fraction, out int index0)
|
|
629
|
+
{
|
|
630
|
+
// Determine index0.
|
|
282
631
|
|
|
283
|
-
|
|
632
|
+
if (count == 1 || fraction <= texelFetch (sampler, 0, 0) .x)
|
|
633
|
+
{
|
|
634
|
+
index0 = 0;
|
|
635
|
+
}
|
|
636
|
+
else if (fraction >= texelFetch (sampler, count - 1, 0) .x)
|
|
637
|
+
{
|
|
638
|
+
index0 = count - 2;
|
|
639
|
+
}
|
|
640
|
+
else
|
|
641
|
+
{
|
|
642
|
+
int index = upperBound (sampler, count, fraction);
|
|
643
|
+
|
|
644
|
+
if (index < count)
|
|
645
|
+
index0 = index - 1;
|
|
646
|
+
else
|
|
647
|
+
index0 = 0;
|
|
284
648
|
}
|
|
285
649
|
}
|
|
286
650
|
|
|
287
|
-
|
|
651
|
+
vec3
|
|
652
|
+
getRandomBarycentricCoord ()
|
|
653
|
+
{
|
|
654
|
+
// Random barycentric coordinates.
|
|
288
655
|
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
656
|
+
float u = random ();
|
|
657
|
+
float v = random ();
|
|
658
|
+
|
|
659
|
+
if (u + v > 1.0)
|
|
660
|
+
{
|
|
661
|
+
u = 1.0 - u;
|
|
662
|
+
v = 1.0 - v;
|
|
663
|
+
}
|
|
295
664
|
|
|
296
|
-
|
|
665
|
+
float t = 1.0 - u - v;
|
|
297
666
|
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
intersectionNormals = this .intersectionNormals,
|
|
301
|
-
numIntersections = boundedVolume .intersectsLine (line, intersections, intersectionNormals);
|
|
667
|
+
return vec3 (t, u, v);
|
|
668
|
+
}
|
|
302
669
|
|
|
303
|
-
|
|
670
|
+
void
|
|
671
|
+
getRandomPointOnSurface (const in sampler2D surface, const in int verticesIndex, const in int normalsIndex, out vec4 position, out vec3 normal)
|
|
304
672
|
{
|
|
305
|
-
|
|
306
|
-
|
|
673
|
+
// Determine index0, index1 and weight.
|
|
674
|
+
|
|
675
|
+
float lastAreaSoFar = texelFetch (surface, verticesIndex - 1, 0) .x;
|
|
676
|
+
float fraction = random () * lastAreaSoFar;
|
|
307
677
|
|
|
308
|
-
|
|
678
|
+
int index0;
|
|
679
|
+
int index1;
|
|
680
|
+
int index2;
|
|
681
|
+
float weight;
|
|
309
682
|
|
|
310
|
-
|
|
683
|
+
interpolate (surface, verticesIndex, fraction, index0, index1, weight);
|
|
311
684
|
|
|
312
|
-
|
|
685
|
+
// Interpolate and return position.
|
|
313
686
|
|
|
314
|
-
|
|
687
|
+
index0 *= 3;
|
|
688
|
+
index1 = index0 + 1;
|
|
689
|
+
index2 = index0 + 2;
|
|
690
|
+
|
|
691
|
+
vec4 vertex0 = texelFetch (surface, verticesIndex + index0, 0);
|
|
692
|
+
vec4 vertex1 = texelFetch (surface, verticesIndex + index1, 0);
|
|
693
|
+
vec4 vertex2 = texelFetch (surface, verticesIndex + index2, 0);
|
|
694
|
+
|
|
695
|
+
vec3 normal0 = texelFetch (surface, normalsIndex + index0, 0) .xyz;
|
|
696
|
+
vec3 normal1 = texelFetch (surface, normalsIndex + index1, 0) .xyz;
|
|
697
|
+
vec3 normal2 = texelFetch (surface, normalsIndex + index2, 0) .xyz;
|
|
698
|
+
|
|
699
|
+
// Random barycentric coordinates.
|
|
700
|
+
|
|
701
|
+
vec3 r = getRandomBarycentricCoord ();
|
|
702
|
+
|
|
703
|
+
// Calculate position and direction.
|
|
704
|
+
|
|
705
|
+
position = r .z * vertex0 + r .x * vertex1 + r .y * vertex2;
|
|
706
|
+
normal = save_normalize (r .z * normal0 + r .x * normal1 + r .y * normal2);
|
|
707
|
+
}
|
|
708
|
+
|
|
709
|
+
// Functions
|
|
710
|
+
|
|
711
|
+
${this .functions .join ("\n")}
|
|
712
|
+
|
|
713
|
+
// Current values
|
|
714
|
+
|
|
715
|
+
vec4
|
|
716
|
+
getColor (const in float lifetime, const in float elapsedTime)
|
|
717
|
+
{
|
|
718
|
+
if (numColors > 0)
|
|
315
719
|
{
|
|
316
|
-
|
|
317
|
-
intersection = intersections [index],
|
|
318
|
-
intersectionNormal = intersectionNormals [intersection .index];
|
|
720
|
+
// Determine index0, index1 and weight.
|
|
319
721
|
|
|
320
|
-
|
|
722
|
+
float fraction = elapsedTime / lifetime;
|
|
321
723
|
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
724
|
+
int index0;
|
|
725
|
+
int index1;
|
|
726
|
+
float weight;
|
|
325
727
|
|
|
326
|
-
|
|
327
|
-
velocity .y -= intersectionNormal .y * dot2;
|
|
328
|
-
velocity .z -= intersectionNormal .z * dot2;
|
|
728
|
+
interpolate (colorRamp, numColors, fraction, index0, index1, weight);
|
|
329
729
|
|
|
330
|
-
|
|
730
|
+
// Interpolate and return color.
|
|
331
731
|
|
|
332
|
-
|
|
732
|
+
vec4 color0 = texelFetch (colorRamp, numColors + index0, 0);
|
|
733
|
+
vec4 color1 = texelFetch (colorRamp, numColors + index1, 0);
|
|
333
734
|
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
735
|
+
return mix (color0, color1, weight);
|
|
736
|
+
}
|
|
737
|
+
else
|
|
738
|
+
{
|
|
739
|
+
return vec4 (1.0);
|
|
338
740
|
}
|
|
339
741
|
}
|
|
340
|
-
},
|
|
341
|
-
getColors: function (particles, colorKeys, colorRamp, numParticles)
|
|
342
|
-
{
|
|
343
|
-
var
|
|
344
|
-
length = colorKeys .length,
|
|
345
|
-
index0 = 0,
|
|
346
|
-
index1 = 0,
|
|
347
|
-
weight = 0;
|
|
348
742
|
|
|
349
|
-
|
|
743
|
+
void
|
|
744
|
+
bounce (const in vec4 fromPosition, inout vec4 toPosition, inout vec3 velocity)
|
|
350
745
|
{
|
|
351
|
-
|
|
746
|
+
if (boundedHierarchyRoot < 0)
|
|
747
|
+
return;
|
|
748
|
+
|
|
749
|
+
Line3 line = Line3 (fromPosition .xyz, save_normalize (velocity));
|
|
352
750
|
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
fraction = particle .elapsedTime / particle .lifetime,
|
|
356
|
-
color = particle .color;
|
|
751
|
+
vec4 points [ARRAY_SIZE];
|
|
752
|
+
vec3 normals [ARRAY_SIZE];
|
|
357
753
|
|
|
358
|
-
|
|
754
|
+
int numIntersections = getIntersections (boundedVolume, boundedVerticesIndex, boundedNormalsIndex, boundedHierarchyIndex, boundedHierarchyRoot, line, points, normals);
|
|
755
|
+
|
|
756
|
+
if (numIntersections == 0)
|
|
757
|
+
return;
|
|
758
|
+
|
|
759
|
+
Plane3 plane1 = plane3 (line .point, line .direction);
|
|
760
|
+
|
|
761
|
+
int index = min_index (points, numIntersections, 0.0, plane1);
|
|
762
|
+
|
|
763
|
+
if (index == -1)
|
|
764
|
+
return;
|
|
765
|
+
|
|
766
|
+
Plane3 plane2 = plane3 (points [index] .xyz, normals [index]);
|
|
767
|
+
|
|
768
|
+
if (sign (plane_distance (plane2, fromPosition .xyz)) == sign (plane_distance (plane2, toPosition .xyz)))
|
|
769
|
+
return;
|
|
770
|
+
|
|
771
|
+
velocity = reflect (velocity, normals [index]);
|
|
772
|
+
toPosition = vec4 (points [index] .xyz + reflect (points [index] .xyz - fromPosition .xyz, normals [index]), 1.0);
|
|
773
|
+
}
|
|
774
|
+
|
|
775
|
+
int
|
|
776
|
+
getTexCoordIndex0 (const in float lifetime, const in float elapsedTime)
|
|
777
|
+
{
|
|
778
|
+
if (numTexCoords == 0)
|
|
359
779
|
{
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
780
|
+
return -1;
|
|
781
|
+
}
|
|
782
|
+
else
|
|
783
|
+
{
|
|
784
|
+
float fraction = elapsedTime / lifetime;
|
|
785
|
+
int index0 = 0;
|
|
786
|
+
|
|
787
|
+
interpolate (texCoordRamp, numTexCoords, fraction, index0);
|
|
788
|
+
|
|
789
|
+
return numTexCoords + index0 * texCoordCount;
|
|
363
790
|
}
|
|
364
|
-
|
|
791
|
+
}
|
|
792
|
+
|
|
793
|
+
void
|
|
794
|
+
main ()
|
|
795
|
+
{
|
|
796
|
+
int life = int (input0 [0]);
|
|
797
|
+
float lifetime = input0 [1];
|
|
798
|
+
float elapsedTime = input0 [2] + deltaTime;
|
|
799
|
+
|
|
800
|
+
srand ((gl_VertexID + randomSeed) * randomSeed);
|
|
801
|
+
|
|
802
|
+
if (elapsedTime > lifetime)
|
|
365
803
|
{
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
804
|
+
// Create new particle or hide particle.
|
|
805
|
+
|
|
806
|
+
lifetime = getRandomLifetime ();
|
|
807
|
+
elapsedTime = 0.0;
|
|
808
|
+
|
|
809
|
+
output0 = vec4 (max (life + 1, 1), lifetime, elapsedTime, getTexCoordIndex0 (lifetime, elapsedTime));
|
|
810
|
+
|
|
811
|
+
if (createParticles)
|
|
812
|
+
{
|
|
813
|
+
output1 = getColor (lifetime, elapsedTime);
|
|
814
|
+
output2 = vec4 (getRandomVelocity (), 0.0);
|
|
815
|
+
output6 = getRandomPosition ();
|
|
816
|
+
}
|
|
817
|
+
else
|
|
818
|
+
{
|
|
819
|
+
output1 = vec4 (0.0);
|
|
820
|
+
output2 = vec4 (0.0);
|
|
821
|
+
output6 = vec4 (NaN);
|
|
822
|
+
}
|
|
369
823
|
}
|
|
370
824
|
else
|
|
371
825
|
{
|
|
372
|
-
|
|
826
|
+
// Animate particle.
|
|
827
|
+
|
|
828
|
+
vec3 velocity = input2 .xyz;
|
|
829
|
+
vec4 position = input6;
|
|
373
830
|
|
|
374
|
-
|
|
831
|
+
for (int i = 0; i < numForces; ++ i)
|
|
375
832
|
{
|
|
376
|
-
|
|
377
|
-
|
|
833
|
+
vec4 force = texelFetch (forces, i, 0);
|
|
834
|
+
float turbulence = force .w;
|
|
835
|
+
vec3 normal = getRandomNormalWithDirectionAndAngle (force .xyz, turbulence);
|
|
836
|
+
float speed = length (force .xyz);
|
|
837
|
+
|
|
838
|
+
velocity += normal * speed;
|
|
839
|
+
}
|
|
840
|
+
|
|
841
|
+
position .xyz += velocity * deltaTime;
|
|
378
842
|
|
|
379
|
-
|
|
380
|
-
key0 = colorKeys [index0],
|
|
381
|
-
key1 = colorKeys [index1];
|
|
843
|
+
bounce (input6, position, velocity);
|
|
382
844
|
|
|
383
|
-
|
|
845
|
+
output0 = vec4 (life, lifetime, elapsedTime, getTexCoordIndex0 (lifetime, elapsedTime));
|
|
846
|
+
output1 = getColor (lifetime, elapsedTime);
|
|
847
|
+
output2 = vec4 (velocity, 0.0);
|
|
848
|
+
output6 = position;
|
|
849
|
+
}
|
|
850
|
+
|
|
851
|
+
switch (geometryType)
|
|
852
|
+
{
|
|
853
|
+
case POINT:
|
|
854
|
+
case SPRITE:
|
|
855
|
+
case GEOMETRY:
|
|
856
|
+
{
|
|
857
|
+
output3 = vec4 (1.0, 0.0, 0.0, 0.0);
|
|
858
|
+
output4 = vec4 (0.0, 1.0, 0.0, 0.0);
|
|
859
|
+
output5 = vec4 (0.0, 0.0, 1.0, 0.0);
|
|
860
|
+
break;
|
|
384
861
|
}
|
|
385
|
-
|
|
862
|
+
case LINE:
|
|
386
863
|
{
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
864
|
+
mat3 r = Matrix3 (Quaternion (vec3 (0.0, 0.0, 1.0), output2 .xyz));
|
|
865
|
+
mat3 s = mat3 (1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, particleSize .y);
|
|
866
|
+
mat3 m = r * s;
|
|
867
|
+
|
|
868
|
+
output3 = vec4 (m [0], 0.0);
|
|
869
|
+
output4 = vec4 (m [1], 0.0);
|
|
870
|
+
output5 = vec4 (m [2], 0.0);
|
|
871
|
+
break;
|
|
872
|
+
}
|
|
873
|
+
default: // QUAD, TRIANGLE
|
|
874
|
+
{
|
|
875
|
+
output3 = vec4 (particleSize .x, 0.0, 0.0, 0.0);
|
|
876
|
+
output4 = vec4 (0.0, particleSize .y, 0.0, 0.0);
|
|
877
|
+
output5 = vec4 (0.0, 0.0, 1.0, 0.0);
|
|
878
|
+
break;
|
|
390
879
|
}
|
|
391
880
|
}
|
|
881
|
+
}
|
|
882
|
+
`;
|
|
883
|
+
|
|
884
|
+
const fragmentShaderSource = /* glsl */ `#version 300 es
|
|
885
|
+
|
|
886
|
+
precision highp float;
|
|
887
|
+
|
|
888
|
+
void
|
|
889
|
+
main () { }
|
|
890
|
+
`;
|
|
891
|
+
|
|
892
|
+
// Vertex shader
|
|
893
|
+
|
|
894
|
+
const vertexShader = gl .createShader (gl .VERTEX_SHADER);
|
|
895
|
+
|
|
896
|
+
gl .shaderSource (vertexShader, vertexShaderSource);
|
|
897
|
+
gl .compileShader (vertexShader);
|
|
898
|
+
|
|
899
|
+
// Fragment shader
|
|
900
|
+
|
|
901
|
+
const fragmentShader = gl .createShader (gl .FRAGMENT_SHADER);
|
|
902
|
+
|
|
903
|
+
gl .shaderSource (fragmentShader, fragmentShaderSource);
|
|
904
|
+
gl .compileShader (fragmentShader);
|
|
905
|
+
|
|
906
|
+
// Program
|
|
907
|
+
|
|
908
|
+
const program = gl .createProgram ();
|
|
909
|
+
|
|
910
|
+
gl .attachShader (program, vertexShader);
|
|
911
|
+
gl .attachShader (program, fragmentShader);
|
|
912
|
+
gl .transformFeedbackVaryings (program, Array .from ({length: 7}, (_, i) => "output" + i), gl .INTERLEAVED_ATTRIBS);
|
|
913
|
+
gl .linkProgram (program);
|
|
914
|
+
|
|
915
|
+
if (!gl .getProgramParameter (program, gl .LINK_STATUS))
|
|
916
|
+
console .error ("Couldn't initialize particle shader: " + gl .getProgramInfoLog (program));
|
|
917
|
+
|
|
918
|
+
program .inputs = [
|
|
919
|
+
[0, gl .getAttribLocation (program, "input0")],
|
|
920
|
+
[2, gl .getAttribLocation (program, "input2")],
|
|
921
|
+
[6, gl .getAttribLocation (program, "input6")],
|
|
922
|
+
];
|
|
392
923
|
|
|
393
|
-
|
|
924
|
+
program .randomSeed = gl .getUniformLocation (program, "randomSeed");
|
|
925
|
+
program .geometryType = gl .getUniformLocation (program, "geometryType");
|
|
926
|
+
program .createParticles = gl .getUniformLocation (program, "createParticles");
|
|
927
|
+
program .particleLifetime = gl .getUniformLocation (program, "particleLifetime");
|
|
928
|
+
program .lifetimeVariation = gl .getUniformLocation (program, "lifetimeVariation");
|
|
929
|
+
program .deltaTime = gl .getUniformLocation (program, "deltaTime");
|
|
930
|
+
program .particleSize = gl .getUniformLocation (program, "particleSize");
|
|
394
931
|
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
color1 = colorRamp [index1];
|
|
932
|
+
program .numForces = gl .getUniformLocation (program, "numForces");
|
|
933
|
+
program .forces = gl .getUniformLocation (program, "forces");
|
|
398
934
|
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
935
|
+
program .boundedVerticesIndex = gl .getUniformLocation (program, "boundedVerticesIndex");
|
|
936
|
+
program .boundedNormalsIndex = gl .getUniformLocation (program, "boundedNormalsIndex");
|
|
937
|
+
program .boundedHierarchyIndex = gl .getUniformLocation (program, "boundedHierarchyIndex");
|
|
938
|
+
program .boundedHierarchyRoot = gl .getUniformLocation (program, "boundedHierarchyRoot");
|
|
939
|
+
program .boundedVolume = gl .getUniformLocation (program, "boundedVolume");
|
|
940
|
+
|
|
941
|
+
program .numColors = gl .getUniformLocation (program, "numColors");
|
|
942
|
+
program .colorRamp = gl .getUniformLocation (program, "colorRamp");
|
|
943
|
+
|
|
944
|
+
program .texCoordCount = gl .getUniformLocation (program, "texCoordCount");
|
|
945
|
+
program .numTexCoords = gl .getUniformLocation (program, "numTexCoords");
|
|
946
|
+
program .texCoordRamp = gl .getUniformLocation (program, "texCoordRamp");
|
|
947
|
+
|
|
948
|
+
for (const name of Object .keys (this .uniforms))
|
|
949
|
+
program [name] = gl .getUniformLocation (program, name);
|
|
950
|
+
|
|
951
|
+
program .NaN = gl .getUniformLocation (program, "NaN");
|
|
952
|
+
|
|
953
|
+
gl .useProgram (program);
|
|
954
|
+
|
|
955
|
+
for (const name of this .samplers)
|
|
956
|
+
{
|
|
957
|
+
const location = gl .getUniformLocation (program, name);
|
|
958
|
+
|
|
959
|
+
gl .uniform1i (location, program [name + "TextureUnit"] = browser .getTexture2DUnit ());
|
|
404
960
|
}
|
|
961
|
+
|
|
962
|
+
gl .uniform1f (program .NaN, NaN);
|
|
963
|
+
|
|
964
|
+
browser .resetTextureUnits ();
|
|
965
|
+
|
|
966
|
+
return program;
|
|
967
|
+
},
|
|
968
|
+
activateTextures: function ()
|
|
969
|
+
{ },
|
|
970
|
+
createTexture: function ()
|
|
971
|
+
{
|
|
972
|
+
const
|
|
973
|
+
gl = this .getBrowser () .getContext (),
|
|
974
|
+
texture = gl .createTexture ();
|
|
975
|
+
|
|
976
|
+
gl .bindTexture (gl .TEXTURE_2D, texture);
|
|
977
|
+
|
|
978
|
+
gl .texParameteri (gl .TEXTURE_2D, gl .TEXTURE_WRAP_S, gl .CLAMP_TO_EDGE);
|
|
979
|
+
gl .texParameteri (gl .TEXTURE_2D, gl .TEXTURE_WRAP_T, gl .CLAMP_TO_EDGE);
|
|
980
|
+
gl .texParameteri (gl .TEXTURE_2D, gl .TEXTURE_MAG_FILTER, gl .NEAREST);
|
|
981
|
+
gl .texParameteri (gl .TEXTURE_2D, gl .TEXTURE_MIN_FILTER, gl .NEAREST);
|
|
982
|
+
|
|
983
|
+
gl .texImage2D (gl .TEXTURE_2D, 0, gl .RGBA32F, 1, 1, 0, gl .RGBA, gl .FLOAT, new Float32Array (4));
|
|
984
|
+
|
|
985
|
+
return texture;
|
|
986
|
+
},
|
|
987
|
+
getTexture2DUnit: function (browser, object, property)
|
|
988
|
+
{
|
|
989
|
+
const textureUnit = object [property];
|
|
990
|
+
|
|
991
|
+
if (textureUnit === undefined)
|
|
992
|
+
return object [property] = browser .getTexture2DUnit ();
|
|
993
|
+
|
|
994
|
+
return textureUnit;
|
|
405
995
|
},
|
|
406
996
|
});
|
|
407
997
|
|