terrain colourmap

This commit is contained in:
scrawl 2012-07-14 11:13:38 +02:00
parent d2fbb11475
commit 16c2ea3a75
5 changed files with 49 additions and 10 deletions

View file

@ -191,6 +191,9 @@ namespace MWRender
y*(mLandSize-1), y*(mLandSize-1),
mLandSize); mLandSize);
mActiveProfile->setGlobalColourMapEnabled(true);
mActiveProfile->setGlobalColourMap (terrain, vertex->getName());
//this is a hack to get around the fact that Ogre seems to //this is a hack to get around the fact that Ogre seems to
//corrupt the global colour map leading to rendering errors //corrupt the global colour map leading to rendering errors
//MaterialPtr mat = terrain->getMaterial(); //MaterialPtr mat = terrain->getMaterial();

View file

@ -31,6 +31,7 @@ namespace MWRender
TerrainMaterial::Profile::Profile(Ogre::TerrainMaterialGenerator* parent, const Ogre::String& name, const Ogre::String& desc) TerrainMaterial::Profile::Profile(Ogre::TerrainMaterialGenerator* parent, const Ogre::String& name, const Ogre::String& desc)
: Ogre::TerrainMaterialGenerator::Profile(parent, name, desc) : Ogre::TerrainMaterialGenerator::Profile(parent, name, desc)
, mGlobalColourMap(false)
{ {
} }
@ -56,11 +57,17 @@ namespace MWRender
createPass(); createPass();
return Ogre::MaterialManager::getSingleton().getByName(matName); return Ogre::MaterialManager::getSingleton().getByName(matName);
}
/* void TerrainMaterial::Profile::setGlobalColourMapEnabled (bool enabled)
Ogre::MaterialPtr m = Ogre::MaterialManager::getSingleton().create(matName, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME); {
return m; mGlobalColourMap = enabled;
*/ mParent->_markChanged();
}
void TerrainMaterial::Profile::setGlobalColourMap (Ogre::Terrain* terrain, const std::string& name)
{
sh::Factory::getInstance ().setTextureAlias (terrain->getMaterialName () + "_colourMap", name);
} }
int TerrainMaterial::Profile::getLayersPerPass () const int TerrainMaterial::Profile::getLayersPerPass () const
@ -76,6 +83,11 @@ namespace MWRender
p->setProperty ("vertex_program", sh::makeProperty<sh::StringValue>(new sh::StringValue("terrain_vertex"))); 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"))); p->setProperty ("fragment_program", sh::makeProperty<sh::StringValue>(new sh::StringValue("terrain_fragment")));
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"));
} }
Ogre::MaterialPtr TerrainMaterial::Profile::generateForCompositeMap(const Ogre::Terrain* terrain) Ogre::MaterialPtr TerrainMaterial::Profile::generateForCompositeMap(const Ogre::Terrain* terrain)

View file

@ -47,10 +47,6 @@ namespace MWRender
class Profile : public Ogre::TerrainMaterialGenerator::Profile class Profile : public Ogre::TerrainMaterialGenerator::Profile
{ {
protected:
Ogre::TerrainMaterialGenerator* mParent;
Ogre::String mName;
Ogre::String mDesc;
public: public:
Profile(Ogre::TerrainMaterialGenerator* parent, const Ogre::String& name, const Ogre::String& desc); Profile(Ogre::TerrainMaterialGenerator* parent, const Ogre::String& name, const Ogre::String& desc);
virtual ~Profile(); virtual ~Profile();
@ -69,9 +65,14 @@ namespace MWRender
virtual void requestOptions(Ogre::Terrain* terrain); virtual void requestOptions(Ogre::Terrain* terrain);
void setGlobalColourMapEnabled(bool enabled);
void setGlobalColourMap (Ogre::Terrain* terrain, const std::string& name);
private: private:
sh::MaterialInstance* mMaterial; sh::MaterialInstance* mMaterial;
bool mGlobalColourMap;
void createPass (int index=0); void createPass (int index=0);
int getLayersPerPass () const; int getLayersPerPass () const;

2
extern/shiny vendored

@ -1 +1 @@
Subproject commit 1c25aca082214beddd05fa9b8adf481c7299cf0e Subproject commit 5cf02ac0c39115fcf7f69eea7a79c9c6ad7dbd71

View file

@ -3,8 +3,11 @@
#define FOG @shGlobalSettingBool(fog) #define FOG @shGlobalSettingBool(fog)
#define MRT @shGlobalSettingBool(mrt_output) #define MRT @shGlobalSettingBool(mrt_output)
#define COLOUR_MAP @shPropertyBool(colour_map)
@shAllocatePassthrough(1, depth) @shAllocatePassthrough(1, depth)
@shAllocatePassthrough(2, UV)
#ifdef SH_VERTEX_SHADER #ifdef SH_VERTEX_SHADER
@ -26,6 +29,7 @@
shOutputPosition = shMatrixMult(viewProjMatrix, worldPos); shOutputPosition = shMatrixMult(viewProjMatrix, worldPos);
@shPassthroughAssign(depth, shOutputPosition.z); @shPassthroughAssign(depth, shOutputPosition.z);
@shPassthroughAssign(UV, uv0);
} }
@ -34,11 +38,20 @@
SH_BEGIN_PROGRAM SH_BEGIN_PROGRAM
#if COLOUR_MAP
shSampler2D(colourMap)
#endif
#if FOG
shUniform(float3, fogColor) @shAutoConstant(fogColor, fog_colour)
shUniform(float4, fogParams) @shAutoConstant(fogParams, fog_params)
#endif
@shPassthroughFragmentInputs @shPassthroughFragmentInputs
#if MRT #if MRT
shDeclareMrtOutput(1) shDeclareMrtOutput(1)
shUniform(float, far) @shAutoConstant(far, far_clip_distance)
#endif #endif
@ -47,12 +60,22 @@
{ {
float depth = @shPassthroughReceive(depth); float depth = @shPassthroughReceive(depth);
float2 UV = @shPassthroughReceive(UV);
shOutputColour(0) = float4(1,0,0,1); shOutputColour(0) = float4(1,0,0,1);
#if COLOUR_MAP
shOutputColour(0).rgb *= shSample(colourMap, UV).rgb;
#endif
#if FOG
float fogValue = shSaturate((depth - fogParams.y) * fogParams.w);
shOutputColour(0).xyz = shLerp (shOutputColour(0).xyz, fogColor, fogValue);
#endif
#if MRT #if MRT
//shOutputColour(1) = float4(1,1,1,1); shOutputColour(1) = float4(depth / far,1,1,1);
#endif #endif
} }