Update overworld with 'force fields' to guard the entrance to challenges as discussed. I <3 my new shader\!
git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@10491 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
parent
5c7d45576e
commit
f23f537620
9
data/shaders/bubble.frag
Normal file
9
data/shaders/bubble.frag
Normal file
@ -0,0 +1,9 @@
|
||||
|
||||
|
||||
uniform sampler2D main_texture;
|
||||
varying vec2 uv;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_FragColor = texture2D(main_texture, uv);
|
||||
}
|
15
data/shaders/bubble.vert
Normal file
15
data/shaders/bubble.vert
Normal file
@ -0,0 +1,15 @@
|
||||
// Creates a bubble (wave) effect by distorting the texture depending on time
|
||||
|
||||
uniform float time;
|
||||
varying vec2 uv;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_TexCoord[0] = gl_MultiTexCoord0;
|
||||
gl_Position = ftransform();
|
||||
|
||||
float delta_x = cos(time*3.0) * sin( 4.0 * gl_TexCoord[0].st.s * 6.28318531 );
|
||||
float delta_y = cos(time*2.0) * sin( 3.0 * gl_TexCoord[0].st.t * 6.28318531 );
|
||||
|
||||
uv = gl_TexCoord[0].st + vec2(0.02*delta_x, 0.02*delta_y);
|
||||
}
|
@ -120,6 +120,30 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
class BubbleEffectProvider : public video::IShaderConstantSetCallBack
|
||||
{
|
||||
irr::u32 initial_time;
|
||||
|
||||
public:
|
||||
LEAK_CHECK()
|
||||
|
||||
BubbleEffectProvider()
|
||||
{
|
||||
initial_time = irr_driver->getDevice()->getTimer()->getRealTime();
|
||||
}
|
||||
|
||||
virtual void OnSetConstants(
|
||||
irr::video::IMaterialRendererServices *services,
|
||||
s32 userData)
|
||||
{
|
||||
float time = (irr_driver->getDevice()->getTimer()->getRealTime() - initial_time) / 1000.0f;
|
||||
services->setVertexShaderConstant("time", &time, 1);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/** Create a new material using the parameters specified in the xml file.
|
||||
* \param node Node containing the parameters for this material.
|
||||
@ -230,12 +254,16 @@ Material::Material(const XMLNode *node, int index)
|
||||
}
|
||||
|
||||
s="";
|
||||
node->get("graphical-effect", &s );
|
||||
node->get("graphical-effect", &s);
|
||||
|
||||
if (s == "water")
|
||||
{
|
||||
m_graphical_effect = GE_WATER;
|
||||
}
|
||||
else if (s == "bubble")
|
||||
{
|
||||
m_graphical_effect = GE_BUBBLE;
|
||||
}
|
||||
else if (s == "none")
|
||||
{
|
||||
}
|
||||
@ -365,7 +393,8 @@ void Material::init(unsigned int index)
|
||||
m_alpha_to_coverage = false;
|
||||
m_normal_map_provider = NULL;
|
||||
m_splatting_provider = NULL;
|
||||
m_splatting = NULL;
|
||||
m_bubble_provider = NULL;
|
||||
m_splatting = false;
|
||||
|
||||
for (int n=0; n<EMIT_KINDS_COUNT; n++)
|
||||
{
|
||||
@ -431,6 +460,11 @@ Material::~Material()
|
||||
m_splatting_provider->drop();
|
||||
m_splatting_provider = NULL;
|
||||
}
|
||||
if (m_bubble_provider != NULL)
|
||||
{
|
||||
m_bubble_provider->drop();
|
||||
m_bubble_provider = NULL;
|
||||
}
|
||||
|
||||
// If a special sfx is installed (that isn't part of stk itself), the
|
||||
// entry needs to be removed from the sfx_manager's mapping, since other
|
||||
@ -764,6 +798,43 @@ void Material::setMaterialProperties(video::SMaterial *m)
|
||||
m->MaterialType = (E_MATERIAL_TYPE)material_type;
|
||||
}
|
||||
|
||||
if (m_graphical_effect == GE_BUBBLE)
|
||||
{
|
||||
IVideoDriver* video_driver = irr_driver->getVideoDriver();
|
||||
if (UserConfigParams::m_pixel_shaders &&
|
||||
video_driver->queryFeature(video::EVDF_ARB_GLSL) &&
|
||||
video_driver->queryFeature(video::EVDF_PIXEL_SHADER_2_0))
|
||||
{
|
||||
if (m_bubble_provider == NULL)
|
||||
{
|
||||
m_bubble_provider = new BubbleEffectProvider();
|
||||
}
|
||||
|
||||
// Material and shaders
|
||||
IGPUProgrammingServices* gpu = video_driver->getGPUProgrammingServices();
|
||||
s32 material_type = gpu->addHighLevelShaderMaterialFromFiles(
|
||||
(file_manager->getDataDir() + "shaders/bubble.vert").c_str(),
|
||||
"main",
|
||||
video::EVST_VS_2_0,
|
||||
(file_manager->getDataDir() + "shaders/bubble.frag").c_str(),
|
||||
"main",
|
||||
video::EPST_PS_2_0,
|
||||
m_bubble_provider,
|
||||
(m_alpha_blending ?
|
||||
video::EMT_TRANSPARENT_ALPHA_CHANNEL :
|
||||
video::EMT_SOLID)
|
||||
);
|
||||
m->MaterialType = (E_MATERIAL_TYPE)material_type;
|
||||
|
||||
// alpha blending and bubble shading can work together so when both are enabled
|
||||
// don't increment the 'modes' counter to not get the 'too many modes' warning
|
||||
if (!m_alpha_blending)
|
||||
{
|
||||
modes++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (modes > 1)
|
||||
{
|
||||
std::cerr << "[Material::setMaterialProperties] More than one main "
|
||||
|
@ -39,6 +39,7 @@ class ParticleKind;
|
||||
|
||||
class NormalMapProvider;
|
||||
class SplattingProvider;
|
||||
class BubbleEffectProvider;
|
||||
|
||||
/**
|
||||
* \ingroup graphics
|
||||
@ -46,7 +47,11 @@ class SplattingProvider;
|
||||
class Material : public NoCopy
|
||||
{
|
||||
public:
|
||||
enum GraphicalEffect {GE_NONE, GE_WATER};
|
||||
enum GraphicalEffect {GE_NONE,
|
||||
/** Water splash effect. This is set on the seabed material. */
|
||||
GE_WATER,
|
||||
/** Effect where the UV texture is moved in a wave pattern */
|
||||
GE_BUBBLE};
|
||||
|
||||
enum ParticleConditions
|
||||
{
|
||||
@ -95,7 +100,7 @@ private:
|
||||
bool m_add;
|
||||
|
||||
bool m_fog;
|
||||
|
||||
|
||||
ParticleKind* m_particles_effects[EMIT_KINDS_COUNT];
|
||||
|
||||
/** For normal maps */
|
||||
@ -185,6 +190,9 @@ private:
|
||||
/** Only used if splatting is used */
|
||||
SplattingProvider* m_splatting_provider;
|
||||
|
||||
/** Only used if bubble effect is enabled */
|
||||
BubbleEffectProvider* m_bubble_provider;
|
||||
|
||||
void init (unsigned int index);
|
||||
void install (bool is_full_path=false);
|
||||
void initCustomSFX(const XMLNode *sfx);
|
||||
|
Loading…
x
Reference in New Issue
Block a user