Integrated the motion blur in game and adjusted the parameters
git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@9349 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
parent
230ada44c2
commit
1a0c45be42
data
src
config
graphics
karts
states_screens
@ -22,7 +22,7 @@
|
||||
<div width="75%" height="50" layout="horizontal-row" >
|
||||
<label I18N="In the graphics settings" text="Graphical Effects Level" align="center"/>
|
||||
<spacer width="20" height="20"/>
|
||||
<gauge id="gfx_level" min_value="1" max_value="5" width="300" />
|
||||
<gauge id="gfx_level" min_value="1" max_value="7" width="300" />
|
||||
</div>
|
||||
|
||||
<spacer height="10" width="10"/>
|
||||
|
@ -1,22 +1,50 @@
|
||||
// motion_blur.frag
|
||||
|
||||
uniform float boost_amount;
|
||||
uniform float boost_amount; // should be in the range [0.0, 1.0]
|
||||
uniform sampler2D color_buffer;
|
||||
|
||||
#define BLUR_CENTER vec2(0.5, 0.3)
|
||||
#define BLUR_SCALE 0.1
|
||||
// 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)
|
||||
|
||||
// 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
|
||||
|
||||
// Final scaling factor
|
||||
#define BLUR_SCALE 0.2
|
||||
|
||||
// Number of samples used for blurring
|
||||
#define NB_SAMPLES 12
|
||||
|
||||
void main()
|
||||
{
|
||||
vec2 texcoords = gl_TexCoord[0].st;
|
||||
vec3 color = texture2D(color_buffer, texcoords);
|
||||
vec2 blur_dir = -BLUR_SCALE * (texcoords - BLUR_CENTER);
|
||||
|
||||
// Avoid blurring the top of the screen
|
||||
float blur_factor = (1.0-texcoords.t);
|
||||
// Sample the color buffer
|
||||
vec3 color = texture2D(color_buffer, texcoords);
|
||||
|
||||
// Compute the blur direction.
|
||||
// IMPORTANT: we don't normalize it so that it avoids a glitch around BLUR_DIR_CENTER,
|
||||
// plus it naturally scales the motion blur in a cool way :)
|
||||
vec2 blur_dir = BLUR_DIR_CENTER - texcoords;
|
||||
|
||||
// Compute the blurring factor:
|
||||
// - apply the mask
|
||||
float blur_factor = max(0.0, length(texcoords - BLUR_MASK_CENTER) - BLUR_MASK_RADIUS);
|
||||
|
||||
// - avoid blurring the top of the screen
|
||||
blur_factor *= (1.0-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;
|
||||
|
||||
// Compute the blur
|
||||
vec2 inc_vec = blur_dir / NB_SAMPLES;
|
||||
vec2 blur_texcoords = texcoords + inc_vec;
|
||||
for(int i=1 ; i < NB_SAMPLES ; i++)
|
||||
@ -25,6 +53,8 @@ void main()
|
||||
blur_texcoords += inc_vec;
|
||||
}
|
||||
color /= NB_SAMPLES;
|
||||
|
||||
gl_FragColor = vec4(color, 0.0);
|
||||
|
||||
// Keep this commented line for debugging:
|
||||
// gl_FragColor = vec4(blur_factor, blur_factor, blur_factor, 0.0);
|
||||
}
|
||||
|
@ -387,9 +387,6 @@ namespace UserConfigParams
|
||||
/** True if hardware skinning should be enabled */
|
||||
PARAM_PREFIX bool m_hw_skinning_enabled PARAM_DEFAULT( false );
|
||||
|
||||
/** True if post-processing effects should be enabled */
|
||||
PARAM_PREFIX bool m_postprocess_enabled PARAM_DEFAULT( false );
|
||||
|
||||
// not saved to file
|
||||
|
||||
// ---- Networking
|
||||
@ -437,6 +434,9 @@ namespace UserConfigParams
|
||||
PARAM_PREFIX BoolUserConfigParam m_vsync
|
||||
PARAM_DEFAULT( BoolUserConfigParam(false, "vsync", &m_graphics_quality,
|
||||
"Whether vertical sync is enabled") );
|
||||
PARAM_PREFIX BoolUserConfigParam m_postprocess_enabled
|
||||
PARAM_DEFAULT( BoolUserConfigParam(false, "postprocess_enabled", &m_graphics_quality,
|
||||
"Whether post-processing (motion blur...) should be enabled") );
|
||||
|
||||
// ---- Misc
|
||||
PARAM_PREFIX BoolUserConfigParam m_minimal_race_gui
|
||||
|
@ -442,6 +442,10 @@ void Camera::update(float dt)
|
||||
m_camera->setTarget(current_target);
|
||||
return;
|
||||
}
|
||||
|
||||
// Apply the motion blur according to the speed of the kart
|
||||
if(UserConfigParams::m_postprocess_enabled)
|
||||
irr_driver->getPostProcessing()->setCameraSpeed(m_kart->getCurrentMaxSpeed());
|
||||
|
||||
positionCamera(dt, above_kart, cam_angle, side_way, distance, smoothing);
|
||||
} // update
|
||||
|
@ -21,13 +21,15 @@
|
||||
#include "irr_driver.hpp"
|
||||
#include "config/user_config.hpp"
|
||||
|
||||
#define MOTION_BLUR_FACTOR (1.0f/15.0f)
|
||||
#define MOTION_BLUR_OFFSET 20.0f
|
||||
|
||||
using namespace video;
|
||||
using namespace scene;
|
||||
|
||||
PostProcessing::PostProcessing()
|
||||
{
|
||||
m_boost_amount = 0.0f;
|
||||
//UserConfigParams::m_postprocess_enabled = true; // BOUM
|
||||
}
|
||||
|
||||
PostProcessing::~PostProcessing()
|
||||
@ -122,6 +124,12 @@ void PostProcessing::render()
|
||||
video_driver->drawIndexedTriangleList(&vertices[0], 6, &indices[0], 2);
|
||||
}
|
||||
|
||||
/** Set the boost amount according to the speed of the camera */
|
||||
void PostProcessing::setCameraSpeed(float cam_speed)
|
||||
{
|
||||
m_boost_amount = core::clamp(MOTION_BLUR_FACTOR * (cam_speed - MOTION_BLUR_OFFSET), 0.0f, 1.0f);
|
||||
}
|
||||
|
||||
/** Implement IShaderConstantsSetCallback. Shader constants setter for post-processing */
|
||||
void PostProcessing::OnSetConstants(video::IMaterialRendererServices *services, s32 user_data)
|
||||
{
|
||||
|
@ -54,8 +54,8 @@ public:
|
||||
/** Is the hardware able to use post-processing? */
|
||||
inline bool isSupported() const {return m_supported;}
|
||||
|
||||
/** Boost amount, used to tune the motion blur. Must be in the range 0.0 to 1.0 */
|
||||
inline void setBoostAmount(float boost_amount) {m_boost_amount = boost_amount;}
|
||||
/** Set the boost amount according to the speed of the camera */
|
||||
void setCameraSpeed(float cam_speed);
|
||||
|
||||
/** Implement IShaderConstantsSetCallback. Shader constants setter for post-processing */
|
||||
virtual void OnSetConstants(video::IMaterialRendererServices *services, s32 user_data);
|
||||
|
@ -159,7 +159,7 @@ float MaxSpeed::getSpeedIncreaseTimeLeft(unsigned int category)
|
||||
void MaxSpeed::update(float dt)
|
||||
{
|
||||
|
||||
// First comput the minimum max-speed fraction, which
|
||||
// First compute the minimum max-speed fraction, which
|
||||
// determines the overall decrease of maximum speed.
|
||||
// ---------------------------------------------------
|
||||
float f = 1.0f;
|
||||
|
@ -44,11 +44,12 @@ using namespace GUIEngine;
|
||||
DEFINE_SCREEN_SINGLETON( OptionsScreenVideo );
|
||||
|
||||
// Look-up table for GFX levels
|
||||
const bool GFX [] = {false, true, true, true, true, true};
|
||||
const int GFX_ANIM_KARTS[] = {0, 0, 1, 2, 2, 2 };
|
||||
const bool GFX_WEATHER [] = {false, false, false, false, true, true};
|
||||
const bool GFX_ANTIALIAS [] = {false, false, false, false, false, true};
|
||||
const int GFX_LEVEL_AMOUNT = 6;
|
||||
const bool GFX [] = {false, true, true, true, true, true, true};
|
||||
const int GFX_ANIM_KARTS [] = {0, 0, 1, 2, 2, 2, 2};
|
||||
const bool GFX_WEATHER [] = {false, false, false, false, true, true, true};
|
||||
const bool GFX_ANTIALIAS [] = {false, false, false, false, false, true, true};
|
||||
const bool GFX_POSTPROCESSING [] = {false, false, false, false, false, false, true};
|
||||
const int GFX_LEVEL_AMOUNT = 7;
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
@ -252,7 +253,8 @@ void OptionsScreenVideo::init()
|
||||
if (UserConfigParams::m_show_steering_animations == GFX_ANIM_KARTS[l] &&
|
||||
UserConfigParams::m_graphical_effects == GFX[l] &&
|
||||
UserConfigParams::m_weather_effects == GFX_WEATHER[l] &&
|
||||
UserConfigParams::m_fullscreen_antialiasing == GFX_ANTIALIAS[l])
|
||||
UserConfigParams::m_fullscreen_antialiasing == GFX_ANTIALIAS[l] &&
|
||||
UserConfigParams::m_postprocess_enabled == GFX_POSTPROCESSING[l])
|
||||
{
|
||||
gfx->setValue(l+1);
|
||||
break;
|
||||
@ -303,6 +305,8 @@ void OptionsScreenVideo::updateTooltip()
|
||||
(UserConfigParams::m_show_steering_animations == 1 ? me : none));
|
||||
//I18N: in graphical options
|
||||
tooltip = tooltip + L"\n" + _("Anti-aliasing (requires restart) : %s", UserConfigParams::m_fullscreen_antialiasing ? enabled : disabled);
|
||||
//I18N: in graphical options
|
||||
tooltip = tooltip + L"\n" + _("Post-processing (motion blur) : %s", UserConfigParams::m_postprocess_enabled ? enabled : disabled);
|
||||
gfx->setTooltip(tooltip);
|
||||
}
|
||||
|
||||
@ -357,6 +361,7 @@ void OptionsScreenVideo::eventCallback(Widget* widget, const std::string& name,
|
||||
UserConfigParams::m_graphical_effects = GFX[level-1];
|
||||
UserConfigParams::m_weather_effects = GFX_WEATHER[level-1];
|
||||
UserConfigParams::m_fullscreen_antialiasing = GFX_ANTIALIAS[level-1];
|
||||
UserConfigParams::m_postprocess_enabled = GFX_POSTPROCESSING[level-1];
|
||||
|
||||
updateTooltip();
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user