UnrealBloomPass constructor

UnrealBloomPass(
  1. Vector2? resolution,
  2. num? strength,
  3. double radius,
  4. double threshold,
)

Implementation

UnrealBloomPass(
    Vector2? resolution, num? strength, double radius, double threshold)
    : super() {
  this.strength = strength ?? 1.0;
  this.radius = radius;
  this.threshold = threshold;
  this.resolution = (resolution != null)
      ? new Vector2(resolution.x, resolution.y)
      : new Vector2(256, 256);

  this.uniforms = {
    "strength": {"value": this.strength}
  };

  // create color only once here, reuse it later inside the render function
  this.clearColor = new Color(0, 0, 0);

  // render targets
  var pars = WebGLRenderTargetOptions({
    "minFilter": LinearFilter,
    "magFilter": LinearFilter,
    "format": RGBAFormat
  });
  this.renderTargetsHorizontal = [];
  this.renderTargetsVertical = [];
  this.nMips = 5;
  int resx = (this.resolution.x / 2).toInt();
  int resy = (this.resolution.y / 2).toInt();

  this.renderTargetBright = new WebGLRenderTarget(resx, resy, pars);
  this.renderTargetBright.texture.name = 'UnrealBloomPass.bright';
  this.renderTargetBright.texture.generateMipmaps = false;

  for (var i = 0; i < this.nMips; i++) {
    var renderTargetHorizonal = new WebGLRenderTarget(resx, resy, pars);

    renderTargetHorizonal.texture.name = 'UnrealBloomPass.h' + i.toString();
    renderTargetHorizonal.texture.generateMipmaps = false;

    this.renderTargetsHorizontal.add(renderTargetHorizonal);

    var renderTargetVertical = new WebGLRenderTarget(resx, resy, pars);

    renderTargetVertical.texture.name = 'UnrealBloomPass.v' + i.toString();
    renderTargetVertical.texture.generateMipmaps = false;

    this.renderTargetsVertical.add(renderTargetVertical);

    resx = (resx / 2).toInt();

    resy = (resy / 2).toInt();
  }

  // luminosity high pass material

  if (LuminosityHighPassShader == null) {
    print('THREE.UnrealBloomPass relies on LuminosityHighPassShader');
  }

  var highPassShader = LuminosityHighPassShader;
  this.highPassUniforms = UniformsUtils.clone(highPassShader["uniforms"]);

  this.highPassUniforms['luminosityThreshold']["value"] = threshold;
  this.highPassUniforms['smoothWidth']["value"] = 0.01;

  this.materialHighPassFilter = new ShaderMaterial({
    "uniforms": this.highPassUniforms,
    "vertexShader": highPassShader["vertexShader"],
    "fragmentShader": highPassShader["fragmentShader"],
    "defines": Map<String, dynamic>()
  });

  // Gaussian Blur Materials
  this.separableBlurMaterials = [];
  var kernelSizeArray = [3, 5, 7, 9, 11];
  resx = (this.resolution.x / 2).toInt();
  resy = (this.resolution.y / 2).toInt();

  for (var i = 0; i < this.nMips; i++) {
    this
        .separableBlurMaterials
        .add(this.getSeperableBlurMaterial(kernelSizeArray[i]));

    this.separableBlurMaterials[i].uniforms['texSize']["value"] =
        new Vector2(resx.toDouble(), resy.toDouble());

    resx = (resx / 2).toInt();

    resy = (resy / 2).toInt();
  }

  // Composite material
  this.compositeMaterial = this.getCompositeMaterial(this.nMips);
  this.compositeMaterial.uniforms['blurTexture1']["value"] =
      this.renderTargetsVertical[0].texture;
  this.compositeMaterial.uniforms['blurTexture2']["value"] =
      this.renderTargetsVertical[1].texture;
  this.compositeMaterial.uniforms['blurTexture3']["value"] =
      this.renderTargetsVertical[2].texture;
  this.compositeMaterial.uniforms['blurTexture4']["value"] =
      this.renderTargetsVertical[3].texture;
  this.compositeMaterial.uniforms['blurTexture5']["value"] =
      this.renderTargetsVertical[4].texture;
  this.compositeMaterial.uniforms['bloomStrength']["value"] = this.strength;
  this.compositeMaterial.uniforms['bloomRadius']["value"] = 0.1;
  this.compositeMaterial.needsUpdate = true;

  var bloomFactors = [1.0, 0.8, 0.6, 0.4, 0.2];
  this.compositeMaterial.uniforms['bloomFactors']["value"] = bloomFactors;
  this.bloomTintColors = [
    new Vector3(1, 1, 1),
    new Vector3(1, 1, 1),
    new Vector3(1, 1, 1),
    new Vector3(1, 1, 1),
    new Vector3(1, 1, 1)
  ];
  this.compositeMaterial.uniforms['bloomTintColors']["value"] =
      this.bloomTintColors;

  // copy material
  if (CopyShader == null) {
    print('THREE.UnrealBloomPass relies on CopyShader');
  }

  var copyShader = CopyShader;

  this.copyUniforms = UniformsUtils.clone(copyShader["uniforms"]);
  this.copyUniforms['opacity']["value"] = 1.0;

  this.materialCopy = new ShaderMaterial({
    "uniforms": this.copyUniforms,
    "vertexShader": copyShader["vertexShader"],
    "fragmentShader": copyShader["fragmentShader"],
    "blending": AdditiveBlending,
    "depthTest": false,
    "depthWrite": false,
    "transparent": true
  });

  this.enabled = true;
  this.needsSwap = false;

  this.oldClearColor = Color.fromHex(0xffffff);
  this.oldClearAlpha = 0.0;

  this.basic = new MeshBasicMaterial(Map<String, dynamic>());

  this.fsQuad = FullScreenQuad(null);
}