Jump to content
  • Advertisement

Unity Weekly Updates #40 - PIXEL MAP

jb-dev

955 views

Hey! It's you again! Nice to see you!

Another week ended, so it's time for a new entry in your favourite Weekly Updates blog!

Last week I was hinting about fixing a particular performance issue, so the main gist was about fixing this. 

So let's get right to it!

The Minimap Problem

So after a bit of profiling, I realized that one of the most frame eating thing was by far the minimap.

The minimap used to be made of many smaller rectangles representing actual rooms. To move the map around I simply change the pivot point, which helps me keep the minimap's orientation while following the player's current position.

image.png.7e9d6ecdcb524fc390b0a48a3197bd91.png

The thing was that each of these movements triggered a re-layering of the minimap.

In essence, this re-layering cost me about 25 FPS. No good at all.

I clearly needed to optimize this process, as having a very low FPS for such a simple game was unacceptable.

There were many different options on how to make a new minimap. Two of these examples were rendered textures and just textures.

While using a camera simplifies the minimap a whole lot it's also quite expensive to re-render the scene onto a render texture. In fact, the framerate lowered by half! Not good either.

So instead I decided to go with the other option: building my own texture. While this is relatively inexpensive to use it was quite a pain to set up. This was because of the marching square algorithm which is always using the middle to build geometries. Needless to say that I needed to round these rooms up. 

This wasn't the only problem either! Unity's rect class which represents a 2D rectangle has two different things which made positioning and sizing a huge pain.

RectXY.svg

First, it's coordinate system has it's Y axis reversed compared to the 3D coordinate system. It can be really confusing to try to map a 3D Bounding Box to a 2D rectangle. To get it I needed to take a step back and really think about it.

RectSetX.svg

Second, the rect class has a really interesting way to deal with positioning. Basically, the position of the rectangle is its min. This means that, for example, to center a rectangle you need to find by how much you need to change the min and apply it. Another big problem was clamping the room's max and min while keeping the same size. In this case, you need to offset the position of the rect in a way that the room would keep the correct position while growing according to the available space. This is ok for rects that can just change their max but was quite cumbersome when the min needed to change.

Nevertheless, after a day or two, I was able to solve most of my problems and was able to draw out each room correctly.

The Minimap Texture

Once all these rectangles are properly set up I simply needed to render each room onto the minimap texture.

I particularly had a bit of fun with this. With the previous minimap rooms were just solid rectangles with no details at all. Pretty boring if you ask me.

Now I can tell which colour each pixel of the room will use. This means that I was able to pick the specific floor colour at that pixel. This means nicely rendered rooms with a whole lot more colours than before!

I was even able to get the right grass shade too!

image.png.56a9e9e08d19cef86eac898c4765c6bd.png

Each ground types has its own colour that makes sense, which is quite pleasing to the eye. There are event elaborate textures on some of these!

I also tried to add shadows to it by using the sun and trying to mimic the actual shadows as they appear on the ground. This was quite cumbersome as I basically had no experience with shadowing at all, and most people use a shadowing technique that inherently uses cameras frustum, position and maps to create shadows. So instead I decided to create a really simple casted shadow that was simple to set up and to calculate. While being quite simple it gave the effect I wanted. So it's a win for me!

Aside from that, special rooms now all got unique designs that try to display the room at a minimal resolution. Some even try to display relevant props and other distinctive designs too!

With the minimap texture, I was able to keep my current minimap rotating and positioning algorithm. Except I now got a more steady FPS of around 60 frames per seconds. Pretty good if you ask me.

Room Redesigns

Aside from that, I'm also on a redesign quest too. During the week I was able to redesign two rooms: the pawnshop and the pharma research lab.

As always, the design is always an iterative process, so it's not really the final designs but it's slowly getting there!

The Pawn Shop

image.thumb.png.421a67f2dc1aef00dc85209fcd1e9846.png

So This new design isn't as different. While the layout remained pretty much the same the amount of polish is greater in this one.

Here are the main points:

  • For once there's now a nice texture on the ceiling.
    image.thumb.png.a410b31f5736113ee57753844984ea24.png
  • The shelves are more reflective and had more varied materials.
    image.thumb.png.0a91abf2d284938b07719ac27c0bded7.png
  • The computer screen is a whole lot more "low-poly" and flatter.
    image.thumb.png.c90a67cb22328e81f665d01d768399ad.png
  • There are now new props coming straight from the spa room.
    image.thumb.png.70532040e490a718e8f9f9c6848fda7a.png
  • The lighting is a whole lot better.
  • Finally, there's a lot more variation in material that before.

The Pharma Research Lab

image.thumb.png.afd0d196ac2c4fceea309ffd808e3f1b.png

This room got quite the uplift to be honest. I think it looks a whole lot better now.

Here are the new things to notice:

  • The ceiling now got a window. The sun's light goes through it and makes quite the scene!
    image.thumb.png.27c156655bfdf74724f351a61b1d6162.png
  • The floor geometries are now split. The base floor got a tile texture to it and the carpet looks a whole lot more like a carpet too!
    image.thumb.png.72aeab886e6bb454c75f9b8659861e2e.png
  • The back room's ceiling is lowered, making it feels a whole lot more like a back room.
    image.thumb.png.5b086fba0cb55334b2153bdba2fdecce.png
  • Better lighting altogether, better reflection probes and, of course, optimized geometries!

Minor updates

  • Optimized and refactored most of my shaders:
    • Boy, it takes a long time to compile those shaders...
      • Having everything in a .cginc is quite handy to centralize code but each edit means recompiling all my shaders...
    • Anyways, I added a metallic map that will be surely useful in the future.
  • Redesigned minor props;
  • Optimized some expensive scripts.

Next Week

I'm on a redesigned train and no one can stop me! Each room has to be looked at and changed accordingly. This takes quite the time but it's an important thing to get right.

I'm starting to think, though, that I really need to have something new. A special room, relic, capacity or anything really. This will give me quite the insight on how the game will be played and optimize things from the getgo.

Right now in terms of optimization things aren't as dire as before: I'm getting a steady framerate and my verts counts aren't that hight. I think it's quite a time for something new...

So basically the order is reversed and our "Usual suspects" are now higher on the priority list. This means that optimization can take a step back and gets to simmer on the back-burner.

So next week prepare to see some new things! I can't promise it but I'm going to try!




0 Comments


Recommended Comments

There are no comments to display.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Advertisement
  • Advertisement
  • Blog Entries

  • Similar Content

    • By SCP-173
      Hello,
      I'm currently working on a 3D mobile game in Unity, and I've basically designed the whole thing already. Problem is, I do not know where to get started on the music/rhythm integration for the game. I'm relatively new to coding in C#, but am pretty comfortable with the Unity workflow having made some games off tutorials to learn C# and Unity. I was wondering if there is anyone who is experienced in or knows about making rhythm-based games who could help me understand the process? My concept is similar to these to just give you an idea of what I'm going towards: https://www.youtube.com/watch?v=RcHzJ5lAdHQ
      I've also read about this software Koreographer while doing research on how to make a rhythm-based game, but I'm hoping that whoever's willing to help can help me achieve some of the neat effects that Koreographer can do without buying and learning the software.
    • By RoKabium Games
      ALPHA TESTERS WANTED! Our PC game "Something Ate My Alien" is starting public testing today! If you would like to test our game, contact us or visit the link below:
      SAMA forums: http://bit.ly/sama-testing
    • By pristondev
      Hey, I've updated my shaders to uses Shader Model 2.0, with ps_2_0 and vs_2_0, works good only on PC's where was possible to use Shader Model 3.0.
      The problem its the shaders its already compiled for SM 2.0, but it doesnt works on PC's with obsolete hardware config. That PC's supports SM 2.0, so I dont know the shaders isn't working. Looks the crash is caused on DrawIndexedPrimitive, but this function never returns something different from S_OK. This way I can't check any log or something like that.
       
      Im compiling shaders like:
      technique Mesh { pass P0 { VertexShader = compile vs_2_0 MeshVS(); PixelShader = compile ps_2_0 MeshPS(); } } Initialization logs where have that crashing problem:
      16/04/2019 23:18:13 - (INF) Direct3D 9 Interface Created 16/04/2019 23:18:13 - (ERR) Your graphics hardware doest not support 32 bit Dynamic Texture [8876086A] 16/04/2019 23:18:13 - (INF) FPU Preserve 16/04/2019 23:18:13 - (INF) Vertex Processing: Software 16/04/2019 23:18:13 - (INF) Device Created! 16/04/2019 23:18:13 - (INF) Multi Sample: 0 0 16/04/2019 23:18:13 - (INF) Resolution: 800x600 16/04/2019 23:18:13 - (INF) Window Mode 16/04/2019 23:18:13 - (INF) Color Depth: 32BPP 16/04/2019 23:18:13 - (INF) @ Device Capabilities 16/04/2019 23:18:13 - (INF) Vertex Shader Version: 0.0 16/04/2019 23:18:13 - (INF) Pixel Shader Version: 2.0 16/04/2019 23:18:13 - (INF) Max Vertex Blend Matrices: 0 16/04/2019 23:18:13 - (INF) Max Vertex Blend Matrix Index: 0 16/04/2019 23:18:13 - (INF) Max Primitive Count: 65535 16/04/2019 23:18:13 - (INF) Max Vertex Index: 65534 16/04/2019 23:18:13 - (INF) Max Streams: 16 16/04/2019 23:18:13 - (INF) Max Streams Stride: 255 16/04/2019 23:18:13 - (INF) Max Vertex Shader Constant Registers: 0 16/04/2019 23:18:13 - (INF) Max VShader Instructions Executed: 0 16/04/2019 23:18:13 - (INF) Max PShader Instructions Executed: 96 16/04/2019 23:18:13 - (INF) Max Vertex Shader 30 Instruction Slots: 0 16/04/2019 23:18:13 - (INF) Max Pixel Shader 30 Instruction Slots: 0 16/04/2019 23:18:13 - (INF) Max Simultaneous Textures: 8 16/04/2019 23:18:13 - (INF) Max Texture Blend Stages: 8 16/04/2019 23:18:13 - (INF) Max Texture Width: 2048 16/04/2019 23:18:13 - (INF) Max Texture Height: 2048 16/04/2019 23:18:13 - (INF) Max Volume Extent: 256 16/04/2019 23:18:13 - (INF) Max Texture Repeat: 8192 16/04/2019 23:18:13 - (INF) Max Texture Aspect Ratio: 2048 16/04/2019 23:18:13 - (INF) Max Anisotropy: 4 16/04/2019 23:18:13 - (INF) Max Active Lights: 0 16/04/2019 23:18:13 - (INF) Max User Clip Planes: 0 16/04/2019 23:18:13 - (INF) Max Point Size: 256.000000 16/04/2019 23:18:13 - (INF) Max Npatch Tesselation Level: 0.000000 16/04/2019 23:18:13 - (INF) Num Simultaneous RTs: 1 16/04/2019 23:18:13 - (INF) Using Textures Non Pow2 Conditional: Yes 16/04/2019 23:18:13 - (INF) Using Textures Pow2: Yes 16/04/2019 23:18:13 - (INF) Supports HW Skinning: No 16/04/2019 23:18:13 - (INF) Software Skinning My initialization logs (where shader with sm2 works perfectly):
      22/04/2019 14:45:21 - (INF) Direct3D 9 Interface Created 22/04/2019 14:45:21 - (INF) FPU Preserve 22/04/2019 14:45:21 - (INF) Vertex Processing: Hardware 22/04/2019 14:45:21 - (INF) Pure Device 22/04/2019 14:45:21 - (INF) Device Created! 22/04/2019 14:45:21 - (INF) Multi Sample: 0 0 22/04/2019 14:45:21 - (INF) Resolution: 1024x768 22/04/2019 14:45:21 - (INF) Window Mode 22/04/2019 14:45:21 - (INF) Color Depth: 32BPP 22/04/2019 14:45:21 - (INF) 32 bit Back Buffer 22/04/2019 14:45:21 - (INF) @ Device Capabilities 22/04/2019 14:45:21 - (INF) Vertex Shader Version: 3.0 22/04/2019 14:45:21 - (INF) Pixel Shader Version: 3.0 22/04/2019 14:45:21 - (INF) Max Vertex Blend Matrices: 4 22/04/2019 14:45:21 - (INF) Max Vertex Blend Matrix Index: 0 22/04/2019 14:45:21 - (INF) Max Primitive Count: 16777215 22/04/2019 14:45:21 - (INF) Max Vertex Index: 16777215 22/04/2019 14:45:21 - (INF) Max Streams: 16 22/04/2019 14:45:21 - (INF) Max Streams Stride: 255 22/04/2019 14:45:21 - (INF) Max Vertex Shader Constant Registers: 256 22/04/2019 14:45:21 - (INF) Max VShader Instructions Executed: 65535 22/04/2019 14:45:21 - (INF) Max PShader Instructions Executed: 65535 22/04/2019 14:45:21 - (INF) Max Vertex Shader 30 Instruction Slots: 4096 22/04/2019 14:45:21 - (INF) Max Pixel Shader 30 Instruction Slots: 4096 22/04/2019 14:45:21 - (INF) Max Simultaneous Textures: 8 22/04/2019 14:45:21 - (INF) Max Texture Blend Stages: 8 22/04/2019 14:45:21 - (INF) Max Texture Width: 16384 22/04/2019 14:45:22 - (INF) Max Texture Height: 16384 22/04/2019 14:45:22 - (INF) Max Volume Extent: 2048 22/04/2019 14:45:22 - (INF) Max Texture Repeat: 8192 22/04/2019 14:45:22 - (INF) Max Texture Aspect Ratio: 16384 22/04/2019 14:45:22 - (INF) Max Anisotropy: 16 22/04/2019 14:45:22 - (INF) Max Active Lights: 8 22/04/2019 14:45:22 - (INF) Max User Clip Planes: 8 22/04/2019 14:45:22 - (INF) Max Point Size: 8192.000000 22/04/2019 14:45:22 - (INF) Max Npatch Tesselation Level: 0.000000 22/04/2019 14:45:22 - (INF) Num Simultaneous RTs: 4 22/04/2019 14:45:22 - (INF) Using Textures Non Pow2 Conditional: No 22/04/2019 14:45:22 - (INF) Using Textures Pow2: No 22/04/2019 14:45:22 - (INF) Supports HW Skinning: Yes 22/04/2019 14:45:22 - (INF) Hardware Skinning  
      Does anyone know what might be happening?
      Thanks.
    • By Belfa96
      I've got a single vertex buffer and an index buffer for a cube in Directx9. I now want to generate a LPD3DXMESH  object from them, so that I can manage mouse picking and other stuff with the cube model. How can I achieve this? Here's the code of my vertex and index buffers:
      CUSTOMVERTEX vertices[] = { { -3.0f, 3.0f, -3.0f, D3DCOLOR_XRGB(0, 0, 0), }, { 3.0f, 3.0f, -3.0f, D3DCOLOR_XRGB(0, 0, 0), }, { -3.0f, -3.0f, -3.0f, D3DCOLOR_XRGB(0, 0, 0), }, { 3.0f, -3.0f, -3.0f, D3DCOLOR_XRGB(0, 0, 0), }, { -3.0f, 3.0f, 3.0f, D3DCOLOR_XRGB(0, 0, 0), }, { 3.0f, 3.0f, 3.0f, D3DCOLOR_XRGB(0, 0, 0), }, { -3.0f, -3.0f, 3.0f, D3DCOLOR_XRGB(0, 0, 0), }, { 3.0f, -3.0f, 3.0f, D3DCOLOR_XRGB(0, 0, 0), }, }; d3ddev->CreateVertexBuffer(8 * sizeof(CUSTOMVERTEX), 0, CUSTOMFVF, D3DPOOL_MANAGED, &vertex_buffer, NULL); VOID* pVoid; vertex_buffer->Lock(0, 0, (void**)&pVoid, 0); memcpy(pVoid, vertices, sizeof(vertices)); vertex_buffer->Unlock(); short indices[] = { 0, 1, 2, 2, 1, 3, 4, 0, 6, 6, 0, 2, 7, 5, 6, 6, 5, 4, 3, 1, 7, 7, 1, 5, 4, 5, 0, 0, 5, 1, 3, 7, 2, 2, 7, 6, }; d3ddev->CreateIndexBuffer(36 * sizeof(short), 0, D3DFMT_INDEX16, D3DPOOL_MANAGED, &index_buffer, NULL); index_buffer->Lock(0, 0, (void**)&pVoid, 0); memcpy(pVoid, indices, sizeof(indices)); index_buffer->Unlock();  
    • By RhinoBladeX2
      hi you my call me rhino would love to chat about blender, gimp and 3d design learning all the time. hope we can be friends I uploaded picture's for everyone 



×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!