terrain colourmap

actorid
scrawl 13 years ago
parent d2fbb11475
commit 16c2ea3a75

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

@ -31,6 +31,7 @@ namespace MWRender
TerrainMaterial::Profile::Profile(Ogre::TerrainMaterialGenerator* parent, const Ogre::String& name, const Ogre::String& desc)
: Ogre::TerrainMaterialGenerator::Profile(parent, name, desc)
, mGlobalColourMap(false)
{
}
@ -56,11 +57,17 @@ namespace MWRender
createPass();
return Ogre::MaterialManager::getSingleton().getByName(matName);
}
/*
Ogre::MaterialPtr m = Ogre::MaterialManager::getSingleton().create(matName, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
return m;
*/
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);
}
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 ("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)

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

2
extern/shiny vendored

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

@ -3,8 +3,11 @@
#define FOG @shGlobalSettingBool(fog)
#define MRT @shGlobalSettingBool(mrt_output)
#define COLOUR_MAP @shPropertyBool(colour_map)
@shAllocatePassthrough(1, depth)
@shAllocatePassthrough(2, UV)
#ifdef SH_VERTEX_SHADER
@ -26,6 +29,7 @@
shOutputPosition = shMatrixMult(viewProjMatrix, worldPos);
@shPassthroughAssign(depth, shOutputPosition.z);
@shPassthroughAssign(UV, uv0);
}
@ -34,11 +38,20 @@
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
#if MRT
shDeclareMrtOutput(1)
shUniform(float, far) @shAutoConstant(far, far_clip_distance)
#endif
@ -47,12 +60,22 @@
{
float depth = @shPassthroughReceive(depth);
float2 UV = @shPassthroughReceive(UV);
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
//shOutputColour(1) = float4(1,1,1,1);
shOutputColour(1) = float4(depth / far,1,1,1);
#endif
}

Loading…
Cancel
Save