Use alpha blending to achieve pseudo-motion blur effects

zhaozj2021-02-16  53

Use alpha blending to achieve pseudo-motion blur effects

Pan Li Liang 2003 8 31

Stanly Lee 2003-10-4

Email: xheartblue@etang.com

Homepage Gamehunter.3322.Net/xpertsoft/

We know that motion fuzzy effect can bring great visual authenticity to our scene. Implementation methods of motion blurring in common books and other places are based on cumulative buffers. The advantages of this method are precise, and some areas called time to sample motion blur. However, a fatal disadvantage of this method is slower, usually the speed of the cumulative buffer cumulative number of times, which is large in a real-time system. So we need to make a compromise here: We can use time to sample how to sample, but accumulate the previous rendering results and current rendering results. Form a effect called "pseudo" motion blur, practice proves that the effect of this method is still acceptable.

When I was a "rendering of the large-scale outdoor scene" in the previous time, I found a way to Game Tutorils. We save the previous rendering results in a texture, then render the current scene, and then in the scene. Painting a rectangle covering the entire viewport, this rectangle is mapping with our saved texture and a certain attenuation with the alpha value. (The specific implementation method can be found on Game Tutorils, or refer to my DEMO). In theory, this method is only necessary to render the scene once. But in fact it still brings a relatively large performance sacrifice, such as copy texture data, mapping texture, etc.

Let me introduce a motion blur effect that needs to be drawn. This method is the main thinking about the scene that needs to update the entire screen. We know that the previous rendering results are saved in the frame buffer. We need to make certain attenuation, then mix it with our scenes. Attenuation Process We only need to draw a black rectangle with a certain alpha blending in the viewport. Here is the key code I have given. This effect does not lose how much FPS. But the effect coming out is very good. I finally explain the lack of deficiencies, which is the defect: it requires us to use Alpha Blending to use Alpha Blending to combine the rendering results. Of course, you don't have to use alpha beding, but if your scene updates the entire screen. There is no way to exercise the fuzzy effect. That is to say, it is more suitable for some small DEMO special effects.

Rendering.

void render ()

{

// Note, this sentence must not comment it, or your motion is blurred.

/ / Of course, you have to clear the render target before the program enters the message loop. in case

// g_pd3ddevice-> Clear (0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB (0, 0, 0), 1.0F, 0);

// Do not clear the rendering target, but the depth buffer, the template buffers a class of things you have to be cleared.

g_pd3ddevice-> clear (0, NULL, D3DCLEAR_ZBuffer, D3DCOLOR_XRGB (0, 0, 0), 1.0F, 0);

// Start drawing.

g_pd3ddevice-> beginscene ();

/ / Open Alpha Blending

g_pd3ddevice-> setrenderstate (D3DRS_ALPHABLENDENABLE, TRUE);

// Turn off the light and texture saving overhead.

g_pd3ddevice-> setrenderstate (D3DRS_LIGHTING, FALSE);

g_pd3ddevice-> setfvf (Custom_FVF);

g_pd3ddevice-> setStreamSource (0, g_pvbuffer, 0, sizeof (custom_vertex)); g_pd3ddevice-> settexture (0, 0);

// Set alphablending factor.

g_pd3ddevice-> setrenderstate (D3DRS_SRCBLEND, D3DBLEND_ONE);

g_pd3ddevice-> setrenderstate (d3drs_destblend, d3dblend_srcalpha);

// Draw an alpha value between 0-0xFF,

// This rectangle is just filled with the entire viewport

Drawarect ();

/ / Set the projection method and transformation matrix of the scene

Setsencetrans ();

// You can open the lights here.

g_pd3ddevice-> setrenderstate (D3DRS_Lighting, True);

// Draw a scenario under normal conditions.

Drawsence ();

// Draw the end,

g_pd3ddevice-> endscene ();

g_pd3ddevice-> present (null, null, null, null);

}

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

New Post(0)