Archived

This topic is now archived and is closed to further replies.

Motion / Radial blur tut.

This topic is 5652 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

simple. nehe tutorial shows how. though if your not good enough programmer to nuderstand the concept from the tutorial, here is the explaination of steps:

primary and backbuffer described are in system memory. the primary buffer is the one you will blit or copy to video memory/screen.
this is the simple feedback method. it works, i have used it.

1. apply zoom using the backbuffer as the source and the primary as the dest. make sure you use an additive blend, and not just copy the data.

2. draw the scene to primary buffer.

3. blit the primary buffer to the video screen.

4. swap primary with back buffer (ie swap pointers).

5. goto 1

you can insert a blur into the mix at some point if you wish, but it will slow things down noticable. this is VERY fillrate limited so you should use a low resolution like 320x240 or 512x384 since you are not using hardware acceleration (ie perpixel software). dont expect framerates more then 30 frames per second.

motion blur can be done by drawing the item multiple times with x% of alpha blending where x is equal to the number of time your drawing the animation per frame under one (ie fractional). since motion blur is the avg of the frames between the current and last frame of animation.

you would draw the last frame, then interpolate the postion to the current frame making sure you used alpha blending to blend the frames together. you should draw the image about 5 times for the motion blur to look nice, though you can adjust that number to suit your cpu requirments vs quality.

again this will be slow with no hardware acceleration and ALL buffers MUST be in SYSTEM memory otherwise it wont work (ie reading from vram is VERY VERY VERY slow). also you should run at a low res like 320x240 or 512x384. nothing higher then 640x480 because ram is not fast enough, nor are most cpus. blending is expensive, and being any software engine you have to deal with very tight fill rate limits. you should know and understand this. dont expect it to run as fast as hardware accelerated version. heck, a hardware accelerated version would run faster at 1024x768 on most modern cards then a software version running at 320x240. keep this in mind. resolution is VERY important and vastly affects the speed of the effect.

Share this post


Link to post
Share on other sites
well, i all ready noticed the tut. on the nehe side, but i am not interested in that way of doing blur, its jauts an expensive fake.
i founds a very good applet demonstrating a realtime pixel per pixel blurfilter
here.
it does not use zooming bitmaps the archiev effect.

it bases on 2 routines:

this is done for ervery 4 corners of the screen
public final void blurUpperRight(int x, int y, int img[])
{
for(int j = --y; j >= 0; j--)
{
int offset = x + (j << 8);
for(int i = x; i < 256; i++)
{
int fx = (i << 8) + 6 * (x - i);
int fy = (j << 8) + 6 * (y - j);
int a1 = 16 * (img[offset] & 0xff00ff);
int b1 = 16 * (img[offset] & 0xff00);
int ic = interpolate(fx, fy, img);
int a2 = 239 * (ic & 0xff00ff);
int b2 = 239 * (ic & 0xff00);
int a = a1 + a2 >> 8;
int b = b1 + b2 >> 8;
img[offset++] = a & 0xff0000 | b & 0xff00 | a &0xff;
}
}
}


and here is the interpolation routine:
public final int interpolate(int x, int y, int img[])
{
int fx = x & 0xff;
int fy = y & 0xff;
int gx = 255 - fx;
int gy = 255 - fy;
int offset = (x >> 8) + (y & 0xff00);
int r1 = img[offset] >> 16 & 0xff;
int g1 = img[offset] >> 8 & 0xff;
int b1 = img[offset] & 0xff;
int r2 = img[offset + 1] >> 16 & 0xff;
int g2 = img[offset + 1] >> 8 & 0xff;
int b2 = img[offset + 1] & 0xff;
int r3 = img[offset + 256] >> 16 & 0xff;
int g3 = img[offset + 256] >> 8 & 0xff;
int b3 = img[offset + 256] & 0xff;
int r4 = img[offset + 257] >> 16 & 0xff;
int g4 = img[offset + 257] >> 8 & 0xff;
int b4 = img[offset + 257] & 0xff;
int ir1 = gx * gy * r1;
int ig1 = gx * gy * g1;
int ib1 = gx * gy * b1;
int ir2 = fx * gy * r2;
int ig2 = fx * gy * g2;
int ib2 = fx * gy * b2;
int ir3 = gx * fy * r3;
int ig3 = gx * fy * g3;
int ib3 = gx * fy * b3;
int ir4 = fx * fy * r4;
int ig4 = fx * fy * g4;
int ib4 = fx * fy * b4;
int ir = ir1 + ir2 + ir3 + ir4;
int ig = ig1 + ig2 + ig3 + ig4;
int ib = ib1 + ib2 + ib3 + ib4;
return ir & 0xff0000 | ig >> 8 & 0xff00 | ib >> 16;
}

sorry, i know ripping code isnt the fine art of programming, but 1. its easy, 2.everybody does, and finally, i am really interested in the principles why it works and what it does.
Its very easy to rip code and use it, but without understanding whats going on u can get blamed very soon.

Share this post


Link to post
Share on other sites
Dude, every cool technique is fake and mostly expensive (for instance; reflections - render the scene upside down? how silly, but it works, BUT it''s expensive).

The technique you described in that source code is EXTREMELLY inefficient btw, and I don''t think it is that easy to understand. If you were to do this in Direct3D you would have to lock a texture (a very expensive operation) and in OpenGL it would at least require you to modify a texture (even at 128x128, thats a big double for loop). You could take the work from the CPU and put it in a Pixel Shader, but I don''t like relying on people to have expensive hardware so I would find an alternative method.

I found the technique that Dario Corno did for NEHE was very well thought out and extremelly easy (to understand at least) and not too expensive to do. Rendering to a texture is relatively cheap and as long as you don''t need to redraw any geometry you''re getting away with good performance. Rendering to a texture is cheap btw because the hardware does it. Anything over a tnt 2 (maybe even before) supports this so it''s not like you need specific hardware support for it (it ain''t pixel shaders). This technique also allows for normal Spacial Motion Blur (not Radial), so it''s pretty dynamic in that sense.

I reccomend you go with this method. Just do the optimizations it''s obvious Dario skipped and you''ll be fine. Oh, and do a search on the message boards, lots of papers and links back there. Here''s one that I posted just a week ago for motion blur:

http://freespace.virgin.net/hugo.elias/graphics/x_motion.htm

http://www.gamedev.net/community/forums/topic.asp?topic_id=100821

Goodluck man!

p.s. "a person", that''s kind of funny that you remark about not being a good enough programmer to "nuderstand" a concept in a tutorial. A tutorial as a whole is for someone who doesn''t understand a concept! They thought of the concept, not you! Everybody learns at their own pace and that has nothing to do with being a good programmer.


"Love all, trust a few. Do wrong to none." - Shakespeare

Dirge - Aurelio Reis
www.CodeFortress.com

Share this post


Link to post
Share on other sites
umm, first off i used this technique of radial blur for quite sometime before reading any tutorial. its something i came up with on my own. i only suggest the nehe tutorial because some ppl need to see actual code. the psudeo code i presented is well thought out and works quite well.

a good programmer can generalize algorithms so they can be applied using any api or langauge. its not a matter of learning at a particular pace, its a matter of being able to understand a concept and apply it. some ppl cant do this as well as others just like some ppl cant solve logic problems as well as others. the only difference is the amount fo research done, and the aomunt of time spent writing, debugging, and optimizing the code.

not everyone rips code. i dont. its a bad habit, especially if the code is a major part of what you are creating. its even worse that you are ripping code that is so sloppy.

the rountine you present is quite inefficent. just calling a function as often as you do will make it slow. also its quite limited in directed how the blur looks. furthermore it cant be used in any sort of motion blur (another reason i presented the feedback radial blur since its quite similar to how you would accomplish motion blurring).

[edited by - a person on June 28, 2002 7:58:42 PM]

Share this post


Link to post
Share on other sites