src/effects/ChromaticAberrationEffect.js
import { Uniform, Vector2 } from "three";
import { BlendFunction } from "./blending/BlendFunction.js";
import { Effect, EffectAttribute } from "./Effect.js";
import fragment from "./glsl/chromatic-aberration/shader.frag";
import vertex from "./glsl/chromatic-aberration/shader.vert";
/**
* A chromatic aberration effect.
*/
export class ChromaticAberrationEffect extends Effect {
/**
* Constructs a new chromatic aberration effect.
*
* @param {Object} [options] - The options.
* @param {BlendFunction} [options.blendFunction=BlendFunction.NORMAL] - The blend function of this effect.
* @param {Vector2} [options.offset] - The color offset.
*/
constructor(options = {}) {
const settings = Object.assign({
blendFunction: BlendFunction.NORMAL,
offset: new Vector2(0.001, 0.0005)
}, options);
super("ChromaticAberrationEffect", fragment, {
attributes: EffectAttribute.CONVOLUTION,
blendFunction: settings.blendFunction,
uniforms: new Map([
["offset", new Uniform(settings.offset)]
]),
vertexShader: vertex
});
}
/**
* The color offset.
*
* @type {Vector2}
*/
get offset() {
return this.uniforms.get("offset").value;
}
/**
* @type {Vector2}
*/
set offset(value) {
this.uniforms.get("offset").value = value;
}
}