Add initial splatting support

git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@10282 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
auria 2011-11-30 16:56:04 +00:00
parent 83527e9146
commit 47d0e01f12
4 changed files with 110 additions and 0 deletions

View File

@ -0,0 +1,14 @@
uniform sampler2D tex_layout;
uniform sampler2D tex_detail0;
uniform sampler2D tex_detail1;
void main()
{
vec4 layout = texture2D(tex_layout, gl_TexCoord[0].st);
vec4 detail0 = texture2D(tex_detail0, gl_TexCoord[1].st);
vec4 detail1 = texture2D(tex_detail1, gl_TexCoord[1].st);
gl_FragColor = layout.r * detail0 + (1.0 - layout.r) * detail1;
}

View File

@ -0,0 +1,7 @@
void main()
{
gl_TexCoord[0] = gl_MultiTexCoord0;
gl_TexCoord[1] = gl_MultiTexCoord1;
gl_Position = ftransform();
}

View File

@ -65,6 +65,30 @@ public:
}
};
//-----------------------------------------------------------------------------
class SplattingProvider : public video::IShaderConstantSetCallBack
{
public:
LEAK_CHECK()
virtual void OnSetConstants(
irr::video::IMaterialRendererServices *services,
s32 userData)
{
// Irrlicht knows this is actually a GLint and makes the conversion
int tex_layout = 0;
services->setPixelShaderConstant("tex_layout", (float*)&tex_layout, 1);
// Irrlicht knows this is actually a GLint and makes the conversion
int tex_detail0 = 1;
services->setPixelShaderConstant("tex_detail0", (float*)&tex_detail0, 1);
// Irrlicht knows this is actually a GLint and makes the conversion
int tex_detail1 = 2;
services->setPixelShaderConstant("tex_detail1", (float*)&tex_detail1, 1);
}
};
//-----------------------------------------------------------------------------
/** Create a new material using the parameters specified in the xml file.
@ -189,6 +213,13 @@ Material::Material(const XMLNode *node, int index)
s.c_str());
}
node->get("splatting", &m_splatting);
if (m_splatting)
{
node->get("splatting-texture-1", &m_splatting_texture_1);
node->get("splatting-texture-2", &m_splatting_texture_2);
}
// Terrain-specifc sound effect
const unsigned int children_count = node->getNumNodes();
for (unsigned int i=0; i<children_count; i++)
@ -280,6 +311,8 @@ void Material::init(unsigned int index)
m_parallax_map = false;
m_is_heightmap = false;
m_normal_map_provider = NULL;
m_splatting_provider = NULL;
m_splatting = NULL;
for (int n=0; n<EMIT_KINDS_COUNT; n++)
{
@ -340,6 +373,11 @@ Material::~Material()
m_normal_map_provider->drop();
m_normal_map_provider = NULL;
}
if (m_splatting_provider != NULL)
{
m_splatting_provider->drop();
m_splatting_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
@ -613,6 +651,44 @@ void Material::setMaterialProperties(video::SMaterial *m)
m->SpecularColor.set(0,0,0,0);
modes++;
}
if (m_splatting)
{
IVideoDriver* video_driver = irr_driver->getVideoDriver();
if (video_driver->queryFeature(video::EVDF_ARB_GLSL) &&
video_driver->queryFeature(video::EVDF_PIXEL_SHADER_2_0) &&
video_driver->queryFeature(video::EVDF_RENDER_TO_TARGET))
{
ITexture* tex = irr_driver->getTexture(m_splatting_texture_1);
m->setTexture(1, tex);
tex = irr_driver->getTexture(m_splatting_texture_2);
m->setTexture(2, tex);
if (m_splatting_provider == NULL)
{
m_splatting_provider = new SplattingProvider();
}
// Material and shaders
IGPUProgrammingServices* gpu =
video_driver->getGPUProgrammingServices();
s32 material_type = gpu->addHighLevelShaderMaterialFromFiles(
(file_manager->getDataDir() +
"shaders/splatting.vert").c_str(),
"main",
video::EVST_VS_2_0,
(file_manager->getDataDir() +
"shaders/splatting.frag").c_str(),
"main",
video::EPST_PS_2_0,
m_splatting_provider,
video::EMT_SOLID_2_LAYER );
m->MaterialType = (E_MATERIAL_TYPE)material_type;
}
else
{
// TODO: we need a sane fallback when splatting is not available!
}
}
if (modes > 1)
{

View File

@ -39,6 +39,7 @@ class SFXBase;
class ParticleKind;
class NormalMapProvider;
class SplattingProvider;
/**
* \ingroup graphics
@ -161,9 +162,21 @@ private:
std::string m_mask;
/** Whether to use splatting */
bool m_splatting;
/** If m_splatting is true, indicates the first splatting texture */
std::string m_splatting_texture_1;
/** If m_splatting is true, indicates the second splatting texture */
std::string m_splatting_texture_2;
/** Only used if normal maps are used */
NormalMapProvider* m_normal_map_provider;
/** Only used if splatting is used */
SplattingProvider* m_splatting_provider;
void init (unsigned int index);
void install (bool is_full_path=false);
void initCustomSFX(const XMLNode *sfx);