patchMaterial method

void patchMaterial()

Implementation

void patchMaterial(){
  final shaderMap = new Map<String, WebGLParameters>();

  this.onBeforeCompile = (WebGLParameters shader, WebGLRenderer renderer) {
    final hexTilingID = genRandomStringID;
    this.hexTilingID = hexTilingID;
    shaderMap[hexTilingID] = shader;

    if (this.hexTiling != null) {
      this.defines?['USE_THREE_HEX_TILING'] = "";
    }
  };

  this.customProgramCacheKey = (){
    return this.hexTiling != null? "1": "0";
  };

  // internal ID used to match the shader to the material so that the custom uniforms can be updated
  // from the material
  this.onBeforeRender = (
    WebGLRenderer? renderer,
    Scene? scene,
    Camera? camera,
    BufferGeometry? geometry,
    Object3D? object,
    Map<String, dynamic>? group
  ) {
    final shaderRef = shaderMap[hexTilingID];
    if (shaderRef == null) {
      return;
    }

    final params = this.hexTiling ?? HexTilingParams();

    shaderRef.uniforms!['hexTilingPatchScale']['value'] = params.patchScale;
    shaderRef.uniforms!['hexTilingUseContrastCorrectedBlending']['value'] = params.useContrastCorrectedBlending;
    shaderRef.uniforms!['hexTilingLookupSkipThreshold']['value'] = params.lookupSkipThreshold;
    shaderRef.uniforms!['hexTilingTextureSampleCoefficientExponent']['value'] = params.textureSampleCoefficientExponent;
  };
}