elation-engine 0.9.113 → 0.9.115
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/css/systems/render.css +5 -1
- package/package.json +1 -1
- package/scripts/assets.js +103 -20
- package/scripts/assetworker.js +18 -1
- package/scripts/external/holoplay.js +1494 -0
- package/scripts/external/octree.js +0 -0
- package/scripts/external/three/CSS3DRenderer.js +46 -43
- package/scripts/external/three/CubemapToEquirectangular.js +1 -1
- package/scripts/external/three/three-extras.js +1553 -392
- package/scripts/external/three/three-icosa.js +2575 -0
- package/scripts/external/three/three-loaders.js +925 -133
- package/scripts/external/three/three-postprocessing.js +3 -3
- package/scripts/external/three/three-r116dev.js +50930 -0
- package/scripts/external/three/three-spotlighttextures.js +50953 -0
- package/scripts/external/three/three-vrm.js +2 -2
- package/scripts/external/three/three-working.js +35968 -0
- package/scripts/external/three/three.js +38532 -24087
- package/scripts/external/three-mesh-bvh.js +5370 -0
- package/scripts/external/three-old/BVHLoader.js +406 -0
- package/scripts/external/three-old/ColladaLoader.js +5519 -0
- package/scripts/external/three-old/ColladaLoader2.js +1694 -0
- package/scripts/external/three-old/CubemapToEquirectangular.js +188 -0
- package/scripts/external/three-old/DDSLoader.js +269 -0
- package/scripts/external/three-old/FBXLoader-mine.js +5063 -0
- package/scripts/external/three-old/FBXLoader.js +5112 -0
- package/scripts/external/three-old/FlyControls.js +295 -0
- package/scripts/external/three-old/GLTF2Loader.js +2950 -0
- package/scripts/external/three-old/GLTFLoader.js +2213 -0
- package/scripts/external/three-old/JSONLoader.js +435 -0
- package/scripts/external/three-old/MTLLoader.js +533 -0
- package/scripts/external/three-old/OBJLoader-experimental.js +874 -0
- package/scripts/external/three-old/OBJLoader-working.js +727 -0
- package/scripts/external/three-old/OBJLoader.js +723 -0
- package/scripts/external/three-old/OBJMTLLoader.js +440 -0
- package/scripts/external/three-old/OrbitControls.js +592 -0
- package/scripts/external/three-old/PLYLoader.js +517 -0
- package/scripts/external/three-old/TransformControls.js +1100 -0
- package/scripts/external/three-old/VRMLLoader.js +1021 -0
- package/scripts/external/three-old/glTFLoader-combined.js +2513 -0
- package/scripts/external/three-old/nodethree.js +44018 -0
- package/scripts/external/three-old/render/BleachBypassShader.js +64 -0
- package/scripts/external/three-old/render/BloomPass.js +116 -0
- package/scripts/external/three-old/render/CSS3DRenderer.js +310 -0
- package/scripts/external/three-old/render/ClearPass.js +44 -0
- package/scripts/external/three-old/render/ConvolutionShader.js +101 -0
- package/scripts/external/three-old/render/CopyShader.js +46 -0
- package/scripts/external/three-old/render/EffectComposer.js +211 -0
- package/scripts/external/three-old/render/FXAAShader.js +88 -0
- package/scripts/external/three-old/render/FilmPass.js +60 -0
- package/scripts/external/three-old/render/FilmShader.js +104 -0
- package/scripts/external/three-old/render/ManualMSAARenderPass.js +168 -0
- package/scripts/external/three-old/render/MaskPass.js +97 -0
- package/scripts/external/three-old/render/OculusRenderPass.js +84 -0
- package/scripts/external/three-old/render/OculusRiftEffect.js +240 -0
- package/scripts/external/three-old/render/PortalRenderPass.js +166 -0
- package/scripts/external/three-old/render/RecordingPass.js +208 -0
- package/scripts/external/three-old/render/RenderPass.js +57 -0
- package/scripts/external/three-old/render/SSAOShader.js +259 -0
- package/scripts/external/three-old/render/SepiaShader.js +54 -0
- package/scripts/external/three-old/render/ShaderPass.js +66 -0
- package/scripts/external/three-old/render/VREffect.js +482 -0
- package/scripts/external/three-old/shimthree.js +23 -0
- package/scripts/external/three-old/stats.js +6 -0
- package/scripts/external/three-old/three-88dev.js +45004 -0
- package/scripts/external/three-old/three-backgroundoptimization.js +44432 -0
- package/scripts/external/three-old/three-updates.js +44735 -0
- package/scripts/external/three-old/three-working.js +44719 -0
- package/scripts/external/three-old/three.js +44431 -0
- package/scripts/external/three-old/threex.rendererstats.js +66 -0
- package/scripts/external/three-old/tween.js +13 -0
- package/scripts/external/webvr-polyfill-new.js +3497 -0
- package/scripts/external/webvr-polyfill-newest.js +3491 -0
- package/scripts/external/webvr-polyfill-old.js +6337 -0
- package/scripts/geometries.js +2 -2
- package/scripts/math.js +6 -6
- package/scripts/systems/admin.js +1 -1
- package/scripts/systems/controls.js +6 -4
- package/scripts/systems/physics.js +10 -10
- package/scripts/systems/render.js +58 -20
- package/scripts/systems/render2.js +38 -0
- package/scripts/things/camera.js +6 -1
- package/scripts/things/generic-trackedvectors.js +1875 -0
- package/scripts/things/generic.js +3 -4
- package/scripts/things/label2d.js +1 -1
- package/scripts/things/leapmotion.js +6 -6
- package/scripts/things/menu.js +1 -1
- package/scripts/things/player-bak.js +638 -0
- package/scripts/things/player.js +28 -10
- package/scripts/things/skysphere.js +1 -1
- package/scripts/things/terrain.js +1 -1
- package/scripts/things/text.js +1 -1
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @author alteredq / http://alteredqualia.com/
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
THREE.EffectComposer = function ( renderer, renderTarget ) {
|
|
6
|
+
|
|
7
|
+
this.renderer = renderer;
|
|
8
|
+
|
|
9
|
+
if ( renderTarget === undefined ) {
|
|
10
|
+
|
|
11
|
+
var parameters = {
|
|
12
|
+
minFilter: THREE.LinearFilter,
|
|
13
|
+
magFilter: THREE.LinearFilter,
|
|
14
|
+
format: THREE.RGBAFormat,
|
|
15
|
+
stencilBuffer: false
|
|
16
|
+
};
|
|
17
|
+
var size = renderer.getSize();
|
|
18
|
+
renderTarget = new THREE.WebGLRenderTarget( size.width, size.height, parameters );
|
|
19
|
+
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
this.renderTarget1 = renderTarget;
|
|
23
|
+
this.renderTarget2 = renderTarget.clone();
|
|
24
|
+
|
|
25
|
+
this.writeBuffer = this.renderTarget1;
|
|
26
|
+
this.readBuffer = this.renderTarget2;
|
|
27
|
+
|
|
28
|
+
this.passes = [];
|
|
29
|
+
|
|
30
|
+
if ( THREE.CopyShader === undefined )
|
|
31
|
+
console.error( "THREE.EffectComposer relies on THREE.CopyShader" );
|
|
32
|
+
|
|
33
|
+
this.copyPass = new THREE.ShaderPass( THREE.CopyShader );
|
|
34
|
+
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
Object.assign( THREE.EffectComposer.prototype, {
|
|
38
|
+
|
|
39
|
+
swapBuffers: function() {
|
|
40
|
+
|
|
41
|
+
var tmp = this.readBuffer;
|
|
42
|
+
this.readBuffer = this.writeBuffer;
|
|
43
|
+
this.writeBuffer = tmp;
|
|
44
|
+
|
|
45
|
+
},
|
|
46
|
+
|
|
47
|
+
addPass: function ( pass ) {
|
|
48
|
+
|
|
49
|
+
this.passes.push( pass );
|
|
50
|
+
|
|
51
|
+
var size = this.renderer.getSize();
|
|
52
|
+
pass.setSize( size.width, size.height );
|
|
53
|
+
|
|
54
|
+
},
|
|
55
|
+
|
|
56
|
+
insertPass: function ( pass, index ) {
|
|
57
|
+
|
|
58
|
+
this.passes.splice( index, 0, pass );
|
|
59
|
+
|
|
60
|
+
},
|
|
61
|
+
|
|
62
|
+
render: function ( delta ) {
|
|
63
|
+
|
|
64
|
+
var maskActive = false;
|
|
65
|
+
|
|
66
|
+
var pass, i, il = this.passes.length;
|
|
67
|
+
|
|
68
|
+
for ( i = 0; i < il; i ++ ) {
|
|
69
|
+
|
|
70
|
+
pass = this.passes[ i ];
|
|
71
|
+
|
|
72
|
+
if ( pass.enabled === false ) continue;
|
|
73
|
+
|
|
74
|
+
pass.render( this.renderer, this.writeBuffer, this.readBuffer, delta, maskActive );
|
|
75
|
+
|
|
76
|
+
if ( pass.needsSwap ) {
|
|
77
|
+
|
|
78
|
+
if ( maskActive ) {
|
|
79
|
+
|
|
80
|
+
var context = this.renderer.context;
|
|
81
|
+
|
|
82
|
+
context.stencilFunc( context.NOTEQUAL, 1, 0xffffffff );
|
|
83
|
+
|
|
84
|
+
this.copyPass.render( this.renderer, this.writeBuffer, this.readBuffer, delta );
|
|
85
|
+
|
|
86
|
+
context.stencilFunc( context.EQUAL, 1, 0xffffffff );
|
|
87
|
+
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
this.swapBuffers();
|
|
91
|
+
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
if ( THREE.MaskPass !== undefined ) {
|
|
95
|
+
|
|
96
|
+
if ( pass instanceof THREE.MaskPass ) {
|
|
97
|
+
|
|
98
|
+
maskActive = true;
|
|
99
|
+
|
|
100
|
+
} else if ( pass instanceof THREE.ClearMaskPass ) {
|
|
101
|
+
|
|
102
|
+
maskActive = false;
|
|
103
|
+
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
},
|
|
111
|
+
|
|
112
|
+
reset: function ( renderTarget ) {
|
|
113
|
+
|
|
114
|
+
if ( renderTarget === undefined ) {
|
|
115
|
+
|
|
116
|
+
var size = this.renderer.getSize();
|
|
117
|
+
|
|
118
|
+
renderTarget = this.renderTarget1.clone();
|
|
119
|
+
renderTarget.setSize( size.width, size.height );
|
|
120
|
+
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
this.renderTarget1.dispose();
|
|
124
|
+
this.renderTarget2.dispose();
|
|
125
|
+
this.renderTarget1 = renderTarget;
|
|
126
|
+
this.renderTarget2 = renderTarget.clone();
|
|
127
|
+
|
|
128
|
+
this.writeBuffer = this.renderTarget1;
|
|
129
|
+
this.readBuffer = this.renderTarget2;
|
|
130
|
+
|
|
131
|
+
},
|
|
132
|
+
|
|
133
|
+
setSize: function ( width, height ) {
|
|
134
|
+
|
|
135
|
+
this.renderTarget1.setSize( width, height );
|
|
136
|
+
this.renderTarget2.setSize( width, height );
|
|
137
|
+
|
|
138
|
+
for ( var i = 0; i < this.passes.length; i ++ ) {
|
|
139
|
+
|
|
140
|
+
this.passes[i].setSize( width, height );
|
|
141
|
+
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
},
|
|
145
|
+
|
|
146
|
+
getSize: function() {
|
|
147
|
+
|
|
148
|
+
return this.renderer.getSize();
|
|
149
|
+
|
|
150
|
+
},
|
|
151
|
+
|
|
152
|
+
getPixelRatio: function() {
|
|
153
|
+
|
|
154
|
+
return this.renderer.getPixelRatio();
|
|
155
|
+
|
|
156
|
+
},
|
|
157
|
+
|
|
158
|
+
setPixelRatio: function(ratio) {
|
|
159
|
+
|
|
160
|
+
return this.renderer.setPixelRatio(ratio);
|
|
161
|
+
|
|
162
|
+
},
|
|
163
|
+
|
|
164
|
+
setScissor: function(x, y, width, height) {
|
|
165
|
+
|
|
166
|
+
return this.renderer.setScissor(x, y, width, height);
|
|
167
|
+
|
|
168
|
+
},
|
|
169
|
+
|
|
170
|
+
setScissorTest: function(boolean) {
|
|
171
|
+
|
|
172
|
+
return this.renderer.setScissorTest(boolean);
|
|
173
|
+
|
|
174
|
+
},
|
|
175
|
+
|
|
176
|
+
setViewport: function(x, y, width, height) {
|
|
177
|
+
|
|
178
|
+
return this.renderer.setViewport(x, y, width, height);
|
|
179
|
+
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
} );
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
THREE.Pass = function () {
|
|
186
|
+
|
|
187
|
+
// if set to true, the pass is processed by the composer
|
|
188
|
+
this.enabled = true;
|
|
189
|
+
|
|
190
|
+
// if set to true, the pass indicates to swap read and write buffer after rendering
|
|
191
|
+
this.needsSwap = true;
|
|
192
|
+
|
|
193
|
+
// if set to true, the pass clears its buffer before rendering
|
|
194
|
+
this.clear = false;
|
|
195
|
+
|
|
196
|
+
// if set to true, the result of the pass is rendered to screen
|
|
197
|
+
this.renderToScreen = false;
|
|
198
|
+
|
|
199
|
+
};
|
|
200
|
+
|
|
201
|
+
Object.assign( THREE.Pass.prototype, {
|
|
202
|
+
|
|
203
|
+
setSize: function( width, height ) {},
|
|
204
|
+
|
|
205
|
+
render: function ( renderer, writeBuffer, readBuffer, delta, maskActive ) {
|
|
206
|
+
|
|
207
|
+
console.error( "THREE.Pass: .render() must be implemented in derived pass." );
|
|
208
|
+
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
} );
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @author alteredq / http://alteredqualia.com/
|
|
3
|
+
* @author davidedc / http://www.sketchpatch.net/
|
|
4
|
+
*
|
|
5
|
+
* NVIDIA FXAA by Timothy Lottes
|
|
6
|
+
* http://timothylottes.blogspot.com/2011/06/fxaa3-source-released.html
|
|
7
|
+
* - WebGL port by @supereggbert
|
|
8
|
+
* http://www.glge.org/demos/fxaa/
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
THREE.FXAAShader = {
|
|
12
|
+
|
|
13
|
+
uniforms: {
|
|
14
|
+
|
|
15
|
+
"tDiffuse": { type: "t", value: null },
|
|
16
|
+
"resolution": { type: "v2", value: new THREE.Vector2( 1 / 1024, 1 / 512 ) }
|
|
17
|
+
|
|
18
|
+
},
|
|
19
|
+
|
|
20
|
+
vertexShader: [
|
|
21
|
+
|
|
22
|
+
"void main() {",
|
|
23
|
+
|
|
24
|
+
"gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
|
|
25
|
+
|
|
26
|
+
"}"
|
|
27
|
+
|
|
28
|
+
].join( "\n" ),
|
|
29
|
+
|
|
30
|
+
fragmentShader: [
|
|
31
|
+
|
|
32
|
+
"uniform sampler2D tDiffuse;",
|
|
33
|
+
"uniform vec2 resolution;",
|
|
34
|
+
|
|
35
|
+
"#define FXAA_REDUCE_MIN (1.0/128.0)",
|
|
36
|
+
"#define FXAA_REDUCE_MUL (1.0/8.0)",
|
|
37
|
+
"#define FXAA_SPAN_MAX 8.0",
|
|
38
|
+
|
|
39
|
+
"void main() {",
|
|
40
|
+
|
|
41
|
+
"vec3 rgbNW = texture2D( tDiffuse, ( gl_FragCoord.xy + vec2( -1.0, -1.0 ) ) * resolution ).xyz;",
|
|
42
|
+
"vec3 rgbNE = texture2D( tDiffuse, ( gl_FragCoord.xy + vec2( 1.0, -1.0 ) ) * resolution ).xyz;",
|
|
43
|
+
"vec3 rgbSW = texture2D( tDiffuse, ( gl_FragCoord.xy + vec2( -1.0, 1.0 ) ) * resolution ).xyz;",
|
|
44
|
+
"vec3 rgbSE = texture2D( tDiffuse, ( gl_FragCoord.xy + vec2( 1.0, 1.0 ) ) * resolution ).xyz;",
|
|
45
|
+
"vec4 rgbaM = texture2D( tDiffuse, gl_FragCoord.xy * resolution );",
|
|
46
|
+
"vec3 rgbM = rgbaM.xyz;",
|
|
47
|
+
"vec3 luma = vec3( 0.299, 0.587, 0.114 );",
|
|
48
|
+
|
|
49
|
+
"float lumaNW = dot( rgbNW, luma );",
|
|
50
|
+
"float lumaNE = dot( rgbNE, luma );",
|
|
51
|
+
"float lumaSW = dot( rgbSW, luma );",
|
|
52
|
+
"float lumaSE = dot( rgbSE, luma );",
|
|
53
|
+
"float lumaM = dot( rgbM, luma );",
|
|
54
|
+
"float lumaMin = min( lumaM, min( min( lumaNW, lumaNE ), min( lumaSW, lumaSE ) ) );",
|
|
55
|
+
"float lumaMax = max( lumaM, max( max( lumaNW, lumaNE) , max( lumaSW, lumaSE ) ) );",
|
|
56
|
+
|
|
57
|
+
"vec2 dir;",
|
|
58
|
+
"dir.x = -((lumaNW + lumaNE) - (lumaSW + lumaSE));",
|
|
59
|
+
"dir.y = ((lumaNW + lumaSW) - (lumaNE + lumaSE));",
|
|
60
|
+
|
|
61
|
+
"float dirReduce = max( ( lumaNW + lumaNE + lumaSW + lumaSE ) * ( 0.25 * FXAA_REDUCE_MUL ), FXAA_REDUCE_MIN );",
|
|
62
|
+
|
|
63
|
+
"float rcpDirMin = 1.0 / ( min( abs( dir.x ), abs( dir.y ) ) + dirReduce );",
|
|
64
|
+
"dir = min( vec2( FXAA_SPAN_MAX, FXAA_SPAN_MAX),",
|
|
65
|
+
"max( vec2(-FXAA_SPAN_MAX, -FXAA_SPAN_MAX),",
|
|
66
|
+
"dir * rcpDirMin)) * resolution;",
|
|
67
|
+
"vec4 rgbA = (1.0/2.0) * (",
|
|
68
|
+
"texture2D(tDiffuse, gl_FragCoord.xy * resolution + dir * (1.0/3.0 - 0.5)) +",
|
|
69
|
+
"texture2D(tDiffuse, gl_FragCoord.xy * resolution + dir * (2.0/3.0 - 0.5)));",
|
|
70
|
+
"vec4 rgbB = rgbA * (1.0/2.0) + (1.0/4.0) * (",
|
|
71
|
+
"texture2D(tDiffuse, gl_FragCoord.xy * resolution + dir * (0.0/3.0 - 0.5)) +",
|
|
72
|
+
"texture2D(tDiffuse, gl_FragCoord.xy * resolution + dir * (3.0/3.0 - 0.5)));",
|
|
73
|
+
"float lumaB = dot(rgbB, vec4(luma, 0.0));",
|
|
74
|
+
|
|
75
|
+
"if ( ( lumaB < lumaMin ) || ( lumaB > lumaMax ) ) {",
|
|
76
|
+
|
|
77
|
+
"gl_FragColor = rgbA;",
|
|
78
|
+
|
|
79
|
+
"} else {",
|
|
80
|
+
"gl_FragColor = rgbB;",
|
|
81
|
+
|
|
82
|
+
"}",
|
|
83
|
+
|
|
84
|
+
"}"
|
|
85
|
+
|
|
86
|
+
].join( "\n" )
|
|
87
|
+
|
|
88
|
+
};
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @author alteredq / http://alteredqualia.com/
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
THREE.FilmPass = function ( noiseIntensity, scanlinesIntensity, scanlinesCount, grayscale ) {
|
|
6
|
+
|
|
7
|
+
THREE.Pass.call( this );
|
|
8
|
+
|
|
9
|
+
if ( THREE.FilmShader === undefined )
|
|
10
|
+
console.error( "THREE.FilmPass relies on THREE.FilmShader" );
|
|
11
|
+
|
|
12
|
+
var shader = THREE.FilmShader;
|
|
13
|
+
|
|
14
|
+
this.uniforms = THREE.UniformsUtils.clone( shader.uniforms );
|
|
15
|
+
|
|
16
|
+
this.material = new THREE.ShaderMaterial( {
|
|
17
|
+
|
|
18
|
+
uniforms: this.uniforms,
|
|
19
|
+
vertexShader: shader.vertexShader,
|
|
20
|
+
fragmentShader: shader.fragmentShader
|
|
21
|
+
|
|
22
|
+
} );
|
|
23
|
+
|
|
24
|
+
if ( grayscale !== undefined ) this.uniforms.grayscale.value = grayscale;
|
|
25
|
+
if ( noiseIntensity !== undefined ) this.uniforms.nIntensity.value = noiseIntensity;
|
|
26
|
+
if ( scanlinesIntensity !== undefined ) this.uniforms.sIntensity.value = scanlinesIntensity;
|
|
27
|
+
if ( scanlinesCount !== undefined ) this.uniforms.sCount.value = scanlinesCount;
|
|
28
|
+
|
|
29
|
+
this.camera = new THREE.OrthographicCamera( - 1, 1, 1, - 1, 0, 1 );
|
|
30
|
+
this.scene = new THREE.Scene();
|
|
31
|
+
|
|
32
|
+
this.quad = new THREE.Mesh( new THREE.PlaneBufferGeometry( 2, 2 ), null );
|
|
33
|
+
this.scene.add( this.quad );
|
|
34
|
+
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
THREE.FilmPass.prototype = Object.assign( Object.create( THREE.Pass.prototype ), {
|
|
38
|
+
|
|
39
|
+
constructor: THREE.FilmPass,
|
|
40
|
+
|
|
41
|
+
render: function ( renderer, writeBuffer, readBuffer, delta, maskActive ) {
|
|
42
|
+
|
|
43
|
+
this.uniforms[ "tDiffuse" ].value = readBuffer.texture;
|
|
44
|
+
this.uniforms[ "time" ].value += delta;
|
|
45
|
+
|
|
46
|
+
this.quad.material = this.material;
|
|
47
|
+
|
|
48
|
+
if ( this.renderToScreen ) {
|
|
49
|
+
|
|
50
|
+
renderer.render( this.scene, this.camera );
|
|
51
|
+
|
|
52
|
+
} else {
|
|
53
|
+
|
|
54
|
+
renderer.render( this.scene, this.camera, writeBuffer, this.clear );
|
|
55
|
+
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
} );
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @author alteredq / http://alteredqualia.com/
|
|
3
|
+
*
|
|
4
|
+
* Film grain & scanlines shader
|
|
5
|
+
*
|
|
6
|
+
* - ported from HLSL to WebGL / GLSL
|
|
7
|
+
* http://www.truevision3d.com/forums/showcase/staticnoise_colorblackwhite_scanline_shaders-t18698.0.html
|
|
8
|
+
*
|
|
9
|
+
* Screen Space Static Postprocessor
|
|
10
|
+
*
|
|
11
|
+
* Produces an analogue noise overlay similar to a film grain / TV static
|
|
12
|
+
*
|
|
13
|
+
* Original implementation and noise algorithm
|
|
14
|
+
* Pat 'Hawthorne' Shearon
|
|
15
|
+
*
|
|
16
|
+
* Optimized scanlines + noise version with intensity scaling
|
|
17
|
+
* Georg 'Leviathan' Steinrohder
|
|
18
|
+
*
|
|
19
|
+
* This version is provided under a Creative Commons Attribution 3.0 License
|
|
20
|
+
* http://creativecommons.org/licenses/by/3.0/
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
THREE.FilmShader = {
|
|
24
|
+
|
|
25
|
+
uniforms: {
|
|
26
|
+
|
|
27
|
+
"tDiffuse": { type: "t", value: null },
|
|
28
|
+
"time": { type: "f", value: 0.0 },
|
|
29
|
+
"nIntensity": { type: "f", value: 0.5 },
|
|
30
|
+
"sIntensity": { type: "f", value: 0.05 },
|
|
31
|
+
"sCount": { type: "f", value: 4096 },
|
|
32
|
+
"grayscale": { type: "i", value: 1 }
|
|
33
|
+
|
|
34
|
+
},
|
|
35
|
+
|
|
36
|
+
vertexShader: [
|
|
37
|
+
|
|
38
|
+
"varying vec2 vUv;",
|
|
39
|
+
|
|
40
|
+
"void main() {",
|
|
41
|
+
|
|
42
|
+
"vUv = uv;",
|
|
43
|
+
"gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
|
|
44
|
+
|
|
45
|
+
"}"
|
|
46
|
+
|
|
47
|
+
].join("\n"),
|
|
48
|
+
|
|
49
|
+
fragmentShader: [
|
|
50
|
+
|
|
51
|
+
// control parameter
|
|
52
|
+
"uniform float time;",
|
|
53
|
+
|
|
54
|
+
"uniform bool grayscale;",
|
|
55
|
+
|
|
56
|
+
// noise effect intensity value (0 = no effect, 1 = full effect)
|
|
57
|
+
"uniform float nIntensity;",
|
|
58
|
+
|
|
59
|
+
// scanlines effect intensity value (0 = no effect, 1 = full effect)
|
|
60
|
+
"uniform float sIntensity;",
|
|
61
|
+
|
|
62
|
+
// scanlines effect count value (0 = no effect, 4096 = full effect)
|
|
63
|
+
"uniform float sCount;",
|
|
64
|
+
|
|
65
|
+
"uniform sampler2D tDiffuse;",
|
|
66
|
+
|
|
67
|
+
"varying vec2 vUv;",
|
|
68
|
+
|
|
69
|
+
"void main() {",
|
|
70
|
+
|
|
71
|
+
// sample the source
|
|
72
|
+
"vec4 cTextureScreen = texture2D( tDiffuse, vUv );",
|
|
73
|
+
|
|
74
|
+
// make some noise
|
|
75
|
+
"float x = vUv.x * vUv.y * time * 1000.0;",
|
|
76
|
+
"x = mod( x, 13.0 ) * mod( x, 123.0 );",
|
|
77
|
+
"float dx = mod( x, 0.01 );",
|
|
78
|
+
|
|
79
|
+
// add noise
|
|
80
|
+
"vec3 cResult = cTextureScreen.rgb + cTextureScreen.rgb * clamp( 0.1 + dx * 100.0, 0.0, 1.0 );",
|
|
81
|
+
|
|
82
|
+
// get us a sine and cosine
|
|
83
|
+
"vec2 sc = vec2( sin( vUv.y * sCount ), cos( vUv.y * sCount ) );",
|
|
84
|
+
|
|
85
|
+
// add scanlines
|
|
86
|
+
"cResult += cTextureScreen.rgb * vec3( sc.x, sc.y, sc.x ) * sIntensity;",
|
|
87
|
+
|
|
88
|
+
// interpolate between source and result by intensity
|
|
89
|
+
"cResult = cTextureScreen.rgb + clamp( nIntensity, 0.0,1.0 ) * ( cResult - cTextureScreen.rgb );",
|
|
90
|
+
|
|
91
|
+
// convert to grayscale if desired
|
|
92
|
+
"if( grayscale ) {",
|
|
93
|
+
|
|
94
|
+
"cResult = vec3( cResult.r * 0.3 + cResult.g * 0.59 + cResult.b * 0.11 );",
|
|
95
|
+
|
|
96
|
+
"}",
|
|
97
|
+
|
|
98
|
+
"gl_FragColor = vec4( cResult, cTextureScreen.a );",
|
|
99
|
+
|
|
100
|
+
"}"
|
|
101
|
+
|
|
102
|
+
].join("\n")
|
|
103
|
+
|
|
104
|
+
};
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*
|
|
3
|
+
* Manual Multi-Sample Anti-Aliasing Render Pass
|
|
4
|
+
*
|
|
5
|
+
* @author bhouston / http://clara.io/
|
|
6
|
+
*
|
|
7
|
+
* This manual approach to MSAA re-renders the scene ones for each sample with camera jitter and accumulates the results.
|
|
8
|
+
*
|
|
9
|
+
* References: https://en.wikipedia.org/wiki/Multisample_anti-aliasing
|
|
10
|
+
*
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
THREE.ManualMSAARenderPass = function ( scene, camera, clearColor, clearAlpha ) {
|
|
14
|
+
|
|
15
|
+
THREE.Pass.call( this );
|
|
16
|
+
|
|
17
|
+
this.scene = scene;
|
|
18
|
+
this.camera = camera;
|
|
19
|
+
|
|
20
|
+
this.sampleLevel = 4; // specified as n, where the number of samples is 2^n, so sampleLevel = 4, is 2^4 samples, 16.
|
|
21
|
+
this.unbiased = true;
|
|
22
|
+
|
|
23
|
+
// as we need to clear the buffer in this pass, clearColor must be set to something, defaults to black.
|
|
24
|
+
this.clearColor = ( clearColor !== undefined ) ? clearColor : 0x000000;
|
|
25
|
+
this.clearAlpha = ( clearAlpha !== undefined ) ? clearAlpha : 0;
|
|
26
|
+
|
|
27
|
+
if ( THREE.CopyShader === undefined ) console.error( "THREE.ManualMSAARenderPass relies on THREE.CopyShader" );
|
|
28
|
+
|
|
29
|
+
var copyShader = THREE.CopyShader;
|
|
30
|
+
this.copyUniforms = THREE.UniformsUtils.clone( copyShader.uniforms );
|
|
31
|
+
|
|
32
|
+
this.copyMaterial = new THREE.ShaderMaterial( {
|
|
33
|
+
uniforms: this.copyUniforms,
|
|
34
|
+
vertexShader: copyShader.vertexShader,
|
|
35
|
+
fragmentShader: copyShader.fragmentShader,
|
|
36
|
+
premultipliedAlpha: true,
|
|
37
|
+
transparent: true,
|
|
38
|
+
blending: THREE.AdditiveBlending,
|
|
39
|
+
depthTest: false,
|
|
40
|
+
depthWrite: false
|
|
41
|
+
} );
|
|
42
|
+
|
|
43
|
+
this.camera2 = new THREE.OrthographicCamera( - 1, 1, 1, - 1, 0, 1 );
|
|
44
|
+
this.scene2 = new THREE.Scene();
|
|
45
|
+
this.quad2 = new THREE.Mesh( new THREE.PlaneGeometry( 2, 2 ), this.copyMaterial );
|
|
46
|
+
this.scene2.add( this.quad2 );
|
|
47
|
+
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
THREE.ManualMSAARenderPass.prototype = Object.assign( Object.create( THREE.Pass.prototype ), {
|
|
51
|
+
|
|
52
|
+
constructor: THREE.ManualMSAARenderPass,
|
|
53
|
+
|
|
54
|
+
dispose: function() {
|
|
55
|
+
|
|
56
|
+
if ( this.sampleRenderTarget ) {
|
|
57
|
+
|
|
58
|
+
this.sampleRenderTarget.dispose();
|
|
59
|
+
this.sampleRenderTarget = null;
|
|
60
|
+
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
},
|
|
64
|
+
|
|
65
|
+
setSize: function ( width, height ) {
|
|
66
|
+
|
|
67
|
+
if ( this.sampleRenderTarget ) this.sampleRenderTarget.setSize( width, height );
|
|
68
|
+
|
|
69
|
+
},
|
|
70
|
+
|
|
71
|
+
render: function ( renderer, writeBuffer, readBuffer, delta, maskActive ) {
|
|
72
|
+
|
|
73
|
+
if ( ! this.sampleRenderTarget ) {
|
|
74
|
+
|
|
75
|
+
this.sampleRenderTarget = new THREE.WebGLRenderTarget( readBuffer.width, readBuffer.height,
|
|
76
|
+
{ minFilter: THREE.LinearFilter, magFilter: THREE.LinearFilter, format: THREE.RGBAFormat } );
|
|
77
|
+
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
var jitterOffsets = THREE.ManualMSAARenderPass.JitterVectors[ Math.max( 0, Math.min( this.sampleLevel, 5 ) ) ];
|
|
81
|
+
|
|
82
|
+
var autoClear = renderer.autoClear;
|
|
83
|
+
renderer.autoClear = false;
|
|
84
|
+
|
|
85
|
+
var oldClearColor = renderer.getClearColor().getHex();
|
|
86
|
+
var oldClearAlpha = renderer.getClearAlpha();
|
|
87
|
+
|
|
88
|
+
var baseSampleWeight = 1.0 / jitterOffsets.length;
|
|
89
|
+
var roundingRange = 1 / 32;
|
|
90
|
+
this.copyUniforms[ "tDiffuse" ].value = this.sampleRenderTarget.texture;
|
|
91
|
+
|
|
92
|
+
var width = readBuffer.width, height = readBuffer.height;
|
|
93
|
+
|
|
94
|
+
// render the scene multiple times, each slightly jitter offset from the last and accumulate the results.
|
|
95
|
+
for ( var i = 0; i < jitterOffsets.length; i ++ ) {
|
|
96
|
+
|
|
97
|
+
var jitterOffset = jitterOffsets[i];
|
|
98
|
+
if ( this.camera.setViewOffset ) {
|
|
99
|
+
this.camera.setViewOffset( width, height,
|
|
100
|
+
jitterOffset[ 0 ] * 0.0625, jitterOffset[ 1 ] * 0.0625, // 0.0625 = 1 / 16
|
|
101
|
+
width, height );
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
var sampleWeight = baseSampleWeight;
|
|
105
|
+
if( this.unbiased ) {
|
|
106
|
+
// the theory is that equal weights for each sample lead to an accumulation of rounding errors.
|
|
107
|
+
// The following equation varies the sampleWeight per sample so that it is uniformly distributed
|
|
108
|
+
// across a range of values whose rounding errors cancel each other out.
|
|
109
|
+
var uniformCenteredDistribution = ( -0.5 + ( i + 0.5 ) / jitterOffsets.length );
|
|
110
|
+
sampleWeight += roundingRange * uniformCenteredDistribution;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
this.copyUniforms[ "opacity" ].value = sampleWeight;
|
|
114
|
+
renderer.setClearColor( this.clearColor, this.clearAlpha );
|
|
115
|
+
renderer.render( this.scene, this.camera, this.sampleRenderTarget, true );
|
|
116
|
+
if (i === 0) {
|
|
117
|
+
renderer.setClearColor( 0x000000, 0.0 );
|
|
118
|
+
}
|
|
119
|
+
renderer.render( this.scene2, this.camera2, this.renderToScreen ? null : writeBuffer, (i === 0) );
|
|
120
|
+
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
if ( this.camera.clearViewOffset ) this.camera.clearViewOffset();
|
|
124
|
+
|
|
125
|
+
renderer.autoClear = autoClear;
|
|
126
|
+
renderer.setClearColor( oldClearColor, oldClearAlpha );
|
|
127
|
+
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
} );
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
// These jitter vectors are specified in integers because it is easier.
|
|
134
|
+
// I am assuming a [-8,8) integer grid, but it needs to be mapped onto [-0.5,0.5)
|
|
135
|
+
// before being used, thus these integers need to be scaled by 1/16.
|
|
136
|
+
//
|
|
137
|
+
// Sample patterns reference: https://msdn.microsoft.com/en-us/library/windows/desktop/ff476218%28v=vs.85%29.aspx?f=255&MSPPError=-2147217396
|
|
138
|
+
THREE.ManualMSAARenderPass.JitterVectors = [
|
|
139
|
+
[
|
|
140
|
+
[ 0, 0 ]
|
|
141
|
+
],
|
|
142
|
+
[
|
|
143
|
+
[ 4, 4 ], [ - 4, - 4 ]
|
|
144
|
+
],
|
|
145
|
+
[
|
|
146
|
+
[ - 2, - 6 ], [ 6, - 2 ], [ - 6, 2 ], [ 2, 6 ]
|
|
147
|
+
],
|
|
148
|
+
[
|
|
149
|
+
[ 1, - 3 ], [ - 1, 3 ], [ 5, 1 ], [ - 3, - 5 ],
|
|
150
|
+
[ - 5, 5 ], [ - 7, - 1 ], [ 3, 7 ], [ 7, - 7 ]
|
|
151
|
+
],
|
|
152
|
+
[
|
|
153
|
+
[ 1, 1 ], [ - 1, - 3 ], [ - 3, 2 ], [ 4, - 1 ],
|
|
154
|
+
[ - 5, - 2 ], [ 2, 5 ], [ 5, 3 ], [ 3, - 5 ],
|
|
155
|
+
[ - 2, 6 ], [ 0, - 7 ], [ - 4, - 6 ], [ - 6, 4 ],
|
|
156
|
+
[ - 8, 0 ], [ 7, - 4 ], [ 6, 7 ], [ - 7, - 8 ]
|
|
157
|
+
],
|
|
158
|
+
[
|
|
159
|
+
[ - 4, - 7 ], [ - 7, - 5 ], [ - 3, - 5 ], [ - 5, - 4 ],
|
|
160
|
+
[ - 1, - 4 ], [ - 2, - 2 ], [ - 6, - 1 ], [ - 4, 0 ],
|
|
161
|
+
[ - 7, 1 ], [ - 1, 2 ], [ - 6, 3 ], [ - 3, 3 ],
|
|
162
|
+
[ - 7, 6 ], [ - 3, 6 ], [ - 5, 7 ], [ - 1, 7 ],
|
|
163
|
+
[ 5, - 7 ], [ 1, - 6 ], [ 6, - 5 ], [ 4, - 4 ],
|
|
164
|
+
[ 2, - 3 ], [ 7, - 2 ], [ 1, - 1 ], [ 4, - 1 ],
|
|
165
|
+
[ 2, 1 ], [ 6, 2 ], [ 0, 4 ], [ 4, 4 ],
|
|
166
|
+
[ 2, 5 ], [ 7, 5 ], [ 5, 6 ], [ 3, 7 ]
|
|
167
|
+
]
|
|
168
|
+
];
|