super-three 0.157.1 → 0.160.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/README.md +6 -4
- package/build/three.cjs +3100 -1537
- package/build/three.js +3100 -1537
- package/build/three.min.js +1 -1
- package/build/three.module.js +3093 -1538
- package/build/three.module.min.js +1 -1
- package/examples/jsm/Addons.js +291 -0
- package/examples/jsm/controls/FlyControls.js +26 -0
- package/examples/jsm/controls/OrbitControls.js +62 -41
- package/examples/jsm/controls/TransformControls.js +27 -11
- package/examples/jsm/csm/CSMShader.js +53 -48
- package/examples/jsm/exporters/GLTFExporter.js +151 -3
- package/examples/jsm/exporters/USDZExporter.js +27 -19
- package/examples/jsm/geometries/InstancedPointsGeometry.js +174 -0
- package/examples/jsm/geometries/SDFGeometryGenerator.js +144 -0
- package/examples/jsm/helpers/TextureHelper.js +237 -0
- package/examples/jsm/interactive/HTMLMesh.js +9 -2
- package/examples/jsm/libs/lottie_canvas.module.js +6 -1
- package/examples/jsm/libs/opentype.module.js +13 -75
- package/examples/jsm/libs/surfaceNet.js +201 -0
- package/examples/jsm/lines/LineMaterial.js +16 -33
- package/examples/jsm/loaders/ColladaLoader.js +0 -6
- package/examples/jsm/loaders/DRACOLoader.js +4 -3
- package/examples/jsm/loaders/FBXLoader.js +294 -124
- package/examples/jsm/loaders/GLTFLoader.js +83 -6
- package/examples/jsm/loaders/LUTImageLoader.js +162 -0
- package/examples/jsm/loaders/MaterialXLoader.js +73 -54
- package/examples/jsm/loaders/NRRDLoader.js +0 -13
- package/examples/jsm/loaders/SVGLoader.js +4 -4
- package/examples/jsm/loaders/USDZLoader.js +3 -17
- package/examples/jsm/loaders/lwo/IFFParser.js +89 -93
- package/examples/jsm/materials/MeshGouraudMaterial.js +2 -0
- package/examples/jsm/math/Capsule.js +0 -55
- package/examples/jsm/math/Octree.js +85 -7
- package/examples/jsm/misc/Timer.js +119 -0
- package/examples/jsm/misc/TubePainter.js +3 -6
- package/examples/jsm/modifiers/CurveModifier.js +20 -2
- package/examples/jsm/modifiers/SimplifyModifier.js +103 -11
- package/examples/jsm/modifiers/TessellateModifier.js +3 -3
- package/examples/jsm/nodes/Nodes.js +16 -12
- package/examples/jsm/nodes/accessors/CameraNode.js +18 -2
- package/examples/jsm/nodes/accessors/CubeTextureNode.js +5 -73
- package/examples/jsm/nodes/accessors/InstanceNode.js +3 -3
- package/examples/jsm/nodes/accessors/InstancedPointsMaterialNode.js +21 -0
- package/examples/jsm/nodes/accessors/MaterialNode.js +68 -31
- package/examples/jsm/nodes/accessors/MaterialReferenceNode.js +11 -2
- package/examples/jsm/nodes/accessors/ModelNode.js +1 -2
- package/examples/jsm/nodes/accessors/ModelViewProjectionNode.js +12 -3
- package/examples/jsm/nodes/accessors/MorphNode.js +191 -16
- package/examples/jsm/nodes/accessors/NormalNode.js +1 -1
- package/examples/jsm/nodes/accessors/PositionNode.js +1 -1
- package/examples/jsm/nodes/accessors/ReferenceNode.js +25 -1
- package/examples/jsm/nodes/accessors/SkinningNode.js +13 -3
- package/examples/jsm/nodes/accessors/TextureNode.js +123 -37
- package/examples/jsm/nodes/code/CodeNode.js +3 -3
- package/examples/jsm/nodes/code/FunctionNode.js +1 -1
- package/examples/jsm/nodes/core/AssignNode.js +72 -0
- package/examples/jsm/nodes/core/AttributeNode.js +7 -1
- package/examples/jsm/nodes/core/CacheNode.js +4 -1
- package/examples/jsm/nodes/core/ConstNode.js +1 -1
- package/examples/jsm/nodes/core/LightingModel.js +3 -1
- package/examples/jsm/nodes/core/Node.js +13 -15
- package/examples/jsm/nodes/core/NodeBuilder.js +209 -42
- package/examples/jsm/nodes/core/NodeFrame.js +10 -8
- package/examples/jsm/nodes/core/NodeUniform.js +12 -0
- package/examples/jsm/nodes/core/NodeUtils.js +7 -9
- package/examples/jsm/nodes/core/OutputStructNode.js +4 -4
- package/examples/jsm/nodes/core/ParameterNode.js +33 -0
- package/examples/jsm/nodes/core/PropertyNode.js +15 -6
- package/examples/jsm/nodes/core/StackNode.js +7 -17
- package/examples/jsm/nodes/core/StructTypeNode.js +4 -4
- package/examples/jsm/nodes/core/TempNode.js +1 -1
- package/examples/jsm/nodes/core/UniformGroup.js +13 -0
- package/examples/jsm/nodes/core/UniformGroupNode.js +36 -0
- package/examples/jsm/nodes/core/UniformNode.js +17 -0
- package/examples/jsm/nodes/core/VarNode.js +7 -34
- package/examples/jsm/nodes/core/VaryingNode.js +3 -7
- package/examples/jsm/nodes/display/BumpMapNode.js +35 -13
- package/examples/jsm/nodes/display/ColorAdjustmentNode.js +6 -10
- package/examples/jsm/nodes/display/GaussianBlurNode.js +170 -0
- package/examples/jsm/nodes/display/NormalMapNode.js +3 -1
- package/examples/jsm/nodes/display/PassNode.js +182 -0
- package/examples/jsm/nodes/display/ViewportDepthNode.js +31 -3
- package/examples/jsm/nodes/display/ViewportDepthTextureNode.js +2 -2
- package/examples/jsm/nodes/display/ViewportNode.js +17 -10
- package/examples/jsm/nodes/functions/BSDF/BRDF_Sheen.js +20 -6
- package/examples/jsm/nodes/functions/BSDF/DFGApprox.js +8 -7
- package/examples/jsm/nodes/functions/BSDF/D_GGX.js +8 -3
- package/examples/jsm/nodes/functions/BSDF/Schlick_to_F0.js +8 -0
- package/examples/jsm/nodes/functions/BSDF/V_GGX_SmithCorrelated.js +8 -0
- package/examples/jsm/nodes/functions/PhysicalLightingModel.js +93 -43
- package/examples/jsm/nodes/gpgpu/ComputeNode.js +2 -2
- package/examples/jsm/nodes/lighting/AmbientLightNode.js +1 -1
- package/examples/jsm/nodes/lighting/AnalyticLightNode.js +55 -6
- package/examples/jsm/nodes/lighting/DirectionalLightNode.js +1 -1
- package/examples/jsm/nodes/lighting/EnvironmentNode.js +8 -18
- package/examples/jsm/nodes/lighting/LightingContextNode.js +21 -57
- package/examples/jsm/nodes/lighting/LightsNode.js +80 -20
- package/examples/jsm/nodes/lighting/PointLightNode.js +1 -1
- package/examples/jsm/nodes/lighting/SpotLightNode.js +1 -1
- package/examples/jsm/nodes/materials/InstancedPointsNodeMaterial.js +162 -0
- package/examples/jsm/nodes/materials/Line2NodeMaterial.js +76 -77
- package/examples/jsm/nodes/materials/LineDashedNodeMaterial.js +5 -5
- package/examples/jsm/nodes/materials/Materials.js +1 -0
- package/examples/jsm/nodes/materials/MeshBasicNodeMaterial.js +1 -0
- package/examples/jsm/nodes/materials/MeshNormalNodeMaterial.js +3 -3
- package/examples/jsm/nodes/materials/MeshPhongNodeMaterial.js +3 -3
- package/examples/jsm/nodes/materials/MeshPhysicalNodeMaterial.js +47 -20
- package/examples/jsm/nodes/materials/MeshStandardNodeMaterial.js +6 -6
- package/examples/jsm/nodes/materials/NodeMaterial.js +82 -60
- package/examples/jsm/nodes/materials/PointsNodeMaterial.js +0 -10
- package/examples/jsm/nodes/materials/SpriteNodeMaterial.js +0 -7
- package/examples/jsm/nodes/materialx/MaterialXNodes.js +10 -10
- package/examples/jsm/nodes/materialx/lib/mx_hsv.js +128 -54
- package/examples/jsm/nodes/materialx/lib/mx_noise.js +1430 -618
- package/examples/jsm/nodes/materialx/lib/mx_transform_color.js +24 -14
- package/examples/jsm/nodes/math/MathNode.js +2 -0
- package/examples/jsm/nodes/math/OperatorNode.js +24 -27
- package/examples/jsm/nodes/shadernode/ShaderNode.js +158 -10
- package/examples/jsm/nodes/utils/ArrayElementNode.js +2 -0
- package/examples/jsm/nodes/utils/DiscardNode.js +3 -2
- package/examples/jsm/nodes/utils/FunctionOverloadingNode.js +95 -0
- package/examples/jsm/nodes/utils/JoinNode.js +11 -1
- package/examples/jsm/nodes/utils/LoopNode.js +36 -24
- package/examples/jsm/nodes/utils/RemapNode.js +2 -2
- package/examples/jsm/nodes/utils/SplitNode.js +10 -2
- package/examples/jsm/nodes/utils/TriplanarTexturesNode.js +3 -3
- package/examples/jsm/objects/InstancedPoints.js +21 -0
- package/examples/jsm/objects/Lensflare.js +20 -0
- package/examples/jsm/objects/QuadMesh.js +60 -0
- package/examples/jsm/objects/ReflectorForSSRPass.js +3 -0
- package/examples/jsm/objects/Refractor.js +3 -0
- package/examples/jsm/objects/Sky.js +5 -3
- package/examples/jsm/objects/Water.js +5 -2
- package/examples/jsm/objects/Water2.js +3 -0
- package/examples/jsm/physics/AmmoPhysics.js +21 -0
- package/examples/jsm/physics/RapierPhysics.js +21 -0
- package/examples/jsm/postprocessing/BokehPass.js +3 -2
- package/examples/jsm/postprocessing/GTAOPass.js +572 -0
- package/examples/jsm/postprocessing/LUTPass.js +2 -1
- package/examples/jsm/postprocessing/OutputPass.js +3 -0
- package/examples/jsm/postprocessing/Pass.js +14 -3
- package/examples/jsm/postprocessing/SAOPass.js +0 -1
- package/examples/jsm/postprocessing/SMAAPass.js +0 -2
- package/examples/jsm/postprocessing/TAARenderPass.js +1 -2
- package/examples/jsm/renderers/CSS3DRenderer.js +3 -9
- package/examples/jsm/renderers/SVGRenderer.js +9 -6
- package/examples/jsm/renderers/common/Animation.js +10 -21
- package/examples/jsm/renderers/common/Backend.js +19 -3
- package/examples/jsm/renderers/common/Background.js +20 -22
- package/examples/jsm/renderers/common/Bindings.js +31 -22
- package/examples/jsm/renderers/common/ChainMap.js +3 -3
- package/examples/jsm/renderers/common/Color4.js +37 -0
- package/examples/jsm/renderers/common/Geometries.js +4 -4
- package/examples/jsm/renderers/common/Info.js +12 -2
- package/examples/jsm/renderers/common/Pipelines.js +3 -51
- package/examples/jsm/renderers/common/PostProcessing.js +25 -0
- package/examples/jsm/renderers/common/RenderContext.js +1 -1
- package/examples/jsm/renderers/common/RenderContexts.js +1 -1
- package/examples/jsm/renderers/common/RenderObject.js +21 -2
- package/examples/jsm/renderers/common/RenderObjects.js +5 -3
- package/examples/jsm/renderers/common/Renderer.js +137 -37
- package/examples/jsm/renderers/common/StorageTexture.js +1 -0
- package/examples/jsm/renderers/common/Textures.js +8 -37
- package/examples/jsm/renderers/common/nodes/NodeBuilderState.js +10 -2
- package/examples/jsm/renderers/common/nodes/NodeUniformsGroup.js +44 -0
- package/examples/jsm/renderers/common/nodes/Nodes.js +121 -19
- package/examples/jsm/renderers/webgl/WebGLBackend.js +366 -67
- package/examples/jsm/renderers/webgl/nodes/GLSLNodeBuilder.js +183 -38
- package/examples/jsm/renderers/webgl/utils/WebGLAttributeUtils.js +92 -5
- package/examples/jsm/renderers/webgl/utils/WebGLCapabilities.js +36 -0
- package/examples/jsm/renderers/webgl/utils/WebGLExtensions.js +11 -1
- package/examples/jsm/renderers/webgl/utils/WebGLState.js +14 -2
- package/examples/jsm/renderers/webgl/utils/WebGLTextureUtils.js +71 -2
- package/examples/jsm/renderers/webgl/utils/WebGLUtils.js +42 -0
- package/examples/jsm/renderers/webgl-legacy/nodes/SlotNode.js +1 -1
- package/examples/jsm/renderers/webgl-legacy/nodes/WebGLNodeBuilder.js +33 -3
- package/examples/jsm/renderers/webgl-legacy/nodes/WebGLNodes.js +4 -14
- package/examples/jsm/renderers/webgpu/WebGPUBackend.js +188 -137
- package/examples/jsm/renderers/webgpu/WebGPURenderer.js +1 -1
- package/examples/jsm/renderers/webgpu/nodes/WGSLNodeBuilder.js +241 -90
- package/examples/jsm/renderers/webgpu/utils/WebGPUAttributeUtils.js +15 -10
- package/examples/jsm/renderers/webgpu/utils/WebGPUBindingUtils.js +11 -3
- package/examples/jsm/renderers/webgpu/utils/WebGPUPipelineUtils.js +2 -3
- package/examples/jsm/renderers/webgpu/utils/WebGPUTextureUtils.js +88 -6
- package/examples/jsm/shaders/ACESFilmicToneMappingShader.js +2 -0
- package/examples/jsm/shaders/AfterimageShader.js +2 -0
- package/examples/jsm/shaders/BasicShader.js +2 -0
- package/examples/jsm/shaders/BlendShader.js +2 -0
- package/examples/jsm/shaders/BokehShader.js +2 -0
- package/examples/jsm/shaders/BokehShader2.js +4 -0
- package/examples/jsm/shaders/BrightnessContrastShader.js +2 -0
- package/examples/jsm/shaders/ColorCorrectionShader.js +2 -0
- package/examples/jsm/shaders/DOFMipMapShader.js +2 -0
- package/examples/jsm/shaders/DepthLimitedBlurShader.js +5 -0
- package/examples/jsm/shaders/FXAAShader.js +135 -133
- package/examples/jsm/shaders/FilmShader.js +1 -1
- package/examples/jsm/shaders/FocusShader.js +2 -0
- package/examples/jsm/shaders/FreiChenShader.js +2 -0
- package/examples/jsm/shaders/GTAOShader.js +424 -0
- package/examples/jsm/shaders/GodRaysShader.js +8 -0
- package/examples/jsm/shaders/HalftoneShader.js +2 -0
- package/examples/jsm/shaders/HorizontalTiltShiftShader.js +2 -0
- package/examples/jsm/shaders/HueSaturationShader.js +2 -0
- package/examples/jsm/shaders/KaleidoShader.js +2 -0
- package/examples/jsm/shaders/LuminosityHighPassShader.js +2 -0
- package/examples/jsm/shaders/LuminosityShader.js +2 -0
- package/examples/jsm/shaders/MMDToonShader.js +2 -0
- package/examples/jsm/shaders/MirrorShader.js +2 -0
- package/examples/jsm/shaders/NormalMapShader.js +2 -0
- package/examples/jsm/shaders/OutputShader.js +8 -5
- package/examples/jsm/shaders/PoissonDenoiseShader.js +226 -0
- package/examples/jsm/shaders/SAOShader.js +7 -3
- package/examples/jsm/shaders/SMAAShader.js +6 -0
- package/examples/jsm/shaders/SSAOShader.js +8 -3
- package/examples/jsm/shaders/SSRShader.js +6 -0
- package/examples/jsm/shaders/SobelOperatorShader.js +2 -0
- package/examples/jsm/shaders/SubsurfaceScatteringShader.js +2 -0
- package/examples/jsm/shaders/TechnicolorShader.js +2 -0
- package/examples/jsm/shaders/TriangleBlurShader.js +2 -0
- package/examples/jsm/shaders/UnpackDepthRGBAShader.js +2 -0
- package/examples/jsm/shaders/VelocityShader.js +2 -0
- package/examples/jsm/shaders/VerticalTiltShiftShader.js +2 -0
- package/examples/jsm/shaders/WaterRefractionShader.js +2 -0
- package/examples/jsm/transpiler/AST.js +270 -0
- package/examples/jsm/transpiler/GLSLDecoder.js +941 -0
- package/examples/jsm/transpiler/ShaderToyDecoder.js +49 -0
- package/examples/jsm/transpiler/TSLEncoder.js +715 -0
- package/examples/jsm/transpiler/Transpiler.js +18 -0
- package/examples/jsm/utils/SortUtils.js +158 -0
- package/examples/jsm/utils/TextureUtils.js +33 -21
- package/examples/jsm/webxr/ARButton.js +14 -0
- package/examples/jsm/webxr/VRButton.js +24 -9
- package/examples/jsm/webxr/XRButton.js +27 -11
- package/examples/jsm/webxr/XREstimatedLight.js +1 -1
- package/package.json +8 -6
- package/src/Three.js +1 -0
- package/src/constants.js +8 -1
- package/src/core/BufferAttribute.js +21 -2
- package/src/core/InterleavedBuffer.js +21 -1
- package/src/core/Object3D.js +60 -12
- package/src/core/UniformsGroup.js +7 -1
- package/src/extras/PMREMGenerator.js +7 -1
- package/src/extras/curves/LineCurve3.js +4 -0
- package/src/loaders/AudioLoader.js +1 -1
- package/src/loaders/BufferGeometryLoader.js +0 -7
- package/src/loaders/ImageBitmapLoader.js +25 -1
- package/src/loaders/MaterialLoader.js +10 -2
- package/src/loaders/ObjectLoader.js +49 -0
- package/src/materials/Material.js +27 -13
- package/src/materials/ShaderMaterial.js +2 -1
- package/src/math/Box3.js +35 -18
- package/src/math/ColorManagement.js +0 -16
- package/src/math/Quaternion.js +5 -4
- package/src/math/Sphere.js +2 -0
- package/src/math/Triangle.js +17 -5
- package/src/math/Vector3.js +11 -12
- package/src/objects/BatchedMesh.js +1020 -0
- package/src/objects/Skeleton.js +1 -3
- package/src/objects/SkinnedMesh.js +6 -7
- package/src/renderers/WebGL3DRenderTarget.js +2 -2
- package/src/renderers/WebGLArrayRenderTarget.js +2 -2
- package/src/renderers/WebGLRenderer.js +165 -43
- package/src/renderers/shaders/ShaderChunk/aomap_fragment.glsl.js +8 -0
- package/src/renderers/shaders/ShaderChunk/batching_pars_vertex.glsl.js +19 -0
- package/src/renderers/shaders/ShaderChunk/batching_vertex.glsl.js +5 -0
- package/src/renderers/shaders/ShaderChunk/bumpmap_pars_fragment.glsl.js +3 -2
- package/src/renderers/shaders/ShaderChunk/cube_uv_reflection_fragment.glsl.js +0 -5
- package/src/renderers/shaders/ShaderChunk/defaultnormal_vertex.glsl.js +31 -4
- package/src/renderers/shaders/ShaderChunk/lights_fragment_begin.glsl.js +1 -1
- package/src/renderers/shaders/ShaderChunk/lights_physical_fragment.glsl.js +9 -4
- package/src/renderers/shaders/ShaderChunk/lights_physical_pars_fragment.glsl.js +8 -6
- package/src/renderers/shaders/ShaderChunk/project_vertex.glsl.js +6 -0
- package/src/renderers/shaders/ShaderChunk/skinning_pars_vertex.glsl.js +9 -17
- package/src/renderers/shaders/ShaderChunk/tonemapping_pars_fragment.glsl.js +84 -0
- package/src/renderers/shaders/ShaderChunk/worldpos_vertex.glsl.js +6 -0
- package/src/renderers/shaders/ShaderChunk.js +4 -0
- package/src/renderers/shaders/ShaderLib/depth.glsl.js +2 -0
- package/src/renderers/shaders/ShaderLib/distanceRGBA.glsl.js +2 -0
- package/src/renderers/shaders/ShaderLib/meshbasic.glsl.js +2 -0
- package/src/renderers/shaders/ShaderLib/meshlambert.glsl.js +2 -0
- package/src/renderers/shaders/ShaderLib/meshmatcap.glsl.js +3 -0
- package/src/renderers/shaders/ShaderLib/meshnormal.glsl.js +2 -0
- package/src/renderers/shaders/ShaderLib/meshphong.glsl.js +2 -0
- package/src/renderers/shaders/ShaderLib/meshphysical.glsl.js +4 -2
- package/src/renderers/shaders/ShaderLib/meshtoon.glsl.js +2 -0
- package/src/renderers/shaders/ShaderLib/shadow.glsl.js +3 -0
- package/src/renderers/webgl/WebGLAttributes.js +39 -5
- package/src/renderers/webgl/WebGLBufferRenderer.js +31 -0
- package/src/renderers/webgl/WebGLCubeMaps.js +1 -1
- package/src/renderers/webgl/WebGLExtensions.js +1 -0
- package/src/renderers/webgl/WebGLIndexedBufferRenderer.js +31 -0
- package/src/renderers/webgl/WebGLLights.js +11 -2
- package/src/renderers/webgl/WebGLProgram.js +100 -51
- package/src/renderers/webgl/WebGLPrograms.js +8 -0
- package/src/renderers/webgl/WebGLShadowMap.js +35 -0
- package/src/renderers/webgl/WebGLState.js +25 -4
- package/src/renderers/webgl/WebGLTextures.js +7 -11
- package/src/renderers/webgl/WebGLUniforms.js +11 -1
- package/src/renderers/webgl/WebGLUniformsGroups.js +72 -93
- package/src/renderers/webxr/WebXRManager.js +16 -0
- package/examples/jsm/nodes/accessors/ExtendedMaterialNode.js +0 -76
- package/examples/jsm/nodes/accessors/LineMaterialNode.js +0 -29
|
@@ -2,8 +2,7 @@ import { Material, ShaderMaterial, NoColorSpace, LinearSRGBColorSpace } from 'th
|
|
|
2
2
|
import { getNodeChildren, getCacheKey } from '../core/NodeUtils.js';
|
|
3
3
|
import { attribute } from '../core/AttributeNode.js';
|
|
4
4
|
import { output, diffuseColor } from '../core/PropertyNode.js';
|
|
5
|
-
import { materialNormal } from '../accessors/
|
|
6
|
-
import { materialAlphaTest, materialColor, materialOpacity, materialEmissive } from '../accessors/MaterialNode.js';
|
|
5
|
+
import { materialAlphaTest, materialColor, materialOpacity, materialEmissive, materialNormal } from '../accessors/MaterialNode.js';
|
|
7
6
|
import { modelViewProjection } from '../accessors/ModelViewProjectionNode.js';
|
|
8
7
|
import { transformedNormalView } from '../accessors/NormalNode.js';
|
|
9
8
|
import { instance } from '../accessors/InstanceNode.js';
|
|
@@ -12,12 +11,14 @@ import { skinning } from '../accessors/SkinningNode.js';
|
|
|
12
11
|
import { morph } from '../accessors/MorphNode.js';
|
|
13
12
|
import { texture } from '../accessors/TextureNode.js';
|
|
14
13
|
import { cubeTexture } from '../accessors/CubeTextureNode.js';
|
|
15
|
-
import {
|
|
16
|
-
import { mix
|
|
14
|
+
import { lightNodes } from '../lighting/LightsNode.js';
|
|
15
|
+
import { mix } from '../math/MathNode.js';
|
|
17
16
|
import { float, vec3, vec4 } from '../shadernode/ShaderNode.js';
|
|
18
17
|
import AONode from '../lighting/AONode.js';
|
|
19
18
|
import { lightingContext } from '../lighting/LightingContextNode.js';
|
|
20
19
|
import EnvironmentNode from '../lighting/EnvironmentNode.js';
|
|
20
|
+
import { depthPixel } from '../display/ViewportDepthNode.js';
|
|
21
|
+
import { cameraLogDepth } from '../accessors/CameraNode.js';
|
|
21
22
|
|
|
22
23
|
const NodeMaterials = new Map();
|
|
23
24
|
|
|
@@ -33,12 +34,11 @@ class NodeMaterial extends ShaderMaterial {
|
|
|
33
34
|
|
|
34
35
|
this.forceSinglePass = false;
|
|
35
36
|
|
|
36
|
-
this.unlit = this.constructor === NodeMaterial.prototype.constructor; // Extended materials are not unlit by default
|
|
37
|
-
|
|
38
37
|
this.fog = true;
|
|
39
38
|
this.lights = true;
|
|
40
39
|
this.normals = true;
|
|
41
|
-
|
|
40
|
+
|
|
41
|
+
this.colorSpaced = true;
|
|
42
42
|
|
|
43
43
|
this.lightsNode = null;
|
|
44
44
|
this.envNode = null;
|
|
@@ -52,7 +52,11 @@ class NodeMaterial extends ShaderMaterial {
|
|
|
52
52
|
|
|
53
53
|
this.positionNode = null;
|
|
54
54
|
|
|
55
|
-
this.
|
|
55
|
+
this.depthNode = null;
|
|
56
|
+
|
|
57
|
+
this.outputNode = null;
|
|
58
|
+
|
|
59
|
+
this.fragmentNode = null;
|
|
56
60
|
this.vertexNode = null;
|
|
57
61
|
|
|
58
62
|
}
|
|
@@ -75,7 +79,7 @@ class NodeMaterial extends ShaderMaterial {
|
|
|
75
79
|
|
|
76
80
|
builder.addStack();
|
|
77
81
|
|
|
78
|
-
builder.stack.outputNode = this.setupPosition( builder );
|
|
82
|
+
builder.stack.outputNode = this.vertexNode || this.setupPosition( builder );
|
|
79
83
|
|
|
80
84
|
builder.addFlow( 'vertex', builder.removeStack() );
|
|
81
85
|
|
|
@@ -83,9 +87,11 @@ class NodeMaterial extends ShaderMaterial {
|
|
|
83
87
|
|
|
84
88
|
builder.addStack();
|
|
85
89
|
|
|
86
|
-
let
|
|
90
|
+
let resultNode;
|
|
91
|
+
|
|
92
|
+
if ( this.fragmentNode === null ) {
|
|
87
93
|
|
|
88
|
-
|
|
94
|
+
if ( this.depthWrite === true ) this.setupDepth( builder );
|
|
89
95
|
|
|
90
96
|
if ( this.normals === true ) this.setupNormal( builder );
|
|
91
97
|
|
|
@@ -94,66 +100,95 @@ class NodeMaterial extends ShaderMaterial {
|
|
|
94
100
|
|
|
95
101
|
const outgoingLightNode = this.setupLighting( builder );
|
|
96
102
|
|
|
97
|
-
|
|
103
|
+
resultNode = this.setupOutput( builder, vec4( outgoingLightNode, diffuseColor.a ) );
|
|
98
104
|
|
|
99
105
|
// OUTPUT NODE
|
|
100
106
|
|
|
101
|
-
|
|
107
|
+
output.assign( resultNode );
|
|
102
108
|
|
|
103
109
|
//
|
|
104
110
|
|
|
105
|
-
if ( this.outputNode !== null )
|
|
111
|
+
if ( this.outputNode !== null ) resultNode = this.outputNode;
|
|
106
112
|
|
|
107
113
|
} else {
|
|
108
114
|
|
|
109
|
-
|
|
115
|
+
resultNode = this.setupOutput( builder, this.fragmentNode );
|
|
110
116
|
|
|
111
117
|
}
|
|
112
118
|
|
|
113
|
-
builder.stack.outputNode =
|
|
119
|
+
builder.stack.outputNode = resultNode;
|
|
114
120
|
|
|
115
121
|
builder.addFlow( 'fragment', builder.removeStack() );
|
|
116
122
|
|
|
117
123
|
}
|
|
118
124
|
|
|
125
|
+
setupDepth( builder ) {
|
|
126
|
+
|
|
127
|
+
const { renderer } = builder;
|
|
128
|
+
|
|
129
|
+
// Depth
|
|
130
|
+
|
|
131
|
+
let depthNode = this.depthNode;
|
|
132
|
+
|
|
133
|
+
if ( depthNode === null && renderer.logarithmicDepthBuffer === true ) {
|
|
134
|
+
|
|
135
|
+
const fragDepth = modelViewProjection().w.add( 1 );
|
|
136
|
+
|
|
137
|
+
depthNode = fragDepth.log2().mul( cameraLogDepth ).mul( 0.5 );
|
|
138
|
+
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
if ( depthNode !== null ) {
|
|
142
|
+
|
|
143
|
+
depthPixel.assign( depthNode ).append();
|
|
144
|
+
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
}
|
|
148
|
+
|
|
119
149
|
setupPosition( builder ) {
|
|
120
150
|
|
|
121
|
-
const object = builder
|
|
151
|
+
const { object } = builder;
|
|
122
152
|
const geometry = object.geometry;
|
|
123
153
|
|
|
124
154
|
builder.addStack();
|
|
125
155
|
|
|
156
|
+
// Vertex
|
|
157
|
+
|
|
126
158
|
if ( geometry.morphAttributes.position || geometry.morphAttributes.normal || geometry.morphAttributes.color ) {
|
|
127
159
|
|
|
128
|
-
|
|
160
|
+
morph( object ).append();
|
|
129
161
|
|
|
130
162
|
}
|
|
131
163
|
|
|
132
164
|
if ( object.isSkinnedMesh === true ) {
|
|
133
165
|
|
|
134
|
-
|
|
166
|
+
skinning( object ).append();
|
|
135
167
|
|
|
136
168
|
}
|
|
137
169
|
|
|
138
170
|
if ( ( object.instanceMatrix && object.instanceMatrix.isInstancedBufferAttribute === true ) && builder.isAvailable( 'instance' ) === true ) {
|
|
139
171
|
|
|
140
|
-
|
|
172
|
+
instance( object ).append();
|
|
141
173
|
|
|
142
174
|
}
|
|
143
175
|
|
|
144
176
|
if ( this.positionNode !== null ) {
|
|
145
177
|
|
|
146
|
-
|
|
178
|
+
positionLocal.assign( this.positionNode );
|
|
147
179
|
|
|
148
180
|
}
|
|
149
181
|
|
|
182
|
+
const mvp = modelViewProjection();
|
|
183
|
+
|
|
150
184
|
builder.context.vertex = builder.removeStack();
|
|
185
|
+
builder.context.mvp = mvp;
|
|
151
186
|
|
|
152
|
-
return
|
|
187
|
+
return mvp;
|
|
153
188
|
|
|
154
189
|
}
|
|
155
190
|
|
|
156
|
-
setupDiffuseColor( {
|
|
191
|
+
setupDiffuseColor( { geometry } ) {
|
|
157
192
|
|
|
158
193
|
let colorNode = this.colorNode ? vec4( this.colorNode ) : materialColor;
|
|
159
194
|
|
|
@@ -161,18 +196,18 @@ class NodeMaterial extends ShaderMaterial {
|
|
|
161
196
|
|
|
162
197
|
if ( this.vertexColors === true && geometry.hasAttribute( 'color' ) ) {
|
|
163
198
|
|
|
164
|
-
colorNode = vec4( colorNode.xyz.mul( attribute( 'color' ) ), colorNode.a );
|
|
199
|
+
colorNode = vec4( colorNode.xyz.mul( attribute( 'color', 'vec3' ) ), colorNode.a );
|
|
165
200
|
|
|
166
201
|
}
|
|
167
202
|
|
|
168
203
|
// COLOR
|
|
169
204
|
|
|
170
|
-
|
|
205
|
+
diffuseColor.assign( colorNode );
|
|
171
206
|
|
|
172
207
|
// OPACITY
|
|
173
208
|
|
|
174
209
|
const opacityNode = this.opacityNode ? float( this.opacityNode ) : materialOpacity;
|
|
175
|
-
|
|
210
|
+
diffuseColor.a.assign( diffuseColor.a.mul( opacityNode ) );
|
|
176
211
|
|
|
177
212
|
// ALPHA TEST
|
|
178
213
|
|
|
@@ -180,7 +215,7 @@ class NodeMaterial extends ShaderMaterial {
|
|
|
180
215
|
|
|
181
216
|
const alphaTestNode = this.alphaTestNode !== null ? float( this.alphaTestNode ) : materialAlphaTest;
|
|
182
217
|
|
|
183
|
-
|
|
218
|
+
diffuseColor.a.lessThanEqual( alphaTestNode ).discard();
|
|
184
219
|
|
|
185
220
|
}
|
|
186
221
|
|
|
@@ -192,23 +227,21 @@ class NodeMaterial extends ShaderMaterial {
|
|
|
192
227
|
|
|
193
228
|
}
|
|
194
229
|
|
|
195
|
-
setupNormal(
|
|
230
|
+
setupNormal() {
|
|
196
231
|
|
|
197
232
|
// NORMAL VIEW
|
|
198
233
|
|
|
199
234
|
if ( this.flatShading === true ) {
|
|
200
235
|
|
|
201
|
-
const
|
|
202
|
-
const fdy = dFdy( positionView );
|
|
203
|
-
const normalNode = fdx.cross( fdy ).normalize();
|
|
236
|
+
const normalNode = positionView.dFdx().cross( positionView.dFdy() ).normalize();
|
|
204
237
|
|
|
205
|
-
|
|
238
|
+
transformedNormalView.assign( normalNode );
|
|
206
239
|
|
|
207
240
|
} else {
|
|
208
241
|
|
|
209
242
|
const normalNode = this.normalNode ? vec3( this.normalNode ) : materialNormal;
|
|
210
243
|
|
|
211
|
-
|
|
244
|
+
transformedNormalView.assign( normalNode );
|
|
212
245
|
|
|
213
246
|
}
|
|
214
247
|
|
|
@@ -260,7 +293,7 @@ class NodeMaterial extends ShaderMaterial {
|
|
|
260
293
|
|
|
261
294
|
if ( materialLightsNode.length > 0 ) {
|
|
262
295
|
|
|
263
|
-
lightsNode =
|
|
296
|
+
lightsNode = lightNodes( [ ...lightsNode.lightNodes, ...materialLightsNode ] );
|
|
264
297
|
|
|
265
298
|
}
|
|
266
299
|
|
|
@@ -289,9 +322,9 @@ class NodeMaterial extends ShaderMaterial {
|
|
|
289
322
|
|
|
290
323
|
if ( lightsNode && lightsNode.hasLight !== false ) {
|
|
291
324
|
|
|
292
|
-
const
|
|
325
|
+
const lightingModel = this.setupLightingModel( builder );
|
|
293
326
|
|
|
294
|
-
outgoingLightNode = lightingContext( lightsNode,
|
|
327
|
+
outgoingLightNode = lightingContext( lightsNode, lightingModel, backdropNode, backdropAlphaNode );
|
|
295
328
|
|
|
296
329
|
} else if ( backdropNode !== null ) {
|
|
297
330
|
|
|
@@ -319,7 +352,7 @@ class NodeMaterial extends ShaderMaterial {
|
|
|
319
352
|
|
|
320
353
|
const toneMappingNode = builder.toneMappingNode;
|
|
321
354
|
|
|
322
|
-
if ( toneMappingNode ) {
|
|
355
|
+
if ( this.toneMapped === true && toneMappingNode ) {
|
|
323
356
|
|
|
324
357
|
outputNode = vec4( toneMappingNode.context( { color: outputNode.rgb } ), outputNode.a );
|
|
325
358
|
|
|
@@ -337,29 +370,9 @@ class NodeMaterial extends ShaderMaterial {
|
|
|
337
370
|
|
|
338
371
|
// ENCODING
|
|
339
372
|
|
|
340
|
-
if ( this.
|
|
341
|
-
|
|
342
|
-
const renderTarget = renderer.getRenderTarget();
|
|
343
|
-
|
|
344
|
-
let outputColorSpace;
|
|
345
|
-
|
|
346
|
-
if ( renderTarget !== null ) {
|
|
347
|
-
|
|
348
|
-
if ( Array.isArray( renderTarget.texture ) ) {
|
|
349
|
-
|
|
350
|
-
outputColorSpace = renderTarget.texture[ 0 ].colorSpace;
|
|
351
|
-
|
|
352
|
-
} else {
|
|
353
|
-
|
|
354
|
-
outputColorSpace = renderTarget.texture.colorSpace;
|
|
373
|
+
if ( this.colorSpaced === true ) {
|
|
355
374
|
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
} else {
|
|
359
|
-
|
|
360
|
-
outputColorSpace = renderer.outputColorSpace;
|
|
361
|
-
|
|
362
|
-
}
|
|
375
|
+
const outputColorSpace = renderer.currentColorSpace;
|
|
363
376
|
|
|
364
377
|
if ( outputColorSpace !== LinearSRGBColorSpace && outputColorSpace !== NoColorSpace ) {
|
|
365
378
|
|
|
@@ -482,7 +495,11 @@ class NodeMaterial extends ShaderMaterial {
|
|
|
482
495
|
|
|
483
496
|
this.positionNode = source.positionNode;
|
|
484
497
|
|
|
498
|
+
this.depthNode = source.depthNode;
|
|
499
|
+
|
|
485
500
|
this.outputNode = source.outputNode;
|
|
501
|
+
|
|
502
|
+
this.fragmentNode = source.fragmentNode;
|
|
486
503
|
this.vertexNode = source.vertexNode;
|
|
487
504
|
|
|
488
505
|
return super.copy( source );
|
|
@@ -524,7 +541,12 @@ export default NodeMaterial;
|
|
|
524
541
|
export function addNodeMaterial( type, nodeMaterial ) {
|
|
525
542
|
|
|
526
543
|
if ( typeof nodeMaterial !== 'function' || ! type ) throw new Error( `Node material ${ type } is not a class` );
|
|
527
|
-
if ( NodeMaterials.has( type ) )
|
|
544
|
+
if ( NodeMaterials.has( type ) ) {
|
|
545
|
+
|
|
546
|
+
console.warn( `Redefinition of node material ${ type }` );
|
|
547
|
+
return;
|
|
548
|
+
|
|
549
|
+
}
|
|
528
550
|
|
|
529
551
|
NodeMaterials.set( type, nodeMaterial );
|
|
530
552
|
nodeMaterial.type = type;
|
|
@@ -14,20 +14,10 @@ class PointsNodeMaterial extends NodeMaterial {
|
|
|
14
14
|
|
|
15
15
|
this.lights = false;
|
|
16
16
|
this.normals = false;
|
|
17
|
-
|
|
18
17
|
this.transparent = true;
|
|
19
18
|
|
|
20
|
-
this.colorNode = null;
|
|
21
|
-
this.opacityNode = null;
|
|
22
|
-
|
|
23
|
-
this.alphaTestNode = null;
|
|
24
|
-
|
|
25
|
-
this.lightNode = null;
|
|
26
|
-
|
|
27
19
|
this.sizeNode = null;
|
|
28
20
|
|
|
29
|
-
this.positionNode = null;
|
|
30
|
-
|
|
31
21
|
this.setDefaultValues( defaultValues );
|
|
32
22
|
|
|
33
23
|
this.setValues( parameters );
|
|
@@ -21,13 +21,6 @@ class SpriteNodeMaterial extends NodeMaterial {
|
|
|
21
21
|
this.lights = false;
|
|
22
22
|
this.normals = false;
|
|
23
23
|
|
|
24
|
-
this.colorNode = null;
|
|
25
|
-
this.opacityNode = null;
|
|
26
|
-
|
|
27
|
-
this.alphaTestNode = null;
|
|
28
|
-
|
|
29
|
-
this.lightNode = null;
|
|
30
|
-
|
|
31
24
|
this.positionNode = null;
|
|
32
25
|
this.rotationNode = null;
|
|
33
26
|
this.scaleNode = null;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import {
|
|
2
|
-
mx_perlin_noise_float,
|
|
2
|
+
mx_perlin_noise_float, mx_perlin_noise_vec3,
|
|
3
3
|
mx_worley_noise_float as worley_noise_float, mx_worley_noise_vec2 as worley_noise_vec2, mx_worley_noise_vec3 as worley_noise_vec3,
|
|
4
4
|
mx_cell_noise_float as cell_noise_float,
|
|
5
5
|
mx_fractal_noise_float as fractal_noise_float, mx_fractal_noise_vec2 as fractal_noise_vec2, mx_fractal_noise_vec3 as fractal_noise_vec3, mx_fractal_noise_vec4 as fractal_noise_vec4
|
|
@@ -8,7 +8,7 @@ import { mx_hsvtorgb, mx_rgbtohsv } from './lib/mx_hsv.js';
|
|
|
8
8
|
import { mx_srgb_texture_to_lin_rec709 } from './lib/mx_transform_color.js';
|
|
9
9
|
import { mix, smoothstep } from '../math/MathNode.js';
|
|
10
10
|
import { uv } from '../accessors/UVNode.js';
|
|
11
|
-
import { float, vec2, vec4 } from '../shadernode/ShaderNode.js';
|
|
11
|
+
import { float, vec2, vec4, int } from '../shadernode/ShaderNode.js';
|
|
12
12
|
|
|
13
13
|
export const mx_aastep = ( threshold, value ) => {
|
|
14
14
|
|
|
@@ -42,7 +42,7 @@ export const mx_safepower = ( in1, in2 = 1 ) => {
|
|
|
42
42
|
export const mx_contrast = ( input, amount = 1, pivot = .5 ) => float( input ).sub( pivot ).mul( amount ).add( pivot );
|
|
43
43
|
|
|
44
44
|
export const mx_noise_float = ( texcoord = uv(), amplitude = 1, pivot = 0 ) => mx_perlin_noise_float( texcoord.convert( 'vec2|vec3' ) ).mul( amplitude ).add( pivot );
|
|
45
|
-
export const mx_noise_vec2 = ( texcoord = uv(), amplitude = 1, pivot = 0 ) =>
|
|
45
|
+
//export const mx_noise_vec2 = ( texcoord = uv(), amplitude = 1, pivot = 0 ) => mx_perlin_noise_vec3( texcoord.convert( 'vec2|vec3' ) ).mul( amplitude ).add( pivot );
|
|
46
46
|
export const mx_noise_vec3 = ( texcoord = uv(), amplitude = 1, pivot = 0 ) => mx_perlin_noise_vec3( texcoord.convert( 'vec2|vec3' ) ).mul( amplitude ).add( pivot );
|
|
47
47
|
export const mx_noise_vec4 = ( texcoord = uv(), amplitude = 1, pivot = 0 ) => {
|
|
48
48
|
|
|
@@ -54,15 +54,15 @@ export const mx_noise_vec4 = ( texcoord = uv(), amplitude = 1, pivot = 0 ) => {
|
|
|
54
54
|
|
|
55
55
|
};
|
|
56
56
|
|
|
57
|
-
export const mx_worley_noise_float = ( texcoord = uv(), jitter = 1 ) => worley_noise_float( texcoord.convert( 'vec2|vec3' ), jitter, 1 );
|
|
58
|
-
export const mx_worley_noise_vec2 = ( texcoord = uv(), jitter = 1 ) => worley_noise_vec2( texcoord.convert( 'vec2|vec3' ), jitter, 1 );
|
|
59
|
-
export const mx_worley_noise_vec3 = ( texcoord = uv(), jitter = 1 ) => worley_noise_vec3( texcoord.convert( 'vec2|vec3' ), jitter, 1 );
|
|
57
|
+
export const mx_worley_noise_float = ( texcoord = uv(), jitter = 1 ) => worley_noise_float( texcoord.convert( 'vec2|vec3' ), jitter, int( 1 ) );
|
|
58
|
+
export const mx_worley_noise_vec2 = ( texcoord = uv(), jitter = 1 ) => worley_noise_vec2( texcoord.convert( 'vec2|vec3' ), jitter, int( 1 ) );
|
|
59
|
+
export const mx_worley_noise_vec3 = ( texcoord = uv(), jitter = 1 ) => worley_noise_vec3( texcoord.convert( 'vec2|vec3' ), jitter, int( 1 ) );
|
|
60
60
|
|
|
61
61
|
export const mx_cell_noise_float = ( texcoord = uv() ) => cell_noise_float( texcoord.convert( 'vec2|vec3' ) );
|
|
62
62
|
|
|
63
|
-
export const mx_fractal_noise_float = ( position = uv(), octaves = 3, lacunarity = 2, diminish = .5, amplitude = 1 ) => fractal_noise_float( position, octaves, lacunarity, diminish ).mul( amplitude );
|
|
64
|
-
export const mx_fractal_noise_vec2 = ( position = uv(), octaves = 3, lacunarity = 2, diminish = .5, amplitude = 1 ) => fractal_noise_vec2( position, octaves, lacunarity, diminish ).mul( amplitude );
|
|
65
|
-
export const mx_fractal_noise_vec3 = ( position = uv(), octaves = 3, lacunarity = 2, diminish = .5, amplitude = 1 ) => fractal_noise_vec3( position, octaves, lacunarity, diminish ).mul( amplitude );
|
|
66
|
-
export const mx_fractal_noise_vec4 = ( position = uv(), octaves = 3, lacunarity = 2, diminish = .5, amplitude = 1 ) => fractal_noise_vec4( position, octaves, lacunarity, diminish ).mul( amplitude );
|
|
63
|
+
export const mx_fractal_noise_float = ( position = uv(), octaves = 3, lacunarity = 2, diminish = .5, amplitude = 1 ) => fractal_noise_float( position, int( octaves ), lacunarity, diminish ).mul( amplitude );
|
|
64
|
+
export const mx_fractal_noise_vec2 = ( position = uv(), octaves = 3, lacunarity = 2, diminish = .5, amplitude = 1 ) => fractal_noise_vec2( position, int( octaves ), lacunarity, diminish ).mul( amplitude );
|
|
65
|
+
export const mx_fractal_noise_vec3 = ( position = uv(), octaves = 3, lacunarity = 2, diminish = .5, amplitude = 1 ) => fractal_noise_vec3( position, int( octaves ), lacunarity, diminish ).mul( amplitude );
|
|
66
|
+
export const mx_fractal_noise_vec4 = ( position = uv(), octaves = 3, lacunarity = 2, diminish = .5, amplitude = 1 ) => fractal_noise_vec4( position, int( octaves ), lacunarity, diminish ).mul( amplitude );
|
|
67
67
|
|
|
68
68
|
export { mx_hsvtorgb, mx_rgbtohsv, mx_srgb_texture_to_lin_rec709 };
|
|
@@ -1,56 +1,130 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
// Original shader code from:
|
|
1
|
+
// Three.js Transpiler
|
|
4
2
|
// https://github.com/AcademySoftwareFoundation/MaterialX/blob/main/libraries/stdlib/genglsl/lib/mx_hsv.glsl
|
|
5
3
|
|
|
6
|
-
|
|
7
|
-
{
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
{
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
}
|
|
4
|
+
import { int, float, vec3, If, tslFn } from '../../shadernode/ShaderNode.js';
|
|
5
|
+
import { add, sub, mul } from '../../math/OperatorNode.js';
|
|
6
|
+
import { floor, trunc, max, min } from '../../math/MathNode.js';
|
|
7
|
+
|
|
8
|
+
const mx_hsvtorgb = tslFn( ( [ hsv_immutable ] ) => {
|
|
9
|
+
|
|
10
|
+
const hsv = vec3( hsv_immutable ).toVar();
|
|
11
|
+
const h = float( hsv.x ).toVar();
|
|
12
|
+
const s = float( hsv.y ).toVar();
|
|
13
|
+
const v = float( hsv.z ).toVar();
|
|
14
|
+
|
|
15
|
+
If( s.lessThan( 0.0001 ), () => {
|
|
16
|
+
|
|
17
|
+
return vec3( v, v, v );
|
|
18
|
+
|
|
19
|
+
} ).else( () => {
|
|
20
|
+
|
|
21
|
+
h.assign( mul( 6.0, h.sub( floor( h ) ) ) );
|
|
22
|
+
const hi = int( trunc( h ) ).toVar();
|
|
23
|
+
const f = float( h.sub( float( hi ) ) ).toVar();
|
|
24
|
+
const p = float( v.mul( sub( 1.0, s ) ) ).toVar();
|
|
25
|
+
const q = float( v.mul( sub( 1.0, s.mul( f ) ) ) ).toVar();
|
|
26
|
+
const t = float( v.mul( sub( 1.0, s.mul( sub( 1.0, f ) ) ) ) ).toVar();
|
|
27
|
+
|
|
28
|
+
If( hi.equal( int( 0 ) ), () => {
|
|
29
|
+
|
|
30
|
+
return vec3( v, t, p );
|
|
31
|
+
|
|
32
|
+
} ).elseif( hi.equal( int( 1 ) ), () => {
|
|
33
|
+
|
|
34
|
+
return vec3( q, v, p );
|
|
35
|
+
|
|
36
|
+
} ).elseif( hi.equal( int( 2 ) ), () => {
|
|
37
|
+
|
|
38
|
+
return vec3( p, v, t );
|
|
39
|
+
|
|
40
|
+
} ).elseif( hi.equal( int( 3 ) ), () => {
|
|
41
|
+
|
|
42
|
+
return vec3( p, q, v );
|
|
43
|
+
|
|
44
|
+
} ).elseif( hi.equal( int( 4 ) ), () => {
|
|
45
|
+
|
|
46
|
+
return vec3( t, p, v );
|
|
47
|
+
|
|
48
|
+
} );
|
|
49
|
+
|
|
50
|
+
return vec3( v, p, q );
|
|
51
|
+
|
|
52
|
+
} );
|
|
53
|
+
|
|
54
|
+
} );
|
|
55
|
+
|
|
56
|
+
const mx_rgbtohsv = tslFn( ( [ c_immutable ] ) => {
|
|
57
|
+
|
|
58
|
+
const c = vec3( c_immutable ).toVar();
|
|
59
|
+
const r = float( c.x ).toVar();
|
|
60
|
+
const g = float( c.y ).toVar();
|
|
61
|
+
const b = float( c.z ).toVar();
|
|
62
|
+
const mincomp = float( min( r, min( g, b ) ) ).toVar();
|
|
63
|
+
const maxcomp = float( max( r, max( g, b ) ) ).toVar();
|
|
64
|
+
const delta = float( maxcomp.sub( mincomp ) ).toVar();
|
|
65
|
+
const h = float().toVar(), s = float().toVar(), v = float().toVar();
|
|
66
|
+
v.assign( maxcomp );
|
|
67
|
+
|
|
68
|
+
If( maxcomp.greaterThan( 0.0 ), () => {
|
|
69
|
+
|
|
70
|
+
s.assign( delta.div( maxcomp ) );
|
|
71
|
+
|
|
72
|
+
} ).else( () => {
|
|
73
|
+
|
|
74
|
+
s.assign( 0.0 );
|
|
75
|
+
|
|
76
|
+
} );
|
|
77
|
+
|
|
78
|
+
If( s.lessThanEqual( 0.0 ), () => {
|
|
79
|
+
|
|
80
|
+
h.assign( 0.0 );
|
|
81
|
+
|
|
82
|
+
} ).else( () => {
|
|
83
|
+
|
|
84
|
+
If( r.greaterThanEqual( maxcomp ), () => {
|
|
85
|
+
|
|
86
|
+
h.assign( g.sub( b ).div( delta ) );
|
|
87
|
+
|
|
88
|
+
} ).elseif( g.greaterThanEqual( maxcomp ), () => {
|
|
89
|
+
|
|
90
|
+
h.assign( add( 2.0, b.sub( r ).div( delta ) ) );
|
|
91
|
+
|
|
92
|
+
} ).else( () => {
|
|
93
|
+
|
|
94
|
+
h.assign( add( 4.0, r.sub( g ).div( delta ) ) );
|
|
95
|
+
|
|
96
|
+
} );
|
|
97
|
+
|
|
98
|
+
h.mulAssign( 1.0 / 6.0 );
|
|
99
|
+
|
|
100
|
+
If( h.lessThan( 0.0 ), () => {
|
|
101
|
+
|
|
102
|
+
h.addAssign( 1.0 );
|
|
103
|
+
|
|
104
|
+
} );
|
|
105
|
+
|
|
106
|
+
} );
|
|
107
|
+
|
|
108
|
+
return vec3( h, s, v );
|
|
109
|
+
|
|
110
|
+
} );
|
|
111
|
+
|
|
112
|
+
// layouts
|
|
113
|
+
|
|
114
|
+
mx_hsvtorgb.setLayout( {
|
|
115
|
+
name: 'mx_hsvtorgb',
|
|
116
|
+
type: 'vec3',
|
|
117
|
+
inputs: [
|
|
118
|
+
{ name: 'hsv', type: 'vec3' }
|
|
119
|
+
]
|
|
120
|
+
} );
|
|
121
|
+
|
|
122
|
+
mx_rgbtohsv.setLayout( {
|
|
123
|
+
name: 'mx_rgbtohsv',
|
|
124
|
+
type: 'vec3',
|
|
125
|
+
inputs: [
|
|
126
|
+
{ name: 'c', type: 'vec3' }
|
|
127
|
+
]
|
|
128
|
+
} );
|
|
129
|
+
|
|
130
|
+
export { mx_hsvtorgb, mx_rgbtohsv };
|