Hi Robert,
Clamping is one way to tackle it, but in my case (using the
IntersectionVisitor and calculate the texture coordinates) I sometimes
get negative texture coordinates, which have to be wrapped to modify the
correct texel.
I think we can live with this behaviour, as one should do the wrapping
as desired on his end. Maybe we could provide the wrapping function
somewhere in the Math section?
Cheers
Sebastian.
On 21 November 2014 16:29, Robert Osfield <[email protected]
<mailto:[email protected]>> wrote:
On 14 November 2014 09:18, Sebastian Messerschmidt
<[email protected]
<mailto:[email protected]>> wrote:
During my in-depth tests I found some general problem with
set/getColor functions if negative texture coordinates are passed.
Right now I'm fixing this on my end, by wrapping them
manually, since I didn't find a clever and nice looking
solution other than:
float int_part;
if (tc[0] < 0) { tc[0] = 1.0 - modf(tc[0], &int_part); }
if (tc[1] < 0) { tc[1] = 1.0 - modf(tc[1], &int_part); }
if (tc[2] < 0) { tc[2] = 1.0 - modf(tc[2], &int_part); }
This issue affects the getColor() as well so I'll look at both now.
I have decided to implement clamp to edge policy for the
setColor(color, texcoord) using the follow modification:
$ svn diff
Index: Image.cpp
===================================================================
--- Image.cpp (revision 14517)
+++ Image.cpp (working copy)
@@ -1919,9 +1919,9 @@
Vec4 Image::getColor(const Vec3& texcoord) const
{
- int s = int(texcoord.x()*float(_s-1)) % _s;
- int t = int(texcoord.y()*float(_t-1)) % _t;
- int r = int(texcoord.z()*float(_r-1)) % _r;
+ unsigned int s = osg::clampTo(int(texcoord.x()*float(_s-1)), 0,
_s-1);
+ unsigned int t = osg::clampTo(int(texcoord.y()*float(_t-1)), 0,
_t-1);
+ unsigned int r = osg::clampTo(int(texcoord.z()*float(_r-1)), 0,
_r-1);
//OSG_NOTICE<<"getColor("<<texcoord<<")="<<getColor(s,t,r)<<std::endl;
return getColor(s,t,r);
}
This is now checked into svn/trunk. Could you test it out please?
Thanks,
Robert.
_______________________________________________
osg-submissions mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-submissions-openscenegraph.org
_______________________________________________
osg-submissions mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-submissions-openscenegraph.org