Tuesday 1 January 2019

UV's in UE4

After working with Unreal Engine 4 over the past few years, I have come to appreciate how open and exposed a lot of features are. This allows artists easily dive deeper in to procedural content and shader creation. Artists can easily helping textures such as blending masks or shading gradients and also derivative functions that allow for more complicated shaders and VFX work.
But before any of this is possible it is important to have some understanding on how UV's work within the material editor in the engine.In this post we are going to get an overview of how UV's are represented and handled inside UE4.
Basics
First of all the basic UV node Texture Coordinates. Even though this is not necessary to have by default when we are using uniquely mapped textures it is a really important node for creating tiling textures and extracting basic linear gradients within the material editor.



As we can see above we have actually have some funky colour information that is actually being created by encoding the U (horizontal) and V (vertical) texture coordinate values in 2 colour channels. The Red (U) and the Green (V). In order to understand this better we will add to "Component Mask" nodes. The first will only have the (R) mask enabled and the second the (G) mask enabled. What we now see is that the 0 to 1, U values - Mask (R) - are encoded (represented) in a form of a black (0) to white (1) gradient. The same thing happens for the V values and they are represented in a vertical gradient.













It is worth noting here that in traditional modelling software such as Maya/Maya LT, UV's are represented as 0-1 left to right (U) and 0-1 bottom to top (V). From what we see in UE4 the V (vertical) gradient actually goes from from 1 (bottom-white) to 0 ( top-black).
Below is a screenshot from Maya LT's UV editor  demonstrating the UV axis values 0-1 and 0-1 starting from the bottom left. So logically if we would translate the 0-1 values to RGB (0-255) it would make sense that the bottom value in the V axis should be 0, hence black. None the less, this seems to have no effect in the way textures or UV's are translated in the engine. There is not U or V flipping.