Make grass speed and amplitude configurable

git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@12735 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
auria 2013-05-12 00:14:53 +00:00
parent fd54f68a92
commit 3b20637b48
3 changed files with 25 additions and 10 deletions

View File

@ -1,4 +1,5 @@
uniform float angle; uniform float angle;
uniform float amplitude;
varying vec4 coord; varying vec4 coord;
@ -6,7 +7,7 @@ void main()
{ {
gl_TexCoord[0] = gl_MultiTexCoord0; gl_TexCoord[0] = gl_MultiTexCoord0;
vec4 vertexPosition = ftransform(); //gl_ModelViewMatrix * gl_Vertex; vec4 vertexPosition = ftransform(); //gl_ModelViewMatrix * gl_Vertex;
vertexPosition += vec4(1,1,0,0) * 0.25 * gl_Color.r * sin(angle); vertexPosition += vec4(1,1,0,0) * amplitude * gl_Color.r * sin(angle);
gl_Position = vertexPosition; gl_Position = vertexPosition;
gl_FrontColor = vec4(1,1,1,1); gl_FrontColor = vec4(1,1,1,1);
gl_BackColor = vec4(1,1,1,1); gl_BackColor = vec4(1,1,1,1);

View File

@ -174,26 +174,31 @@ class GrassShaderProvider : public video::IShaderConstantSetCallBack
{ {
bool m_fog; bool m_fog;
float m_angle; float m_angle;
float m_amplitude;
float m_speed;
public: public:
LEAK_CHECK() LEAK_CHECK()
GrassShaderProvider(float amplitude, float speed)
{
m_fog = false;
m_angle = 0.0f;
m_amplitude = amplitude;
m_speed = speed;
}
void enableFog(bool enable) void enableFog(bool enable)
{ {
m_fog = enable; m_fog = enable;
} }
GrassShaderProvider()
{
m_fog = false;
m_angle = 0.0f;
}
virtual void OnSetConstants(irr::video::IMaterialRendererServices *services, virtual void OnSetConstants(irr::video::IMaterialRendererServices *services,
s32 userData) s32 userData)
{ {
m_angle += GUIEngine::getLatestDt()*0.4f; m_angle += GUIEngine::getLatestDt()*m_speed;
if (m_angle > M_PI*2) m_angle -= M_PI*2; if (m_angle > M_PI*2) m_angle -= M_PI*2;
services->setVertexShaderConstant("angle", &m_angle, 1); services->setVertexShaderConstant("angle", &m_angle, 1);
@ -203,6 +208,8 @@ public:
s32 tex = 0; s32 tex = 0;
services->setVertexShaderConstant("tex", &tex, 1); services->setVertexShaderConstant("tex", &tex, 1);
services->setVertexShaderConstant("amplitude", &m_amplitude, 1);
if (m_fog) if (m_fog)
{ {
Track* t = World::getWorld()->getTrack(); Track* t = World::getWorld()->getTrack();
@ -531,6 +538,10 @@ Material::Material(const XMLNode *node, int index, bool deprecated)
else if (s == "grass") else if (s == "grass")
{ {
m_graphical_effect = GE_GRASS; m_graphical_effect = GE_GRASS;
m_grass_speed = 0.4f;
m_grass_amplitude = 0.25f;
node->get("grass-speed", &m_grass_speed);
node->get("grass-amplitude", &m_grass_amplitude);
} }
else if (s == "none") else if (s == "none")
{ {
@ -1292,7 +1303,7 @@ void Material::setMaterialProperties(video::SMaterial *m, scene::IMeshBuffer* m
{ {
if (m_shaders[GRASS_SHADER] == NULL) if (m_shaders[GRASS_SHADER] == NULL)
{ {
m_shaders[GRASS_SHADER] = new GrassShaderProvider(); m_shaders[GRASS_SHADER] = new GrassShaderProvider(m_grass_speed, m_grass_amplitude);
} }
bool fog = World::getWorld()->getTrack()->isFogEnabled(); bool fog = World::getWorld()->getTrack()->isFogEnabled();

View File

@ -131,6 +131,9 @@ private:
/** Particles to show on touch */ /** Particles to show on touch */
std::string m_collision_particles; std::string m_collision_particles;
float m_grass_speed;
float m_grass_amplitude;
/** If the property should be ignored in the physics. Example would be /** If the property should be ignored in the physics. Example would be
* plants that a kart can just drive through. */ * plants that a kart can just drive through. */
bool m_ignore; bool m_ignore;