1. Trang chủ
  2. » Công Nghệ Thông Tin

Creating 3D Game Art for the iPhone with Unity Part 9 ppsx

28 356 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 28
Dung lượng 3 MB

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

Working with Game Assets in Unity iOS Throughout this book, we’ve been discussing creating game objects for a Unity iOS iPhone or iPad game using both modo and Blender.. Now, we’ll look

Trang 1

I created a different look for my game as you can see in the comparison of the default-baked scene and the color-graded scene.

Adding Grime to Maps

The level looks great with the lightmaps applied; however, for a trash yard, the scene looks way to clean We need to introduce some dirt and grime to the scene.This is quite simple to do in Photoshop First, I created a grime brush preset as shown in Fig 8.30

I then created a new layer and chose my preset brush, changed some tings in the brush editor so that I could stamp the grime down by simply left-clicking I then began to stamp random dirt across the scene as shown in Fig 8.31 It’s important to be mindful of the seams as due to the nature of the lightmap UVs, there are lots of seams and careless painting can really reveal these seams as shown in Fig 8.32

set-FIG 8.28 The Exposure Was Adjusted

in Photoshop Using the HDR Toning

Tools

FIG 8.29 Here You Can See the

Difference That Color Grading Your

Maps Can Have on the Style and Look

of Your Levels

Trang 2

FIG 8.30 I Took a Grime Map from My Texture Collection and Created a Brush Preset in Photoshop.

FIG 8.31 The Dirt Was Stamped Across the Scene and Was Placed on Its Own Layer

Creating Lightmaps Using Beast

Trang 3

FIG 8.32 By Painting Directly on the

Seams, You Can See That the Seams

Become Visible in the Lightmap

In Photoshop, you can then adjust the strength of the dirt by adjusting the opacity of the layer Again, saving the file results in the lightmap automatically being updated in Unity iOS

FIG 8.33 The Secondary Dirt Layer Was

Used to Create Accumulation in the

Corners and at the Base of the Walls

Once the base layer of grime was laid down, I went back and then added a secondary layer to further hide the tiling effect of the dirt In this second layer

of dirt, I stayed completely away from the seams and used a combination of a smaller version of the grime brush and the eraser tool to create dirt accumula-tion around the edges of the walls and areas where the barrels were stacked in corners In Fig 8.33, you can see the secondary dirt layer

Trang 4

In this chapter, we discussed the usage of lightmaps not only to optimize your

scene, but also to add a greater level of style and realism The adoption of

Beast has quickly become one of my favorite features in Unity iOS Its quality

and productive workflow is unparalleled, and in the spirit of being “Unity way,”

its full integration makes creating lightmaps a breeze and puts the creative

power back into the hands of the artist

In Fig 8.34, you can see a comparison between the default lightmap and the

lightmap with dirt applied Notice that the scene looks much better and more

rich since the dirt layer provides a level of randomness and detail to the level,

as well as match the overstyle of the level design being that of a trash yard

FIG 8.34 Notice That the Dirt Layer Provides a Layer of Randomness and Detail, Thus Improving the Look and Style of the Level

Creating Lightmaps Using Beast

Trang 6

Working with Game Assets

in Unity iOS

Throughout this book, we’ve been discussing creating game objects for a

Unity iOS iPhone or iPad game using both modo and Blender In this chapter,

I’d like to discuss the Unity iOS component as it relates to art assets created in

the previous chapters

The goal of this chapter isn’t about creating an entire game from start to

finish All of the previous chapters have paid close attention to how our game

assets were built with the mindset of using Unity iOS to deploy them to

Apple’s iDevices Now, we’ll look at using Unity iOS in regards to how we can

begin to integrate these assets into actual game components as well as

fur-ther optimize them for the iPhone and iPad We’re going to discuss topics such

as using Prefabs, texture compression, as well as iPhone- and iPad-optimized

shaders We’re also going to revisit the usage of physics in your game by

showing the usage of Unity’s NVIDIA PhysX Engine as an alternative over the

baked animation method discussed in Chapter 7 Finally, we’ll look at

publish-ing your game and the iPhone Player Settpublish-ings as well as optimizpublish-ing your game

with the Internal Profiler

Chapter 9

Trang 7

Let’s get started with taking a look at Prefabs and as always, be sure to drop in

to Tater’s Weapon Load Out to stock up on extra resources

Prefabs

Prefabs allow you to create reusable game objects and are extremely useful when building complex objects in your scene For instance, with the environ-ment objects such as the barrels and boards, I created a prefab out of these items as shown in Fig 9.1

Tater’s Weapon Load

Out

Go to the resource

site to view the video

walkthrough for this

chapter

Creating Prefab for Environment Props

Since these objects were going to be duplicated and reused across the entire level, creating a Prefab for these objects makes a lot of sense In the Prefab,

I arranged the props in a predetermined setup This setup allowed me to save time when duplicating the objects and arranging them in the scene as I only had

to do some minor rotation and translation on the props to randomize their ment in the level I also added the Colliders to the objects as shown in Fig 9.2

place-Target Prefab

I created a Prefab for the target object as well, since it will be reused out the level as well In Fig 9.3, you can see this Prefab We’ll talk more about the target object later in this chapter This Prefab is more complex in that

through-FIG 9.1 The Environment Props Were Created into a Prefab for Reuse Throughout the Level

Trang 8

it contains Rigidbody objects, a Particle Emitter, and scripts for driving the

particles and physics simulation Being that the target object has a complex

setup, creating a Prefab allows me to do this setup once, and then the Prefab

can be arranged throughout the level with all of its functionality already

worked out

Working with Game Assets in Unity iOS

FIG 9.2 Each Object Has a Box Collider Added to It so that the Character Won’t Pass Through It in the Level

FIG 9.3 The Target Object Was Also Created into a Prefab so that It’s Complex Animation Could Be Easily Distributed Throughout the Level

Trang 9

Camera Control Kit

The Third-Person Player controls, as shown in Fig 9.4, are a modified Prefab that is available online at UnityPrefabs.com UnityPrefabs is an excellent resource for purchasing high-quality game objects such as camera control kits, particle effects, and artificial intelligence Setting up camera controls is

a complex process, and for those, like me, who are more art oriented, being able to purchase a premade kit as shown in Fig 9.5, with all the functional-ity needed for my game is a great time-saver For instance, the Third-Person Camera Kit from UnityPrefabs.com, which was provided for the book by Efraim Meulenberg, quickly provided me with a ready-made control system that I could simply drop into my project

The Prefabs can be easily modified with your own graphics to meet the style

of your game The Camera Control Kits work very well and contain advanced features such as the camera never going through walls and the character swaying left and right while strafing

Probably the biggest challenge in game development isn’t in creating content or programming, but in simply completing the game and get-ting it to market Any headaches you can save yourself only help you

to overcome that challenge, and UnityPrefabs.com is there to lend a helping hand

Probably the biggest challenge in game development isn’t in creating content or programming, but in simply completing the game and getting

it to market.

FIG 9.4 This Image Shows a Modified Version of the Third-Person Camera Control from UnityPrefabs.com

Trang 10

Setting up Colliders

In order to have your character react with the environment such as being

able to move across the ground and stop when running into objects, you’ll

need to use Colliders

Colliders can be very expensive on the iDevices and should be used with

care There are five types of Colliders you can use, and some are more

expen-sive than others In Fig 9.6, you can see a diagram that shows each Collider

type as they progress from cheap to expensive in terms of performance

impact

You can actually choose to have Unity iOS automatically create Colliders for

you upon import by checking Generate Colliders in the Import Settings Dialog

as shown in Fig 9.7

The Generate Colliders option will add a Mesh Collider to your object The

Mesh Collider builds a Collider based off the mesh it’s applied to It can

Working with Game Assets in Unity iOS

FIG 9.5 This Image Shows the Default Prefab from the Third-Person Controller for the iPhone Available on UnityPrefabs.com

Trang 11

be very accurate for collisions, but also very expensive depending on the mesh In Fig 9.8, you can see that a Mesh Collider is added to the level sections.

In my case, the Mesh Collider will work fine since the level sections are very basic with a lower poly count However, on a more complex level model with a higher poly count, you’ll want to use a more optimized Collider such as the Box Collider Physics runs on the CPU so you’ll need to

use the Internal Profiler as we’ll discuss later, to find possible bottlenecks and to see if the game

is CPU bound, meaning expensive on the CPU However, you can’t just add a Box Collider to the section as it won’t compensate for the ground and walls, but instead just make the entire section

a Collider as shown in Fig 9.9

Instead, in your 3D program, you can create

a collision object that fits the area your level occupies, but it is much lower in resolution in which you can then safely apply the Mesh Collider Again, this wasn’t needed in my case, so we’ll take

a look at one of the Penelope tutorial assets that

is available in the Resources section at Unity3d.com In Fig 9.10, you can see that the level mesh for the Penelope game is more complex and just using a Mesh Collider on this geometry could cause an unnecessary performance hit Instead,

a lower resolution collision object was created

in order to optimize the performance of the Mesh Collider

FIG 9.6 This Diagram Lists the

Different Colliders in Order of the Least

Trang 12

Working with Game Assets in Unity iOS

FIG 9.9 The Box Collider Is Covering the Entire Mesh Like a Bounding Box and Won’t Work as an Effective

Collider

FIG 9.10 The Highlighted Mesh Above the Actual Level Is the Collider Object Notice Its Much Simpler Than the

Actual Level Mesh

Trang 13

Texture Compression

In Chapter 3, we discussed texture size and format You can actually compress textures and change their size within Unity iOS In Fig 9.11, you can see by checking Override for iPhone, you can then have access to setting the maxi-mum size as well as the format for the texture The size you choose for your textures depends on your game as well as the device the game is running

on For instance, you’ll need to use higher resolution textures such as 1024 

1024 for the iPad and iPhone 4 However, this is over-kill on the 3GS since its screen resolution isn’t high enough to really showcase these higher resolu-tion textures and thus would be a waste of system resources In Chapter 3,

we also discussed the importance of creating textures that are a Power of 2 (POT) Nonpower of 2 textures (NPOT) doesn’t fit in the iPhone memory It’s important to note that the rule of thumb is to create square POT textures, i.e.,

1024  1024 or 512  512 as nonsquare POT textures may end up not getting compressed, i.e., 1024  512 or 256  128

You should monitor your texture sizes in the inspector and verify that you’re using PVRTC4 or PVRTC2 compression Now, there are always exceptions to rule, say for example if you want to create some high-quality icons for your game’s UI, you could use RGB16 compression

Mip maps

Mip maps, which can be set on the Texture Importer by checking Generate Mip Maps as shown in Fig 9.12, are a series of progressively smaller versions

FIG 9.11 You Can Set the Texture

Size as well as Format In the Texture

Importer Dialog

Trang 14

of the image used to optimize performance They can be extremely vital on

the iPhone and iPad Using Mip maps uses more memory, but not using them

can cause major performance loss

However, Mip maps can make your scene textures look blurry To compensate

for this, I typically set the Mip Map Filtering to Kaiser, which in my opinion

tends to lessen this blur as shown in Fig 9.13

Working with Game Assets in Unity iOS

FIG 9.12 You Can Enable Mip Maps for a Texture in the Texture Importer Dialog

FIG 9.13 Here You Can See the Difference between Kaiser and Box Mip Map Filtering Box Filtering Is Much More Blurry than Kaiser

Trang 15

Mip maps are designed to optimized textures that can appear very small on screen as they are pushed into the distance in 3D space However, as discussed

in Chapter 4 in the “Building on the Grid” section, we can manually create this effect ensuring the meshes are using only a specific and proportional section of the texture atlas to mesh size, which directly relates as a one-to-one relationship between the meshes size in units and the texture size in pixels This means that the textures will never be too small in the scene, and thus, we don’t need to worry about using Mip maps Profiling your game will ensure it’s optimized correctly

Optimized Shaders

It’s very important to make sure that you’re using shaders that are optimized for the iPhone and iPad devices Unity iOS ships with several useful iPhone compatible shaders as shown in Fig 9.14

I highly suggest that you use these shaders as much as possible Using the wrong shader can cause your game’s performance to drop dramatically There

FIG 9.14 Here You Can See the

iPhone-Specific Shaders

Trang 16

are two categories in terms of shader optimization,

which are Pixel-Lit and Vertex-Lit

Pixel-Lit shaders are much more expensive than

Vertex-Lit shaders Pixel-Lit shaders cause objects to

be drawn multiple times depending on the number

of Pixel Lights shining on the object since they

cal-culate lighting at each pixel This not only increases

the load on the CPU to process and send commands

to the GPU, but the GPU will also have to process the

vertices and draw the pixels on screen

Vertex-Lit shaders calculate light based off the mesh

vertices using all of lights at one time, which means

the mesh will only need to be drawn once

It’s important that you don’t use any Pixel-Lit shaders

in your scenes for the iPhone and iPad To be safe,

stick with the iPhone Shaders provided by Unity iOS

unless you have a specific reason for using a different

or custom shader For example, when setting up Beast

for my level material, I had accidently set it to use

the Diffuse shader, which is a Pixel-Lit shader When

profiling my game, I realized that all of a sudden, my

frame rate had dropped down 6 FPS After digging

around a bit, I realized my mistake I then switched the

level material to use the Diffuse Fast shader, which is a

Vertex-Lit shader as shown in Fig 9.15

Shaders can have a dramatic impact on your game

It’s important to be sure that you’re strictly using

Vertex-Lit shaders and that your shaders aren’t

per-forming any multipass operations, as this will cause

your object to be drawn more than once and also

impact performance on the iPhone and iPad

Using Physics in Unity iOS

In Chapter 7, we discussed a method for baking a dynamics simulation in

Blender As I mentioned, that method can be more expensive on the GPU

Typically, with the newer iDevices such as the 3GS, iPhone 4, and iPad, the

CPU is quite fast and the bottleneck for performance can fall to the GPU

side with the higher resolution devices such as the iPhone 4 and iPad as we

discussed in Chapter 1 If your game is already heavy on the rendering side,

meaning it’s already using up a lot of the GPU resources, it might make more

sense in terms of performance to use Unity’s NVIDIA PhysX Engine This would

shift the workload over to the more capable CPU rather than the GPU and can

be an alternative to the baked animation method discussed in Chapter 7 Also,

Working with Game Assets in Unity iOS

FIG 9.15 For My Level Material, I Used the Diffuse Fast Shader Because It’s a Vertex-Lit Shader

Ngày đăng: 08/08/2014, 13:21

TỪ KHÓA LIÊN QUAN