- // Create a new StateSet for the texture, if required.
- StateSetMap::iterator iter = cloudTextureMap.find(texture);
-
- if (iter == cloudTextureMap.end()) {
- stateSet = new osg::StateSet;
-
- osg::ref_ptr<osgDB::ReaderWriter::Options> options = makeOptionsFromPath(tex_path);
-
- osg::Texture2D *tex = new osg::Texture2D;
- tex->setWrap( osg::Texture2D::WRAP_S, osg::Texture2D::CLAMP );
- tex->setWrap( osg::Texture2D::WRAP_T, osg::Texture2D::CLAMP );
- tex->setImage(osgDB::readImageFile(texture, options.get()));
-
- StateAttributeFactory* attribFactory = StateAttributeFactory::instance();
-
- stateSet->setMode(GL_LIGHTING, osg::StateAttribute::ON);
- stateSet->setMode(GL_CULL_FACE, osg::StateAttribute::OFF);
-
- // Fog handling
- osg::Fog* fog = new osg::Fog;
- fog->setUpdateCallback(new SGCloudFogUpdateCallback);
- stateSet->setAttributeAndModes(fog);
- stateSet->setDataVariance(osg::Object::DYNAMIC);
-
- stateSet->setAttributeAndModes(attribFactory->getSmoothShadeModel());
- stateSet->setAttributeAndModes(attribFactory->getStandardBlendFunc());
-
- stateSet->setTextureAttributeAndModes(0, tex, osg::StateAttribute::ON );
- stateSet->setRenderBinDetails(osg::StateSet::TRANSPARENT_BIN, "DepthSortedBin");
-
- static ref_ptr<AlphaFunc> alphaFunc;
- static ref_ptr<Program> program;
- static ref_ptr<Uniform> baseTextureSampler;
- static ref_ptr<Material> material;
-
- // Generate the shader etc, if we don't already have one.
- if (!program.valid()) {
- alphaFunc = new AlphaFunc;
- alphaFunc->setFunction(AlphaFunc::GREATER,0.002f);
- program = new Program;
- baseTextureSampler = new osg::Uniform("baseTexture", 0);
- Shader* vertex_shader = new Shader(Shader::VERTEX, vertexShaderSource);
- program->addShader(vertex_shader);
- program->addBindAttribLocation("textureIndexX", CloudShaderGeometry::TEXTURE_INDEX_X);
- program->addBindAttribLocation("textureIndexY", CloudShaderGeometry::TEXTURE_INDEX_Y);
- program->addBindAttribLocation("wScale", CloudShaderGeometry::WIDTH);
- program->addBindAttribLocation("hScale", CloudShaderGeometry::HEIGHT);
- program->addBindAttribLocation("shade", CloudShaderGeometry::SHADE);
-
- Shader* fragment_shader = new Shader(Shader::FRAGMENT, fragmentShaderSource);
- program->addShader(fragment_shader);
- material = new Material;
- // DonĀ“t track vertex color
- material->setColorMode(Material::OFF);
-
- // We don't actually use the material information either - see shader.
- material->setAmbient(Material::FRONT_AND_BACK,
- Vec4(0.5f, 0.5f, 0.5f, 1.0f));
- material->setDiffuse(Material::FRONT_AND_BACK,
- Vec4(0.5f, 0.5f, 0.5f, 1.0f));
- }
-
- stateSet->setAttributeAndModes(alphaFunc.get());
- stateSet->setAttribute(program.get());
- stateSet->addUniform(baseTextureSampler.get());
- stateSet->setMode(GL_VERTEX_PROGRAM_TWO_SIDE, StateAttribute::ON);
- stateSet->setAttribute(material.get());
-
- // Add the newly created texture to the map for use later.
- cloudTextureMap.insert(StateSetMap::value_type(texture, stateSet));
+ // Create a new Effect for the texture, if required.
+ EffectMap::iterator iter = effectMap.find(texture);
+ if (iter == effectMap.end()) {
+ SGPropertyNode_ptr pcloudEffect = new SGPropertyNode;
+ makeChild(pcloudEffect, "inherits-from")->setValue("Effects/cloud");
+ setValue(makeChild(makeChild(makeChild(pcloudEffect, "parameters"),
+ "texture"),
+ "image"),
+ texture);
+ osg::ref_ptr<osgDB::ReaderWriter::Options> options
+ = makeOptionsFromPath(tex_path);
+ if ((effect = makeEffect(pcloudEffect, true, options)))
+ effectMap.insert(EffectMap::value_type(texture, effect));