2012-02-27 18:44:52 +00:00
|
|
|
#include "terrainmaterial.hpp"
|
|
|
|
|
2012-07-13 04:16:55 +00:00
|
|
|
#include <OgreTerrain.h>
|
2012-03-01 13:35:39 +00:00
|
|
|
|
2012-07-13 04:16:55 +00:00
|
|
|
#include <extern/shiny/Main/Factory.hpp>
|
2012-04-13 13:09:38 +00:00
|
|
|
|
2012-02-27 18:44:52 +00:00
|
|
|
|
2012-07-13 04:16:55 +00:00
|
|
|
namespace MWRender
|
|
|
|
{
|
2012-02-27 18:44:52 +00:00
|
|
|
|
2012-07-13 04:16:55 +00:00
|
|
|
TerrainMaterial::TerrainMaterial()
|
|
|
|
{
|
|
|
|
mLayerDecl.samplers.push_back(Ogre::TerrainLayerSampler("albedo_specular", Ogre::PF_BYTE_RGBA));
|
|
|
|
//mLayerDecl.samplers.push_back(Ogre::TerrainLayerSampler("normal_height", Ogre::PF_BYTE_RGBA));
|
2012-02-27 18:44:52 +00:00
|
|
|
|
2012-07-13 04:16:55 +00:00
|
|
|
mLayerDecl.elements.push_back(
|
|
|
|
Ogre::TerrainLayerSamplerElement(0, Ogre::TLSS_ALBEDO, 0, 3));
|
|
|
|
//mLayerDecl.elements.push_back(
|
|
|
|
// Ogre::TerrainLayerSamplerElement(0, Ogre::TLSS_SPECULAR, 3, 1));
|
|
|
|
//mLayerDecl.elements.push_back(
|
|
|
|
// Ogre::TerrainLayerSamplerElement(1, Ogre::TLSS_NORMAL, 0, 3));
|
|
|
|
//mLayerDecl.elements.push_back(
|
|
|
|
// Ogre::TerrainLayerSamplerElement(1, Ogre::TLSS_HEIGHT, 3, 1));
|
2012-02-27 18:44:52 +00:00
|
|
|
|
|
|
|
|
2012-07-13 04:16:55 +00:00
|
|
|
mProfiles.push_back(OGRE_NEW Profile(this, "SM2", "Profile for rendering on Shader Model 2 capable cards"));
|
|
|
|
setActiveProfile("SM2");
|
2012-04-11 16:53:13 +00:00
|
|
|
}
|
2012-02-27 18:44:52 +00:00
|
|
|
|
2012-07-13 04:16:55 +00:00
|
|
|
// -----------------------------------------------------------------------------------------------------------------------
|
2012-02-27 18:44:52 +00:00
|
|
|
|
2012-07-13 04:16:55 +00:00
|
|
|
TerrainMaterial::Profile::Profile(Ogre::TerrainMaterialGenerator* parent, const Ogre::String& name, const Ogre::String& desc)
|
|
|
|
: Ogre::TerrainMaterialGenerator::Profile(parent, name, desc)
|
2012-07-14 09:13:38 +00:00
|
|
|
, mGlobalColourMap(false)
|
2012-04-01 16:48:37 +00:00
|
|
|
{
|
|
|
|
}
|
2012-02-27 18:44:52 +00:00
|
|
|
|
2012-07-13 04:16:55 +00:00
|
|
|
TerrainMaterial::Profile::~Profile()
|
|
|
|
{
|
|
|
|
}
|
2012-02-27 18:44:52 +00:00
|
|
|
|
|
|
|
|
2012-07-13 04:16:55 +00:00
|
|
|
Ogre::MaterialPtr TerrainMaterial::Profile::generate(const Ogre::Terrain* terrain)
|
|
|
|
{
|
|
|
|
const Ogre::String& matName = terrain->getMaterialName();
|
2012-07-13 09:26:36 +00:00
|
|
|
|
|
|
|
sh::Factory::getInstance().destroyMaterialInstance (matName);
|
|
|
|
|
2012-07-13 04:16:55 +00:00
|
|
|
Ogre::MaterialPtr mat = Ogre::MaterialManager::getSingleton().getByName(matName);
|
|
|
|
if (!mat.isNull())
|
|
|
|
Ogre::MaterialManager::getSingleton().remove(matName);
|
2012-02-27 18:44:52 +00:00
|
|
|
|
2012-07-13 07:13:12 +00:00
|
|
|
mMaterial = sh::Factory::getInstance().createMaterialInstance (matName);
|
2012-02-27 18:44:52 +00:00
|
|
|
|
2012-07-13 07:13:12 +00:00
|
|
|
mMaterial->setProperty ("allow_fixed_function", sh::makeProperty<sh::BooleanValue>(new sh::BooleanValue(false)));
|
|
|
|
|
|
|
|
createPass();
|
2012-02-27 18:44:52 +00:00
|
|
|
|
2012-07-13 04:16:55 +00:00
|
|
|
return Ogre::MaterialManager::getSingleton().getByName(matName);
|
2012-07-14 09:13:38 +00:00
|
|
|
}
|
2012-07-13 09:26:36 +00:00
|
|
|
|
2012-07-14 09:13:38 +00:00
|
|
|
void TerrainMaterial::Profile::setGlobalColourMapEnabled (bool enabled)
|
|
|
|
{
|
|
|
|
mGlobalColourMap = enabled;
|
|
|
|
mParent->_markChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
void TerrainMaterial::Profile::setGlobalColourMap (Ogre::Terrain* terrain, const std::string& name)
|
|
|
|
{
|
|
|
|
sh::Factory::getInstance ().setTextureAlias (terrain->getMaterialName () + "_colourMap", name);
|
2012-07-13 04:16:55 +00:00
|
|
|
}
|
2012-02-27 18:44:52 +00:00
|
|
|
|
2012-07-13 07:13:12 +00:00
|
|
|
int TerrainMaterial::Profile::getLayersPerPass () const
|
|
|
|
{
|
|
|
|
return 10;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TerrainMaterial::Profile::createPass (int index)
|
|
|
|
{
|
|
|
|
int layerOffset = index * getLayersPerPass();
|
|
|
|
|
|
|
|
sh::MaterialInstancePass* p = mMaterial->createPass ();
|
|
|
|
|
|
|
|
p->setProperty ("vertex_program", sh::makeProperty<sh::StringValue>(new sh::StringValue("terrain_vertex")));
|
|
|
|
p->setProperty ("fragment_program", sh::makeProperty<sh::StringValue>(new sh::StringValue("terrain_fragment")));
|
2012-07-14 09:13:38 +00:00
|
|
|
|
|
|
|
p->mShaderProperties.setProperty ("colour_map", sh::makeProperty<sh::BooleanValue>(new sh::BooleanValue(mGlobalColourMap)));
|
|
|
|
|
|
|
|
sh::MaterialInstanceTextureUnit* colourMap = p->createTextureUnit ("colourMap");
|
|
|
|
colourMap->setProperty ("texture_alias", sh::makeProperty(mMaterial->getName() + "_colourMap"));
|
2012-07-13 07:13:12 +00:00
|
|
|
}
|
|
|
|
|
2012-07-13 04:16:55 +00:00
|
|
|
Ogre::MaterialPtr TerrainMaterial::Profile::generateForCompositeMap(const Ogre::Terrain* terrain)
|
|
|
|
{
|
|
|
|
throw std::runtime_error ("composite map not supported");
|
|
|
|
}
|
2012-02-27 18:44:52 +00:00
|
|
|
|
2012-07-13 04:16:55 +00:00
|
|
|
Ogre::uint8 TerrainMaterial::Profile::getMaxLayers(const Ogre::Terrain* terrain) const
|
|
|
|
{
|
|
|
|
return 32;
|
|
|
|
}
|
2012-02-27 18:44:52 +00:00
|
|
|
|
2012-07-13 04:16:55 +00:00
|
|
|
void TerrainMaterial::Profile::updateParams(const Ogre::MaterialPtr& mat, const Ogre::Terrain* terrain)
|
|
|
|
{
|
|
|
|
}
|
2012-02-27 18:44:52 +00:00
|
|
|
|
2012-07-13 04:16:55 +00:00
|
|
|
void TerrainMaterial::Profile::updateParamsForCompositeMap(const Ogre::MaterialPtr& mat, const Ogre::Terrain* terrain)
|
|
|
|
{
|
|
|
|
}
|
2012-02-27 18:44:52 +00:00
|
|
|
|
2012-07-13 04:16:55 +00:00
|
|
|
void TerrainMaterial::Profile::requestOptions(Ogre::Terrain* terrain)
|
|
|
|
{
|
|
|
|
terrain->_setMorphRequired(true);
|
|
|
|
terrain->_setNormalMapRequired(false);
|
|
|
|
terrain->_setLightMapRequired(false);
|
|
|
|
terrain->_setCompositeMapRequired(false);
|
|
|
|
}
|
2012-02-27 18:44:52 +00:00
|
|
|
|
|
|
|
}
|