function initMaterial(material, scene, object) {
if (scene.isScene !== true) scene = _emptyScene;
const materialProperties = properties.get(material);
const lights = currentRenderState.state.lights;
const shadowsArray = currentRenderState.state.shadowsArray;
const lightsStateVersion = lights.state.version;
const parameters = programCache.getParameters(
material,
lights.state,
shadowsArray,
scene,
_clipping.numPlanes,
_clipping.numIntersection,
object
);
const programCacheKey = programCache.getProgramCacheKey(parameters);
let program = materialProperties.program;
let programChange = true;
if (program === undefined) {
material.addEventListener('dispose', onMaterialDispose);
} else if (program.cacheKey !== programCacheKey) {
releaseMaterialProgramReference(material);
} else if (materialProperties.lightsStateVersion !== lightsStateVersion) {
materialProperties.lightsStateVersion = lightsStateVersion;
programChange = false;
} else if (parameters.shaderID !== undefined) {
return;
} else {
programChange = false;
}
if (programChange) {
parameters.uniforms = programCache.getUniforms(material, parameters);
material.onBeforeCompile(parameters, _this);
if(material.onBeforeOITCompile) material.onBeforeOITCompile(parameters, _this);
program = programCache.acquireProgram(parameters, programCacheKey);
materialProperties.program = program;
materialProperties.uniforms = parameters.uniforms;
materialProperties.outputEncoding = parameters.outputEncoding;
}
const programAttributes = program.getAttributes();
if (material.morphTargets) {
material.numSupportedMorphTargets = 0;
for (let i = 0; i < _this.maxMorphTargets; i++) {
if (programAttributes['morphTarget' + i] >= 0) {
material.numSupportedMorphTargets++;
}
}
}
if (material.morphNormals) {
material.numSupportedMorphNormals = 0;
for (let i = 0; i < _this.maxMorphNormals; i++) {
if (programAttributes['morphNormal' + i] >= 0) {
material.numSupportedMorphNormals++;
}
}
}
const uniforms = materialProperties.uniforms;
if ((!material.isShaderMaterial && !material.isRawShaderMaterial) || material.clipping === true) {
materialProperties.numClippingPlanes = _clipping.numPlanes;
materialProperties.numIntersection = _clipping.numIntersection;
uniforms.clippingPlanes = _clipping.uniform;
}
materialProperties.environment = material.isMeshStandardMaterial ? scene.environment : null;
materialProperties.fog = scene.fog;
materialProperties.needsLights = materialNeedsLights(material);
materialProperties.lightsStateVersion = lightsStateVersion;
if (materialProperties.needsLights) {
uniforms.ambientLightColor.value = lights.state.ambient;
uniforms.lightProbe.value = lights.state.probe;
uniforms.directionalLights.value = lights.state.directional;
uniforms.directionalLightShadows.value = lights.state.directionalShadow;
uniforms.spotLights.value = lights.state.spot;
uniforms.spotLightShadows.value = lights.state.spotShadow;
uniforms.rectAreaLights.value = lights.state.rectArea;
uniforms.pointLights.value = lights.state.point;
uniforms.pointLightShadows.value = lights.state.pointShadow;
uniforms.hemisphereLights.value = lights.state.hemi;
uniforms.directionalShadowMap.value = lights.state.directionalShadowMap;
uniforms.directionalShadowMatrix.value = lights.state.directionalShadowMatrix;
uniforms.spotShadowMap.value = lights.state.spotShadowMap;
uniforms.spotShadowMatrix.value = lights.state.spotShadowMatrix;
uniforms.pointShadowMap.value = lights.state.pointShadowMap;
uniforms.pointShadowMatrix.value = lights.state.pointShadowMatrix;
}
const progUniforms = materialProperties.program.getUniforms(),
uniformsList = WebGLUniforms.seqWithValue(progUniforms.seq, uniforms);
materialProperties.uniformsList = uniformsList;
}