/** * Compiles the shaders for a material and caches them in this shader map. * @param Material - The material to compile shaders for. * @param InShaderMapId - the set of static parameters to compile for * @param Platform - The platform to compile to */ voidFMaterialShaderMap::Compile( FMaterial* Material, const FMaterialShaderMapId& InShaderMapId, const TRefCountPtr<FSharedShaderCompilerEnvironment>& MaterialEnvironment, const FMaterialCompilationOutput& InMaterialCompilationOutput, EShaderPlatform InPlatform, EMaterialShaderPrecompileMode PrecompileMode) { ...
if (PrecompileMode != EMaterialShaderPrecompileMode::None) { EShaderCompileJobPriority CompilePriority = EShaderCompileJobPriority::Low; ...
// Compile the shaders for this shader map now if the material is not deferring and deferred compiles are not enabled globally if (PrecompileMode == EMaterialShaderPrecompileMode::Synchronous) { TArray<int32> CurrentShaderMapId; CurrentShaderMapId.Add(CompilingId); GShaderCompilingManager->FinishCompilation( GetFriendlyName(), CurrentShaderMapId); } }
for (TObjectIterator<UPrimitiveComponent> PrimitiveIt; PrimitiveIt; ++PrimitiveIt) { UPrimitiveComponent* PrimitiveComponent = *PrimitiveIt;
if (PrimitiveComponent->IsRenderStateCreated()) { UsedMaterials.Reset(); bool bPrimitiveIsDependentOnMaterial = false;
// Note: relying on GetUsedMaterials to be accurate, or else we won't propagate to the right primitives and the renderer will crash later // FPrimitiveSceneProxy::VerifyUsedMaterial is used to make sure that all materials used for rendering are reported in GetUsedMaterials PrimitiveComponent->GetUsedMaterials(UsedMaterials);
if (UsedMaterials.Num() > 0) { ... // 判断当前 PrimitiveComponent 是否依赖于 MaterialsToUpdate 中的 Material
if (bPrimitiveIsDependentOnMaterial) { ComponentContexts.Add(newFComponentRecreateRenderStateContext(PrimitiveComponent));
/** Destroys render state for a component and then recreates it when this object is destroyed */ classFComponentRecreateRenderStateContext { private: /** Pointer to component we are recreating render state for */ UActorComponent* Component;