Wednesday, June 5, 2013

A Simple Case of Too Flat Textures

My floor and ceiling leave a lot to be desired. No, I'm not talking about my real-life home; the textures of the ceiling and floor in my little Blender-made room simply don't cut it. It's not that they're bad: they just lack enough detail to make them believable.

I'm not particularly fond of this texture anyway.
After days of scouring the internet and finding no free carpet textures that tickled my fancy, I was forced to stick with the one I'd been using since day 1. It's an alright texture, but it just doesn't feel right for the room. I was dead set on finding a replacement texture for it, and I would not rest until the task was complete; I even went as far as to ask people to take high resolution photographs of their non-white carpet, make them seamlessly tileable, and upload them for me to use as a texture. This didn't happen, but I did manage to find some decent carpet textures with the help of someone in an IRC channel.

The reason I didn't want white carpeting in the room was because the walls and ceiling were already light-colored, and a white carpet just wouldn't look right. A darker colored carpet, such as the one I have already been using, creates much needed contrast between the walls, ceiling, and floor, so they don't blend together as one.

This texture looks more like carpet than the last.
The new texture was great and looked a lot like carpet, but it still lacked certain details to make it feel real. The problem is that it was too flat, and the solution to this type of situation is to create a normal map to create the illusion of bumpiness. I used GIMP in conjunction with the downloadable gimp-normalmap plugin to create the appropriate normal map texture by using a copy of the carpet texture, imported it into Unity, changed the floor plane's shader from diffuse to bumped diffuse, and applied the normal map to the floor.

Now with extra bumpiness!
With the normal map applied, the carpet texture looks more bumpy and less flat. Sure, the results aren't spectacular, but you're not going to get super realistic strands of carpet poking up out of the floor unless you want to hurt your game's performance by using extra polygons or something. I might continue to tweak the normal map in GIMP until I find a "perfect" fit for the floor, but this is good enough for now. I also normal mapped the ceiling due to its ugly flatness.

Before applying the normal map.
After applying the normal map.
As you can see, normal mapping the dull, blurry ceiling turned it into a crisp, detailed ceiling. Normal mapping is definitely a great way to add more detail to your game, and it just looks so much better than without.

Monday, June 3, 2013

The Wall and the Room

When I began using Unity3D about two weeks ago, I was overwhelmed by the vast amount of features and couldn't decide where to begin. The manual seemed like the best place to start, but it just wasn't teaching me in a way where I could quickly grasp onto the basic mechanics. I needed a tutorial; one that was thorough, but not enough to feel too overwhelming.

I wanted a written tutorial because I learn better when I see the details in writing than I do by parsing voice instructions (that and the fact that I have a 15GB/mo bandwidth cap,) and I found what I was looking for in two PDFs tucked away in the Unity manual (GUI Essentials/Scripting Essentials). Reading these was quick and painless, and afterward made me feel like I'd been using Unity for years. They taught me how to maneuver around the scene editor, create objects, scale them, apply textures to them, and much more. As short as those two tutorials were, they certainly cleared the path for me and I no longer had to wonder where to begin using Unity; they are, as their titles imply, essential when beginning with Unity.

Since I now knew the basics of using Unity, I wanted to further expand upon my knowledge; what better way to do so than just chuck learning aside and focus on making something? Granted, you'll need to learn to do the things you want to do, but you need to want to do something before knowing what you need to learn.

I began work on a small project based on an idea that I have no intentions of undertaking right now. It's a simple house (at the moment: room) which I began constructing in Unity using cubes for the walls, ceilings, and floors. It was simple and taught me more about constructing more believable environments than just cube pillars, planes, and falling boxes with rigid body physics. I threw in a point light and Unity's preset first person controller asset and had a nice, textured box that I could walk around on the inside.

Emptiness at its (somewhat) finest.
Being the IRC addict that I am, some people and I got into a conversation about properly constructing interior environments. While you could use Unity's built-in geometry, it is by no means a 3D modeler (unless you have GameDraw or something.) Since I was building a house, I would want more than just four walls, a floor, and a ceiling. Doors, for instance, would require having a hole in the wall for its placement, not to mention the door model itself.

Someone had stated that most/some developers create their interior environments in a proper 3D modelling tool, import them into their project, throw them into the scene, and decorate it with other imported assets (such as furniture models.) I had Blender, but never really had a reason to learn how to use it other than for fun; since my plan was to make a 3D game and I would eventually need to learn how to use it to create models, I decided to go ahead and learn how to use it for the purpose of modelling my house.

Skipping the details of me learning the interface of Blender (a lot more difficult than Unity's - I'll say that much,) I created a cube and scaled it appropriately until it resembled a wall. I then subdivided the cube many times until there were enough faces for me to select to cut out a hole into each side of the cube where the door would go, and then I closed off the gap between the two walls where the door holes were by adding 3 new faces (left, top, and right inside of the door holes.) All that was left to do now was texture it.

Unity requires a UV map for texturing models imported into it from Blender (this possibly goes for other modelling tools as well.) If you're uninformed on the subject, a UV map is essentially a map of the object's vertices upon a texture: a vertices' position is mapped to a texture, and the texture is applied to the model using the coordinates of all of the object's vertices within the texture map or something like that.

I couldn't for the life of me figure out how to create a proper UV map for the wall in Blender, and none of the tutorials on YouTube I watched were helpful. The most I could do was remake the wall model over and over and over, messing with the UV map each time until I eventually figured out how it worked on my own. This process took a week of on-again, off-again messing about, and I discovered that there were simply just too many vertices in my cube for me to easily manipulate the UV coordinates. Dissolving the vertices into as minimal faces as possible wasn't helping the fact that my unwrapped mesh looked like some random lines scattered about a blank image.

It kind of resembled a web slung by a drunken Spider-Man.
Finally, it occurred to me that using a cube for a wall probably wasn't the "proper" way of doing things, and I decided to use a rotated and scaled plane instead. I had just learned about the knife tool in Blender, so I straightened out my view in the editor and began cutting a hole into the plane in the shape of a rectangle door. The result was magnificent; I had finally figured out how to properly create my wall!

I duplicated the freshly made wall, moved it -0.25 on the x-axis, rotated it 180 degrees so the visible side of the duplicated plane was facing outward, selected both meshes, went into edit mode, and created faces on the left, right, and top between the two planes inside of the door holes to attach them. I unwrapped the walls using the Smart UV Unwrapping tool since normal unwrapping produced unusual results (because I have no clue what I'm doing) and proceeded to align the vertices up with the texture.

Using the color grid is extremely helpful in my case.
I had finally done it! I created a wall with a door hole and got the UV coordinates correctly mapped to the texture! Would it work in Unity, though? I tossed it in there and applied the wallpaper texture to it to see. The result was better than I anticipated.

Success!
I was pleased. After success had finally sunk in, I decided to go ahead and model the rest of the room. Using the same technique I did for the door wall (minus cutting a hole into it,) I successfully created a room that had unexpected gaps between the floor and walls. Bummer, but at least it could be fixed by repositioning the meshes in either Unity or Blender; being the perfectionist I am, however, that simply wasn't going to fly.

I had an idea that I could subdivide the plane and cut the faces off of it instead of using the knife tool to haphazardly cut the hole into the wall, so I decided to recreate the wall yet again using this method to cut out the door hole. After doing so, I selected all of the plane's vertices and did a limited dissolve which gave me the same results that I got with the knife tool - the only difference was that the position and size of the door hole was dependent on the subdivided faces I cut out and not my own judgment from dragging around the knife tool. This was overall a much cleaner way of cutting the hole into the wall.

The entire room model in Blender.
I grabbed a couple of new wallpaper textures from CG Textures and imported them into Unity for use on my walls. I was sick of seeing the old checkered pattern I'd been using from day 1. I also grabbed a new texture for the ceiling, but not for the carpet as I couldn't find any decent carpet textures.

This new wallpaper brings a fresh look to the room I've recreated a dozen times.
As you can see from the above screenshot, I threw in a first person controller so I could walk around the room. I also had to add a mesh collider component to the walls, floor, and ceiling to prevent the controller from going through them.

It looks a lot better than my first attempts.
In the end, I'm quite fond of my room. Sure, it's pretty barren and simple, but it's an achievement for me. The textures provide just enough detail to make me feel like a pro (hurrah for high-res,) though I know have a very long way to go before I can even dream to be.

What's next on my agenda? I haven't decided yet.

Sunday, June 2, 2013

To Reinvent the Wheel, or Not to Reinvent the Wheel

As a programmer (and perfectionist,) quite often I envision that reinventing the wheel is the way to go. As such, I often contemplated programming my own custom game engine, but is it really necessary to start from scratch when there are engines out there capable of doing what you need and more? That is a question I often pondered, and a question which always drove me insane.

Is it better to use this? Is it better to use that? Should I make my own? Should I steal this guy's code? I can't make up my mind, so I'm just going to do something else.

After going through this so many times, I finally decided to sit down and look at the situation more realistically: I have never done any sort of 3D programming before in my life, so in the time it would take me to learn OpenGL or some random library I found on the internet, I could easily learn to use an engine that is already made. I just wanted to make a game, right? That's what I always want to do, but the idea of making my own engine and knowing it from the inside out just appealed to me.

Unity3D was an engine I often looked at but never used. Why put the time into learning to use something when I'll never really know how to use it? As contradictory as that was to my statement in the previous paragraph, it made sense: Why? I could just make my own and know how to use it right off the bat, but that would require knowing how to make it.

I just kept going in circles. My mind was filled with confusion and the sensation of being shoved into a blender. My indecisiveness was getting the best of me (as usual); I needed to do something before it was too late and I lost interest in doing anything at all.

At the time, I had an idea for a game that would be a perfect fit for a certain platform. The idea was a 2D game at first, so - as usual - I fell back to GameMaker for its development. I soon realized that while it could work in 2D, the idea would be better off with 3D visuals instead. This brought me back into the loop of not knowing what to do. Make the engine myself, or use something else?

After weighing my options for the umpteenth time, I came to the conclusion that it would be in my best interest (and the game's) if I went ahead and used an engine to focus on the game itself, and not its foundation. I went with Unity3D due to my prior interest in it and its various platform support, and I have to say that I'm glad I did.

It's not like I probably would've written my own engine anyway; I'm an incompetent programmer who is overly ambitious and often get myself in over my head. Sure, there are some pros to programming your own engine, one of them being flexibility. You can do whatever you want with it and you already know how to use it, but that isn't for me; I don't need features that other engines don't already offer.

As I said before: to each his own. What's good for me may not be good for you and vice versa. Perhaps you have reasons for making your own engine that I do not, or perhaps you just want to do it for the experience. The developers of these engines have worked their butts off to bring you awesome features that would likely take you years to implement into your own engine if you don't know what you're doing, so I see no point in redoing their work when all you want to do is make a game.

That's all I want to do.