Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
mamayaya1
GitHub Repository: mamayaya1/game
Path: blob/main/projects/HexGL/libs/postprocessing/EffectComposer.js
4627 views
1
/**
2
* @author alteredq / http://alteredqualia.com/
3
*/
4
5
THREE.EffectComposer = function ( renderer, renderTarget ) {
6
7
this.renderer = renderer;
8
9
this.renderTarget1 = renderTarget;
10
11
if ( this.renderTarget1 === undefined ) {
12
13
var width = window.innerWidth || 1;
14
var height = window.innerHeight || 1;
15
16
this.renderTargetParameters = { minFilter: THREE.LinearFilter, magFilter: THREE.LinearFilter, format: THREE.RGBFormat, stencilBuffer: false };
17
this.renderTarget1 = new THREE.WebGLRenderTarget( width, height, this.renderTargetParameters );
18
19
}
20
21
this.renderTarget2 = this.renderTarget1.clone();
22
23
this.writeBuffer = this.renderTarget1;
24
this.readBuffer = this.renderTarget2;
25
26
this.passes = [];
27
28
this.copyPass = new THREE.ShaderPass( THREE.ShaderExtras[ "screen" ] );
29
30
};
31
32
THREE.EffectComposer.prototype = {
33
34
swapBuffers: function() {
35
36
var tmp = this.readBuffer;
37
this.readBuffer = this.writeBuffer;
38
this.writeBuffer = tmp;
39
40
},
41
42
addPass: function ( pass ) {
43
44
this.passes.push( pass );
45
46
},
47
48
render: function ( delta ) {
49
50
this.writeBuffer = this.renderTarget1;
51
this.readBuffer = this.renderTarget2;
52
53
var maskActive = false;
54
55
var pass, i, il = this.passes.length;
56
57
for ( i = 0; i < il; i ++ ) {
58
59
pass = this.passes[ i ];
60
61
if ( !pass.enabled ) continue;
62
63
pass.render( this.renderer, this.writeBuffer, this.readBuffer, delta, maskActive );
64
65
if ( pass.needsSwap ) {
66
67
if ( maskActive ) {
68
69
var context = this.renderer.context;
70
71
context.stencilFunc( context.NOTEQUAL, 1, 0xffffffff );
72
73
this.copyPass.render( this.renderer, this.writeBuffer, this.readBuffer, delta );
74
75
context.stencilFunc( context.EQUAL, 1, 0xffffffff );
76
77
}
78
79
this.swapBuffers();
80
81
}
82
83
if ( pass instanceof THREE.MaskPass ) {
84
85
maskActive = true;
86
87
} else if ( pass instanceof THREE.ClearMaskPass ) {
88
89
maskActive = false;
90
91
}
92
93
}
94
95
},
96
97
reset: function ( renderTarget ) {
98
99
this.renderTarget1 = renderTarget;
100
101
if ( this.renderTarget1 === undefined ) {
102
103
this.renderTarget1 = new THREE.WebGLRenderTarget( window.innerWidth, window.innerHeight, this.renderTargetParameters );
104
105
}
106
107
this.renderTarget2 = this.renderTarget1.clone();
108
109
this.writeBuffer = this.renderTarget1;
110
this.readBuffer = this.renderTarget2;
111
112
THREE.EffectComposer.quad.scale.set( window.innerWidth, window.innerHeight, 1 );
113
114
THREE.EffectComposer.camera.left = window.innerWidth / - 2;
115
THREE.EffectComposer.camera.right = window.innerWidth / 2;
116
THREE.EffectComposer.camera.top = window.innerHeight / 2;
117
THREE.EffectComposer.camera.bottom = window.innerHeight / - 2;
118
119
THREE.EffectComposer.camera.updateProjectionMatrix();
120
121
}
122
123
};
124
125
// shared ortho camera
126
127
THREE.EffectComposer.initWidth = window.innerWidth || 1;
128
THREE.EffectComposer.initHeight = window.innerHeight || 1;
129
130
THREE.EffectComposer.camera = new THREE.OrthographicCamera( THREE.EffectComposer.initWidth / - 2, THREE.EffectComposer.initWidth / 2, THREE.EffectComposer.initHeight / 2, THREE.EffectComposer.initHeight / - 2, -10000, 10000 );
131
132
// shared fullscreen quad scene
133
134
THREE.EffectComposer.geometry = new THREE.PlaneGeometry( 1, 1 );
135
THREE.EffectComposer.geometry.applyMatrix( new THREE.Matrix4().makeRotationX( Math.PI / 2 ) );
136
137
THREE.EffectComposer.quad = new THREE.Mesh( THREE.EffectComposer.geometry, null );
138
THREE.EffectComposer.quad.position.z = -100;
139
THREE.EffectComposer.quad.scale.set( THREE.EffectComposer.initWidth, THREE.EffectComposer.initHeight, 1 );
140
141
THREE.EffectComposer.scene = new THREE.Scene();
142
THREE.EffectComposer.scene.add( THREE.EffectComposer.quad );
143
THREE.EffectComposer.scene.add( THREE.EffectComposer.camera );
144
145