75 lines
1.8 KiB
JavaScript
75 lines
1.8 KiB
JavaScript
|
|
"use strict";
|
||
|
|
|
||
|
|
Object.defineProperty(exports, "__esModule", {
|
||
|
|
value: true
|
||
|
|
});
|
||
|
|
exports.default = void 0;
|
||
|
|
|
||
|
|
var _Matrix = require("claygl/src/math/Matrix4");
|
||
|
|
|
||
|
|
var _Vector = require("claygl/src/math/Vector3");
|
||
|
|
|
||
|
|
var _Texture2D = require("claygl/src/Texture2D");
|
||
|
|
|
||
|
|
var _Texture = require("claygl/src/Texture");
|
||
|
|
|
||
|
|
var _Pass = require("claygl/src/compositor/Pass");
|
||
|
|
|
||
|
|
var _Shader = require("claygl/src/Shader");
|
||
|
|
|
||
|
|
var _FrameBuffer = require("claygl/src/FrameBuffer");
|
||
|
|
|
||
|
|
function EdgePass(opt) {
|
||
|
|
opt = opt || {};
|
||
|
|
this._edgePass = new _Pass.default({
|
||
|
|
fragment: _Shader.default.source('ecgl.edge')
|
||
|
|
});
|
||
|
|
|
||
|
|
this._edgePass.setUniform('normalTexture', opt.normalTexture);
|
||
|
|
|
||
|
|
this._edgePass.setUniform('depthTexture', opt.depthTexture);
|
||
|
|
|
||
|
|
this._targetTexture = new _Texture2D.default({
|
||
|
|
type: _Texture.default.HALF_FLOAT
|
||
|
|
});
|
||
|
|
this._frameBuffer = new _FrameBuffer.default();
|
||
|
|
|
||
|
|
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);
|
||
|
|
};
|
||
|
|
|
||
|
|
var _default = EdgePass;
|
||
|
|
exports.default = _default;
|