molstar
Version:
A comprehensive macromolecular library.
94 lines • 5.66 kB
JavaScript
/**
* Copyright (c) 2020 mol* contributors, licensed under MIT, See LICENSE file for more info.
*
* @author Alexander Rose <alexander.rose@weirdbyte.de>
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.FxaaPass = exports.FxaaParams = void 0;
var tslib_1 = require("tslib");
var util_1 = require("../../mol-gl/compute/util");
var renderable_1 = require("../../mol-gl/renderable");
var schema_1 = require("../../mol-gl/renderable/schema");
var shader_code_1 = require("../../mol-gl/shader-code");
var render_item_1 = require("../../mol-gl/webgl/render-item");
var linear_algebra_1 = require("../../mol-math/linear-algebra");
var mol_util_1 = require("../../mol-util");
var param_definition_1 = require("../../mol-util/param-definition");
var quad_vert_1 = require("../../mol-gl/shader/quad.vert");
var fxaa_frag_1 = require("../../mol-gl/shader/fxaa.frag");
exports.FxaaParams = {
edgeThresholdMin: param_definition_1.ParamDefinition.Numeric(0.0312, { min: 0.0312, max: 0.0833, step: 0.0001 }, { description: 'Trims the algorithm from processing darks.' }),
edgeThresholdMax: param_definition_1.ParamDefinition.Numeric(0.063, { min: 0.063, max: 0.333, step: 0.001 }, { description: 'The minimum amount of local contrast required to apply algorithm.' }),
iterations: param_definition_1.ParamDefinition.Numeric(12, { min: 0, max: 16, step: 1 }, { description: 'Number of edge exploration steps.' }),
subpixelQuality: param_definition_1.ParamDefinition.Numeric(0.30, { min: 0.00, max: 1.00, step: 0.01 }, { description: 'Choose the amount of sub-pixel aliasing removal.' }),
};
var FxaaPass = /** @class */ (function () {
function FxaaPass(webgl, input) {
this.webgl = webgl;
this.renderable = getFxaaRenderable(webgl, input);
}
FxaaPass.prototype.updateState = function (viewport) {
var _a = this.webgl, gl = _a.gl, state = _a.state;
state.enable(gl.SCISSOR_TEST);
state.disable(gl.BLEND);
state.disable(gl.DEPTH_TEST);
state.depthMask(false);
var x = viewport.x, y = viewport.y, width = viewport.width, height = viewport.height;
gl.viewport(x, y, width, height);
gl.scissor(x, y, width, height);
state.clearColor(0, 0, 0, 1);
gl.clear(gl.COLOR_BUFFER_BIT);
};
FxaaPass.prototype.setSize = function (width, height) {
mol_util_1.ValueCell.update(this.renderable.values.uTexSizeInv, linear_algebra_1.Vec2.set(this.renderable.values.uTexSizeInv.ref.value, 1 / width, 1 / height));
};
FxaaPass.prototype.update = function (input, props) {
var values = this.renderable.values;
var edgeThresholdMin = props.edgeThresholdMin, edgeThresholdMax = props.edgeThresholdMax, iterations = props.iterations, subpixelQuality = props.subpixelQuality;
var needsUpdate = false;
if (values.tColor.ref.value !== input) {
mol_util_1.ValueCell.update(this.renderable.values.tColor, input);
needsUpdate = true;
}
if (values.dEdgeThresholdMin.ref.value !== edgeThresholdMin)
needsUpdate = true;
mol_util_1.ValueCell.updateIfChanged(values.dEdgeThresholdMin, edgeThresholdMin);
if (values.dEdgeThresholdMax.ref.value !== edgeThresholdMax)
needsUpdate = true;
mol_util_1.ValueCell.updateIfChanged(values.dEdgeThresholdMax, edgeThresholdMax);
if (values.dIterations.ref.value !== iterations)
needsUpdate = true;
mol_util_1.ValueCell.updateIfChanged(values.dIterations, iterations);
if (values.dSubpixelQuality.ref.value !== subpixelQuality)
needsUpdate = true;
mol_util_1.ValueCell.updateIfChanged(values.dSubpixelQuality, subpixelQuality);
if (needsUpdate) {
this.renderable.update();
}
};
FxaaPass.prototype.render = function (viewport, target) {
if (target) {
target.bind();
}
else {
this.webgl.unbindFramebuffer();
}
this.updateState(viewport);
this.renderable.render();
};
return FxaaPass;
}());
exports.FxaaPass = FxaaPass;
//
var FxaaSchema = (0, tslib_1.__assign)((0, tslib_1.__assign)({}, util_1.QuadSchema), { tColor: (0, schema_1.TextureSpec)('texture', 'rgba', 'ubyte', 'linear'), uTexSizeInv: (0, schema_1.UniformSpec)('v2'), dEdgeThresholdMin: (0, schema_1.DefineSpec)('number'), dEdgeThresholdMax: (0, schema_1.DefineSpec)('number'), dIterations: (0, schema_1.DefineSpec)('number'), dSubpixelQuality: (0, schema_1.DefineSpec)('number') });
var FxaaShaderCode = (0, shader_code_1.ShaderCode)('fxaa', quad_vert_1.quad_vert, fxaa_frag_1.fxaa_frag);
function getFxaaRenderable(ctx, colorTexture) {
var width = colorTexture.getWidth();
var height = colorTexture.getHeight();
var values = (0, tslib_1.__assign)((0, tslib_1.__assign)({}, util_1.QuadValues), { tColor: mol_util_1.ValueCell.create(colorTexture), uTexSizeInv: mol_util_1.ValueCell.create(linear_algebra_1.Vec2.create(1 / width, 1 / height)), dEdgeThresholdMin: mol_util_1.ValueCell.create(0.0312), dEdgeThresholdMax: mol_util_1.ValueCell.create(0.125), dIterations: mol_util_1.ValueCell.create(12), dSubpixelQuality: mol_util_1.ValueCell.create(0.3) });
var schema = (0, tslib_1.__assign)({}, FxaaSchema);
var renderItem = (0, render_item_1.createComputeRenderItem)(ctx, 'triangles', FxaaShaderCode, schema, values);
return (0, renderable_1.createComputeRenderable)(renderItem, values);
}
//# sourceMappingURL=fxaa.js.map
;