Blender Model Import & 1 UV Unwrap Query

Hi

I have a blender model of a cube (8 vert, 6 faces, 12 tris). when i import this without a material it reads the same vertices etc in Unity editor. Now, if i do a UV Unwrap (project from view with bounds) and re-import the vertices stay the same. If i do a ‘Cube Projection Unwrap’ on the model and re-import i get 16 vert. Why does the number double?

Im new to this and i am just experimenting with textures and the workflow between Unity and Blender.

A vertex can hold different attributes like position, normal vector, UV coordinate and colour etc. When you UV unwrap a mesh you start making seams, and seams double the vertex count on the affected vertex.
This happens because one vertex can only hold one UV coordinate and a seam has two or more UV coordinates. The same is true for hard edges that is made by having two Normal vectors that are unequal on the same position. Blender is only displaying vertex position count and in Unity you get the GPU vertex count which include position, UV coordinate, normal vector etc. multiplied with amount of lights and shadows if using forward rendering…

Knowing this modellers try to place UV seams together with hard edges, since if you have one or the other, then having both on the same position will be “free” when looking at the GPU vertex count.

What confuses you about the “project from view with bounds” probably is that if you project from an orthographic view it skips unwrapping the sides of the cube so the sides would actually be one pixel wide since there is not a single UV seam or in other words the box would be flat as a pancake Texture-wise.

oh that makes sense now. I guess there is an art to how the model is unwrapped and how the texture design is made. So just theoretically is it possible to unwrap a cube (all 6 faces) to use one whole texture space. so its essentially like project from view with bounds for all faces of the cube. Or is this not possible?

My guess it would have to be done with texture baking? i haven’t read about this yet, just learning about unwraps at the moment.

Thanks for your advice and time!

Texture baking is generally thought of as baking details from a high poly-count mesh into a low poly-count mesh. There is also light baking where you bake light information into a light-map texture so the GPU don’t have to calculate static lights at run-time. It can just look-up the values from the light-map.

I am not sure I quite understand your question but if you mean if you can fit the cube UV map into the 0 to 1 UV space and have 100% usage of the texture?. The answer would be yes but not without a little stretching on one axis if you want every face of the cube to be unique. You could also have two of the sides be identical, then it would be 4 squares and the last 2 are placed onto either of the 4 squares.
Keep in mind that the GPU works only with Power of two textures. So the texture size should be something like 128,256,512,1024,2048 etc. But a texture does not need to be squared. So the texture could be 512U/128V. You should however only use rectangle textures when necessary since small textures are often bunched together into a texture atlas consisting of many small textures. It can be very difficult to fit an oblong texture into a texture atlas.

Hi thanks for the detailed answer.

Sorry I meant to say I want all 6 sides to use the 256 texture. So the same texture repeated on all 6 sides.

So instead of me selecting a side and then unwrapping and repeating this process 5 more times. Is there a way of doing this with one unwrap only?

I hope im making sense now otherwise I’ll upload a illustration as I’m not good at explaining.

Nick

I don’t think you can do this with one default unwrap only. However if you have to do this on many models you could make a small python script that makes it a one button step.

Ok thanks man.

Just found this post. I don’t understand the answer given. It seems they are after the same as me texturing - How to texture a cube so that each face has the same uv coordinates? - Blender Stack Exchange

Using reset on a cube looks like it remains a pancake. I’m curious how some people made this method successful. So I don’t understand the answer either.

Usually the default Unwrap command will do what you want; same with Reset. Do you have any edges marked? You don’t need anything marked to have each face of a cube use the whole texture, since that’s the default anyway.

Try this for instance:

  • Add a new cube from the Add menu
  • Press Tab to go to edit mode
  • Press U and choose Unwrap
    Then go to the UV view and you’ll see that’s it’s unwrapped with every face taking up the whole UV area.

It’ll still have only 8 verts as well - some verts on the UV map will actually appear multiple times.

1 Like

Hi

Thanks Pengocat for your help

Hi Nition
I have not got any seams, i started a new blender file and added a cube in a followed your steps and i dont get 8 in Unity, i get 20 now? and i am just importing the blender file and have ‘normals’ set to none in the settings. I just cant figure out where i am going wrong :frowning:

2922999--215968--upload_2017-1-16_23-20-3.png

Ah, don’t worry, you’re not doing anything wrong, I was just thinking you meant number of verts shown in Blender. Unity does its own import and things ends up a bit different.

So as you can see, Unity is splitting the vertices, giving one to each face of the cube so you end up with 20 or even 24 (depending on your import settings). Why is this?

Well, Unity will split a vertex into multiple copies if one or more of the following is true:

  • It has a different normal vector
  • It has a different UV coordinate
  • It uses multiple materials so it’s part of a submesh
  • Probably other arcane Unity magic reasons

Sometimes you can increase the Normals smoothing angle (when set to Calculate) in Unity to reduce the total verts on things, but that’s unlikely to help for your cube because it also triggers point #2.

Thing is, think of a single vertex at one top corner of your cube. You want every face to display the same texture here, so that one vertex is going to be at the top right of the UV map for one side face, the top left for another face, and probably some other corner for the top face too. Since that one vertex is in multiple locations on the UV map, Unity is splitting it up. Same applies to the others.

For instance if you unwrapped your cube like this instead:

A lot more of the verts would be all in the same place. And if you do that, and go into Unity, and set Normals to calculate, and set the smoothing angle above 90, you’ll see that your cube suddenly has a lot less verts. But you’ll also have a very smoothed-out looking cube: Unity needs the extra verts to show the sharp edges anyway. Plus now you’re getting a lot less use out of your texture with that tiny non-repeated UV map.

Does that make sense? Honestly the real answer is you aren’t doing anything wrong, that’s just how it is, and don’t worry about it. Graphics cards can push millions of triangles and you can’t avoid the extra verts here easily anyway. But it is good to know why.

Hey

Thanks again, I think i understand now, Im glad i posted on here. Its interesting about the smooth vertices and how Unity needs the vertices to show sharp edges. So all i think im not understanding is that from my point of view that with the default unwrap (which i did in the last post) layers all of the 6 sides to use the whole 256x256 texture bounds. So i imagine it like they are all exactly in the same position on the texture, therefore use the same co-ordinates?

I ask as i imagine that if i unwrap using project from view i dont get any increase in vertices in Unity and i imagine that they all must use different co-ordinates. Or i have know idea still how it truly works haha.

The other reason im interested in this area is that for a basic model of a cube if i get 20 vertices instead of 8 then if i repeated this cube (duplicated) across the scene in Unity it would be ok as Unity will batch them and could end up with 1/2 draw calls.

I have another model (crate) with 40 vertices and import into unity (same process with the material etc) i get 160 vertices or so (around that number). Then if i duplicate this across the scene i start getting batching only up to 70 instances.

So the more detail i add it seems im getting alot higher ratio of Unity multiplying the vertices count. So lets say i had a model with 150 vertices and i could end up with a count of 300+ in Unity and ive read that batching wont happen above 300. Which is not good as the model is only has 150 vertices.

p.s. i need alot of various shapes of cubes across my scene and im targeting Android for my test game.

Thanks.

Nick

Nah, here’s an MS Paint diagram:


Imagine that’s your cube on the right, with texture on the left. UV set so that every side is covering the whole texture.

Now think about the vertex I marked with an arrow on the right. For the side of the cube on the left that you can see there, that vertex will be at the top right of the UV map. For the side of the cube on the right, that same vertex will be at the top left of the UV map, by the sun. For the top side of the cube there, that same vertex will be at the top right again, so that one won’t count as extra.

You can rotate the UV map for each side to save some vertices, but you can only save a certain amount and still have it mapped that way.

This is getting a bit more complicated, since dynamic batching is affected by lots of things. Static batching is much better - can you make them static or do they all need to move? GPU Instancing may help you.

1 Like

Hi Nitron,

thanks for the visual representation, it makes sense now i there is a visual. Many thanks.

Im using dynamic batching as i have cubes which 80% of them dont move (static) BUT i have triggers on them and I use physics in my game so ive been told static batching is best not to be used?

Nick

Trigger colliders can also be static. If the cube is not enabled/disabled, scaled or moved during gameplay and there is no rigidbody it is static.

Well, I’ve learnt something from this thread now too. I didn’t know that activating/deactivating static objects had a performance penalty. Does it really? I found a couple of other threads of people asking the same question but neither had an answer.

But yeah, any of your cubes that don’t ever move, you can set those ones to static. Even with trigger colliders on them.

Thanks guys you have made alot of things clear now. I guess it’s important for me to test now as see what results I get. Now to read on about the Unity profiler.