Add grass shader for samuncle
git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@12730 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
parent
bb2c41b413
commit
3eb6c034d0
35
data/shaders/grass.frag
Normal file
35
data/shaders/grass.frag
Normal file
@ -0,0 +1,35 @@
|
||||
uniform vec4 fogColor;
|
||||
uniform float fogFrom;
|
||||
uniform float fogTo;
|
||||
uniform int fog;
|
||||
uniform sampler2D tex;
|
||||
varying vec4 coord;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 color = texture2D(tex, gl_TexCoord[0].st);
|
||||
vec4 solidColor = vec4(color.r, color.g, color.b, 1);
|
||||
|
||||
if (fog == 1)
|
||||
{
|
||||
if (coord.z > fogTo)
|
||||
{
|
||||
gl_FragColor = fogColor;
|
||||
}
|
||||
else if (coord.z > fogFrom)
|
||||
{
|
||||
float fogIntensity = (coord.z - fogFrom) / (fogTo - fogFrom);
|
||||
vec4 color2 = fogIntensity*fogColor + (1.0 - fogIntensity)*solidColor;
|
||||
color2.a = color.a;
|
||||
gl_FragColor = color2;
|
||||
}
|
||||
else
|
||||
{
|
||||
gl_FragColor = color;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
gl_FragColor = color;
|
||||
}
|
||||
}
|
14
data/shaders/grass.vert
Normal file
14
data/shaders/grass.vert
Normal file
@ -0,0 +1,14 @@
|
||||
uniform float angle;
|
||||
varying vec4 coord;
|
||||
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_TexCoord[0] = gl_MultiTexCoord0;
|
||||
vec4 vertexPosition = ftransform(); //gl_ModelViewMatrix * gl_Vertex;
|
||||
vertexPosition += vec4(1,1,0,0) * 0.25 * gl_Color.r * sin(angle);
|
||||
gl_Position = vertexPosition;
|
||||
gl_FrontColor = vec4(1,1,1,1);
|
||||
gl_BackColor = vec4(1,1,1,1);
|
||||
coord = vertexPosition;
|
||||
}
|
@ -168,6 +168,59 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
class GrassShaderProvider : public video::IShaderConstantSetCallBack
|
||||
{
|
||||
bool m_fog;
|
||||
float m_angle;
|
||||
|
||||
public:
|
||||
LEAK_CHECK()
|
||||
|
||||
void enableFog(bool enable)
|
||||
{
|
||||
m_fog = enable;
|
||||
}
|
||||
|
||||
|
||||
GrassShaderProvider()
|
||||
{
|
||||
m_fog = false;
|
||||
m_angle = 0.0f;
|
||||
}
|
||||
|
||||
virtual void OnSetConstants(irr::video::IMaterialRendererServices *services,
|
||||
s32 userData)
|
||||
{
|
||||
m_angle += GUIEngine::getLatestDt()*0.4f;
|
||||
if (m_angle > M_PI*2) m_angle -= M_PI*2;
|
||||
services->setVertexShaderConstant("angle", &m_angle, 1);
|
||||
|
||||
int fog = (m_fog ? 1 : 0);
|
||||
services->setVertexShaderConstant("fog", &fog, 1);
|
||||
|
||||
s32 tex = 0;
|
||||
services->setVertexShaderConstant("tex", &tex, 1);
|
||||
|
||||
if (m_fog)
|
||||
{
|
||||
Track* t = World::getWorld()->getTrack();
|
||||
|
||||
float fogStart = t->getFogStart();
|
||||
services->setPixelShaderConstant("fogFrom", &fogStart, 1);
|
||||
|
||||
float fogEnd = t->getFogEnd();
|
||||
services->setPixelShaderConstant("fogTo", &fogEnd, 1);
|
||||
|
||||
video::SColor fogColor = t->getFogColor();
|
||||
float fogColorVec[] = {fogColor.getRed()/255.0f,
|
||||
fogColor.getGreen()/255.0f,
|
||||
fogColor.getBlue()/255.0f, 1.0f};
|
||||
services->setVertexShaderConstant("fogColor", fogColorVec, 4);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
@ -475,6 +528,10 @@ Material::Material(const XMLNode *node, int index, bool deprecated)
|
||||
{
|
||||
m_graphical_effect = GE_BUBBLE;
|
||||
}
|
||||
else if (s == "grass")
|
||||
{
|
||||
m_graphical_effect = GE_GRASS;
|
||||
}
|
||||
else if (s == "none")
|
||||
{
|
||||
}
|
||||
@ -1226,6 +1283,36 @@ void Material::setMaterialProperties(video::SMaterial *m, scene::IMeshBuffer* m
|
||||
modes++;
|
||||
}
|
||||
|
||||
if (m_graphical_effect == GE_GRASS)
|
||||
{
|
||||
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_shaders[GRASS_SHADER] == NULL)
|
||||
{
|
||||
m_shaders[GRASS_SHADER] = new GrassShaderProvider();
|
||||
}
|
||||
|
||||
bool fog = World::getWorld()->getTrack()->isFogEnabled();
|
||||
((GrassShaderProvider*)m_shaders[GRASS_SHADER])->enableFog(fog);
|
||||
|
||||
// Material and shaders
|
||||
IGPUProgrammingServices* gpu =
|
||||
irr_driver->getVideoDriver()->getGPUProgrammingServices();
|
||||
s32 material_type = gpu->addHighLevelShaderMaterialFromFiles(
|
||||
(file_manager->getShaderDir() + "grass.vert").c_str(),
|
||||
"main", video::EVST_VS_2_0,
|
||||
(file_manager->getShaderDir() + "grass.frag").c_str(),
|
||||
"main", video::EPST_PS_2_0,
|
||||
m_shaders[GRASS_SHADER],
|
||||
video::EMT_TRANSPARENT_ALPHA_CHANNEL);
|
||||
m->MaterialType = (E_MATERIAL_TYPE)material_type;
|
||||
}
|
||||
modes++;
|
||||
}
|
||||
|
||||
if (modes > 1)
|
||||
{
|
||||
std::cerr << "[Material::setMaterialProperties] More than one main "
|
||||
|
@ -54,7 +54,9 @@ public:
|
||||
/** 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};
|
||||
GE_BUBBLE,
|
||||
/** Effect that makes grass wave as in the wind */
|
||||
GE_GRASS};
|
||||
|
||||
enum ParticleConditions
|
||||
{
|
||||
@ -81,7 +83,8 @@ private:
|
||||
WATER_SHADER,
|
||||
SPHERE_MAP,
|
||||
SHADER_COUNT,
|
||||
SPLATTING_LIGHTMAP
|
||||
SPLATTING_LIGHTMAP,
|
||||
GRASS_SHADER
|
||||
};
|
||||
|
||||
video::ITexture *m_texture;
|
||||
|
Loading…
Reference in New Issue
Block a user