Guest User

Untitled

a guest
Jan 19th, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.80 KB | None | 0 0
  1. void ClientModeSkeleton::DoObjectMotionBlur( const CViewSetup *pSetup )
  2. {
  3.     if ( g_ObjectMotionBlurManager.GetDrawableObjectCount() <= 0 )
  4.         return;
  5.  
  6.     CMatRenderContextPtr pRenderContext( materials );
  7.  
  8.     ITexture *pFullFrameFB1 = materials->FindTexture( "_rt_FullFrameFB1", TEXTURE_GROUP_RENDER_TARGET );
  9.  
  10.     //
  11.     // Render Velocities into a full-frame FB1
  12.     //
  13.     IMaterial *pGlowColorMaterial = materials->FindMaterial( "dev/glow_color", TEXTURE_GROUP_OTHER, true );
  14.    
  15.     pRenderContext->PushRenderTargetAndViewport();
  16.     pRenderContext->SetRenderTarget( pFullFrameFB1 );
  17.     pRenderContext->Viewport( 0, 0, pSetup->width, pSetup->height );
  18.  
  19.     // Red and Green are x- and y- screen-space velocities biased and packed into the [0,1] range.
  20.     // A value of 127 gets mapped to 0, a value of 0 gets mapped to -1, and a value of 255 gets mapped to 1.
  21.     //
  22.     // Blue is set to 1 within the object's bounds and 0 outside, and is used as a mask to ensure that
  23.     // motion blur samples only pull from the core object itself and not surrounding pixels (even though
  24.     // the area being blurred is larger than the core object).
  25.     //
  26.     // Alpha is not used
  27.     pRenderContext->ClearColor4ub( 127, 127, 0, 0 );
  28.     // Clear only color, not depth & stencil
  29.     pRenderContext->ClearBuffers( true, false, false );
  30.  
  31.     // Save off state
  32.     Vector vOrigColor;
  33.     render->GetColorModulation( vOrigColor.Base() );
  34.  
  35.     // Use a solid-color unlit material to render velocity into the buffer
  36.     g_pStudioRender->ForcedMaterialOverride( pGlowColorMaterial );
  37.     g_ObjectMotionBlurManager.DrawObjects();   
  38.     g_pStudioRender->ForcedMaterialOverride( NULL );
  39.  
  40.     render->SetColorModulation( vOrigColor.Base() );
  41.    
  42.     pRenderContext->PopRenderTargetAndViewport();
  43.  
  44.     //
  45.     // Render full-screen pass
  46.     //
  47.     IMaterial *pMotionBlurMaterial;
  48.     IMaterialVar *pFBTextureVariable;
  49.     IMaterialVar *pVelocityTextureVariable;
  50.     bool bFound1 = false, bFound2 = false;
  51.  
  52.     // Make sure our render target of choice has the results of the engine post-process pass
  53.     ITexture *pFullFrameFB = materials->FindTexture( "_rt_FullFrameFB", TEXTURE_GROUP_RENDER_TARGET );
  54.     pRenderContext->CopyRenderTargetToTexture( pFullFrameFB );
  55.  
  56.     pMotionBlurMaterial = materials->FindMaterial( "effects/object_motion_blur", TEXTURE_GROUP_OTHER, true );
  57.     pFBTextureVariable = pMotionBlurMaterial->FindVar( "$fb_texture", &bFound1, true );
  58.     pVelocityTextureVariable = pMotionBlurMaterial->FindVar( "$velocity_texture", &bFound2, true );
  59.     if ( bFound1 && bFound2 )
  60.     {
  61.         pFBTextureVariable->SetTextureValue( pFullFrameFB );
  62.        
  63.         pVelocityTextureVariable->SetTextureValue( pFullFrameFB1 );
  64.  
  65.         int nWidth, nHeight;
  66.         pRenderContext->GetRenderTargetDimensions( nWidth, nHeight );
  67.  
  68.         pRenderContext->DrawScreenSpaceRectangle( pMotionBlurMaterial, 0, 0, nWidth, nHeight, 0.0f, 0.0f, nWidth - 1, nHeight - 1, nWidth, nHeight );
  69.     }
  70. }
Add Comment
Please, Sign In to add comment