Added AlphaFunc support into osgVolume::AlphaFuncProperty.

This commit is contained in:
Robert Osfield 2009-01-20 12:39:26 +00:00
parent 8a971d96d2
commit 87cd4530f5
11 changed files with 51 additions and 19 deletions

View File

@ -782,6 +782,7 @@ class FollowMouseCallback : public osgGA::GUIEventHandler, public osg::StateSet:
if (_updateAlphaCutOff && cpv._afProperty.valid())
{
osg::notify(osg::NOTICE)<<"Setting afProperty to "<<v<<std::endl;
cpv._afProperty->setValue(v);
}
}
@ -1345,24 +1346,27 @@ int main( int argc, char **argv )
switch(shadingModel)
{
case(Standard):
layer->addProperty(new osgVolume::AlphaFuncProperty(alphaFunc));
break;
case(Light):
layer->addProperty(new osgVolume::AlphaFuncProperty(alphaFunc));
layer->addProperty(new osgVolume::LightingProperty);
break;
case(Isosurface):
layer->addProperty(new osgVolume::IsoSurfaceProperty(alphaFunc));
break;
case(MaximumIntensityProjection):
layer->addProperty(new osgVolume::AlphaFuncProperty(alphaFunc));
layer->addProperty(new osgVolume::MaximumIntensityProjectionProperty);
break;
}
layer->addProperty(new osgVolume::AlphaFuncProperty(alphaFunc));
tile->setVolumeTechnique(new osgVolume::ShaderTechnique);
}
else
{
layer->addProperty(new osgVolume::AlphaFuncProperty(alphaFunc));
tile->setVolumeTechnique(new osgVolume::FixedFunctionTechnique);
}

View File

@ -16,6 +16,7 @@
#include <osg/TransferFunction>
#include <osg/Uniform>
#include <osg/AlphaFunc>
#include <osgVolume/Export>
@ -150,7 +151,7 @@ class OSGVOLUME_EXPORT ScalarProperty : public Property
virtual void accept(PropertyVisitor& pv) { pv.apply(*this); }
/** Set the value.*/
void setValue(float v) { _uniform->set(v); }
virtual void setValue(float v) { _uniform->set(v); }
/** Get the value.*/
float getValue() const { float v; _uniform->get(v); return v; }
@ -198,9 +199,18 @@ class OSGVOLUME_EXPORT AlphaFuncProperty : public ScalarProperty
virtual void accept(PropertyVisitor& pv) { pv.apply(*this); }
virtual void setValue(float v);
osg::AlphaFunc* getAlphaFunc() { return _alphaFunc.get(); }
const osg::AlphaFunc* getAlphaFunc() const { return _alphaFunc.get(); }
protected:
virtual ~AlphaFuncProperty() {}
osg::ref_ptr<osg::AlphaFunc> _alphaFunc;
};
class OSGVOLUME_EXPORT MaximumIntensityProjectionProperty : public Property

View File

@ -183,7 +183,15 @@ void FixedFunctionTechnique::init()
stateset->setMode(GL_LIGHTING,osg::StateAttribute::ON);
stateset->setMode(GL_BLEND,osg::StateAttribute::ON);
stateset->setAttributeAndModes(new osg::AlphaFunc(osg::AlphaFunc::GREATER,alphaFuncValue), osg::StateAttribute::ON);
if (cpv._afProperty.valid())
{
stateset->setAttributeAndModes(cpv._afProperty->getAlphaFunc(), osg::StateAttribute::ON);
}
else
{
stateset->setAttributeAndModes(new osg::AlphaFunc(osg::AlphaFunc::GREATER,alphaFuncValue), osg::StateAttribute::ON);
}
osg::Material* material = new osg::Material;
material->setDiffuse(osg::Material::FRONT_AND_BACK,osg::Vec4(1.0f,1.0f,1.0f,1.0f));

View File

@ -106,11 +106,19 @@ IsoSurfaceProperty::IsoSurfaceProperty(const IsoSurfaceProperty& isp,const osg::
AlphaFuncProperty::AlphaFuncProperty(float value):
ScalarProperty("AlphaFuncValue",value)
{
_alphaFunc = new osg::AlphaFunc(osg::AlphaFunc::GREATER, value);
}
AlphaFuncProperty::AlphaFuncProperty(const AlphaFuncProperty& afp,const osg::CopyOp& copyop):
ScalarProperty(afp, copyop)
{
_alphaFunc = new osg::AlphaFunc(osg::AlphaFunc::GREATER, getValue());
}
void AlphaFuncProperty::setValue(float v)
{
_uniform->set(v);
_alphaFunc->setReferenceValue(v);
}
/////////////////////////////////////////////////////////////////////////////

View File

@ -300,8 +300,10 @@ void ShaderTechnique::init()
osg::Uniform* transpancy = new osg::Uniform("transparency",0.5f);
stateset->addUniform(transpancy);
osg::Uniform* alphaCutOff = new osg::Uniform("alphaCutOff",alphaFuncValue);
stateset->addUniform(alphaCutOff);
if (cpv._afProperty.valid())
{
stateset->addUniform(cpv._afProperty->getUniform());
}
stateset->setMode(GL_CULL_FACE, osg::StateAttribute::ON);

View File

@ -1,7 +1,7 @@
char volume_frag[] = "uniform sampler3D baseTexture;\n"
"uniform float sampleDensity;\n"
"uniform float transparency;\n"
"uniform float alphaCutOff;\n"
"uniform float AlphaFuncValue;\n"
"\n"
"varying vec4 cameraPos;\n"
"varying vec4 vertexPos;\n"
@ -74,7 +74,7 @@ char volume_frag[] = "uniform sampler3D baseTexture;\n"
" {\n"
" vec4 color = texture3D( baseTexture, texcoord);\n"
" float r = color[3]*transparency;\n"
" if (r>alphaCutOff)\n"
" if (r>AlphaFuncValue)\n"
" {\n"
" fragColor.xyz = fragColor.xyz*(1.0-r)+color.xyz*r;\n"
" fragColor.w += r;\n"
@ -92,7 +92,7 @@ char volume_frag[] = "uniform sampler3D baseTexture;\n"
" fragColor.w *= transparency;\n"
"\n"
" if (fragColor.w>1.0) fragColor.w = 1.0; \n"
" if (fragColor.w<alphaCutOff) discard;\n"
" if (fragColor.w<AlphaFuncValue) discard;\n"
" \n"
" gl_FragColor = fragColor;\n"
"}\n"

View File

@ -1,7 +1,7 @@
char volume_mip_frag[] = "uniform sampler3D baseTexture;\n"
"uniform float sampleDensity;\n"
"uniform float transparency;\n"
"uniform float alphaCutOff;\n"
"uniform float AlphaFuncValue;\n"
"\n"
"varying vec4 cameraPos;\n"
"varying vec4 vertexPos;\n"
@ -85,7 +85,7 @@ char volume_mip_frag[] = "uniform sampler3D baseTexture;\n"
" fragColor.w *= transparency;\n"
"\n"
" if (fragColor.w>1.0) fragColor.w = 1.0; \n"
" if (fragColor.w<alphaCutOff) discard;\n"
" if (fragColor.w<AlphaFuncValue) discard;\n"
" \n"
" gl_FragColor = fragColor;\n"
"}\n"

View File

@ -2,7 +2,7 @@ char volume_n_frag[] = "uniform sampler3D baseTexture;\n"
"uniform sampler3D normalMap;\n"
"uniform float sampleDensity;\n"
"uniform float transparency;\n"
"uniform float alphaCutOff;\n"
"uniform float AlphaFuncValue;\n"
"\n"
"varying vec4 cameraPos;\n"
"varying vec4 vertexPos;\n"
@ -103,7 +103,7 @@ char volume_n_frag[] = "uniform sampler3D baseTexture;\n"
"\n"
" float r = color[3]*transparency;\n"
"#endif \n"
" if (r>alphaCutOff)\n"
" if (r>AlphaFuncValue)\n"
" {\n"
" fragColor.xyz = fragColor.xyz*(1.0-r)+color.xyz*r;\n"
" fragColor.w += r;\n"

View File

@ -2,7 +2,7 @@ char volume_tf_frag[] = "uniform sampler3D baseTexture;\n"
"uniform sampler1D tfTexture;\n"
"uniform float sampleDensity;\n"
"uniform float transparency;\n"
"uniform float alphaCutOff;\n"
"uniform float AlphaFuncValue;\n"
"\n"
"varying vec4 cameraPos;\n"
"varying vec4 vertexPos;\n"
@ -77,7 +77,7 @@ char volume_tf_frag[] = "uniform sampler3D baseTexture;\n"
" vec4 color = texture1D( tfTexture, v);\n"
"\n"
" float r = color[3]*transparency;\n"
" if (r>alphaCutOff)\n"
" if (r>AlphaFuncValue)\n"
" {\n"
" fragColor.xyz = fragColor.xyz*(1.0-r)+color.xyz*r;\n"
" fragColor.w += r;\n"
@ -95,7 +95,7 @@ char volume_tf_frag[] = "uniform sampler3D baseTexture;\n"
" fragColor.w *= transparency;\n"
"\n"
" if (fragColor.w>1.0) fragColor.w = 1.0; \n"
" if (fragColor.w<alphaCutOff) discard;\n"
" if (fragColor.w<AlphaFuncValue) discard;\n"
" \n"
" gl_FragColor = fragColor;\n"
"}\n"

View File

@ -2,7 +2,7 @@ char volume_tf_mip_frag[] = "uniform sampler3D baseTexture;\n"
"uniform sampler1D tfTexture;\n"
"uniform float sampleDensity;\n"
"uniform float transparency;\n"
"uniform float alphaCutOff;\n"
"uniform float AlphaFuncValue;\n"
"\n"
"varying vec4 cameraPos;\n"
"varying vec4 vertexPos;\n"
@ -87,7 +87,7 @@ char volume_tf_mip_frag[] = "uniform sampler3D baseTexture;\n"
" fragColor.w *= transparency;\n"
"\n"
" if (fragColor.w>1.0) fragColor.w = 1.0; \n"
" if (fragColor.w<alphaCutOff) discard;\n"
" if (fragColor.w<AlphaFuncValue) discard;\n"
" gl_FragColor = fragColor;\n"
"}\n"
"\n";

View File

@ -3,7 +3,7 @@ char volume_tf_n_frag[] = "uniform sampler3D baseTexture;\n"
"uniform sampler1D tfTexture;\n"
"uniform float sampleDensity;\n"
"uniform float transparency;\n"
"uniform float alphaCutOff;\n"
"uniform float AlphaFuncValue;\n"
"\n"
"varying vec4 cameraPos;\n"
"varying vec4 vertexPos;\n"
@ -90,7 +90,7 @@ char volume_tf_n_frag[] = "uniform sampler3D baseTexture;\n"
" color.z *= lightScale;\n"
"\n"
" float r = normal[3]*transparency;\n"
" if (r>alphaCutOff)\n"
" if (r>AlphaFuncValue)\n"
" {\n"
" fragColor.xyz = fragColor.xyz*(1.0-r)+color.xyz*r;\n"
" fragColor.w += r;\n"