From 666aa81185ca92f9c1e022f526229ee73cb0175a Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Tue, 17 Dec 2013 10:52:50 +0000 Subject: [PATCH] Added experimental image 3d downsample function. --- src/osgVolume/MultipassTechnique.cpp | 137 ++++++++++++++++++++++++++- 1 file changed, 132 insertions(+), 5 deletions(-) diff --git a/src/osgVolume/MultipassTechnique.cpp b/src/osgVolume/MultipassTechnique.cpp index 0a94ba419..8d4453337 100644 --- a/src/osgVolume/MultipassTechnique.cpp +++ b/src/osgVolume/MultipassTechnique.cpp @@ -26,6 +26,7 @@ #include #include #include +#include #include #include @@ -34,6 +35,119 @@ namespace osgVolume { +osg::Image* createDownsampledImage(osg::Image* sourceImage) +{ + osg::ref_ptr targetImage = new osg::Image; + + int s_base = sourceImage->s()/2; + int s_odd = (sourceImage->s()%2); + int s = s_base + s_odd; + + int t_base = sourceImage->t()/2; + int t_odd = (sourceImage->t()%2); + int t = t_base + t_odd; + + int r_base = sourceImage->r()/2; + int r_odd = (sourceImage->r()%2); + int r = r_base + r_odd; + + OSG_NOTICE<<"createDownsampledImage("<s()<<", "<t()<<", "<r()<<")"< image_3d = _volumeTile->getLayer()->getImage(); + + // create a downsampled image to use when rendering at a lower quality. + // osg::ref_ptr downsampled_image_3d = createDownsampledImage(image_3d.get()); + + //image_3d = createDownsampledImage(downsampled_image_3d.get()); + // image_3d = downsampled_image_3d; + osg::ref_ptr texture3D = new osg::Texture3D; { osg::Texture::InternalFormatMode internalFormatMode = osg::Texture::USE_IMAGE_DATA_FORMAT; -#if 1 +#define VOLUME_TYPE 2 +#if VOLUME_TYPE==1 + osg::Texture::FilterMode minFilter = osg::Texture::LINEAR_MIPMAP_LINEAR; + osg::Texture::FilterMode magFilter = osg::Texture::LINEAR; +#elif VOLUME_TYPE==2 osg::Texture::FilterMode minFilter = osg::Texture::LINEAR; osg::Texture::FilterMode magFilter = osg::Texture::LINEAR; #else @@ -268,6 +393,7 @@ void MultipassTechnique::init() texture3D->setWrap(osg::Texture3D::WRAP_R,osg::Texture3D::CLAMP_TO_BORDER); texture3D->setWrap(osg::Texture3D::WRAP_S,osg::Texture3D::CLAMP_TO_BORDER); texture3D->setWrap(osg::Texture3D::WRAP_T,osg::Texture3D::CLAMP_TO_BORDER); + //texture3D->setMaxAnisotropy(16.0f); texture3D->setBorderColor(osg::Vec4(0.0,0.0,0.0,0.0)); if (image_3d->getPixelFormat()==GL_ALPHA || image_3d->getPixelFormat()==GL_LUMINANCE) @@ -564,6 +690,7 @@ void MultipassTechnique::init() if (cpv._sampleRatioWhenMovingProperty.valid()) { _whenMovingStateSet = new osg::StateSet; + //_whenMovingStateSet->setTextureAttributeAndModes(volumeTextureUnit, new osg::TexEnvFilter(1.0)); _whenMovingStateSet->addUniform(cpv._sampleRatioWhenMovingProperty->getUniform(), osg::StateAttribute::OVERRIDE | osg::StateAttribute::ON); } @@ -616,8 +743,8 @@ void MultipassTechnique::cull(osgUtil::CullVisitor* cv) int shaderMaskFront = shaderMask | FRONT_SHADERS; int shaderMaskBack = shaderMask | BACK_SHADERS; - OSG_NOTICE<<"shaderMaskFront "< front_stateset = _stateSetMap[shaderMaskFront]; @@ -632,7 +759,7 @@ void MultipassTechnique::cull(osgUtil::CullVisitor* cv) if (front_stateset.valid()) { - OSG_NOTICE<<"Have front stateset"<pushStateSet(front_stateset.get()); _transform->accept(*cv); cv->popStateSet(); @@ -640,7 +767,7 @@ void MultipassTechnique::cull(osgUtil::CullVisitor* cv) if (back_stateset.valid()) { - OSG_NOTICE<<"Have back stateset"<pushStateSet(back_stateset.get()); _transform->accept(*cv); cv->popStateSet();