Materials are a key part of every Unity game. Every scene will feature materials whether it be a AAA shooter to a slapdash asset flip. Materials are in every single game.

Materials are one of the deep parts of the Unity ocean. It’s as deep as they come. You could make a career just out of crafting Unity materials. It involves learning another programming language, some amazing math skills, and a deep appreciation of computer-based graphics.

Thankfully, you don’t need to go that deep. Unity provides everything you need out of the box.

Note: This tutorial is part of a collection that teaches Unity development from the ground up. You can read the entire series over here. This series is free and does not require any account creation. All assets are provided. If you find it useful, feel free to buy me a coffee.

Meet the shader

When speaking with game developers, you’ll often hear shaders interchanged with materials. In most cases, this makes sense, but do understand, a shader is not the same thing as a material. A material is a game engine construct. A shader is a program that runs on the GPU. Materials use shaders to produce graphics in your game.

A shader is written in a specialized language, such as HLSL (high-level shader language). This is a C-based language that calculates the color of every single pixel of a model taking into factors such as light, shadow, texture, and other properties.

So far, all your materials have been using pre-packaged shaders, but you can write your own.

Take for example the game Dead by Daylight. As you play the game, you will bump into another player. They will be playing one of the many different survivors.

A screenshot of Dead by Daylight with a survivor running from the killer.

Each aspect of the character will use different shaders. The hair shows texture. The face is moist and reflective. The eyes may glitter. The clothes use many different shaders, from the red sleeves to the dark shirt. You’ll notice a wristband on the survivor. That may also utilize a shader.

The game also features “aura reading” perks. Should you have such a perk, you will be able to see survivors outlines through walls.

This shows the red outlines of survivors in Dead by Daylight through the wall.

These are different shaders. They no longer show detail, but instead, provide a color outline of the player.

Games typically have hundreds to thousands of shaders. These shaders need to be compiled for the GPU. Console owners have the advantage of pre-packaged shaders since console hardware is identical. For PC users, they must suffer shader compilation. This can take a few minutes at the start of the game, but sometimes shaders are compiled during the gameplay, causing stutters.

Meet the material

Materials are created in the game engine, and they use a shader to produce the graphics. Materials often take many different inputs and also allow you to configure various properties. When you add a texture to a material, the material passes in the texture to the shader to use to draw the model. You can think of materials as the “control panel” for shaders.

Materials don’t just take textures, they also take various other image files. For instance, there’s also a normal map that defines the “roughness” of a surface. Height maps determine provide extra definition to a surface, giving the illusion of an uneven surface.

As this data is passed into the shader during runtime. The shader calculates the color of a single pixel based on all this information.

Understanding material properties

Open up your current project in progress. In the Project window, drag a BobbleArena-Column from the Models folder to the Scene view. The position doesn’t matter.

This shows a gray column without any cultures.

Expand the column in the Hierarchy and select the Cube GameObject. In the Inspector, you’ll see the material at the very bottom.

This shows all the Material properties.

There are many different fields. You’ll notice that the first dropdown is the backing shader. Currently, you are using the Lit shader from the Universal Render Pipeline. This is a general purpose shader provided by Unity. You can experiment with all the different shaders to see how your column changes.

If you are curious to see the shader code, click the Edit button next to the shader dropdown. This opens your code editor, allowing you to view all the shader code.

This shows shader code in an IDE.

As you can see, there’s some deep magic going on here. Should you be interested in writing your own shaders, there are many free resources out there. Just prepared to tackle the task like a boss straight out of Dark Souls. Also, there is a visual tool called ShaderGraph that allows you to visually construct your shader.

Now you’ll notice many properties in your material. If you hold your mouse over a property, a tooltip will explain the purpose of it. Here is an example of the Alpha Clipping property.

This shows a tooltip with the information of the Alpha Clipping property.

This is part of the Surface Options category. This determines how the material will look. You see examples from the official Unity documentation.

The most important property for this series is the Base Map property. This is where you add your image texture. Click the Base Map circle, and select the Bobble Wars Marine texture.

This shows the Base Map with the textures showing

When you do this, the entire column updates. This is because all the various GameObjects are using the same material.

This shows a column now with colors.

Adding the Columns

Materials can be its own tutorial series. For now, you’ll return to the game in progress and add all the columns.

In the Hierarchy, drag the BobbleArena-Column into your Prefabs folder to turn it into a prefab.

With BobbleArena-Column instance still selected in the Hierarchy view, go to the Inspector and set position to (1.66, 12.83, -54.48). Set scale to (3.5, 3.5, 3.5).

This shows the transform with the updated coordinates.

You do want all the prefabs to be the same scale. In the Overrides dropdown, click the Apply All button.

This shows the Overrides dropdown with the Apply All selected.

This will share the Scale and Rotation with all the other Prefabs. Positions are not shared.

Now it’s time for you to make the rest of the columns.

Dragging one column at a time from project to project in the Scene view can be a little tedious, especially when there are several instances. Duplicate a column by selecting one in the Hierarchy and pressing Ctrl–D on PC or Command–D on Mac.

Create a total of six duplicates and give them the following positions:

  • Column 1: (44.69, 12.83, -28.25)
  • Column 2: (42.10, 12.83, 30.14)
  • Column 3: (-8.29, 12.83, 63.04)
  • Column 4: (80.40, 12.83, -13.65)
  • Column 5: (-91.79, 12.83, -13.65)
  • Column 6: (-48.69, 12.83, 33.74)

You’ll notice that the columns have a similar name with unique numbers appended to them. Since they essentially act as one entity, it’s fine for them to share a name. Hold the Shift key and select all the columns in the Hierarchy. In the Inspector, change the name to Column.

You should now have seven columns in the arena.

This shows the arena with all the columns

The arena looks good, but the Hierarchy is a bit messy. Tidy it up by clicking the Create button and select Create Empty. Rename the GameObject to Columns and drag each column into it.

Your hierarchy should look like the following:

This shows Hierarchy with the columns in a Column game object.

Your arena is ready for some action!

Where to go from here

Materials are an insanely deep topic that combines math and art. Thankfully, Unity provides some out of the box shaders that work well in most cases. At some point, you will reach a point where you will need to dabble in shaders.

ShaderGraph is a built-in Unity tool that allows you to build your own shaders, but using Unity’s interface. It still looks wildly complex, but it’s a good way to approach custom shaders. Finally, there are lots of other free sites and videos that teach shader development.

That said, you are moving on from materials and explore using labels specifically to create alien spawn points. You’ll do this in the next tutorial.


Discover more from Jezner Blog

Subscribe to get the latest posts sent to your email.

By Brian Moakley

Brian Moakley is a writer and editor who lives amongst the quiet hills in New England. When not reading tales of high adventure, he is often telling such stories to all who will listen.

Related Post

Leave a Reply