Saturday, July 20, 2013

Masked textures in UDK

July 20th, 2013

I have been working on my project and discovered that 20,000+ actors/meshes on the map can easily drag performance into the toilet. I am rethinking my models to minimize faces/vertexes. A big piece of the puzzle is masked / see-thru textures.

I had a hell of a lot of trouble getting masking to work properly. I thought I'd document the key bits of the process for reference & anyone else trying to solve this problem. I have photoshop as an image editor. I do a ton of photography and have been using this tool for a long time...

1. I built a sample graffiti cube texture with 2 windows. I cut the window areas out on the texture:

1. [CNTL]-click on the image of the layer. This selects all the pixels on that layer excluding the window cut outs in this case:

3. Click on the Channel tab and click on the alpha-channel button at the bottom. This adds the alpha channel for the windows.

Save your image as a 32 bit Targa (tga). If you save it as 24 bit, the transparency won't work: 

In UDK I imported the texture. I created a material directly from the texture. Here are the settings for the import:

After the import, the material doesn't work for some reason. Open the material, drag the texture around and then click the green checkbox and voila, you have a masked texture.

Monday, July 8, 2013

Blender & UDK continued

July 8th, 2013

Making sure your blender objects are the right scale is important if you intend to export them to UDK (or any engine). I've seen the following 2 setups:

Metric : 1 meter per grid square:
lines 16
scale 50 (a cube of 50 theoretically exports to 1 meter in UDK)
subdivision 10 (metric is all about divisions of 10)

Imperial : 1 foot per grid square:
lines 16
scale 16 (a cube of 16 theoretically exports to 1 foot in UDK)
subdivision 12 (12 inches per foot)

My observations:
1. a cube of 16 does not appear to be big enough for a foot. I think 22 is closer.
2. Blender builds its grid and snap-to-grid in multiples of 2. If you want your object to snap nicely inside UDK, it will need to be a multiple of 2. 16 works well & 50 does not.
3. these settings are done in the properties panel for the 3d view. while in the 3d view, press n and go to the "display" section.

I am going to go with a scale of 16 for now. I will see how that plays out over time.

Sunday, July 7, 2013

Blender -> UDK

July 7th, 2013

Creating Blender Meshes & Importing them into UDK

It has been a while since I posted but that doesn't mean I've been idle. There is so much to learn about blender and UDK that it is often intimidating to know where to begin. I have been focused on Blender, learning how to create meshes, simplify them and add texture to them.

I have learned a lot and I thought I'd jot down the important stuff that is a combination of information from a variety of sources.

Blender notes:

Texture Solid
If you are going to apply a texture to your mesh/object you need to view your object as textured solid from the start. I wasted an entire day building a complex object to find out that it was a mess when it came to applying the texture. What do I mean by this? Well, each face has 2 sides to it. One side is not textured and one side is textured. The is referred to as the face's Normal. When you add faces by hand (click 3+ vertexes and press f) blender doesn't know which side is textured. If you are not viewing the object as textured, you will end up with a lot of faces with the texture side facing the wrong way. If your object is complex, like a house/trailer, you can forget trying to fix it if you didn't start off viewing textures from the get-go
To view your object as textured, in your 3D View press CNTL-N to view the properties panel and select 'singletexture' for shading and check 'Textured Solid'.

Starting from a cube
For a project I am working on I needed to model a trailer. I watched some clever tutorials on building homes from floor layouts. They started with a plane that they extruded along the walls to build the house. Once complete they extruded the planes along the z axis. This was great except for one big problem: The faces on the extrude randomly faced inward and outward.
I recommend you don't start with a plane but with a cube. Blender then knows which way textures face because the cube starts out correct.

Vertex/Edge/Face cleanup
If you extrude cubes a lot, you are going to get a lot of vertexes, edges and planes. Reducing these as much as possible is important to improve render time. My goal with my trailer object was to eliminate all non essential vertexes/edges/faces to maximize performance. I have merged so many vertexes and created so many faces that it is second hand. I took it to an extreme however and when it came time to apply the texture to the faces, the face geometry was too big and complex and it made a mess out of things. In the end, I settled for smaller rectangles/squares when at all possible.
Example: even though the floor could be 1 rectangle, I chose to break it into about 20 rectangles so the texture could be unfolded for each rectangle.
So.. the rule of thumb is to not make faces of your model too large or your texture will look overly stretch. Break large faces into smaller faces to improve detail.

UV Map Texture
My goal with my object was to create one 1024x1024 image that contained all the textures I would need for my model. This required some planning. My image ended up containing 6 different images that I appropriately placed unwrapped faces onto:

I downloaded the images I needed from I then put them together into one image via photoshop. I knew the primary detail would be the white siding. The second largest detail would be the red siding. The remainder did not need as much detail. I may revisit this layout so that I can add curtains and other window details.
When you unwrap faces with a non-organic object like this, do it one face at a time. Blender does a much better job creating a face on the UV map you can work with.
For the trailer, I determined the largest face for each texture and based the size of the remaining faces mapped on the UV image from that. As you can see from the above image, you have complete control over the orientation, position and scale of the faces on the UV map.
Note: I heard that images for UDK must be a factor of 2 (ie: 128x128,256x256,1024x1024,etc). I am unsure if this is true but I wasn't taking any chances.
Here is an excellent tutorial on UV map editing:

Collision map for UDK
If you intend that your blender object lives in UDK, you will need a collision map. It shouldn't be anything fancy. For my trailer I create 1 cube that surrounded it. Here are the rules for collision objects:
1. You can have as many as you want
2. give each collisioin object the name UCX_* (* can be anything).
3. The collision objects do not need to touch each other
4. A collision object can not have any convex points
5. Keep it simple when at all possible

Exporting for UDK
When you have your object complete, export it to FBX format. This will not include your UV map texture but it will include your mapping of faces onto the UV map texture.

Importing into UDK
I don't know what it is about tutorial videos but no one seems to cover all the parts of importing into UDK in a clear step-by-step manner. I had to watch 4 different videos to understand everything I needed.
Here is what you need to do:
1. You need a Targa version of your UV map texture. You just need to save your image in photoshop as a targa. In the end I had a PSD (photoshop), JPG and TGA of my image.
2. Import the TGA as a texture in the content browser
3. right click in the content browser and add a new material
4. drag your TGA file into the material editor
5. connect black square on the texture to the 'diffuse' black square in the material and save the material:

6. import your FBX file
7. open the object and expand the LODInfo section until you get to Material entry
8. select your material from the content browser
9. click the green arrow on the Material section of the LODInfo on the object

And voila, you are done.

I must say, I am very impressed with the results in UDK. It looks really good and scales nicely. I am very excited about the project I am working on. In a few months I will post a link to it for the Oculus. It will be great. Really great.