Graphics - palette: Palette effects in games.

Info Guide #12
Palette effects in games
Hippiman/Conscience

   ATM Turbo (and its implementation in ZX Evo) -
quite powerful machine for Spectrum 
compatible computers, of course. 
   However, not powerful enough to pull
complete redrawing of the entire screen and layouts─ 
be done in one frame. At least 
At least in the Evo SDK this is true. 
   But there is one trick with the ears that allows─
Let's recolor the entire screen and do this 
quickly. It's called "palette effects" 
not suitable for all occasions, but about that 
I'll tell you further. 

        Who or what is the palette?

   Roughly speaking, in our case the palette is
this is a certain area of ​​memory where it is stored
information about colors that can be
currently displayed on the screen.
   But the image itself is not stored in a form─
those colors are on a point, and in the form of a follower─
indexes.
   This allows you to save significantly
memory, for example:
  - 320x200 image in 32-bit color
will occupy 320*200*4=256000 B = 250 kB 
  - image 320x200 from 256 colors bu─
children occupy 320*200=64000 B = 62.5 kB 
  - and the image is in the ATM/ZX Evo standard with
a palette of 16 colors will take up only 
320*200*0.5=32000 B = 31 kB. 
   The difference is obvious.
   With obvious advantages of indexed
graphics: small image sizesand how
consequence, less load on the system, that─
what approach to image storage does
negative sides in the form of less "color"
tastiness", and with a small palette size -
also a headache when trying to squeeze in─
jump into this palette and make it beautiful.
   So that periodically you can me─
select colors (from level to level, for example).
And so that the graphics can be used
repeatedly, and not just once for some reason
a strictly defined palette, and even left─
moose a pair of unoccupied flowers for effects in
game time.

    Color representation on ATM/ZX Evo

   Now let's move closer to our platforms─
meh. ATM/ZX Evo can display ra─
size 320x2OOpx 16 colors from
64 possible. Frankly speaking, some of
those 64 colors are practically useless due to
its “eye-popping” (for example, acid-
green or bubblegum pink), but this is already
costs. Maybe someone will find it for them
application, but most often will be used─
there are all shades of gray, plus black and white─
bright and dark shades of different colors.
   For each color component (red,
green, blue) 2 bits are allocated.
   Thus, each component can
take values:
 representation:
 binary hexadecimal
 00 00
 01 55
 10 AA
 11 FF
 Color components are recorded in volume─
in military order - i.e. BGR.
   For example, in the program code you need to replace─
thread some color in the palette on Oxffaa55
(light orange).
   Let's transform the components:
 R - Oxff - %11
 G - Oxaa - %10
 B - 0x55 - %01
 Let's write it in reverse order in binary
form:
 BGR - %011011
 Convert to a decimal number, for use─
use in code (since C does not provide
the ability to write binary numbers is now available). B
win7 built-in copes with this perfectly
calculator:27.

            What is this for?

   Let's move on to the main question: why in─
In general, you need to bother with the palette next─
what programmer for ATM/ZX Evo?
   The answer is simple - for special effects. It is possible
Of course, we can do without them, the game is in terms ofnothing will lose any interest from this.
But we know that the player must first
lure, and what if not beautiful graphics,
full of special effects, best reduces
entry bar?
   The beauty of palette effects is that
that they use resources extremely economically
systems. To get the result you need
just change a couple of bytes, instead of re─
resource-intensive redrawing of the entire image
or some part of it. Application of palit─
ditch effects instead of animation where it is
perhaps, really very much times─
loads the processor.

                 Examples

 1. The simplest and most commonly used:
smooth dimming and brightening of the screen. 
Most often used when transitioning from od─
one scene to another (for example, from a menu in
game).
   This is done by changing the brightness of the palette fu─
functionpal_bright(u8 bright), where the parameter
bright can take values from0 - that's all 
black, up to6 - all white. 3 - corresponding─
but, normal brightness value.
   Also changing the brightness of the palette to
one or two frames can be taken differently
flashes (from explosions, lightning, etc.)

 2. Another commonly used example:
water animation. 



   I drew a picture - an example. on her
shows how you can make an animated
water without animation as such. In the upper
in the row you can see the image itself, and in
lower - the state of the three colors of the palette.
   The point is this: In the water tile initially
two animation frames are hidden (this is good
can be seen in the last frame, where all three
different colors). These two frames (in the sense, with
different waves) at the same time never
are shown, the color of one of them is made
equal to the background color. The wave effect can be achieved─
flow, smoothly changing one color when the second
equal to the background color. Then they change months─
tami. And so on in a circle.

 3. Shading effect. 

   The meaning of this effect is similar to the first one, one─
The first effect darkens the entire screen, and
There are situations when it’s not okay to do this─
it's good.
   For example, a character turns off in a room
light. The interface should remain visible,
character and gender, most likely too.
   In such a situation, it is necessary to clearly separate
colors that will never change
(colors of the interface, character, other necessary
objects), and the colors of the environment to which
the effect will be applied. In the application -
example from the game Sonic & Knuckles on Sega
Mega Drive (sonic_sample.gif ).  Natural─ 
there are more colors on this platform, and
active palettefour times more, but
The general meaning does not change from this. When you─
When the light is turned on, some colors remain unexposed─
variable, and part changes according to the composition in advance─
in the table.
   Let me explain a little about the change table─
flowers. For every color in the palette
all its states are calculated in advance
with the lights on and off. When
necessary, the program runs according to the value─
niyami this table and apply in turn
them to the screen palette.

 4. Motion effects.  

   The most beautiful looking effects.
Most often used for animation is the handle─
trees, waterfalls, conveyors, etc.

   In general, everything that moves, whose animation
is cyclical and fits into one or two tiles.

   I'll take the waterfall tile as an example.
from the second level of Contra for the Famicom.

 


   In the small square below - single
tile. Above it, for clarity, there are nine of these
the same, placed in a 3x3 grid.
   Everything should be clear from the example─
well, but just in case - the tile is drawn
in such a way that during a cyclic shift
colors in the palette created the illusion of movement─
water, in this case water.

 5. Here is a more complex example from the final
Nomad screensavers for ATM Turbo 2+/ZX Evo, in
which creates the effect of movement separately
standing objects:nomad_outro.png.
 At the top of the example is the base map─
teen, painted in everything for clarity
the colors of the rainbow. As can be seen from the example, she once─
divided into many narrow strips, of which
the end result is animation. B
the program colors all these stripes
colors from the plate below: two colors - b─
nie, the rest are black. Actually, why
Are the two stripes colored blue? For pla─
animation. Each beat, move the bar─
bends to half its length.
   Animation is done using the same principle.
lands in 2D racing with a rear view (Chase HQ,
Top Gear, Outrun), and many other places: Space 
Harrier, for example. 

                  * * *

   I have described the most common ones
effects. The palette of special effects themselves ve─ 
faceless multitude. There is also a huge category─ 
a range of simple effects in one/two colors, 
like lightning flashes, neon lights 
somewhere on the horizon, etc. But they are so 
primitive that the reader, if desired, can easily 
You will figure out how such effects are made. 
   I would also like to note what to plan
effects are needed even before you start drawing graphics─ 
ki, because there may simply not be any left for them 
places in the palette. It’s unfortunate, but both─ 
The opposite happens. Developer in the heat of the moment 
enthusiastically makes one or two levels, draws 
for them graphics, sprites, backgrounds, but only 
then he starts to think about how they managed it all─ 
the beauty can be made even better with the help of effe─whov. But the palette has already been used for─ 
mating, and you need to either give up the effects, 
or redraw the graphics, choose something─ 
to throw something around, to shuffle something. And it’s good if 
It will only be a matter of graphics. Maybe 
such that you will have to radically change the movement─ 
Jock. So, to prevent this from happening, comrades, 
before starting physical work on the game 
think carefully about what will happen in the game 
and at what point it will appear. 

Share your thoughts about the article