getParameters method

WebGLParameters getParameters(
  1. Material material,
  2. LightState lights,
  3. dynamic shadows,
  4. dynamic scene,
  5. dynamic object,
)

Implementation

WebGLParameters getParameters(
    Material material, LightState lights, shadows, scene, object) {
  var fog = scene.fog;
  var geometry = object.geometry;
  var environment =
      material is MeshStandardMaterial ? scene.environment : null;

  Texture? envMap;
  if (material is MeshStandardMaterial) {
    envMap = cubeuvmaps.get(material.envMap ?? environment);
  } else {
    envMap = cubemaps.get(material.envMap ?? environment);
  }

  var cubeUVHeight = (envMap != null) &&
          (envMap.mapping == CubeUVReflectionMapping)
      ? envMap.image.height
      : null;

  var shaderID = shaderIDs[material.shaderID];

  // heuristics to create shader parameters according to lights in the scene
  // (not to blow over maxLights budget)

  if (material.precision != null) {
    precision = capabilities.getMaxPrecision(material.precision);

    if (precision != material.precision) {
      print(
          'THREE.WebGLProgram.getParameters: ${material.precision} not supported, using $precision instead.');
    }
  }

  var morphAttribute = geometry.morphAttributes["position"] ??
      geometry.morphAttributes["normal"] ??
      geometry.morphAttributes["color"];
  var morphTargetsCount =
      (morphAttribute != null) ? morphAttribute.length : 0;

  var morphTextureStride = 0;

  if (geometry.morphAttributes["position"] != null) morphTextureStride = 1;
  if (geometry.morphAttributes["normal"] != null) morphTextureStride = 2;
  if (geometry.morphAttributes["color"] != null) morphTextureStride = 3;

  //

  String? vertexShader, fragmentShader;
  var customVertexShaderID, customFragmentShaderID;

  if (shaderID != null) {
    var shader = ShaderLib[shaderID];
    vertexShader = shader["vertexShader"];
    fragmentShader = shader["fragmentShader"];
  } else {
    vertexShader = material.vertexShader;
    fragmentShader = material.fragmentShader;

    _customShaders.update(material);

    customVertexShaderID = _customShaders.getVertexShaderID(material);
    customFragmentShaderID = _customShaders.getFragmentShaderID(material);
  }

  // print(" WebGLPrograms material : ${material.type} ${material.shaderID} ${material.id} object: ${object.type} ${object.id} shaderID: ${shaderID} vertexColors: ${material.vertexColors} ");

  var currentRenderTarget = renderer.getRenderTarget();

  var useAlphaTest = material.alphaTest > 0;
  var useClearcoat = material.clearcoat > 0;



  var parameters = WebGLParameters({
    "isWebGL2": isWebGL2,
    "shaderID": shaderID,
    "shaderName": material.type + " - " + material.name,
    "vertexShader": vertexShader,
    "fragmentShader": fragmentShader,
    "defines": material.defines,
    "customVertexShaderID": customVertexShaderID,
    "customFragmentShaderID": customFragmentShaderID,
    "isRawShaderMaterial": material is RawShaderMaterial,
    "glslVersion": material.glslVersion,
    "precision": precision,
    "instancing": object is InstancedMesh,
    "instancingColor":
        object is InstancedMesh && object.instanceColor != null,
    "supportsVertexTextures": vertexTextures,
    "outputEncoding": (currentRenderTarget == null)
        ? renderer.outputEncoding
        : (currentRenderTarget.isXRRenderTarget == true
            ? currentRenderTarget.texture.encoding
            : LinearEncoding),
    "map": material.map != null,
    "matcap": material.matcap != null,
    "envMap": envMap != null,
    "envMapMode": envMap?.mapping,
    "cubeUVHeight": cubeUVHeight,
    "lightMap": material.lightMap != null,
    "aoMap": material.aoMap != null,
    "emissiveMap": material.emissiveMap != null,
    "bumpMap": material.bumpMap != null,
    "normalMap": material.normalMap != null,
    "objectSpaceNormalMap": material.normalMapType == ObjectSpaceNormalMap,
    "tangentSpaceNormalMap": material.normalMapType == TangentSpaceNormalMap,
    "decodeVideoTexture": material.map != null &&
        (material.map is VideoTexture) &&
        (material.map!.encoding == sRGBEncoding),
    "clearcoat": useClearcoat,
    "clearcoatMap": useClearcoat && material.clearcoatMap != null,
    "clearcoatRoughnessMap":
        useClearcoat && material.clearcoatRoughnessMap != null,
    "clearcoatNormalMap": useClearcoat && material.clearcoatNormalMap != null,
    "displacementMap": material.displacementMap != null,
    "roughnessMap": material.roughnessMap != null,
    "metalnessMap": material.metalnessMap != null,
    "specularMap": material.specularMap != null,
    "specularIntensityMap": material.specularIntensityMap != null,
    "specularColorMap": material.specularColorMap != null,
    "opaque": material.transparent == false && material.blending == NormalBlending,
    "alphaMap": material.alphaMap != null,
    "alphaTest": useAlphaTest,
    "gradientMap": material.gradientMap != null,
    "sheen": material.sheen > 0,
    "sheenColorMap": material.sheenColorMap != null,
    "sheenRoughnessMap": material.sheenRoughnessMap != null,
    "transmission": material.transmission > 0,
    "transmissionMap": material.transmissionMap != null,
    "thicknessMap": material.thicknessMap != null,
    "combine": material.combine,
    "vertexTangents": (material.normalMap != null &&
        geometry != null &&
        geometry.attributes["tangent"] != null),
    "vertexColors": material.vertexColors,
    "vertexAlphas": material.vertexColors == true &&
        geometry != null &&
        geometry.attributes["color"] != null &&
        geometry.attributes["color"].itemSize == 4,
    "vertexUvs": material.map != null ||
        material.bumpMap != null ||
        material.normalMap != null ||
        material.specularMap != null ||
        material.alphaMap != null ||
        material.emissiveMap != null ||
        material.roughnessMap != null ||
        material.metalnessMap != null ||
        material.clearcoatMap != null ||
        material.clearcoatRoughnessMap != null ||
        material.clearcoatNormalMap != null ||
        material.displacementMap != null ||
        material.transmissionMap != null ||
        material.thicknessMap != null ||
        material.specularIntensityMap != null ||
        material.specularColorMap != null ||
        material.sheenColorMap != null ||
        material.sheenRoughnessMap != null,
    "uvsVertexOnly": !(material.map != null ||
            material.bumpMap != null ||
            material.normalMap != null ||
            material.specularMap != null ||
            material.alphaMap != null ||
            material.emissiveMap != null ||
            material.roughnessMap != null ||
            material.metalnessMap != null ||
            material.clearcoatNormalMap != null ||
            material.transmission != null ||
            material.transmissionMap != null ||
            material.thicknessMap != null ||
            material.sheen > 0 ||
            material.sheenColorMap != null ||
            material.sheenRoughnessMap != null) &&
        material.displacementMap != null,
    "flipNormalScaleY":
        ((material.normalMap != null && material.normalMap!.flipY == false ||
                material.clearcoatNormalMap != null &&
                    material.clearcoatNormalMap!.flipY == false) &&
            !(object.geometry != null &&
                object.geometry.attributes["tangent"] != null)),
    "fog": fog != null,
    "useFog": material.fog,
    "fogExp2": (fog != null && fog.isFogExp2),
    "flatShading": material.flatShading,
    "sizeAttenuation": material.sizeAttenuation,
    "logarithmicDepthBuffer": logarithmicDepthBuffer,
    "skinning": object is SkinnedMesh,
    "morphTargets":
        geometry != null && geometry.morphAttributes["position"] != null,
    "morphNormals":
        geometry != null && geometry.morphAttributes["normal"] != null,
    "morphColors":
        geometry != null && geometry.morphAttributes["color"] != null,
    "morphTargetsCount": morphTargetsCount,
    "morphTextureStride": morphTextureStride,
    "numDirLights": lights.directional.length,
    "numPointLights": lights.point.length,
    "numSpotLights": lights.spot.length,
    "numRectAreaLights": lights.rectArea.length,
    "numHemiLights": lights.hemi.length,
    "numDirLightShadows": lights.directionalShadowMap.length,
    "numPointLightShadows": lights.pointShadowMap.length,
    "numSpotLightShadows": lights.spotShadowMap.length,
    "numClippingPlanes": clipping.numPlanes,
    "numClipIntersection": clipping.numIntersection,
    "dithering": material.dithering,
    "shadowMapEnabled": renderer.shadowMap.enabled && shadows.length > 0,
    "shadowMapType": renderer.shadowMap.type,
    "toneMapping": material.toneMapped ? renderer.toneMapping : NoToneMapping,
    "physicallyCorrectLights": renderer.physicallyCorrectLights,
    "premultipliedAlpha": material.premultipliedAlpha,
    "doubleSided": material.side == DoubleSide,
    "flipSided": material.side == BackSide,
    "useDepthPacking": material.depthPacking != null,
    "depthPacking": material.depthPacking ?? 0,
    "index0AttributeName": material.index0AttributeName,
    "extensionDerivatives": material.extensions != null &&
        material.extensions!["derivatives"] != null,
    "extensionFragDepth": material.extensions != null &&
        material.extensions!["fragDepth"] != null,
    "extensionDrawBuffers": material.extensions != null &&
        material.extensions!["drawBuffers"] != null,
    "extensionShaderTextureLOD": material.extensions != null &&
        material.extensions!["shaderTextureLOD"] != null,
    "rendererExtensionFragDepth":
        isWebGL2 ? isWebGL2 : extensions.has('EXT_frag_depth'),
    "rendererExtensionDrawBuffers":
        isWebGL2 ? isWebGL2 : extensions.has('WEBGL_draw_buffers'),
    "rendererExtensionShaderTextureLod":
        isWebGL2 ? isWebGL2 : extensions.has('EXT_shader_texture_lod'),
    "customProgramCacheKey": material.customProgramCacheKey()
  });

  return parameters;
}