void USsPlayerComponent::SendRenderDynamicData_Concurrent() { if(NULL == SceneProxy) { return; } switch(RenderMode) { case ESsPlayerComponentRenderMode::Default: { const TArray<FSsRenderPart> RenderParts = Player.GetRenderParts(); TArray<FSsRenderPartWithMaterial> NewRenderParts; NewRenderParts.Reserve(RenderParts.Num()); for(int32 i = 0; i < RenderParts.Num(); ++i) { FSsRenderPartWithMaterial Part; FMemory::Memcpy(&Part, &(RenderParts[i]), sizeof(FSsRenderPart)); uint32 MatIdx = PartsMatIndex(Part.AlphaBlendType, Part.ColorBlendType); UMaterialInstanceDynamic** ppMID = PartsMIDMap[MatIdx].Find(Part.Texture); if(ppMID && *ppMID) { Part.Material = *ppMID; } else { UMaterialInstanceDynamic* NewMID = UMaterialInstanceDynamic::Create(BasePartsMaterials[MatIdx], this); if(NewMID) { NewMID->AddToRoot(); NewMID->SetFlags(RF_Transient); NewMID->SetTextureParameterValue(FName(TEXT("SsCellTexture")), Part.Texture); Part.Material = NewMID; PartsMIDMap[MatIdx].Add(Part.Texture, NewMID); } } NewRenderParts.Add(Part); } if(0 < NewRenderParts.Num()) { ENQUEUE_UNIQUE_RENDER_COMMAND_FOURPARAMETER( FSendSsPartsData, FSsRenderPartsProxy*, SsPartsProxy, (FSsRenderPartsProxy*)SceneProxy, TArray<FSsRenderPartWithMaterial>, InRenderParts, NewRenderParts, FVector2D, Pivot, Player.GetAnimPivot(), FVector2D, CanvasSizeUU, (Player.GetAnimCanvasSize() * UUPerPixel), { SsPartsProxy->CanvasSizeUU = CanvasSizeUU; SsPartsProxy->SetPivot(Pivot); SsPartsProxy->SetDynamicData_RenderThread(InRenderParts); }); }
void AShaderPluginDemoCharacter::OnFire() { //Try to set a texture to the object we hit! FHitResult HitResult; FVector StartLocation = FirstPersonCameraComponent->GetComponentLocation(); FRotator Direction = FirstPersonCameraComponent->GetComponentRotation(); FVector EndLocation = StartLocation + Direction.Vector() * 10000; FCollisionQueryParams QueryParams; QueryParams.AddIgnoredActor(this); if (GetWorld()->LineTraceSingleByChannel(HitResult, StartLocation, EndLocation, ECC_Visibility, QueryParams)) { TArray<UStaticMeshComponent*> StaticMeshComponents = TArray<UStaticMeshComponent*>(); AActor* HitActor = HitResult.GetActor(); if (NULL != HitActor) { HitActor->GetComponents<UStaticMeshComponent>(StaticMeshComponents); for (int32 i = 0; i < StaticMeshComponents.Num(); i++) { UStaticMeshComponent* CurrentStaticMeshPtr = StaticMeshComponents[i]; CurrentStaticMeshPtr->SetMaterial(0, MaterialToApplyToClickedObject); UMaterialInstanceDynamic* MID = CurrentStaticMeshPtr->CreateAndSetMaterialInstanceDynamic(0); UTexture* CastedRenderTarget = Cast<UTexture>(RenderTarget); MID->SetTextureParameterValue("InputTexture", CastedRenderTarget); } } } // try and play the sound if specified if (FireSound != NULL) { UGameplayStatics::PlaySoundAtLocation(this, FireSound, GetActorLocation()); } // try and play a firing animation if specified if (FireAnimation != NULL) { // Get the animation object for the arms mesh UAnimInstance* AnimInstance = Mesh1P->GetAnimInstance(); if (AnimInstance != NULL) { AnimInstance->Montage_Play(FireAnimation, 1.f); } } }
int32 SSpineWidget::OnPaint(const FPaintArgs& Args, const FGeometry& AllottedGeometry, const FSlateRect& MyClippingRect, FSlateWindowElementList& OutDrawElements, int32 LayerId, const FWidgetStyle& InWidgetStyle, bool bParentEnabled) const { SSpineWidget* self = (SSpineWidget*)this; if (widget && widget->skeleton && widget->Atlas) { widget->skeleton->getColor().set(widget->Color.R, widget->Color.G, widget->Color.B, widget->Color.A); if (widget->atlasNormalBlendMaterials.Num() != widget->Atlas->atlasPages.Num()) { widget->atlasNormalBlendMaterials.SetNum(0); widget->pageToNormalBlendMaterial.Empty(); widget->atlasAdditiveBlendMaterials.SetNum(0); widget->pageToAdditiveBlendMaterial.Empty(); widget->atlasMultiplyBlendMaterials.SetNum(0); widget->pageToMultiplyBlendMaterial.Empty(); widget->atlasScreenBlendMaterials.SetNum(0); widget->pageToScreenBlendMaterial.Empty(); for (int i = 0; i < widget->Atlas->atlasPages.Num(); i++) { AtlasPage* currPage = widget->Atlas->GetAtlas()->getPages()[i]; UMaterialInstanceDynamic* material = UMaterialInstanceDynamic::Create(widget->NormalBlendMaterial, widget); material->SetTextureParameterValue(widget->TextureParameterName, widget->Atlas->atlasPages[i]); widget->atlasNormalBlendMaterials.Add(material); widget->pageToNormalBlendMaterial.Add(currPage, material); material = UMaterialInstanceDynamic::Create(widget->AdditiveBlendMaterial, widget); material->SetTextureParameterValue(widget->TextureParameterName, widget->Atlas->atlasPages[i]); widget->atlasAdditiveBlendMaterials.Add(material); widget->pageToAdditiveBlendMaterial.Add(currPage, material); material = UMaterialInstanceDynamic::Create(widget->MultiplyBlendMaterial, widget); material->SetTextureParameterValue(widget->TextureParameterName, widget->Atlas->atlasPages[i]); widget->atlasMultiplyBlendMaterials.Add(material); widget->pageToMultiplyBlendMaterial.Add(currPage, material); material = UMaterialInstanceDynamic::Create(widget->ScreenBlendMaterial, widget); material->SetTextureParameterValue(widget->TextureParameterName, widget->Atlas->atlasPages[i]); widget->atlasScreenBlendMaterials.Add(material); widget->pageToScreenBlendMaterial.Add(currPage, material); } } else { widget->pageToNormalBlendMaterial.Empty(); widget->pageToAdditiveBlendMaterial.Empty(); widget->pageToMultiplyBlendMaterial.Empty(); widget->pageToScreenBlendMaterial.Empty(); for (int i = 0; i < widget->Atlas->atlasPages.Num(); i++) { AtlasPage* currPage = widget->Atlas->GetAtlas()->getPages()[i]; UTexture2D* texture = widget->Atlas->atlasPages[i]; UTexture* oldTexture = nullptr; UMaterialInstanceDynamic* current = widget->atlasNormalBlendMaterials[i]; if (!current || !current->GetTextureParameterValue(widget->TextureParameterName, oldTexture) || oldTexture != texture) { UMaterialInstanceDynamic* material = UMaterialInstanceDynamic::Create(widget->NormalBlendMaterial, widget); material->SetTextureParameterValue(widget->TextureParameterName, texture); widget->atlasNormalBlendMaterials[i] = material; } widget->pageToNormalBlendMaterial.Add(currPage, widget->atlasNormalBlendMaterials[i]); current = widget->atlasAdditiveBlendMaterials[i]; if (!current || !current->GetTextureParameterValue(widget->TextureParameterName, oldTexture) || oldTexture != texture) { UMaterialInstanceDynamic* material = UMaterialInstanceDynamic::Create(widget->AdditiveBlendMaterial, widget); material->SetTextureParameterValue(widget->TextureParameterName, texture); widget->atlasAdditiveBlendMaterials[i] = material; } widget->pageToAdditiveBlendMaterial.Add(currPage, widget->atlasAdditiveBlendMaterials[i]); current = widget->atlasMultiplyBlendMaterials[i]; if (!current || !current->GetTextureParameterValue(widget->TextureParameterName, oldTexture) || oldTexture != texture) { UMaterialInstanceDynamic* material = UMaterialInstanceDynamic::Create(widget->MultiplyBlendMaterial, widget); material->SetTextureParameterValue(widget->TextureParameterName, texture); widget->atlasMultiplyBlendMaterials[i] = material; } widget->pageToMultiplyBlendMaterial.Add(currPage, widget->atlasMultiplyBlendMaterials[i]); current = widget->atlasScreenBlendMaterials[i]; if (!current || !current->GetTextureParameterValue(widget->TextureParameterName, oldTexture) || oldTexture != texture) { UMaterialInstanceDynamic* material = UMaterialInstanceDynamic::Create(widget->ScreenBlendMaterial, widget); material->SetTextureParameterValue(widget->TextureParameterName, texture); widget->atlasScreenBlendMaterials[i] = material; } widget->pageToScreenBlendMaterial.Add(currPage, widget->atlasScreenBlendMaterials[i]); } } // self->UpdateMesh(LayerId, OutDrawElements, AllottedGeometry, widget->skeleton); } //return LayerId; self->renderData.IndexData.SetNumUninitialized(6); uint32* indexData = (uint32*)renderData.IndexData.GetData(); indexData[0] = 0; indexData[1] = 1; indexData[2] = 2; indexData[3] = 2; indexData[4] = 3; indexData[5] = 0; self->renderData.VertexData.SetNumUninitialized(4); FSlateVertex* vertexData = (FSlateVertex*)renderData.VertexData.GetData(); FVector2D offset = AllottedGeometry.AbsolutePosition; FColor white = FColor(0xffffffff); float width = AllottedGeometry.GetAbsoluteSize().X; float height = AllottedGeometry.GetAbsoluteSize().Y; setVertex(&vertexData[0], 0, 0, 0, 0, white, offset); setVertex(&vertexData[1], width, 0, 1, 0, white, offset); setVertex(&vertexData[2], width, height, 1, 1, white, offset); setVertex(&vertexData[3], 0, height, 0, 1, white, offset); if (brush && renderData.VertexData.Num() > 0 && renderData.IndexData.Num() > 0) { FSlateShaderResourceProxy* shaderResource = FSlateDataPayload::ResourceManager->GetShaderResource(widget->Brush); FSlateResourceHandle resourceHandle = FSlateApplication::Get().GetRenderer()->GetResourceHandle(widget->Brush); if (shaderResource) FSlateDrawElement::MakeCustomVerts(OutDrawElements, LayerId, resourceHandle, renderData.VertexData, renderData.IndexData, nullptr, 0, 0); } return LayerId; }