Hi
check if you treat directional light in a right way (i mean use light direction 
instead of position and such)

28.03.2012, 13:29, "Andrey Ibe" <xry...@gmail.com>:
> Hi,
>
> i am doing an off-line ray-tracing. at the beginning of the computation i 
> fetch all the lights and then use them.
>
> the problem is, i am not getting the correct light position, obviously. i 
> attached two pictures showing the difference between the position the 
> osg::viewer is getting and the one i'm getting for the ray-tracing. the 
> pictures feature a solo directional light. in the viewer picture you can 
> guess the position of the light by the specular reflection on the pink 
> object. it seems to be exactly on the opposite side compared to the 
> ray-traced image.
>
> so far this only happened with the directional light for this model, but i 
> start to suspect, that the other lights (in different models) are not 
> positioned correctly either.
>
> i fetch the lights using a lightsource visitor, taht collects the light 
> sources, then i use getWorldMatrices() and take the first transformation 
> matrix, finally i multiply the light's position and directions.  this is the 
> code:
> Code:
>
> void RayManager::collectLightSources(WorldLightSourceContainer& lc) const {
>
>         osg::ref_ptr<LightSourceVisitor> lVisitor = new 
> LightSourceVisitor(lc.sources);
>         _scene->accept(*(lVisitor.get()));
>         for (LightSources::iterator lsIt = lc.sources.begin(); lsIt != 
> lc.sources.end(); lsIt++) {
>
>                 osg::MatrixList worldMatrices = (*lsIt)->getWorldMatrices();
>                 // take the first world matrix
>                 osg::Matrix m = worldMatrices.front();
>                                 lc.positions.push_back((*lsIt)->getLight()->getPosition()
>  * m);
>                                 osg::Vec3d direction = 
> (*lsIt)->getLight()->getDirection() * m;
>                 direction.normalize();
>                 lc.directions.push_back(direction);
>         }
> }
>
> and this is the code for my lighSource visitor
> Code:
>
> LightSourceVisitor::LightSourceVisitor(LightSources& lightSources) : 
> osg::NodeVisitor(TRAVERSE_ALL_CHILDREN),
> _lightSources(lightSources) {
> }
>
> void LightSourceVisitor::apply(osg::LightSource& node) {
>         _lightSources.push_back(&node);
>         osg::NodeVisitor::apply((osg::Group&)node);
> }
>
> am i doing something wrong ? the code seems to work for the two other lights 
> (which are turned off in the attached pictures), that's what worries me.
> Thank you!
>
> Cheers,
> Andrey
>
> ------------------
> Read this topic online here:
> http://forum.openscenegraph.org/viewtopic.php?p=46645#46645
>
> _______________________________________________
> osg-users mailing list
> osg-users@lists.openscenegraph.org
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
_______________________________________________
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to