Enabled motion blur shader in split screen multiplayer.

git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@12552 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
hikerstk
2013-03-14 21:04:48 +00:00
parent a14a9df3f1
commit 5445cec7ba
9 changed files with 281 additions and 157 deletions

View File

@@ -1,17 +1,26 @@
// motion_blur.frag
uniform float boost_amount; // should be in the range [0.0, 1.0]
// The actual boost amount (which linearly scales the blur to be shown).
// should be in the range [0.0, 1.0], though a larger value might make
// the blurring too string. Atm we are using [0, 0.5].
uniform float boost_amount;
// The color buffer to use.
uniform sampler2D color_buffer;
// The blur direction points to the following center (we work in [0, 1]x[0, 1] coordinates):
#define BLUR_DIR_CENTER vec2(0.5, 0.7)
// Center (in texture coordinates) at which the kart is. A small circle
// around this center is not blurred (see mask_radius below)
uniform vec2 center;
// There is a mask around the character so that it doesn't get blurred
#define BLUR_MASK_CENTER vec2(0.5, 0.2)
#define BLUR_MASK_RADIUS 0.15
// The direction to which the blurring aims at
uniform vec2 direction;
// Final scaling factor
#define BLUR_SCALE 0.2
// Radius of mask around the character in which no blurring happens
// so that the kart doesn't get blurred.
uniform float mask_radius;
// Maximum height of texture used
uniform float max_tex_height;
// Number of samples used for blurring
#define NB_SAMPLES 12
@@ -23,24 +32,29 @@ void main()
// Sample the color buffer
vec3 color = texture2D(color_buffer, texcoords).rgb;
// If no motion blur is needed, don't do any of the blur computation,
// just return the color from the texture.
if(boost_amount==0)
{
gl_FragColor = vec4(color, 1.0);
return;
}
// Compute the blur direction.
// IMPORTANT: we don't normalize it so that it avoids a glitch around BLUR_DIR_CENTER,
// IMPORTANT: we don't normalize it so that it avoids a glitch around 'center',
// plus it naturally scales the motion blur in a cool way :)
vec2 blur_dir = BLUR_DIR_CENTER - texcoords;
vec2 blur_dir = direction - texcoords;
// Compute the blurring factor:
// - apply the mask
float blur_factor = max(0.0, length(texcoords - BLUR_MASK_CENTER) - BLUR_MASK_RADIUS);
// - apply the mask, i.e. no blurring in a small circle around the kart
float blur_factor = max(0.0, length(texcoords - center) - mask_radius);
// - avoid blurring the top of the screen
blur_factor *= (1.0-texcoords.t);
blur_factor *= (max_tex_height - texcoords.t);
// - apply the boost amount
blur_factor *= boost_amount;
// - apply a final scaling factor
blur_factor *= BLUR_SCALE;
// Scale the blur direction
blur_dir *= blur_factor;
@@ -56,5 +70,5 @@ void main()
gl_FragColor = vec4(color, 1.0);
// Keep this commented line for debugging:
// gl_FragColor = vec4(blur_factor, blur_factor, blur_factor, 0.0);
//gl_FragColor = vec4(blur_factor, blur_factor, blur_factor, 0.0);
}

View File

@@ -2,6 +2,6 @@
void main()
{
gl_TexCoord[0].st = vec2(gl_MultiTexCoord0.s, 1.0-gl_MultiTexCoord0.t);
gl_TexCoord[0].st = vec2(gl_MultiTexCoord0.s, gl_MultiTexCoord0.t);
gl_Position = gl_Vertex;
}