Special effects world - fade in fade out (true color mode)

zhaozj2021-02-08  254

Fade in fade out is Fade in, Fade Out. The former refers to the translucent of a image from a black background, and the latter refers to let a image disappear in a black background. Almost all games use this effect, when the screen on the screen needs to switch, let the previous image fade in, let the next image Fade Out. Everyone is the most familiar, "Xianjian", when you encounter an enemy or enter another scene, the screen will come to such an effect, let you slow down, and there is a certain role of the game plot, Let you feel a short silence after you are in a hurry.

There are many ways to achieve fade-in fade out. The previous game because mostly run in the 8-bit palette mode, for this situation, the fastest way to achieve fade in fade is dynamically modify the palette.

Dynamically modified palette: There is a slight change in the color value of each entry of the palette before each update screen. If it is fade, let this change have a trend from primary color to black. If it is faded, this change has a trend from black to the primary color.

Because the palette entry is up to 256 items, and the update palette work is that the hardware is complete, the speed is very fast, so this method can be used to get a very good full screen fade out.

However, with the continuous improvement of hardware and software technology, the current game has the trend towards 16 or 24 models. Imagine how wonderful things will be fad out of a high-color picture. However, in the high color mode, the system does not use the palette, so in this case, if you want to achieve fade out, you have to use another method to directly modify the color value.

Directly modify the color value: As the name suggestion, it is to change the pixel color value on the page one by one to modify it, and then send it back to the page. This method is actually one of Alpha mixed.

This method seems to be very dead, there is no smart component, but it can be said to be the only effective way to fade into the high color image. So, have you thought about switching the display mode from a high color to 8-bit mode when you need to fade out? Brother, I advise you don't do this, because when you switch the display mode, your monitor will have a very obvious flash, and the user who does not understand will only burn the display! Such a big tail is still not exposed.

In fact, use the method of directly modifying the color value, on the PC's computer (configured as follows: K6-180, 2M memory, 64M memory, except for the memory bigger, the rest is the standard configuration of the previous year, such a configuration should Not good), 640x480x24 mode, an image of a 320x240 (1/4 screen) can reach a good fade out, FPS can reach 20, this is said that if you will fade out to 20 One second can be completed, which is enough to meet the needs of human discerning visual.

Dynamic modifying the palette method I will not introduce in this article. The following simply introduces the way to achieve fade out in high color mode.

Only one off-screen page is used in the program, and it is stored in a 320x240 BMP true color bitmap, which is Down from Netease Wallpapers.

Original image:

The following tasks are not to update the background cache and then change the page. Updating the work of the background cache is similar to the alpha, first using the LOCK function to locate the left-screen page and the background cache page, get the pointer to the page, then use two for loops, each of the remote papers The three original colors of a pixel, calculates the fade-in or fade of color values, and then assigns this value to the background cache. This is also an alpha mixed operation. In this example, the Alpha hybrid formula is as follows: destColor = Source = Source * alpha / 256;

DestColor = target color, Source = primary color, alpha = alpha value (0 ~ 255 reciprocating changes)

The alpha value here should be collected from 0 to 255, so that the effect of fade out is displayed. It can be seen that the fade of an alpha mixed formula is very simple.

From this article and the first two introductions ALPHA mixed article, Alpha mixed in the current game programming, the status is increasingly important, and many special effects are produced by it. However, in the current DirectX version 5.0, Alpha hybrids are not supported, so if you want to write such a program, you must write code yourself, the use of pointers is essential, Alpha mix is ​​basically a pointer operation, so write ALPHA mixed programs are troublesome. And A monitor, and installed Win98, it is really a very goodism), often happens (actually doesn't have a real crash, just because your DirectX program completely controls the machine, the adjuster can not work, resulting in You can't return to the Windows interface, only weighted). So, after your compilation is successful, try to make sure there is no logic error or pointer error, then run the program.

In order to make the program more easier, these routines are used 24-bit color modes, and the operation formula is also very simple and easy to understand. If you are interested, you can turn them to 16-bit mode. In addition, because the old king is very busy, these programs have not been optimized, if you find faster methods, please don't know.

This fade-in-drop routine here, including executables, source code, download fade.zip (200K), because this package is relatively large.

Lao Wang 1999-2-22

modify:

Later, if this program does not use Alpha mix, the speed can be faster, that is, incrementing the color value number or decrements a fixed value, and add a judgment, if> 255 or <0, let it equal 255 or 0 . Because of this, the complex multi-division method is saved, and the number of times of reading page data is also reduced, and the only less than two judgments are.

After modification, other conditions are unchanged, and the frame rate has increased by 5 frames, and now you can reach 25 fps.

I used Alpha operation to achieve fade in fade out, the change in color is equal to the actual situation; and now the method of incrementing or decrementing with a fixed value, the change in color is equal, and it is not very mature, and a special case: If there are RGB (5, 5, 5) and RGB (250, 250, 250) on the page, if the fade increment is 10, then the previous color has become a pure black after the first level fades. The latter one requires 25 fading to become black, and in practice, the two should become all black after 25 fades. Despite this, the fade in fade out is achieved with a fixed value, and for the user, sometimes it does not seem to have any flaws, and this method is better to handle on the computer, and the speed can be improved. . Lao Wang 1999-2-23

转载请注明原文地址:https://www.9cbs.com/read-1292.html

New Post(0)