EdgePass.js
1.7 KB
1
2
3
4
5
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
57
import Matrix4 from 'claygl/src/math/Matrix4';
import Vector3 from 'claygl/src/math/Vector3';
import Texture2D from 'claygl/src/Texture2D';
import Texture from 'claygl/src/Texture';
import Pass from 'claygl/src/compositor/Pass';
import Shader from 'claygl/src/Shader';
import FrameBuffer from 'claygl/src/FrameBuffer';
function EdgePass(opt) {
opt = opt || {};
this._edgePass = new Pass({
fragment: Shader.source('ecgl.edge')
});
this._edgePass.setUniform('normalTexture', opt.normalTexture);
this._edgePass.setUniform('depthTexture', opt.depthTexture);
this._targetTexture = new Texture2D({
type: Texture.HALF_FLOAT
});
this._frameBuffer = new FrameBuffer();
this._frameBuffer.attach(this._targetTexture);
}
EdgePass.prototype.update = function (renderer, camera, sourceTexture, frame) {
var width = renderer.getWidth();
var height = renderer.getHeight();
var texture = this._targetTexture;
texture.width = width;
texture.height = height;
var frameBuffer = this._frameBuffer;
frameBuffer.bind(renderer);
this._edgePass.setUniform('projectionInv', camera.invProjectionMatrix.array);
this._edgePass.setUniform('textureSize', [width, height]);
this._edgePass.setUniform('texture', sourceTexture);
this._edgePass.render(renderer);
frameBuffer.unbind(renderer);
};
EdgePass.prototype.getTargetTexture = function () {
return this._targetTexture;
};
EdgePass.prototype.setParameter = function (name, val) {
this._edgePass.setUniform(name, val);
};
EdgePass.prototype.dispose = function (renderer) {
this._targetTexture.dispose(renderer);
this._frameBuffer.dispose(renderer);
};
export default EdgePass;