x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

How to move texture UV offset

I need to create the illusion of movement of a spaceship by moving the texture offset of a starfield background image. The camera and starfield image keep track of the spaceship as it moves and I am using a APaperSpriteActor to display the background image, however I am unable to figure out how I change the background texture UV offset at runtime (there is a UPaperSprite::GetSourceUV() method, but no equivalent Set method).

I'm sure I could get this working by using Material, but then I am unsure how to present the material as a flat image (perhaps using a plane?).

Can anyone provide some guidance on this please?

Product Version: UE 4.12
Tags:
more ▼

asked Aug 26 '16 at 01:51 PM in C++ Programming

avatar image

trojanfoe
199 10 18 26

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

4 answers: sort voted first

I haven't messed around with Sprites yet, but what you're trying to do can be easily accomplished with a plane and a Material, as you said yourself.

The material setup (using Customized UVs to move coordinates in an optimized way): Material Customized UVs change the same UVs Texture Samples use, but once for each vertex instead of each pixel. As Texture Samples use the coordinate index 0 by default, customizing UV0 already alters the default textures coordinate.

Changing the coordinates Scalar Parameters in Blueprint: Edit mat params in BP

Result: Result

capture.jpg (164.8 kB)
capture2.jpg (83.7 kB)
animation.gif (4.4 MB)
more ▼

answered Aug 26 '16 at 03:41 PM

avatar image

RVillani
1.1k 28 41 90

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

Personally I would use something called Material Parameter Collection to change these values. This is much cheaper than what has been proposed and is more flexible.

Just create a material paramter collection in your editor and use material parameter nodes in your material. Then, inside some blueprint you simply update the values in a tick event and you are good to go. I am not at a PC until monday so I cant give you a screenshot. Sorry for that.

more ▼

answered Aug 26 '16 at 06:24 PM

avatar image

NoobsDeSroobs
2.7k 108 36 180

avatar image RVillani Aug 26 '16 at 06:37 PM

Hey! Cheaper is always good! =D Why are MPCs cheaper?

avatar image NoobsDeSroobs Aug 26 '16 at 06:58 PM

It is cheaper because you dont have to create a new dynamic material instance, you simply send in a uniform.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

Sorry about waking up an old post but I was looking for something similar for some hours now, and I found on another post something which could be useful in that case and without using MPC, dynamic material and blueprints, only a node in the Material editor.

So, i'm posting it here, just in case someone was in the same case as me and arrive on this post while asking google "offset UV UE4" or "moving dynamically UV in UE4" etc...

And here is my saver : The node "Panner".

You have to put the pin out of the "TexCoords" in the "Panner" and then "TextureSample". Easy and less cost than dynamic material apparently ! =) It also exists another node named "Rotator" to rotate these UVs in real-time.

=) Hope it helps another nooby like me ! =)

more ▼

answered Nov 18 '17 at 06:41 PM

avatar image

Mush.
20 1 3 5

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

Thanks to RVillani and NoobsDeSroobs, this is now working (Animated GIF; 47.2MB).

I basically used the set-up suggested by RVillani, exposing UOffset and VOffset as parameters and then using a Material Instance for the starfield material.

The base C++ CameraActor class does the movement:

 FVector Position = GetActorLocation();
 FVector Diff = Position - LastPosition;
 LastPosition = Position;

 if (StarfieldMID) {
     float UOffset, VOffset;
     if (StarfieldMID->GetScalarParameterValue(TEXT("UOffset"), UOffset) &&
         StarfieldMID->GetScalarParameterValue(TEXT("VOffset"), VOffset)) {
         UOffset += Diff.X * UVOffsetScale;
         VOffset -= Diff.Z * UVOffsetScale;

         StarfieldMID->SetScalarParameterValue(TEXT("UOffset"), UOffset);
         StarfieldMID->SetScalarParameterValue(TEXT("VOffset"), VOffset);
     } else {
         UE_LOG(LogGame, Error, TEXT("[%s] Failed to get U/V offset parameter values"), *GetName());
     }
 }

and the blueprint-subclass creates the Material Instance Dynamic in the BeginPlay event and passes it to the base class:

alt text

I don't think using a Material Parameter Collection was at all straight forward and I didn't see what advantage it gave me over a material instance as I will be adding a total of 3 textures to the starfield to give a parallax effect and MPCs seem to be global, unless I have misunderstood their use? Thanks anyway for the suggestion.

more ▼

answered Aug 27 '16 at 06:01 PM

avatar image

trojanfoe
199 10 18 26

avatar image RVillani Aug 29 '16 at 01:32 PM

MPCs are global, indeed, and if you'd like to synchronize the effect across multiple materials, it would be really useful.

Nice catch on creating the Dynamic Material Instance on BeginPlay. I always do that, but I messed up when making the example for you XD Glad you saw that!

And thanks for sharing your solution! =D

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question