@woosh/meep-engine 2.56.1 → 2.57.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/editor/ecs/component/editors/ColorEditor.js +1 -1
- package/editor/ecs/component/editors/ImagePathEditor.js +2 -2
- package/editor/ecs/component/editors/{LargeStrongEditor.js → LargeStringEditor.js} +1 -1
- package/editor/tools/GridPaintTool.js +3 -3
- package/editor/tools/TopDownCameraControlTool.js +1 -1
- package/editor/tools/TransformTool.js +1 -1
- package/editor/tools/engine/Tool.js +9 -23
- package/editor/tools/engine/ToolEngine.js +5 -7
- package/editor/tools/paint/TerrainHeightPaintTool.js +2 -2
- package/editor/tools/paint/TerrainPaintTool.js +2 -2
- package/editor/tools/paint/TerrainTexturePaintTool.js +2 -2
- package/package.json +1 -1
- package/src/core/bvh2/bvh3/query/compute_tight_near_far_clipping_planes.js +1 -1
- package/src/core/bvh2/traversal/ThreeClippingPlaneComputingBVHVisitor.js +1 -1
- package/src/core/bvh2/traversal/__process_point_if_within_planes.js +1 -1
- package/src/core/cache/LoadingCache.js +3 -2
- package/src/core/collection/array/arraySetSortingDiff.spec.js +12 -12
- package/src/core/collection/array/weightedRandomFromArray.js +2 -2
- package/src/core/color/Color.js +6 -6
- package/src/core/color/YCbCr/YCbCr.spec.js +16 -0
- package/src/core/color/{YCbCr_to_rgb_uint24.js → YCbCr/YCbCr_to_rgb_uint24.js} +6 -6
- package/src/core/color/YCbCr/rgb_to_YCbCr_uint24.js +16 -0
- package/src/core/color/{hex2rgb.js → hex/hex2rgb.js} +1 -1
- package/src/core/color/{rgb2hex.js → hex/rgb2hex.js} +1 -1
- package/src/core/color/{hsv2rgb.js → hsv/hsv2rgb.js} +3 -3
- package/src/core/color/hsv/rgb2hsv.js +49 -0
- package/src/core/color/{kelvin_to_rgb.js → kelvin/kelvin_to_rgb.js} +1 -1
- package/src/core/color/{kelvin_to_rgb.spec.js → kelvin/kelvin_to_rgb.spec.js} +2 -2
- package/src/core/color/{prototype_kelvin_to_rgb.js → kelvin/prototype_kelvin_to_rgb.js} +5 -5
- package/src/core/color/{rgb_to_kelvin.spec.js → kelvin/rgb_to_kelvin.spec.js} +1 -1
- package/src/core/color/{parseColor.js → parse_color.js} +4 -4
- package/src/core/color/parse_color.spec.js +18 -0
- package/src/core/color/rgb2uint24.js +3 -3
- package/src/core/color/sRGB/sRGB.spec.js +16 -0
- package/src/core/color/xyz/XYZ.spec.js +16 -0
- package/src/core/color/xyz/rgb_to_xyz.js +15 -0
- package/src/core/color/xyz/xyz_to_rgb.js +14 -0
- package/src/core/events/signal/Signal.js +5 -0
- package/src/core/events/signal/{signalAggregateByTimeWindow.js → signal_aggregate_by_time_window.js} +1 -1
- package/src/core/events/signal/{SignalUtils.js → signal_filter.js} +1 -2
- package/src/core/geom/2d/spline_bezier2_2d.js +26 -0
- package/src/core/geom/2d/spline_bezier2_2d.spec.js +16 -0
- package/src/core/geom/3d/SurfacePoint3.js +1 -1
- package/src/core/geom/3d/aabb/aabb3_compute_plane_side.js +1 -1
- package/src/core/geom/3d/aabb/aabb3_detailed_volume_intersection.js +1 -1
- package/src/core/geom/3d/aabb/aabb3_transformed_compute_plane_side.js +1 -1
- package/src/core/geom/3d/compute_circle_bounding_box.js +1 -1
- package/src/core/geom/3d/cone/computeConeBoundingBox.js +1 -1
- package/src/core/geom/3d/frustum/frustum3_computeNearestPointToPoint.js +1 -1
- package/src/core/geom/3d/line/line3_computeSegmentPointDistance_sqr.js +1 -1
- package/src/core/geom/3d/line/line3_compute_nearest_point_to_point.js +1 -1
- package/src/core/geom/3d/normal/hemioct/unit_hemioct.spec.js +1 -1
- package/src/core/geom/3d/normal/spherical/sphere_map_transform.js +1 -1
- package/src/core/geom/3d/plane/is_point_within_planes.js +1 -1
- package/src/core/geom/3d/plane/lerp_planes_to_array.js +1 -1
- package/src/core/geom/3d/plane/plane3_compute_convex_3_plane_intersection.js +1 -1
- package/src/core/geom/3d/plane/plane3_compute_line_segment_intersection.js +1 -1
- package/src/core/geom/3d/plane/plane3_compute_ray_intersection.js +1 -1
- package/src/core/geom/3d/plane/plane3_lerp.js +2 -2
- package/src/core/geom/3d/plane/plane3_projectPoint.js +1 -1
- package/src/core/geom/3d/plane/plane3_slerp.js +3 -3
- package/src/core/geom/3d/ray/ray_computeNearestPointToPoint.js +1 -1
- package/src/core/geom/3d/ray/ray_distance_to_point.js +1 -1
- package/src/core/geom/3d/shape/UnionShape3D.js +3 -3
- package/src/core/geom/3d/shape/UnitCubeShape3D.js +1 -1
- package/src/core/geom/3d/shape/UnitSphereShape3D.js +1 -1
- package/src/core/geom/3d/sphere/sphere_intersects_ray.js +1 -1
- package/src/core/geom/3d/tetrahedra/TetrahedralMesh.js +6 -0
- package/src/core/geom/3d/tetrahedra/compute_bounding_simplex_3d.js +1 -1
- package/src/core/geom/3d/tetrahedra/compute_bounding_simplex_3d.spec.js +1 -1
- package/src/core/geom/3d/tetrahedra/compute_circumsphere.js +1 -1
- package/src/core/geom/3d/tetrahedra/delaunay/compute_delaunay_tetrahedral_mesh.js +1 -0
- package/src/core/geom/3d/tetrahedra/delaunay/compute_delaunay_tetrahedral_mesh.spec.js +10 -2
- package/src/core/geom/3d/topology/bounds/computeTriangleClusterNormalBoundingCone.js +1 -1
- package/src/core/geom/3d/topology/samples/sampleFloodFill.js +1 -1
- package/src/core/geom/3d/topology/simplify/compute_face_normal_change_dot_product.js +1 -1
- package/src/core/geom/3d/topology/simplify/quadratic/Quadratic3.js +1 -1
- package/src/core/geom/3d/topology/simplify/tm_edge_collapse_is_degenerate_flip.js +2 -2
- package/src/core/geom/3d/topology/struct/TopoVertex.js +1 -1
- package/src/core/geom/3d/topology/util/compute_face_connection_weight.js +2 -2
- package/src/core/geom/3d/triangle/computeTrianglePlaneSide.js +1 -1
- package/src/core/geom/3d/triangle/computeTriangleRayIntersection.js +1 -1
- package/src/core/geom/3d/triangle/computeTriangleRayIntersectionBarycentricEdge.js +1 -1
- package/src/core/geom/3d/v3_compute_triangle_normal.js +1 -1
- package/src/core/geom/Quaternion.js +1 -1
- package/src/core/geom/Vector3.js +7 -7
- package/src/core/geom/Vector3.spec.js +68 -1
- package/src/core/geom/mat2/m2_add.js +17 -0
- package/src/core/geom/mat2/m2_determinant.js +8 -0
- package/src/core/geom/mat2/m2_multiply.js +17 -0
- package/src/core/geom/mat2/m2_multiply_scalar.js +18 -0
- package/src/core/geom/mat2/m2_multiply_transposed.js +18 -0
- package/src/core/geom/mat2/m2_sub_transposed.js +17 -0
- package/src/{view → core/geom/mat3}/m3_cm_compose_transform.js +0 -29
- package/src/core/geom/mat3/m3_cm_extract_rotation.js +8 -0
- package/src/core/geom/mat3/m3_cm_from_translation.js +19 -0
- package/src/{view/multiplyMatrices3.js → core/geom/mat3/m3_multiply.js} +2 -2
- package/src/{view → core/geom/mat3}/m3_rm_compose_transform.js +0 -9
- package/src/core/geom/mat3/m3_rm_extract_scale.js +7 -0
- package/src/core/geom/{3d/vector/allocate_v3.js → vec3/v3_allocate.js} +1 -1
- package/src/core/geom/{v3_angle_between.js → vec3/v3_angle_between.js} +1 -1
- package/src/core/geom/vec3/v3_dot_array_array.js +20 -0
- package/src/core/geom/{v3_lerp.js → vec3/v3_lerp.js} +1 -1
- package/src/core/graph/SquareMatrix.js +26 -3
- package/src/core/graph/SquareMatrix.spec.js +52 -2
- package/src/core/math/clamp01.js +1 -0
- package/src/core/math/fract.js +3 -1
- package/src/core/math/inverseLerp.js +7 -5
- package/src/core/math/lerp.js +5 -5
- package/src/core/math/physics/spring/computeHookeForce.js +9 -0
- package/src/core/math/remap.js +19 -0
- package/src/core/math/remap.spec.js +15 -0
- package/src/core/math/smoothStep.spec.js +16 -0
- package/src/core/math/spline/spline_bezier2.js +13 -0
- package/src/core/math/spline/spline_bezier2.spec.js +13 -0
- package/src/core/model/object/compareValues.js +2 -2
- package/src/core/model/object/read_property.js +10 -2
- package/src/core/model/object/write_property.js +3 -23
- package/src/core/model/object/write_property.spec.js +26 -0
- package/src/core/primitives/numbers/number_pretty_print.spec.js +19 -0
- package/src/engine/ecs/ik/OneBoneSurfaceAlignmentSolver.js +2 -2
- package/src/engine/ecs/ik/TwoBoneInverseKinematicsSolver.js +2 -2
- package/src/engine/ecs/systems/SteeringSystem.js +1 -1
- package/src/engine/ecs/terrain/ecs/splat/SplatMapOptimizerDebugger.js +1 -1
- package/src/engine/graphics/ecs/camera/Camera.js +1 -1
- package/src/engine/graphics/ecs/camera/CameraClippingPlaneComputer.js +1 -1
- package/src/engine/graphics/ecs/decal/v2/FPDecalSystem.js +3 -11
- package/src/engine/graphics/ecs/highlight/Highlight.js +20 -102
- package/src/engine/graphics/ecs/mesh/Mesh.js +12 -18
- package/src/engine/graphics/ecs/mesh/MeshSystem.js +41 -26
- package/src/engine/graphics/ecs/mesh-v2/ShadedGeometrySystem.js +1 -1
- package/src/engine/graphics/ecs/path/tube/build/TubePathBuilder.js +1 -1
- package/src/engine/graphics/ecs/path/tube/build/makeTubeGeometry.js +1 -1
- package/src/engine/graphics/ecs/path/tube/build/make_cap.js +3 -3
- package/src/engine/graphics/ecs/path/tube/build/make_ring_vertices.js +1 -1
- package/src/engine/graphics/geometry/MikkT/InitTriInfo.js +5 -6
- package/src/engine/graphics/geometry/MikkT/MikkTSpace.js +3 -3
- package/src/engine/graphics/geometry/MikkT/NormalizeSafe.js +1 -2
- package/src/engine/graphics/geometry/MikkT/STSpace.js +3 -3
- package/src/engine/graphics/geometry/MikkT/v3_scale_dot_sub_normalize.js +2 -2
- package/src/engine/graphics/geometry/bvh/buffered/BVHGeometryRaycaster.js +1 -1
- package/src/engine/graphics/geometry/clipping/ClippedGeometry.js +1 -1
- package/src/engine/graphics/particles/particular/engine/emitter/ParticleEmitter.js +102 -95
- package/src/engine/graphics/particles/particular/engine/emitter/ParticleLayer.spec.js +25 -0
- package/src/engine/graphics/particles/particular/engine/emitter/ParticlePool.js +0 -35
- package/src/engine/graphics/particles/particular/engine/emitter/ParticlePool.spec.js +39 -2
- package/src/engine/graphics/particles/particular/engine/shader/ShaderManager.js +22 -6
- package/src/engine/graphics/render/forward_plus/LightManager.js +1 -1
- package/src/engine/graphics/render/forward_plus/plugin/ptototypeFPPlugin.js +2 -2
- package/src/engine/graphics/render/forward_plus/prototype/prototypeLightManager.js +3 -3
- package/src/engine/graphics/render/forward_plus/query/detailed_sphere_frustum_intersection_test.js +1 -1
- package/src/engine/graphics/render/layers/RenderLayerUtils.js +1 -1
- package/src/engine/graphics/render/visibility/hiz/prototypeHiZ.js +3 -2
- package/src/engine/graphics/sh3/LightProbeVolume.js +1 -1
- package/src/engine/graphics/sh3/path_tracer/PathTracer.js +2 -2
- package/src/engine/graphics/sh3/path_tracer/prototypePathTracer.js +2 -2
- package/src/engine/graphics/sh3/path_tracer/random_in_hemisphere.js +1 -1
- package/src/engine/graphics/sh3/path_tracer/ray_hit_apply_transform.js +1 -1
- package/src/engine/graphics/sh3/path_tracer/ray_reflect.js +1 -1
- package/src/engine/graphics/sh3/sky/hosek/data.js +3744 -0
- package/src/engine/graphics/sh3/sky/hosek/sky_hosek_compute_irradiance_by_direction.js +10 -3786
- package/src/engine/graphics/texture/atlas/AbstractTextureAtlas.js +1 -1
- package/src/engine/graphics/texture/atlas/AtlasPatch.js +0 -1
- package/src/engine/graphics/texture/atlas/AtlasPatchFlag.js +8 -1
- package/src/engine/graphics/texture/atlas/CachingTextureAtlas.js +25 -0
- package/src/engine/graphics/texture/atlas/CachingTextureAtlas.spec.js +54 -0
- package/src/engine/graphics/texture/atlas/ManagedTextureAtlas.js +101 -160
- package/src/engine/graphics/texture/atlas/TextureAtlas.js +18 -1
- package/src/engine/graphics/texture/sampler/sampler2d_ensure_uint8_RGBA.js +22 -0
- package/src/engine/graphics/util/projectSphere.js +1 -1
- package/src/engine/navigation/ecs/components/Path.js +1 -1
- package/src/engine/physics/mls-mpm/MLS_MPM.js +11 -106
- package/src/engine/reference/v2/Reference.js +6 -2
- package/src/engine/sound/ecs/emitter/SoundEmitter.js +7 -7
- package/src/engine/sound/ecs/emitter/SoundTrack.js +6 -6
- package/src/generation/filtering/numeric/complex/CellFilterAngleToNormal.js +1 -1
- package/src/generation/grid/generation/road/GridTaskGenerateRoads.js +2 -4
- package/src/generation/placement/action/random/weighted/CellActionSelectWeightedRandom.js +2 -2
- package/src/generation/theme/ThemeEngine.js +2 -2
- package/src/generation/theme/ThemeEngine.spec.js +7 -0
- package/src/view/View.js +21 -13
- package/src/view/elements/ColorPickerView.js +2 -2
- package/src/view/minimap/gl/MarkerGL.js +20 -18
- package/src/view/minimap/gl/MinimapMarkersGL.js +2 -1
- package/editor/tools/FoliagePaintTool.js +0 -168
- package/editor/tools/engine/ToolStateMachine.js +0 -53
- package/src/core/NumberFormat.js +0 -4
- package/src/core/color/rgb2hsv.js +0 -47
- package/src/core/color/rgb_to_YCbCr_uint24.js +0 -16
- package/src/core/fsm/StateMachine.js +0 -440
- package/src/core/fsm/Transition.js +0 -65
- package/src/core/geom/Bezier.js +0 -24
- package/src/core/geom/Bezier.spec.js +0 -16
- package/src/core/math/spline/quadraticCurve.js +0 -11
- package/src/core/math/spline/quadraticCurve.spec.js +0 -13
- package/src/core/primitives/numbers/compareNumbers.js +0 -9
- package/src/engine/graphics/ecs/decal/Decal.js +0 -10
- package/src/engine/graphics/ecs/decal/DecalSystem.js +0 -99
- package/src/engine/graphics/ecs/decal/threejs/DecalGeometry.js +0 -298
- package/src/engine/graphics/ecs/trail/Trail.js +0 -83
- package/src/engine/graphics/ecs/trail/TrailMaterial.js +0 -67
- package/src/engine/graphics/ecs/trail/TrailMaterial2.js +0 -73
- package/src/engine/graphics/ecs/trail/TrailSystem.js +0 -162
- package/src/engine/graphics/ecs/water2/NodeWaterShader1.js +0 -213
- package/src/engine/graphics/ecs/water2/shader/JBWaterShader.js +0 -315
- package/src/engine/graphics/geometry/MikkT/Length.js +0 -10
- package/src/engine/graphics/texture/ImageLoader.js +0 -33
- package/src/engine/graphics/three/DDSLoader.js +0 -286
- package/src/engine/graphics/three/Water2.js +0 -343
- package/src/engine/physics/spring/computeHookeForce.js +0 -9
- package/src/engine/reference/v1/ReferenceManager.js +0 -124
- /package/src/core/color/{hex2rgb.spec.js → hex/hex2rgb.spec.js} +0 -0
- /package/src/core/color/{rgb2hex.spec.js → hex/rgb2hex.spec.js} +0 -0
- /package/src/core/color/{hsv2rgb.spec.js → hsv/hsv2rgb.spec.js} +0 -0
- /package/src/core/color/{rgb_to_kelvin.js → kelvin/rgb_to_kelvin.js} +0 -0
- /package/src/core/color/{linear_to_sRGB.js → sRGB/linear_to_sRGB.js} +0 -0
- /package/src/core/color/{sRGB_to_linear.js → sRGB/sRGB_to_linear.js} +0 -0
- /package/src/core/geom/{m3_determinant.js → mat3/m3_determinant.js} +0 -0
- /package/src/core/geom/{v3_distance.js → vec3/v3_distance.js} +0 -0
- /package/src/core/geom/{v3_distance_above_plane.js → vec3/v3_distance_above_plane.js} +0 -0
- /package/src/core/geom/{v3_distance_above_plane.spec.js → vec3/v3_distance_above_plane.spec.js} +0 -0
- /package/src/core/geom/{v3_distance_sqr.d.ts → vec3/v3_distance_sqr.d.ts} +0 -0
- /package/src/core/geom/{v3_distance_sqr.js → vec3/v3_distance_sqr.js} +0 -0
- /package/src/core/geom/{v3_dot.js → vec3/v3_dot.js} +0 -0
- /package/src/core/geom/{v3_length.js → vec3/v3_length.js} +0 -0
- /package/src/core/geom/{v3_length_sqr.js → vec3/v3_length_sqr.js} +0 -0
- /package/src/core/geom/{v3_slerp.js → vec3/v3_slerp.js} +0 -0
|
@@ -1,213 +0,0 @@
|
|
|
1
|
-
import { FloatNode } from "three/examples/jsm/nodes/inputs/FloatNode.js";
|
|
2
|
-
import { OperatorNode } from "three/examples/jsm/nodes/math/OperatorNode.js";
|
|
3
|
-
import { PositionNode } from "three/examples/jsm/nodes/accessors/PositionNode.js";
|
|
4
|
-
import { MathNode } from "three/examples/jsm/nodes/math/MathNode.js";
|
|
5
|
-
import { SwitchNode } from "three/examples/jsm/nodes/utils/SwitchNode.js";
|
|
6
|
-
import { StandardNodeMaterial } from "three/examples/jsm/nodes/materials/StandardNodeMaterial.js";
|
|
7
|
-
import { TextureNode } from "three/examples/jsm/nodes/inputs/TextureNode.js";
|
|
8
|
-
import { ScreenUVNode } from "three/examples/jsm/nodes/accessors/ScreenUVNode.js";
|
|
9
|
-
import { FunctionNode } from "three/examples/jsm/nodes/core/FunctionNode.js";
|
|
10
|
-
import { FunctionCallNode } from "three/examples/jsm/nodes/core/FunctionCallNode.js";
|
|
11
|
-
import { ColorNode } from "three/examples/jsm/nodes/inputs/ColorNode.js";
|
|
12
|
-
import { UVNode } from "three/examples/jsm/nodes/accessors/UVNode.js";
|
|
13
|
-
import { Vector2Node } from "three/examples/jsm/nodes/inputs/Vector2Node.js";
|
|
14
|
-
import { Vector4Node } from "three/examples/jsm/nodes/inputs/Vector4Node.js";
|
|
15
|
-
import CheckersTexture from "../../texture/CheckersTexture.js";
|
|
16
|
-
import { CondNode } from "three/examples/jsm/nodes/math/CondNode.js";
|
|
17
|
-
import { TimerNode } from "three/examples/jsm/nodes/utils/TimerNode.js";
|
|
18
|
-
|
|
19
|
-
export class NodeWaterShader {
|
|
20
|
-
constructor(depthTexture) {
|
|
21
|
-
|
|
22
|
-
const depthBuffer = new TextureNode(depthTexture, new ScreenUVNode());
|
|
23
|
-
|
|
24
|
-
const uv = new UVNode();
|
|
25
|
-
|
|
26
|
-
const heightUv = new Vector4Node();
|
|
27
|
-
this.heightUv = heightUv;
|
|
28
|
-
|
|
29
|
-
const heightUvSize = new SwitchNode(heightUv, 'zw');
|
|
30
|
-
const worldUV = new OperatorNode(
|
|
31
|
-
new OperatorNode(
|
|
32
|
-
uv,
|
|
33
|
-
new SwitchNode(heightUv, 'xy'),
|
|
34
|
-
OperatorNode.ADD
|
|
35
|
-
),
|
|
36
|
-
heightUvSize,
|
|
37
|
-
OperatorNode.MUL
|
|
38
|
-
);
|
|
39
|
-
|
|
40
|
-
const heightTextureNode = new TextureNode(CheckersTexture.create(),
|
|
41
|
-
worldUV,
|
|
42
|
-
);
|
|
43
|
-
|
|
44
|
-
this.heightTexture = heightTextureNode;
|
|
45
|
-
|
|
46
|
-
this.level = new FloatNode(0);
|
|
47
|
-
|
|
48
|
-
const textureRepeat = new Vector2Node(40, 40);
|
|
49
|
-
|
|
50
|
-
const mainColor = new ColorNode();
|
|
51
|
-
const shoreColor = new ColorNode('#387992');
|
|
52
|
-
|
|
53
|
-
const cameraNear = new FloatNode(3);
|
|
54
|
-
cameraNear.name = "cameraNear";
|
|
55
|
-
|
|
56
|
-
const cameraFar = new FloatNode(24);
|
|
57
|
-
cameraFar.name = "cameraFar";
|
|
58
|
-
|
|
59
|
-
const positionNode = new PositionNode();
|
|
60
|
-
|
|
61
|
-
const gaussianSample = new FunctionNode(`vec4 sampleTextureGaussian( sampler2D tex,vec2 uv, vec2 texelSize){
|
|
62
|
-
float r = 1.0;
|
|
63
|
-
|
|
64
|
-
float dx0 = - texelSize.x * r;
|
|
65
|
-
float dy0 = - texelSize.y * r;
|
|
66
|
-
float dx1 = + texelSize.x * r;
|
|
67
|
-
float dy1 = + texelSize.y * r;
|
|
68
|
-
|
|
69
|
-
return (
|
|
70
|
-
texture2D(tex, uv + vec2( dx0, dy0 ) ) +
|
|
71
|
-
texture2D(tex, uv + vec2( 0.0, dy0 ) ) +
|
|
72
|
-
texture2D(tex, uv + vec2( dx1, dy0 ) ) +
|
|
73
|
-
texture2D(tex, uv + vec2( dx0, 0.0 ) ) +
|
|
74
|
-
texture2D(tex, uv) +
|
|
75
|
-
texture2D(tex, uv + vec2( dx1, 0.0 ) ) +
|
|
76
|
-
texture2D(tex, uv + vec2( dx0, dy1 ) ) +
|
|
77
|
-
texture2D(tex, uv + vec2( 0.0, dy1 ) ) +
|
|
78
|
-
texture2D(tex, uv + vec2( dx1, dy1 ) )
|
|
79
|
-
) * ( 1.0 / 9.0 );
|
|
80
|
-
}`);
|
|
81
|
-
|
|
82
|
-
const depthToLinear = new FunctionNode(`float depthToLinear( float z, float cameraNear, float cameraFar ) {
|
|
83
|
-
float z_n = 2.0 * z - 1.0;
|
|
84
|
-
|
|
85
|
-
float z_e = 2.0 * cameraNear * cameraFar / (cameraFar + cameraNear - z_n * (cameraFar - cameraNear));
|
|
86
|
-
|
|
87
|
-
return z_e;
|
|
88
|
-
}`);
|
|
89
|
-
|
|
90
|
-
const fragmentDepth = new FunctionNode('float fragmentDepth(){ return gl_FragCoord.z; }');
|
|
91
|
-
|
|
92
|
-
const linearObjectDepth = new FunctionCallNode(depthToLinear, [
|
|
93
|
-
new FunctionCallNode(fragmentDepth),
|
|
94
|
-
cameraNear,
|
|
95
|
-
cameraFar
|
|
96
|
-
]);
|
|
97
|
-
|
|
98
|
-
const screenDepth = new SwitchNode(depthBuffer, 'x');
|
|
99
|
-
|
|
100
|
-
const linearScreenDepth = new FunctionCallNode(depthToLinear, [
|
|
101
|
-
screenDepth,
|
|
102
|
-
cameraNear,
|
|
103
|
-
cameraFar
|
|
104
|
-
]);
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
var distance = new OperatorNode(
|
|
108
|
-
linearScreenDepth,
|
|
109
|
-
linearObjectDepth,
|
|
110
|
-
OperatorNode.SUB
|
|
111
|
-
);
|
|
112
|
-
|
|
113
|
-
const mtl = new StandardNodeMaterial();
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
const alpha = new FloatNode(1);
|
|
117
|
-
|
|
118
|
-
const minFadeDepth = new FloatNode(0);
|
|
119
|
-
const maxFadeDepth = new FloatNode(1.7);
|
|
120
|
-
|
|
121
|
-
const deepWaterDepthMin = new FloatNode(0);
|
|
122
|
-
const deepWaterDepthMax = new FloatNode(0.3);
|
|
123
|
-
|
|
124
|
-
const heightmapResolution = new Vector2Node(512, 512);
|
|
125
|
-
|
|
126
|
-
const distanceRange = new OperatorNode(maxFadeDepth, minFadeDepth, OperatorNode.SUB);
|
|
127
|
-
|
|
128
|
-
const smoothHeight = new FunctionCallNode(gaussianSample, [heightTextureNode, worldUV,
|
|
129
|
-
new OperatorNode(
|
|
130
|
-
heightUvSize,
|
|
131
|
-
heightmapResolution,
|
|
132
|
-
OperatorNode.DIV
|
|
133
|
-
)
|
|
134
|
-
]);
|
|
135
|
-
|
|
136
|
-
const terrainHeight = new SwitchNode(
|
|
137
|
-
smoothHeight
|
|
138
|
-
, 'x');
|
|
139
|
-
|
|
140
|
-
mtl.color = new MathNode(
|
|
141
|
-
mainColor,
|
|
142
|
-
shoreColor,
|
|
143
|
-
new MathNode(
|
|
144
|
-
deepWaterDepthMin,
|
|
145
|
-
deepWaterDepthMax,
|
|
146
|
-
new MathNode(
|
|
147
|
-
terrainHeight,
|
|
148
|
-
new OperatorNode(
|
|
149
|
-
terrainHeight,
|
|
150
|
-
new MathNode(
|
|
151
|
-
new OperatorNode(
|
|
152
|
-
new OperatorNode(
|
|
153
|
-
new OperatorNode(
|
|
154
|
-
new SwitchNode(worldUV, 'x'),
|
|
155
|
-
new SwitchNode(worldUV, 'y'),
|
|
156
|
-
OperatorNode.ADD
|
|
157
|
-
),
|
|
158
|
-
new FloatNode(20),
|
|
159
|
-
OperatorNode.MUL
|
|
160
|
-
),
|
|
161
|
-
new TimerNode(1),
|
|
162
|
-
OperatorNode.ADD
|
|
163
|
-
),
|
|
164
|
-
MathNode.SIN
|
|
165
|
-
),
|
|
166
|
-
OperatorNode.MUL
|
|
167
|
-
),
|
|
168
|
-
new FloatNode(0.3),
|
|
169
|
-
MathNode.MIX
|
|
170
|
-
),
|
|
171
|
-
MathNode.SMOOTHSTEP
|
|
172
|
-
),
|
|
173
|
-
MathNode.MIX
|
|
174
|
-
);
|
|
175
|
-
|
|
176
|
-
const alphaGradient = new OperatorNode(
|
|
177
|
-
new MathNode(
|
|
178
|
-
new MathNode(distance, MathNode.ABS),
|
|
179
|
-
minFadeDepth,
|
|
180
|
-
maxFadeDepth,
|
|
181
|
-
MathNode.CLAMP
|
|
182
|
-
),
|
|
183
|
-
distanceRange,
|
|
184
|
-
OperatorNode.DIV
|
|
185
|
-
);
|
|
186
|
-
mtl.alpha = new OperatorNode(
|
|
187
|
-
alpha,
|
|
188
|
-
alphaGradient,
|
|
189
|
-
OperatorNode.MUL
|
|
190
|
-
);
|
|
191
|
-
|
|
192
|
-
// mtl.alpha = alpha;
|
|
193
|
-
|
|
194
|
-
mtl.position = positionNode;
|
|
195
|
-
mtl.mask = new CondNode(
|
|
196
|
-
distance,
|
|
197
|
-
new FloatNode(0),
|
|
198
|
-
CondNode.GREATER
|
|
199
|
-
);
|
|
200
|
-
// mtl.normal = normalTextureNode;
|
|
201
|
-
mtl.roughness = new FloatNode(0.7);
|
|
202
|
-
mtl.metalness = new FloatNode(0);
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
this.cameraNear = cameraNear;
|
|
206
|
-
this.cameraFar = cameraFar;
|
|
207
|
-
this.color = mainColor;
|
|
208
|
-
this.alpha = alpha;
|
|
209
|
-
this.textureRepeat = textureRepeat;
|
|
210
|
-
|
|
211
|
-
this.material = mtl;
|
|
212
|
-
}
|
|
213
|
-
}
|
|
@@ -1,315 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
|
|
3
|
-
based on:
|
|
4
|
-
https://codepen.io/knoland/pen/XKxAJb?editors=1010
|
|
5
|
-
by Jonathan Blair
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import { Vector2 } from "three";
|
|
9
|
-
|
|
10
|
-
const vs = `void main() {
|
|
11
|
-
gl_Position = vec4( position, 1.0 );
|
|
12
|
-
}`;
|
|
13
|
-
|
|
14
|
-
const fs = `uniform float iGlobalTime;
|
|
15
|
-
uniform vec2 iResolution;
|
|
16
|
-
|
|
17
|
-
const int NUM_STEPS = 8;
|
|
18
|
-
const float PI = 3.1415;
|
|
19
|
-
const float EPSILON = 1e-3;
|
|
20
|
-
float EPSILON_NRM = 0.1 / iResolution.x;
|
|
21
|
-
|
|
22
|
-
// sea variables
|
|
23
|
-
const int ITER_GEOMETRY = 3;
|
|
24
|
-
const int ITER_FRAGMENT = 5;
|
|
25
|
-
const float SEA_HEIGHT = 0.6;
|
|
26
|
-
const float SEA_CHOPPY = 1.0;
|
|
27
|
-
const float SEA_SPEED = 1.0;
|
|
28
|
-
const float SEA_FREQ = 0.16;
|
|
29
|
-
const vec3 SEA_BASE = vec3(0.1,0.19,0.22);
|
|
30
|
-
const vec3 SEA_WATER_COLOR = vec3(0.8,0.9,0.6);
|
|
31
|
-
float SEA_TIME = iGlobalTime * SEA_SPEED;
|
|
32
|
-
mat2 octave_m = mat2(1.6,1.2,-1.2,1.6);
|
|
33
|
-
|
|
34
|
-
mat3 fromEuler(vec3 ang) {
|
|
35
|
-
vec2 a1 = vec2(sin(ang.x),cos(ang.x));
|
|
36
|
-
vec2 a2 = vec2(sin(ang.y),cos(ang.y));
|
|
37
|
-
vec2 a3 = vec2(sin(ang.z),cos(ang.z));
|
|
38
|
-
mat3 m;
|
|
39
|
-
m[0] = vec3(
|
|
40
|
-
a1.y*a3.y+a1.x*a2.x*a3.x,
|
|
41
|
-
a1.y*a2.x*a3.x+a3.y*a1.x,
|
|
42
|
-
-a2.y*a3.x
|
|
43
|
-
);
|
|
44
|
-
m[1] = vec3(-a2.y*a1.x,a1.y*a2.y,a2.x);
|
|
45
|
-
m[2] = vec3(
|
|
46
|
-
a3.y*a1.x*a2.x+a1.y*a3.x,
|
|
47
|
-
a1.x*a3.x-a1.y*a3.y*a2.x,
|
|
48
|
-
a2.y*a3.y
|
|
49
|
-
);
|
|
50
|
-
return m;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
float hash( vec2 p ) {
|
|
54
|
-
float h = dot(p,vec2(127.1,311.7));
|
|
55
|
-
return fract(sin(h)*43758.5453123);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
float noise( in vec2 p ) {
|
|
59
|
-
vec2 i = floor(p);
|
|
60
|
-
vec2 f = fract(p);
|
|
61
|
-
vec2 u = f * f * (3.0 - 2.0 * f);
|
|
62
|
-
return -1.0 + 2.0 * mix(
|
|
63
|
-
mix(
|
|
64
|
-
hash(i + vec2(0.0,0.0)
|
|
65
|
-
),
|
|
66
|
-
hash(i + vec2(1.0,0.0)), u.x),
|
|
67
|
-
mix(hash(i + vec2(0.0,1.0) ),
|
|
68
|
-
hash(i + vec2(1.0,1.0) ), u.x),
|
|
69
|
-
u.y
|
|
70
|
-
);
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
float diffuse(vec3 n,vec3 l,float p) {
|
|
74
|
-
return pow(dot(n,l) * 0.4 + 0.6,p);
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
float specular(vec3 n,vec3 l,vec3 e,float s) {
|
|
78
|
-
float nrm = (s + 8.0) / (3.1415 * 8.0);
|
|
79
|
-
return pow(max(dot(reflect(e,n),l),0.0),s) * nrm;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
vec3 getSkyColor(vec3 e) {
|
|
83
|
-
e.y = max(e.y, 0.0);
|
|
84
|
-
vec3 ret;
|
|
85
|
-
ret.x = pow(1.0 - e.y, 2.0);
|
|
86
|
-
ret.y = 1.0 - e.y;
|
|
87
|
-
ret.z = 0.6+(1.0 - e.y) * 0.4;
|
|
88
|
-
return ret;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
float sea_octave(vec2 uv, float choppy) {
|
|
93
|
-
uv += noise(uv);
|
|
94
|
-
vec2 wv = 1.0 - abs(sin(uv));
|
|
95
|
-
vec2 swv = abs(cos(uv));
|
|
96
|
-
wv = mix(wv, swv, wv);
|
|
97
|
-
return pow(1.0 - pow(wv.x * wv.y, 0.65), choppy);
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
float map(vec3 p) {
|
|
101
|
-
float freq = SEA_FREQ;
|
|
102
|
-
float amp = SEA_HEIGHT;
|
|
103
|
-
float choppy = SEA_CHOPPY;
|
|
104
|
-
vec2 uv = p.xz;
|
|
105
|
-
uv.x *= 0.75;
|
|
106
|
-
|
|
107
|
-
float d, h = 0.0;
|
|
108
|
-
for(int i = 0; i < ITER_GEOMETRY; i++) {
|
|
109
|
-
d = sea_octave((uv + SEA_TIME) * freq, choppy);
|
|
110
|
-
d += sea_octave((uv - SEA_TIME) * freq, choppy);
|
|
111
|
-
h += d * amp;
|
|
112
|
-
uv *= octave_m;
|
|
113
|
-
freq *= 1.9;
|
|
114
|
-
amp *= 0.22;
|
|
115
|
-
choppy = mix(choppy, 1.0, 0.2);
|
|
116
|
-
}
|
|
117
|
-
return p.y - h;
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
float map_detailed(vec3 p) {
|
|
121
|
-
float freq = SEA_FREQ;
|
|
122
|
-
float amp = SEA_HEIGHT;
|
|
123
|
-
float choppy = SEA_CHOPPY;
|
|
124
|
-
vec2 uv = p.xz;
|
|
125
|
-
uv.x *= 0.75;
|
|
126
|
-
|
|
127
|
-
float d, h = 0.0;
|
|
128
|
-
for(int i = 0; i < ITER_FRAGMENT; i++) {
|
|
129
|
-
d = sea_octave((uv+SEA_TIME) * freq, choppy);
|
|
130
|
-
d += sea_octave((uv-SEA_TIME) * freq, choppy);
|
|
131
|
-
h += d * amp;
|
|
132
|
-
uv *= octave_m;
|
|
133
|
-
freq *= 1.9;
|
|
134
|
-
amp *= 0.22;
|
|
135
|
-
choppy = mix(choppy,1.0,0.2);
|
|
136
|
-
}
|
|
137
|
-
return p.y - h;
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
vec3 getSeaColor(
|
|
141
|
-
vec3 p,
|
|
142
|
-
vec3 n,
|
|
143
|
-
vec3 l,
|
|
144
|
-
vec3 eye,
|
|
145
|
-
vec3 dist
|
|
146
|
-
) {
|
|
147
|
-
float fresnel = 1.0 - max(dot(n,-eye),0.0);
|
|
148
|
-
fresnel = pow(fresnel,3.0) * 0.65;
|
|
149
|
-
|
|
150
|
-
vec3 reflected = getSkyColor(reflect(eye,n));
|
|
151
|
-
vec3 refracted = SEA_BASE + diffuse(n,l,80.0) * SEA_WATER_COLOR * 0.12;
|
|
152
|
-
|
|
153
|
-
vec3 color = mix(refracted,reflected,fresnel);
|
|
154
|
-
|
|
155
|
-
float atten = max(1.0 - dot(dist,dist) * 0.001, 0.0);
|
|
156
|
-
color += SEA_WATER_COLOR * (p.y - SEA_HEIGHT) * 0.18 * atten;
|
|
157
|
-
|
|
158
|
-
color += vec3(specular(n,l,eye,60.0));
|
|
159
|
-
|
|
160
|
-
return color;
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
// tracing
|
|
164
|
-
vec3 getNormal(vec3 p, float eps) {
|
|
165
|
-
vec3 n;
|
|
166
|
-
n.y = map_detailed(p);
|
|
167
|
-
n.x = map_detailed(vec3(p.x+eps,p.y,p.z)) - n.y;
|
|
168
|
-
n.z = map_detailed(vec3(p.x,p.y,p.z+eps)) - n.y;
|
|
169
|
-
n.y = eps;
|
|
170
|
-
return normalize(n);
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
float heightMapTracing(vec3 ori, vec3 dir, out vec3 p) {
|
|
174
|
-
float tm = 0.0;
|
|
175
|
-
float tx = 1000.0;
|
|
176
|
-
float hx = map(ori + dir * tx);
|
|
177
|
-
|
|
178
|
-
if(hx > 0.0) {
|
|
179
|
-
return tx;
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
float hm = map(ori + dir * tm);
|
|
183
|
-
float tmid = 0.0;
|
|
184
|
-
for(int i = 0; i < NUM_STEPS; i++) {
|
|
185
|
-
tmid = mix(tm,tx, hm/(hm-hx));
|
|
186
|
-
p = ori + dir * tmid;
|
|
187
|
-
float hmid = map(p);
|
|
188
|
-
if(hmid < 0.0) {
|
|
189
|
-
tx = tmid;
|
|
190
|
-
hx = hmid;
|
|
191
|
-
} else {
|
|
192
|
-
tm = tmid;
|
|
193
|
-
hm = hmid;
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
return tmid;
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
void main() {
|
|
200
|
-
vec2 uv = gl_FragCoord.xy / iResolution.xy;
|
|
201
|
-
uv = uv * 2.0 - 1.0;
|
|
202
|
-
uv.x *= iResolution.x / iResolution.y;
|
|
203
|
-
float time = iGlobalTime * 0.3;
|
|
204
|
-
|
|
205
|
-
// ray
|
|
206
|
-
vec3 ang = vec3(
|
|
207
|
-
sin(time*3.0)*0.1,sin(time)*0.2+0.3,time
|
|
208
|
-
);
|
|
209
|
-
vec3 ori = vec3(0.0,3.5,time*5.0);
|
|
210
|
-
vec3 dir = normalize(
|
|
211
|
-
vec3(uv.xy,-2.0)
|
|
212
|
-
);
|
|
213
|
-
dir.z += length(uv) * 0.15;
|
|
214
|
-
dir = normalize(dir);
|
|
215
|
-
|
|
216
|
-
// tracing
|
|
217
|
-
vec3 p;
|
|
218
|
-
heightMapTracing(ori,dir,p);
|
|
219
|
-
vec3 dist = p - ori;
|
|
220
|
-
vec3 n = getNormal(
|
|
221
|
-
p,
|
|
222
|
-
dot(dist,dist) * EPSILON_NRM
|
|
223
|
-
);
|
|
224
|
-
vec3 light = normalize(vec3(0.0,1.0,0.8));
|
|
225
|
-
|
|
226
|
-
// color
|
|
227
|
-
vec3 color = mix(
|
|
228
|
-
getSkyColor(dir),
|
|
229
|
-
getSeaColor(p,n,light,dir,dist),
|
|
230
|
-
pow(smoothstep(0.0,-0.05,dir.y),0.3)
|
|
231
|
-
);
|
|
232
|
-
|
|
233
|
-
// post
|
|
234
|
-
gl_FragColor = vec4(pow(color,vec3(0.75)), 1.0);
|
|
235
|
-
}`;
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
function makeMaterial() {
|
|
239
|
-
var container,
|
|
240
|
-
renderer,
|
|
241
|
-
scene,
|
|
242
|
-
camera,
|
|
243
|
-
mesh,
|
|
244
|
-
start = Date.now(),
|
|
245
|
-
fov = 30;
|
|
246
|
-
|
|
247
|
-
var clock = new THREE.Clock();
|
|
248
|
-
|
|
249
|
-
var timeUniform = {
|
|
250
|
-
iGlobalTime: {
|
|
251
|
-
type: 'f',
|
|
252
|
-
value: 0.1
|
|
253
|
-
},
|
|
254
|
-
iResolution: {
|
|
255
|
-
type: 'v2',
|
|
256
|
-
value: new Vector2()
|
|
257
|
-
}
|
|
258
|
-
};
|
|
259
|
-
|
|
260
|
-
timeUniform.iResolution.value.x = window.innerWidth;
|
|
261
|
-
timeUniform.iResolution.value.y = window.innerHeight;
|
|
262
|
-
|
|
263
|
-
container = document.getElementById('container');
|
|
264
|
-
scene = new THREE.Scene();
|
|
265
|
-
|
|
266
|
-
camera = new THREE.PerspectiveCamera(
|
|
267
|
-
fov,
|
|
268
|
-
window.innerWidth / window.innerHeight,
|
|
269
|
-
1,
|
|
270
|
-
10000
|
|
271
|
-
);
|
|
272
|
-
camera.position.x = 20;
|
|
273
|
-
camera.position.y = 10;
|
|
274
|
-
camera.position.z = 20;
|
|
275
|
-
camera.lookAt(scene.position);
|
|
276
|
-
scene.add(camera);
|
|
277
|
-
|
|
278
|
-
var axis = new THREE.AxisHelper(10);
|
|
279
|
-
scene.add(axis);
|
|
280
|
-
|
|
281
|
-
material = new THREE.ShaderMaterial({
|
|
282
|
-
uniforms: timeUniform,
|
|
283
|
-
vertexShader: document.getElementById('vertex-shader').textContent,
|
|
284
|
-
fragmentShader: document.getElementById('fragment-shader').textContent
|
|
285
|
-
});
|
|
286
|
-
|
|
287
|
-
var water = new THREE.Mesh(
|
|
288
|
-
new THREE.PlaneBufferGeometry(window.innerWidth, window.innerHeight, 40), material
|
|
289
|
-
);
|
|
290
|
-
scene.add(water);
|
|
291
|
-
|
|
292
|
-
var geometry = new THREE.SphereGeometry(10, 32, 32);
|
|
293
|
-
var material = new THREE.MeshBasicMaterial({ color: 0xffff00 });
|
|
294
|
-
var sphere = new THREE.Mesh(geometry, material);
|
|
295
|
-
scene.add(sphere);
|
|
296
|
-
|
|
297
|
-
renderer = new THREE.WebGLRenderer();
|
|
298
|
-
renderer.setSize(window.innerWidth, window.innerHeight);
|
|
299
|
-
|
|
300
|
-
container.appendChild(renderer.domElement);
|
|
301
|
-
|
|
302
|
-
render();
|
|
303
|
-
|
|
304
|
-
window.addEventListener('resize', function () {
|
|
305
|
-
camera.aspect = window.innerWidth / window.innerHeight;
|
|
306
|
-
camera.updateProjectionMatrix();
|
|
307
|
-
renderer.setSize(window.innerWidth, window.innerHeight);
|
|
308
|
-
});
|
|
309
|
-
|
|
310
|
-
function render() {
|
|
311
|
-
timeUniform.iGlobalTime.value += clock.getDelta();
|
|
312
|
-
renderer.render(scene, camera);
|
|
313
|
-
requestAnimationFrame(render);
|
|
314
|
-
}
|
|
315
|
-
}
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Created by Alex on 16/10/2014.
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
export default function loadImage(url, callback) {
|
|
8
|
-
const img = new Image();
|
|
9
|
-
img.onload = function () {
|
|
10
|
-
const imgWidth = img.width;
|
|
11
|
-
const imgHeight = img.height;
|
|
12
|
-
//
|
|
13
|
-
const canvas = document.createElement('canvas');
|
|
14
|
-
canvas.width = imgWidth;
|
|
15
|
-
canvas.height = imgHeight;
|
|
16
|
-
const context = canvas.getContext('2d');
|
|
17
|
-
|
|
18
|
-
context.drawImage(img, 0, 0, imgWidth, imgHeight);
|
|
19
|
-
const imgd = context.getImageData(0, 0, imgWidth, imgHeight);
|
|
20
|
-
|
|
21
|
-
callback({
|
|
22
|
-
width: imgWidth,
|
|
23
|
-
height: imgHeight,
|
|
24
|
-
data: imgd.data,
|
|
25
|
-
canvas: canvas
|
|
26
|
-
});
|
|
27
|
-
};
|
|
28
|
-
img.onerror = function () {
|
|
29
|
-
console.error("failed to load image " + url);
|
|
30
|
-
};
|
|
31
|
-
// load img source
|
|
32
|
-
img.src = url;
|
|
33
|
-
};
|