#include <motion_blur.h>
Nevrax France
Definition at line 45 of file motion_blur.h.
Public Member Functions | |
CMotionBlur () | |
void | performMotionBlur (IDriver *driver, float motionBlurAmount) |
void | releaseMotionBlur () |
release the resources used by motion blur | |
void | startMotionBlur (uint x, uint y, uint width, uint height) |
Protected Attributes | |
uint | _H |
NLMISC::CSmartPtr< ITexture > | _Tex |
uint | _W |
uint | _X |
uint | _Y |
|
Definition at line 39 of file motion_blur.cpp.
|
|
perform motion blur, using the given driver This can only have been called between a startMotionBlur / releaseMotionBlur pair. It must be called after the scene has been drawn of course. WARNING : this change the projection matrix and the frustum in the driver.
Definition at line 62 of file motion_blur.cpp. References _H, _W, NL3D::IDriver::activeVertexBuffer(), NL3D::IDriver::copyFrameBufferToTexture(), NL3D::IDriver::getWindowSize(), height, nlassert, NLMISC::raiseToNextPowerOf2(), NL3D::IDriver::renderQuads(), NL3D::CMaterial::setBlend(), NL3D::CMaterial::setBlendFunc(), NL3D::CMaterial::setColor(), NL3D::CMaterial::setDoubleSided(), NL3D::IDriver::setFrustum(), NL3D::CVertexBuffer::setNumVertices(), NL3D::CVertexBuffer::setTexCoord(), NL3D::CMaterial::setTexture(), NL3D::IDriver::setupModelMatrix(), NL3D::IDriver::setupViewMatrix(), NL3D::CVertexBuffer::setVertexCoord(), NL3D::CVertexBuffer::setVertexFormat(), NL3D::CMaterial::setZFunc(), NL3D::CMaterial::setZWrite(), NL3D::CMaterial::texEnvArg0Alpha(), NL3D::CMaterial::texEnvOpAlpha(), NL3D::CMaterial::texEnvOpRGB(), uint, uint32, uint8, and width.
00063 { 00064 nlassert(_Tex) ; //start motion blur has not been called !! 00065 nlassert(driver) ; 00066 nlassert(motionBlurAmount >= 0.f && motionBlurAmount <= 1.f) ; 00067 00068 static CVertexBuffer vb ; 00069 vb.setVertexFormat(CVertexBuffer::PositionFlag | CVertexBuffer::TexCoord0Flag ) ; 00070 vb.setNumVertices(4) ; 00071 00072 uint32 width, height ; 00073 driver->getWindowSize(width, height) ; 00074 00075 float widthRatio = _W / (float) NLMISC::raiseToNextPowerOf2 (_W) ; 00076 float heightRatio = _H / (float) NLMISC::raiseToNextPowerOf2 (_H) ; 00077 00078 driver->setFrustum(0, (float) width, 0, (float) height, -1, 1, false) ; 00079 00080 for (uint sn = 0 ; sn < 2 ; ++sn) 00081 { 00082 vb.setTexCoord(0, sn, CUV(0, 0)) ; 00083 vb.setTexCoord(1, sn, CUV(widthRatio, 0)) ; 00084 vb.setTexCoord(2, sn, CUV(widthRatio, heightRatio)) ; 00085 vb.setTexCoord(3, sn, CUV(0, heightRatio)) ; 00086 } 00087 00088 00089 static CMaterial mbMat ; 00090 static bool matSetup = false ; // set to true when mbMat has Been setup 00091 if (!matSetup) 00092 { 00093 mbMat.setBlend(true) ; 00094 mbMat.setBlendFunc(CMaterial::srcalpha, CMaterial::invsrcalpha) ; 00095 mbMat.setZWrite(false) ; 00096 mbMat.setZFunc(CMaterial::always) ; 00097 // stage 0 00098 mbMat.setTexture(0, _Tex) ; 00099 mbMat.texEnvOpRGB(0, CMaterial::Replace ); 00100 00101 mbMat.texEnvArg0Alpha(0, CMaterial::Diffuse, CMaterial::SrcAlpha); 00102 mbMat.texEnvOpAlpha(0, CMaterial::Replace); 00103 00104 mbMat.setDoubleSided(true) ; 00105 matSetup = true ; 00106 } 00107 00108 00109 mbMat.setColor(CRGBA(255, 255, 255, (uint8) (255.f * motionBlurAmount) ) ) ; 00110 00111 00112 vb.setVertexCoord(0, CVector((float) _X, 0, 0) ) ; 00113 vb.setVertexCoord(1, CVector((float) (_X + _W), 0 ,0) ) ; 00114 vb.setVertexCoord(2, CVector((float) (_X + _W), 0, (float) (_Y + _H) ) ); 00115 vb.setVertexCoord(3, CVector(0 , 0, (float) (_Y + _H) ) ) ; 00116 00117 driver->setupViewMatrix(CMatrix::Identity) ; 00118 driver->setupModelMatrix(CMatrix::Identity) ; 00119 00120 00121 driver->activeVertexBuffer(vb) ; 00122 driver->renderQuads(mbMat, 0, 1) ; 00123 00124 // blit back frame buffer to save this frame 00125 00126 00127 00128 driver->copyFrameBufferToTexture(_Tex, 0, 0, 0, _X, _Y, _W, _H) ; 00129 00130 00131 } |
|
release the resources used by motion blur
Definition at line 56 of file motion_blur.cpp.
|
|
Must be called before performing motion blur on a image sequence. Motion blur is performed on a rectangular area. 2 calls -> nlassert. Once motion blur must be stopped, you must call releaseMotionBlur.
Definition at line 45 of file motion_blur.cpp. References _H, _W, height, nlassert, uint, width, x, and y.
|
|
Definition at line 73 of file motion_blur.h. Referenced by performMotionBlur(), releaseMotionBlur(), and startMotionBlur(). |
|
Definition at line 72 of file motion_blur.h. |
|
Definition at line 73 of file motion_blur.h. Referenced by performMotionBlur(), releaseMotionBlur(), and startMotionBlur(). |
|
Definition at line 73 of file motion_blur.h. |
|
Definition at line 73 of file motion_blur.h. |