- osg::StateSet* stateset = 0;
- StateSetMap::iterator iter = treeTextureMap.find(forest.texture);
- if (iter == treeTextureMap.end()) {
- 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(forest.texture));
-
- static ref_ptr<AlphaFunc> alphaFunc;
- static ref_ptr<Program> program;
- static ref_ptr<Uniform> baseTextureSampler;
- static ref_ptr<Material> material;
-
- stateset = new osg::StateSet;
- stateset->setTextureAttributeAndModes(0, tex, osg::StateAttribute::ON );
- stateset->setRenderBinDetails(RANDOM_OBJECTS_BIN, "DepthSortedBin");
- if (!program.valid()) {
- alphaFunc = new AlphaFunc;
- alphaFunc->setFunction(AlphaFunc::GEQUAL,0.33f);
- program = new Program;
- baseTextureSampler = new osg::Uniform("baseTexture", 0);
- Shader* vertex_shader = new Shader(Shader::VERTEX, vertexShaderSource);
- program->addShader(vertex_shader);
- program->addBindAttribLocation("textureIndex", 1);
-
- Shader* fragment_shader = new Shader(Shader::FRAGMENT,
- fragmentShaderSource);
- program->addShader(fragment_shader);
- material = new Material;
- // DonĀ“t track vertex color
- material->setColorMode(Material::OFF);
- material->setAmbient(Material::FRONT_AND_BACK,
- Vec4(.8f, .8f, .8f, 1.0f));
- material->setDiffuse(Material::FRONT_AND_BACK,
- Vec4(.2f, .2f, .2f, 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());
-
- treeTextureMap.insert(StateSetMap::value_type(forest.texture,
- stateset));
+ Effect* effect = 0;
+ EffectMap::iterator iter = treeEffectMap.find(forest.texture);
+ if (iter == treeEffectMap.end()) {
+ SGPropertyNode_ptr effectProp = new SGPropertyNode;
+ makeChild(effectProp, "inherits-from")->setStringValue("Effects/tree");
+ SGPropertyNode* params = makeChild(effectProp, "parameters");
+ // emphasize n = 0
+ params->getChild("texture", 0, true)->getChild("image", 0, true)
+ ->setStringValue(forest.texture);
+ effect = makeEffect(effectProp, true);
+ treeEffectMap.insert(EffectMap::value_type(forest.texture, effect));