three-stdlib 2.7.0 → 2.8.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/{Nodes-ec4e1143.js → Nodes-894ac9dc.js} +0 -0
- package/{Nodes-427f68b0.js → Nodes-af575af7.js} +0 -0
- package/cameras/CinematicCamera.cjs.js +1 -1
- package/cameras/CinematicCamera.js +3 -8
- package/controls/ArcballControls.cjs.js +1 -1
- package/controls/ArcballControls.d.ts +6 -9
- package/controls/ArcballControls.js +188 -234
- package/controls/FirstPersonControls.cjs.js +1 -1
- package/controls/FirstPersonControls.d.ts +4 -5
- package/controls/FirstPersonControls.js +36 -45
- package/controls/TransformControls.cjs.js +1 -1
- package/controls/TransformControls.d.ts +2 -1
- package/controls/TransformControls.js +25 -26
- package/exporters/GLTFExporter.cjs.js +1 -1
- package/exporters/GLTFExporter.js +9 -18
- package/geometries/TeapotGeometry.js +2 -2
- package/index.cjs.js +1 -1
- package/loaders/EXRLoader.cjs.js +1 -1
- package/loaders/EXRLoader.js +21 -10
- package/loaders/GLTFLoader.cjs.js +1 -1
- package/loaders/GLTFLoader.js +5 -6
- package/loaders/HDRCubeTextureLoader.cjs.js +1 -1
- package/loaders/HDRCubeTextureLoader.js +1 -3
- package/loaders/LDrawLoader.cjs.js +1 -1
- package/loaders/LDrawLoader.js +1450 -1105
- package/loaders/LUT3dlLoader.cjs.js +1 -1
- package/loaders/LUT3dlLoader.js +18 -11
- package/loaders/LUTCubeLoader.cjs.js +1 -1
- package/loaders/LUTCubeLoader.js +4 -5
- package/loaders/NodeMaterialLoader.cjs.js +1 -1
- package/loaders/PCDLoader.cjs.js +1 -1
- package/loaders/PCDLoader.js +2 -2
- package/loaders/RGBELoader.cjs.js +1 -1
- package/loaders/RGBELoader.js +6 -6
- package/loaders/STLLoader.js +7 -7
- package/loaders/VRMLLoader.cjs.js +1 -1
- package/loaders/VRMLLoader.js +10 -18
- package/modifiers/CurveModifier.cjs.js +1 -1
- package/modifiers/CurveModifier.js +9 -8
- package/nodes/accessors/CameraNode.js +12 -12
- package/nodes/accessors/PositionNode.js +3 -3
- package/nodes/accessors/ReflectNode.js +3 -3
- package/nodes/core/FunctionNode.js +3 -3
- package/nodes/core/InputNode.js +3 -3
- package/nodes/core/Node.js +6 -6
- package/nodes/core/TempNode.js +6 -6
- package/nodes/effects/BlurNode.js +3 -3
- package/nodes/math/MathNode.js +3 -3
- package/nodes/utils/VelocityNode.js +6 -6
- package/objects/Lensflare.cjs.js +1 -1
- package/objects/Lensflare.js +3 -11
- package/objects/Reflector.cjs.js +1 -1
- package/objects/Reflector.js +16 -12
- package/objects/ReflectorForSSRPass.cjs.js +1 -1
- package/objects/ReflectorForSSRPass.js +1 -9
- package/objects/Refractor.cjs.js +1 -1
- package/objects/Refractor.js +7 -12
- package/objects/Water.cjs.js +1 -1
- package/objects/Water.js +5 -16
- package/package.json +2 -2
- package/postprocessing/GlitchPass.cjs.js +1 -1
- package/postprocessing/GlitchPass.js +36 -33
- package/postprocessing/SMAAPass.cjs.js +1 -1
- package/postprocessing/SMAAPass.js +93 -96
- package/postprocessing/SSAOPass.cjs.js +1 -1
- package/postprocessing/SSAOPass.js +151 -152
- package/postprocessing/SavePass.cjs.js +1 -1
- package/postprocessing/SavePass.js +27 -28
- package/renderers/nodes/accessors/UVNode.js +1 -3
- package/renderers/nodes/core/AttributeNode.js +1 -3
- package/renderers/nodes/core/Node.js +4 -12
- package/renderers/nodes/core/NodeBuilder.js +6 -18
- package/renderers/webgpu/WebGPUTextures.cjs.js +1 -1
- package/renderers/webgpu/WebGPUTextures.js +1 -2
- package/utils/LDrawUtils.cjs.js +1 -0
- package/utils/LDrawUtils.js +144 -0
- package/webxr/ARButton.js +6 -6
- package/webxr/VRButton.js +6 -6
@@ -47,9 +47,9 @@ CameraNode.prototype.setScope = function (scope) {
|
|
47
47
|
}
|
48
48
|
};
|
49
49
|
|
50
|
-
CameraNode.prototype.getType = function
|
51
|
-
/* builder */
|
52
|
-
{
|
50
|
+
CameraNode.prototype.getType = function
|
51
|
+
/* builder */
|
52
|
+
() {
|
53
53
|
switch (this.scope) {
|
54
54
|
case CameraNode.DEPTH:
|
55
55
|
return 'f';
|
@@ -58,9 +58,9 @@ CameraNode.prototype.getType = function ()
|
|
58
58
|
return this.type;
|
59
59
|
};
|
60
60
|
|
61
|
-
CameraNode.prototype.getUnique = function
|
62
|
-
/* builder */
|
63
|
-
{
|
61
|
+
CameraNode.prototype.getUnique = function
|
62
|
+
/* builder */
|
63
|
+
() {
|
64
64
|
switch (this.scope) {
|
65
65
|
case CameraNode.DEPTH:
|
66
66
|
case CameraNode.TO_VERTEX:
|
@@ -70,9 +70,9 @@ CameraNode.prototype.getUnique = function ()
|
|
70
70
|
return false;
|
71
71
|
};
|
72
72
|
|
73
|
-
CameraNode.prototype.getShared = function
|
74
|
-
/* builder */
|
75
|
-
{
|
73
|
+
CameraNode.prototype.getShared = function
|
74
|
+
/* builder */
|
75
|
+
() {
|
76
76
|
switch (this.scope) {
|
77
77
|
case CameraNode.POSITION:
|
78
78
|
return false;
|
@@ -102,9 +102,9 @@ CameraNode.prototype.generate = function (builder, output) {
|
|
102
102
|
return builder.format(result, this.getType(builder), output);
|
103
103
|
};
|
104
104
|
|
105
|
-
CameraNode.prototype.onUpdateFrame = function
|
106
|
-
/* frame */
|
107
|
-
{
|
105
|
+
CameraNode.prototype.onUpdateFrame = function
|
106
|
+
/* frame */
|
107
|
+
() {
|
108
108
|
switch (this.scope) {
|
109
109
|
case CameraNode.DEPTH:
|
110
110
|
var camera = this.camera;
|
@@ -23,9 +23,9 @@ PositionNode.prototype.getType = function () {
|
|
23
23
|
return this.type;
|
24
24
|
};
|
25
25
|
|
26
|
-
PositionNode.prototype.getShared = function
|
27
|
-
/* builder */
|
28
|
-
{
|
26
|
+
PositionNode.prototype.getShared = function
|
27
|
+
/* builder */
|
28
|
+
() {
|
29
29
|
switch (this.scope) {
|
30
30
|
case PositionNode.LOCAL:
|
31
31
|
case PositionNode.WORLD:
|
@@ -18,9 +18,9 @@ ReflectNode.prototype.getUnique = function (builder) {
|
|
18
18
|
return !builder.context.viewNormal;
|
19
19
|
};
|
20
20
|
|
21
|
-
ReflectNode.prototype.getType = function
|
22
|
-
/* builder */
|
23
|
-
{
|
21
|
+
ReflectNode.prototype.getType = function
|
22
|
+
/* builder */
|
23
|
+
() {
|
24
24
|
switch (this.scope) {
|
25
25
|
case ReflectNode.SPHERE:
|
26
26
|
return 'v2';
|
@@ -16,9 +16,9 @@ FunctionNode.prototype.constructor = FunctionNode;
|
|
16
16
|
FunctionNode.prototype.nodeType = 'Function';
|
17
17
|
FunctionNode.prototype.useKeywords = true;
|
18
18
|
|
19
|
-
FunctionNode.prototype.getShared = function
|
20
|
-
/* builder, output */
|
21
|
-
{
|
19
|
+
FunctionNode.prototype.getShared = function
|
20
|
+
/* builder, output */
|
21
|
+
() {
|
22
22
|
return !this.isMethod;
|
23
23
|
};
|
24
24
|
|
package/nodes/core/InputNode.js
CHANGED
@@ -16,9 +16,9 @@ InputNode.prototype.setReadonly = function (value) {
|
|
16
16
|
return this;
|
17
17
|
};
|
18
18
|
|
19
|
-
InputNode.prototype.getReadonly = function
|
20
|
-
/* builder */
|
21
|
-
{
|
19
|
+
InputNode.prototype.getReadonly = function
|
20
|
+
/* builder */
|
21
|
+
() {
|
22
22
|
return this.readonly;
|
23
23
|
};
|
24
24
|
|
package/nodes/core/Node.js
CHANGED
@@ -53,9 +53,9 @@ Node.prototype = {
|
|
53
53
|
|
54
54
|
return this.generate(builder, output, uuid);
|
55
55
|
},
|
56
|
-
generate: function
|
57
|
-
|
58
|
-
{// This method needs to be implemented in subclasses
|
56
|
+
generate: function
|
57
|
+
/* builder, output, uuid, type, ns */
|
58
|
+
() {// This method needs to be implemented in subclasses
|
59
59
|
},
|
60
60
|
getHash: function () {
|
61
61
|
var hash = '{';
|
@@ -93,9 +93,9 @@ Node.prototype = {
|
|
93
93
|
this.name = name;
|
94
94
|
return this;
|
95
95
|
},
|
96
|
-
getName: function
|
97
|
-
|
98
|
-
{
|
96
|
+
getName: function
|
97
|
+
/* builder */
|
98
|
+
() {
|
99
99
|
return this.name;
|
100
100
|
},
|
101
101
|
getType: function (builder, output) {
|
package/nodes/core/TempNode.js
CHANGED
@@ -59,9 +59,9 @@ TempNode.prototype.getShared = function (builder, output) {
|
|
59
59
|
return output !== 'sampler2D' && output !== 'samplerCube' && this.shared;
|
60
60
|
};
|
61
61
|
|
62
|
-
TempNode.prototype.getUnique = function
|
63
|
-
/* builder, output */
|
64
|
-
{
|
62
|
+
TempNode.prototype.getUnique = function
|
63
|
+
/* builder, output */
|
64
|
+
() {
|
65
65
|
return this.unique;
|
66
66
|
};
|
67
67
|
|
@@ -70,9 +70,9 @@ TempNode.prototype.setLabel = function (name) {
|
|
70
70
|
return this;
|
71
71
|
};
|
72
72
|
|
73
|
-
TempNode.prototype.getLabel = function
|
74
|
-
/* builder */
|
75
|
-
{
|
73
|
+
TempNode.prototype.getLabel = function
|
74
|
+
/* builder */
|
75
|
+
() {
|
76
76
|
return this.label;
|
77
77
|
};
|
78
78
|
|
@@ -31,9 +31,9 @@ BlurNode.prototype.constructor = BlurNode;
|
|
31
31
|
BlurNode.prototype.nodeType = 'Blur';
|
32
32
|
BlurNode.prototype.hashProperties = ['blurX', 'blurY'];
|
33
33
|
|
34
|
-
BlurNode.prototype.updateFrame = function
|
35
|
-
/* frame */
|
36
|
-
{
|
34
|
+
BlurNode.prototype.updateFrame = function
|
35
|
+
/* frame */
|
36
|
+
() {
|
37
37
|
if (this.size) {
|
38
38
|
this.horizontal.value = this.radius.x / this.size.x;
|
39
39
|
this.vertical.value = this.radius.y / this.size.y;
|
package/nodes/math/MathNode.js
CHANGED
@@ -54,9 +54,9 @@ MathNode.prototype.constructor = MathNode;
|
|
54
54
|
MathNode.prototype.nodeType = 'Math';
|
55
55
|
MathNode.prototype.hashProperties = ['method'];
|
56
56
|
|
57
|
-
MathNode.prototype.getNumInputs = function
|
58
|
-
/*builder*/
|
59
|
-
{
|
57
|
+
MathNode.prototype.getNumInputs = function
|
58
|
+
/*builder*/
|
59
|
+
() {
|
60
60
|
switch (this.method) {
|
61
61
|
case MathNode.MIX:
|
62
62
|
case MathNode.CLAMP:
|
@@ -13,9 +13,9 @@ VelocityNode.prototype = Object.create(Vector3Node.prototype);
|
|
13
13
|
VelocityNode.prototype.constructor = VelocityNode;
|
14
14
|
VelocityNode.prototype.nodeType = 'Velocity';
|
15
15
|
|
16
|
-
VelocityNode.prototype.getReadonly = function
|
17
|
-
/*builder*/
|
18
|
-
{
|
16
|
+
VelocityNode.prototype.getReadonly = function
|
17
|
+
/*builder*/
|
18
|
+
() {
|
19
19
|
return false;
|
20
20
|
};
|
21
21
|
|
@@ -55,9 +55,9 @@ VelocityNode.prototype.setTarget = function (target) {
|
|
55
55
|
}
|
56
56
|
};
|
57
57
|
|
58
|
-
VelocityNode.prototype.updateFrameVelocity = function
|
59
|
-
/*frame*/
|
60
|
-
{
|
58
|
+
VelocityNode.prototype.updateFrameVelocity = function
|
59
|
+
/*frame*/
|
60
|
+
() {
|
61
61
|
if (this.target) {
|
62
62
|
this.position = this.target.getWorldPosition(this.position || new Vector3());
|
63
63
|
this.velocity.subVectors(this.position, this.oldPosition);
|
package/objects/Lensflare.cjs.js
CHANGED
@@ -1 +1 @@
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("three");class e extends t.Mesh{constructor(){super(e.Geometry,new t.MeshBasicMaterial({opacity:0,transparent:!0})),this.type="Lensflare",this.frustumCulled=!1,this.renderOrder=1/0;const i=new t.Vector3,r=new t.Vector3,o=new t.
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("three");class e extends t.Mesh{constructor(){super(e.Geometry,new t.MeshBasicMaterial({opacity:0,transparent:!0})),this.type="Lensflare",this.frustumCulled=!1,this.renderOrder=1/0;const i=new t.Vector3,r=new t.Vector3,o=new t.FramebufferTexture(16,16,t.RGBAFormat),s=new t.FramebufferTexture(16,16,t.RGBAFormat),a=e.Geometry,l=new t.RawShaderMaterial({uniforms:{scale:{value:null},screenPosition:{value:null}},vertexShader:"\n\n\t\t\t\tprecision highp float;\n\n\t\t\t\tuniform vec3 screenPosition;\n\t\t\t\tuniform vec2 scale;\n\n\t\t\t\tattribute vec3 position;\n\n\t\t\t\tvoid main() {\n\n\t\t\t\t\tgl_Position = vec4( position.xy * scale + screenPosition.xy, screenPosition.z, 1.0 );\n\n\t\t\t\t}",fragmentShader:"\n\n\t\t\t\tprecision highp float;\n\n\t\t\t\tvoid main() {\n\n\t\t\t\t\tgl_FragColor = vec4( 1.0, 0.0, 1.0, 1.0 );\n\n\t\t\t\t}",depthTest:!0,depthWrite:!1,transparent:!1}),c=new t.RawShaderMaterial({uniforms:{map:{value:o},scale:{value:null},screenPosition:{value:null}},vertexShader:"\n\n\t\t\t\tprecision highp float;\n\n\t\t\t\tuniform vec3 screenPosition;\n\t\t\t\tuniform vec2 scale;\n\n\t\t\t\tattribute vec3 position;\n\t\t\t\tattribute vec2 uv;\n\n\t\t\t\tvarying vec2 vUV;\n\n\t\t\t\tvoid main() {\n\n\t\t\t\t\tvUV = uv;\n\n\t\t\t\t\tgl_Position = vec4( position.xy * scale + screenPosition.xy, screenPosition.z, 1.0 );\n\n\t\t\t\t}",fragmentShader:"\n\n\t\t\t\tprecision highp float;\n\n\t\t\t\tuniform sampler2D map;\n\n\t\t\t\tvarying vec2 vUV;\n\n\t\t\t\tvoid main() {\n\n\t\t\t\t\tgl_FragColor = texture2D( map, vUV );\n\n\t\t\t\t}",depthTest:!1,depthWrite:!1,transparent:!1}),u=new t.Mesh(a,l),v=[],p=n.Shader,f=new t.RawShaderMaterial({uniforms:{map:{value:null},occlusionMap:{value:s},color:{value:new t.Color(16777215)},scale:{value:new t.Vector2},screenPosition:{value:new t.Vector3}},vertexShader:p.vertexShader,fragmentShader:p.fragmentShader,blending:t.AdditiveBlending,transparent:!0,depthWrite:!1}),d=new t.Mesh(a,f);this.addElement=function(t){v.push(t)};const m=new t.Vector2,x=new t.Vector2,y=new t.Box2,h=new t.Vector4;this.onBeforeRender=function(t,e,n){t.getCurrentViewport(h);const p=h.w/h.z,b=h.z/2,g=h.w/2;let w=16/h.w;if(m.set(w*p,w),y.min.set(h.x,h.y),y.max.set(h.x+(h.z-16),h.y+(h.w-16)),r.setFromMatrixPosition(this.matrixWorld),r.applyMatrix4(n.matrixWorldInverse),!(r.z>0)&&(i.copy(r).applyMatrix4(n.projectionMatrix),x.x=h.x+i.x*b+b-8,x.y=h.y+i.y*g+g-8,y.containsPoint(x))){t.copyFramebufferToTexture(x,o);let e=l.uniforms;e.scale.value=m,e.screenPosition.value=i,t.renderBufferDirect(n,null,a,l,u,null),t.copyFramebufferToTexture(x,s),e=c.uniforms,e.scale.value=m,e.screenPosition.value=i,t.renderBufferDirect(n,null,a,c,u,null);const r=2*-i.x,p=2*-i.y;for(let e=0,o=v.length;e<o;e++){const o=v[e],s=f.uniforms;s.color.value.copy(o.color),s.map.value=o.texture,s.screenPosition.value.x=i.x+r*o.distance,s.screenPosition.value.y=i.y+p*o.distance,w=o.size/h.w;const l=h.w/h.z;s.scale.value.set(w*l,w),f.uniformsNeedUpdate=!0,t.renderBufferDirect(n,null,a,f,d,null)}}},this.dispose=function(){l.dispose(),c.dispose(),f.dispose(),o.dispose(),s.dispose();for(let t=0,e=v.length;t<e;t++)v[t].texture.dispose()}}}e.prototype.isLensflare=!0;class n{constructor(e,n=1,i=0,r=new t.Color(16777215)){this.texture=e,this.size=n,this.distance=i,this.color=r}}n.Shader={uniforms:{map:{value:null},occlusionMap:{value:null},color:{value:null},scale:{value:null},screenPosition:{value:null}},vertexShader:"\n\n\t\tprecision highp float;\n\n\t\tuniform vec3 screenPosition;\n\t\tuniform vec2 scale;\n\n\t\tuniform sampler2D occlusionMap;\n\n\t\tattribute vec3 position;\n\t\tattribute vec2 uv;\n\n\t\tvarying vec2 vUV;\n\t\tvarying float vVisibility;\n\n\t\tvoid main() {\n\n\t\t\tvUV = uv;\n\n\t\t\tvec2 pos = position.xy;\n\n\t\t\tvec4 visibility = texture2D( occlusionMap, vec2( 0.1, 0.1 ) );\n\t\t\tvisibility += texture2D( occlusionMap, vec2( 0.5, 0.1 ) );\n\t\t\tvisibility += texture2D( occlusionMap, vec2( 0.9, 0.1 ) );\n\t\t\tvisibility += texture2D( occlusionMap, vec2( 0.9, 0.5 ) );\n\t\t\tvisibility += texture2D( occlusionMap, vec2( 0.9, 0.9 ) );\n\t\t\tvisibility += texture2D( occlusionMap, vec2( 0.5, 0.9 ) );\n\t\t\tvisibility += texture2D( occlusionMap, vec2( 0.1, 0.9 ) );\n\t\t\tvisibility += texture2D( occlusionMap, vec2( 0.1, 0.5 ) );\n\t\t\tvisibility += texture2D( occlusionMap, vec2( 0.5, 0.5 ) );\n\n\t\t\tvVisibility = visibility.r / 9.0;\n\t\t\tvVisibility *= 1.0 - visibility.g / 9.0;\n\t\t\tvVisibility *= visibility.b / 9.0;\n\n\t\t\tgl_Position = vec4( ( pos * scale + screenPosition.xy ).xy, screenPosition.z, 1.0 );\n\n\t\t}",fragmentShader:"\n\n\t\tprecision highp float;\n\n\t\tuniform sampler2D map;\n\t\tuniform vec3 color;\n\n\t\tvarying vec2 vUV;\n\t\tvarying float vVisibility;\n\n\t\tvoid main() {\n\n\t\t\tvec4 texture = texture2D( map, vUV );\n\t\t\ttexture.a *= vVisibility;\n\t\t\tgl_FragColor = texture;\n\t\t\tgl_FragColor.rgb *= color;\n\n\t\t}"},e.Geometry=function(){const e=new t.BufferGeometry,n=new Float32Array([-1,-1,0,0,0,1,-1,0,1,0,1,1,0,1,1,-1,1,0,0,1]),i=new t.InterleavedBuffer(n,5);return e.setIndex([0,1,2,0,2,3]),e.setAttribute("position",new t.InterleavedBufferAttribute(i,3,0,!1)),e.setAttribute("uv",new t.InterleavedBufferAttribute(i,2,3,!1)),e}(),exports.Lensflare=e,exports.LensflareElement=n;
|
package/objects/Lensflare.js
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
import { Mesh, MeshBasicMaterial, Vector3,
|
1
|
+
import { Mesh, MeshBasicMaterial, Vector3, FramebufferTexture, RGBAFormat, RawShaderMaterial, Color, Vector2, AdditiveBlending, Box2, Vector4, BufferGeometry, InterleavedBuffer, InterleavedBufferAttribute } from 'three';
|
2
2
|
|
3
3
|
class Lensflare extends Mesh {
|
4
4
|
constructor() {
|
@@ -13,16 +13,8 @@ class Lensflare extends Mesh {
|
|
13
13
|
const positionScreen = new Vector3();
|
14
14
|
const positionView = new Vector3(); // textures
|
15
15
|
|
16
|
-
const tempMap = new
|
17
|
-
|
18
|
-
tempMap.magFilter = NearestFilter;
|
19
|
-
tempMap.wrapS = ClampToEdgeWrapping;
|
20
|
-
tempMap.wrapT = ClampToEdgeWrapping;
|
21
|
-
const occlusionMap = new DataTexture(new Uint8Array(16 * 16 * 3), 16, 16, RGBFormat);
|
22
|
-
occlusionMap.minFilter = NearestFilter;
|
23
|
-
occlusionMap.magFilter = NearestFilter;
|
24
|
-
occlusionMap.wrapS = ClampToEdgeWrapping;
|
25
|
-
occlusionMap.wrapT = ClampToEdgeWrapping; // material
|
16
|
+
const tempMap = new FramebufferTexture(16, 16, RGBAFormat);
|
17
|
+
const occlusionMap = new FramebufferTexture(16, 16, RGBAFormat); // material
|
26
18
|
|
27
19
|
const geometry = Lensflare.Geometry;
|
28
20
|
const material1a = new RawShaderMaterial({
|
package/objects/Reflector.cjs.js
CHANGED
@@ -1 +1 @@
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("three");class t extends e.Mesh{constructor(r,n={}){super(r),this.type="Reflector";const a=this,o=void 0!==n.color?new e.Color(n.color):new e.Color(8355711),
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("three");class t extends e.Mesh{constructor(r,n={}){super(r),this.type="Reflector";const a=this,o=void 0!==n.color?new e.Color(n.color):new e.Color(8355711),l=n.textureWidth||512,i=n.textureHeight||512,s=n.clipBias||0,d=n.shader||t.ReflectorShader,c=new e.Plane,u=new e.Vector3,p=new e.Vector3,m=new e.Vector3,x=new e.Matrix4,v=new e.Vector3(0,0,-1),f=new e.Vector4,b=new e.Vector3,g=new e.Vector3,h=new e.Vector4,M=new e.Matrix4,y=new e.PerspectiveCamera,w=new e.WebGLRenderTarget(l,i),R=new e.ShaderMaterial({uniforms:e.UniformsUtils.clone(d.uniforms),fragmentShader:d.fragmentShader,vertexShader:d.vertexShader});R.uniforms.tDiffuse.value=w.texture,R.uniforms.color.value=o,R.uniforms.textureMatrix.value=M,this.material=R,this.onBeforeRender=function(e,t,r){if(p.setFromMatrixPosition(a.matrixWorld),m.setFromMatrixPosition(r.matrixWorld),x.extractRotation(a.matrixWorld),u.set(0,0,1),u.applyMatrix4(x),b.subVectors(p,m),b.dot(u)>0)return;b.reflect(u).negate(),b.add(p),x.extractRotation(r.matrixWorld),v.set(0,0,-1),v.applyMatrix4(x),v.add(m),g.subVectors(p,v),g.reflect(u).negate(),g.add(p),y.position.copy(b),y.up.set(0,1,0),y.up.applyMatrix4(x),y.up.reflect(u),y.lookAt(g),y.far=r.far,y.updateMatrixWorld(),y.projectionMatrix.copy(r.projectionMatrix),M.set(.5,0,0,.5,0,.5,0,.5,0,0,.5,.5,0,0,0,1),M.multiply(y.projectionMatrix),M.multiply(y.matrixWorldInverse),M.multiply(a.matrixWorld),c.setFromNormalAndCoplanarPoint(u,p),c.applyMatrix4(y.matrixWorldInverse),f.set(c.normal.x,c.normal.y,c.normal.z,c.constant);const n=y.projectionMatrix;h.x=(Math.sign(f.x)+n.elements[8])/n.elements[0],h.y=(Math.sign(f.y)+n.elements[9])/n.elements[5],h.z=-1,h.w=(1+n.elements[10])/n.elements[14],f.multiplyScalar(2/f.dot(h)),n.elements[2]=f.x,n.elements[6]=f.y,n.elements[10]=f.z+1-s,n.elements[14]=f.w,w.texture.encoding=e.outputEncoding,a.visible=!1;const o=e.getRenderTarget(),l=e.xr.enabled,i=e.shadowMap.autoUpdate;e.xr.enabled=!1,e.shadowMap.autoUpdate=!1,e.setRenderTarget(w),e.state.buffers.depth.setMask(!0),!1===e.autoClear&&e.clear(),e.render(t,y),e.xr.enabled=l,e.shadowMap.autoUpdate=i,e.setRenderTarget(o);const d=r.viewport;void 0!==d&&e.state.viewport(d),a.visible=!0},this.getRenderTarget=function(){return w},this.dispose=function(){w.dispose(),a.material.dispose()}}}t.prototype.isReflector=!0,t.ReflectorShader={uniforms:{color:{value:null},tDiffuse:{value:null},textureMatrix:{value:null}},vertexShader:"\n\t\tuniform mat4 textureMatrix;\n\t\tvarying vec4 vUv;\n\n\t\t#include <common>\n\t\t#include <logdepthbuf_pars_vertex>\n\n\t\tvoid main() {\n\n\t\t\tvUv = textureMatrix * vec4( position, 1.0 );\n\n\t\t\tgl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n\n\t\t\t#include <logdepthbuf_vertex>\n\n\t\t}",fragmentShader:"\n\t\tuniform vec3 color;\n\t\tuniform sampler2D tDiffuse;\n\t\tvarying vec4 vUv;\n\n\t\t#include <logdepthbuf_pars_fragment>\n\n\t\tfloat blendOverlay( float base, float blend ) {\n\n\t\t\treturn( base < 0.5 ? ( 2.0 * base * blend ) : ( 1.0 - 2.0 * ( 1.0 - base ) * ( 1.0 - blend ) ) );\n\n\t\t}\n\n\t\tvec3 blendOverlay( vec3 base, vec3 blend ) {\n\n\t\t\treturn vec3( blendOverlay( base.r, blend.r ), blendOverlay( base.g, blend.g ), blendOverlay( base.b, blend.b ) );\n\n\t\t}\n\n\t\tvoid main() {\n\n\t\t\t#include <logdepthbuf_fragment>\n\n\t\t\tvec4 base = texture2DProj( tDiffuse, vUv );\n\t\t\tgl_FragColor = vec4( blendOverlay( base.rgb, color ), 1.0 );\n\n\t\t}"},exports.Reflector=t;
|
package/objects/Reflector.js
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
import { Mesh, Color, Plane, Vector3, Matrix4, Vector4, PerspectiveCamera, WebGLRenderTarget,
|
1
|
+
import { Mesh, Color, Plane, Vector3, Matrix4, Vector4, PerspectiveCamera, WebGLRenderTarget, ShaderMaterial, UniformsUtils } from 'three';
|
2
2
|
|
3
3
|
class Reflector extends Mesh {
|
4
4
|
constructor(geometry, options = {}) {
|
@@ -23,17 +23,7 @@ class Reflector extends Mesh {
|
|
23
23
|
const q = new Vector4();
|
24
24
|
const textureMatrix = new Matrix4();
|
25
25
|
const virtualCamera = new PerspectiveCamera();
|
26
|
-
const
|
27
|
-
minFilter: LinearFilter,
|
28
|
-
magFilter: LinearFilter,
|
29
|
-
format: RGBFormat
|
30
|
-
};
|
31
|
-
const renderTarget = new WebGLRenderTarget(textureWidth, textureHeight, parameters);
|
32
|
-
|
33
|
-
if (!MathUtils.isPowerOfTwo(textureWidth) || !MathUtils.isPowerOfTwo(textureHeight)) {
|
34
|
-
renderTarget.texture.generateMipmaps = false;
|
35
|
-
}
|
36
|
-
|
26
|
+
const renderTarget = new WebGLRenderTarget(textureWidth, textureHeight);
|
37
27
|
const material = new ShaderMaterial({
|
38
28
|
uniforms: UniformsUtils.clone(shader.uniforms),
|
39
29
|
fragmentShader: shader.fragmentShader,
|
@@ -124,6 +114,11 @@ class Reflector extends Mesh {
|
|
124
114
|
this.getRenderTarget = function () {
|
125
115
|
return renderTarget;
|
126
116
|
};
|
117
|
+
|
118
|
+
this.dispose = function () {
|
119
|
+
renderTarget.dispose();
|
120
|
+
scope.material.dispose();
|
121
|
+
};
|
127
122
|
}
|
128
123
|
|
129
124
|
}
|
@@ -147,12 +142,17 @@ Reflector.ReflectorShader = {
|
|
147
142
|
uniform mat4 textureMatrix;
|
148
143
|
varying vec4 vUv;
|
149
144
|
|
145
|
+
#include <common>
|
146
|
+
#include <logdepthbuf_pars_vertex>
|
147
|
+
|
150
148
|
void main() {
|
151
149
|
|
152
150
|
vUv = textureMatrix * vec4( position, 1.0 );
|
153
151
|
|
154
152
|
gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
|
155
153
|
|
154
|
+
#include <logdepthbuf_vertex>
|
155
|
+
|
156
156
|
}`,
|
157
157
|
fragmentShader:
|
158
158
|
/* glsl */
|
@@ -161,6 +161,8 @@ Reflector.ReflectorShader = {
|
|
161
161
|
uniform sampler2D tDiffuse;
|
162
162
|
varying vec4 vUv;
|
163
163
|
|
164
|
+
#include <logdepthbuf_pars_fragment>
|
165
|
+
|
164
166
|
float blendOverlay( float base, float blend ) {
|
165
167
|
|
166
168
|
return( base < 0.5 ? ( 2.0 * base * blend ) : ( 1.0 - 2.0 * ( 1.0 - base ) * ( 1.0 - blend ) ) );
|
@@ -175,6 +177,8 @@ Reflector.ReflectorShader = {
|
|
175
177
|
|
176
178
|
void main() {
|
177
179
|
|
180
|
+
#include <logdepthbuf_fragment>
|
181
|
+
|
178
182
|
vec4 base = texture2DProj( tDiffuse, vUv );
|
179
183
|
gl_FragColor = vec4( blendOverlay( base.rgb, color ), 1.0 );
|
180
184
|
|
@@ -1 +1 @@
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("three");class e extends t.Mesh{constructor(r,a={}){super(r),this.type="ReflectorForSSRPass";const n=this,i=void 0!==a.color?new t.Color(a.color):new t.Color(8355711),o=a.textureWidth||512,l=a.textureHeight||512,s=a.clipBias||0,u=a.shader||e.ReflectorShader,c=!0===a.useDepthTexture,d=new t.Vector3(0,1,0),v=new t.Vector3,f=new t.Vector3;n.needsUpdate=!1,n.maxDistance=e.ReflectorShader.uniforms.maxDistance.value,n.opacity=e.ReflectorShader.uniforms.opacity.value,n.color=i,n.resolution=a.resolution||new t.Vector2(window.innerWidth,window.innerHeight),n._distanceAttenuation=e.ReflectorShader.defines.DISTANCE_ATTENUATION,Object.defineProperty(n,"distanceAttenuation",{get:()=>n._distanceAttenuation,set(t){n._distanceAttenuation!==t&&(n._distanceAttenuation=t,n.material.defines.DISTANCE_ATTENUATION=t,n.material.needsUpdate=!0)}}),n._fresnel=e.ReflectorShader.defines.FRESNEL,Object.defineProperty(n,"fresnel",{get:()=>n._fresnel,set(t){n._fresnel!==t&&(n._fresnel=t,n.material.defines.FRESNEL=t,n.material.needsUpdate=!0)}});const p=new t.Vector3,m=new t.Vector3,x=new t.Vector3,h=new t.Matrix4,w=new t.Vector3(0,0,-1),
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("three");class e extends t.Mesh{constructor(r,a={}){super(r),this.type="ReflectorForSSRPass";const n=this,i=void 0!==a.color?new t.Color(a.color):new t.Color(8355711),o=a.textureWidth||512,l=a.textureHeight||512,s=a.clipBias||0,u=a.shader||e.ReflectorShader,c=!0===a.useDepthTexture,d=new t.Vector3(0,1,0),v=new t.Vector3,f=new t.Vector3;n.needsUpdate=!1,n.maxDistance=e.ReflectorShader.uniforms.maxDistance.value,n.opacity=e.ReflectorShader.uniforms.opacity.value,n.color=i,n.resolution=a.resolution||new t.Vector2(window.innerWidth,window.innerHeight),n._distanceAttenuation=e.ReflectorShader.defines.DISTANCE_ATTENUATION,Object.defineProperty(n,"distanceAttenuation",{get:()=>n._distanceAttenuation,set(t){n._distanceAttenuation!==t&&(n._distanceAttenuation=t,n.material.defines.DISTANCE_ATTENUATION=t,n.material.needsUpdate=!0)}}),n._fresnel=e.ReflectorShader.defines.FRESNEL,Object.defineProperty(n,"fresnel",{get:()=>n._fresnel,set(t){n._fresnel!==t&&(n._fresnel=t,n.material.defines.FRESNEL=t,n.material.needsUpdate=!0)}});const p=new t.Vector3,m=new t.Vector3,x=new t.Vector3,h=new t.Matrix4,w=new t.Vector3(0,0,-1),g=new t.Vector3,M=new t.Vector3,b=new t.Matrix4,y=new t.PerspectiveCamera;let C;c&&(C=new t.DepthTexture,C.type=t.UnsignedShortType,C.minFilter=t.NearestFilter,C.magFilter=t.NearestFilter);const P={depthTexture:c?C:null},D=new t.WebGLRenderTarget(o,l,P),S=new t.ShaderMaterial({transparent:c,defines:Object.assign({},e.ReflectorShader.defines,{useDepthTexture:c}),uniforms:t.UniformsUtils.clone(u.uniforms),fragmentShader:u.fragmentShader,vertexShader:u.vertexShader});S.uniforms.tDiffuse.value=D.texture,S.uniforms.color.value=n.color,S.uniforms.textureMatrix.value=b,c&&(S.uniforms.tDepth.value=D.depthTexture),this.material=S;const T=[new t.Plane(new t.Vector3(0,1,0),s)];this.doRender=function(t,e,r){if(S.uniforms.maxDistance.value=n.maxDistance,S.uniforms.color.value=n.color,S.uniforms.opacity.value=n.opacity,v.copy(r.position).normalize(),f.copy(v).reflect(d),S.uniforms.fresnelCoe.value=(v.dot(f)+1)/2,m.setFromMatrixPosition(n.matrixWorld),x.setFromMatrixPosition(r.matrixWorld),h.extractRotation(n.matrixWorld),p.set(0,0,1),p.applyMatrix4(h),g.subVectors(m,x),g.dot(p)>0)return;g.reflect(p).negate(),g.add(m),h.extractRotation(r.matrixWorld),w.set(0,0,-1),w.applyMatrix4(h),w.add(x),M.subVectors(m,w),M.reflect(p).negate(),M.add(m),y.position.copy(g),y.up.set(0,1,0),y.up.applyMatrix4(h),y.up.reflect(p),y.lookAt(M),y.far=r.far,y.updateMatrixWorld(),y.projectionMatrix.copy(r.projectionMatrix),S.uniforms.virtualCameraNear.value=r.near,S.uniforms.virtualCameraFar.value=r.far,S.uniforms.virtualCameraMatrixWorld.value=y.matrixWorld,S.uniforms.virtualCameraProjectionMatrix.value=r.projectionMatrix,S.uniforms.virtualCameraProjectionMatrixInverse.value=r.projectionMatrixInverse,S.uniforms.resolution.value=n.resolution,b.set(.5,0,0,.5,0,.5,0,.5,0,0,.5,.5,0,0,0,1),b.multiply(y.projectionMatrix),b.multiply(y.matrixWorldInverse),b.multiply(n.matrixWorld),D.texture.encoding=t.outputEncoding;const a=t.getRenderTarget(),i=t.xr.enabled,o=t.shadowMap.autoUpdate,l=t.clippingPlanes;t.xr.enabled=!1,t.shadowMap.autoUpdate=!1,t.clippingPlanes=T,t.setRenderTarget(D),t.state.buffers.depth.setMask(!0),!1===t.autoClear&&t.clear(),t.render(e,y),t.xr.enabled=i,t.shadowMap.autoUpdate=o,t.clippingPlanes=l,t.setRenderTarget(a);const s=r.viewport;void 0!==s&&t.state.viewport(s)},this.getRenderTarget=function(){return D}}}e.prototype.isReflectorForSSRPass=!0,e.ReflectorShader={defines:{DISTANCE_ATTENUATION:!0,FRESNEL:!0},uniforms:{color:{value:null},tDiffuse:{value:null},tDepth:{value:null},textureMatrix:{value:new t.Matrix4},maxDistance:{value:180},opacity:{value:.5},fresnelCoe:{value:null},virtualCameraNear:{value:null},virtualCameraFar:{value:null},virtualCameraProjectionMatrix:{value:new t.Matrix4},virtualCameraMatrixWorld:{value:new t.Matrix4},virtualCameraProjectionMatrixInverse:{value:new t.Matrix4},resolution:{value:new t.Vector2}},vertexShader:"\n\t\tuniform mat4 textureMatrix;\n\t\tvarying vec4 vUv;\n\n\t\tvoid main() {\n\n\t\t\tvUv = textureMatrix * vec4( position, 1.0 );\n\n\t\t\tgl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n\n\t\t}",fragmentShader:"\n\t\tuniform vec3 color;\n\t\tuniform sampler2D tDiffuse;\n\t\tuniform sampler2D tDepth;\n\t\tuniform float maxDistance;\n\t\tuniform float opacity;\n\t\tuniform float fresnelCoe;\n\t\tuniform float virtualCameraNear;\n\t\tuniform float virtualCameraFar;\n\t\tuniform mat4 virtualCameraProjectionMatrix;\n\t\tuniform mat4 virtualCameraProjectionMatrixInverse;\n\t\tuniform mat4 virtualCameraMatrixWorld;\n\t\tuniform vec2 resolution;\n\t\tvarying vec4 vUv;\n\t\t#include <packing>\n\t\tfloat blendOverlay( float base, float blend ) {\n\t\t\treturn( base < 0.5 ? ( 2.0 * base * blend ) : ( 1.0 - 2.0 * ( 1.0 - base ) * ( 1.0 - blend ) ) );\n\t\t}\n\t\tvec3 blendOverlay( vec3 base, vec3 blend ) {\n\t\t\treturn vec3( blendOverlay( base.r, blend.r ), blendOverlay( base.g, blend.g ), blendOverlay( base.b, blend.b ) );\n\t\t}\n\t\tfloat getDepth( const in vec2 uv ) {\n\t\t\treturn texture2D( tDepth, uv ).x;\n\t\t}\n\t\tfloat getViewZ( const in float depth ) {\n\t\t\treturn perspectiveDepthToViewZ( depth, virtualCameraNear, virtualCameraFar );\n\t\t}\n\t\tvec3 getViewPosition( const in vec2 uv, const in float depth/*clip space*/, const in float clipW ) {\n\t\t\tvec4 clipPosition = vec4( ( vec3( uv, depth ) - 0.5 ) * 2.0, 1.0 );//ndc\n\t\t\tclipPosition *= clipW; //clip\n\t\t\treturn ( virtualCameraProjectionMatrixInverse * clipPosition ).xyz;//view\n\t\t}\n\t\tvoid main() {\n\t\t\tvec4 base = texture2DProj( tDiffuse, vUv );\n\t\t\t#ifdef useDepthTexture\n\t\t\t\tvec2 uv=(gl_FragCoord.xy-.5)/resolution.xy;\n\t\t\t\tuv.x=1.-uv.x;\n\t\t\t\tfloat depth = texture2DProj( tDepth, vUv ).r;\n\t\t\t\tfloat viewZ = getViewZ( depth );\n\t\t\t\tfloat clipW = virtualCameraProjectionMatrix[2][3] * viewZ+virtualCameraProjectionMatrix[3][3];\n\t\t\t\tvec3 viewPosition=getViewPosition( uv, depth, clipW );\n\t\t\t\tvec3 worldPosition=(virtualCameraMatrixWorld*vec4(viewPosition,1)).xyz;\n\t\t\t\tif(worldPosition.y>maxDistance) discard;\n\t\t\t\tfloat op=opacity;\n\t\t\t\t#ifdef DISTANCE_ATTENUATION\n\t\t\t\t\tfloat ratio=1.-(worldPosition.y/maxDistance);\n\t\t\t\t\tfloat attenuation=ratio*ratio;\n\t\t\t\t\top=opacity*attenuation;\n\t\t\t\t#endif\n\t\t\t\t#ifdef FRESNEL\n\t\t\t\t\top*=fresnelCoe;\n\t\t\t\t#endif\n\t\t\t\tgl_FragColor = vec4( blendOverlay( base.rgb, color ), op );\n\t\t\t#else\n\t\t\t\tgl_FragColor = vec4( blendOverlay( base.rgb, color ), 1.0 );\n\t\t\t#endif\n\t\t}\n\t"},exports.ReflectorForSSRPass=e;
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import { Mesh, Color, Vector3, Vector2, Matrix4, PerspectiveCamera, DepthTexture, UnsignedShortType, NearestFilter, WebGLRenderTarget,
|
1
|
+
import { Mesh, Color, Vector3, Vector2, Matrix4, PerspectiveCamera, DepthTexture, UnsignedShortType, NearestFilter, WebGLRenderTarget, ShaderMaterial, UniformsUtils, Plane } from 'three';
|
2
2
|
|
3
3
|
class ReflectorForSSRPass extends Mesh {
|
4
4
|
constructor(geometry, options = {}) {
|
@@ -67,17 +67,9 @@ class ReflectorForSSRPass extends Mesh {
|
|
67
67
|
}
|
68
68
|
|
69
69
|
const parameters = {
|
70
|
-
minFilter: LinearFilter,
|
71
|
-
magFilter: LinearFilter,
|
72
|
-
format: RGBFormat,
|
73
70
|
depthTexture: useDepthTexture ? depthTexture : null
|
74
71
|
};
|
75
72
|
const renderTarget = new WebGLRenderTarget(textureWidth, textureHeight, parameters);
|
76
|
-
|
77
|
-
if (!MathUtils.isPowerOfTwo(textureWidth) || !MathUtils.isPowerOfTwo(textureHeight)) {
|
78
|
-
renderTarget.texture.generateMipmaps = false;
|
79
|
-
}
|
80
|
-
|
81
73
|
const material = new ShaderMaterial({
|
82
74
|
transparent: useDepthTexture,
|
83
75
|
defines: Object.assign({}, ReflectorForSSRPass.ReflectorShader.defines, {
|
package/objects/Refractor.cjs.js
CHANGED
@@ -1 +1 @@
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("three");class t extends e.Mesh{constructor(r,n={}){super(r),this.type="Refractor";const
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("three");class t extends e.Mesh{constructor(r,n={}){super(r),this.type="Refractor";const o=this,a=void 0!==n.color?new e.Color(n.color):new e.Color(8355711),i=n.textureWidth||512,l=n.textureHeight||512,s=n.clipBias||0,c=n.shader||t.RefractorShader,u=new e.PerspectiveCamera;u.matrixAutoUpdate=!1,u.userData.refractor=!0;const d=new e.Plane,m=new e.Matrix4,v=new e.WebGLRenderTarget(i,l);this.material=new e.ShaderMaterial({uniforms:e.UniformsUtils.clone(c.uniforms),vertexShader:c.vertexShader,fragmentShader:c.fragmentShader,transparent:!0}),this.material.uniforms.color.value=a,this.material.uniforms.tDiffuse.value=v.texture,this.material.uniforms.textureMatrix.value=m;const x=function(){const t=new e.Vector3,r=new e.Vector3,n=new e.Matrix4,a=new e.Vector3,i=new e.Vector3;return function(e){return t.setFromMatrixPosition(o.matrixWorld),r.setFromMatrixPosition(e.matrixWorld),a.subVectors(t,r),n.extractRotation(o.matrixWorld),i.set(0,0,1),i.applyMatrix4(n),a.dot(i)<0}}(),p=function(){const t=new e.Vector3,r=new e.Vector3,n=new e.Quaternion,a=new e.Vector3;return function(){o.matrixWorld.decompose(r,n,a),t.set(0,0,1).applyQuaternion(n).normalize(),t.negate(),d.setFromNormalAndCoplanarPoint(t,r)}}(),f=function(){const t=new e.Plane,r=new e.Vector4,n=new e.Vector4;return function(e){u.matrixWorld.copy(e.matrixWorld),u.matrixWorldInverse.copy(u.matrixWorld).invert(),u.projectionMatrix.copy(e.projectionMatrix),u.far=e.far,t.copy(d),t.applyMatrix4(u.matrixWorldInverse),r.set(t.normal.x,t.normal.y,t.normal.z,t.constant);const o=u.projectionMatrix;n.x=(Math.sign(r.x)+o.elements[8])/o.elements[0],n.y=(Math.sign(r.y)+o.elements[9])/o.elements[5],n.z=-1,n.w=(1+o.elements[10])/o.elements[14],r.multiplyScalar(2/r.dot(n)),o.elements[2]=r.x,o.elements[6]=r.y,o.elements[10]=r.z+1-s,o.elements[14]=r.w}}();this.onBeforeRender=function(e,t,r){v.texture.encoding=e.outputEncoding,!0!==r.userData.refractor&&!0!=!x(r)&&(p(),function(e){m.set(.5,0,0,.5,0,.5,0,.5,0,0,.5,.5,0,0,0,1),m.multiply(e.projectionMatrix),m.multiply(e.matrixWorldInverse),m.multiply(o.matrixWorld)}(r),f(r),function(e,t,r){o.visible=!1;const n=e.getRenderTarget(),a=e.xr.enabled,i=e.shadowMap.autoUpdate;e.xr.enabled=!1,e.shadowMap.autoUpdate=!1,e.setRenderTarget(v),!1===e.autoClear&&e.clear(),e.render(t,u),e.xr.enabled=a,e.shadowMap.autoUpdate=i,e.setRenderTarget(n);const l=r.viewport;void 0!==l&&e.state.viewport(l),o.visible=!0}(e,t,r))},this.getRenderTarget=function(){return v},this.dispose=function(){v.dispose(),o.material.dispose()}}}t.prototype.isRefractor=!0,t.RefractorShader={uniforms:{color:{value:null},tDiffuse:{value:null},textureMatrix:{value:null}},vertexShader:"\n\n\t\tuniform mat4 textureMatrix;\n\n\t\tvarying vec4 vUv;\n\n\t\tvoid main() {\n\n\t\t\tvUv = textureMatrix * vec4( position, 1.0 );\n\t\t\tgl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n\n\t\t}",fragmentShader:"\n\n\t\tuniform vec3 color;\n\t\tuniform sampler2D tDiffuse;\n\n\t\tvarying vec4 vUv;\n\n\t\tfloat blendOverlay( float base, float blend ) {\n\n\t\t\treturn( base < 0.5 ? ( 2.0 * base * blend ) : ( 1.0 - 2.0 * ( 1.0 - base ) * ( 1.0 - blend ) ) );\n\n\t\t}\n\n\t\tvec3 blendOverlay( vec3 base, vec3 blend ) {\n\n\t\t\treturn vec3( blendOverlay( base.r, blend.r ), blendOverlay( base.g, blend.g ), blendOverlay( base.b, blend.b ) );\n\n\t\t}\n\n\t\tvoid main() {\n\n\t\t\tvec4 base = texture2DProj( tDiffuse, vUv );\n\t\t\tgl_FragColor = vec4( blendOverlay( base.rgb, color ), 1.0 );\n\n\t\t}"},exports.Refractor=t;
|
package/objects/Refractor.js
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
import { Mesh, Color, PerspectiveCamera, Plane, Matrix4, WebGLRenderTarget,
|
1
|
+
import { Mesh, Color, PerspectiveCamera, Plane, Matrix4, WebGLRenderTarget, ShaderMaterial, UniformsUtils, Vector3, Quaternion, Vector4 } from 'three';
|
2
2
|
|
3
3
|
class Refractor extends Mesh {
|
4
4
|
constructor(geometry, options = {}) {
|
@@ -18,17 +18,7 @@ class Refractor extends Mesh {
|
|
18
18
|
const refractorPlane = new Plane();
|
19
19
|
const textureMatrix = new Matrix4(); // render target
|
20
20
|
|
21
|
-
const
|
22
|
-
minFilter: LinearFilter,
|
23
|
-
magFilter: LinearFilter,
|
24
|
-
format: RGBFormat
|
25
|
-
};
|
26
|
-
const renderTarget = new WebGLRenderTarget(textureWidth, textureHeight, parameters);
|
27
|
-
|
28
|
-
if (!MathUtils.isPowerOfTwo(textureWidth) || !MathUtils.isPowerOfTwo(textureHeight)) {
|
29
|
-
renderTarget.texture.generateMipmaps = false;
|
30
|
-
} // material
|
31
|
-
|
21
|
+
const renderTarget = new WebGLRenderTarget(textureWidth, textureHeight); // material
|
32
22
|
|
33
23
|
this.material = new ShaderMaterial({
|
34
24
|
uniforms: UniformsUtils.clone(shader.uniforms),
|
@@ -162,6 +152,11 @@ class Refractor extends Mesh {
|
|
162
152
|
this.getRenderTarget = function () {
|
163
153
|
return renderTarget;
|
164
154
|
};
|
155
|
+
|
156
|
+
this.dispose = function () {
|
157
|
+
renderTarget.dispose();
|
158
|
+
scope.material.dispose();
|
159
|
+
};
|
165
160
|
}
|
166
161
|
|
167
162
|
}
|
package/objects/Water.cjs.js
CHANGED
@@ -1 +1 @@
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("three");class e extends t.Mesh{constructor(e,r={}){super(e);const o=this,n=void 0!==r.textureWidth?r.textureWidth:512,i=void 0!==r.textureHeight?r.textureHeight:512,a=void 0!==r.clipBias?r.clipBias:0,l=void 0!==r.alpha?r.alpha:1,s=void 0!==r.time?r.time:0,u=void 0!==r.waterNormals?r.waterNormals:null,c=void 0!==r.sunDirection?r.sunDirection:new t.Vector3(.70707,.70707,0),m=new t.Color(void 0!==r.sunColor?r.sunColor:16777215),d=new t.Color(void 0!==r.waterColor?r.waterColor:8355711),v=void 0!==r.eye?r.eye:new t.Vector3(0,0,0),f=void 0!==r.distortionScale?r.distortionScale:20,p=void 0!==r.side?r.side:t.FrontSide,x=void 0!==r.fog&&r.fog,g=
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("three");class e extends t.Mesh{constructor(e,r={}){super(e);const o=this,n=void 0!==r.textureWidth?r.textureWidth:512,i=void 0!==r.textureHeight?r.textureHeight:512,a=void 0!==r.clipBias?r.clipBias:0,l=void 0!==r.alpha?r.alpha:1,s=void 0!==r.time?r.time:0,u=void 0!==r.waterNormals?r.waterNormals:null,c=void 0!==r.sunDirection?r.sunDirection:new t.Vector3(.70707,.70707,0),m=new t.Color(void 0!==r.sunColor?r.sunColor:16777215),d=new t.Color(void 0!==r.waterColor?r.waterColor:8355711),v=void 0!==r.eye?r.eye:new t.Vector3(0,0,0),f=void 0!==r.distortionScale?r.distortionScale:20,p=void 0!==r.side?r.side:t.FrontSide,x=void 0!==r.fog&&r.fog,g=new t.Plane,w=new t.Vector3,h=new t.Vector3,y=new t.Vector3,C=new t.Matrix4,M=new t.Vector3(0,0,-1),S=new t.Vector4,_=new t.Vector3,b=new t.Vector3,D=new t.Vector4,P=new t.Matrix4,V=new t.PerspectiveCamera,z=new t.WebGLRenderTarget(n,i),L={uniforms:t.UniformsUtils.merge([t.UniformsLib.fog,t.UniformsLib.lights,{normalSampler:{value:null},mirrorSampler:{value:null},alpha:{value:1},time:{value:0},size:{value:1},distortionScale:{value:20},textureMatrix:{value:new t.Matrix4},sunColor:{value:new t.Color(8355711)},sunDirection:{value:new t.Vector3(.70707,.70707,0)},eye:{value:new t.Vector3},waterColor:{value:new t.Color(5592405)}}]),vertexShader:"\n\t\t\t\tuniform mat4 textureMatrix;\n\t\t\t\tuniform float time;\n\n\t\t\t\tvarying vec4 mirrorCoord;\n\t\t\t\tvarying vec4 worldPosition;\n\n\t\t\t\t#include <common>\n\t\t\t\t#include <fog_pars_vertex>\n\t\t\t\t#include <shadowmap_pars_vertex>\n\t\t\t\t#include <logdepthbuf_pars_vertex>\n\n\t\t\t\tvoid main() {\n\t\t\t\t\tmirrorCoord = modelMatrix * vec4( position, 1.0 );\n\t\t\t\t\tworldPosition = mirrorCoord.xyzw;\n\t\t\t\t\tmirrorCoord = textureMatrix * mirrorCoord;\n\t\t\t\t\tvec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );\n\t\t\t\t\tgl_Position = projectionMatrix * mvPosition;\n\n\t\t\t\t#include <beginnormal_vertex>\n\t\t\t\t#include <defaultnormal_vertex>\n\t\t\t\t#include <logdepthbuf_vertex>\n\t\t\t\t#include <fog_vertex>\n\t\t\t\t#include <shadowmap_vertex>\n\t\t\t}",fragmentShader:"\n\t\t\t\tuniform sampler2D mirrorSampler;\n\t\t\t\tuniform float alpha;\n\t\t\t\tuniform float time;\n\t\t\t\tuniform float size;\n\t\t\t\tuniform float distortionScale;\n\t\t\t\tuniform sampler2D normalSampler;\n\t\t\t\tuniform vec3 sunColor;\n\t\t\t\tuniform vec3 sunDirection;\n\t\t\t\tuniform vec3 eye;\n\t\t\t\tuniform vec3 waterColor;\n\n\t\t\t\tvarying vec4 mirrorCoord;\n\t\t\t\tvarying vec4 worldPosition;\n\n\t\t\t\tvec4 getNoise( vec2 uv ) {\n\t\t\t\t\tvec2 uv0 = ( uv / 103.0 ) + vec2(time / 17.0, time / 29.0);\n\t\t\t\t\tvec2 uv1 = uv / 107.0-vec2( time / -19.0, time / 31.0 );\n\t\t\t\t\tvec2 uv2 = uv / vec2( 8907.0, 9803.0 ) + vec2( time / 101.0, time / 97.0 );\n\t\t\t\t\tvec2 uv3 = uv / vec2( 1091.0, 1027.0 ) - vec2( time / 109.0, time / -113.0 );\n\t\t\t\t\tvec4 noise = texture2D( normalSampler, uv0 ) +\n\t\t\t\t\t\ttexture2D( normalSampler, uv1 ) +\n\t\t\t\t\t\ttexture2D( normalSampler, uv2 ) +\n\t\t\t\t\t\ttexture2D( normalSampler, uv3 );\n\t\t\t\t\treturn noise * 0.5 - 1.0;\n\t\t\t\t}\n\n\t\t\t\tvoid sunLight( const vec3 surfaceNormal, const vec3 eyeDirection, float shiny, float spec, float diffuse, inout vec3 diffuseColor, inout vec3 specularColor ) {\n\t\t\t\t\tvec3 reflection = normalize( reflect( -sunDirection, surfaceNormal ) );\n\t\t\t\t\tfloat direction = max( 0.0, dot( eyeDirection, reflection ) );\n\t\t\t\t\tspecularColor += pow( direction, shiny ) * sunColor * spec;\n\t\t\t\t\tdiffuseColor += max( dot( sunDirection, surfaceNormal ), 0.0 ) * sunColor * diffuse;\n\t\t\t\t}\n\n\t\t\t\t#include <common>\n\t\t\t\t#include <packing>\n\t\t\t\t#include <bsdfs>\n\t\t\t\t#include <fog_pars_fragment>\n\t\t\t\t#include <logdepthbuf_pars_fragment>\n\t\t\t\t#include <lights_pars_begin>\n\t\t\t\t#include <shadowmap_pars_fragment>\n\t\t\t\t#include <shadowmask_pars_fragment>\n\n\t\t\t\tvoid main() {\n\n\t\t\t\t\t#include <logdepthbuf_fragment>\n\t\t\t\t\tvec4 noise = getNoise( worldPosition.xz * size );\n\t\t\t\t\tvec3 surfaceNormal = normalize( noise.xzy * vec3( 1.5, 1.0, 1.5 ) );\n\n\t\t\t\t\tvec3 diffuseLight = vec3(0.0);\n\t\t\t\t\tvec3 specularLight = vec3(0.0);\n\n\t\t\t\t\tvec3 worldToEye = eye-worldPosition.xyz;\n\t\t\t\t\tvec3 eyeDirection = normalize( worldToEye );\n\t\t\t\t\tsunLight( surfaceNormal, eyeDirection, 100.0, 2.0, 0.5, diffuseLight, specularLight );\n\n\t\t\t\t\tfloat distance = length(worldToEye);\n\n\t\t\t\t\tvec2 distortion = surfaceNormal.xz * ( 0.001 + 1.0 / distance ) * distortionScale;\n\t\t\t\t\tvec3 reflectionSample = vec3( texture2D( mirrorSampler, mirrorCoord.xy / mirrorCoord.w + distortion ) );\n\n\t\t\t\t\tfloat theta = max( dot( eyeDirection, surfaceNormal ), 0.0 );\n\t\t\t\t\tfloat rf0 = 0.3;\n\t\t\t\t\tfloat reflectance = rf0 + ( 1.0 - rf0 ) * pow( ( 1.0 - theta ), 5.0 );\n\t\t\t\t\tvec3 scatter = max( 0.0, dot( surfaceNormal, eyeDirection ) ) * waterColor;\n\t\t\t\t\tvec3 albedo = mix( ( sunColor * diffuseLight * 0.3 + scatter ) * getShadowMask(), ( vec3( 0.1 ) + reflectionSample * 0.9 + reflectionSample * specularLight ), reflectance);\n\t\t\t\t\tvec3 outgoingLight = albedo;\n\t\t\t\t\tgl_FragColor = vec4( outgoingLight, alpha );\n\n\t\t\t\t\t#include <tonemapping_fragment>\n\t\t\t\t\t#include <fog_fragment>\n\t\t\t\t}"},N=new t.ShaderMaterial({fragmentShader:L.fragmentShader,vertexShader:L.vertexShader,uniforms:t.UniformsUtils.clone(L.uniforms),lights:!0,side:p,fog:x});N.uniforms.mirrorSampler.value=z.texture,N.uniforms.textureMatrix.value=P,N.uniforms.alpha.value=l,N.uniforms.time.value=s,N.uniforms.normalSampler.value=u,N.uniforms.sunColor.value=m,N.uniforms.waterColor.value=d,N.uniforms.sunDirection.value=c,N.uniforms.distortionScale.value=f,N.uniforms.eye.value=v,o.material=N,o.onBeforeRender=function(t,e,r){if(h.setFromMatrixPosition(o.matrixWorld),y.setFromMatrixPosition(r.matrixWorld),C.extractRotation(o.matrixWorld),w.set(0,0,1),w.applyMatrix4(C),_.subVectors(h,y),_.dot(w)>0)return;_.reflect(w).negate(),_.add(h),C.extractRotation(r.matrixWorld),M.set(0,0,-1),M.applyMatrix4(C),M.add(y),b.subVectors(h,M),b.reflect(w).negate(),b.add(h),V.position.copy(_),V.up.set(0,1,0),V.up.applyMatrix4(C),V.up.reflect(w),V.lookAt(b),V.far=r.far,V.updateMatrixWorld(),V.projectionMatrix.copy(r.projectionMatrix),P.set(.5,0,0,.5,0,.5,0,.5,0,0,.5,.5,0,0,0,1),P.multiply(V.projectionMatrix),P.multiply(V.matrixWorldInverse),g.setFromNormalAndCoplanarPoint(w,h),g.applyMatrix4(V.matrixWorldInverse),S.set(g.normal.x,g.normal.y,g.normal.z,g.constant);const n=V.projectionMatrix;D.x=(Math.sign(S.x)+n.elements[8])/n.elements[0],D.y=(Math.sign(S.y)+n.elements[9])/n.elements[5],D.z=-1,D.w=(1+n.elements[10])/n.elements[14],S.multiplyScalar(2/S.dot(D)),n.elements[2]=S.x,n.elements[6]=S.y,n.elements[10]=S.z+1-a,n.elements[14]=S.w,v.setFromMatrixPosition(r.matrixWorld);const i=t.getRenderTarget(),l=t.xr.enabled,s=t.shadowMap.autoUpdate;o.visible=!1,t.xr.enabled=!1,t.shadowMap.autoUpdate=!1,t.setRenderTarget(z),t.state.buffers.depth.setMask(!0),!1===t.autoClear&&t.clear(),t.render(e,V),o.visible=!0,t.xr.enabled=l,t.shadowMap.autoUpdate=s,t.setRenderTarget(i);const u=r.viewport;void 0!==u&&t.state.viewport(u)}}}e.prototype.isWater=!0,exports.Water=e;
|
package/objects/Water.js
CHANGED
@@ -1,9 +1,9 @@
|
|
1
|
-
import { Mesh, Vector3, Color, FrontSide,
|
1
|
+
import { Mesh, Vector3, Color, FrontSide, Plane, Matrix4, Vector4, PerspectiveCamera, WebGLRenderTarget, UniformsUtils, UniformsLib, ShaderMaterial } from 'three';
|
2
2
|
|
3
3
|
/**
|
4
4
|
* Work based on :
|
5
|
-
*
|
6
|
-
*
|
5
|
+
* https://github.com/Slayvin: Flat mirror for three.js
|
6
|
+
* https://home.adelphi.edu/~stemkoski/ : An implementation of water shader based on the flat mirror
|
7
7
|
* http://29a.ch/ && http://29a.ch/slides/2012/webglwater/ : Water shader explanations in WebGL
|
8
8
|
*/
|
9
9
|
|
@@ -23,8 +23,7 @@ class Water extends Mesh {
|
|
23
23
|
const eye = options.eye !== undefined ? options.eye : new Vector3(0, 0, 0);
|
24
24
|
const distortionScale = options.distortionScale !== undefined ? options.distortionScale : 20.0;
|
25
25
|
const side = options.side !== undefined ? options.side : FrontSide;
|
26
|
-
const fog = options.fog !== undefined ? options.fog : false;
|
27
|
-
const format = options.format !== undefined ? options.format : RGBFormat; //
|
26
|
+
const fog = options.fog !== undefined ? options.fog : false; //
|
28
27
|
|
29
28
|
const mirrorPlane = new Plane();
|
30
29
|
const normal = new Vector3();
|
@@ -38,17 +37,7 @@ class Water extends Mesh {
|
|
38
37
|
const q = new Vector4();
|
39
38
|
const textureMatrix = new Matrix4();
|
40
39
|
const mirrorCamera = new PerspectiveCamera();
|
41
|
-
const
|
42
|
-
minFilter: LinearFilter,
|
43
|
-
magFilter: LinearFilter,
|
44
|
-
format
|
45
|
-
};
|
46
|
-
const renderTarget = new WebGLRenderTarget(textureWidth, textureHeight, parameters);
|
47
|
-
|
48
|
-
if (!MathUtils.isPowerOfTwo(textureWidth) || !MathUtils.isPowerOfTwo(textureHeight)) {
|
49
|
-
renderTarget.texture.generateMipmaps = false;
|
50
|
-
}
|
51
|
-
|
40
|
+
const renderTarget = new WebGLRenderTarget(textureWidth, textureHeight);
|
52
41
|
const mirrorShader = {
|
53
42
|
uniforms: UniformsUtils.merge([UniformsLib['fog'], UniformsLib['lights'], {
|
54
43
|
normalSampler: {
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "three-stdlib",
|
3
|
-
"version": "2.
|
3
|
+
"version": "2.8.1",
|
4
4
|
"private": false,
|
5
5
|
"description": "stand-alone library of threejs examples",
|
6
6
|
"main": "index.cjs.js",
|
@@ -20,7 +20,7 @@
|
|
20
20
|
},
|
21
21
|
"homepage": "https://github.com/pmndrs/three-stdlib#readme",
|
22
22
|
"dependencies": {
|
23
|
-
"@babel/runtime": "^7.
|
23
|
+
"@babel/runtime": "^7.16.7",
|
24
24
|
"@webgpu/glslang": "^0.0.15",
|
25
25
|
"@webxr-input-profiles/motion-controllers": "^1.0.0",
|
26
26
|
"chevrotain": "^9.0.2",
|
@@ -1 +1 @@
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("three"),e=require("./Pass.cjs.js"),
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("three"),e=require("./Pass.cjs.js"),i=require("../shaders/DigitalGlitch.cjs.js");require("@babel/runtime/helpers/defineProperty");class s extends e.Pass{constructor(s=64){super(),void 0===i.DigitalGlitch&&console.error("THREE.GlitchPass relies on DigitalGlitch");const r=i.DigitalGlitch;this.uniforms=t.UniformsUtils.clone(r.uniforms),this.uniforms.tDisp.value=this.generateHeightmap(s),this.material=new t.ShaderMaterial({uniforms:this.uniforms,vertexShader:r.vertexShader,fragmentShader:r.fragmentShader}),this.fsQuad=new e.FullScreenQuad(this.material),this.goWild=!1,this.curF=0,this.generateTrigger()}render(e,i,s){!1===e.capabilities.isWebGL2&&(this.uniforms.tDisp.value.format=t.LuminanceFormat),this.uniforms.tDiffuse.value=s.texture,this.uniforms.seed.value=Math.random(),this.uniforms.byp.value=0,this.curF%this.randX==0||1==this.goWild?(this.uniforms.amount.value=Math.random()/30,this.uniforms.angle.value=t.MathUtils.randFloat(-Math.PI,Math.PI),this.uniforms.seed_x.value=t.MathUtils.randFloat(-1,1),this.uniforms.seed_y.value=t.MathUtils.randFloat(-1,1),this.uniforms.distortion_x.value=t.MathUtils.randFloat(0,1),this.uniforms.distortion_y.value=t.MathUtils.randFloat(0,1),this.curF=0,this.generateTrigger()):this.curF%this.randX<this.randX/5?(this.uniforms.amount.value=Math.random()/90,this.uniforms.angle.value=t.MathUtils.randFloat(-Math.PI,Math.PI),this.uniforms.distortion_x.value=t.MathUtils.randFloat(0,1),this.uniforms.distortion_y.value=t.MathUtils.randFloat(0,1),this.uniforms.seed_x.value=t.MathUtils.randFloat(-.3,.3),this.uniforms.seed_y.value=t.MathUtils.randFloat(-.3,.3)):0==this.goWild&&(this.uniforms.byp.value=1),this.curF++,this.renderToScreen?(e.setRenderTarget(null),this.fsQuad.render(e)):(e.setRenderTarget(i),this.clear&&e.clear(),this.fsQuad.render(e))}generateTrigger(){this.randX=t.MathUtils.randInt(120,240)}generateHeightmap(e){const i=new Float32Array(e*e),s=e*e;for(let e=0;e<s;e++){const s=t.MathUtils.randFloat(0,1);i[e]=s}const r=new t.DataTexture(i,e,e,t.RedFormat,t.FloatType);return r.needsUpdate=!0,r}}exports.GlitchPass=s;
|