mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-03-26 22:49:01 +08:00
[ue4] Reworked material generation so we can implement (most) blend modes
This commit is contained in:
parent
08ef2ec560
commit
277920b7fa
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -11,8 +11,18 @@ USpineSkeletonRendererComponent::USpineSkeletonRendererComponent (const FObjectI
|
|||||||
bTickInEditor = true;
|
bTickInEditor = true;
|
||||||
bAutoActivate = true;
|
bAutoActivate = true;
|
||||||
|
|
||||||
static ConstructorHelpers::FObjectFinder<UMaterialInterface> MaskedMaterialRef(TEXT("/Paper2D/MaskedUnlitSpriteMaterial"));
|
static ConstructorHelpers::FObjectFinder<UMaterialInterface> NormalMaterialRef(TEXT("/SpinePlugin/SpineUnlitNormalMaterial"));
|
||||||
DefaultMaterial = MaskedMaterialRef.Object;
|
NormalBlendMaterial = NormalMaterialRef.Object;
|
||||||
|
|
||||||
|
static ConstructorHelpers::FObjectFinder<UMaterialInterface> AdditiveMaterialRef(TEXT("/SpinePlugin/SpineUnlitAdditiveMaterial"));
|
||||||
|
AdditiveBlendMaterial = AdditiveMaterialRef.Object;
|
||||||
|
|
||||||
|
static ConstructorHelpers::FObjectFinder<UMaterialInterface> MultiplyMaterialRef(TEXT("/SpinePlugin/SpineUnlitMultiplyMaterial"));
|
||||||
|
MultiplyBlendMaterial = MultiplyMaterialRef.Object;
|
||||||
|
|
||||||
|
static ConstructorHelpers::FObjectFinder<UMaterialInterface> ScreenMaterialRef(TEXT("/SpinePlugin/SpineUnlitScreenMaterial"));
|
||||||
|
ScreenBlendMaterial = ScreenMaterialRef.Object;
|
||||||
|
|
||||||
|
|
||||||
TextureParameterName = FName(TEXT("SpriteTexture"));
|
TextureParameterName = FName(TEXT("SpriteTexture"));
|
||||||
}
|
}
|
||||||
@ -30,30 +40,84 @@ void USpineSkeletonRendererComponent::TickComponent (float DeltaTime, ELevelTick
|
|||||||
USpineSkeletonComponent* skeleton = Cast<USpineSkeletonComponent>(owner->GetComponentByClass(skeletonClass));
|
USpineSkeletonComponent* skeleton = Cast<USpineSkeletonComponent>(owner->GetComponentByClass(skeletonClass));
|
||||||
|
|
||||||
if (skeleton && !skeleton->IsBeingDestroyed() && skeleton->GetSkeleton()) {
|
if (skeleton && !skeleton->IsBeingDestroyed() && skeleton->GetSkeleton()) {
|
||||||
if (atlasMaterials.Num() != skeleton->Atlas->atlasPages.Num()) {
|
if (atlasNormalBlendMaterials.Num() != skeleton->Atlas->atlasPages.Num()) {
|
||||||
atlasMaterials.SetNum(0);
|
atlasNormalBlendMaterials.SetNum(0);
|
||||||
pageToMaterial.Empty();
|
pageToNormalBlendMaterial.Empty();
|
||||||
|
atlasAdditiveBlendMaterials.SetNum(0);
|
||||||
|
pageToAdditiveBlendMaterial.Empty();
|
||||||
|
atlasMultiplyBlendMaterials.SetNum(0);
|
||||||
|
pageToMultiplyBlendMaterial.Empty();
|
||||||
|
atlasScreenBlendMaterials.SetNum(0);
|
||||||
|
pageToScreenBlendMaterial.Empty();
|
||||||
|
|
||||||
spAtlasPage* currPage = skeleton->Atlas->GetAtlas(false)->pages;
|
spAtlasPage* currPage = skeleton->Atlas->GetAtlas(false)->pages;
|
||||||
for (int i = 0; i < skeleton->Atlas->atlasPages.Num(); i++) {
|
for (int i = 0; i < skeleton->Atlas->atlasPages.Num(); i++) {
|
||||||
UMaterialInstanceDynamic* material = UMaterialInstanceDynamic::Create(DefaultMaterial, owner);
|
|
||||||
|
UMaterialInstanceDynamic* material = UMaterialInstanceDynamic::Create(NormalBlendMaterial, owner);
|
||||||
material->SetTextureParameterValue(TextureParameterName, skeleton->Atlas->atlasPages[i]);
|
material->SetTextureParameterValue(TextureParameterName, skeleton->Atlas->atlasPages[i]);
|
||||||
atlasMaterials.Add(material);
|
atlasNormalBlendMaterials.Add(material);
|
||||||
pageToMaterial.Add(currPage, material);
|
pageToNormalBlendMaterial.Add(currPage, material);
|
||||||
|
|
||||||
|
material = UMaterialInstanceDynamic::Create(AdditiveBlendMaterial, owner);
|
||||||
|
material->SetTextureParameterValue(TextureParameterName, skeleton->Atlas->atlasPages[i]);
|
||||||
|
atlasAdditiveBlendMaterials.Add(material);
|
||||||
|
pageToAdditiveBlendMaterial.Add(currPage, material);
|
||||||
|
|
||||||
|
material = UMaterialInstanceDynamic::Create(MultiplyBlendMaterial, owner);
|
||||||
|
material->SetTextureParameterValue(TextureParameterName, skeleton->Atlas->atlasPages[i]);
|
||||||
|
atlasMultiplyBlendMaterials.Add(material);
|
||||||
|
pageToMultiplyBlendMaterial.Add(currPage, material);
|
||||||
|
|
||||||
|
material = UMaterialInstanceDynamic::Create(ScreenBlendMaterial, owner);
|
||||||
|
material->SetTextureParameterValue(TextureParameterName, skeleton->Atlas->atlasPages[i]);
|
||||||
|
atlasScreenBlendMaterials.Add(material);
|
||||||
|
pageToScreenBlendMaterial.Add(currPage, material);
|
||||||
|
|
||||||
currPage = currPage->next;
|
currPage = currPage->next;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
pageToMaterial.Empty();
|
pageToNormalBlendMaterial.Empty();
|
||||||
|
pageToAdditiveBlendMaterial.Empty();
|
||||||
|
pageToMultiplyBlendMaterial.Empty();
|
||||||
|
pageToScreenBlendMaterial.Empty();
|
||||||
|
|
||||||
spAtlasPage* currPage = skeleton->Atlas->GetAtlas(false)->pages;
|
spAtlasPage* currPage = skeleton->Atlas->GetAtlas(false)->pages;
|
||||||
for (int i = 0; i < skeleton->Atlas->atlasPages.Num(); i++) {
|
for (int i = 0; i < skeleton->Atlas->atlasPages.Num(); i++) {
|
||||||
UMaterialInstanceDynamic* current = atlasMaterials[i];
|
|
||||||
UTexture2D* texture = skeleton->Atlas->atlasPages[i];
|
UTexture2D* texture = skeleton->Atlas->atlasPages[i];
|
||||||
UTexture* oldTexture = nullptr;
|
UTexture* oldTexture = nullptr;
|
||||||
|
|
||||||
|
UMaterialInstanceDynamic* current = atlasNormalBlendMaterials[i];
|
||||||
if(!current->GetTextureParameterValue(TextureParameterName, oldTexture) || oldTexture != texture) {
|
if(!current->GetTextureParameterValue(TextureParameterName, oldTexture) || oldTexture != texture) {
|
||||||
UMaterialInstanceDynamic* material = UMaterialInstanceDynamic::Create(DefaultMaterial, owner);
|
UMaterialInstanceDynamic* material = UMaterialInstanceDynamic::Create(NormalBlendMaterial, owner);
|
||||||
material->SetTextureParameterValue(TextureParameterName, texture);
|
material->SetTextureParameterValue(TextureParameterName, texture);
|
||||||
atlasMaterials[i] = material;
|
atlasNormalBlendMaterials[i] = material;
|
||||||
}
|
}
|
||||||
pageToMaterial.Add(currPage, atlasMaterials[i]);
|
pageToNormalBlendMaterial.Add(currPage, atlasNormalBlendMaterials[i]);
|
||||||
|
|
||||||
|
current = atlasAdditiveBlendMaterials[i];
|
||||||
|
if(!current->GetTextureParameterValue(TextureParameterName, oldTexture) || oldTexture != texture) {
|
||||||
|
UMaterialInstanceDynamic* material = UMaterialInstanceDynamic::Create(AdditiveBlendMaterial, owner);
|
||||||
|
material->SetTextureParameterValue(TextureParameterName, texture);
|
||||||
|
atlasAdditiveBlendMaterials[i] = material;
|
||||||
|
}
|
||||||
|
pageToAdditiveBlendMaterial.Add(currPage, atlasAdditiveBlendMaterials[i]);
|
||||||
|
|
||||||
|
current = atlasMultiplyBlendMaterials[i];
|
||||||
|
if(!current->GetTextureParameterValue(TextureParameterName, oldTexture) || oldTexture != texture) {
|
||||||
|
UMaterialInstanceDynamic* material = UMaterialInstanceDynamic::Create(MultiplyBlendMaterial, owner);
|
||||||
|
material->SetTextureParameterValue(TextureParameterName, texture);
|
||||||
|
atlasMultiplyBlendMaterials[i] = material;
|
||||||
|
}
|
||||||
|
pageToMultiplyBlendMaterial.Add(currPage, atlasMultiplyBlendMaterials[i]);
|
||||||
|
|
||||||
|
current = atlasScreenBlendMaterials[i];
|
||||||
|
if(!current->GetTextureParameterValue(TextureParameterName, oldTexture) || oldTexture != texture) {
|
||||||
|
UMaterialInstanceDynamic* material = UMaterialInstanceDynamic::Create(ScreenBlendMaterial, owner);
|
||||||
|
material->SetTextureParameterValue(TextureParameterName, texture);
|
||||||
|
atlasScreenBlendMaterials[i] = material;
|
||||||
|
}
|
||||||
|
pageToScreenBlendMaterial.Add(currPage, atlasScreenBlendMaterials[i]);
|
||||||
|
|
||||||
currPage = currPage->next;
|
currPage = currPage->next;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -99,7 +163,7 @@ void USpineSkeletonRendererComponent::UpdateMesh(spSkeleton* Skeleton) {
|
|||||||
if (attachment->type == SP_ATTACHMENT_REGION) {
|
if (attachment->type == SP_ATTACHMENT_REGION) {
|
||||||
spRegionAttachment* regionAttachment = (spRegionAttachment*)attachment;
|
spRegionAttachment* regionAttachment = (spRegionAttachment*)attachment;
|
||||||
spAtlasRegion* region = (spAtlasRegion*)regionAttachment->rendererObject;
|
spAtlasRegion* region = (spAtlasRegion*)regionAttachment->rendererObject;
|
||||||
UMaterialInstanceDynamic* material = pageToMaterial[region->page];
|
UMaterialInstanceDynamic* material = pageToNormalBlendMaterial[region->page];
|
||||||
|
|
||||||
if (lastMaterial != material) {
|
if (lastMaterial != material) {
|
||||||
Flush(meshSection, vertices, indices, uvs, colors, lastMaterial);
|
Flush(meshSection, vertices, indices, uvs, colors, lastMaterial);
|
||||||
@ -142,7 +206,7 @@ void USpineSkeletonRendererComponent::UpdateMesh(spSkeleton* Skeleton) {
|
|||||||
} else if (attachment->type == SP_ATTACHMENT_MESH) {
|
} else if (attachment->type == SP_ATTACHMENT_MESH) {
|
||||||
spMeshAttachment* mesh = (spMeshAttachment*)attachment;
|
spMeshAttachment* mesh = (spMeshAttachment*)attachment;
|
||||||
spAtlasRegion* region = (spAtlasRegion*)mesh->rendererObject;
|
spAtlasRegion* region = (spAtlasRegion*)mesh->rendererObject;
|
||||||
UMaterialInstanceDynamic* material = pageToMaterial[region->page];
|
UMaterialInstanceDynamic* material = pageToNormalBlendMaterial[region->page];
|
||||||
|
|
||||||
if (lastMaterial != material) {
|
if (lastMaterial != material) {
|
||||||
Flush(meshSection, vertices, indices, uvs, colors, lastMaterial);
|
Flush(meshSection, vertices, indices, uvs, colors, lastMaterial);
|
||||||
|
|||||||
@ -20,7 +20,16 @@ public:
|
|||||||
virtual void TickComponent (float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override;
|
virtual void TickComponent (float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override;
|
||||||
|
|
||||||
UPROPERTY(Category = Spine, EditAnywhere, BlueprintReadOnly)
|
UPROPERTY(Category = Spine, EditAnywhere, BlueprintReadOnly)
|
||||||
UMaterialInterface* DefaultMaterial;
|
UMaterialInterface* NormalBlendMaterial;
|
||||||
|
|
||||||
|
UPROPERTY(Category = Spine, EditAnywhere, BlueprintReadOnly)
|
||||||
|
UMaterialInterface* AdditiveBlendMaterial;
|
||||||
|
|
||||||
|
UPROPERTY(Category = Spine, EditAnywhere, BlueprintReadOnly)
|
||||||
|
UMaterialInterface* MultiplyBlendMaterial;
|
||||||
|
|
||||||
|
UPROPERTY(Category = Spine, EditAnywhere, BlueprintReadOnly)
|
||||||
|
UMaterialInterface* ScreenBlendMaterial;
|
||||||
|
|
||||||
UPROPERTY(Category = Spine, EditAnywhere, BlueprintReadWrite)
|
UPROPERTY(Category = Spine, EditAnywhere, BlueprintReadWrite)
|
||||||
float DepthOffset = 0.1f;
|
float DepthOffset = 0.1f;
|
||||||
@ -33,6 +42,15 @@ protected:
|
|||||||
|
|
||||||
void Flush (int &Idx, TArray<FVector> &Vertices, TArray<int32> &Indices, TArray<FVector2D> &Uvs, TArray<FColor> &Colors, UMaterialInstanceDynamic* Material);
|
void Flush (int &Idx, TArray<FVector> &Vertices, TArray<int32> &Indices, TArray<FVector2D> &Uvs, TArray<FColor> &Colors, UMaterialInstanceDynamic* Material);
|
||||||
|
|
||||||
TArray<UMaterialInstanceDynamic*> atlasMaterials;
|
TArray<UMaterialInstanceDynamic*> atlasNormalBlendMaterials;
|
||||||
TMap<spAtlasPage*, UMaterialInstanceDynamic*> pageToMaterial;
|
TMap<spAtlasPage*, UMaterialInstanceDynamic*> pageToNormalBlendMaterial;
|
||||||
|
|
||||||
|
TArray<UMaterialInstanceDynamic*> atlasAdditiveBlendMaterials;
|
||||||
|
TMap<spAtlasPage*, UMaterialInstanceDynamic*> pageToAdditiveBlendMaterial;
|
||||||
|
|
||||||
|
TArray<UMaterialInstanceDynamic*> atlasMultiplyBlendMaterials;
|
||||||
|
TMap<spAtlasPage*, UMaterialInstanceDynamic*> pageToMultiplyBlendMaterial;
|
||||||
|
|
||||||
|
TArray<UMaterialInstanceDynamic*> atlasScreenBlendMaterials;
|
||||||
|
TMap<spAtlasPage*, UMaterialInstanceDynamic*> pageToScreenBlendMaterial;
|
||||||
};
|
};
|
||||||
|
|||||||
@ -11,7 +11,7 @@
|
|||||||
"MarketplaceURL" : "",
|
"MarketplaceURL" : "",
|
||||||
"SupportURL" : "",
|
"SupportURL" : "",
|
||||||
"EnabledByDefault" : false,
|
"EnabledByDefault" : false,
|
||||||
"CanContainContent" : false,
|
"CanContainContent" : true,
|
||||||
"IsBetaVersion" : false,
|
"IsBetaVersion" : false,
|
||||||
"Installed" : false,
|
"Installed" : false,
|
||||||
"Modules" :
|
"Modules" :
|
||||||
@ -26,4 +26,4 @@
|
|||||||
"Type" : "Editor"
|
"Type" : "Editor"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user