Jump to content
  • Advertisement

Unity Weekly Updates #40 - PIXEL MAP

jb-dev

929 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 horror_man
      Hello, I'm currently searching for additional talented and passionate members for our team that's creating a small horror game.
       
      About the game: The game would be a small sci-fi/post-apocalyptic survival horror 3D game with FPS (First person shooter) mechanics and an original setting and story based in a book (which I'm writing) scene, where a group of prisoners are left behind in an abandoned underground facility. It would play similar to Dead Space combined with Penumbra and SCP: Secret Laboratory, with the option of playing solo or multiplayer.
       
      Engine that'd be used to create the game: Unity
       
      About me: I'm a music composer with 4 years of experience and I'm fairly new in this game development world, and I'm currently leading the team that'd be creating this beautiful and horrifying game. I decided that making the book which I'm writing into a game would be really cool, and I got more motivated about doing so some time ago when I got a bunch of expensive Unity assets for a very low price. However, I researched about how to do things right in game development so I reduced the scope of it as much as I could so that's why this game is really based in a scene of the book and not the entire thing. Also I'm currently learning how to use Unity and learning how to program.
       
      Our team right now consists of: Me (Game Designer, Creator, Music Composer, Writer), 4 3D Modelers, 2 Game Programmers, 1 Sound Effect Designer, 1 Concept Artist, 1 3D Animator and 1 Community Manager.
       
      Who am I looking for: We are looking for a talented and passionate programmer that's experienced with Unity and C#.
      Right now the game is in mid-early development and you can see more information about it and follow our progress in our game jolt page here: https://gamejolt.com/games/devilspunishment/391190 . We expect to finish some sort of prototype in 3 months from now.
       
      This is a contract rev-share position
       
      If you are interested in joining, contributing or have questions about the project then let's talk. You can message me in Discord: world_creator#9524
    • By koekjes_boy
      Hi,  Im 16 year old im a pretty good coder in unreal im creating a fishing game for my brother maybe if its cool i gonna publish it but i need help with the animations its like impossible for me to let the animations look good so if you wanna help me out      Add my discord    Koekjes_boy#2964
    • By RoKabium Games
      A message from the Aliens for this week's #screenshotsaturday.
      Happy Easter to all!
      If you're looking for something to do, why not join our Alpha testing?
      Check it out at this link: http://bit.ly/sama-testing
    • By Belfa96
      I'm a total beginner with Directx/3D programming. I need help with implementing hardware instancing on Directx 11. I'm trying to render multiple cubes on the screen, to create some sort of Minecraft-esque voxel engine. The problem is, I don't know where to start to achieve this. This is how my "render frame" function looks:
      void RenderFrame(void) { D3DXMATRIX matView, matProjection; D3DXMATRIX matFinal; // create a view matrix D3DXMatrixLookAtLH(&matView, &D3DXVECTOR3(0.0f, 9.0f, 24.0f), // the camera position &D3DXVECTOR3(0.0f, 0.0f, 0.0f), // the look-at position &D3DXVECTOR3(0.0f, 1.0f, 0.0f)); // the up direction // create a projection matrix D3DXMatrixPerspectiveFovLH(&matProjection, (FLOAT)D3DXToRadian(45), // field of view (FLOAT)SCREEN_WIDTH / (FLOAT)SCREEN_HEIGHT, // aspect ratio 1.0f, // near view-plane 100.0f); // far view-plane // create the final transform matFinal = matView * matProjection; // clear the back buffer to a deep blue devcon->ClearRenderTargetView(backbuffer, D3DXCOLOR(0.0f, 0.2f, 0.4f, 1.0f)); // clear the depth buffer devcon->ClearDepthStencilView(zbuffer, D3D11_CLEAR_DEPTH, 1.0f, 0); // select which vertex buffer to display UINT stride = sizeof(VERTEX); UINT offset = 0; devcon->IASetVertexBuffers(0, 1, &pVBuffer, &stride, &offset); devcon->IASetIndexBuffer(pIBuffer, DXGI_FORMAT_R32_UINT, 0); // select which primtive type we are using devcon->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST); // draw the Hypercraft devcon->UpdateSubresource(pCBuffer, 0, 0, &matFinal, 0, 0); devcon->DrawIndexed(24, 0, 0); // switch the back buffer and the front buffer swapchain->Present(0, 0); } Notice that there's a single vertex buffer containing the verteces of a cube, and index buffer containing its indeces. I want to render many (5000+) cubes on the screen at once on a single draw call, without performance issues, so I know instancing is the way to go, but I don't know how to implement it in my code. What changes do I need to do to my code in order to display multiple instances of the cube?
      Thanks in advance!
×

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!