super-three 0.168.0 → 0.169.1
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/build/three.cjs +384 -700
- package/build/three.module.js +384 -700
- package/build/three.module.min.js +1 -1
- package/build/three.webgpu.js +24644 -22406
- package/build/three.webgpu.min.js +1 -1
- package/build/three.webgpu.nodes.js +79941 -0
- package/build/three.webgpu.nodes.min.js +6 -0
- package/examples/jsm/Addons.js +0 -6
- package/examples/jsm/controls/TrackballControls.js +32 -12
- package/examples/jsm/controls/TransformControls.js +97 -62
- package/examples/jsm/exporters/DRACOExporter.js +4 -2
- package/examples/jsm/exporters/EXRExporter.js +19 -11
- package/examples/jsm/exporters/KTX2Exporter.js +21 -13
- package/examples/jsm/exporters/OBJExporter.js +5 -1
- package/examples/jsm/exporters/PLYExporter.js +9 -7
- package/examples/jsm/geometries/DecalGeometry.js +4 -1
- package/examples/jsm/geometries/InstancedPointsGeometry.js +1 -1
- package/examples/jsm/helpers/LightProbeHelper.js +1 -1
- package/examples/jsm/helpers/LightProbeHelperGPU.js +65 -0
- package/examples/jsm/libs/basis/basis_transcoder.js +8 -10
- package/examples/jsm/libs/basis/basis_transcoder.wasm +0 -0
- package/examples/jsm/libs/ktx-parse.module.js +1 -1
- package/examples/jsm/lights/LightProbeGenerator.js +24 -10
- package/examples/jsm/loaders/ColladaLoader.js +9 -6
- package/examples/jsm/loaders/DRACOLoader.js +3 -1
- package/examples/jsm/loaders/FBXLoader.js +30 -20
- package/examples/jsm/loaders/GLTFLoader.js +5 -10
- package/examples/jsm/loaders/KTX2Loader.js +10 -7
- package/examples/jsm/loaders/MTLLoader.js +4 -3
- package/examples/jsm/loaders/MaterialXLoader.js +29 -10
- package/examples/jsm/loaders/OBJLoader.js +5 -3
- package/examples/jsm/loaders/PCDLoader.js +5 -4
- package/examples/jsm/loaders/PDBLoader.js +3 -2
- package/examples/jsm/loaders/PLYLoader.js +8 -5
- package/examples/jsm/loaders/STLLoader.js +3 -2
- package/examples/jsm/loaders/VRMLLoader.js +10 -10
- package/examples/jsm/loaders/VTKLoader.js +4 -3
- package/examples/jsm/loaders/XYZLoader.js +3 -2
- package/examples/jsm/misc/Timer.js +1 -1
- package/examples/jsm/modifiers/CurveModifierGPU.js +233 -0
- package/examples/jsm/objects/LensflareMesh.js +322 -0
- package/examples/jsm/objects/SkyMesh.js +1 -2
- package/examples/jsm/objects/Water2Mesh.js +2 -3
- package/examples/jsm/objects/WaterMesh.js +1 -2
- package/examples/jsm/physics/JoltPhysics.js +1 -1
- package/examples/jsm/physics/RapierPhysics.js +1 -1
- package/examples/jsm/transpiler/GLSLDecoder.js +1 -1
- package/examples/jsm/transpiler/ShaderToyDecoder.js +2 -2
- package/examples/jsm/utils/GeometryCompressionUtils.js +37 -122
- package/examples/jsm/utils/ShadowMapViewer.js +3 -8
- package/examples/jsm/utils/ShadowMapViewerGPU.js +201 -0
- package/examples/jsm/utils/SkeletonUtils.js +84 -66
- package/examples/jsm/utils/TextureUtils.js +1 -0
- package/examples/jsm/utils/TextureUtilsGPU.js +63 -0
- package/examples/jsm/webxr/XRControllerModelFactory.js +1 -1
- package/package.json +2 -2
- package/src/Three.WebGPU.Nodes.js +200 -0
- package/src/Three.WebGPU.js +2 -1
- package/src/audio/Audio.js +2 -2
- package/src/constants.js +1 -1
- package/src/core/BufferAttribute.js +0 -9
- package/src/core/Clock.js +1 -1
- package/src/core/InterleavedBuffer.js +0 -9
- package/src/extras/Controls.js +1 -1
- package/src/geometries/CylinderGeometry.js +11 -4
- package/src/loaders/MaterialLoader.js +7 -1
- package/src/loaders/nodes/NodeLoader.js +24 -4
- package/src/loaders/nodes/NodeMaterialLoader.js +21 -17
- package/src/loaders/nodes/NodeObjectLoader.js +19 -0
- package/src/materials/nodes/InstancedPointsNodeMaterial.js +19 -34
- package/src/materials/nodes/Line2NodeMaterial.js +26 -26
- package/src/materials/nodes/LineBasicNodeMaterial.js +7 -3
- package/src/materials/nodes/LineDashedNodeMaterial.js +7 -3
- package/src/materials/nodes/MeshBasicNodeMaterial.js +7 -3
- package/src/materials/nodes/MeshLambertNodeMaterial.js +7 -3
- package/src/materials/nodes/MeshMatcapNodeMaterial.js +7 -3
- package/src/materials/nodes/MeshNormalNodeMaterial.js +7 -3
- package/src/materials/nodes/MeshPhongNodeMaterial.js +7 -3
- package/src/materials/nodes/MeshPhysicalNodeMaterial.js +6 -3
- package/src/materials/nodes/MeshSSSNodeMaterial.js +6 -3
- package/src/materials/nodes/MeshStandardNodeMaterial.js +7 -3
- package/src/materials/nodes/MeshToonNodeMaterial.js +7 -3
- package/src/materials/nodes/NodeMaterial.js +20 -45
- package/src/materials/nodes/NodeMaterials.js +2 -0
- package/src/materials/nodes/PointsNodeMaterial.js +7 -3
- package/src/materials/nodes/ShadowNodeMaterial.js +7 -3
- package/src/materials/nodes/SpriteNodeMaterial.js +39 -6
- package/src/materials/nodes/VolumeNodeMaterial.js +13 -9
- package/src/materials/nodes/manager/NodeMaterialObserver.js +302 -0
- package/src/math/Triangle.js +24 -0
- package/src/nodes/Nodes.js +3 -3
- package/src/nodes/TSL.js +96 -93
- package/src/nodes/accessors/BatchNode.js +7 -3
- package/src/nodes/accessors/BufferAttributeNode.js +6 -3
- package/src/nodes/accessors/BufferNode.js +6 -3
- package/src/nodes/accessors/Camera.js +10 -16
- package/src/nodes/accessors/ClippingNode.js +7 -3
- package/src/nodes/accessors/CubeTextureNode.js +6 -3
- package/src/nodes/accessors/InstanceNode.js +11 -11
- package/src/nodes/accessors/InstancedPointsMaterialNode.js +6 -3
- package/src/nodes/accessors/Lights.js +51 -0
- package/src/nodes/accessors/MaterialNode.js +8 -4
- package/src/nodes/accessors/MaterialReferenceNode.js +6 -3
- package/src/nodes/accessors/ModelNode.js +42 -7
- package/src/nodes/accessors/ModelViewProjectionNode.js +9 -5
- package/src/nodes/accessors/MorphNode.js +7 -3
- package/src/nodes/accessors/Normal.js +32 -6
- package/src/nodes/accessors/Object3DNode.js +11 -27
- package/src/nodes/accessors/PointUVNode.js +7 -3
- package/src/nodes/accessors/ReferenceBaseNode.js +32 -4
- package/src/nodes/accessors/ReferenceNode.js +40 -3
- package/src/nodes/accessors/RendererReferenceNode.js +9 -3
- package/src/nodes/accessors/SceneNode.js +7 -3
- package/src/nodes/accessors/SkinningNode.js +7 -3
- package/src/nodes/accessors/StorageBufferNode.js +21 -3
- package/src/nodes/accessors/StorageTextureNode.js +7 -4
- package/src/nodes/accessors/Texture3DNode.js +7 -4
- package/src/nodes/accessors/TextureNode.js +19 -8
- package/src/nodes/accessors/TextureSizeNode.js +8 -5
- package/src/nodes/accessors/UniformArrayNode.js +12 -9
- package/src/nodes/accessors/UserDataNode.js +9 -6
- package/src/nodes/accessors/VelocityNode.js +74 -23
- package/src/nodes/accessors/VertexColorNode.js +6 -3
- package/src/nodes/code/CodeNode.js +7 -3
- package/src/nodes/code/ExpressionNode.js +8 -4
- package/src/nodes/code/FunctionCallNode.js +6 -3
- package/src/nodes/code/FunctionNode.js +6 -3
- package/src/nodes/code/ScriptableNode.js +11 -6
- package/src/nodes/code/ScriptableValueNode.js +7 -3
- package/src/nodes/core/AssignNode.js +9 -6
- package/src/nodes/core/AttributeNode.js +7 -3
- package/src/nodes/core/BypassNode.js +8 -4
- package/src/nodes/core/CacheNode.js +8 -4
- package/src/nodes/core/ConstNode.js +6 -3
- package/src/nodes/core/ContextNode.js +7 -3
- package/src/nodes/core/IndexNode.js +25 -3
- package/src/nodes/core/InputNode.js +7 -3
- package/src/nodes/core/MRTNode.js +6 -3
- package/src/nodes/core/Node.js +10 -51
- package/src/nodes/core/NodeBuilder.js +71 -5
- package/src/nodes/core/NodeUtils.js +48 -6
- package/src/nodes/core/OutputStructNode.js +8 -4
- package/src/nodes/core/ParameterNode.js +6 -3
- package/src/nodes/core/PropertyNode.js +7 -3
- package/src/nodes/core/StackNode.js +7 -3
- package/src/nodes/core/StructTypeNode.js +7 -3
- package/src/nodes/core/TempNode.js +8 -4
- package/src/nodes/core/UniformGroupNode.js +10 -6
- package/src/nodes/core/UniformNode.js +6 -3
- package/src/nodes/core/VarNode.js +8 -4
- package/src/nodes/core/VaryingNode.js +7 -3
- package/src/nodes/display/AfterImageNode.js +6 -0
- package/src/nodes/display/AnaglyphPassNode.js +6 -0
- package/src/nodes/display/AnamorphicNode.js +6 -0
- package/src/nodes/display/BloomNode.js +6 -0
- package/src/nodes/display/BumpMapNode.js +6 -0
- package/src/nodes/display/ColorSpaceFunctions.js +4 -4
- package/src/nodes/display/ColorSpaceNode.js +43 -14
- package/src/nodes/display/DenoiseNode.js +6 -3
- package/src/nodes/display/DepthOfFieldNode.js +6 -3
- package/src/nodes/display/DotScreenNode.js +8 -5
- package/src/nodes/display/FXAANode.js +6 -3
- package/src/nodes/display/FilmNode.js +6 -3
- package/src/nodes/display/FrontFacingNode.js +7 -3
- package/src/nodes/display/GTAONode.js +6 -3
- package/src/nodes/display/GaussianBlurNode.js +6 -3
- package/src/nodes/display/Lut3DNode.js +6 -3
- package/src/nodes/display/NormalMapNode.js +8 -6
- package/src/nodes/display/ParallaxBarrierPassNode.js +8 -5
- package/src/nodes/display/PassNode.js +18 -7
- package/src/nodes/display/PixelationPassNode.js +12 -5
- package/src/nodes/display/PosterizeNode.js +6 -3
- package/src/nodes/display/RGBShiftNode.js +6 -3
- package/src/nodes/display/RenderOutputNode.js +12 -8
- package/src/nodes/display/SSAAPassNode.js +6 -3
- package/src/nodes/display/ScreenNode.js +181 -0
- package/src/nodes/display/SobelOperatorNode.js +6 -3
- package/src/nodes/display/StereoCompositePassNode.js +6 -3
- package/src/nodes/display/StereoPassNode.js +6 -3
- package/src/nodes/display/ToneMappingFunctions.js +12 -12
- package/src/nodes/display/ToneMappingNode.js +8 -7
- package/src/nodes/display/ToonOutlinePassNode.js +111 -0
- package/src/nodes/display/TransitionNode.js +6 -3
- package/src/nodes/display/ViewportDepthNode.js +7 -3
- package/src/nodes/display/ViewportDepthTextureNode.js +8 -5
- package/src/nodes/display/ViewportSharedTextureNode.js +8 -5
- package/src/nodes/display/ViewportTextureNode.js +8 -5
- package/src/nodes/fog/FogExp2Node.js +6 -3
- package/src/nodes/fog/FogNode.js +7 -3
- package/src/nodes/fog/FogRangeNode.js +6 -3
- package/src/nodes/functions/PhysicalLightingModel.js +2 -2
- package/src/nodes/functions/material/getShIrradianceAt.js +28 -0
- package/src/nodes/geometry/RangeNode.js +7 -3
- package/src/nodes/gpgpu/AtomicFunctionNode.js +99 -0
- package/src/nodes/gpgpu/BarrierNode.js +40 -0
- package/src/nodes/gpgpu/ComputeBuiltinNode.js +98 -0
- package/src/nodes/gpgpu/ComputeNode.js +8 -4
- package/src/nodes/gpgpu/WorkgroupInfoNode.js +100 -0
- package/src/nodes/lighting/AONode.js +6 -3
- package/src/nodes/lighting/AmbientLightNode.js +6 -3
- package/src/nodes/lighting/AnalyticLightNode.js +198 -30
- package/src/nodes/lighting/BasicEnvironmentNode.js +6 -3
- package/src/nodes/lighting/BasicLightMapNode.js +6 -3
- package/src/nodes/lighting/DirectionalLightNode.js +7 -4
- package/src/nodes/lighting/EnvironmentNode.js +6 -3
- package/src/nodes/lighting/HemisphereLightNode.js +10 -6
- package/src/nodes/lighting/IESSpotLightNode.js +6 -3
- package/src/nodes/lighting/IrradianceNode.js +6 -3
- package/src/nodes/lighting/LightProbeNode.js +8 -31
- package/src/nodes/lighting/LightingContextNode.js +6 -3
- package/src/nodes/lighting/LightingNode.js +7 -3
- package/src/nodes/lighting/LightsNode.js +24 -5
- package/src/nodes/lighting/PointLightNode.js +11 -7
- package/src/nodes/lighting/RectAreaLightNode.js +11 -7
- package/src/nodes/lighting/SpotLightNode.js +13 -10
- package/src/nodes/math/ConditionalNode.js +23 -6
- package/src/nodes/math/MathNode.js +6 -3
- package/src/nodes/math/OperatorNode.js +6 -3
- package/src/nodes/pmrem/PMREMNode.js +6 -3
- package/src/nodes/utils/ArrayElementNode.js +8 -4
- package/src/nodes/utils/ConvertNode.js +7 -3
- package/src/nodes/utils/CubeMapNode.js +6 -3
- package/src/nodes/utils/EquirectUVNode.js +6 -3
- package/src/nodes/utils/FlipNode.js +7 -4
- package/src/nodes/utils/FunctionOverloadingNode.js +7 -3
- package/src/nodes/utils/JoinNode.js +6 -3
- package/src/nodes/utils/LoopNode.js +7 -3
- package/src/nodes/utils/MatcapUVNode.js +6 -3
- package/src/nodes/utils/MaxMipLevelNode.js +6 -3
- package/src/nodes/utils/OscNode.js +7 -3
- package/src/nodes/utils/RTTNode.js +6 -3
- package/src/nodes/utils/ReflectorNode.js +8 -5
- package/src/nodes/utils/RemapNode.js +7 -3
- package/src/nodes/utils/RotateNode.js +6 -3
- package/src/nodes/utils/SetNode.js +7 -4
- package/src/nodes/utils/SplitNode.js +7 -3
- package/src/nodes/utils/SpriteSheetUVNode.js +7 -3
- package/src/nodes/utils/StorageArrayElementNode.js +9 -8
- package/src/nodes/utils/TimerNode.js +6 -3
- package/src/nodes/utils/TriplanarTexturesNode.js +7 -3
- package/src/nodes/utils/ViewportUtils.js +2 -2
- package/src/objects/BatchedMesh.js +76 -10
- package/src/objects/LOD.js +21 -0
- package/src/objects/Line.js +1 -0
- package/src/objects/Mesh.js +7 -23
- package/src/objects/Points.js +2 -0
- package/src/renderers/WebGLRenderer.js +65 -50
- package/src/renderers/common/BundleGroup.js +26 -0
- package/src/renderers/common/ClippingContext.js +4 -3
- package/src/renderers/common/RenderContext.js +4 -5
- package/src/renderers/common/RenderObject.js +116 -5
- package/src/renderers/common/RenderObjects.js +8 -1
- package/src/renderers/common/Renderer.js +57 -49
- package/src/renderers/common/extras/PMREMGenerator.js +7 -9
- package/src/renderers/common/nodes/NodeBuilderState.js +3 -3
- package/src/renderers/common/nodes/Nodes.js +33 -14
- package/src/renderers/shaders/ShaderLib/sprite.glsl.js +2 -4
- package/src/renderers/webgl/WebGLAttributes.js +45 -14
- package/src/renderers/webgl/WebGLCapabilities.js +9 -0
- package/src/renderers/webgl/WebGLProgram.js +2 -0
- package/src/renderers/webgl/WebGLPrograms.js +21 -17
- package/src/renderers/webgl/WebGLState.js +21 -0
- package/src/renderers/webgl/WebGLTextures.js +22 -0
- package/src/renderers/webgl-fallback/WebGLBackend.js +50 -45
- package/src/renderers/webgl-fallback/nodes/GLSLNodeBuilder.js +4 -4
- package/src/renderers/webgl-fallback/utils/WebGLAttributeUtils.js +6 -0
- package/src/renderers/webgl-fallback/utils/WebGLState.js +1 -4
- package/src/renderers/webgl-fallback/utils/WebGLTextureUtils.js +61 -16
- package/src/renderers/webgpu/WebGPUBackend.js +33 -25
- package/src/renderers/webgpu/WebGPURenderer.Nodes.js +42 -0
- package/src/renderers/webgpu/WebGPURenderer.js +5 -2
- package/src/renderers/webgpu/nodes/BasicNodeLibrary.js +59 -0
- package/src/renderers/{common → webgpu}/nodes/StandardNodeLibrary.js +11 -11
- package/src/renderers/webgpu/nodes/WGSLNodeBuilder.js +91 -11
- package/src/renderers/webgpu/utils/WebGPUAttributeUtils.js +6 -16
- package/src/renderers/webgpu/utils/WebGPUPipelineUtils.js +1 -1
- package/src/renderers/webgpu/utils/WebGPUTextureUtils.js +7 -5
- package/src/renderers/webgpu/utils/WebGPUUtils.js +1 -1
- package/src/utils.js +33 -1
- package/examples/jsm/geometries/SDFGeometryGenerator.js +0 -144
- package/examples/jsm/loaders/TiltLoader.js +0 -520
- package/examples/jsm/utils/GPUStatsPanel.js +0 -95
- package/examples/jsm/utils/PackedPhongMaterial.js +0 -178
- package/src/nodes/display/ViewportNode.js +0 -138
- package/src/nodes/lighting/LightNode.js +0 -57
- package/src/renderers/common/StandardRenderer.js +0 -18
- package/src/renderers/webvr/WebVRManager.js +0 -495
- package/src/renderers/webvr/WebVRUtils.js +0 -66
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
// Original src: https://github.com/zz85/threejs-path-flow
|
|
2
|
+
const CHANNELS = 4;
|
|
3
|
+
const TEXTURE_WIDTH = 1024;
|
|
4
|
+
const TEXTURE_HEIGHT = 4;
|
|
5
|
+
|
|
6
|
+
import {
|
|
7
|
+
DataTexture,
|
|
8
|
+
DataUtils,
|
|
9
|
+
RGBAFormat,
|
|
10
|
+
HalfFloatType,
|
|
11
|
+
RepeatWrapping,
|
|
12
|
+
Mesh,
|
|
13
|
+
InstancedMesh,
|
|
14
|
+
LinearFilter
|
|
15
|
+
} from 'three';
|
|
16
|
+
|
|
17
|
+
import { modelWorldMatrix, normalLocal, vec2, vec3, vec4, mat3, varyingProperty, texture, reference, Fn, select, positionLocal } from 'three/tsl';
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Make a new DataTexture to store the descriptions of the curves.
|
|
21
|
+
*
|
|
22
|
+
* @param { number } numberOfCurves the number of curves needed to be described by this texture.
|
|
23
|
+
*/
|
|
24
|
+
export function initSplineTexture( numberOfCurves = 1 ) {
|
|
25
|
+
|
|
26
|
+
const dataArray = new Uint16Array( TEXTURE_WIDTH * TEXTURE_HEIGHT * numberOfCurves * CHANNELS );
|
|
27
|
+
const dataTexture = new DataTexture(
|
|
28
|
+
dataArray,
|
|
29
|
+
TEXTURE_WIDTH,
|
|
30
|
+
TEXTURE_HEIGHT * numberOfCurves,
|
|
31
|
+
RGBAFormat,
|
|
32
|
+
HalfFloatType
|
|
33
|
+
);
|
|
34
|
+
|
|
35
|
+
dataTexture.wrapS = RepeatWrapping;
|
|
36
|
+
dataTexture.wrapY = RepeatWrapping;
|
|
37
|
+
dataTexture.magFilter = LinearFilter;
|
|
38
|
+
dataTexture.minFilter = LinearFilter;
|
|
39
|
+
dataTexture.needsUpdate = true;
|
|
40
|
+
|
|
41
|
+
return dataTexture;
|
|
42
|
+
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Write the curve description to the data texture
|
|
47
|
+
*
|
|
48
|
+
* @param { DataTexture } texture The DataTexture to write to
|
|
49
|
+
* @param { Curve } splineCurve The curve to describe
|
|
50
|
+
* @param { number } offset Which curve slot to write to
|
|
51
|
+
*/
|
|
52
|
+
export function updateSplineTexture( texture, splineCurve, offset = 0 ) {
|
|
53
|
+
|
|
54
|
+
const numberOfPoints = Math.floor( TEXTURE_WIDTH * ( TEXTURE_HEIGHT / 4 ) );
|
|
55
|
+
splineCurve.arcLengthDivisions = numberOfPoints / 2;
|
|
56
|
+
splineCurve.updateArcLengths();
|
|
57
|
+
const points = splineCurve.getSpacedPoints( numberOfPoints );
|
|
58
|
+
const frenetFrames = splineCurve.computeFrenetFrames( numberOfPoints, true );
|
|
59
|
+
|
|
60
|
+
for ( let i = 0; i < numberOfPoints; i ++ ) {
|
|
61
|
+
|
|
62
|
+
const rowOffset = Math.floor( i / TEXTURE_WIDTH );
|
|
63
|
+
const rowIndex = i % TEXTURE_WIDTH;
|
|
64
|
+
|
|
65
|
+
let pt = points[ i ];
|
|
66
|
+
setTextureValue( texture, rowIndex, pt.x, pt.y, pt.z, 0 + rowOffset + ( TEXTURE_HEIGHT * offset ) );
|
|
67
|
+
pt = frenetFrames.tangents[ i ];
|
|
68
|
+
setTextureValue( texture, rowIndex, pt.x, pt.y, pt.z, 1 + rowOffset + ( TEXTURE_HEIGHT * offset ) );
|
|
69
|
+
pt = frenetFrames.normals[ i ];
|
|
70
|
+
setTextureValue( texture, rowIndex, pt.x, pt.y, pt.z, 2 + rowOffset + ( TEXTURE_HEIGHT * offset ) );
|
|
71
|
+
pt = frenetFrames.binormals[ i ];
|
|
72
|
+
setTextureValue( texture, rowIndex, pt.x, pt.y, pt.z, 3 + rowOffset + ( TEXTURE_HEIGHT * offset ) );
|
|
73
|
+
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
texture.needsUpdate = true;
|
|
77
|
+
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
function setTextureValue( texture, index, x, y, z, o ) {
|
|
82
|
+
|
|
83
|
+
const image = texture.image;
|
|
84
|
+
const { data } = image;
|
|
85
|
+
const i = CHANNELS * TEXTURE_WIDTH * o; // Row Offset
|
|
86
|
+
|
|
87
|
+
data[ index * CHANNELS + i + 0 ] = DataUtils.toHalfFloat( x );
|
|
88
|
+
data[ index * CHANNELS + i + 1 ] = DataUtils.toHalfFloat( y );
|
|
89
|
+
data[ index * CHANNELS + i + 2 ] = DataUtils.toHalfFloat( z );
|
|
90
|
+
data[ index * CHANNELS + i + 3 ] = DataUtils.toHalfFloat( 1 );
|
|
91
|
+
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Create a new set of uniforms for describing the curve modifier
|
|
96
|
+
*
|
|
97
|
+
* @param { DataTexture } Texture which holds the curve description
|
|
98
|
+
*/
|
|
99
|
+
export function getUniforms( splineTexture ) {
|
|
100
|
+
|
|
101
|
+
return {
|
|
102
|
+
spineTexture: splineTexture,
|
|
103
|
+
pathOffset: 0, // time of path curve
|
|
104
|
+
pathSegment: 1, // fractional length of path
|
|
105
|
+
spineOffset: 161,
|
|
106
|
+
spineLength: 400,
|
|
107
|
+
flow: 1, // int
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export function modifyShader( material, uniforms, numberOfCurves ) {
|
|
113
|
+
|
|
114
|
+
const spineTexture = uniforms.spineTexture;
|
|
115
|
+
|
|
116
|
+
const pathOffset = reference( 'pathOffset', 'float', uniforms );
|
|
117
|
+
const pathSegment = reference( 'pathSegment', 'float', uniforms );
|
|
118
|
+
const spineOffset = reference( 'spineOffset', 'float', uniforms );
|
|
119
|
+
const spineLength = reference( 'spineLength', 'float', uniforms );
|
|
120
|
+
const flow = reference( 'flow', 'float', uniforms );
|
|
121
|
+
|
|
122
|
+
material.positionNode = Fn( () => {
|
|
123
|
+
|
|
124
|
+
const textureStacks = TEXTURE_HEIGHT / 4;
|
|
125
|
+
const textureScale = TEXTURE_HEIGHT * numberOfCurves;
|
|
126
|
+
|
|
127
|
+
const worldPos = modelWorldMatrix.mul( vec4( positionLocal, 1 ) ).toVar();
|
|
128
|
+
|
|
129
|
+
const bend = flow.greaterThan( 0 ).toVar();
|
|
130
|
+
const xWeight = select( bend, 0, 1 ).toVar();
|
|
131
|
+
|
|
132
|
+
const spinePortion = select( bend, worldPos.x.add( spineOffset ).div( spineLength ), 0 );
|
|
133
|
+
const mt = spinePortion.mul( pathSegment ).add( pathOffset ).mul( textureStacks ).toVar();
|
|
134
|
+
|
|
135
|
+
mt.assign( mt.mod( textureStacks ) );
|
|
136
|
+
|
|
137
|
+
const rowOffset = mt.floor().toVar();
|
|
138
|
+
|
|
139
|
+
const spinePos = texture( spineTexture, vec2( mt, rowOffset.add( 0.5 ).div( textureScale ) ) ).xyz;
|
|
140
|
+
|
|
141
|
+
const a = texture( spineTexture, vec2( mt, rowOffset.add( 1.5 ).div( textureScale ) ) ).xyz;
|
|
142
|
+
const b = texture( spineTexture, vec2( mt, rowOffset.add( 2.5 ).div( textureScale ) ) ).xyz;
|
|
143
|
+
const c = texture( spineTexture, vec2( mt, rowOffset.add( 3.5 ).div( textureScale ) ) ).xyz;
|
|
144
|
+
|
|
145
|
+
const basis = mat3( a, b, c ).toVar();
|
|
146
|
+
|
|
147
|
+
varyingProperty( 'vec3', 'curveNormal' ).assign( basis.mul( normalLocal ) );
|
|
148
|
+
|
|
149
|
+
return basis.mul( vec3( worldPos.x.mul( xWeight ), worldPos.y, worldPos.z ) ).add( spinePos );
|
|
150
|
+
|
|
151
|
+
} )();
|
|
152
|
+
|
|
153
|
+
material.normalNode = varyingProperty( 'vec3', 'curveNormal' );
|
|
154
|
+
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* A helper class for making meshes bend aroudn curves
|
|
159
|
+
*/
|
|
160
|
+
export class Flow {
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* @param {Mesh} mesh The mesh to clone and modify to bend around the curve
|
|
164
|
+
* @param {number} numberOfCurves The amount of space that should preallocated for additional curves
|
|
165
|
+
*/
|
|
166
|
+
constructor( mesh, numberOfCurves = 1 ) {
|
|
167
|
+
|
|
168
|
+
const obj3D = mesh.clone();
|
|
169
|
+
const splineTexure = initSplineTexture( numberOfCurves );
|
|
170
|
+
const uniforms = getUniforms( splineTexure );
|
|
171
|
+
|
|
172
|
+
obj3D.traverse( function ( child ) {
|
|
173
|
+
|
|
174
|
+
if (
|
|
175
|
+
child instanceof Mesh ||
|
|
176
|
+
child instanceof InstancedMesh
|
|
177
|
+
) {
|
|
178
|
+
|
|
179
|
+
if ( Array.isArray( child.material ) ) {
|
|
180
|
+
|
|
181
|
+
const materials = [];
|
|
182
|
+
|
|
183
|
+
for ( const material of child.material ) {
|
|
184
|
+
|
|
185
|
+
const newMaterial = material.clone();
|
|
186
|
+
modifyShader( newMaterial, uniforms, numberOfCurves );
|
|
187
|
+
materials.push( newMaterial );
|
|
188
|
+
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
child.material = materials;
|
|
192
|
+
|
|
193
|
+
} else {
|
|
194
|
+
|
|
195
|
+
child.material = child.material.clone();
|
|
196
|
+
modifyShader( child.material, uniforms, numberOfCurves );
|
|
197
|
+
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
} );
|
|
203
|
+
|
|
204
|
+
this.curveArray = new Array( numberOfCurves );
|
|
205
|
+
this.curveLengthArray = new Array( numberOfCurves );
|
|
206
|
+
|
|
207
|
+
this.object3D = obj3D;
|
|
208
|
+
this.splineTexure = splineTexure;
|
|
209
|
+
this.uniforms = uniforms;
|
|
210
|
+
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
updateCurve( index, curve ) {
|
|
214
|
+
|
|
215
|
+
if ( index >= this.curveArray.length ) throw Error( 'Index out of range for Flow' );
|
|
216
|
+
|
|
217
|
+
const curveLength = curve.getLength();
|
|
218
|
+
|
|
219
|
+
this.uniforms.spineLength = curveLength;
|
|
220
|
+
this.curveLengthArray[ index ] = curveLength;
|
|
221
|
+
this.curveArray[ index ] = curve;
|
|
222
|
+
|
|
223
|
+
updateSplineTexture( this.splineTexure, curve, index );
|
|
224
|
+
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
moveAlongCurve( amount ) {
|
|
228
|
+
|
|
229
|
+
this.uniforms.pathOffset += amount;
|
|
230
|
+
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
}
|
|
@@ -0,0 +1,322 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AdditiveBlending,
|
|
3
|
+
Box2,
|
|
4
|
+
BufferGeometry,
|
|
5
|
+
Color,
|
|
6
|
+
FramebufferTexture,
|
|
7
|
+
InterleavedBuffer,
|
|
8
|
+
InterleavedBufferAttribute,
|
|
9
|
+
Mesh,
|
|
10
|
+
MeshBasicNodeMaterial,
|
|
11
|
+
NodeMaterial,
|
|
12
|
+
UnsignedByteType,
|
|
13
|
+
Vector2,
|
|
14
|
+
Vector3,
|
|
15
|
+
Vector4 } from 'three';
|
|
16
|
+
|
|
17
|
+
import { texture, textureLoad, uv, ivec2, vec2, vec4, positionGeometry, reference, varyingProperty, materialReference, Fn, Node } from 'three/tsl';
|
|
18
|
+
|
|
19
|
+
class LensflareMesh extends Mesh {
|
|
20
|
+
|
|
21
|
+
constructor() {
|
|
22
|
+
|
|
23
|
+
super( LensflareMesh.Geometry, new MeshBasicNodeMaterial( { opacity: 0, transparent: true } ) );
|
|
24
|
+
|
|
25
|
+
this.isLensflare = true;
|
|
26
|
+
|
|
27
|
+
this.type = 'LensflareMesh';
|
|
28
|
+
this.frustumCulled = false;
|
|
29
|
+
this.renderOrder = Infinity;
|
|
30
|
+
|
|
31
|
+
//
|
|
32
|
+
|
|
33
|
+
const positionView = new Vector3();
|
|
34
|
+
|
|
35
|
+
// textures
|
|
36
|
+
|
|
37
|
+
const tempMap = new FramebufferTexture( 16, 16 );
|
|
38
|
+
const occlusionMap = new FramebufferTexture( 16, 16 );
|
|
39
|
+
|
|
40
|
+
let currentType = UnsignedByteType;
|
|
41
|
+
|
|
42
|
+
const geometry = LensflareMesh.Geometry;
|
|
43
|
+
|
|
44
|
+
// values for shared material uniforms
|
|
45
|
+
|
|
46
|
+
const sharedValues = {
|
|
47
|
+
scale: new Vector2(),
|
|
48
|
+
positionScreen: new Vector3()
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
// materials
|
|
52
|
+
|
|
53
|
+
const scale = reference( 'scale', 'vec2', sharedValues );
|
|
54
|
+
const screenPosition = reference( 'positionScreen', 'vec3', sharedValues );
|
|
55
|
+
|
|
56
|
+
const vertexNode = vec4( positionGeometry.xy.mul( scale ).add( screenPosition.xy ), screenPosition.z, 1.0 );
|
|
57
|
+
|
|
58
|
+
const material1a = new NodeMaterial();
|
|
59
|
+
|
|
60
|
+
material1a.depthTest = true;
|
|
61
|
+
material1a.depthWrite = false;
|
|
62
|
+
material1a.transparent = false;
|
|
63
|
+
material1a.fog = false;
|
|
64
|
+
material1a.type = 'Lensflare-1a';
|
|
65
|
+
|
|
66
|
+
material1a.vertexNode = vertexNode;
|
|
67
|
+
material1a.fragmentNode = vec4( 1.0, 0.0, 1.0, 1.0 );
|
|
68
|
+
|
|
69
|
+
const material1b = new NodeMaterial();
|
|
70
|
+
|
|
71
|
+
material1b.depthTest = false;
|
|
72
|
+
material1b.depthWrite = false;
|
|
73
|
+
material1b.transparent = false;
|
|
74
|
+
material1b.fog = false;
|
|
75
|
+
material1b.type = 'Lensflare-1b';
|
|
76
|
+
|
|
77
|
+
material1b.vertexNode = vertexNode;
|
|
78
|
+
material1b.fragmentNode = texture( tempMap, vec2( uv().flipY() ) );
|
|
79
|
+
|
|
80
|
+
// the following object is used for occlusionMap generation
|
|
81
|
+
|
|
82
|
+
const mesh1 = new Mesh( geometry, material1a );
|
|
83
|
+
|
|
84
|
+
//
|
|
85
|
+
|
|
86
|
+
const elements = [];
|
|
87
|
+
const elementMeshes = [];
|
|
88
|
+
|
|
89
|
+
const material2 = new NodeMaterial();
|
|
90
|
+
|
|
91
|
+
material2.transparent = true;
|
|
92
|
+
material2.blending = AdditiveBlending;
|
|
93
|
+
material2.depthWrite = false;
|
|
94
|
+
material2.depthTest = false;
|
|
95
|
+
material2.fog = false;
|
|
96
|
+
material2.type = 'Lensflare-2';
|
|
97
|
+
|
|
98
|
+
material2.screenPosition = new Vector3();
|
|
99
|
+
material2.scale = new Vector2();
|
|
100
|
+
material2.occlusionMap = occlusionMap;
|
|
101
|
+
|
|
102
|
+
material2.vertexNode = Fn( ( { material } ) => {
|
|
103
|
+
|
|
104
|
+
const scale = materialReference( 'scale', 'vec2' );
|
|
105
|
+
const screenPosition = materialReference( 'screenPosition', 'vec3' );
|
|
106
|
+
|
|
107
|
+
const occlusionMap = material.occlusionMap;
|
|
108
|
+
|
|
109
|
+
const pos = positionGeometry.xy.toVar();
|
|
110
|
+
|
|
111
|
+
const visibility = textureLoad( occlusionMap, ivec2( 2, 2 ) ).toVar();
|
|
112
|
+
visibility.addAssign( textureLoad( occlusionMap, ivec2( 8, 2 ) ) );
|
|
113
|
+
visibility.addAssign( textureLoad( occlusionMap, ivec2( 14, 2 ) ) );
|
|
114
|
+
visibility.addAssign( textureLoad( occlusionMap, ivec2( 14, 8 ) ) );
|
|
115
|
+
visibility.addAssign( textureLoad( occlusionMap, ivec2( 14, 14 ) ) );
|
|
116
|
+
visibility.addAssign( textureLoad( occlusionMap, ivec2( 8, 14 ) ) );
|
|
117
|
+
visibility.addAssign( textureLoad( occlusionMap, ivec2( 2, 14 ) ) );
|
|
118
|
+
visibility.addAssign( textureLoad( occlusionMap, ivec2( 2, 8 ) ) );
|
|
119
|
+
visibility.addAssign( textureLoad( occlusionMap, ivec2( 8, 8 ) ) );
|
|
120
|
+
|
|
121
|
+
const vVisibility = varyingProperty( 'float', 'vVisibility' );
|
|
122
|
+
|
|
123
|
+
vVisibility.assign( visibility.r.div( 9.0 ) );
|
|
124
|
+
vVisibility.mulAssign( visibility.g.div( 9.0 ).oneMinus() );
|
|
125
|
+
vVisibility.mulAssign( visibility.b.div( 9.0 ) );
|
|
126
|
+
|
|
127
|
+
return vec4( ( pos.mul( scale ).add( screenPosition.xy ).xy ), screenPosition.z, 1.0 );
|
|
128
|
+
|
|
129
|
+
} )();
|
|
130
|
+
|
|
131
|
+
material2.fragmentNode = Fn( () => {
|
|
132
|
+
|
|
133
|
+
const color = reference( 'color', 'color' );
|
|
134
|
+
const map = reference( 'map', 'texture' );
|
|
135
|
+
|
|
136
|
+
const vVisibility = varyingProperty( 'float', 'vVisibility' );
|
|
137
|
+
|
|
138
|
+
const output = map.toVar();
|
|
139
|
+
|
|
140
|
+
output.a.mulAssign( vVisibility );
|
|
141
|
+
output.rgb.mulAssign( color );
|
|
142
|
+
|
|
143
|
+
return output;
|
|
144
|
+
|
|
145
|
+
} )();
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
this.addElement = function ( element ) {
|
|
149
|
+
|
|
150
|
+
elements.push( element );
|
|
151
|
+
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
//
|
|
155
|
+
|
|
156
|
+
const positionScreen = sharedValues.positionScreen;
|
|
157
|
+
const screenPositionPixels = new Vector4( 0, 0, 16, 16 );
|
|
158
|
+
const validArea = new Box2();
|
|
159
|
+
const viewport = new Vector4();
|
|
160
|
+
|
|
161
|
+
// dummy node for renderer.renderObject()
|
|
162
|
+
const lightsNode = new Node();
|
|
163
|
+
|
|
164
|
+
this.onBeforeRender = ( renderer, scene, camera ) => {
|
|
165
|
+
|
|
166
|
+
renderer.getViewport( viewport );
|
|
167
|
+
|
|
168
|
+
viewport.multiplyScalar( window.devicePixelRatio );
|
|
169
|
+
|
|
170
|
+
const renderTarget = renderer.getRenderTarget();
|
|
171
|
+
const type = ( renderTarget !== null ) ? renderTarget.texture.type : UnsignedByteType;
|
|
172
|
+
|
|
173
|
+
if ( currentType !== type ) {
|
|
174
|
+
|
|
175
|
+
tempMap.dispose();
|
|
176
|
+
occlusionMap.dispose();
|
|
177
|
+
|
|
178
|
+
tempMap.type = occlusionMap.type = type;
|
|
179
|
+
|
|
180
|
+
currentType = type;
|
|
181
|
+
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
const invAspect = viewport.w / viewport.z;
|
|
185
|
+
const halfViewportWidth = viewport.z / 2.0;
|
|
186
|
+
const halfViewportHeight = viewport.w / 2.0;
|
|
187
|
+
|
|
188
|
+
const size = 16 / viewport.w;
|
|
189
|
+
|
|
190
|
+
sharedValues.scale.set( size * invAspect, size );
|
|
191
|
+
|
|
192
|
+
validArea.min.set( viewport.x, viewport.y );
|
|
193
|
+
validArea.max.set( viewport.x + ( viewport.z - 16 ), viewport.y + ( viewport.w - 16 ) );
|
|
194
|
+
|
|
195
|
+
// calculate position in screen space
|
|
196
|
+
|
|
197
|
+
positionView.setFromMatrixPosition( this.matrixWorld );
|
|
198
|
+
positionView.applyMatrix4( camera.matrixWorldInverse );
|
|
199
|
+
|
|
200
|
+
if ( positionView.z > 0 ) return; // lensflare is behind the camera
|
|
201
|
+
|
|
202
|
+
positionScreen.copy( positionView ).applyMatrix4( camera.projectionMatrix );
|
|
203
|
+
|
|
204
|
+
// horizontal and vertical coordinate of the lower left corner of the pixels to copy
|
|
205
|
+
|
|
206
|
+
screenPositionPixels.x = viewport.x + ( positionScreen.x * halfViewportWidth ) + halfViewportWidth - 8;
|
|
207
|
+
screenPositionPixels.y = viewport.y - ( positionScreen.y * halfViewportHeight ) + halfViewportHeight - 8;
|
|
208
|
+
|
|
209
|
+
// screen cull
|
|
210
|
+
|
|
211
|
+
if ( validArea.containsPoint( screenPositionPixels ) ) {
|
|
212
|
+
|
|
213
|
+
// save current RGB to temp texture
|
|
214
|
+
|
|
215
|
+
renderer.copyFramebufferToTexture( tempMap, screenPositionPixels );
|
|
216
|
+
|
|
217
|
+
// render pink quad
|
|
218
|
+
|
|
219
|
+
renderer.renderObject( mesh1, scene, camera, geometry, material1a, null, lightsNode );
|
|
220
|
+
|
|
221
|
+
// copy result to occlusionMap
|
|
222
|
+
|
|
223
|
+
renderer.copyFramebufferToTexture( occlusionMap, screenPositionPixels );
|
|
224
|
+
|
|
225
|
+
// restore graphics
|
|
226
|
+
|
|
227
|
+
renderer.renderObject( mesh1, scene, camera, geometry, material1b, null, lightsNode );
|
|
228
|
+
|
|
229
|
+
// render elements
|
|
230
|
+
|
|
231
|
+
const vecX = - positionScreen.x * 2;
|
|
232
|
+
const vecY = - positionScreen.y * 2;
|
|
233
|
+
|
|
234
|
+
for ( let i = 0, l = elements.length; i < l; i ++ ) {
|
|
235
|
+
|
|
236
|
+
const element = elements[ i ];
|
|
237
|
+
|
|
238
|
+
let mesh2 = elementMeshes[ i ];
|
|
239
|
+
|
|
240
|
+
if ( mesh2 === undefined ) {
|
|
241
|
+
|
|
242
|
+
mesh2 = elementMeshes[ i ] = new Mesh( geometry, material2 );
|
|
243
|
+
|
|
244
|
+
mesh2.color = element.color.convertSRGBToLinear();
|
|
245
|
+
mesh2.map = element.texture;
|
|
246
|
+
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
material2.screenPosition.x = positionScreen.x + vecX * element.distance;
|
|
250
|
+
material2.screenPosition.y = positionScreen.y - vecY * element.distance;
|
|
251
|
+
material2.screenPosition.z = positionScreen.z;
|
|
252
|
+
|
|
253
|
+
const size = element.size / viewport.w;
|
|
254
|
+
|
|
255
|
+
material2.scale.set( size * invAspect, size );
|
|
256
|
+
|
|
257
|
+
renderer.renderObject( mesh2, scene, camera, geometry, material2, null, lightsNode );
|
|
258
|
+
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
};
|
|
264
|
+
|
|
265
|
+
this.dispose = function () {
|
|
266
|
+
|
|
267
|
+
material1a.dispose();
|
|
268
|
+
material1b.dispose();
|
|
269
|
+
material2.dispose();
|
|
270
|
+
|
|
271
|
+
tempMap.dispose();
|
|
272
|
+
occlusionMap.dispose();
|
|
273
|
+
|
|
274
|
+
for ( let i = 0, l = elements.length; i < l; i ++ ) {
|
|
275
|
+
|
|
276
|
+
elements[ i ].texture.dispose();
|
|
277
|
+
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
};
|
|
281
|
+
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
//
|
|
287
|
+
|
|
288
|
+
class LensflareElement {
|
|
289
|
+
|
|
290
|
+
constructor( texture, size = 1, distance = 0, color = new Color( 0xffffff ) ) {
|
|
291
|
+
|
|
292
|
+
this.texture = texture;
|
|
293
|
+
this.size = size;
|
|
294
|
+
this.distance = distance;
|
|
295
|
+
this.color = color;
|
|
296
|
+
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
LensflareMesh.Geometry = ( function () {
|
|
302
|
+
|
|
303
|
+
const geometry = new BufferGeometry();
|
|
304
|
+
|
|
305
|
+
const float32Array = new Float32Array( [
|
|
306
|
+
- 1, - 1, 0, 0, 0,
|
|
307
|
+
1, - 1, 0, 1, 0,
|
|
308
|
+
1, 1, 0, 1, 1,
|
|
309
|
+
- 1, 1, 0, 0, 1
|
|
310
|
+
] );
|
|
311
|
+
|
|
312
|
+
const interleavedBuffer = new InterleavedBuffer( float32Array, 5 );
|
|
313
|
+
|
|
314
|
+
geometry.setIndex( [ 0, 1, 2, 0, 2, 3 ] );
|
|
315
|
+
geometry.setAttribute( 'position', new InterleavedBufferAttribute( interleavedBuffer, 3, 0, false ) );
|
|
316
|
+
geometry.setAttribute( 'uv', new InterleavedBufferAttribute( interleavedBuffer, 2, 3, false ) );
|
|
317
|
+
|
|
318
|
+
return geometry;
|
|
319
|
+
|
|
320
|
+
} )();
|
|
321
|
+
|
|
322
|
+
export { LensflareMesh, LensflareElement };
|
|
@@ -2,10 +2,9 @@ import {
|
|
|
2
2
|
BackSide,
|
|
3
3
|
BoxGeometry,
|
|
4
4
|
Mesh,
|
|
5
|
-
NodeMaterial,
|
|
6
5
|
Vector3
|
|
7
6
|
} from 'three';
|
|
8
|
-
import {
|
|
7
|
+
import { Fn, NodeMaterial, float, vec3, acos, add, mul, clamp, cos, dot, exp, max, mix, modelViewProjection, normalize, positionWorld, pow, smoothstep, sub, varying, varyingProperty, vec4, uniform, cameraPosition } from 'three/tsl';
|
|
9
8
|
|
|
10
9
|
/**
|
|
11
10
|
* Based on "A Practical Analytic Model for Daylight"
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
2
|
Color,
|
|
3
3
|
Mesh,
|
|
4
|
-
NodeMaterial,
|
|
5
4
|
Vector2,
|
|
6
5
|
Vector3
|
|
7
6
|
} from 'three';
|
|
8
|
-
import { vec2, viewportSafeUV, viewportSharedTexture, reflector, pow, float, abs, texture, uniform,
|
|
7
|
+
import { Fn, NodeMaterial, NodeUpdateType, TempNode, vec2, viewportSafeUV, viewportSharedTexture, reflector, pow, float, abs, texture, uniform, vec4, cameraPosition, positionWorld, uv, mix, vec3, normalize, max, dot, screenUV } from 'three/tsl';
|
|
9
8
|
|
|
10
9
|
/**
|
|
11
10
|
* References:
|
|
@@ -141,7 +140,7 @@ class WaterNode extends TempNode {
|
|
|
141
140
|
this.waterBody.add( reflectionSampler.target );
|
|
142
141
|
reflectionSampler.uvNode = reflectionSampler.uvNode.add( offset );
|
|
143
142
|
|
|
144
|
-
const refractorUV =
|
|
143
|
+
const refractorUV = screenUV.add( offset );
|
|
145
144
|
const refractionSampler = viewportSharedTexture( viewportSafeUV( refractorUV ) );
|
|
146
145
|
|
|
147
146
|
// calculate final uv coords
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
2
|
Color,
|
|
3
3
|
Mesh,
|
|
4
|
-
NodeMaterial,
|
|
5
4
|
Vector3
|
|
6
5
|
} from 'three';
|
|
7
|
-
import { add, cameraPosition, div, normalize, positionWorld, sub, timerLocal,
|
|
6
|
+
import { Fn, NodeMaterial, add, cameraPosition, div, normalize, positionWorld, sub, timerLocal, texture, vec2, vec3, vec4, max, dot, reflect, pow, length, float, uniform, reflector, mul, mix } from 'three/tsl';
|
|
8
7
|
|
|
9
8
|
/**
|
|
10
9
|
* Work based on :
|
|
@@ -226,7 +226,7 @@ class GLSLDecoder {
|
|
|
226
226
|
|
|
227
227
|
this._currentFunction = null;
|
|
228
228
|
|
|
229
|
-
this.addPolyfill( 'gl_FragCoord', 'vec3 gl_FragCoord = vec3(
|
|
229
|
+
this.addPolyfill( 'gl_FragCoord', 'vec3 gl_FragCoord = vec3( screenCoordinate.x, screenCoordinate.y.oneMinus(), screenCoordinate.z );' );
|
|
230
230
|
|
|
231
231
|
}
|
|
232
232
|
|
|
@@ -8,8 +8,8 @@ class ShaderToyDecoder extends GLSLDecoder {
|
|
|
8
8
|
super();
|
|
9
9
|
|
|
10
10
|
this.addPolyfill( 'iTime', 'float iTime = timerGlobal();' );
|
|
11
|
-
this.addPolyfill( 'iResolution', 'vec2 iResolution =
|
|
12
|
-
this.addPolyfill( 'fragCoord', 'vec3 fragCoord = vec3(
|
|
11
|
+
this.addPolyfill( 'iResolution', 'vec2 iResolution = screenSize;' );
|
|
12
|
+
this.addPolyfill( 'fragCoord', 'vec3 fragCoord = vec3( screenCoordinate.x, screenSize.y - screenCoordinate.y, screenCoordinate.z );' );
|
|
13
13
|
|
|
14
14
|
}
|
|
15
15
|
|