Download

Understanding the format of material editor UVs

Hi,

I’m familiar with the concept of UVs. Essentially, it’s a vector of 4 values in the range 0 to 1: (horizontal start, horizontal end, vertical start, vertical end).
I’m trying to use the unreal material editor and it has a UVs field. That field seems to contain only 2 values, which makes absolutely no sense to me. I can use a flipbook node to cut up my texture and use these UVs. How can it do that with only 2 values!? All it should be able to do is to slide the texture, not parse it. When I try to manually provide UVs, it only accepts vec2s and it only does translations.

uvs.png

I can’t find any discussion on this, which I find very strange. Can anyone explain this to me?

I’m trying to clamp my UVs on an animation so that each frame is a little clamped.
This is to solve what seems like an unreal bug… (Destructible mesh physics and rendering issues)

So the uvs are stored per vertex. They map the vertex to the texture. The texture has 2 coords.

U and V

Hence the name uv

I’m not sure if you’re just giving me a definition of UVs, or if you’re actually trying to explain to me what I want to know and I don’t get it.

Let’s say I have this generic sprite sheet texture. I want to map the part that’s inside the red square to a flat mesh with 4 vertex points. I create a material and I assign it to this mesh. What do I need to pass in the UVs parameter of the TextureSample node in the material editor? Without using the FlipBook node.

uvs2.png

At a high level, the 3d vertices of a model are sent down the pipeline and rasterized.

The material node runs for each of these interpolated pixel fragment.

The uv node in this case is receiving a u,v coordinate found by interpolating the associated vertexes.

It has been a while since I used Paper2D - but the mapped quad will get rasterized and the material will get interpolated uvs.

I was able to achieve what I wanted by copying the contents of the FlipBook node and “hacking” it. I don’t fully understand how it works, but it seems that the TexCoord node gives us some kind of structure with internal logic that isn’t a float[2]. Dividing the TexCoord by the amount of columns and rows specifies the size of the zone we want. Then adding a float to that will move the zone to the location in the texture we want. Passing this to the UVs field of the Texture Sample node “crops” the zone.

I obviously don’t understand this, but this image seems to be valid. What are the contents/format of TexCoord? Should I see it as the coordinate of one of the rasterized points?

Anyway, to crop the edges of a frame, I divided the zone into a smaller area and then added a small float to center it on in the right area on the texture.

“I’m familiar with the concept of UVs. Essentially, it’s a vector of 4 values in the range 0 to 1: (horizontal start, horizontal end, vertical start, vertical end).”

Your not familiar with it cause your definition is wrong. UV is a vec2, U for horizontal axis, V for vertical axis.

“it seems that the TexCoord node gives us some kind of structure with internal logic that isn’t a float[2]”

no, it IS a float2, or vec2, the part that your not understanding is that we are not talking about a single array of 2 values we are talking about a ‘gradient’ of arrays of 2 values, each vertex of the mesh makes up a ‘point’ of the gradient. This data is then interpolated from per-vertex to per-pixel in the material when you access it in the material (since its a pixel shader) so you end up with a per-pixel gradient of values.

“I was able to achieve what I wanted by copying the contents of the FlipBook node and “hacking” it.”

I imagine the flipbook function could already do what you wanted, sounds like all you need to do was set your rows/columns correctly and then choose the frame you wanted by using a scalar param going into the animation phase input.

Yes UV is float2.

What you are basically describing is something similar to Cropped Emissive coordinates. Here is an old UDK doc with a lnk to a photoshop thing that can help get values.
https://docs.unrealengine.com/udk/Th…Assistant.html

Observer64 is correct, UVs are stored per vertex and then interpolated. So a standard quad has 4 verts and their UV values would be (0,0), (0,1), (1,1), and (1,0). Then for any given pixel in between it simply blends the values. Specifying UVs as a struct the way you mentioned does not really make sense for a graphics pipeline since geometry can be arbitrary and each vert needs a value. A system like that wouldn’t be able to represent custom unwraps.

What you in effect need to do is just Multiply UVs by the size of the Cropped part you want, then add the value of the minimum corner. The flipbook node could work for that, assuming your frames are laid out in a perfect grid, otherwies you just need to do a Multiply and Add using the local size/offset.

ie lets say you broke up your image into 4x4 grid, and that you want to display the frame with coordinate x=1,y=2 (not pixel coord, frame coords so (1/4, 2/4). You know the local size is 1/4 so 0.25. The offset is just float2(1,2) / float2(4,4) which gives an offset of float2(0.25, 0.5).

So if you had a quad with UVs already on the 0-1 scale, you simply would multiply UVs by 0.25 and then add (0.25, 0.5) and then use those to get frame at 1,2. The flipbook node just lets you specify using a 1D range… ie 1,2 would be the same as frame 5 in 1d. (1 + 2x4). But input is 0-1 which means it just multiplies the input by total frames under the hood.

Any chance we’ll ever see sparse texture support?

https://www.khronos.org/registry/Ope…e_texture2.txt

It would let you essentially automatically crop emissive into lots of little chunks (and fall back to a lower res mip level in all the other areas).

It would also make texture masks and possibly SDF shadow maps much more efficient by only storing the edge detail at a high res mip, everything else low res.

Thanks for the precisions. My definition of UVs comes from my experience in non-shader OpenGL a long time ago. I don’t know much about shaders, but the explanation that the material UV is for a single vertex makes sense. I seem to have solved the problem properly with my original solution.

By the way, I was having to crop materials because of what seems like an issue in the destructible mesh component. Regardless of the texture settings, it seems to repeat the texture on the edges. I’m also having many other issues with desctructible mesh components which definitely look like bugs, but I have other posts open for that and honestly, I gave up on it.