motion blur or slow motion

Discuss programming topics for the various GPL'd game engine sources.
Post Reply
franqutrass
Posts: 69
Joined: Wed Dec 30, 2009 6:29 pm
Location: peru
Contact:

motion blur or slow motion

Post by franqutrass »

how I can add "motion blur" or "slow motion" an engine of quake.
hello
Baker
Posts: 3666
Joined: Tue Mar 14, 2006 5:15 am

Post by Baker »

See Qrack's nail trails or read this for the basic idea ...

MH tutorial on simple motion blurs ...

http://forums.inside3d.com/viewtopic.php?p=16012
The night is young. How else can I annoy the world before sunsrise? 8) Inquisitive minds want to know ! And if they don't -- well like that ever has stopped me before ..
r00k
Posts: 1111
Joined: Sat Nov 13, 2004 10:39 pm

Post by r00k »

In gl_rmain.c, add this function above R_RenderView,

Code: Select all

void R_RenderSceneBlur (float alpha, GLenum format)
{
	extern int	sceneblur_texture;
	int vwidth = 2, vheight = 2;
	float vs, vt;

	if (alpha < 0.1)
		alpha = 0.1;

	while (vwidth < glwidth)
	{
		vwidth *= 2;
	}
	while (vheight < glheight)
	{
		vheight *= 2;
	}

	glViewport (glx, gly, glwidth, glheight);

	GL_Bind(sceneblur_texture);

	// go 2d
	glMatrixMode(GL_PROJECTION);
	glPushMatrix();
	glLoadIdentity ();
	glOrtho  (0, glwidth, 0, glheight, -99999, 99999);
	glMatrixMode(GL_MODELVIEW);
	glPushMatrix();
	glLoadIdentity ();

	vs = ((float)glwidth / vwidth);
	vt = ((float)glheight / vheight) ;

	glDisable (GL_DEPTH_TEST);
	glDisable (GL_CULL_FACE);
	glEnable(GL_BLEND);

	glColor4f(1, 1, 1, alpha);
	glBegin(GL_QUADS);
		glTexCoord2f(0, 0);
		glVertex2f(0, 0);
		glTexCoord2f(vs , 0);
		glVertex2f(glwidth, 0);
		glTexCoord2f(vs , vt);
		glVertex2f(glwidth, glheight);
		glTexCoord2f(0, vt);
		glVertex2f(0, glheight);
	glEnd();

	glEnable(GL_DEPTH_TEST);
	glDepthMask(1);
	glColor3f (1,1,1);   
    glDisable (GL_BLEND);   

	glMatrixMode(GL_PROJECTION);
	glPopMatrix();		
	glMatrixMode(GL_MODELVIEW);
	glPopMatrix();		

	glCopyTexImage2D(GL_TEXTURE_2D, 0, format, glx, gly, vwidth, vheight, 0);


	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);	  	
}
then in R_RenderView, after R_DrawViewModel() add

Code: Select all

				if (gl_motion_blur.value)
				{
					R_RenderSceneBlur (gl_motion_blur.value, GL_RGB);
				}
u have to make your oen cvar for motion blur of course...

The blur value sets the percentage of the alpha, depends on your FPS in-game, so around 75fps, 0.2 - 0.3 seems acceptable. 0.85, and you are in a drunk haze!


EDIT: Oh just looked at MH's code, may work faster.
Post Reply