@polygonjs/polygonjs
Version:
node-based WebGL 3D engine https://polygonjs.com
56 lines (55 loc) • 1.85 kB
JavaScript
;
import { TypedPostNode, PostParamOptions } from "./_Base";
import { NodeParamsConfig, ParamConfig } from "../utils/params/ParamsConfig";
import { BlendFunction, EffectPass, PredicationMode, SMAAEffect, TextureEffect, SMAAPreset } from "postprocessing";
class AntialiasingPostParamsConfig extends NodeParamsConfig {
constructor() {
super(...arguments);
/** @param opacity */
this.opacity = ParamConfig.FLOAT(1, {
range: [0, 1],
rangeLocked: [true, true],
...PostParamOptions
});
}
}
const ParamsConfig = new AntialiasingPostParamsConfig();
export class AntialiasingPostNode extends TypedPostNode {
constructor() {
super(...arguments);
this.paramsConfig = ParamsConfig;
}
static type() {
return "antialiasing";
}
createPass(context) {
const smaaEffect = new SMAAEffect(
{
preset: SMAAPreset.ULTRA
}
// assets.get("smaa-search"),
// assets.get("smaa-area"),
// SMAAPreset.HIGH,
// EdgeDetectionMode.COLOR
);
smaaEffect.edgeDetectionMaterial.edgeDetectionThreshold = 0.02;
smaaEffect.edgeDetectionMaterial.predicationMode = PredicationMode.DEPTH;
smaaEffect.edgeDetectionMaterial.predicationThreshold = 2e-3;
smaaEffect.edgeDetectionMaterial.predicationScale = 1;
const edgesTextureEffect = new TextureEffect({
blendFunction: BlendFunction.SKIP,
texture: smaaEffect.edgesTexture
});
const weightsTextureEffect = new TextureEffect({
blendFunction: BlendFunction.SKIP,
texture: smaaEffect.weightsTexture
});
const pass = new EffectPass(context.camera, smaaEffect, edgesTextureEffect, weightsTextureEffect);
this.updatePass(pass);
return pass;
}
updatePass(pass) {
const effect = pass.effects[0];
effect.blendMode.opacity.value = this.pv.opacity;
}
}