|
|
|
@ -2,11 +2,13 @@
|
|
|
|
|
|
|
|
|
|
#include <stdexcept>
|
|
|
|
|
|
|
|
|
|
#include <osg/Fog>
|
|
|
|
|
#include <osg/Depth>
|
|
|
|
|
#include <osg/TexEnvCombine>
|
|
|
|
|
#include <osg/Texture2D>
|
|
|
|
|
#include <osg/TexMat>
|
|
|
|
|
#include <osg/Material>
|
|
|
|
|
#include <osg/BlendFunc>
|
|
|
|
|
|
|
|
|
|
#include <components/shader/shadermanager.hpp>
|
|
|
|
|
|
|
|
|
@ -59,24 +61,52 @@ namespace Terrain
|
|
|
|
|
}
|
|
|
|
|
return depth;
|
|
|
|
|
}
|
|
|
|
|
osg::ref_ptr<osg::Depth> getLequalDepth()
|
|
|
|
|
{
|
|
|
|
|
static osg::ref_ptr<osg::Depth> depth;
|
|
|
|
|
if (!depth)
|
|
|
|
|
{
|
|
|
|
|
depth = new osg::Depth;
|
|
|
|
|
depth->setFunction(osg::Depth::LEQUAL);
|
|
|
|
|
}
|
|
|
|
|
return depth;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::vector<osg::ref_ptr<osg::StateSet> > createPasses(bool useShaders, bool forcePerPixelLighting, bool clampLighting, Shader::ShaderManager* shaderManager, const std::vector<TextureLayer> &layers,
|
|
|
|
|
const std::vector<osg::ref_ptr<osg::Texture2D> > &blendmaps, int blendmapScale, float layerTileSize)
|
|
|
|
|
{
|
|
|
|
|
std::vector<osg::ref_ptr<osg::StateSet> > passes;
|
|
|
|
|
|
|
|
|
|
bool firstLayer = true;
|
|
|
|
|
unsigned int blendmapIndex = 0;
|
|
|
|
|
unsigned int passIndex = 0;
|
|
|
|
|
for (std::vector<TextureLayer>::const_iterator it = layers.begin(); it != layers.end(); ++it)
|
|
|
|
|
{
|
|
|
|
|
bool firstLayer = (it == layers.begin());
|
|
|
|
|
|
|
|
|
|
osg::ref_ptr<osg::StateSet> stateset (new osg::StateSet);
|
|
|
|
|
|
|
|
|
|
if (!firstLayer)
|
|
|
|
|
{
|
|
|
|
|
static osg::ref_ptr<osg::BlendFunc> blendFunc;
|
|
|
|
|
if (!blendFunc)
|
|
|
|
|
{
|
|
|
|
|
blendFunc= new osg::BlendFunc();
|
|
|
|
|
blendFunc->setFunction(osg::BlendFunc::SRC_ALPHA, osg::BlendFunc::ONE);
|
|
|
|
|
}
|
|
|
|
|
stateset->setMode(GL_BLEND, osg::StateAttribute::ON);
|
|
|
|
|
stateset->setAttributeAndModes(blendFunc, osg::StateAttribute::ON);
|
|
|
|
|
|
|
|
|
|
stateset->setAttributeAndModes(getEqualDepth(), osg::StateAttribute::ON);
|
|
|
|
|
}
|
|
|
|
|
// disable fog if we're the first layer of several - supposed to be completely black
|
|
|
|
|
if (firstLayer && blendmaps.size() > 0)
|
|
|
|
|
{
|
|
|
|
|
osg::ref_ptr<osg::Fog> fog (new osg::Fog);
|
|
|
|
|
fog->setStart(10000000);
|
|
|
|
|
fog->setEnd(10000000);
|
|
|
|
|
stateset->setAttributeAndModes(fog, osg::StateAttribute::OFF|osg::StateAttribute::OVERRIDE);
|
|
|
|
|
stateset->setAttributeAndModes(getLequalDepth(), osg::StateAttribute::ON);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int texunit = 0;
|
|
|
|
|
|
|
|
|
@ -158,8 +188,6 @@ namespace Terrain
|
|
|
|
|
stateset->setTextureAttributeAndModes(texunit, getLayerTexMat(layerTileSize), osg::StateAttribute::ON);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
firstLayer = false;
|
|
|
|
|
|
|
|
|
|
stateset->setRenderBinDetails(passIndex++, "RenderBin");
|
|
|
|
|
|
|
|
|
|
passes.push_back(stateset);
|
|
|
|
|