Showing posts with label graphics. Show all posts
Showing posts with label graphics. Show all posts

18 August 2020

8bit And 16bit Color Palettes

It took me quite a while to understand how 8bit and 16bit palettes work.

To spare you the search, I've decided to write this guide.


Motivation

Creating authentic 8bit and 16bit graphics requires understanding palettes. There are programs and algorithms, which transform your images into 8- or 16bit. Since algorithms cannot guess the intention behind the color choice and miss the context, creating them yourself is more flexible and results in higher quality. It also prevents the loss of details due to quantization. Additionally, to some, pixel-art is about control, and creating the palette gives such.


8Bit Graphics

During the era of the Nintendo Entertainment System, the technology worked with 8bit. Therefore the color of a pixel is represented by eight ones or zeroes. Today a pixel carries up to 32. You might be familiar with the red, green, and blue or RGB, where we split a color into three components. However, dividing 8bits into three colors is ambiguous. That's why there are formats for palettes. RGB332 is the most common for 8bit. It means we assign 3 bits to each red and green, and two bits to blue. A lighter orange would be 111 100 01, which would be 7 for red, 4 for green, and 1 for blue. That's nearly 0, so almost black.

comparisonBlackAndOrange
Comparing the colors.
Left: Black; Right: Our Orange


What Is A Palette

Better idea: We map each RGB value onto a level. 

For example, let's map the following blue levels:

00 -> 0

01 -> 79

10 -> 155

11 -> 255

The color levels (right-hand side) the bits map to is our palette. Back then, hardware limited us to use one palette for all drawn on the screen at the same time. Years later, the Super Nintendo Entertainment System was released. Powered by 16bit, our capabilities increased immensely! A typical format for 16bit is RGB565. Today we use 24bit ("true-color") and the RGB888 format. Some formats use RGBA, followed by four numbers, where A (="alpha") stands for the transparency.

Side note: The sum of the numbers does not need to add up to the number of available bits. Ergo RGB333 is a valid format for 16bits.


Creating A Palette From Colors

Using preexisting colors to create a palette takes three steps. First, choose a format. Then add them to your palette.

Let's use the following colors for an 8bit palette of the format RGB332:


Red
Green
Blue
Black   
000
Color 2
212211198
White  
255255255
Color 4
248216198
Color 5
248197198
Color 6
232173159
Color 7
979943
Color 8
11723473

The format gives us 3 bits for red and green and 2 bits for blue. The formula for the number of representable levels is 2bits. That is enough for 23 = 8 levels of red and green each and 22 = 4 levels of blue. However, our colors have six unique levels of blue (0, 43, 73, 159, 198, 255). Therefore we can't represent all eight colors.


Quantization

Quantization, the third step, will help us here. For this one, we'll merge close color levels.

Our two colors:

248 red, 216 green, 198 blue            232 red, 173 green, 159 blue

will then (for example) become:

248 red, 216 green, 198 blue            232 red, 173 green, 198 blue

By choosing a good looking and distinguishable color level, we can optimize this better than an algorithm. Then we continue adding all needed colors and quantify them to our palette. Now with our palette created, we can color the pixel art.


Tips And Tricks

Reminder: In 8bit and 16bit video games, everything on-screen at the same time uses one palette. Therefore use the same palette for all associated sprites.

The difference between darker colors is harder to notice. Thus use less dark color levels.


Examples


senkoPixelArt16Bit
Senko Pixel Art, 16Bit Palette (RGB565)
 drawn by GreenyNeko

This pixel art of Senko uses an RGB565 palette with the following color levels:

Color1234567891011121314151617...32
Red097126155174197205212222227232248----

Green04654608399106163173188197207211216224234255...-
Blue0434860738893101118159175198236255--



Notice that there's still space in the palette marked by the "-"s.

Senko Pixel Art, 8Bit Palette (RGB332)
drawn by GreenyNeko


This one uses an RGB332 palette with the following color levels:

Color12345678
Red097126155174197212248
Green4683106156173197216234
Blue43106175198


01 February 2020

I Was Ignorant About Shaders

Congratulations, University. January is the first month on which I didn't post on this blog for a whole month. I've been working on four different projects: Specifically Audio, Assembly, Interactionmethods, and Shaders.

Me And Shaders

When I had first come in contact with shaders, I've been ~8 years younger. Back then, I first started to learn to program with the DirectX SDK. I never really understood shaders back then, and they were annoying. I never really did anything with them. From there on out, it took seven years until I came across them again during studying when I saw the project of a fellow student talking about his shaders. The game looked amazing. One semester later, in the Realtime graphics course, we were taught DirectX as well as shaders. It was- fascinating but pretty technical. It wasn't until I took the "Modern Techniques for Shader Development and Imagesynthesis" course.

The Epiphany

Until then, I didn't think much about shaders, but the courses made me realize how important they are and how easy it is to write them. Most of the animations, particle systems, post-processing effects, and other things making your games more beautiful, are probably done using shaders. Vertex shaders, geometry shaders, fragment shaders, image effect or post-processing shaders, and compute shaders give you the power to push your games to a new level of aesthetics and beauty.

What If Shaders Are Not Your Thing?

Of course, it's not the end of the world if you don't write your shaders. There are shader assets out there that you can get. You can make other people write them for you (like me :P), and most engines come with standard shaders. So, no one is forcing you to get into writing shaders. However, I still want to make you realize how important they are and that it is possible to create great things with them.

How To Get Started?

The university course I took taught all techniques by using case studies. So, get out there, take a game and try to recreate the effect. Oh wait, maybe you should start with some tutorials on the basics first. Read into how Vertex and Fragment shaders work and make your own in Unity since you can get started right away there. Check for some websites that teach shading while using case studies. The tutor of the course has a website called lexdev.net.

Shimmy, Shimmy... Out And Away

That's it from my side for today. I'll come back with more posts eventually, especially after the exam phase. Also, I started to use Grammarly again, given your feedback on the blog posts that didn't use it compared to the ones that do. Thanks for that feedback, btw. Oh yeah, I could write my case study or tutorials in the future.

12 December 2018

The Split Between Traditional and Modern Pixel Art

This is a post I wanted to write back when I made my first post about pixel art, sharing what I thought was a good post on making pixel art bigger without it looking too "blocky". Anyways after that post, I had a discussion with some people and it's really interesting.

Where Did Pixel Art Come From?

Back in the old days, when games for consoles like the Nintendo Entertainment System were available. Hardware and software were limited. Due to only saving 8-bit per each pixel of an image only a limited amount of colors could be displayed.[1] Combining this with the limited resolution Pixel Art was the best option back in the old days.[2] Thankfully the detail in each sprite or Pixel Art, as well as the number of colors kept increasing. Continuing through to 16-bit per pixel with the Super Nintendo Entertainment System up to our 24-bit true color system that is widely spread.

Then Why Is There Still Pixel Art?

Even though we don't have the restrictions we had back in the old days, it has evolved into a style for multiple purposes. It may remind us of the old days, it's much simpler to create than drawing a full detailed picture, you have more power over each and every pixel and all the details of the picture since every pixel matters and you can decide over every of their positions, and many more I haven't captured here.

The Split Between Traditional and Modern

Now, with our much better hard- and software we are no longer restricted to the limits we had back in the old days. This resulted in a split between traditional and modern Pixel Art. So what's the difference? What makes Pixel Art traditional and what makes it modern? Where are the bounds of each?

Traditional Pixel Art

Traditional Pixel Art is very strict about its rules. Thus you are not allowed to use more than 16-bit per pixel, which can be enforced by color palettes. Additionally, you are limited in the amount of detail you can add. Plus each pixel needs to be clearly visible so that the control over each pixel is not lost. Though the exact rules may vary from person to person and additional may be added or ones may be removed. Which cuts the bounds of modern Pixel Art.

Modern Pixel Art

Breaking the limits of traditional Pixel Art, this may not be considered to be much anymore. It can be argued whether there are any rules to this but some things can be said at least. First of all, there is no limitation in colors anymore. All the colors of true color can be used for these, which means no palettes or limited color choice per pixel. Pixel Art is all about the pixels. Without any rules, isn't any computer-created art Pixel Art? This is where we can take one of the rules of traditional Pixel Art to help us. Each pixel needs to matter and a change in pixels should be visible. I think this is probably the best way to draw a line. The more detail you add the more blurry each pixel becomes and the more blurry the line between what can be considered Pixel Art and what cannot becomes as well.

Conclusion

Now, this is just my thought on this topic so I don't know how far I'm off or if I hit the bulls-eye. However, even if I'm off I consider this to be a good way to differentiate between Traditional, Modern Pixel Art and the other types of computer-aided graphics that have been made and I don't think you can do any wrong by holding onto these guidelines or rules mentioned here.

[1] https://en.wikipedia.org/wiki/8-bit_color
[2] https://www.theseus.fi/bitstream/handle/10024/133067/Keo_Mary.pdf

About Me

My photo
I'm a M.Sc. Games Engineer and I created this blog to share my ideas, theorycrafting, thoughts and whatever I'm working on or doing.