getDepthMaterial method
Implementation
Material getDepthMaterial(
Object3D object,
Material material,
Light light,
double shadowCameraNear,
double shadowCameraFar,
int type
) {
Material? result;
final 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
) ||
(material.displacementMap != null && material.displacementScale != 0 ) ||
( material.alphaMap != null && material.alphaTest > 0 ) ||
(material.map != null && material.alphaTest > 0)
) {
// in this case we need a unique material instance reflecting the
// appropriate state
final keyA = result.uuid;
final keyB = material.uuid;
Map? materialsForVariant = _materialCache[keyA];
if (materialsForVariant == null) {
materialsForVariant = {};
_materialCache[keyA] = materialsForVariant;
}
Material? 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.alphaMap = material.alphaMap;
result.alphaTest = material.alphaTest;
result.map = material.map;
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;
}
}