[osg-users] Texture Mapping Meeting Point Shadow
Erik Hensens
ehensens at hunter.com
Mon May 11 12:39:38 PDT 2015
Hello all!
I'm having trouble with image texture mapping a geode. Specifically, where the top and the bottom of the image meet, there is a dark shadow effect that I want to avoid.
I've created the simplest example of how I'm attempting the texture mapping and I've taken screenshots that show the unwanted shadow (please see the attached screenshots and the overlay image itself).
Below is the code I'm using. As you can see, it's very simple: just four quadrangle faces that form four sides of an open-ended box. I've attempted to map the overlay image around the entire box so that the top and bottom meet at one of the four edges.
Does anyone have any idea what I'm doing wrong or how I can modify my code to get rid of the shadow effect? Thanks a bunch in advance!
Code:
// Create the new geode node
osg::ref_ptr < osg::Geode > pGeode = new osg::Geode;
// Create the single new geometry
osg::ref_ptr < osg::Geometry > pGeometry = new osg::Geometry;
// The vertex array to define the geometry shape
osg::ref_ptr < osg::Vec3Array > pVertices = new osg::Vec3Array;
// Add face 1/4 quad vertices
pVertices->push_back(osg::Vec3(0.0f, 0.0f, 0.0f));
pVertices->push_back(osg::Vec3(10.0f, 0.0f, 0.0f));
pVertices->push_back(osg::Vec3(10.0f, 5.0f, 5.0f));
pVertices->push_back(osg::Vec3(0.0f, 5.0f, 5.0f));
// Add face 2/4 quad vertices
pVertices->push_back(osg::Vec3(0.0f, 5.0f, 5.0f));
pVertices->push_back(osg::Vec3(10.0f, 5.0f, 5.0f));
pVertices->push_back(osg::Vec3(10.0f, 0.0f, 10.0f));
pVertices->push_back(osg::Vec3(0.0f, 0.0f, 10.0f));
// Add face 3/4 quad vertices
pVertices->push_back(osg::Vec3(0.0f, 0.0f, 10.0f));
pVertices->push_back(osg::Vec3(10.0f, 0.0f, 10.0f));
pVertices->push_back(osg::Vec3(10.0f, -5.0f, 5.0f));
pVertices->push_back(osg::Vec3(0.0f, -5.0f, 5.0f));
// Add face 4/4 quad vertices
pVertices->push_back(osg::Vec3(0.0f, -5.0f, 5.0f));
pVertices->push_back(osg::Vec3(10.0f, -5.0f, 5.0f));
pVertices->push_back(osg::Vec3(10.0f, 0.0f, 0.0f));
pVertices->push_back(osg::Vec3(0.0f, 0.0f, 0.0f));
// Set the vertex array on the geometry
pGeometry->setVertexArray(pVertices);
// Create the geometry's color array
osg::ref_ptr < osg::Vec4Array > pColors = new osg::Vec4Array;
pColors->push_back(osg::Vec4(1.0f, 1.0f, 1.0f, 1.0f));
// Set the color array on the geometry
pGeometry->setColorArray(pColors);
pGeometry->setColorBinding(osg::Geometry::BIND_OVERALL);
// Set the quad draw array on the geometry
osg::ref_ptr < osg::DrawArrays > pDrawArrays = new osg::DrawArrays(osg::PrimitiveSet::QUADS, 0, static_cast < GLsizei >(pVertices->size()));
pGeometry->addPrimitiveSet(pDrawArrays);
// Load the overlay image
osg::ref_ptr < osg::Image > pImage = osgDB::readImageFile("overlay.png");
// Create the image texture
osg::ref_ptr < osg::Texture2D > pTexture = new osg::Texture2D(pImage);
// Create the texture coordinates array
osg::ref_ptr < osg::Vec2Array > pTexCoords = new osg::Vec2Array;
// Set face 1/4 quad texture overlay coordinates
pTexCoords->push_back(osg::Vec2(0.0f, 0.0f));
pTexCoords->push_back(osg::Vec2(1.0f, 0.0f));
pTexCoords->push_back(osg::Vec2(1.0f, 0.25f));
pTexCoords->push_back(osg::Vec2(0.0f, 0.25f));
// Set face 2/4 quad texture overlay coordinates
pTexCoords->push_back(osg::Vec2(0.0f, 0.25f));
pTexCoords->push_back(osg::Vec2(1.0f, 0.25f));
pTexCoords->push_back(osg::Vec2(1.0f, 0.50f));
pTexCoords->push_back(osg::Vec2(0.0f, 0.50f));
// Set 3/4 quad texture overlay coordinates
pTexCoords->push_back(osg::Vec2(0.0f, 0.50f));
pTexCoords->push_back(osg::Vec2(1.0f, 0.50f));
pTexCoords->push_back(osg::Vec2(1.0f, 0.75f));
pTexCoords->push_back(osg::Vec2(0.0f, 0.75f));
// Set 4/4 quad texture overlay coordinates
pTexCoords->push_back(osg::Vec2(0.0f, 0.75f));
pTexCoords->push_back(osg::Vec2(1.0f, 0.75f));
pTexCoords->push_back(osg::Vec2(1.0f, 1.0f));
pTexCoords->push_back(osg::Vec2(0.0f, 1.0f));
// Set the geometry's texture coordinates array
pGeometry->setTexCoordArray(0, pTexCoords);
// Get the geometry's stateset
osg::ref_ptr < osg::StateSet > pStateSet = pGeometry->getOrCreateStateSet();
// Set the texture on the stateset
pStateSet->setTextureAttributeAndModes(0, pTexture, osg::StateAttribute::ON);
// Set the geometry's stateset
pGeometry->setStateSet(pStateSet);
// Add the single drawable to the geode node
pGeode->addDrawable(pGeometry);
// Add this new geode to the scene
pTopGroupNode->addChild(pGeode);
Cheers,
Erik
------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=63711#63711
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Zoomed_Out.png
Type: image/png
Size: 29748 bytes
Desc: not available
URL: <http://lists.openscenegraph.org/pipermail/osg-users-openscenegraph.org/attachments/20150511/53ddaadb/attachment-0006.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Zoomed_In.png
Type: image/png
Size: 19036 bytes
Desc: not available
URL: <http://lists.openscenegraph.org/pipermail/osg-users-openscenegraph.org/attachments/20150511/53ddaadb/attachment-0007.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: overlay.png
Type: image/png
Size: 6910 bytes
Desc: not available
URL: <http://lists.openscenegraph.org/pipermail/osg-users-openscenegraph.org/attachments/20150511/53ddaadb/attachment-0008.png>
More information about the osg-users
mailing list