mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-03-26 22:49:01 +08:00
[ue4] Modifying parent materials (of the four blend modes) updates material instances again. Closes #1791.
This commit is contained in:
parent
2039efc5b7
commit
a088270186
@ -126,41 +126,12 @@ void USpineSkeletonRendererComponent::UpdateRenderer(USpineSkeletonComponent* sk
|
|||||||
|
|
||||||
for (int i = 0; i < skeleton->Atlas->atlasPages.Num(); i++) {
|
for (int i = 0; i < skeleton->Atlas->atlasPages.Num(); i++) {
|
||||||
AtlasPage* currPage = skeleton->Atlas->GetAtlas()->getPages()[i];
|
AtlasPage* currPage = skeleton->Atlas->GetAtlas()->getPages()[i];
|
||||||
|
|
||||||
UTexture2D* texture = skeleton->Atlas->atlasPages[i];
|
UTexture2D* texture = skeleton->Atlas->atlasPages[i];
|
||||||
UTexture* oldTexture = nullptr;
|
|
||||||
|
|
||||||
UMaterialInstanceDynamic* current = atlasNormalBlendMaterials[i];
|
UpdateRendererMaterial(currPage, texture, atlasNormalBlendMaterials[i], NormalBlendMaterial, pageToNormalBlendMaterial);
|
||||||
if (!current || !current->GetTextureParameterValue(TextureParameterName, oldTexture) || oldTexture != texture) {
|
UpdateRendererMaterial(currPage, texture, atlasAdditiveBlendMaterials[i], AdditiveBlendMaterial, pageToAdditiveBlendMaterial);
|
||||||
UMaterialInstanceDynamic* material = UMaterialInstanceDynamic::Create(NormalBlendMaterial, this);
|
UpdateRendererMaterial(currPage, texture, atlasMultiplyBlendMaterials[i], MultiplyBlendMaterial, pageToMultiplyBlendMaterial);
|
||||||
material->SetTextureParameterValue(TextureParameterName, texture);
|
UpdateRendererMaterial(currPage, texture, atlasScreenBlendMaterials[i], ScreenBlendMaterial, pageToScreenBlendMaterial);
|
||||||
atlasNormalBlendMaterials[i] = material;
|
|
||||||
}
|
|
||||||
pageToNormalBlendMaterial.Add(currPage, atlasNormalBlendMaterials[i]);
|
|
||||||
|
|
||||||
current = atlasAdditiveBlendMaterials[i];
|
|
||||||
if (!current || !current->GetTextureParameterValue(TextureParameterName, oldTexture) || oldTexture != texture) {
|
|
||||||
UMaterialInstanceDynamic* material = UMaterialInstanceDynamic::Create(AdditiveBlendMaterial, this);
|
|
||||||
material->SetTextureParameterValue(TextureParameterName, texture);
|
|
||||||
atlasAdditiveBlendMaterials[i] = material;
|
|
||||||
}
|
|
||||||
pageToAdditiveBlendMaterial.Add(currPage, atlasAdditiveBlendMaterials[i]);
|
|
||||||
|
|
||||||
current = atlasMultiplyBlendMaterials[i];
|
|
||||||
if (!current || !current->GetTextureParameterValue(TextureParameterName, oldTexture) || oldTexture != texture) {
|
|
||||||
UMaterialInstanceDynamic* material = UMaterialInstanceDynamic::Create(MultiplyBlendMaterial, this);
|
|
||||||
material->SetTextureParameterValue(TextureParameterName, texture);
|
|
||||||
atlasMultiplyBlendMaterials[i] = material;
|
|
||||||
}
|
|
||||||
pageToMultiplyBlendMaterial.Add(currPage, atlasMultiplyBlendMaterials[i]);
|
|
||||||
|
|
||||||
current = atlasScreenBlendMaterials[i];
|
|
||||||
if (!current || !current->GetTextureParameterValue(TextureParameterName, oldTexture) || oldTexture != texture) {
|
|
||||||
UMaterialInstanceDynamic* material = UMaterialInstanceDynamic::Create(ScreenBlendMaterial, this);
|
|
||||||
material->SetTextureParameterValue(TextureParameterName, texture);
|
|
||||||
atlasScreenBlendMaterials[i] = material;
|
|
||||||
}
|
|
||||||
pageToScreenBlendMaterial.Add(currPage, atlasScreenBlendMaterials[i]);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
UpdateMesh(skeleton->GetSkeleton());
|
UpdateMesh(skeleton->GetSkeleton());
|
||||||
@ -170,6 +141,21 @@ void USpineSkeletonRendererComponent::UpdateRenderer(USpineSkeletonComponent* sk
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void USpineSkeletonRendererComponent::UpdateRendererMaterial (spine::AtlasPage *CurrentPage, UTexture2D *Texture,
|
||||||
|
UMaterialInstanceDynamic *&CurrentInstance, UMaterialInterface *ParentMaterial,
|
||||||
|
TMap<spine::AtlasPage *, UMaterialInstanceDynamic *> &PageToBlendMaterial) {
|
||||||
|
|
||||||
|
UTexture* oldTexture = nullptr;
|
||||||
|
if (!CurrentInstance || !CurrentInstance->GetTextureParameterValue(TextureParameterName, oldTexture) ||
|
||||||
|
oldTexture != Texture || CurrentInstance->Parent != ParentMaterial) {
|
||||||
|
|
||||||
|
UMaterialInstanceDynamic* material = UMaterialInstanceDynamic::Create(ParentMaterial, this);
|
||||||
|
material->SetTextureParameterValue(TextureParameterName, Texture);
|
||||||
|
CurrentInstance = material;
|
||||||
|
}
|
||||||
|
PageToBlendMaterial.Add(CurrentPage, CurrentInstance);
|
||||||
|
}
|
||||||
|
|
||||||
void USpineSkeletonRendererComponent::Flush (int &Idx, TArray<FVector> &Vertices, TArray<int32> &Indices, TArray<FVector> &Normals, TArray<FVector2D> &Uvs, TArray<FColor> &Colors, TArray<FVector>& Colors2, UMaterialInstanceDynamic* Material) {
|
void USpineSkeletonRendererComponent::Flush (int &Idx, TArray<FVector> &Vertices, TArray<int32> &Indices, TArray<FVector> &Normals, TArray<FVector2D> &Uvs, TArray<FColor> &Colors, TArray<FVector>& Colors2, UMaterialInstanceDynamic* Material) {
|
||||||
if (Vertices.Num() == 0) return;
|
if (Vertices.Num() == 0) return;
|
||||||
SetMaterial(Idx, Material);
|
SetMaterial(Idx, Material);
|
||||||
|
|||||||
@ -95,6 +95,10 @@ public:
|
|||||||
virtual void FinishDestroy() override;
|
virtual void FinishDestroy() override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
void UpdateRendererMaterial (spine::AtlasPage *CurrentPage, UTexture2D *Texture,
|
||||||
|
UMaterialInstanceDynamic *&CurrentInstance, UMaterialInterface *ParentMaterial,
|
||||||
|
TMap<spine::AtlasPage *, UMaterialInstanceDynamic *> &PageToBlendMaterial);
|
||||||
|
|
||||||
void UpdateMesh (spine::Skeleton* Skeleton);
|
void UpdateMesh (spine::Skeleton* Skeleton);
|
||||||
|
|
||||||
void Flush (int &Idx, TArray<FVector> &Vertices, TArray<int32> &Indices, TArray<FVector> &Normals, TArray<FVector2D> &Uvs, TArray<FColor> &Colors, TArray<FVector> &Colors2, UMaterialInstanceDynamic* Material);
|
void Flush (int &Idx, TArray<FVector> &Vertices, TArray<int32> &Indices, TArray<FVector> &Normals, TArray<FVector2D> &Uvs, TArray<FColor> &Colors, TArray<FVector> &Colors2, UMaterialInstanceDynamic* Material);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user