Hello,
im having problems with the BumpMapping osgFX, somehow it just seems it
doesn't light the model. Model is only responding to ambient light. Is there
any quirck im forgetting of doing ?
The osgfxbrowser example works fine, so its not a hardware problem...
Here is the code for the light setup:
osg::ref_ptr<osg::Light> light = new osg::Light;
light->setLightNum( 0 );
light->setDiffuse( osg::Vec4( 1, 1, 1, 1 ) );
light->setSpecular( osg::Vec4( 1, 1, 0.8f, 1 ) );
light->setAmbient( osg::Vec4( 0.2f, 0.2f, 0.2f, 0.2f ) );
light->setPosition( osg::Vec4( 10, -1, 0, 0 ) );
root = new osg::LightSource;
root->setLight( light.get() );
root->setLocalStateSetModes();
Here is the code for the bump mapping FX node:
void ScenePlanet::generatePlanet()
{
PlanetRotateCallback* rotate_cb;
osg::Geode* planet_geode = new osg::Geode();
osg::StateSet* planet_stateset = planet_geode->getOrCreateStateSet();
// get the textures according to the position that they were inserted at
osg::Texture2D* texture = textures->at(0);
osg::Texture2D* normal_map = textures->at(1);
// set them up
planet_stateset->setMode(GL_LIGHTING, osg::StateAttribute::ON);
planet_stateset->setTextureAttributeAndModes( 0, texture,
osg::StateAttribute::ON );
planet_stateset->setTextureAttributeAndModes( 1, normal_map,
osg::StateAttribute::ON );
osg::TessellationHints* hints = new osg::TessellationHints;
hints->setDetailRatio(0.5f);
planet_geode->addDrawable(
new osg::ShapeDrawable(
new osg::Sphere( osg::Vec3( 0.0f,0.0f,0.0f ), 5.0f ) )
);
// set up the effects of the model
osgFX::BumpMapping* bump_fx = new osgFX::BumpMapping();
bump_fx->setEnabled( true );
bump_fx->addChild( planet_geode );
bump_fx->setNormalMapTextureUnit(1);
bump_fx->setDiffuseTextureUnit(0);
bump_fx->setLightNumber(0);
bump_fx->prepareChildren();
//bump_fx->setUpDemo();
// set up a transform to rotate the model
osg::ref_ptr<osg::PositionAttitudeTransform> xform =
new
osg::PositionAttitudeTransform();
xform->setPosition( osg::Vec3( 1.5, 0, 1 ) );
xform->setPivotPoint( osg::Vec3( 0, 0, 0 ) );
rotate_cb = new PlanetRotateCallback;
xform->setUpdateCallback( rotate_cb );
xform->addChild( bump_fx );
root->addChild( xform.get() );
}
Here is the code for the texture generation:
Diffuse Texture:
osg_img->setImage( size, size, 1,
4, GL_RGBA, GL_UNSIGNED_BYTE,
writer.GetImageData(),
osg::Image::USE_NEW_DELETE );
texture->setImage(osg_img);
texture->setFilter(osg::Texture::MIN_FILTER,
osg::Texture::LINEAR_MIPMAP_LINEAR);
texture->setFilter(osg::Texture::MAG_FILTER, osg::Texture::LINEAR);
texture->setWrap(osg::Texture::WRAP_S, osg::Texture::REPEAT);
texture->setWrap(osg::Texture::WRAP_T, osg::Texture::REPEAT);
texture->setMaxAnisotropy( 8 );
textures->push_back( texture );
Normal Texture:
osg_normalmap_img->setImage( size, size, 1,
4, GL_RGBA, GL_UNSIGNED_BYTE,
writer.GetImageData(),
osg::Image::USE_NEW_DELETE );
normalmap_texture->setImage(osg_normalmap_img);
normalmap_texture->setFilter(osg::Texture::MIN_FILTER,
osg::Texture::LINEAR_MIPMAP_LINEAR);
normalmap_texture->setFilter(osg::Texture::MAG_FILTER,
osg::Texture::LINEAR);
normalmap_texture->setWrap(osg::Texture::WRAP_S, osg::Texture::REPEAT);
normalmap_texture->setWrap(osg::Texture::WRAP_T, osg::Texture::REPEAT);
normalmap_texture->setMaxAnisotropy(8);
textures->push_back( normalmap_texture );
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org