getDepthMaterial method

Material getDepthMaterial(
  1. Object3D object,
  2. Material material,
  3. Light light,
  4. num shadowCameraNear,
  5. num shadowCameraFar,
  6. int type,
)

Implementation

Material getDepthMaterial(Object3D object, Material material, Light light,
    num shadowCameraNear, num shadowCameraFar, int type) {
  Material? result;

  var customMaterial = light is PointLight
      ? object.customDistanceMaterial
      : object.customDepthMaterial;

  if (customMaterial != null) {
    result = customMaterial;
  } else {
    result = light is PointLight ? _distanceMaterial : _depthMaterial;
  }

  if (_renderer.localClippingEnabled &&
      material.clipShadows == true &&
      material.clippingPlanes!.isNotEmpty) {
    // in this case we need a unique material instance reflecting the
    // appropriate state

    var keyA = result.uuid;
    var keyB = material.uuid;

    var materialsForVariant = _materialCache[keyA];

    if (materialsForVariant == null) {
      materialsForVariant = {};
      _materialCache[keyA] = materialsForVariant;
    }

    var cachedMaterial = materialsForVariant[keyB];

    if (cachedMaterial == null) {
      cachedMaterial = result.clone();
      materialsForVariant[keyB] = cachedMaterial;
    }

    result = cachedMaterial;
  }

  result!.visible = material.visible;
  result.wireframe = material.wireframe;

  if (type == VSMShadowMap) {
    result.side =
        (material.shadowSide != null) ? material.shadowSide! : material.side;
  } else {
    result.side = (material.shadowSide != null)
        ? material.shadowSide!
        : shadowSide[material.side]!;
  }

  result.clipShadows = material.clipShadows;
  result.clippingPlanes = material.clippingPlanes;
  result.clipIntersection = material.clipIntersection;

  result.wireframeLinewidth = material.wireframeLinewidth;
  result.linewidth = material.linewidth;

  if (light is PointLight == true && result is MeshDistanceMaterial) {
    result.referencePosition.setFromMatrixPosition(light.matrixWorld);
    result.nearDistance = shadowCameraNear;
    result.farDistance = shadowCameraFar;

    return result;
  } else {
    return result;
  }
}