Tag Archives: unity

04 Oct

Using Optimized Texture Atlas for Particle System in Unity!

header

The tutorial will be much more helpful if you already have a basic understanding of the Shuriken particle system / Native particle system of unity and is directed towards Intermediate unity users.

The particle effects in your game which adds a lot of polish can also increase the Draw calls resulting in spike or decrease in FPS. This usually occurs when you have multiple elements of same effects  visible in the gameplay camera.

particl

As an example, I made a spark particle effect for this tutorial. The particle was created using 5 particle elements and when used, it costs 4 draw calls. Now If I duplicate it multiple  times and simulate it all together in the game camera, it will cost 14 draw calls as shown below. This can be a huge problem and can impact the performance of your game especially when you have a ton of effects later in the development.

unoptimized

In order to curb this issue, we can always optimize the particles to help make sure that it is as efficient as possible. There are many guidelines on optimizing the particles and we recently started using Atlas for our textures in effects. This is a standard technique used in the game industry however while researching on this subject, we never found a good tutorial or concise document explaining the method and hence we thought why not share our technique!

I have used 4 different textures to make the below effect. It consists of a glow effect, sparkle effect, radial effect and a variant of sparkle effect. For the sparks flying, I just used stretched billboard with the glow texture. There are 5 elements used in order to create the particle but 4 materials hence when simulating it, it takes 4 draw calls!

elements

In order to use this technique, we need to create an atlas and for the same purpose, we can use any photo editing software. Since each of our textures are 128 x 128 resolution, we can compile all the 4 textures into 256×256 as shown below!

atlas

Once done with atlas we can go ahead and import it to unity and prepare the material. We will use Additive shader for this particular effect.

If you replace your particle effect with the atlas material, it will not look as intended. This is because you  need to point out the correct texture to each element of your particle system.

mess

We can select the correct texture in the atlas by using the texture sheet animation tab.

texturesheet

The texture tab in default setting looks like above. we need to change it according to our needs. We have 2 rows in our textures with 2 frames each in X and Y coordinates. We need to input the required coordinates, change the animation tab to Single sheet and turn off Random row. Then besides the Frame Of Time graph, you will see a drop down menu. Select the Constant option from the list.

constant

After making the above said changes,  the texture sheet should look like something as below.

texturesheetwithvalues

There are two options now available to us, Rows and Frames Over Time. Below I will explain what each does!

rowsandframes

Rows:This is the value which denotes which row you would like to select in your sheet. Every horizontal break in your texture sheet will be called as Row. They ascend from the top of the page to the bottom. rows

Frames over life a.k.a Frames: Frames are the respective image in your atlas. Since atlas is a compilation of all the textures, the frame number can be used to identify and select the desired texture from your sheet. Refer the image to understand how frame numbers are divided.

frames

After understanding the rows and frame settings, now we can select the desired texture from the sheet. Let’s have a look at our atlas below. If we want to pick a glow texture, then we would need to add Row:1 and Frame: 1. Using this mapping technique we can now start optimizing our entire particle system by selecting each element and replacing it with the corresponding texture in the atlas.

texturesheetanatomy

I went ahead and optimized all of the elements in the particle effects with the atlas texture and now we can see that the draw call has reduced to 1! No matter how many duplicates or instances I make of the same particle, the draw call is always 1. SUPER OPTIMIZED!

optimized

Using the atlas can a very powerful method when using with particle effects in your game. It can help maintain an optimal draw call and boost its performance. Making use of this technique can be very useful especially for mobile games where draw calls are a bane and can drastically impact the fps of your game.

Hope the tutorial helped you in understanding how to use Texture Atlas for your particle effects and may nothing stop you from creating that epic effects for your awesome game! :)

giphy

If you have any queries or if you were confused at any point when following the above process, please do let us know via the comments or email.

Cheers!

30 Sep

Game Dev Tip: How to bake Lightmap in Unity 5 !

Cover

Helloz,

A long time ago, I had blasted in Facebook saying that we will share our findings of Light-map workflow in Unity 5. Along with learning that it is always better to not promise anything before it is done, here is a tutorial… Finally !

Unity 5 came out and they completely overhauled the Light-map system. Although an amazing update, it is kind of difficult at the moment to get the hang of it. The tutorials are difficult to find and the workflow seems as if it is kind of messy.

After working and testing on it for about 6-7 months we have kind of figured how to get a good result with the new Light-map system and that is why this tutorial has been forged!

What is Light-map!?

Light-map is nothing but a texture with lighting information baked directly from the scene to help reduce draw calls and increase performance of one’s game. It usually has shadow, Global Illumination and Ambient occlusion baked onto it to give an amazing depth to the environment without hindering the FPS. Real-time lightning is only set to moving or intractable objects which reflects dynamic shadows. This is a rather standard procedure in games pipeline and has been in use since a long time.

What you need?

In-order to follow this tutorial, we will get down to basics and use primitive objects to bake light-map as an example. Later, you can use the same technique to bake your awesome models in Unity. For now these are the stuff you will need

  • A 3D scene exported from any 3D software with a plane and a box.

Masterpeice

  • The box should have two UV channels. Channel 1 for Diffuse and Channel 2 for Light-mapping. (UV 2 is not mandatory but it is always better to manual unwrap for better quality light-maps)

2

  • Unity 5

Once you have all the above stuff, lets move on to setting up a proper scene in Unity. We will export this in FBX. or Obj. or whatever format your 3D package supports and lets move on to Unity!

Setting up the scene!

  • Import the FBX or your exported 3D Obj into your Unity 5 scene. Use the following import setting to make sure that you get good quality Light-maps.
    Note: If you don’t have UV2 channel in your 3D object then you can turn on the GENERATE LIGHTMAP UVs in the import settings. This will automatically unwrap a UV2 channel for your 3D object.

5

  • Duplicate the boxes and intersect them together so that the contact shadows or Ambient occlusion will be visible

6

  • Mark your 3D objects as static . The object which are static will only be Light-mapped.

7

  • Select the directional light, mark it static as this will be the source which will produce the required lighting information which we need for our Light-map.
  • Change the Directional Light setting as shown below. Basically, you need to change the Baking from Real-time to Baked.

8

  • Go to your quality settings under Project setting and change it as shown in the image below. We do this because the default shadow setting are not that great and are blurry.

9

Once the scene is set and loaded, we can now move on to settings of the Light-map.

Tweaking the Light-map Settings!

To open up the Lighmap setting tab, you need to go to Windows > Lighting  > Scenes

To get more info about each property of the setting tab, please refer to this link. It is highly recommended that you sit down and read it thoroughly before moving on. Please dont skip the documentation or else you will pay for it. It is always better to have atleast a basic understanding of all the parameters before actually working with them!

Please refer the image below and change the settings as shown.

10

It is highly important that you select all objects you want to bake. Once all objects are selected, press BUILD to start the baking process !

Baking Lightmaps!

When the Build button is pressed a progress bar will appear on the bottom right corner of your Unity 5 window indicating that the Baking process has started!

11

Once it is done processing, you will be done with your light-map baking and should have an amazing looking  scene with the shadows all baked into the assets beautifully as shown below.

12

 

As you can see in the below image the difference between a scene which is baked with light-map looks way more cooler then the dull scene which is without any maps! The use of Light-mapping in your game can play a big part in bringing in that added polish and a very nice grounded feel to your environments.

13

Things to remember while baking!

  • The light-map resolution size is displayed in the light-map settings. Make sure to use proper size and not go overboard as it will hamper your performance of the game
  • 15If you want to clear the light-map, you can by do it by going into the Light-map settings, clicking the arrow besides the Build button > Clear Baked Data. It should delete your Light-maps and you will have to bake it again
  • 14If you want to change the Light-map resolution manually, you can do that by going into the Light-maps tab, clicking on the individual Light-map which will take you to the Light-map texture where you can change the texture compression or resolution manually.

16

That is pretty much it on how you can bake Light-maps in Unity 5. We hope you enjoyed the read and use this light-mapping technique in your pipeline. if you already haven’t been using it, go ahead and test it now! The procedure can really enhance the look and feel of your game and you should not ignore it if possible. If you dint understand anything which was explained here then don’t hesitate to let us know. The whole point of blabbering about this is to make sure you get it right!

Fbforblog

Thanks for dropping by and for your support. We will be blogging about our visit to EGX, Birmingham where we showcased Asura! It was an amazing experience and we will share about it pretty soon.

Until then….. Take care, Be Epic and Forge beautiful stuff  :D

 

 

21 May

Game Dev Tip : Exporting with correct unit setup | 3DS Max to Unity !

box

Hello,

Ever pulled out your hair while figuring out why did your 3DSMax  model re-sized itself into a giant city destroying Kaiju when exporting into unity.

Well, It happens due to your Max scale setup being  not configured to proper settings. If you work in Max and if you have been facing such problems then worry not and let us explain how you can get it all sorted.

We personally  use meters as our base unit for level design and to measure all the assets which basically means every tile in the game is equal to 1 meter and the main character is 1.5 meter. Once this is laid out , we move on to building all the assets.

Now if you just directly go ahead in max , make a box mesh of 1 x 1 x 1 unit and export it, catastrophe will strike and you will be disappointed. This is because Max default unit is set to centimeters.

box

box2

Well, you can re-scale the exported box in unity  manually but then you will have to pull up a calculator to figure out the scale and when you work with many assets this simply becomes nigh-on impossible! Yo

Now lets fix this issue shall we!

1.) First thing we should fix is the unit setup. you can open the units setup tab by going over to Customize > Units setup in your 3DS Max tool bar.

units

2.) A tab will open up and under Display Unit Scale, choose Meters in Metric tab.

unit

3.) Now open up system unit setup by clicking the button and change 1 unit = 1.0 Meters. Press OK like a boss and we are ready to export our awesome box ! :)

metric

4.) Now we select the box and go to File > Export selected > Export and another huge export option tab will open up. Please don’t be scared and hide under the table. Just  go to units option in the tab > Turn off Automatic > Change units converted to = Meters and press OK…. again like a boss!

redbox

5.) Now lets head over to unity and import the box. Drag and drop the box mesh into the scene and create a cube in unity with 1 x 1 x 1 scale and viola! The scale from 3DS Max should have properly translated to Unity with the unit of the exported box and unity box being the same. This method should have fix the issue and you are good to go :D

back

This scaling issue used to haunt us for a long time but not any more.  It has been such a relief to just drag and drop models and assemble it . It all fits perfectly and speeds up the pipeline. Hope the tip has helped you and made your development pipeline that much better. If  the issue is fixed you deserve to dance like below, if not just let us know and we will dance after fixing together.

992d027ac6a12d8b60b3c20348b3425a

Everybody needs to dance after fixing stuff !

Happy developing epic stuff !

Peace.

 

 

For any queries please contact zain@ogrehead.com or support @ogrehead.com| Get Presskit here: http://ogrehead.com/press