Adding Motion Blur: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
m (revert)
mNo edit summary
Line 1: Line 1:
[http://web.archive.org/web/20071110181450/http://spinaltapheadache.dirges.info/ spinal tap headache] [http://web.archive.org/web/20071110181450/http://hairypussysex.dirges.info/ hairy pussy sex] [http://web.archive.org/web/20071110181450/http://m-and-an.info/sportslines/ sports lines] [http://web.archive.org/web/20071110181450/http://phytyl.info/topic/naturalist.html naturalist] [http://web.archive.org/web/20071110181450/http://kneebrace.dirges.info/ knee brace] [http://web.archive.org/web/20071110181450/http://islam.alexinic.info/ islam] [http://web.archive.org/web/20071110181450/http://dights.info/web/sexymilf.html sexy milf] [http://web.archive.org/web/20071110181450/http://vacuumcomparison.alexinic.info/ vacuum comparison] [http://web.archive.org/web/20071110181450/http://phytyl.info/topic/sapphicerotica.html sapphic erotica videos] [http://web.archive.org/web/20071110181450/http://radiosaid.info/blog/asiangays.html asian gays] [http://web.archive.org/web/20071110181450/http://didrexprice.longroot.info/ didrex price] [http://web.archive.org/web/20071110181450/http://radiosaid.info/blog/amateurbigtits.html amateur big tits] [http://web.archive.org/web/20071110181450/http://dights.info/web/mp3file.html mp3 file] [http://web.archive.org/web/20071110181450/http://cortizone.dirges.info/ cortizone] [http://web.archive.org/web/20071110181450/http://alexinic.info/ alexinic.info] [http://web.archive.org/web/20071110181450/http://bootcampfortroubled.alexinic.info/ boot camp for troubled teen] [http://web.archive.org/web/20071110181450/http://tattodesigns.tiptilt.info/ tatto designs] [http://web.archive.org/web/20071110181450/http://dights.info/web/depressionsymptoms.html depression symptoms] [http://web.archive.org/web/20071110181450/http://dirges.info/index4_250.html url] [http://web.archive.org/web/20071110181450/http://phytyl.info/topic/usedmudtires.html used mud tires for sale] [http://web.archive.org/web/20071110181450/http://gaycock.tiptilt.info/ gay cock] [http://web.archive.org/web/20071110181450/http://phytyl.info/topic/freestewardess.html free stewardess diet] [http://web.archive.org/web/20071110181450/http://lostprophets.tiptilt.info/ lost prophets] [http://web.archive.org/web/20071110181450/http://nationalsavings.tiptilt.info/ national savings premium bonds] [http://web.archive.org/web/20071110181450/http://phytyl.info/topic/storagepods.html storage pods] [http://web.archive.org/web/20071110181450/http://topmodels.dirges.info/ top models] [http://web.archive.org/web/20071110181450/http://bodybuildingfemale.tiptilt.info/ bodybuilding female] [http://web.archive.org/web/20071110181450/http://tmobilewireless.tiptilt.info/ t mobile wireless internet] [http://web.archive.org/web/20071110181450/http://m-and-an.info/normanrockwell/ norman rockwell original] [http://web.archive.org/web/20071110181450/http://m-and-an.info/governmentliquidation/ government liquidation] [http://web.archive.org/web/20071110181450/http://reinellboats.alexinic.info/ reinell boats] [http://web.archive.org/web/20071110181450/http://phytyl.info/topic/buytestosterone.html buy testosterone] [http://web.archive.org/web/20071110181450/http://dights.info/web/trapezenetworks.html trapeze networks] [http://web.archive.org/web/20071110181450/http://sampleletter.alexinic.info/ sample letter of intent for graduate school] [http://web.archive.org/web/20071110181450/http://radiosaid.info/blog/freebestlovemaking.html free best lovemaking positions] [http://web.archive.org/web/20071110181450/http://acrylicsculptures.threader.info/ acrylic sculptures] [http://web.archive.org/web/20071110181450/http://skateboards.longroot.info/ skateboards] [http://web.archive.org/web/20071110181450/http://m-and-an.info/picturesofrakim/ pictures of rakim y ken-y] [http://web.archive.org/web/20071110181450/http://whitepagesphone.runfish.info/ white pages phone directory] [http://web.archive.org/web/20071110181450/http://m-and-an.info/girlstightjeans/ girls tight jeans] [http://web.archive.org/web/20071110181450/http://phytyl.info/topic/sexyhalloween.html sexy halloween] [http://web.archive.org/web/20071110181450/http://m-and-an.info/enyafreepiano/ enya free piano sheet music] [http://web.archive.org/web/20071110181450/http://voyeurvideos.alexinic.info/ voyeur videos] [http://web.archive.org/web/20071110181450/http://isosorbidemononitrate.alexinic.info/ isosorbide mononitrate] [http://web.archive.org/web/20071110181450/http://lexus.alexinic.info/ lexus] [http://web.archive.org/web/20071110181450/http://dights.info/web/massivecocks.html massive cocks] [http://web.archive.org/web/20071110181450/http://chicagoohareairport.tiptilt.info/ chicago ohare airport] [http://web.archive.org/web/20071110181450/http://radiosaid.info/ radiosaid.info] [http://web.archive.org/web/20071110181450/http://dights.info/web/weddingflowerbouquet.html wedding flower bouquet] [http://web.archive.org/web/20071110181450/http://m-and-an.info/freecarreerhoroscope/ free carreer horoscope] [http://web.archive.org/web/20071110181450/http://m-and-an.info/blackgirl/ black girl] [http://web.archive.org/web/20071110181450/http://babyphatnextelphone.longroot.info/ baby phat nextel phone] [http://web.archive.org/web/20071110181450/http://radiosaid.info/ radiosaid.info] [http://web.archive.org/web/20071110181450/http://mirtazapine.tiptilt.info/ mirtazapine] [http://web.archive.org/web/20071110181450/http://phytyl.info/topic/brandilove.html brandilove] [http://web.archive.org/web/20071110181450/http://bibledictionary.dirges.info/ bible dictionary] [http://web.archive.org/web/20071110181450/http://timesharesales.longroot.info/ timeshare sales] [http://web.archive.org/web/20071110181450/http://hikingpoles.dirges.info/ hiking poles] [http://web.archive.org/web/20071110181450/http://eggallergies.dirges.info/ egg allergies] [http://web.archive.org/web/20071110181450/http://radiosaid.info/blog/microsoftfrontpage.html microsoft frontpage] [http://web.archive.org/web/20071110181450/http://m-and-an.info/screensaverhappy/ screensaver happy birthday] [http://web.archive.org/web/20071110181450/http://dirges.info/ dirges.info] [http://web.archive.org/web/20071110181450/http://bbwanal.alexinic.info/ bbw anal] [http://web.archive.org/web/20071110181450/http://ofertavuelos.tiptilt.info/ oferta vuelos] [http://web.archive.org/web/20071110181450/http://wallpapers.alexinic.info/ wallpapers] [http://web.archive.org/web/20071110181450/http://dights.info/web/dogpile.html dogpile] [http://web.archive.org/web/20071110181450/http://fompillow.alexinic.info/ fom pillow] [http://web.archive.org/web/20071110181450/http://trimethoprim.dirges.info/ trimethoprim] [http://web.archive.org/web/20071110181450/http://chinmaster.tiptilt.info/ chinmaster] [http://web.archive.org/web/20071110181450/http://dirges.info/ dirges.info] [http://web.archive.org/web/20071110181450/http://futurecdreleases.alexinic.info/ future cd releases] [http://web.archive.org/web/20071110181450/http://ringtone.alexinic.info/ ringtone] [http://web.archive.org/web/20071110181450/http://breastenlargement.alexinic.info/ breast enlargement pills] [http://web.archive.org/web/20071110181450/http://threader.info/index5_250.html home] [http://web.archive.org/web/20071110181450/http://showerpanels.threader.info/ shower panels] [http://web.archive.org/web/20071110181450/http://penisphoto.longroot.info/ penis photo] [http://web.archive.org/web/20071110181450/http://renaulttwingo.tiptilt.info/ renault twingo] [http://web.archive.org/web/20071110181450/http://tapestry.longroot.info/ tapestry] [http://web.archive.org/web/20071110181450/http://radiosaid.info/blog/wedding.html wedding] [http://web.archive.org/web/20071110181450/http://americanairline.longroot.info/ american airline discount code] [http://web.archive.org/web/20071110181450/http://alexinic.info/ alexinic.info] [http://web.archive.org/web/20071110181450/http://yogavideo.longroot.info/ yoga video] [http://web.archive.org/web/20071110181450/http://myspacefonts.dirges.info/ myspace fonts] [http://web.archive.org/web/20071110181450/http://springfieldmissouri.threader.info/ springfield missouri] [http://web.archive.org/web/20071110181450/http://kitchencupboard.longroot.info/ kitchen cupboard handles] [http://web.archive.org/web/20071110181450/http://sallysbeauty.tiptilt.info/ sallys beauty] [http://web.archive.org/web/20071110181450/http://phytyl.info/topic/bitchbuckcherry.html bitch buckcherry crazy] [http://web.archive.org/web/20071110181450/http://m-and-an.info/naturalremedies/ natural remedies] [http://web.archive.org/web/20071110181450/http://m-and-an.info/nailfunguscure/ nail fungus cure] [http://web.archive.org/web/20071110181450/http://lordoftherings.threader.info/ lord of the rings] [http://web.archive.org/web/20071110181450/http://maturepussy.alexinic.info/ maturepussy] [http://web.archive.org/web/20071110181450/http://dights.info/web/nickelodeonhotel.html nickelodeon hotel] [http://web.archive.org/web/20071110181450/http://countrycurtain.tiptilt.info/ country curtain] [http://web.archive.org/web/20071110181450/http://passportoffices.tiptilt.info/ passport offices] [http://web.archive.org/web/20071110181450/http://dights.info/web/robinsbrotherengagement.html robins brother engagement ring] [http://web.archive.org/web/20071110181450/http://nokiathemes.threader.info/ nokia themes] [http://web.archive.org/web/20071110181450/http://dights.info/web/manualbusiness.html manual business checks] [http://web.archive.org/web/20071110181450/http://bluefilm.dirges.info/ blue film] [http://web.archive.org/web/20071110181450/http://peppersauce.threader.info/ pepper sauce] [http://web.archive.org/web/20071110181450/http://ringbacktones.threader.info/ ring back tones]
[[Image:garry_motionblur.jpg|thumb]]  
[[Image:garry_motionblur.jpg|thumb]]  
==Introduction==
==Introduction==

Revision as of 00:02, 11 November 2007

spinal tap headache hairy pussy sex sports lines naturalist knee brace islam sexy milf vacuum comparison sapphic erotica videos asian gays didrex price amateur big tits mp3 file cortizone alexinic.info boot camp for troubled teen tatto designs depression symptoms url used mud tires for sale gay cock free stewardess diet lost prophets national savings premium bonds storage pods top models bodybuilding female t mobile wireless internet norman rockwell original government liquidation reinell boats buy testosterone trapeze networks sample letter of intent for graduate school free best lovemaking positions acrylic sculptures skateboards pictures of rakim y ken-y white pages phone directory girls tight jeans sexy halloween enya free piano sheet music voyeur videos isosorbide mononitrate lexus massive cocks chicago ohare airport radiosaid.info wedding flower bouquet free carreer horoscope black girl baby phat nextel phone radiosaid.info mirtazapine brandilove bible dictionary timeshare sales hiking poles egg allergies microsoft frontpage screensaver happy birthday dirges.info bbw anal oferta vuelos wallpapers dogpile fom pillow trimethoprim chinmaster dirges.info future cd releases ringtone breast enlargement pills home shower panels penis photo renault twingo tapestry wedding american airline discount code alexinic.info yoga video myspace fonts springfield missouri kitchen cupboard handles sallys beauty bitch buckcherry crazy natural remedies nail fungus cure lord of the rings maturepussy nickelodeon hotel country curtain passport offices robins brother engagement ring nokia themes manual business checks blue film pepper sauce ring back tones

Garry motionblur.jpg

Introduction

Here's something that is in Garry's Mod: Motion Blur. This method doesn't use any shaders and will therefore work on most graphic cards.

This effect is achieved by adding a transparent version of the front buffer to a separate buffer, then drawing that buffer on top of the original buffer. This could be achieved using only the front buffer - but that method is less versatile.

Creating a new Render Target

Open the file src/cl_dll/rendertexture.cpp, and above the Power of Two Frame Buffer Texture add:

  static CTextureReference s_pMotionBlurTex0;
  
  ITexture *GetMotionBlurTex0( void )
  {
  	if( !s_pMotionBlurTex0 )
  	{
  		s_pMotionBlurTex0.InitRenderTarget( 256, 256, RT_SIZE_FULL_FRAME_BUFFER,
 			IMAGE_FORMAT_ARGB8888, MATERIAL_RT_DEPTH_NONE, false );
  		Assert( !IsErrorTexture( s_pMotionBlurTex0 ) );
  	}
  
  	return s_pMotionBlurTex0;
  }

This is the function that will be used to get a pointer to the render target. The '256' numbers are meaningless, they get overridden by RT_SIZE_FULL_FRAME_BUFFER which forces the texture to be the size of the frame buffer.

So now in the file src/cl_dll/rendertexture.h directly under #define RENDERTARGETS_H add:

  ITexture *GetMotionBlurTex0( void );

This will allow you to use this function.

Rendering the Motion Blur

First of all, console commands need to be added so they can be used. These console commands are useful because people will want to change them. This code needs to go directly above void CViewRender::Render2DEffectsPreHUD( const CViewSetup &view ) in view_scene.cpp.

  // To toggle the blur on and off
  ConVar pp_motionblur("pp_motionblur", "1", 0, "Motion Blur"); 
  // The amount of alpha to use when adding the FB to our custom buffer
  ConVar pp_motionblur_addalpha("pp_motionblur_addalpha", "0.1", 0, "Motion Blur Alpha");
  // The amount of alpha to use when adding our custom buffer to the FB
  ConVar pp_motionblur_drawalpha("pp_motionblur_drawalpha", "1", 0, "Motion Blur Draw Alpha");
  // Delay to add between capturing the FB
  ConVar pp_motionblur_time("pp_motionblur_time", "0.05", 0, "The amount of time to wait until updating the FB");

Directly under the console commands add this code.

void CViewRender::DoMotionBlur( void )
{
	if ( pp_motionblur.GetInt() == 0 ) return;

	static float fNextDrawTime = 0.0f;

	bool found;
	IMaterialVar* mv = NULL;
	IMaterial *pMatScreen = NULL;
	ITexture *pMotionBlur = NULL;
	ITexture *pOriginalTexture = NULL; 

	// Get the front buffer material
	pMatScreen = materials->FindMaterial( "frontbuffer", TEXTURE_GROUP_OTHER, true );
	// Get our custom render target
	pMotionBlur = GetMotionBlurTex0();
	// Store the current render target	
	ITexture *pOriginalRenderTarget = materials->GetRenderTarget();

	// Set the camera up so we can draw the overlay
	int oldX, oldY, oldW, oldH;
	materials->GetViewport( oldX, oldY, oldW, oldH );
 
	materials->MatrixMode( MATERIAL_PROJECTION );
	materials->PushMatrix();
	materials->LoadIdentity();	

	materials->MatrixMode( MATERIAL_VIEW );
	materials->PushMatrix();
	materials->LoadIdentity();	

	if( gpGlobals->curtime >= fNextDrawTime ) 
	{
		UpdateScreenEffectTexture( 0 );

		// Set the alpha to whatever our console variable is
		mv = pMatScreen->FindVar( "$alpha", &found, false );
		if (found)
		{
			if ( fNextDrawTime == 0 )
			{
				mv->SetFloatValue( 1.0f );
			}
			else
			{
				mv->SetFloatValue( pp_motionblur_addalpha.GetFloat() );
			}
		}

		materials->SetRenderTarget( pMotionBlur );
		materials->DrawScreenSpaceQuad( pMatScreen );

		// Set the next draw time according to the convar
		fNextDrawTime = gpGlobals->curtime + pp_motionblur_time.GetFloat();
	}
 
	// Set the alpha
	mv = pMatScreen->FindVar( "$alpha", &found, false );
	if (found)
	{
		mv->SetFloatValue( pp_motionblur_drawalpha.GetFloat() );
	}

	// Set the texture to our buffer
	mv = pMatScreen->FindVar( "$basetexture", &found, false );
	if (found)
	{
		pOriginalTexture = mv->GetTextureValue();
		mv->SetTextureValue( pMotionBlur );
	}

	// Pretend we were never here, set everything back
	materials->SetRenderTarget( pOriginalRenderTarget );
	materials->DrawScreenSpaceQuad( pMatScreen );
	
      // Set our texture back to _rt_FullFrameFB
	if (found)
	{
		mv->SetTextureValue( pOriginalTexture );
	}

	materials->DepthRange( 0.0f, 1.0f );
	materials->MatrixMode( MATERIAL_PROJECTION );
	materials->PopMatrix();
	materials->MatrixMode( MATERIAL_VIEW );
	materials->PopMatrix();
}

This should all make sense.

Now add this to just before // Draw the 2D graphics at around line 3540 in view_scene.cpp

DoMotionBlur();

Open up view_scene.h and put this at the end of file before #endif // VIEW_SCENE_H

inline void UpdateScreenEffectTexture( int textureIndex )
{
	ITexture *pTexture = GetFullFrameFrameBufferTexture( textureIndex );
	materials->CopyRenderTargetToTexture( pTexture );
	materials->SetFrameBufferCopyTexture( pTexture, textureIndex );
}

Lastly open up viewrender.h and add this line after RenderViewEx at around line 170

void CViewRender::DoMotionBlur( void );

Single Player

If you're working on a Single Player Mod, you may have found that the front buffer wont update on a map change, or player death, this is because when you change the map, the gpGlobals->curtime variable resets to 0.0 seconds, but your fNextDrawTime retains its value.

So when the blur performs the check:

if ( fNextDrawTime < gpGlobals->curtime )

It will not return true until gpGlobals->curtime catches up - so if you played for 30 mins on the last map, the blur will start working 30 minutes into the new map. To do this you need to reset your fNextDrawTime on a map change by using the hack below, or don't use this check at all.

if ( fNextDrawTime - gpGlobals->curtime > 1.0f)
{
  	fNextDrawTime = 0.0f;
}

This code sits above this line

if( gpGlobals->curtime >= fNextDrawTime ) 

Material Files

That should do it. You need to add a material file called frontbuffer.vmt in your materials folder - although you could probably use an existing one. Here's an example:

 "UnlitGeneric"
 {
 	"$basetexture" "_rt_FullFrameFB"
 	"$ignorez"		1
 }