Programmer Art: A simple Jet blend for generating game sprites and how to use it

12. September 2014

 

Today while putting together this Phaser spritesheet tutorial I found myself needing a series of sprites to create a sprite sheet with.  Downloading samples from the web can be a tedious process, especially when TexturePacker wants individual frames.  Then I remembered the Blend file for my Blender Game Art tutorial was sitting on my dropbox folder, preconfigured to render sprites.  Two seconds letter, presto, the sprites I needed.

 

Then I realized in the entire tutorial series, I didn’t actually published the finished Blend.  Oops.  It dawned on me today that programmers struggling with programmer art might find a Blend file that can spit out a sequence of jet sprites could be of some use, so here is this post.

 

First, here is the blend file.  It’s nothing special, but its already animated and the texture is included in the Blend file.

 

Now, the how to use it part.  Double click the Blend, and assuming you have Blender installed, it will load up preconfigured for you.  Now to render a sequence of frames.

 

The initial window should look like this:

image

 

Now on the right hand side, change the output directory to where you want the files to render:

 

image

 

An absolute path is fine by the way ( aka, C:\TEMP ).  I used c:\temp\sprites\jet

This will result in the files having the name jet in the folder c:\temp\sprite.  It will make it if it doesn’t exist.

 

Now scroll that window up and click the animation button:

image

 

And now open the folder and presto:

image

 

20 Sprites ready for game use!

 

Of course you can play around with the settings and camera to get different angles etc.  For higher resolution images or more frames, change that in the render panel:

 

image

 

 

Hope some of you find this useful the next time you need a sprite animation!

Art




Baking Blender materials to texture to make them usable in a game engine

16. July 2014

 

Or…

How to take a Blender model you downloaded from the web and make it actually usable in your game in 28 easy steps!

 

… granted, the second title doesn’t have the same flow to it, does it?

 

I just had to run through this process and I figured I would share it as it is something that occurs fairly often.  When working with Blender, there are dozens of behavioral textures available that can make for some very nice results quickly.  The only problem is, when you get your asset out of Blender and into your game engine, things suddenly go horribly wrong.  The problem is, those textures only make sense inside of Blender.  Fortunately through the magic of baking, you can easily convert them into a texture map usable in any game engine.

 

Let’s take a look how.

 

First we need a model.  I am using a beautiful new model that was recently added to Blend-Swap.  It’s a free download but you need to register.  Don’t worry, you can use a real email address, they don’t spam, or at least haven't so far.  The model in question looks like this:

 

image

 

Unfortunately when we load it in Blender we quickly learn this model is in no way game ready.  Let’s take a look:

image

 

Ick.  So instead of a single Mesh, we have a dozen individual meshes.  Problem is, we need to unwrap them as a single object, so let’s join them all together.  First let’s get the camera out of the default layer.

 

If you look at the way this particular Blend is setup, there are currently two layers, the second contains the armature, the first contains everything else.

image

 

Lets get the camera out of there.  Select the camera object then hit the M key.  Then select the layer you want to move the camera to, like so:

image

 

Now click the first layer ( bottom left box ) and it should now only contain geometry.

 

We want to join everything together.  Press ‘A’ to select everything in the layer, then hit “Ctrl + J” to join everything into a single set of geometry.  Now it should look something like this:

image

 

Perfect, now we can unwrap our model.  Switch in to EDIT mode

image

 

Press ‘A’ again, until all faces are selected, like so:

image

 

Now we unwrap our model.  Select Mesh->UV Unwrap-> Unwrap ( or Smart UV Project ).

 

Switch your view to UV/Image Editor

image

 

It should look something like this:

image

 

Now create a New Image:

image

 

This image is where we are going to render our texture to.  Here are the settings I used.  Remember, games like Power of 2 textures.

image

 

Ok, now let’s look at the actual render to texture part.  Take a quick look at how the model is currently shaded:

image

 

Frankly none of those are really game engine friendly.  So let’s render all of those materials out to a single texture.  Go to the render tab

image

 

Scroll down and locate Bake.

In the UV Editor window, make sure everything is selected ( using ‘A’.  They should be highlighted in yellow ).  At this point, with your generated image and all the UV’s selected, it should look like:

image

 

 

Now under bake, set the following settings:

image

The key values being Bake Mode = Full Render and Selected to Active checked.  Now click the Bake button.

 

Up in your top part of Blender, you should see a progress bar like so:

image

 

 

Now if you go back to the UV/Image viewer, and select your image RenderedTexture, you should see:

image

 

Cool!

 

Let’s save the result to an external ( game engine friendly ) texture.  Select Image->Save as Image.  Save the image somewhere.  Remember where.

image

 

 

Now lets modify the textures on our model to use only our newly generated texture map.  First in 3D View, switch back to Object Mode from Edit mode.

Then, open the materials tab:

image

 

Select each material and hit the – ( or killswitch engage! ) button.  So it should ultimately look like this:

image

 

Now hit the + button and create a new Material.  Then click the New button.

image

 

The default values for the material should be OK, but depending on your game engine, you may have to enable Face Textures:

image

 

Now click over to the Texture tab.  Click New.

image

 

Drop down the Type box and select Image or Movie.

image

 

Scroll down to the Image section and select Open.  Pick the image you saved earlier.

image

 

Now scroll down to Mapping, drop down Coordinates and select UV.

image

 

Under Map select UVMap.

image

 

Now if you go to the 3D View and set the view mode to Texture:

image

 

TADA!  A game ready model.

 

One word of caution though, if you render this scene in Blender you will get the following result:

image

 

Don’t worry.  That’s just a biproduct of going from Blender materials to texture mapping.  If you want the texture to be seen, you need to add some lights to the scene.  Or change the material so it has an Emit value > 0, so it will provide it’s own light source.

 

With Emit set to .92, here is the result if you render it:

 

image

 

Now, what about it game?

 

Let’s create a simple LibGDX project that loads and displays our exported model:

 

package com.gamefromscratch;

import com.badlogic.gdx.ApplicationListener;
import com.badlogic.gdx.Files.FileType;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.PerspectiveCamera;
import com.badlogic.gdx.graphics.g3d.Environment;
import com.badlogic.gdx.graphics.g3d.Model;
import com.badlogic.gdx.graphics.g3d.ModelBatch;
import com.badlogic.gdx.graphics.g3d.ModelInstance;
import com.badlogic.gdx.graphics.g3d.attributes.ColorAttribute;
import com.badlogic.gdx.graphics.g3d.loader.G3dModelLoader;
import com.badlogic.gdx.utils.UBJsonReader;


public class ModelTest implements ApplicationListener {
    private PerspectiveCamera camera;
    private ModelBatch modelBatch;
    private Model model;
    private ModelInstance modelInstance;
    private Environment environment;

    @Override
    public void create() {
        camera = new PerspectiveCamera(
                75,
                Gdx.graphics.getWidth(),
                Gdx.graphics.getHeight());

        camera.position.set(3f,0f,6f);
        camera.lookAt(0f,1f,0f);

        // Near and Far (plane) represent the minimum and maximum ranges of the camera in, um, units
        camera.near = 0.1f;
        camera.far = 300.0f;

        modelBatch = new ModelBatch();

        UBJsonReader jsonReader = new UBJsonReader();
        G3dModelLoader modelLoader = new G3dModelLoader(jsonReader);
        model = modelLoader.loadModel(Gdx.files.getFileHandle("robot.g3db", FileType.Internal));
        modelInstance = new ModelInstance(model);

        environment = new Environment();
        environment.set(new ColorAttribute(ColorAttribute.AmbientLight, 0.8f, 0.8f, 0.8f, 1.0f));
    }

    @Override
    public void dispose() {
        modelBatch.dispose();
        model.dispose();
    }

    @Override
    public void render() {
        Gdx.gl.glViewport(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
        Gdx.gl.glClearColor(1, 1, 1, 1);
        Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT);

        camera.update();

        modelBatch.begin(camera);
        modelBatch.render(modelInstance, environment);
        modelBatch.end();
    }

    @Override
    public void resize(int width, int height) {
    }

    @Override
    public void pause() {
    }

    @Override
    public void resume() {
    }
}

 

And we run it and:

image

 

Wow, a model downloaded randomly from the Internet actually working in the game engine!  How often does that actually happen? ;)

Programming, Art , ,




Substance Painter release Beta 3 to Steam

17. April 2014

 

I suck at texturing.

 

There, I said it.  I love 3D modeling, I even enjoy rigging and animating.  While not my favorite activity, I am even OK with UV unwrapping…

 

But texturing, I suck at texture mapping.

 

Over the years I have tried a number of solutions that make texturing easier going back to the early days of 3D Studio Max plugins that allow you to paint directly on your models.  Since then, those tools have become progressively more built in to the base package but at the end of the day, the vast majority of texturing still takes place in Photoshop and I still suck at it.

 

Enter Substance Painter.  It appeared on Steam about a month back and I’ve been playing around with it ever since.  I intend to cover it in more detail soon, in fact I would have already if it weren't for the massive influx of goodies that came with GDC this year.  Anyways, stay tuned for more details shortly…image

 

For now, a spot a of news.  Beta 3 was just released.  Oh, and if you buy during the beta it’s 50% off.

 

Enough talking, so what exactly is Substance Painter?

 

Short version; it’s the program that makes me not completely suck at texturing.  That’s about the biggest endorsement I can give.

 

Long version, well, I’ll use their wording for that:

 

Substance Painter is a brand new 3D Painting app featuring never before seen features and workflow improvements to make the creation of textures for modern games easier than ever.


At Allegorithmic, we have a long history of working very closely with our customers, from the small independents to the largest AAA studios. Today we want you to help us design the ultimate painting tool and bring innovation and state of the art technology to every artist out there at a fair price.

 

Today, as the title suggests, they released Beta 3.  As to what’s new in BETA 3:

Testing focus

  • 2D View
Change list
  • Added: Seamless 2D View!
  • Added: Bitmap layer masks
  • Added: Environment exposure control
  • Updated: Fill Layers now use the Tools windows to set their properties
  • Updated: Materials can be applied to Fill Layers
  • Updated: Added more stencils in the stencil library
  • Updated: Particles presets updated for faster computation
  • Updated: PBR shader optimization and quality improvement for lower quality settings
  • Fixed: Layers thumbnails are linked to the currently selected channel
  • Fixed: Lots of crashes

 

Sound interesting?  Here is a video of Substance Painter in action:

There is also a free trial available.  It’s a stand alone program, although some of the import options are disabled right now ( I used OBJ personally, from Blender ).  Keep in mind it is a beta, and feels Beta-like at times.  Some features are currently missing and performance can occasionally suffer.  On the other hand, outside of some missing features, it feels production ready.  I hope to have a more detailed preview available soon.

 

If you try it out, let me know what you think.

Art, News ,




Building a 3D Mech model: Part 2 Getting a leg up

27. March 2014

 

Ongoing documentation of creating a 3D mech asset.  Previously we ended with the torso and upper leg, like so:

 

image

 

Since then, I’ve rotated the upper leg back, created a foot and lower leg:

imageimage

 

Current face count is at 527, but there is a hell of a lot of optimizing that could occur here.

 

There are a couple ugly areas too, that I intend to address later.  Not to much sense worrying about the ugly bits until you are cleaning things up.  One area of ugliness is the union between the foot and lower leg.  I modeled the foot first then extruded the leg up from it.  I then needed to connect it to the upper leg, which had a different number of edges.

 

I could have simply added an equal number of edge loops, but that seems like over kill, so instead I’ve created a problem to be solved later.

 

image

As you can see, I have about 5 faces blunting into a single face (top arrow ), as well as some triangle junction points.  Getting rid of the tri’s should be simple, but the lower leg presents a bit more of a challenge.  Reality is, I am using far more polygons than I really need to be, so I will probably solve things by reduction, not addition.

Art ,




Building a 3D Mech model: The initial stages.

24. March 2014

 

I have the need of a fully rigged Mech model, for a couple of reasons, so I’ve started working on one.  Figured I would document the process as I go.  It’s somewhat of a background task, so don’t expect a whole lot of speed.  This isn’t a tutorial either, look here for that, just a documentation of my process.  Hopefully some of you find it worthwhile, while I am sure some of you will find it cringe worthy!

 

Here, are the humble beginnings:

image

 

One of the challenges all modelers face is where to start?  I had trouble deciding.  Generally if I stat with a limb, I struggle a bit with proportions going forward, so this time I decided to start with the torso and upper legs.  Of course details are going to be added as I carry on in the process.  Currently we are sitting at 390 faces.  Ultimately I want to be in around the 5,000 mark.  There are several easy points of optimization here.  The eagle eyed viewer may also spot my first mistake too.

 

image

 

I always try to work in quads only, but sometimes corners just turn into triangles like this.  Look what happens if we apply a couple sub-divisions around this corner:

 

image

 

It’s not the end of the world, but not as clean as I would have liked.  In this case though, it still leaves me with proper edge loops in both directions, so I am not to phased about it.

 

 

So, where you might ask, is the concept art?  This is a good point and generally I would sketch in a front and side view, like I did in the Blender tutorial.  That said, for reasons I can’t bring myself to understand, whenever I do this with pen and paper, I just end up ripping off existing designs.  So in this case, I’m just going to wing it, although when it comes to the cockpit area, I may have to reconsider.

Art