Improved GLSL isosurface support when using a transfer function
This commit is contained in:
parent
21865d3ec1
commit
d8cfc9b1f5
@ -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);
|
||||
|
@ -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<color.w)\n"
|
||||
"\n"
|
||||
" normal.x = normal.x*2.0-1.0;\n"
|
||||
" normal.y = normal.y*2.0-1.0;\n"
|
||||
" normal.z = normal.z*2.0-1.0;\n"
|
||||
" \n"
|
||||
" float lightScale = 0.1 + max(dot(normal.xyz, eyeDirection), 0.0);\n"
|
||||
" color.x *= lightScale;\n"
|
||||
" color.y *= lightScale;\n"
|
||||
" color.z *= lightScale;\n"
|
||||
" color.w = 1.0;\n"
|
||||
" \n"
|
||||
" if (v>=alphaCutOff)\n"
|
||||
" {\n"
|
||||
" fragColor = color;\n"
|
||||
" }\n"
|
||||
"\n"
|
||||
" texcoord += deltaTexCoord; \n"
|
||||
"\n"
|
||||
" --num_iterations;\n"
|
||||
|
Loading…
Reference in New Issue
Block a user