diff --git a/src/osgVolume/Layer.cpp b/src/osgVolume/Layer.cpp index 12b8ebf44..8c9ee0506 100644 --- a/src/osgVolume/Layer.cpp +++ b/src/osgVolume/Layer.cpp @@ -182,7 +182,7 @@ void ImageLayer::offsetAndScaleImage(const osg::Vec4& offset, const osg::Vec4& s void ImageLayer::rescaleToZeroToOneRange() { - osg::notify(osg::NOTICE)<<"ImageLayer::rescaleToZeroToOneRange()"<(_volumeTile->getLayer()); + if (imageLayer) + { + tfOffset = (imageLayer->getTexelOffset()[3] - tf->getMinimum()) / (tf->getMaximum() - tf->getMinimum()); + tfScale = imageLayer->getTexelScale()[3] / (tf->getMaximum() - tf->getMinimum()); + } + else + { + tfOffset = -tf->getMinimum() / (tf->getMaximum()-tf->getMinimum()); + tfScale = 1.0f / (tf->getMaximum()-tf->getMinimum()); + } osg::ref_ptr tf_texture = new osg::Texture1D; tf_texture->setImage(tf->getImage()); tf_texture->setResizeNonPowerOfTwoHint(false); @@ -258,10 +272,10 @@ void RayTracedTechnique::init() tf_texture->setFilter(osg::Texture::MAG_FILTER, osg::Texture::LINEAR); tf_texture->setWrap(osg::Texture::WRAP_R,osg::Texture::CLAMP_TO_EDGE); - osg::ref_ptr tf_sampler = new osg::Uniform("tfTexture",1); - stateset->setTextureAttributeAndModes(1, tf_texture.get(), osg::StateAttribute::ON); - stateset->addUniform(tf_sampler.get()); + stateset->addUniform(new osg::Uniform("tfTexture",1)); + stateset->addUniform(new osg::Uniform("tfOffset",tfOffset)); + stateset->addUniform(new osg::Uniform("tfScale",tfScale)); } diff --git a/src/osgVolume/Shaders/volume_lit_tf_frag.cpp b/src/osgVolume/Shaders/volume_lit_tf_frag.cpp index 805f62c6e..92c57be47 100644 --- a/src/osgVolume/Shaders/volume_lit_tf_frag.cpp +++ b/src/osgVolume/Shaders/volume_lit_tf_frag.cpp @@ -1,5 +1,9 @@ char volume_lit_tf_frag[] = "uniform sampler3D baseTexture;\n" + "\n" "uniform sampler1D tfTexture;\n" + "uniform float tfScale;\n" + "uniform float tfOffset;\n" + "\n" "uniform float SampleDensityValue;\n" "uniform float TransparencyValue;\n" "uniform float AlphaFuncValue;\n" @@ -83,7 +87,7 @@ char volume_lit_tf_frag[] = "uniform sampler3D baseTexture;\n" " vec4 fragColor = vec4(0.0, 0.0, 0.0, 0.0); \n" " while(num_iterations>0.0)\n" " {\n" - " float v = texture3D( baseTexture, texcoord).a;\n" + " float v = texture3D( baseTexture, texcoord).a * tfScale + tfOffset;\n" " vec4 color = texture1D( tfTexture, v);\n" "\n" " float a = v;\n" diff --git a/src/osgVolume/Shaders/volume_tf_frag.cpp b/src/osgVolume/Shaders/volume_tf_frag.cpp index 15cf5ca28..e4aa23ea0 100644 --- a/src/osgVolume/Shaders/volume_tf_frag.cpp +++ b/src/osgVolume/Shaders/volume_tf_frag.cpp @@ -1,5 +1,9 @@ char volume_tf_frag[] = "uniform sampler3D baseTexture;\n" + "\n" "uniform sampler1D tfTexture;\n" + "uniform float tfScale;\n" + "uniform float tfOffset;\n" + "\n" "uniform float SampleDensityValue;\n" "uniform float TransparencyValue;\n" "uniform float AlphaFuncValue;\n" @@ -76,7 +80,7 @@ char volume_tf_frag[] = "uniform sampler3D baseTexture;\n" " vec4 fragColor = vec4(0.0, 0.0, 0.0, 0.0); \n" " while(num_iterations>0.0)\n" " {\n" - " float v = texture3D( baseTexture, texcoord).a;\n" + " float v = texture3D( baseTexture, texcoord).a * tfScale + tfOffset;\n" " vec4 color = texture1D( tfTexture, v);\n" "\n" " float r = color[3]*TransparencyValue;\n" diff --git a/src/osgVolume/Shaders/volume_tf_iso_frag.cpp b/src/osgVolume/Shaders/volume_tf_iso_frag.cpp index 5988f9e1f..60eeb9ed7 100644 --- a/src/osgVolume/Shaders/volume_tf_iso_frag.cpp +++ b/src/osgVolume/Shaders/volume_tf_iso_frag.cpp @@ -1,5 +1,9 @@ char volume_tf_iso_frag[] = "uniform sampler3D baseTexture;\n" + "\n" "uniform sampler1D tfTexture;\n" + "uniform float tfScale;\n" + "uniform float tfOffset;\n" + "\n" "uniform float SampleDensityValue;\n" "uniform float TransparencyValue;\n" "uniform float IsoSurfaceValue;\n" @@ -91,7 +95,7 @@ char volume_tf_iso_frag[] = "uniform sampler3D baseTexture;\n" " float r = (IsoSurfaceValue-v)/(previousV-v);\n" " texcoord = texcoord - r*deltaTexCoord;\n" "\n" - " v = texture3D( baseTexture, texcoord).a;\n" + " v = texture3D( baseTexture, texcoord).a * tfScale + tfOffset;\n" " vec4 color = texture1D( tfTexture, v);\n" "\n" " float px = texture3D( baseTexture, texcoord + deltaX).a;\n" diff --git a/src/osgVolume/Shaders/volume_tf_mip_frag.cpp b/src/osgVolume/Shaders/volume_tf_mip_frag.cpp index 49ef80443..17d03e747 100644 --- a/src/osgVolume/Shaders/volume_tf_mip_frag.cpp +++ b/src/osgVolume/Shaders/volume_tf_mip_frag.cpp @@ -1,5 +1,9 @@ char volume_tf_mip_frag[] = "uniform sampler3D baseTexture;\n" + "\n" "uniform sampler1D tfTexture;\n" + "uniform float tfScale;\n" + "uniform float tfOffset;\n" + "\n" "uniform float SampleDensityValue;\n" "uniform float TransparencyValue;\n" "uniform float AlphaFuncValue;\n" @@ -73,7 +77,7 @@ char volume_tf_mip_frag[] = "uniform sampler3D baseTexture;\n" " vec4 fragColor = vec4(0.0, 0.0, 0.0, 0.0); \n" " while(num_iterations>0.0)\n" " {\n" - " float v = texture3D( baseTexture, texcoord).s;\n" + " float v = texture3D( baseTexture, texcoord).s * tfScale + tfOffset;\n" " vec4 color = texture1D( tfTexture, v);\n" " if (fragColor.w