Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you dynamically render quads in UE4?

There are some hand wavey answers for this on answers.unrealengine.com, but they seem to lack any detail or examples.

Specifically, and in detail, if you wanted to implement a set of dynamic textured quads which rendered in the 3d game world, how would you do it?

For use case, consider a 2dish side scroller that uses Spriter animations. The 2D animations are loaded from XML easily enough, but how do you then render this 2D set of textured, rotated and scaled quads dynamically on the scene?

like image 751
Doug Avatar asked Apr 14 '15 13:04

Doug


People also ask

Can Unreal Engine be used for rendering?

The rendering system in Unreal Engine uses DirectX 11 and DirectX 12 pipelines that include deferred shading, global illumination, lit translucency, and post processing, as well as GPU particle simulation utilizing vector fields.

How long does it take to render an animation in Unreal Engine?

At an average of 20 minute renderings per frame, and 30 frames per second, a 1 minute animation takes 25 days on a single computer!!! Real time rendering, on the other hand, takes 5 minutes to render a 5 minute animation, or 1 hour to render a hour animation. You get the idea.

What is shader complexity?

Shader Complexity Mode is used to visualize the number of shader instructions being used to calculate each pixel of your scene. It is generally a good indication of how performance-friendly your scene will be.


1 Answers

Is the problem you are facing concern spawning the mesh or with obtaining the right orientation? (i.e. orthographic projection, facing the camera)

Spawning the mesh is easy enough, can be done either through Blueprints or in code.

In Blueprints, you would set up certain preconditions and then choose to spawn actors based on the conditions. The actual coding solution would look much the same.

If it is regarding orientation, then this answer will be of help to you, found on the UnrealEngine forums:

https://answers.unrealengine.com/questions/62126/how-do-i-render-a-dynamic-mesh-with-orthographic-p.html

EDIT:

After much hair pulling and documentation surfing, here's the code that made things work.

ADynamicMeshSpawner::ADynamicMeshSpawner() {      // Set this actor to call Tick() every frame.  You can turn this off to improve performance if you don't need it.      PrimaryActorTick.bCanEverTick = true;      // Using a SphereComponent is not particularly necessary or relevant, but the cube refused to spawn without a root component to attach to, or so I surmise. Yay Unreal. =/     USphereComponent* CubeComponent = CreateDefaultSubobject<USphereComponent>(TEXT("RootComponent"));     RootComponent = CubeComponent;     CubeComponent->InitSphereRadius(40.0f);     CubeComponent->SetCollisionProfileName(TEXT("Pawn"));      // Create and position a mesh component so we can see where our cube is     UStaticMeshComponent* CubeVisual = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("VisualRepresentation"));     CubeVisual->AttachTo(RootComponent);     static ConstructorHelpers::FObjectFinder<UStaticMesh> SphereVisualAsset(TEXT("StaticMesh'/Game/StarterContent/Shapes/Shape_Cube.Shape_Cube'"));     if (SphereVisualAsset.Succeeded())     {         CubeVisual->SetStaticMesh(SphereVisualAsset.Object);         CubeVisual->SetRelativeLocation(FVector(-200.0f, 0.0f, 100.0f));         CubeVisual->SetWorldScale3D(FVector(2.0f));     }     // Create a material to be applied on the StaticMeshComponent     static ConstructorHelpers::FObjectFinder<UMaterial> Material(TEXT("Material'/Game/StarterContent/Materials/M_Tech_Hex_Tile_Pulse.M_Tech_Hex_Tile_Pulse'"));      if (Material.Object != NULL)     {         TheMaterial = (UMaterial*)Material.Object;     }      CubeVisual->SetMaterial(0, TheMaterial); } 

The headerfile looks like this:

UCLASS() class MYPROJECT_API ADynamicMeshSpawner : public AActor {     GENERATED_BODY()  public:      // Sets default values for this actor's properties     ADynamicMeshSpawner();      // Called when the game starts or when spawned     virtual void BeginPlay() override;      // Called every frame     virtual void Tick( float DeltaSeconds ) override;     // Pointer to the material that needs to be used     UMaterial* TheMaterial; }; 

The final output looked like this in the editor:

A glorious cube spawned from code!

I set it up so that an instance of my class 'DynamicMeshSpawner' would be spawned everytime I hit 'P' on the keyboard. When the instance of this class is created, it calls the constructor, which spawns the cube with the material applied. I did the class instance spawning stuff in BluePrints using the SpawnActor node.

Implemented in the level blueprint

The conditions that you require for spawning stuff would obviously depend on the application.

This method works for normal Materials but NOT Material Instances. I believe you would have to make changes to the type of TheMaterial, the ConstructorHelper call, and the cast from the material reference into TheMaterial in order to make it function.

I'm confident that this would work with Animated materials as well, meaning that the 2D animations would need to be converted into a Material of some sort.

Perhaps the link below would help.

https://forums.unrealengine.com/showthread.php?6744-Flipbook-material-to-recreate-an-animated-gif

EDIT 2:

Below are a very good set of examples on how to procedurally create objects in Unreal. Leaving it here for posterity and in case anyone comes looking.

https://github.com/SiggiG/ProceduralMeshes/

like image 188
Sai Narayan Avatar answered Sep 25 '22 21:09

Sai Narayan