From d8cfc9b1f5fd77cf82e8f9cd677ff4406a9ad476 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Fri, 26 Sep 2008 15:47:31 +0000 Subject: [PATCH] Improved GLSL isosurface support when using a transfer function --- examples/osgvolume/osgvolume.cpp | 8 +++++--- examples/osgvolume/volume_tf_iso_frag.cpp | 21 ++++++++++++++++++--- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/examples/osgvolume/osgvolume.cpp b/examples/osgvolume/osgvolume.cpp index 2e124b143..b34ccc72c 100644 --- a/examples/osgvolume/osgvolume.cpp +++ b/examples/osgvolume/osgvolume.cpp @@ -876,6 +876,9 @@ osg::Node* createShaderModel(ShadingModel shadingModel, texture3D->setImage(image_3d.get()); stateset->setTextureAttributeAndModes(0,texture3D,osg::StateAttribute::ON); + + osg::Uniform* baseTextureSampler = new osg::Uniform("baseTexture",0); + stateset->addUniform(baseTextureSampler); } @@ -943,7 +946,7 @@ osg::Node* createShaderModel(ShadingModel shadingModel, texture1D->setWrap(osg::Texture::WRAP_R,osg::Texture::CLAMP_TO_EDGE); stateset->setTextureAttributeAndModes(0,texture1D,osg::StateAttribute::ON); - osg::Shader* fragmentShader = osgDB::readShaderFile(osg::Shader::FRAGMENT, "volume-tf-iso.frag"); + osg::Shader* fragmentShader = osgDB::readShaderFile(osg::Shader::FRAGMENT, "volume_tf_iso.frag"); if (fragmentShader) { program->addShader(fragmentShader); @@ -1056,6 +1059,7 @@ osg::Node* createShaderModel(ShadingModel shadingModel, } else { + osg::Shader* fragmentShader = osgDB::readShaderFile(osg::Shader::FRAGMENT, "volume.frag"); if (fragmentShader) { @@ -1067,8 +1071,6 @@ osg::Node* createShaderModel(ShadingModel shadingModel, program->addShader(new osg::Shader(osg::Shader::FRAGMENT, volume_frag)); } } - osg::Uniform* baseTextureSampler = new osg::Uniform("baseTexture",0); - stateset->addUniform(baseTextureSampler); osg::Uniform* sampleDensity = new osg::Uniform("sampleDensity", 0.01f); stateset->addUniform(sampleDensity); diff --git a/examples/osgvolume/volume_tf_iso_frag.cpp b/examples/osgvolume/volume_tf_iso_frag.cpp index ada3e14b3..3453f03d4 100644 --- a/examples/osgvolume/volume_tf_iso_frag.cpp +++ b/examples/osgvolume/volume_tf_iso_frag.cpp @@ -1,4 +1,4 @@ -char volume_tf_iso_frag[] = "uniform sampler3D baseTexture;\n" +char volume_tf_iso_frag[] = "uniform sampler3D normalMap;\n" "uniform sampler1D tfTexture;\n" "uniform float sampleDensity;\n" "uniform float transparency;\n" @@ -13,6 +13,8 @@ char volume_tf_iso_frag[] = "uniform sampler3D baseTexture;\n" " vec3 t0 = (texgen * vertexPos).xyz;\n" " vec3 te = (texgen * cameraPos).xyz;\n" "\n" + " vec3 eyeDirection = normalize(te-t0);\n" + "\n" " if (te.x>=0.0 && te.x<=1.0 &&\n" " te.y>=0.0 && te.y<=1.0 &&\n" " te.z>=0.0 && te.z<=1.0)\n" @@ -73,12 +75,25 @@ char volume_tf_iso_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" + " vec4 normal = texture3D( normalMap, texcoord);\n" + " float v = normal.w;\n" " vec4 color = texture1D( tfTexture, v);\n" - " if (alphaCutOff=alphaCutOff)\n" " {\n" " fragColor = color;\n" " }\n" + "\n" " texcoord += deltaTexCoord; \n" "\n" " --num_iterations;\n"