UnrealBloomPass constructor
UnrealBloomPass(
- Vector2? resolution,
- num? strength,
- double radius,
- double threshold,
)
Implementation
UnrealBloomPass(Vector2? resolution, num? strength, this.radius, this.threshold) : super() {
this.strength = strength ?? 1.0;
this.resolution = (resolution != null) ? Vector2(resolution.x, resolution.y) : Vector2(256, 256);
uniforms = {
"strength": {"value": this.strength}
};
// create color only once here, reuse it later inside the render function
clearColor = Color(0, 0, 0);
// render targets
var pars = WebGLRenderTargetOptions({"minFilter": LinearFilter, "magFilter": LinearFilter, "format": RGBAFormat});
renderTargetsHorizontal = [];
renderTargetsVertical = [];
nMips = 5;
int resx = this.resolution.x ~/ 2;
int resy = this.resolution.y ~/ 2;
renderTargetBright = WebGLRenderTarget(resx, resy, pars);
renderTargetBright.texture.name = 'UnrealBloomPass.bright';
renderTargetBright.texture.generateMipmaps = false;
for (var i = 0; i < nMips; i++) {
var renderTargetHorizonal = WebGLRenderTarget(resx, resy, pars);
renderTargetHorizonal.texture.name = 'UnrealBloomPass.h$i';
renderTargetHorizonal.texture.generateMipmaps = false;
renderTargetsHorizontal.add(renderTargetHorizonal);
var renderTargetVertical = WebGLRenderTarget(resx, resy, pars);
renderTargetVertical.texture.name = 'UnrealBloomPass.v$i';
renderTargetVertical.texture.generateMipmaps = false;
renderTargetsVertical.add(renderTargetVertical);
resx = resx ~/ 2;
resy = resy ~/ 2;
}
// luminosity high pass material
var highPassShader = luminosityHighPassShader;
highPassUniforms = UniformsUtils.clone(highPassShader["uniforms"]);
highPassUniforms['luminosityThreshold']["value"] = threshold;
highPassUniforms['smoothWidth']["value"] = 0.01;
materialHighPassFilter = ShaderMaterial({
"uniforms": highPassUniforms,
"vertexShader": highPassShader["vertexShader"],
"fragmentShader": highPassShader["fragmentShader"],
"defines": <String, dynamic>{}
});
// Gaussian Blur Materials
separableBlurMaterials = [];
var kernelSizeArray = [3, 5, 7, 9, 11];
resx = this.resolution.x ~/ 2;
resy = this.resolution.y ~/ 2;
for (var i = 0; i < nMips; i++) {
separableBlurMaterials.add(getSeperableBlurMaterial(kernelSizeArray[i]));
separableBlurMaterials[i].uniforms['texSize']["value"] = Vector2(resx.toDouble(), resy.toDouble());
resx = resx ~/ 2;
resy = resy ~/ 2;
}
// Composite material
compositeMaterial = getCompositeMaterial(nMips);
compositeMaterial.uniforms['blurTexture1']["value"] = renderTargetsVertical[0].texture;
compositeMaterial.uniforms['blurTexture2']["value"] = renderTargetsVertical[1].texture;
compositeMaterial.uniforms['blurTexture3']["value"] = renderTargetsVertical[2].texture;
compositeMaterial.uniforms['blurTexture4']["value"] = renderTargetsVertical[3].texture;
compositeMaterial.uniforms['blurTexture5']["value"] = renderTargetsVertical[4].texture;
compositeMaterial.uniforms['bloomStrength']["value"] = this.strength;
compositeMaterial.uniforms['bloomRadius']["value"] = 0.1;
compositeMaterial.needsUpdate = true;
var bloomFactors = [1.0, 0.8, 0.6, 0.4, 0.2];
compositeMaterial.uniforms['bloomFactors']["value"] = bloomFactors;
bloomTintColors = [Vector3(1, 1, 1), Vector3(1, 1, 1), Vector3(1, 1, 1), Vector3(1, 1, 1), Vector3(1, 1, 1)];
compositeMaterial.uniforms['bloomTintColors']["value"] = bloomTintColors;
// copy material
copyUniforms = UniformsUtils.clone(copyShader["uniforms"]);
copyUniforms['opacity']["value"] = 1.0;
materialCopy = ShaderMaterial({
"uniforms": copyUniforms,
"vertexShader": copyShader["vertexShader"],
"fragmentShader": copyShader["fragmentShader"],
"blending": AdditiveBlending,
"depthTest": false,
"depthWrite": false,
"transparent": true
});
enabled = true;
needsSwap = false;
oldClearColor = Color.fromHex(0xffffff);
oldClearAlpha = 0.0;
basic = MeshBasicMaterial(<String, dynamic>{});
fsQuad = FullScreenQuad(null);
}