From 200b23f354f597a729e961ccc0677769d43f0b9c Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Fri, 3 Sep 2004 10:02:56 +0000 Subject: [PATCH] Added handling of RGBA to normal map computation --- examples/osgvolume/osgvolume.cpp | 77 ++++++++++++++++++++++++-------- 1 file changed, 59 insertions(+), 18 deletions(-) diff --git a/examples/osgvolume/osgvolume.cpp b/examples/osgvolume/osgvolume.cpp index 1e132628f..fcf8599bb 100644 --- a/examples/osgvolume/osgvolume.cpp +++ b/examples/osgvolume/osgvolume.cpp @@ -278,6 +278,7 @@ osg::Image* createTexture3D(ImageList& imageList, ProcessRow& processRow, unsign { max_s = osg::maximum(image->s(), max_s); max_t = osg::maximum(image->t(), max_t); + osg::notify(osg::NOTICE)<<"image, number of components"<r(); } @@ -293,15 +294,19 @@ osg::Image* createTexture3D(ImageList& imageList, ProcessRow& processRow, unsign switch(max_components) { case(1): + osg::notify(osg::NOTICE)<<"desiredPixelFormat = GL_LUMINANCE" << std::endl; desiredPixelFormat = GL_LUMINANCE; break; case(2): + osg::notify(osg::NOTICE)<<"desiredPixelFormat = GL_LUMINANCE_ALPHA" << std::endl; desiredPixelFormat = GL_LUMINANCE_ALPHA; break; case(3): + osg::notify(osg::NOTICE)<<"desiredPixelFormat = GL_RGB" << std::endl; desiredPixelFormat = GL_RGB; break; case(4): + osg::notify(osg::NOTICE)<<"desiredPixelFormat = GL_RGBA" << std::endl; desiredPixelFormat = GL_RGBA; break; } @@ -316,6 +321,11 @@ osg::Image* createTexture3D(ImageList& imageList, ProcessRow& processRow, unsign int r_nearestPowerOfTwo = 1; while(r_nearestPowerOfTwo bumpmap_3d = new osg::Image; bumpmap_3d->allocateImage(image_3d->s(),image_3d->t(),image_3d->r(), GL_RGBA,GL_UNSIGNED_BYTE); + for(int r=1;rr()-1;++r) { for(int t=1;tt()-1;++t) { - unsigned char* ptr = image_3d->data(1,t,r); - unsigned char* left = image_3d->data(0,t,r); - unsigned char* right = image_3d->data(2,t,r); - unsigned char* above = image_3d->data(1,t+1,r); - unsigned char* below = image_3d->data(1,t-1,r); - unsigned char* in = image_3d->data(1,t,r+1); - unsigned char* out = image_3d->data(1,t,r-1); + unsigned char* ptr = image_3d->data(1,t,r)+alphaOffset; + unsigned char* left = image_3d->data(0,t,r)+alphaOffset; + unsigned char* right = image_3d->data(2,t,r)+alphaOffset; + unsigned char* above = image_3d->data(1,t+1,r)+alphaOffset; + unsigned char* below = image_3d->data(1,t-1,r)+alphaOffset; + unsigned char* in = image_3d->data(1,t,r+1)+alphaOffset; + unsigned char* out = image_3d->data(1,t,r-1)+alphaOffset; unsigned char* destination = (unsigned char*) bumpmap_3d->data(1,t,r); @@ -404,13 +441,13 @@ osg::Image* createNormalMapTexture(osg::Image* image_3d) *destination++ = *ptr; - ++ptr; - ++left; - ++right; - ++above; - ++below; - ++in; - ++out; + ptr += sourcePixelIncrement; + left += sourcePixelIncrement; + right += sourcePixelIncrement; + above += sourcePixelIncrement; + below += sourcePixelIncrement; + in += sourcePixelIncrement; + out += sourcePixelIncrement; } } } @@ -536,7 +573,7 @@ osg::Node* createModel(osg::ref_ptr& image_3d, bool createNormalMap, stateset->setMode(GL_LIGHTING,osg::StateAttribute::ON); stateset->setMode(GL_BLEND,osg::StateAttribute::ON); - stateset->setAttribute(new osg::AlphaFunc(osg::AlphaFunc::GREATER,0.02f)); + stateset->setAttribute(new osg::AlphaFunc(osg::AlphaFunc::GREATER,0.00f)); osg::Material* material = new osg::Material; material->setDiffuse(osg::Material::FRONT_AND_BACK,osg::Vec4(1.0f,1.0f,1.0f,1.0f)); @@ -554,8 +591,12 @@ osg::Node* createModel(osg::ref_ptr& image_3d, bool createNormalMap, texture3D->setWrap(osg::Texture3D::WRAP_R,osg::Texture3D::CLAMP); texture3D->setWrap(osg::Texture3D::WRAP_S,osg::Texture3D::CLAMP); texture3D->setWrap(osg::Texture3D::WRAP_T,osg::Texture3D::CLAMP); - texture3D->setInternalFormatMode(osg::Texture3D::USE_USER_DEFINED_FORMAT); - texture3D->setInternalFormat(GL_INTENSITY); + if (image_3d->getPixelFormat()==GL_ALPHA || + image_3d->getPixelFormat()==GL_LUMINANCE) + { + texture3D->setInternalFormatMode(osg::Texture3D::USE_USER_DEFINED_FORMAT); + texture3D->setInternalFormat(GL_INTENSITY); + } texture3D->setImage(image_3d.get()); stateset->setTextureAttributeAndModes(diffuse_unit,texture3D,osg::StateAttribute::ON); @@ -672,7 +713,7 @@ int main( int argc, char **argv ) // pack the textures into a single texture. ProcessRow processRow; - image_3d = createTexture3D(imageList, processRow, 1); + image_3d = createTexture3D(imageList, processRow); }