refreshUniformsCommon method
Implementation
refreshUniformsCommon(Map<String, dynamic> uniforms, Material material) {
uniforms["opacity"]["value"] = material.opacity;
uniforms["diffuse"]["value"].copy(material.color);
if (material.emissive != null) {
uniforms["emissive"]["value"].copy(material.emissive).multiplyScalar(material.emissiveIntensity);
}
if (material.map != null) {
uniforms["map"]["value"] = material.map;
}
if (material.alphaMap != null) {
uniforms["alphaMap"]["value"] = material.alphaMap;
}
if (material.bumpMap != null) {
uniforms["bumpMap"]["value"] = material.bumpMap;
uniforms["bumpScale"]["value"] = material.bumpScale;
if (material.side == BackSide) uniforms["bumpScale"]["value"] *= -1;
}
if (material.displacementMap != null) {
uniforms["displacementMap"]["value"] = material.displacementMap;
uniforms["displacementScale"]["value"] = material.displacementScale;
uniforms["displacementBias"]["value"] = material.displacementBias;
}
if (material.emissiveMap != null) {
uniforms["emissiveMap"]["value"] = material.emissiveMap;
}
if (material.normalMap != null) {
uniforms["normalMap"]["value"] = material.normalMap;
uniforms["normalScale"]["value"].copy(material.normalScale);
if (material.side == BackSide) uniforms["normalScale"]["value"].negate();
}
if (material.specularMap != null) {
uniforms["specularMap"]["value"] = material.specularMap;
}
if (material.alphaTest > 0) {
uniforms["alphaTest"]["value"] = material.alphaTest;
}
var envMap = properties.get(material)["envMap"];
if (envMap != null) {
uniforms["envMap"]["value"] = envMap;
uniforms["flipEnvMap"]["value"] =
(envMap.type == "CubeTexture" && envMap.isRenderTargetTexture == false) ? -1 : 1;
uniforms["reflectivity"]["value"] = material.reflectivity;
uniforms["ior"]["value"] = material.ior;
uniforms["refractionRatio"]["value"] = material.refractionRatio;
}
if (material.lightMap != null) {
uniforms["lightMap"]["value"] = material.lightMap;
// artist-friendly light intensity scaling factor
var scaleFactor = (renderer.physicallyCorrectLights != true) ? Math.pi : 1;
uniforms["lightMapIntensity"]["value"] = material.lightMapIntensity! * scaleFactor;
}
if (material.aoMap != null) {
uniforms["aoMap"]["value"] = material.aoMap;
uniforms["aoMapIntensity"]["value"] = material.aoMapIntensity;
}
// uv repeat and offset setting priorities
// 1. color map
// 2. specular map
// 3. displacementMap map
// 4. normal map
// 5. bump map
// 6. roughnessMap map
// 7. metalnessMap map
// 8. alphaMap map
// 9. emissiveMap map
// 10. clearcoat map
// 11. clearcoat normal map
// 12. clearcoat roughnessMap map
var uvScaleMap;
if (material.map != null) {
uvScaleMap = material.map;
} else if (material.specularMap != null) {
uvScaleMap = material.specularMap;
} else if (material.displacementMap != null) {
uvScaleMap = material.displacementMap;
} else if (material.normalMap != null) {
uvScaleMap = material.normalMap;
} else if (material.bumpMap != null) {
uvScaleMap = material.bumpMap;
} else if (material.roughnessMap != null) {
uvScaleMap = material.roughnessMap;
} else if (material.metalnessMap != null) {
uvScaleMap = material.metalnessMap;
} else if (material.alphaMap != null) {
uvScaleMap = material.alphaMap;
} else if (material.emissiveMap != null) {
uvScaleMap = material.emissiveMap;
} else if (material.clearcoatMap != null) {
uvScaleMap = material.clearcoatMap;
} else if (material.clearcoatNormalMap != null) {
uvScaleMap = material.clearcoatNormalMap;
} else if (material.clearcoatRoughnessMap != null) {
uvScaleMap = material.clearcoatRoughnessMap;
} else if (material.specularIntensityMap != null) {
uvScaleMap = material.specularIntensityMap;
} else if (material.specularColorMap != null) {
uvScaleMap = material.specularColorMap;
} else if (material.transmissionMap != null) {
uvScaleMap = material.transmissionMap;
} else if (material.thicknessMap != null) {
uvScaleMap = material.thicknessMap;
} else if (material.sheenColorMap != null) {
uvScaleMap = material.sheenColorMap;
} else if (material.sheenRoughnessMap != null) {
uvScaleMap = material.sheenRoughnessMap;
}
if (uvScaleMap != null) {
// backwards compatibility
if (uvScaleMap.isWebGLRenderTarget) {
uvScaleMap = uvScaleMap.texture;
}
if (uvScaleMap?.matrixAutoUpdate == true) {
uvScaleMap?.updateMatrix();
}
uniforms["uvTransform"]["value"].copy(uvScaleMap.matrix);
}
// uv repeat and offset setting priorities for uv2
// 1. ao map
// 2. light map
var uv2ScaleMap;
if (material.aoMap != null) {
uv2ScaleMap = material.aoMap;
} else if (material.lightMap != null) {
uv2ScaleMap = material.lightMap;
}
if (uv2ScaleMap != null) {
// backwards compatibility
if (uv2ScaleMap.isWebGLRenderTarget) {
uv2ScaleMap = uv2ScaleMap.texture;
}
if (uv2ScaleMap.matrixAutoUpdate == true) {
uv2ScaleMap.updateMatrix();
}
uniforms["uv2Transform"]["value"].copy(uv2ScaleMap.matrix);
}
}