PBR Materials for Unity

Introduction

PBR stands for Physically Based Rendering, which means in a nutshell that with the aid of  different texture maps, the engine can simulate the interaction between light and materials with different color, metalness, smoothness and bumpiness. Unity Standard Shader is no exception and can handle rendering most natural and artificial materials.

In this post, I would like to briefly introduce how to merge different maps into one texture file and use it in Unity.

 

Channel Mapping

Channel mapping is the process when we get two or more grayscale images and pack them together in an RGB image. We can do this in a photo editing application manually, but many texturing tools have these functions built-in and need only a little tweaking.

Most color images you use as textures have 4 channels – Red, Green, Blue and Alpha. The shader can use one, or all of these channels at once for different purposes. We can take advantage of the fact that PBR Materials usually have 2 colored images (Albedo and Normal) and the rest is grayscale (Roughness, Metallic, Height, Opacity). A realistic looking PBR Material can have up to 7 different texture maps, and managing (and later in the game engine, computing with) these maps can be time-consuming.

 

How to convert a standard PBR Material to use with Unity Standard Shader

Note: I write down the process and the basics. You can find links on the bottom of this article for specific image editing applications.

Albedo: Base Color uses all RGB channels by default. Copy the Opacity (Transparency) mask (if there is any) to Alpha. If you have an Alpha channel, in Unity use one of the non-opaque rendering methods (for example, Cutout) from the dropdown list.

Normal: Unity uses OpenGL format normal maps. If your source texture appears flipped (DirectX format) in Unity, you should edit the Green channel and invert it.

Smoothness/Metallic: Invert your grayscale Roughness map, this will be your Smoothness map. Copy it to the Alpha Channel. Copy the grayscale Metallic map to Red channel.

Height: Uses a single grayscale image in sRGB format. The shader uses only the Green channel, so you can pack it into the Smoothness/Metallic if you need.

Occlusion: a grayscale sRGB format Ambient Occlusion map goes here. If you don’t need a Heightmap, consider packing this texture map into the Green channel of your Smoothness/metallic map.

Emission: Here goes either a black and white mask or a full-color RGB material.

Quick Cheat Sheet for Unity Standard Shader:

Channel Distribution for Unity Standard Shader. Texture names in (brackets) are optional.

Useful Links

Using the Channels Dialog in GIMP

Editing channels with Photoshop

Editing channels with Krita

Thanks for reading, I hope you found it useful!

Header Image Credit: freepbr.com

Creating game assets in low-poly style – Part II.

Welcome back and thank you for visiting again! In the second part of this little series, I would like to tell you about POLYJungle, my first attempt in making a fully detailed polygonal environment scene and models.

Jungle environments in games were always very popular – we all have a mental image of lush, diverse green vegetation, thriving animal populations and remains of ancient civilizations or small, secluded native villages hiding in the shadows of the world’s largest trees.

Jungles are home both to natural beauty and mystery, and in video games, this makes them a perfect setting, let it be platformer-style, adventure or survival game. 

Inspired by great games

Jungles are one of my favorite game settings from way early on – the first video game I ever played was Rayman by Ubisoft, released in 1995. 

The story starts right in the middle of a colorful, magical rainforest, thriving with dangerous inhabitants and collectible shinies, all drawn in a very distinctive cartoon style. 

Luckily, Ubisoft carried this jungle theme forward when they created more and more of Rayman’s world.

Exploring the jungle in Rayman 2

When I start to create a new environment pack, I always look first to reference and write a list about what are the key features of the scene.

In the case of the Jungle environment, I started to collect names and pictures of the most common jungle and rainforest trees, shrubs and smaller plants, as well as flowers.

I noted their size, color, and different parts (like leaves, flowers and separate branches) and decided which parts need to be separate for creating variety, and which parts should stay together in one mesh.

It was very delighting to browse beautiful orchids pictures and decide which ones should be included in the Jungle package.

Orchids growing on a branch

Then I moved on to artificial objects. I choose tribal village with small palm huts, similar to some Amazonian dwellings. I created the hut to be medium-degree modular, which means you can have an early building stage hut, a half-built hut, and a full hut. 

Of course, the future inhabitants on the jungle village will need some personal belongings, so I added a straw sleeping mat and clay jugs, as well as a few tribal masks to show their pride and individuality.

Scene building tricks

After everything was finished, I set up the Materials in Unity and built a little valley with the huts. I created this scene for showcase purposes only, so it shows its best from one angle, but with a little more work it could be expanded to be more immersive.

A little trick I made with the demoscene, is the light shafts – also known as volumetric lighting. I used a rather old-school method to achieve the light shafts and made a cone mesh, and textured it with a semi-transparent shaft texture, and set material rendering to Particles/Additive. 

Of course, there are more advanced tools to create volumetric light effects, such as using a Spotlight with a light cookie (this creates the illusion of the light shining through something, like a canopy). 

There are also numerous excellent volumetric effects solutions in the Asset Store, such as Aura.

I used Cinemachine virtual camera system and Unity’s built-in Post process stack to create the promo art images. With this tool, I can set up multiple virtual cameras with the same – or if needed, different – camera settings and post-process stack in different angles in the scene. 

I can cycle through them and snap high-resolution images easily. 

I asked Adam to write a custom Camera script for taking hi-res screenshots. With his help, I can set the desired resolution, a path to save the images, and a button (for example, “P”) to take a screenshot while in Play mode.

I hope you liked this little behind-the-scenes article and will be interested in the next article, which will feature our POLY Arctic package! 

Export in FBX from Blender to Unity

Exporting from Blender to Unity is a recurring question I meet all the time in various forums and Facebook groups related to modeling and Unity.

I would like to share with you my exporting workflow, which I use almost daily when I create 3D models for Unity projects. I will show the steps to export simple textured models, then move on to more complex cases with sub-meshes and PBR materials.

Common Problems

  • Object rotation is different: While Blender uses Y for depth, Z to height and X to width, Unity uses Z for depth and Y for height. This means all models exported from Blender with default settings will be rotated around the X axis by 90°.
  • Object Scale is different: Although Blender and Unity both use meters as base units, the FBX exporter measures units in centimeters by default. As a result, your model will be 100 times smaller in Unity than you intended if you use the default settings for the export.
  • Child object rotation problem: If you use more than two levels of submesh, you possibly encounter the problem with the rotation of the child objects.
  • Textures are not included in the FBX file.

The Solution

Step 1 – Center the mesh: set the 3D Cursor to the origin (Shift+S, Cursor to Origin), then select the mesh, press Shift+S and choose Selection to Cursor.

Step 2 – Check the Rotation and the Scale: make sure all your models have their rotation set to zero and scale set to 1. If not, apply the desired rotation and scale by pressing Ctrl+A, and selecting Rotation and Scale from the menu.

Step 3 – Set parents correctly: If you have an object with multiple sub-meshes, set them as a child of the main object by selecting first the child, then the parent and press Ctrl+P, then choose Object from the menu. Avoid multiple levels of sub-meshes.

A great example of this is a desk with drawers as child submeshes. If you have a separate submesh for the handle, that should be the sibling of the drawer instead. You can fix the hierarchy later in Unity.

Step 4 – Embed Textures: On the object’s Texture tab, under Image setting, choose your texture. Then click on the yellow box under the source field. This will pack the image file into the blend file.

Step 5 – Export with the following settings

Step 6 – Import to Unity. Check the official documentation for the Unity FBX importer.

Useful Blender add-ons

If you have a larger amount of models, don’t panic! You don’t have to export them one-by-one. I would like to mention one of my favorite Blender add-onsFBXBundle. This add-on was published in winter 2018, developed by Hendrik-Jan Schoenmaker. It has a wonderfully simple and intuitive interface, detailed instructions and Unity support. (Currently available for version 2.79).

Did you like this post? Share it with your friends! 

We post weekly new content, subscribe to our newsletter and stay updated!

Creating game assets in low-poly style – Part I.

What I love in this faceted, cartoony style is the clean shapes and silhouettes, it is easy on the eyes, and of course, lightweight in terms of file size and handling. These qualities making this style very popular in the indie dev scene, and many brilliant games use this style to convey a visually calming, story-driven game.

 

Below you can see games that inspired me:

OMNO is an athmospheric third-person adventure game made by a single dev, Jonas Manke

In this particular scene, simple large-scale forms with warm, soft colors and a straight, forward-driving composition are defining the mood of the setting. I can imagine the thrill when you first arrive in this misty land and start to explore.

AER - memories of old is a story-driven exploration game with puzzle elements by Forgotten Key

It all began in the Blender

Back in 2017, I was fiddling around with the different modifier tools in Blender. I wanted to create a few resource rocks, for later use, but in a more dynamic way than starting with a box and hand-crafting all the vertices. 

I started with very basic shapes – guess who, cubes and pyramids – and applied different modifiers and varied settings, and watched what happens.

Of course, it needed to add the small nicks and cracks manually, but there are many ways to do that part with modifiers too (for example, Booleans). 

When creating these rocks I used Subdivision modifier, Bevel, and Simple deform – Taper, and Simple deform -Twist. After that, I used the Autosmooth settings and some manually selected hard edges to create sharp edges and smooth surfaces on the swirls.

Rocks are easy to make and a staple for every environment, let it be an arid desert, a rocky beach, a mountainside, or a canyon landscape.

Cartoon desert line-up scene featuring the rocks, cacti and succulents.

I especially liked the swirly ice-cream looking spires and decided to make an interesting, fantasy-inspired desert scene with it. I quickly sketched a few cacti and succulents to bring life to my barren rocky desert. 

Well, to be honest, these became much more cartoon-ish than the rocks, and I decided to keep them curved and mid-poly (5000 tris including thorns).

Setting up the materials and textures was really simple, I used material colors only, and exported the meshes in FBX. Other options could be using Vertex Colors, but I ditched that idea since I wasn’t sure about how those work with Unity at that time.

Scene building in Unity

After moving the meshes into Unity, I created a lineup scene and created my prefabs. I also experimented with Material colors. 

Then I added a Terrain and started to carve out a canyon-like structure with the basic terrain tools, then painted it with flat colors (brown, sand, red sand etc.) 

After that, I dropped some of the rock prefabs and started to populate the canyon. It was quite a trial-and-error phase, and I wanted to show the best pieces of the rocks and the desert plants. 

I set up the Camera to focus on a bunch of rocks, and a swirly spire in the background.

The finished desert scene in Unity 5.6

You can see that there are dust floating through the canyon, these are simple Particle effects made with the built-in shuriken particle tool. Since I wanted to keep it simple and cartoon-like, I didn’t added much post-processing to the scene. 

However, I could do much better with the lighting setup, which I wasn’t very proficient back then in 2017.

I would like to show my progress in the next few blog posts with my new lowpoly scenes.

Free Sample

POLYDesert is a free sample of our POLYEnvironment collection.

Behind the Scenes: Dark Fantasy Kit – Part III

In this part, I would like to tell about some of the challenges and difficulties we faced during creating this asset pack. This diary won’t be complete without telling a bit about it. I hope you see them as milestones of a learning curve as I did.

Iterations

Thanks to Hack N Plan I tracked quite well how much time I spent on each task. It turned out, I spent way more time on the first phase than I planned. This was because I wanted to make sure everything will be set before I move on to finalizing the modular parts. 

The cycle was to model, export, build, and if there was a problem, move back to Blender and remodel that part. Making the stairs had more than 3 iteration cycles before I even get to high poly modeling and normal baking.

The elegantly curved form was not really good for vertex snapping. The railings had gaps, but I didn’t want to give up on separate railing parts, for the sake of reusability. 

The rectangular based columns were too small, so I made another set of bigger columns.

Columns in various shapes and sizes help create variation in the environment

Seamless Parts

Creating the walls and floors and make them tile seamlessly was less of a challenge than I thought.

However, the small stairs (steps) needed better planning, because the individual bricks had to be seamless in every direction, and the floor pieces need to be seamless with the basic floor too. 

I had to reshape these meshes a few times until I was satisfied with the result.

An early view in Unity editor of the tileable steps with placeholder textures

Shader shenanigans

Making the leaded glass windows – and making it look like it is leaded glass was one of the most memorable challenges. After creating the model and textures (together with alpha masks for the lead parts) I dropped it into Unity.

I got a friendly feedback on how the glass should refract light and create a distortion effect. First I used a built-in glass shader, but it only had a base color and normal inputs, and I needed the metal parts to be non-transparent and metallic.

We didn’t quite lay our hands on custom shader creation before, so we moved to Amplify Shaders to solve this. I am still new to this whole shader thing, but the result was much better than the first time.

After this, I had to move on with the rest of the package, and this whole glass shader issue was laid apart for more than a month.

 While assembling the Demo Scene, we got to it eventually again, and Adam offered his help with Amplify to solve the issue. Seems like a new eye can make all the difference when working on such a big project.

Cleaning up & Bloopers

When having a big pack with more than 400 prefabs, it can quickly grow out of hand with all the variations, parts, bits and pieces to stay organized. 

We went through multiple times on all of the folders, meshes, and prefabs, so future users of the pack won’t have any trouble while building a level. 

This was the phase in which we found other issues too, such as inconsistent prefab naming, unnecessary large textures, unused materials, and duplicate meshes.

 

So many prefabs to build from!

One of our favorite happy accident happened during the scripting of the doors. We made all drawers, doors, and cabinets interactive with these scripts, which use the pivot and axis of the object to rotate them accordingly. 

In this case, something got messed up and this door opened in a way we both were laughing in tears for a while:

Coming Soon to Asset Store - Dark Fantasy Kit!

The last, but not least task with any Asset Store pack is to create a nice presentation of the contents. With this pack, we built a few demo environments and highlighted the pack’s strong sides, showing its best within Unity. 

We refined the renders with the latest post process stack, and besides the screenshots, we will release videos and downloadable, playable demos too. 

The Dark Fantasy Kit is now available in the Unity Asset Store.
Get it now!

Thank you for reading this blog post, and feel free to share your insights in the Unity Forum.

Behind the Scenes: Dark Fantasy Kit – Part II

Phase I - Concepting and sketching

After all the planning was done, I started to work on the prototypes. 

I quickly sketched a few of every type of items in Blender, using only material colors and rough shapes, combined with lots of Mirroring and Array modifiers; I also used beveled Curves where it was needed to achieve complex curvy forms.

 I figured out the scale, main forms of the models, and tried out modularity in Unity. I also created a few basic materials, such as a stone, brick wall, wrought iron, and used some pre-made materials too.

Phase II: Base Assets Modeling and Texturing

This phase was, in my opinion, the most time-consuming task, and along the way.

I learned a lot about productivity, flexibility, and the importance of feedback. I made some detours and backtracking and had to reconsider some conceptual flaws. 

As it is with most production workflows, gradual iteration led me to refine my skills and I have to admit it is still visible – at least, for me – in the assets quality. 

Here are some early images of the first „pre-alpha” passes in Unity, where I tested modularity:

Testing walls, and stair tiles modularity in Unity

The modelling workflow

I usually use Box modeling, which means I create a model from basic shapes (boxes, cylinders, spheres etc.) and refine and detail them until I get the form I want.

I also like to use beveled Curves to build elegantly curved, or organic models. I often use Cloth simulation in case of draping fabrics. 

One of my favorites was creating the pillows, which I took from a tutorial, basically inflated the high poly mesh with a force field. 

The female sculpture modeling started with a Makehuman base mesh, decimated, her hair was formed of beveled custom Curves, and her dress with Cloth simulation.

Modeling stylized hair with a custom beveled Bezier Curve

Texturing

When I have both the high poly and low poly meshes, I create the UV layouts. If the model has smaller parts, like drawers, I move those away from the main mesh so they won’t interfere with each other when baking maps. 

I do the normal map, curvature, ambient occlusion (etc) bakes in Blender or in Substance. I also make a color-coded version of the mesh and create a color ID to be used in Substance.

I check face normals and correct them with Autosmooth or Weight Normals tool if needed. I export the mesh (or meshes, if they share an atlas). If the mesh is complex, such as the ornamented fences, I also prepare a simple form to be used as a LOD later. 

Then I move on to an image editing software to create masks and ornament alphas if needed.

Below you can see that I created details for this wardrobe from individual Arrayed mesh shapes. After normal map baking, the result was nearly the same as if I used hand-painted alphas to generate the detail normals in Substance. 

Making the high poly details can be more time consuming than painting the alphas, and normal map baking settings can be different for each separate part I do, and the resulting normal maps sometimes need manual correction, which I think is a bad practice. 

To be honest, I encountered this same problem multiple times while baking very small details, until I gave up and decided to paint alphas and generate normals procedurally at the later models. 

Of course, these furniture models are not for architectural visualization projects, which would need a higher level of detail.

Creating Materials

Creating textures from scratch digitally is a very rewarding task, even if you do not excel in traditional art. Luckily Substance Designer is the perfect tool for this. 

I constantly try out new node setups, watch highly skilled material artist’s tutorials and techniques. In some cases, I take the easier path and simply use a modded version of the built-in materials, or turn to an online material library.

While using a material as a reference, you can get a lot of information out of the previews, and there are also options to generate a seamless texture from a single colored picture.

I followed a well-traveled path of PBR material authoring, creating Base color (=Albedo), Normal, Roughness, and Metallic maps in Substance. 

I also experimented with Height maps, both within Substance and Unity, but I found that Unity’s built-in Tessellation shader is not very good when it comes to buildings, and it is more optimized to be used with Terrain.

So I ditched the idea and worked more on the base material. If I can move forward with my (currently limited) Shader knowledge, I will try to find a better solution for wall surface variations. 

Until then, normal maps and cornerstones will do the trick hopefully.

Creating Variation

With Substance, it is very easy to create more variations to a material in a non-destructive way. With the covered crates, I made three graphs for this material – one for the wooden parts, one for the fabric, and one where I merged those two and had the variation options exposed. 

Now I can adjust the base color, detail color, and any other setting I exposed in my main graph. This keeps the work organized: instead of a huge tangled graph, I have compact, customizable sub-graphs.

I also created a custom node which helped me merge the Roughness (inverted Smoothness), Metallic and Ambient Occlusion maps into one RGB image, as Unity’s Standard shader uses it. 

I really like the idea to use the channels of an RGB image instead of having 2-3 grayscale images.

In the next post, I would like to tell you about what challenges and difficulties I faced, and how I solved them while creating this pack.

Behind the Scenes: Dark Fantasy Kit – Part I

The Idea & motivation behind

In the end of 2017, I already had 3 model packs in the Asset Store, the School Gym, the Swimming Pools, and the Climbing Hall packs. Not to mention my earliest try, Alchemy Pack, which was my first attempt to post my work online. 

I looked upon my packs and thought, I definitely can do better, I just need more time… and inspiration. 

What to do for the community and the Store? If you search for Fantasy packs, you can have quite a lot, in various visual styles (lowpoly, cartoon, realistic, etc.) and quality. All have a nice, generic fantasy / medieval feeling to them. 

You can build villages, castles, entire cities… that will look just like all kind of peaceful creatures and law-abidding citizens dwell in it. 

Maybe a few dungeons and sewers for the lower-class villains?

Real Estate for Real Villains

So, what about the baddies? Sure, you can shove the evil guys to an underground, damp dungeon, or a cemetery (who lives in a cemetery, anyway?), or to a crumbling castle.  

But as I was surfing the Asset Store, I found that there are no environments for villains with style. Evil overlords who gain their riches off the poor peasant’s sweat and blood, who display their authority and oppression in forms of not just military power or deadly magic, but with their environment. 

With this pack, I will try to add unique atmospheric elements to a generic fantasy world, where the viewer can instantly feel when he enters the villain’s lair – where the neutral land ends, and the villain’s true domain begins.

Collecting Reference

Reference image from Elder Scrolls Online

First I looked on some references. What makes an environment feel „evil”? After studying lots of images from various fantasy worlds with stylish villains, I found that a few elements are almost, always there: spikey stuff, and black, heavy, wrought iron. 

Gothic architecture is very often portrayed with vampires’ castles. I also found that giving the style an exotic touch, such as Moroccan architecture, can be very interesting and feel elegant, like the way I imagine Dark Elves.

So I took those gothic arches, added a little exotic feel from Moroccan architecture, and topped them with menacing, dark, wrought iron spikes and grates.

I also had to choose a heraldic animal. I’m still a bit ambivalent about the chosen animal, the scorpion. I could choose wolves, ravens, spiders, or snakes as they are all connected to dark and „evil” metaphors. 

Maybe later I’ll add these as ornament and decoration variance to the pack.

Moroccan Window

My main inspirations on style were Lord of the Rings ringwraiths, Elder Scrolls’ Daedric and Ebonheart architecture, and dark elves environment from Styx – Master of Shadows. 

I found that ESO Furniture catalogs made by fans are a nearly endless source of inspiration; it helped me to achieve a certain level of complexity with the furniture models.

Planning the workflow

I also had to plan what exactly I want to build – building and furnishing an entirely unique environment is no small task, and I have limited resources and time until I have to look for a regular job again; I want to use this timeframe as efficiently as possible while maintaining a healthy daily schedule.

 3D work can be very visually intense and one should avoid burnout or health-damaging habits while working on large projects, because both can lead to a decline in motivation, work quality, and in the end, the whole project can go south if you don’t manage yourself correctly.

For this, I looked upon other publisher’s packs and made a nice big spreadsheet about all the pieces I will need. Floors, walls, doorways, columns, windows etc…. and then, filling those empty stone halls with containers, decoration, textiles, furniture, and other clutter.

At this point, I started to realize how big this project will be. I had to divide the work into smaller batches to be manageable: 

  • First, I will create the modular, architectural bases such as the walls and floors.
  • Then come the detail elements, like doors, windows, columns, stairs, and fences.
  • After this part come the individual prop pieces, such as containers, furniture, ornamental items (sculptures, reliefs, etc.) and textiles (rugs, flags, curtains..)

In some cases, I made two or more variants for the same item, especially those which are reused very often. There are still lots of models which have no variants but might be combined with clutter later on. I hope that in the future after I released the pack, I will receive feedback on what needs to be added or altered.

Before the planning phase, I registered on a project management app (Hack’N’Plan) to track my progress and share the project details with Adam. He and I are co-founders of Runemark Studio, our little entrepreneur business. 

He helped me a lot creating the milestones and tackling the massive amount of ToDo’s I had in my spreadsheet. When everything was set and ready, I started to create the prototype models for the pack.

In the next blog post, I would like to share my personal experience and my creative workflow. I will write about my modeling and texturing practices and techniques. See you soon!