Hi Cyclonis, I'm afraid I have rather too much in the way of support emails to get throught to look at user programs and data so I'll just provide some general comments.
When shadow mapping you have to have a shader that combines the textures of the orignal data with the shadow map texture doing the appropriate shader map tests. You can set the texture unit for the shadow map but it's not a general solution - one typically will have to resort to a custom shader to handle the specfics of your data. Robet. On 30 June 2013 13:01, Cyclonis Delta <[email protected]> wrote: > Hi, > > I have been using OSG for a while now, but now I am trying to implement > shadows using the ShadowMap. This generally works, but for some reason all > the .osg models that I import through readNodeFile are now missing their > textures. When I switch back from the ShadowedScene to a regular Group, the > textures work again. > > In order to make it easier to help me, I have reduced my problem to a very > basic setup, which is just a flat plate with a texture and a sphere hovering > over it. I have attached the .osg file for the plate as well as a main.cpp > for the program. It should run immediately. > > Basically the code in my main function is as follows: > > > Code: > //Main light source > Vec3 light_position(0, 0, 5); > ref_ptr<LightSource> light_source (new osg::LightSource); > light_source->getLight()->setPosition(Vec4(light_position, 1)); > light_source->getLight()->setAmbient(Vec4(0.5, 0.5, 0.5, 1)); > light_source->getLight()->setDiffuse(Vec4(0.8, 0.8, 0.8, 1)); > light_source->getLight()->setSpecular(Vec4(0.5, 0.5, 0.5, 1.0)); > light_source->getLight()->setConstantAttenuation(0.5); > > //Set shadow mask ints > int receive_shadow_mask = 0x1; > int cast_shadow_mask = 0x2; > > //Setup root scene > > ref_ptr<ShadowedScene> root = new ShadowedScene(); > ref_ptr<ShadowMap> shadow_map (new osgShadow::ShadowMap); > shadow_map->setLight(light_source); > shadow_map->setTextureSize(osg::Vec2s(1024, 1024)); > shadow_map->setTextureUnit(1); > root->setReceivesShadowTraversalMask(receive_shadow_mask); > root->setCastsShadowTraversalMask(cast_shadow_mask); > root->setShadowTechnique(shadow_map); > > //ref_ptr<Group> root = new Group(); > > //Load the model > osg::ref_ptr<osg::Node> model = > osgDB::readNodeFile("media/plate.osg"); > > //Make a sphere > ref_ptr<osg::Geode> sphere = new osg::Geode(); > osg::ShapeDrawable * drawable = new ShapeDrawable(new > Sphere(Vec3(0.0, 0.0, 1.2), 0.1)); > sphere->addDrawable(drawable); > > //Cast shadows > model->setNodeMask(cast_shadow_mask|receive_shadow_mask); > sphere->setNodeMask(cast_shadow_mask|receive_shadow_mask); > > //Add stuff to root > root->addChild(light_source); > root->addChild(model); > root->addChild(sphere); > > //Setup viewer > osgViewer::Viewer viewer; > > viewer.setCameraManipulator(new osgGA::TrackballManipulator); > viewer.setSceneData(root); > viewer.realize(); > > while (!viewer.done()) { > viewer.frame(); > Sleep(5); > } > > return 0; > > > > > This will not show any textures on my plate. The shadow does work, however. > When I comment the whole ShadowedScene part and I uncomment the line > //ref_ptr<Group> root = new Group(); the textures work once again, but > obviously no shadows. > > I have looked through the forums and there were some people with the same > problem as me. Apparently the problem should lie in the fact that my .osg > texture used the same unit as the shadow texture. This was indeed the case, > as they both used 1. However, after changing this in my .osg model to 2, the > result was the same, no texture on my plate, even though it seemed to solve > the problem for many other users on this forum. > > Attached is also the .osg file in which you can see that I have changed the > texture unit to 2. > > Does anyone have any other ideas on what needs to change in my program in > order to get both the model textures to work, together with shadows? > > Thanks, > Cyclonis[/code] > > ------------------ > Read this topic online here: > http://forum.openscenegraph.org/viewtopic.php?p=55003#55003 > > > > > Attachments: > http://forum.openscenegraph.org//files/main_724.cpp > http://forum.openscenegraph.org//files/plate_822.osg > > > _______________________________________________ > osg-users mailing list > [email protected] > http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org _______________________________________________ osg-users mailing list [email protected] http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

