super-three 0.169.1 → 0.170.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 +24628 -24228
- package/build/three.core.js +37002 -0
- package/build/three.core.min.js +6 -0
- package/build/three.module.js +10519 -47108
- package/build/three.module.min.js +1 -1
- package/build/three.tsl.js +533 -0
- package/build/three.tsl.min.js +6 -0
- package/build/three.webgpu.js +17071 -53583
- package/build/three.webgpu.min.js +1 -1
- package/build/three.webgpu.nodes.js +17134 -53623
- package/build/three.webgpu.nodes.min.js +1 -1
- package/examples/jsm/Addons.js +3 -3
- package/examples/jsm/animation/MMDAnimationHelper.js +2 -0
- package/examples/jsm/animation/MMDPhysics.js +2 -0
- package/examples/jsm/capabilities/WebGPU.js +1 -10
- package/examples/jsm/controls/ArcballControls.js +25 -21
- package/examples/jsm/controls/OrbitControls.js +41 -9
- package/examples/jsm/controls/PointerLockControls.js +2 -5
- package/examples/jsm/controls/TransformControls.js +22 -6
- package/examples/jsm/csm/CSM.js +2 -2
- package/examples/jsm/csm/CSMFrustum.js +7 -4
- package/examples/jsm/csm/CSMHelper.js +2 -0
- package/examples/jsm/csm/CSMShadowNode.js +437 -0
- package/examples/jsm/curves/NURBSCurve.js +34 -3
- package/examples/jsm/exporters/GLTFExporter.js +138 -71
- package/examples/jsm/exporters/KTX2Exporter.js +35 -12
- package/examples/jsm/exporters/MMDExporter.js +6 -0
- package/examples/jsm/exporters/USDZExporter.js +21 -3
- package/examples/jsm/geometries/DecalGeometry.js +70 -21
- package/examples/jsm/geometries/InstancedPointsGeometry.js +2 -0
- package/examples/jsm/helpers/TextureHelperGPU.js +175 -0
- package/examples/jsm/interactive/HTMLMesh.js +1 -0
- package/examples/jsm/lighting/TiledLighting.js +18 -0
- package/examples/jsm/lights/RectAreaLightTexturesLib.js +1 -1
- package/examples/jsm/lines/LineGeometry.js +25 -0
- package/examples/jsm/lines/LineMaterial.js +0 -1
- package/examples/jsm/lines/LineSegmentsGeometry.js +2 -0
- package/examples/jsm/lines/webgpu/Line2.js +2 -1
- package/examples/jsm/lines/webgpu/LineSegments2.js +2 -16
- package/examples/jsm/lines/webgpu/Wireframe.js +57 -0
- package/examples/jsm/loaders/3DMLoader.js +1 -0
- package/examples/jsm/loaders/3MFLoader.js +91 -0
- package/examples/jsm/loaders/FBXLoader.js +12 -2
- package/examples/jsm/loaders/GLTFLoader.js +2 -0
- package/examples/jsm/loaders/KTX2Loader.js +143 -49
- package/examples/jsm/loaders/LDrawLoader.js +22 -136
- package/examples/jsm/loaders/LottieLoader.js +1 -0
- package/examples/jsm/loaders/MMDLoader.js +3 -0
- package/examples/jsm/loaders/MaterialXLoader.js +2 -2
- package/examples/jsm/materials/LDrawConditionalLineMaterial.js +143 -0
- package/examples/jsm/materials/LDrawConditionalLineNodeMaterial.js +114 -0
- package/examples/jsm/math/ColorSpaces.js +76 -0
- package/examples/jsm/misc/ProgressiveLightMap.js +52 -40
- package/examples/jsm/misc/ProgressiveLightMapGPU.js +293 -0
- package/examples/jsm/misc/VolumeSlice.js +1 -0
- package/examples/jsm/objects/InstancedPoints.js +2 -4
- package/examples/jsm/objects/LensflareMesh.js +4 -2
- package/examples/jsm/objects/SkyMesh.js +5 -3
- package/examples/jsm/objects/Water2Mesh.js +7 -3
- package/examples/jsm/objects/WaterMesh.js +12 -10
- package/examples/jsm/postprocessing/AfterimagePass.js +14 -3
- package/examples/jsm/postprocessing/SSRPass.js +6 -0
- package/examples/jsm/renderers/CSS2DRenderer.js +6 -3
- package/examples/jsm/renderers/CSS3DRenderer.js +7 -4
- package/examples/jsm/shaders/FXAAShader.js +225 -224
- package/examples/jsm/transpiler/AST.js +2 -2
- package/examples/jsm/transpiler/GLSLDecoder.js +57 -25
- package/examples/jsm/transpiler/ShaderToyDecoder.js +1 -1
- package/examples/jsm/transpiler/TSLEncoder.js +11 -6
- package/{src/nodes → examples/jsm/tsl}/display/AfterImageNode.js +18 -21
- package/{src/nodes → examples/jsm/tsl}/display/AnaglyphPassNode.js +2 -6
- package/{src/nodes → examples/jsm/tsl}/display/AnamorphicNode.js +12 -18
- package/{src/nodes → examples/jsm/tsl}/display/BleachBypass.js +1 -3
- package/{src/nodes → examples/jsm/tsl}/display/BloomNode.js +12 -41
- package/{src/nodes → examples/jsm/tsl}/display/DenoiseNode.js +60 -47
- package/{src/nodes → examples/jsm/tsl}/display/DepthOfFieldNode.js +4 -9
- package/{src/nodes → examples/jsm/tsl}/display/DotScreenNode.js +2 -9
- package/examples/jsm/tsl/display/FXAANode.js +316 -0
- package/{src/nodes → examples/jsm/tsl}/display/FilmNode.js +4 -7
- package/{src/nodes → examples/jsm/tsl}/display/GTAONode.js +73 -78
- package/{src/nodes → examples/jsm/tsl}/display/GaussianBlurNode.js +78 -42
- package/examples/jsm/tsl/display/LensflareNode.js +161 -0
- package/{src/nodes → examples/jsm/tsl}/display/Lut3DNode.js +3 -5
- package/{src/nodes → examples/jsm/tsl}/display/MotionBlur.js +2 -3
- package/examples/jsm/tsl/display/OutlineNode.js +434 -0
- package/{src/nodes → examples/jsm/tsl}/display/ParallaxBarrierPassNode.js +2 -5
- package/{src/nodes → examples/jsm/tsl}/display/PixelationPassNode.js +5 -17
- package/{src/nodes → examples/jsm/tsl}/display/RGBShiftNode.js +2 -6
- package/examples/jsm/tsl/display/SMAANode.js +620 -0
- package/{src/nodes → examples/jsm/tsl}/display/SSAAPassNode.js +10 -25
- package/examples/jsm/tsl/display/SSRNode.js +366 -0
- package/{src/nodes → examples/jsm/tsl}/display/Sepia.js +1 -2
- package/{src/nodes → examples/jsm/tsl}/display/SobelOperatorNode.js +4 -12
- package/{src/nodes → examples/jsm/tsl}/display/StereoCompositePassNode.js +9 -11
- package/{src/nodes → examples/jsm/tsl}/display/StereoPassNode.js +10 -11
- package/examples/jsm/tsl/display/TRAAPassNode.js +355 -0
- package/{src/nodes → examples/jsm/tsl}/display/TransitionNode.js +3 -7
- package/examples/jsm/tsl/display/hashBlur.js +24 -0
- package/examples/jsm/tsl/lighting/TiledLightsNode.js +389 -0
- package/examples/jsm/utils/SceneOptimizer.js +410 -0
- package/examples/jsm/utils/UVsDebug.js +1 -1
- package/examples/jsm/utils/{TextureUtilsGPU.js → WebGPUTextureUtils.js} +2 -1
- package/examples/jsm/webxr/OculusHandPointerModel.js +21 -21
- package/examples/jsm/webxr/Text2D.js +6 -6
- package/package.json +4 -4
- package/src/Three.Core.js +178 -0
- package/src/Three.TSL.js +526 -0
- package/src/Three.WebGPU.Nodes.js +9 -186
- package/src/Three.WebGPU.js +8 -186
- package/src/Three.js +1 -177
- package/src/animation/AnimationClip.js +2 -2
- package/src/animation/AnimationObjectGroup.js +2 -2
- package/src/audio/Audio.js +38 -0
- package/src/cameras/PerspectiveCamera.js +6 -6
- package/src/cameras/StereoCamera.js +2 -2
- package/src/constants.js +1 -6
- package/src/core/BufferGeometry.js +48 -8
- package/src/core/InterleavedBuffer.js +4 -4
- package/src/core/Object3D.js +2 -2
- package/src/extras/core/Curve.js +3 -3
- package/src/extras/core/Shape.js +2 -2
- package/src/geometries/CylinderGeometry.js +2 -2
- package/src/geometries/EdgesGeometry.js +2 -2
- package/src/geometries/LatheGeometry.js +2 -2
- package/src/lights/SpotLightShadow.js +2 -2
- package/src/materials/LineDashedMaterial.js +0 -1
- package/src/materials/Material.js +2 -2
- package/src/materials/MeshPhongMaterial.js +1 -1
- package/src/materials/MeshPhysicalMaterial.js +2 -2
- package/src/materials/MeshStandardMaterial.js +2 -2
- package/src/materials/nodes/Line2NodeMaterial.js +32 -13
- package/src/materials/nodes/LineDashedNodeMaterial.js +4 -2
- package/src/materials/nodes/NodeMaterial.js +93 -23
- package/src/materials/nodes/SpriteNodeMaterial.js +11 -2
- package/src/materials/nodes/manager/NodeMaterialObserver.js +119 -7
- package/src/math/ColorManagement.js +143 -102
- package/src/math/Line3.js +2 -2
- package/src/math/Quaternion.js +2 -2
- package/src/math/Spherical.js +3 -3
- package/src/math/Vector2.js +7 -7
- package/src/math/Vector3.js +9 -9
- package/src/math/Vector4.js +22 -9
- package/src/nodes/Nodes.js +2 -21
- package/src/nodes/TSL.js +9 -25
- package/src/nodes/accessors/Arrays.js +27 -0
- package/src/nodes/accessors/BuiltinNode.js +26 -0
- package/src/nodes/accessors/Camera.js +0 -1
- package/src/nodes/accessors/ClippingNode.js +76 -42
- package/src/nodes/accessors/InstanceNode.js +17 -20
- package/src/nodes/accessors/InstancedMeshNode.js +26 -0
- package/src/nodes/accessors/Lights.js +32 -0
- package/src/nodes/accessors/SceneNode.js +35 -1
- package/src/nodes/accessors/StorageBufferNode.js +61 -19
- package/src/nodes/accessors/StorageTextureNode.js +10 -4
- package/src/nodes/accessors/TextureNode.js +1 -1
- package/src/nodes/accessors/VelocityNode.js +13 -3
- package/src/nodes/code/FunctionCallNode.js +16 -5
- package/src/nodes/code/ScriptableNode.js +4 -4
- package/src/nodes/core/Node.js +1 -0
- package/src/nodes/core/NodeBuilder.js +31 -14
- package/src/nodes/core/NodeUtils.js +28 -0
- package/src/nodes/core/VarNode.js +15 -3
- package/src/nodes/core/constants.js +6 -0
- package/src/nodes/display/BlendModes.js +99 -0
- package/src/nodes/display/ColorAdjustment.js +53 -4
- package/src/nodes/display/ColorSpaceFunctions.js +5 -5
- package/src/nodes/display/ColorSpaceNode.js +27 -39
- package/src/nodes/display/PassNode.js +6 -4
- package/src/nodes/display/ToneMappingNode.js +1 -1
- package/src/nodes/display/ToonOutlinePassNode.js +3 -3
- package/src/nodes/display/ViewportDepthNode.js +48 -1
- package/src/nodes/functions/PhysicalLightingModel.js +21 -15
- package/src/nodes/functions/material/getAlphaHashThreshold.js +70 -0
- package/src/nodes/functions/material/getGeometryRoughness.js +8 -2
- package/src/nodes/functions/material/getParallaxCorrectNormal.js +22 -0
- package/src/nodes/gpgpu/ComputeNode.js +9 -1
- package/src/nodes/lighting/AnalyticLightNode.js +23 -419
- package/src/nodes/lighting/LightsNode.js +24 -12
- package/src/nodes/lighting/PointLightNode.js +41 -22
- package/src/nodes/lighting/PointShadowNode.js +254 -0
- package/src/nodes/lighting/RectAreaLightNode.js +3 -0
- package/src/nodes/lighting/ShadowNode.js +593 -0
- package/src/nodes/lighting/SpotLightNode.js +14 -2
- package/src/nodes/utils/LoopNode.js +2 -2
- package/src/nodes/utils/Oscillators.js +6 -0
- package/src/nodes/utils/PostProcessingUtils.js +89 -0
- package/src/nodes/utils/RTTNode.js +9 -1
- package/src/nodes/utils/ReflectorNode.js +101 -15
- package/src/nodes/utils/StorageArrayElementNode.js +2 -2
- package/src/nodes/utils/Timer.js +29 -0
- package/src/objects/BatchedMesh.js +472 -296
- package/src/objects/ClippingGroup.js +19 -0
- package/src/objects/Skeleton.js +2 -2
- package/src/renderers/WebGLRenderer.js +183 -109
- package/src/renderers/common/Animation.js +23 -11
- package/src/renderers/common/Attributes.js +4 -0
- package/src/renderers/common/Backend.js +2 -0
- package/src/renderers/common/Background.js +15 -5
- package/src/renderers/common/Bindings.js +23 -6
- package/src/renderers/common/ClippingContext.js +77 -85
- package/src/renderers/common/Constants.js +2 -1
- package/src/renderers/common/Geometries.js +20 -0
- package/src/renderers/common/IndirectStorageBufferAttribute.js +15 -0
- package/src/renderers/common/Lighting.js +45 -0
- package/src/renderers/common/PostProcessingUtils.js +86 -0
- package/src/renderers/common/RenderList.js +48 -17
- package/src/renderers/common/RenderLists.js +4 -2
- package/src/renderers/common/RenderObject.js +45 -28
- package/src/renderers/common/RenderObjects.js +12 -6
- package/src/renderers/common/Renderer.js +222 -77
- package/src/renderers/common/Textures.js +41 -17
- package/src/renderers/common/UniformsGroup.js +16 -4
- package/src/renderers/common/extras/PMREMGenerator.js +89 -13
- package/src/renderers/common/nodes/NodeLibrary.js +2 -15
- package/src/renderers/common/nodes/NodeStorageBuffer.js +2 -3
- package/src/renderers/common/nodes/NodeUniform.js +42 -0
- package/src/renderers/common/nodes/Nodes.js +2 -2
- package/src/renderers/shaders/ShaderChunk/colorspace_pars_fragment.glsl.js +4 -24
- package/src/renderers/shaders/ShaderChunk/emissivemap_fragment.glsl.js +8 -0
- package/src/renderers/shaders/ShaderChunk/map_fragment.glsl.js +2 -2
- package/src/renderers/webgl/WebGLBackground.js +20 -1
- package/src/renderers/webgl/WebGLBufferRenderer.js +2 -6
- package/src/renderers/webgl/WebGLCapabilities.js +0 -7
- package/src/renderers/webgl/WebGLGeometries.js +0 -28
- package/src/renderers/webgl/WebGLIndexedBufferRenderer.js +2 -6
- package/src/renderers/webgl/WebGLProgram.js +24 -28
- package/src/renderers/webgl/WebGLPrograms.js +5 -2
- package/src/renderers/webgl/WebGLState.js +37 -1
- package/src/renderers/webgl/WebGLTextures.js +29 -12
- package/src/renderers/webgl-fallback/WebGLBackend.js +111 -37
- package/src/renderers/webgl-fallback/WebGLBufferRenderer.js +2 -7
- package/src/renderers/webgl-fallback/nodes/GLSLNodeBuilder.js +43 -12
- package/src/renderers/webgl-fallback/utils/WebGLState.js +26 -1
- package/src/renderers/webgl-fallback/utils/WebGLTextureUtils.js +37 -9
- package/src/renderers/webgpu/WebGPUBackend.js +152 -56
- package/src/renderers/webgpu/WebGPURenderer.Nodes.js +1 -1
- package/src/renderers/webgpu/WebGPURenderer.js +1 -1
- package/src/renderers/webgpu/nodes/BasicNodeLibrary.js +0 -8
- package/src/renderers/webgpu/nodes/StandardNodeLibrary.js +13 -34
- package/src/renderers/webgpu/nodes/WGSLNodeBuilder.js +192 -92
- package/src/renderers/webgpu/nodes/WGSLNodeFunction.js +12 -4
- package/src/renderers/webgpu/utils/WebGPUAttributeUtils.js +15 -2
- package/src/renderers/webgpu/utils/WebGPUBindingUtils.js +72 -7
- package/src/renderers/webgpu/utils/WebGPUPipelineUtils.js +29 -9
- package/src/renderers/webgpu/utils/WebGPUTextureUtils.js +29 -7
- package/src/renderers/webgpu/utils/WebGPUUtils.js +0 -1
- package/src/renderers/webxr/WebXRManager.js +4 -4
- package/src/textures/Source.js +2 -2
- package/src/textures/Texture.js +2 -2
- package/examples/jsm/cameras/CinematicCamera.js +0 -208
- package/src/nodes/display/BlendMode.js +0 -54
- package/src/nodes/display/FXAANode.js +0 -332
- package/src/nodes/utils/OscNode.js +0 -85
- package/src/nodes/utils/TimerNode.js +0 -97
- /package/examples/jsm/utils/{TextureUtils.js → WebGLTextureUtils.js} +0 -0
|
@@ -0,0 +1,316 @@
|
|
|
1
|
+
import { Vector2, TempNode } from 'three/webgpu';
|
|
2
|
+
import { nodeObject, Fn, uniformArray, select, float, NodeUpdateType, uv, dot, clamp, uniform, convertToTexture, smoothstep, bool, vec2, vec3, If, Loop, max, min, Break, abs } from 'three/tsl';
|
|
3
|
+
|
|
4
|
+
class FXAANode extends TempNode {
|
|
5
|
+
|
|
6
|
+
static get type() {
|
|
7
|
+
|
|
8
|
+
return 'FXAANode';
|
|
9
|
+
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
constructor( textureNode ) {
|
|
13
|
+
|
|
14
|
+
super( 'vec4' );
|
|
15
|
+
|
|
16
|
+
this.textureNode = textureNode;
|
|
17
|
+
|
|
18
|
+
this.updateBeforeType = NodeUpdateType.FRAME;
|
|
19
|
+
|
|
20
|
+
this._invSize = uniform( new Vector2() );
|
|
21
|
+
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
updateBefore() {
|
|
25
|
+
|
|
26
|
+
const map = this.textureNode.value;
|
|
27
|
+
|
|
28
|
+
this._invSize.value.set( 1 / map.image.width, 1 / map.image.height );
|
|
29
|
+
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
setup() {
|
|
33
|
+
|
|
34
|
+
const textureNode = this.textureNode.bias( - 100 );
|
|
35
|
+
const uvNode = textureNode.uvNode || uv();
|
|
36
|
+
|
|
37
|
+
const EDGE_STEP_COUNT = float( 6 );
|
|
38
|
+
const EDGE_GUESS = float( 8.0 );
|
|
39
|
+
const EDGE_STEPS = uniformArray( [ 1.0, 1.5, 2.0, 2.0, 2.0, 4.0 ] );
|
|
40
|
+
|
|
41
|
+
const _ContrastThreshold = float( 0.0312 );
|
|
42
|
+
const _RelativeThreshold = float( 0.063 );
|
|
43
|
+
const _SubpixelBlending = float( 1.0 );
|
|
44
|
+
|
|
45
|
+
const Sample = Fn( ( [ uv ] ) => {
|
|
46
|
+
|
|
47
|
+
return textureNode.uv( uv );
|
|
48
|
+
|
|
49
|
+
} );
|
|
50
|
+
|
|
51
|
+
const SampleLuminance = Fn( ( [ uv ] ) => {
|
|
52
|
+
|
|
53
|
+
return dot( Sample( uv ).rgb, vec3( 0.3, 0.59, 0.11 ) );
|
|
54
|
+
|
|
55
|
+
} );
|
|
56
|
+
|
|
57
|
+
const SampleLuminanceOffset = Fn( ( [ texSize, uv, uOffset, vOffset ] ) => {
|
|
58
|
+
|
|
59
|
+
const shiftedUv = uv.add( texSize.mul( vec2( uOffset, vOffset ) ) );
|
|
60
|
+
return SampleLuminance( shiftedUv );
|
|
61
|
+
|
|
62
|
+
} );
|
|
63
|
+
|
|
64
|
+
const ShouldSkipPixel = ( l ) => {
|
|
65
|
+
|
|
66
|
+
const threshold = max( _ContrastThreshold, _RelativeThreshold.mul( l.highest ) );
|
|
67
|
+
return l.contrast.lessThan( threshold );
|
|
68
|
+
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
const SampleLuminanceNeighborhood = ( texSize, uv ) => {
|
|
72
|
+
|
|
73
|
+
const m = SampleLuminance( uv );
|
|
74
|
+
|
|
75
|
+
const n = SampleLuminanceOffset( texSize, uv, 0.0, - 1.0 );
|
|
76
|
+
const e = SampleLuminanceOffset( texSize, uv, 1.0, 0.0 );
|
|
77
|
+
const s = SampleLuminanceOffset( texSize, uv, 0.0, 1.0 );
|
|
78
|
+
const w = SampleLuminanceOffset( texSize, uv, - 1.0, 0.0 );
|
|
79
|
+
|
|
80
|
+
const ne = SampleLuminanceOffset( texSize, uv, 1.0, - 1.0 );
|
|
81
|
+
const nw = SampleLuminanceOffset( texSize, uv, - 1.0, - 1.0 );
|
|
82
|
+
const se = SampleLuminanceOffset( texSize, uv, 1.0, 1.0 );
|
|
83
|
+
const sw = SampleLuminanceOffset( texSize, uv, - 1.0, 1.0 );
|
|
84
|
+
|
|
85
|
+
const highest = max( max( max( max( s, e ), n ), w ), m );
|
|
86
|
+
const lowest = min( min( min( min( s, e ), n ), w ), m );
|
|
87
|
+
const contrast = highest.sub( lowest );
|
|
88
|
+
|
|
89
|
+
return { m, n, e, s, w, ne, nw, se, sw, highest, lowest, contrast };
|
|
90
|
+
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
const DeterminePixelBlendFactor = ( l ) => {
|
|
94
|
+
|
|
95
|
+
let f = float( 2.0 ).mul( l.s.add( l.e ).add( l.n ).add( l.w ) );
|
|
96
|
+
f = f.add( l.se.add( l.sw ).add( l.ne ).add( l.nw ) );
|
|
97
|
+
f = f.mul( 1.0 / 12.0 );
|
|
98
|
+
f = abs( f.sub( l.m ) );
|
|
99
|
+
f = clamp( f.div( max( l.contrast, 0 ) ), 0.0, 1.0 );
|
|
100
|
+
|
|
101
|
+
const blendFactor = smoothstep( 0.0, 1.0, f );
|
|
102
|
+
return blendFactor.mul( blendFactor ).mul( _SubpixelBlending );
|
|
103
|
+
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
const DetermineEdge = ( texSize, l ) => {
|
|
107
|
+
|
|
108
|
+
const horizontal =
|
|
109
|
+
abs( l.s.add( l.n ).sub( l.m.mul( 2.0 ) ) ).mul( 2.0 ).add(
|
|
110
|
+
abs( l.se.add( l.ne ).sub( l.e.mul( 2.0 ) ) ).add(
|
|
111
|
+
abs( l.sw.add( l.nw ).sub( l.w.mul( 2.0 ) ) )
|
|
112
|
+
)
|
|
113
|
+
);
|
|
114
|
+
|
|
115
|
+
const vertical =
|
|
116
|
+
abs( l.e.add( l.w ).sub( l.m.mul( 2.0 ) ) ).mul( 2.0 ).add(
|
|
117
|
+
abs( l.se.add( l.sw ).sub( l.s.mul( 2.0 ) ) ).add(
|
|
118
|
+
abs( l.ne.add( l.nw ).sub( l.n.mul( 2.0 ) ) )
|
|
119
|
+
)
|
|
120
|
+
);
|
|
121
|
+
|
|
122
|
+
const isHorizontal = horizontal.greaterThanEqual( vertical );
|
|
123
|
+
|
|
124
|
+
const pLuminance = select( isHorizontal, l.s, l.e );
|
|
125
|
+
const nLuminance = select( isHorizontal, l.n, l.w );
|
|
126
|
+
const pGradient = abs( pLuminance.sub( l.m ) );
|
|
127
|
+
const nGradient = abs( nLuminance.sub( l.m ) );
|
|
128
|
+
|
|
129
|
+
const pixelStep = select( isHorizontal, texSize.y, texSize.x ).toVar();
|
|
130
|
+
const oppositeLuminance = float().toVar();
|
|
131
|
+
const gradient = float().toVar();
|
|
132
|
+
|
|
133
|
+
If( pGradient.lessThan( nGradient ), () => {
|
|
134
|
+
|
|
135
|
+
pixelStep.assign( pixelStep.negate() );
|
|
136
|
+
oppositeLuminance.assign( nLuminance );
|
|
137
|
+
gradient.assign( nGradient );
|
|
138
|
+
|
|
139
|
+
} ).Else( () => {
|
|
140
|
+
|
|
141
|
+
oppositeLuminance.assign( pLuminance );
|
|
142
|
+
gradient.assign( pGradient );
|
|
143
|
+
|
|
144
|
+
} );
|
|
145
|
+
|
|
146
|
+
return { isHorizontal, pixelStep, oppositeLuminance, gradient };
|
|
147
|
+
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
const DetermineEdgeBlendFactor = ( texSize, l, e, uv ) => {
|
|
151
|
+
|
|
152
|
+
const uvEdge = uv.toVar();
|
|
153
|
+
const edgeStep = vec2().toVar();
|
|
154
|
+
If( e.isHorizontal, () => {
|
|
155
|
+
|
|
156
|
+
uvEdge.y.addAssign( e.pixelStep.mul( 0.5 ) );
|
|
157
|
+
edgeStep.assign( vec2( texSize.x, 0.0 ) );
|
|
158
|
+
|
|
159
|
+
} ).Else( () => {
|
|
160
|
+
|
|
161
|
+
uvEdge.x.addAssign( e.pixelStep.mul( 0.5 ) );
|
|
162
|
+
edgeStep.assign( vec2( 0.0, texSize.y ) );
|
|
163
|
+
|
|
164
|
+
} );
|
|
165
|
+
|
|
166
|
+
const edgeLuminance = l.m.add( e.oppositeLuminance ).mul( 0.5 );
|
|
167
|
+
const gradientThreshold = e.gradient.mul( 0.25 );
|
|
168
|
+
|
|
169
|
+
const puv = uvEdge.add( edgeStep.mul( EDGE_STEPS.element( 0 ) ) ).toVar();
|
|
170
|
+
const pLuminanceDelta = SampleLuminance( puv ).sub( edgeLuminance ).toVar();
|
|
171
|
+
const pAtEnd = abs( pLuminanceDelta ).greaterThanEqual( gradientThreshold ).toVar();
|
|
172
|
+
|
|
173
|
+
Loop( { start: 1, end: EDGE_STEP_COUNT }, ( { i } ) => {
|
|
174
|
+
|
|
175
|
+
If( pAtEnd, () => {
|
|
176
|
+
|
|
177
|
+
Break();
|
|
178
|
+
|
|
179
|
+
} );
|
|
180
|
+
|
|
181
|
+
puv.addAssign( edgeStep.mul( EDGE_STEPS.element( i ) ) );
|
|
182
|
+
pLuminanceDelta.assign( SampleLuminance( puv ).sub( edgeLuminance ) );
|
|
183
|
+
pAtEnd.assign( abs( pLuminanceDelta ).greaterThanEqual( gradientThreshold ) );
|
|
184
|
+
|
|
185
|
+
} );
|
|
186
|
+
|
|
187
|
+
If( pAtEnd.not(), () => {
|
|
188
|
+
|
|
189
|
+
puv.addAssign( edgeStep.mul( EDGE_GUESS ) );
|
|
190
|
+
|
|
191
|
+
} );
|
|
192
|
+
|
|
193
|
+
const nuv = uvEdge.sub( edgeStep.mul( EDGE_STEPS.element( 0 ) ) ).toVar();
|
|
194
|
+
const nLuminanceDelta = SampleLuminance( nuv ).sub( edgeLuminance ).toVar();
|
|
195
|
+
const nAtEnd = abs( nLuminanceDelta ).greaterThanEqual( gradientThreshold ).toVar();
|
|
196
|
+
|
|
197
|
+
Loop( { start: 1, end: EDGE_STEP_COUNT }, ( { i } ) => {
|
|
198
|
+
|
|
199
|
+
If( nAtEnd, () => {
|
|
200
|
+
|
|
201
|
+
Break();
|
|
202
|
+
|
|
203
|
+
} );
|
|
204
|
+
|
|
205
|
+
nuv.subAssign( edgeStep.mul( EDGE_STEPS.element( i ) ) );
|
|
206
|
+
nLuminanceDelta.assign( SampleLuminance( nuv ).sub( edgeLuminance ) );
|
|
207
|
+
nAtEnd.assign( abs( nLuminanceDelta ).greaterThanEqual( gradientThreshold ) );
|
|
208
|
+
|
|
209
|
+
} );
|
|
210
|
+
|
|
211
|
+
If( nAtEnd.not(), () => {
|
|
212
|
+
|
|
213
|
+
nuv.subAssign( edgeStep.mul( EDGE_GUESS ) );
|
|
214
|
+
|
|
215
|
+
} );
|
|
216
|
+
|
|
217
|
+
const pDistance = float().toVar();
|
|
218
|
+
const nDistance = float().toVar();
|
|
219
|
+
|
|
220
|
+
If( e.isHorizontal, () => {
|
|
221
|
+
|
|
222
|
+
pDistance.assign( puv.x.sub( uv.x ) );
|
|
223
|
+
nDistance.assign( uv.x.sub( nuv.x ) );
|
|
224
|
+
|
|
225
|
+
} ).Else( () => {
|
|
226
|
+
|
|
227
|
+
pDistance.assign( puv.y.sub( uv.y ) );
|
|
228
|
+
nDistance.assign( uv.y.sub( nuv.y ) );
|
|
229
|
+
|
|
230
|
+
} );
|
|
231
|
+
|
|
232
|
+
const shortestDistance = float().toVar();
|
|
233
|
+
const deltaSign = bool().toVar();
|
|
234
|
+
|
|
235
|
+
If( pDistance.lessThanEqual( nDistance ), () => {
|
|
236
|
+
|
|
237
|
+
shortestDistance.assign( pDistance );
|
|
238
|
+
deltaSign.assign( pLuminanceDelta.greaterThanEqual( 0.0 ) );
|
|
239
|
+
|
|
240
|
+
} ).Else( () => {
|
|
241
|
+
|
|
242
|
+
shortestDistance.assign( nDistance );
|
|
243
|
+
deltaSign.assign( nLuminanceDelta.greaterThanEqual( 0.0 ) );
|
|
244
|
+
|
|
245
|
+
} );
|
|
246
|
+
|
|
247
|
+
const blendFactor = float().toVar();
|
|
248
|
+
|
|
249
|
+
If( deltaSign.equal( l.m.sub( edgeLuminance ).greaterThanEqual( 0.0 ) ), () => {
|
|
250
|
+
|
|
251
|
+
blendFactor.assign( 0.0 );
|
|
252
|
+
|
|
253
|
+
} ).Else( () => {
|
|
254
|
+
|
|
255
|
+
blendFactor.assign( float( 0.5 ).sub( shortestDistance.div( pDistance.add( nDistance ) ) ) );
|
|
256
|
+
|
|
257
|
+
} );
|
|
258
|
+
|
|
259
|
+
return blendFactor;
|
|
260
|
+
|
|
261
|
+
};
|
|
262
|
+
|
|
263
|
+
const ApplyFXAA = Fn( ( [ uv, texSize ] ) => {
|
|
264
|
+
|
|
265
|
+
const luminance = SampleLuminanceNeighborhood( texSize, uv );
|
|
266
|
+
If( ShouldSkipPixel( luminance ), () => {
|
|
267
|
+
|
|
268
|
+
return Sample( uv );
|
|
269
|
+
|
|
270
|
+
} );
|
|
271
|
+
|
|
272
|
+
const pixelBlend = DeterminePixelBlendFactor( luminance );
|
|
273
|
+
const edge = DetermineEdge( texSize, luminance );
|
|
274
|
+
const edgeBlend = DetermineEdgeBlendFactor( texSize, luminance, edge, uv );
|
|
275
|
+
|
|
276
|
+
const finalBlend = max( pixelBlend, edgeBlend );
|
|
277
|
+
const finalUv = uv.toVar();
|
|
278
|
+
|
|
279
|
+
If( edge.isHorizontal, () => {
|
|
280
|
+
|
|
281
|
+
finalUv.y.addAssign( edge.pixelStep.mul( finalBlend ) );
|
|
282
|
+
|
|
283
|
+
} ).Else( () => {
|
|
284
|
+
|
|
285
|
+
finalUv.x.addAssign( edge.pixelStep.mul( finalBlend ) );
|
|
286
|
+
|
|
287
|
+
} );
|
|
288
|
+
|
|
289
|
+
return Sample( finalUv );
|
|
290
|
+
|
|
291
|
+
} ).setLayout( {
|
|
292
|
+
name: 'FxaaPixelShader',
|
|
293
|
+
type: 'vec4',
|
|
294
|
+
inputs: [
|
|
295
|
+
{ name: 'uv', type: 'vec2' },
|
|
296
|
+
{ name: 'texSize', type: 'vec2' },
|
|
297
|
+
]
|
|
298
|
+
} );
|
|
299
|
+
|
|
300
|
+
const fxaa = Fn( () => {
|
|
301
|
+
|
|
302
|
+
return ApplyFXAA( uvNode, this._invSize );
|
|
303
|
+
|
|
304
|
+
} );
|
|
305
|
+
|
|
306
|
+
const outputNode = fxaa();
|
|
307
|
+
|
|
308
|
+
return outputNode;
|
|
309
|
+
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
export default FXAANode;
|
|
315
|
+
|
|
316
|
+
export const fxaa = ( node ) => nodeObject( new FXAANode( convertToTexture( node ) ) );
|
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
import TempNode from '
|
|
2
|
-
import { uv } from '
|
|
3
|
-
import { Fn, nodeProxy, vec4 } from '../tsl/TSLBase.js';
|
|
4
|
-
import { mix, fract, clamp, rand } from '../math/MathNode.js';
|
|
5
|
-
import { timerLocal } from '../utils/TimerNode.js';
|
|
1
|
+
import { TempNode } from 'three/webgpu';
|
|
2
|
+
import { rand, Fn, fract, time, uv, clamp, mix, vec4, nodeProxy } from 'three/tsl';
|
|
6
3
|
|
|
7
4
|
class FilmNode extends TempNode {
|
|
8
5
|
|
|
@@ -14,7 +11,7 @@ class FilmNode extends TempNode {
|
|
|
14
11
|
|
|
15
12
|
constructor( inputNode, intensityNode = null, uvNode = null ) {
|
|
16
13
|
|
|
17
|
-
super();
|
|
14
|
+
super( 'vec4' );
|
|
18
15
|
|
|
19
16
|
this.inputNode = inputNode;
|
|
20
17
|
this.intensityNode = intensityNode;
|
|
@@ -29,7 +26,7 @@ class FilmNode extends TempNode {
|
|
|
29
26
|
const film = Fn( () => {
|
|
30
27
|
|
|
31
28
|
const base = this.inputNode.rgb;
|
|
32
|
-
const noise = rand( fract( uvNode.add(
|
|
29
|
+
const noise = rand( fract( uvNode.add( time ) ) );
|
|
33
30
|
|
|
34
31
|
let color = base.add( base.mul( clamp( noise.add( 0.1 ), 0, 1 ) ) );
|
|
35
32
|
|
|
@@ -1,28 +1,15 @@
|
|
|
1
|
-
import TempNode from '
|
|
2
|
-
import { texture } from '
|
|
3
|
-
import { textureSize } from '../accessors/TextureSizeNode.js';
|
|
4
|
-
import { uv } from '../accessors/UV.js';
|
|
5
|
-
import { nodeObject, Fn, mat3, vec2, vec3, vec4, float, int, If } from '../tsl/TSLBase.js';
|
|
6
|
-
import { NodeUpdateType } from '../core/constants.js';
|
|
7
|
-
import { uniform } from '../core/UniformNode.js';
|
|
8
|
-
import { DataTexture } from '../../textures/DataTexture.js';
|
|
9
|
-
import { Vector2 } from '../../math/Vector2.js';
|
|
10
|
-
import { Vector3 } from '../../math/Vector3.js';
|
|
11
|
-
import { PI, cos, sin, pow, clamp, abs, max, mix, sqrt, acos, dot, normalize, cross } from '../math/MathNode.js';
|
|
12
|
-
import { div, mul, add, sub } from '../math/OperatorNode.js';
|
|
13
|
-
import { Loop } from '../utils/LoopNode.js';
|
|
14
|
-
import { passTexture } from './PassNode.js';
|
|
15
|
-
import { RepeatWrapping } from '../../constants.js';
|
|
16
|
-
import QuadMesh from '../../renderers/common/QuadMesh.js';
|
|
17
|
-
import NodeMaterial from '../../materials/nodes/NodeMaterial.js';
|
|
18
|
-
|
|
19
|
-
import { RenderTarget } from '../../core/RenderTarget.js';
|
|
20
|
-
import { Color } from '../../math/Color.js';
|
|
1
|
+
import { DataTexture, RenderTarget, RepeatWrapping, Vector2, Vector3, TempNode, QuadMesh, NodeMaterial, PostProcessingUtils } from 'three/webgpu';
|
|
2
|
+
import { reference, logarithmicDepthToViewZ, viewZToPerspectiveDepth, getNormalFromDepth, getScreenPosition, getViewPosition, nodeObject, Fn, float, NodeUpdateType, uv, uniform, Loop, vec2, vec3, vec4, int, dot, max, pow, abs, If, textureSize, sin, cos, PI, texture, passTexture, mat3, add, normalize, mul, cross, div, mix, sqrt, sub, acos, clamp } from 'three/tsl';
|
|
21
3
|
|
|
22
4
|
const _quadMesh = /*@__PURE__*/ new QuadMesh();
|
|
23
|
-
const _currentClearColor = /*@__PURE__*/ new Color();
|
|
24
5
|
const _size = /*@__PURE__*/ new Vector2();
|
|
25
6
|
|
|
7
|
+
let _rendererState;
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* References:
|
|
11
|
+
* https://www.activision.com/cdn/research/Practical_Real_Time_Strategies_for_Accurate_Indirect_Occlusion_NEW%20VERSION_COLOR.pdf
|
|
12
|
+
*/
|
|
26
13
|
class GTAONode extends TempNode {
|
|
27
14
|
|
|
28
15
|
static get type() {
|
|
@@ -33,31 +20,44 @@ class GTAONode extends TempNode {
|
|
|
33
20
|
|
|
34
21
|
constructor( depthNode, normalNode, camera ) {
|
|
35
22
|
|
|
36
|
-
super();
|
|
23
|
+
super( 'vec4' );
|
|
37
24
|
|
|
38
25
|
this.depthNode = depthNode;
|
|
39
26
|
this.normalNode = normalNode;
|
|
40
27
|
|
|
28
|
+
this.resolutionScale = 1;
|
|
29
|
+
|
|
30
|
+
this.updateBeforeType = NodeUpdateType.FRAME;
|
|
31
|
+
|
|
32
|
+
// render targets
|
|
33
|
+
|
|
34
|
+
this._aoRenderTarget = new RenderTarget( 1, 1, { depthBuffer: false } );
|
|
35
|
+
this._aoRenderTarget.texture.name = 'GTAONode.AO';
|
|
36
|
+
|
|
37
|
+
// uniforms
|
|
38
|
+
|
|
41
39
|
this.radius = uniform( 0.25 );
|
|
42
40
|
this.resolution = uniform( new Vector2() );
|
|
43
41
|
this.thickness = uniform( 1 );
|
|
44
42
|
this.distanceExponent = uniform( 1 );
|
|
45
43
|
this.distanceFallOff = uniform( 1 );
|
|
46
44
|
this.scale = uniform( 1 );
|
|
47
|
-
this.
|
|
45
|
+
this.samples = uniform( 16 );
|
|
48
46
|
|
|
49
|
-
this.
|
|
50
|
-
this.
|
|
47
|
+
this._noiseNode = texture( generateMagicSquareNoise() );
|
|
48
|
+
this._cameraProjectionMatrix = uniform( camera.projectionMatrix );
|
|
49
|
+
this._cameraProjectionMatrixInverse = uniform( camera.projectionMatrixInverse );
|
|
50
|
+
this._cameraNear = reference( 'near', 'float', camera );
|
|
51
|
+
this._cameraFar = reference( 'far', 'float', camera );
|
|
51
52
|
|
|
52
|
-
|
|
53
|
+
// materials
|
|
53
54
|
|
|
54
|
-
this.
|
|
55
|
-
this.
|
|
55
|
+
this._material = new NodeMaterial();
|
|
56
|
+
this._material.name = 'GTAO';
|
|
56
57
|
|
|
57
|
-
|
|
58
|
-
this._textureNode = passTexture( this, this._aoRenderTarget.texture );
|
|
58
|
+
//
|
|
59
59
|
|
|
60
|
-
this.
|
|
60
|
+
this._textureNode = passTexture( this, this._aoRenderTarget.texture );
|
|
61
61
|
|
|
62
62
|
}
|
|
63
63
|
|
|
@@ -69,6 +69,9 @@ class GTAONode extends TempNode {
|
|
|
69
69
|
|
|
70
70
|
setSize( width, height ) {
|
|
71
71
|
|
|
72
|
+
width = Math.round( this.resolutionScale * width );
|
|
73
|
+
height = Math.round( this.resolutionScale * height );
|
|
74
|
+
|
|
72
75
|
this.resolution.value.set( width, height );
|
|
73
76
|
this._aoRenderTarget.setSize( width, height );
|
|
74
77
|
|
|
@@ -78,20 +81,17 @@ class GTAONode extends TempNode {
|
|
|
78
81
|
|
|
79
82
|
const { renderer } = frame;
|
|
80
83
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
const currentRenderTarget = renderer.getRenderTarget();
|
|
84
|
-
const currentMRT = renderer.getMRT();
|
|
85
|
-
renderer.getClearColor( _currentClearColor );
|
|
86
|
-
const currentClearAlpha = renderer.getClearAlpha();
|
|
84
|
+
_rendererState = PostProcessingUtils.resetRendererState( renderer, _rendererState );
|
|
87
85
|
|
|
88
|
-
|
|
86
|
+
//
|
|
89
87
|
|
|
88
|
+
const size = renderer.getDrawingBufferSize( _size );
|
|
90
89
|
this.setSize( size.width, size.height );
|
|
91
90
|
|
|
91
|
+
_quadMesh.material = this._material;
|
|
92
|
+
|
|
92
93
|
// clear
|
|
93
94
|
|
|
94
|
-
renderer.setMRT( null );
|
|
95
95
|
renderer.setClearColor( 0xffffff, 1 );
|
|
96
96
|
|
|
97
97
|
// ao
|
|
@@ -101,9 +101,7 @@ class GTAONode extends TempNode {
|
|
|
101
101
|
|
|
102
102
|
// restore
|
|
103
103
|
|
|
104
|
-
|
|
105
|
-
renderer.setMRT( currentMRT );
|
|
106
|
-
renderer.setClearColor( _currentClearColor, currentClearAlpha );
|
|
104
|
+
PostProcessingUtils.restoreRendererState( renderer, _rendererState );
|
|
107
105
|
|
|
108
106
|
}
|
|
109
107
|
|
|
@@ -111,42 +109,37 @@ class GTAONode extends TempNode {
|
|
|
111
109
|
|
|
112
110
|
const uvNode = uv();
|
|
113
111
|
|
|
114
|
-
const sampleDepth = ( uv ) =>
|
|
115
|
-
const sampleNoise = ( uv ) => this.noiseNode.uv( uv );
|
|
112
|
+
const sampleDepth = ( uv ) => {
|
|
116
113
|
|
|
117
|
-
|
|
114
|
+
const depth = this.depthNode.uv( uv ).r;
|
|
118
115
|
|
|
119
|
-
|
|
120
|
-
let sampleUv = sampleClipPos.xy.div( sampleClipPos.w ).mul( 0.5 ).add( 0.5 ).toVar();
|
|
121
|
-
sampleUv = vec2( sampleUv.x, sampleUv.y.oneMinus() );
|
|
122
|
-
const sampleSceneDepth = sampleDepth( sampleUv );
|
|
123
|
-
return vec3( sampleUv, sampleSceneDepth );
|
|
116
|
+
if ( builder.renderer.logarithmicDepthBuffer === true ) {
|
|
124
117
|
|
|
125
|
-
|
|
118
|
+
const viewZ = logarithmicDepthToViewZ( depth, this._cameraNear, this._cameraFar );
|
|
126
119
|
|
|
127
|
-
|
|
120
|
+
return viewZToPerspectiveDepth( viewZ, this._cameraNear, this._cameraFar );
|
|
128
121
|
|
|
129
|
-
|
|
122
|
+
}
|
|
130
123
|
|
|
131
|
-
|
|
132
|
-
const viewSpacePosition = vec4( this.cameraProjectionMatrixInverse.mul( clipSpacePosition ) );
|
|
124
|
+
return depth;
|
|
133
125
|
|
|
134
|
-
|
|
126
|
+
};
|
|
135
127
|
|
|
136
|
-
|
|
128
|
+
const sampleNoise = ( uv ) => this._noiseNode.uv( uv );
|
|
129
|
+
const sampleNormal = ( uv ) => ( this.normalNode !== null ) ? this.normalNode.uv( uv ).rgb.normalize() : getNormalFromDepth( uv, this.depthNode.value, this._cameraProjectionMatrixInverse );
|
|
137
130
|
|
|
138
131
|
const ao = Fn( () => {
|
|
139
132
|
|
|
140
|
-
const depth = sampleDepth( uvNode );
|
|
133
|
+
const depth = sampleDepth( uvNode ).toVar();
|
|
141
134
|
|
|
142
135
|
depth.greaterThanEqual( 1.0 ).discard();
|
|
143
136
|
|
|
144
|
-
const viewPosition = getViewPosition( uvNode, depth );
|
|
145
|
-
const viewNormal =
|
|
137
|
+
const viewPosition = getViewPosition( uvNode, depth, this._cameraProjectionMatrixInverse ).toVar();
|
|
138
|
+
const viewNormal = sampleNormal( uvNode ).toVar();
|
|
146
139
|
|
|
147
140
|
const radiusToUse = this.radius;
|
|
148
141
|
|
|
149
|
-
const noiseResolution = textureSize( this.
|
|
142
|
+
const noiseResolution = textureSize( this._noiseNode, 0 );
|
|
150
143
|
let noiseUv = vec2( uvNode.x, uvNode.y.oneMinus() );
|
|
151
144
|
noiseUv = noiseUv.mul( this.resolution.div( noiseResolution ) );
|
|
152
145
|
const noiseTexel = sampleNoise( noiseUv );
|
|
@@ -155,23 +148,23 @@ class GTAONode extends TempNode {
|
|
|
155
148
|
const bitangent = vec3( tangent.y.mul( - 1.0 ), tangent.x, 0.0 );
|
|
156
149
|
const kernelMatrix = mat3( tangent, bitangent, vec3( 0.0, 0.0, 1.0 ) );
|
|
157
150
|
|
|
158
|
-
const DIRECTIONS = this.
|
|
159
|
-
const STEPS = add( this.
|
|
151
|
+
const DIRECTIONS = this.samples.lessThan( 30 ).select( 3, 5 ).toVar();
|
|
152
|
+
const STEPS = add( this.samples, DIRECTIONS.sub( 1 ) ).div( DIRECTIONS ).toVar();
|
|
160
153
|
|
|
161
154
|
const ao = float( 0 ).toVar();
|
|
162
155
|
|
|
163
156
|
Loop( { start: int( 0 ), end: DIRECTIONS, type: 'int', condition: '<' }, ( { i } ) => {
|
|
164
157
|
|
|
165
|
-
const angle = float( i ).div( float( DIRECTIONS ) ).mul( PI );
|
|
158
|
+
const angle = float( i ).div( float( DIRECTIONS ) ).mul( PI ).toVar();
|
|
166
159
|
const sampleDir = vec4( cos( angle ), sin( angle ), 0., add( 0.5, mul( 0.5, noiseTexel.w ) ) );
|
|
167
160
|
sampleDir.xyz = normalize( kernelMatrix.mul( sampleDir.xyz ) );
|
|
168
161
|
|
|
169
|
-
const viewDir = normalize( viewPosition.xyz.negate() );
|
|
170
|
-
const sliceBitangent = normalize( cross( sampleDir.xyz, viewDir ) );
|
|
162
|
+
const viewDir = normalize( viewPosition.xyz.negate() ).toVar();
|
|
163
|
+
const sliceBitangent = normalize( cross( sampleDir.xyz, viewDir ) ).toVar();
|
|
171
164
|
const sliceTangent = cross( sliceBitangent, viewDir );
|
|
172
165
|
const normalInSlice = normalize( viewNormal.sub( sliceBitangent.mul( dot( viewNormal, sliceBitangent ) ) ) );
|
|
173
166
|
|
|
174
|
-
const tangentToNormalInSlice = cross( normalInSlice, sliceBitangent );
|
|
167
|
+
const tangentToNormalInSlice = cross( normalInSlice, sliceBitangent ).toVar();
|
|
175
168
|
const cosHorizons = vec2( dot( viewDir, tangentToNormalInSlice ), dot( viewDir, tangentToNormalInSlice.negate() ) ).toVar();
|
|
176
169
|
|
|
177
170
|
Loop( { end: STEPS, type: 'int', name: 'j', condition: '<' }, ( { j } ) => {
|
|
@@ -180,9 +173,10 @@ class GTAONode extends TempNode {
|
|
|
180
173
|
|
|
181
174
|
// x
|
|
182
175
|
|
|
183
|
-
const
|
|
184
|
-
const
|
|
185
|
-
const
|
|
176
|
+
const sampleScreenPositionX = getScreenPosition( viewPosition.add( sampleViewOffset ), this._cameraProjectionMatrix ).toVar();
|
|
177
|
+
const sampleDepthX = sampleDepth( sampleScreenPositionX ).toVar();
|
|
178
|
+
const sampleSceneViewPositionX = getViewPosition( sampleScreenPositionX, sampleDepthX, this._cameraProjectionMatrixInverse ).toVar();
|
|
179
|
+
const viewDeltaX = sampleSceneViewPositionX.sub( viewPosition ).toVar();
|
|
186
180
|
|
|
187
181
|
If( abs( viewDeltaX.z ).lessThan( this.thickness ), () => {
|
|
188
182
|
|
|
@@ -193,9 +187,10 @@ class GTAONode extends TempNode {
|
|
|
193
187
|
|
|
194
188
|
// y
|
|
195
189
|
|
|
196
|
-
const
|
|
197
|
-
const
|
|
198
|
-
const
|
|
190
|
+
const sampleScreenPositionY = getScreenPosition( viewPosition.sub( sampleViewOffset ), this._cameraProjectionMatrix ).toVar();
|
|
191
|
+
const sampleDepthY = sampleDepth( sampleScreenPositionY ).toVar();
|
|
192
|
+
const sampleSceneViewPositionY = getViewPosition( sampleScreenPositionY, sampleDepthY, this._cameraProjectionMatrixInverse ).toVar();
|
|
193
|
+
const viewDeltaY = sampleSceneViewPositionY.sub( viewPosition ).toVar();
|
|
199
194
|
|
|
200
195
|
If( abs( viewDeltaY.z ).lessThan( this.thickness ), () => {
|
|
201
196
|
|
|
@@ -206,7 +201,7 @@ class GTAONode extends TempNode {
|
|
|
206
201
|
|
|
207
202
|
} );
|
|
208
203
|
|
|
209
|
-
const sinHorizons = sqrt( sub( 1.0, cosHorizons.mul( cosHorizons ) ) );
|
|
204
|
+
const sinHorizons = sqrt( sub( 1.0, cosHorizons.mul( cosHorizons ) ) ).toVar();
|
|
210
205
|
const nx = dot( normalInSlice, sliceTangent );
|
|
211
206
|
const ny = dot( normalInSlice, viewDir );
|
|
212
207
|
const nxb = mul( 0.5, acos( cosHorizons.y ).sub( acos( cosHorizons.x ) ).add( sinHorizons.x.mul( cosHorizons.x ).sub( sinHorizons.y.mul( cosHorizons.y ) ) ) );
|
|
@@ -223,10 +218,8 @@ class GTAONode extends TempNode {
|
|
|
223
218
|
|
|
224
219
|
} );
|
|
225
220
|
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
material.name = 'GTAO';
|
|
229
|
-
material.needsUpdate = true;
|
|
221
|
+
this._material.fragmentNode = ao().context( builder.getSharedContext() );
|
|
222
|
+
this._material.needsUpdate = true;
|
|
230
223
|
|
|
231
224
|
//
|
|
232
225
|
|
|
@@ -238,6 +231,8 @@ class GTAONode extends TempNode {
|
|
|
238
231
|
|
|
239
232
|
this._aoRenderTarget.dispose();
|
|
240
233
|
|
|
234
|
+
this._material.dispose();
|
|
235
|
+
|
|
241
236
|
}
|
|
242
237
|
|
|
243
238
|
}
|