Added support for SampleDensityProperty and TransparencyProperty
This commit is contained in:
parent
87cd4530f5
commit
d46e0fcc79
@ -773,6 +773,7 @@ class FollowMouseCallback : public osgGA::GUIEventHandler, public osg::StateSet:
|
||||
case(osgGA::GUIEventAdapter::DRAG):
|
||||
{
|
||||
float v = (ea.getY()-ea.getYmin())/(ea.getYmax()-ea.getYmin());
|
||||
float v2 = v*v;
|
||||
|
||||
if (_updateAlphaCutOff && cpv._isoProperty.valid())
|
||||
{
|
||||
@ -785,6 +786,18 @@ class FollowMouseCallback : public osgGA::GUIEventHandler, public osg::StateSet:
|
||||
osg::notify(osg::NOTICE)<<"Setting afProperty to "<<v<<std::endl;
|
||||
cpv._afProperty->setValue(v);
|
||||
}
|
||||
|
||||
if (_updateTransparency && cpv._transparencyProperty.valid())
|
||||
{
|
||||
osg::notify(osg::NOTICE)<<"Setting transparency to "<<v2<<std::endl;
|
||||
cpv._transparencyProperty->setValue(v2);
|
||||
}
|
||||
|
||||
if (_updateSampleDensity && cpv._sampleDensityProperty.valid())
|
||||
{
|
||||
osg::notify(osg::NOTICE)<<"Setting sample density to "<<v2<<std::endl;
|
||||
cpv._sampleDensityProperty->setValue(v2);
|
||||
}
|
||||
}
|
||||
case(osgGA::GUIEventAdapter::KEYDOWN):
|
||||
{
|
||||
@ -1361,6 +1374,9 @@ int main( int argc, char **argv )
|
||||
break;
|
||||
}
|
||||
|
||||
layer->addProperty(new osgVolume::SampleDensityProperty(0.005));
|
||||
layer->addProperty(new osgVolume::TransparencyProperty(1.0));
|
||||
|
||||
|
||||
tile->setVolumeTechnique(new osgVolume::ShaderTechnique);
|
||||
}
|
||||
|
@ -31,6 +31,8 @@ class IsoSurfaceProperty;
|
||||
class MaximumIntensityProjectionProperty;
|
||||
class LightingProperty;
|
||||
class AlphaFuncProperty;
|
||||
class SampleDensityProperty;
|
||||
class TransparencyProperty;
|
||||
|
||||
class PropertyVisitor
|
||||
{
|
||||
@ -47,6 +49,8 @@ class PropertyVisitor
|
||||
virtual void apply(AlphaFuncProperty&) {}
|
||||
virtual void apply(MaximumIntensityProjectionProperty&) {}
|
||||
virtual void apply(LightingProperty&) {}
|
||||
virtual void apply(SampleDensityProperty&) {}
|
||||
virtual void apply(TransparencyProperty&) {}
|
||||
};
|
||||
|
||||
|
||||
@ -249,6 +253,41 @@ class OSGVOLUME_EXPORT LightingProperty : public Property
|
||||
};
|
||||
|
||||
|
||||
class OSGVOLUME_EXPORT SampleDensityProperty : public ScalarProperty
|
||||
{
|
||||
public:
|
||||
|
||||
SampleDensityProperty(float value=1.0);
|
||||
|
||||
SampleDensityProperty(const SampleDensityProperty& isp,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
|
||||
|
||||
META_Object(osgVolume, SampleDensityProperty);
|
||||
|
||||
virtual void accept(PropertyVisitor& pv) { pv.apply(*this); }
|
||||
|
||||
protected:
|
||||
|
||||
virtual ~SampleDensityProperty() {}
|
||||
};
|
||||
|
||||
class OSGVOLUME_EXPORT TransparencyProperty : public ScalarProperty
|
||||
{
|
||||
public:
|
||||
|
||||
TransparencyProperty(float value=1.0);
|
||||
|
||||
TransparencyProperty(const TransparencyProperty& isp,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
|
||||
|
||||
META_Object(osgVolume, TransparencyProperty);
|
||||
|
||||
virtual void accept(PropertyVisitor& pv) { pv.apply(*this); }
|
||||
|
||||
protected:
|
||||
|
||||
virtual ~TransparencyProperty() {}
|
||||
};
|
||||
|
||||
|
||||
class OSGVOLUME_EXPORT CollectPropertiesVisitor : public osgVolume::PropertyVisitor
|
||||
{
|
||||
public:
|
||||
@ -264,12 +303,16 @@ class OSGVOLUME_EXPORT CollectPropertiesVisitor : public osgVolume::PropertyVisi
|
||||
virtual void apply(AlphaFuncProperty& af);
|
||||
virtual void apply(MaximumIntensityProjectionProperty& mip);
|
||||
virtual void apply(LightingProperty& lp);
|
||||
virtual void apply(SampleDensityProperty& sdp);
|
||||
virtual void apply(TransparencyProperty& tp);
|
||||
|
||||
osg::ref_ptr<TransferFunctionProperty> _tfProperty;
|
||||
osg::ref_ptr<IsoSurfaceProperty> _isoProperty;
|
||||
osg::ref_ptr<AlphaFuncProperty> _afProperty;
|
||||
osg::ref_ptr<MaximumIntensityProjectionProperty> _mipProperty;
|
||||
osg::ref_ptr<LightingProperty> _lightingProperty;
|
||||
osg::ref_ptr<SampleDensityProperty> _sampleDensityProperty;
|
||||
osg::ref_ptr<TransparencyProperty> _transparencyProperty;
|
||||
|
||||
};
|
||||
|
||||
|
@ -147,6 +147,36 @@ LightingProperty::LightingProperty(const LightingProperty& isp,const osg::CopyOp
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SampleDensityProperty
|
||||
//
|
||||
SampleDensityProperty::SampleDensityProperty(float value):
|
||||
ScalarProperty("SampleDensityValue",value)
|
||||
{
|
||||
}
|
||||
|
||||
SampleDensityProperty::SampleDensityProperty(const SampleDensityProperty& isp,const osg::CopyOp& copyop):
|
||||
ScalarProperty(isp, copyop)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// TransparencyProperty
|
||||
//
|
||||
TransparencyProperty::TransparencyProperty(float value):
|
||||
ScalarProperty("TransparencyValue",value)
|
||||
{
|
||||
}
|
||||
|
||||
TransparencyProperty::TransparencyProperty(const TransparencyProperty& isp,const osg::CopyOp& copyop):
|
||||
ScalarProperty(isp, copyop)
|
||||
{
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// CollectPropertiesVisitor
|
||||
@ -169,3 +199,5 @@ void CollectPropertiesVisitor::apply(IsoSurfaceProperty& iso) { _isoProperty = &
|
||||
void CollectPropertiesVisitor::apply(AlphaFuncProperty& af) { _afProperty = ⁡ }
|
||||
void CollectPropertiesVisitor::apply(MaximumIntensityProjectionProperty& mip) { _mipProperty = &mip; }
|
||||
void CollectPropertiesVisitor::apply(LightingProperty& lp) { _lightingProperty = &lp; }
|
||||
void CollectPropertiesVisitor::apply(SampleDensityProperty& sdp) { _sampleDensityProperty = &sdp; }
|
||||
void CollectPropertiesVisitor::apply(TransparencyProperty& tp) { _transparencyProperty = &tp; }
|
||||
|
@ -294,16 +294,23 @@ void ShaderTechnique::init()
|
||||
}
|
||||
}
|
||||
|
||||
osg::Uniform* sampleDensity = new osg::Uniform("sampleDensity", 0.005f);
|
||||
stateset->addUniform(sampleDensity);
|
||||
if (cpv._sampleDensityProperty.valid())
|
||||
stateset->addUniform(cpv._sampleDensityProperty->getUniform());
|
||||
else
|
||||
stateset->addUniform(new osg::Uniform("SampleDensityValue",0.0005f));
|
||||
|
||||
|
||||
if (cpv._transparencyProperty.valid())
|
||||
stateset->addUniform(cpv._transparencyProperty->getUniform());
|
||||
else
|
||||
stateset->addUniform(new osg::Uniform("TransparencyValue",1.0f));
|
||||
|
||||
osg::Uniform* transpancy = new osg::Uniform("transparency",0.5f);
|
||||
stateset->addUniform(transpancy);
|
||||
|
||||
if (cpv._afProperty.valid())
|
||||
{
|
||||
stateset->addUniform(cpv._afProperty->getUniform());
|
||||
}
|
||||
else
|
||||
stateset->addUniform(new osg::Uniform("AlphaFuncValue",alphaFuncValue));
|
||||
|
||||
|
||||
stateset->setMode(GL_CULL_FACE, osg::StateAttribute::ON);
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
char volume_frag[] = "uniform sampler3D baseTexture;\n"
|
||||
"uniform float sampleDensity;\n"
|
||||
"uniform float transparency;\n"
|
||||
"uniform float SampleDensityValue;\n"
|
||||
"uniform float TransparencyValue;\n"
|
||||
"uniform float AlphaFuncValue;\n"
|
||||
"\n"
|
||||
"varying vec4 cameraPos;\n"
|
||||
@ -58,7 +58,7 @@ char volume_frag[] = "uniform sampler3D baseTexture;\n"
|
||||
" }\n"
|
||||
"\n"
|
||||
" const float max_iteratrions = 2048.0;\n"
|
||||
" float num_iterations = ceil(length(te-t0)/sampleDensity);\n"
|
||||
" float num_iterations = ceil(length(te-t0)/SampleDensityValue);\n"
|
||||
" if (num_iterations<2.0) num_iterations = 2.0;\n"
|
||||
"\n"
|
||||
" if (num_iterations>max_iteratrions) \n"
|
||||
@ -73,7 +73,7 @@ char volume_frag[] = "uniform sampler3D baseTexture;\n"
|
||||
" while(num_iterations>0.0)\n"
|
||||
" {\n"
|
||||
" vec4 color = texture3D( baseTexture, texcoord);\n"
|
||||
" float r = color[3]*transparency;\n"
|
||||
" float r = color[3]*TransparencyValue;\n"
|
||||
" if (r>AlphaFuncValue)\n"
|
||||
" {\n"
|
||||
" fragColor.xyz = fragColor.xyz*(1.0-r)+color.xyz*r;\n"
|
||||
@ -89,7 +89,7 @@ char volume_frag[] = "uniform sampler3D baseTexture;\n"
|
||||
" --num_iterations;\n"
|
||||
" }\n"
|
||||
"\n"
|
||||
" fragColor.w *= transparency;\n"
|
||||
" fragColor.w *= TransparencyValue;\n"
|
||||
"\n"
|
||||
" if (fragColor.w>1.0) fragColor.w = 1.0; \n"
|
||||
" if (fragColor.w<AlphaFuncValue) discard;\n"
|
||||
|
@ -1,6 +1,6 @@
|
||||
char volume_iso_frag[] = "uniform sampler3D baseTexture;\n"
|
||||
"uniform float sampleDensity;\n"
|
||||
"uniform float transparency;\n"
|
||||
"uniform float SampleDensityValue;\n"
|
||||
"uniform float TransparencyValue;\n"
|
||||
"uniform float IsoSurfaceValue;\n"
|
||||
"\n"
|
||||
"varying vec4 cameraPos;\n"
|
||||
@ -61,7 +61,7 @@ char volume_iso_frag[] = "uniform sampler3D baseTexture;\n"
|
||||
" }\n"
|
||||
"\n"
|
||||
" const float max_iteratrions = 2048.0;\n"
|
||||
" float num_iterations = ceil(length(te-t0)/sampleDensity);\n"
|
||||
" float num_iterations = ceil(length(te-t0)/SampleDensityValue);\n"
|
||||
" if (num_iterations<2.0) num_iterations = 2.0;\n"
|
||||
"\n"
|
||||
" if (num_iterations>max_iteratrions) \n"
|
||||
|
@ -1,6 +1,6 @@
|
||||
char volume_mip_frag[] = "uniform sampler3D baseTexture;\n"
|
||||
"uniform float sampleDensity;\n"
|
||||
"uniform float transparency;\n"
|
||||
"uniform float SampleDensityValue;\n"
|
||||
"uniform float TransparencyValue;\n"
|
||||
"uniform float AlphaFuncValue;\n"
|
||||
"\n"
|
||||
"varying vec4 cameraPos;\n"
|
||||
@ -58,7 +58,7 @@ char volume_mip_frag[] = "uniform sampler3D baseTexture;\n"
|
||||
" }\n"
|
||||
"\n"
|
||||
" const float max_iteratrions = 2048.0;\n"
|
||||
" float num_iterations = ceil(length(te-t0)/sampleDensity);\n"
|
||||
" float num_iterations = ceil(length(te-t0)/SampleDensityValue);\n"
|
||||
" if (num_iterations<2.0) num_iterations = 2.0;\n"
|
||||
"\n"
|
||||
" if (num_iterations>max_iteratrions) \n"
|
||||
@ -82,7 +82,7 @@ char volume_mip_frag[] = "uniform sampler3D baseTexture;\n"
|
||||
" --num_iterations;\n"
|
||||
" }\n"
|
||||
"\n"
|
||||
" fragColor.w *= transparency;\n"
|
||||
" fragColor.w *= TransparencyValue;\n"
|
||||
"\n"
|
||||
" if (fragColor.w>1.0) fragColor.w = 1.0; \n"
|
||||
" if (fragColor.w<AlphaFuncValue) discard;\n"
|
||||
|
@ -1,120 +0,0 @@
|
||||
char volume_n_frag[] = "uniform sampler3D baseTexture;\n"
|
||||
"uniform sampler3D normalMap;\n"
|
||||
"uniform float sampleDensity;\n"
|
||||
"uniform float transparency;\n"
|
||||
"uniform float AlphaFuncValue;\n"
|
||||
"\n"
|
||||
"varying vec4 cameraPos;\n"
|
||||
"varying vec4 vertexPos;\n"
|
||||
"varying mat4 texgen;\n"
|
||||
"\n"
|
||||
"void main(void)\n"
|
||||
"{ \n"
|
||||
"\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"
|
||||
" {\n"
|
||||
" // do nothing... te inside volume\n"
|
||||
" }\n"
|
||||
" else\n"
|
||||
" {\n"
|
||||
" if (te.x<0.0)\n"
|
||||
" {\n"
|
||||
" float r = -te.x / (t0.x-te.x);\n"
|
||||
" te = te + (t0-te)*r;\n"
|
||||
" }\n"
|
||||
"\n"
|
||||
" if (te.x>1.0)\n"
|
||||
" {\n"
|
||||
" float r = (1.0-te.x) / (t0.x-te.x);\n"
|
||||
" te = te + (t0-te)*r;\n"
|
||||
" }\n"
|
||||
"\n"
|
||||
" if (te.y<0.0)\n"
|
||||
" {\n"
|
||||
" float r = -te.y / (t0.y-te.y);\n"
|
||||
" te = te + (t0-te)*r;\n"
|
||||
" }\n"
|
||||
"\n"
|
||||
" if (te.y>1.0)\n"
|
||||
" {\n"
|
||||
" float r = (1.0-te.y) / (t0.y-te.y);\n"
|
||||
" te = te + (t0-te)*r;\n"
|
||||
" }\n"
|
||||
"\n"
|
||||
" if (te.z<0.0)\n"
|
||||
" {\n"
|
||||
" float r = -te.z / (t0.z-te.z);\n"
|
||||
" te = te + (t0-te)*r;\n"
|
||||
" }\n"
|
||||
"\n"
|
||||
" if (te.z>1.0)\n"
|
||||
" {\n"
|
||||
" float r = (1.0-te.z) / (t0.z-te.z);\n"
|
||||
" te = te + (t0-te)*r;\n"
|
||||
" }\n"
|
||||
" }\n"
|
||||
"\n"
|
||||
" const float max_iteratrions = 2048.0;\n"
|
||||
" float num_iterations = ceil(length(te-t0)/sampleDensity);\n"
|
||||
" if (num_iterations<2.0) num_iterations = 2.0;\n"
|
||||
"\n"
|
||||
" if (num_iterations>max_iteratrions) \n"
|
||||
" {\n"
|
||||
" num_iterations = max_iteratrions;\n"
|
||||
" }\n"
|
||||
"\n"
|
||||
" vec3 deltaTexCoord=(te-t0)/float(num_iterations-1.0);\n"
|
||||
" vec3 texcoord = t0;\n"
|
||||
"\n"
|
||||
" vec4 fragColor = vec4(0.0, 0.0, 0.0, 0.0); \n"
|
||||
" while(num_iterations>0.0)\n"
|
||||
" {\n"
|
||||
" vec4 normal = texture3D( normalMap, texcoord);\n"
|
||||
"#if 1\n"
|
||||
" vec4 color = texture3D( baseTexture, texcoord);\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"
|
||||
"\n"
|
||||
" float r = normal[3]*transparency;\n"
|
||||
"#else\n"
|
||||
" vec4 color = texture3D( normalMap, texcoord);\n"
|
||||
" color.x = color.x*2.0 - 1.0;\n"
|
||||
" color.y = color.y*2.0 - 1.0;\n"
|
||||
" color.z = color.z*2.0 - 1.0;\n"
|
||||
" \n"
|
||||
" float lightScale = 0.1 + max(dot(color.xyz, eyeDirection), 0.0);\n"
|
||||
" color.x = lightScale;\n"
|
||||
" color.y = lightScale;\n"
|
||||
" color.z = lightScale;\n"
|
||||
"\n"
|
||||
" float r = color[3]*transparency;\n"
|
||||
"#endif \n"
|
||||
" if (r>AlphaFuncValue)\n"
|
||||
" {\n"
|
||||
" fragColor.xyz = fragColor.xyz*(1.0-r)+color.xyz*r;\n"
|
||||
" fragColor.w += r;\n"
|
||||
" }\n"
|
||||
" texcoord += deltaTexCoord; \n"
|
||||
"\n"
|
||||
" --num_iterations;\n"
|
||||
" }\n"
|
||||
"\n"
|
||||
" if (fragColor.w>1.0) fragColor.w = 1.0; \n"
|
||||
" if (fragColor.w==0.0) discard;\n"
|
||||
" gl_FragColor = fragColor;\n"
|
||||
"}\n"
|
||||
"\n";
|
@ -1,7 +1,7 @@
|
||||
char volume_tf_frag[] = "uniform sampler3D baseTexture;\n"
|
||||
"uniform sampler1D tfTexture;\n"
|
||||
"uniform float sampleDensity;\n"
|
||||
"uniform float transparency;\n"
|
||||
"uniform float SampleDensityValue;\n"
|
||||
"uniform float TransparencyValue;\n"
|
||||
"uniform float AlphaFuncValue;\n"
|
||||
"\n"
|
||||
"varying vec4 cameraPos;\n"
|
||||
@ -59,7 +59,7 @@ char volume_tf_frag[] = "uniform sampler3D baseTexture;\n"
|
||||
" }\n"
|
||||
"\n"
|
||||
" const float max_iteratrions = 2048.0;\n"
|
||||
" float num_iterations = ceil(length(te-t0)/sampleDensity);\n"
|
||||
" float num_iterations = ceil(length(te-t0)/SampleDensityValue);\n"
|
||||
" if (num_iterations<2.0) num_iterations = 2.0;\n"
|
||||
"\n"
|
||||
" if (num_iterations>max_iteratrions) \n"
|
||||
@ -76,7 +76,7 @@ char volume_tf_frag[] = "uniform sampler3D baseTexture;\n"
|
||||
" float v = texture3D( baseTexture, texcoord).a;\n"
|
||||
" vec4 color = texture1D( tfTexture, v);\n"
|
||||
"\n"
|
||||
" float r = color[3]*transparency;\n"
|
||||
" float r = color[3]*TransparencyValue;\n"
|
||||
" if (r>AlphaFuncValue)\n"
|
||||
" {\n"
|
||||
" fragColor.xyz = fragColor.xyz*(1.0-r)+color.xyz*r;\n"
|
||||
@ -92,7 +92,7 @@ char volume_tf_frag[] = "uniform sampler3D baseTexture;\n"
|
||||
" --num_iterations;\n"
|
||||
" }\n"
|
||||
"\n"
|
||||
" fragColor.w *= transparency;\n"
|
||||
" fragColor.w *= TransparencyValue;\n"
|
||||
"\n"
|
||||
" if (fragColor.w>1.0) fragColor.w = 1.0; \n"
|
||||
" if (fragColor.w<AlphaFuncValue) discard;\n"
|
||||
|
@ -1,7 +1,7 @@
|
||||
char volume_tf_iso_frag[] = "uniform sampler3D baseTexture;\n"
|
||||
"uniform sampler1D tfTexture;\n"
|
||||
"uniform float sampleDensity;\n"
|
||||
"uniform float transparency;\n"
|
||||
"uniform float SampleDensityValue;\n"
|
||||
"uniform float TransparencyValue;\n"
|
||||
"uniform float IsoSurfaceValue;\n"
|
||||
"\n"
|
||||
"varying vec4 cameraPos;\n"
|
||||
@ -61,7 +61,7 @@ char volume_tf_iso_frag[] = "uniform sampler3D baseTexture;\n"
|
||||
" }\n"
|
||||
"\n"
|
||||
" const float max_iteratrions = 2048.0;\n"
|
||||
" float num_iterations = ceil(length(te-t0)/sampleDensity);\n"
|
||||
" float num_iterations = ceil(length(te-t0)/SampleDensityValue);\n"
|
||||
" if (num_iterations<2.0) num_iterations = 2.0;\n"
|
||||
" \n"
|
||||
" if (num_iterations>max_iteratrions) \n"
|
||||
|
@ -1,7 +1,7 @@
|
||||
char volume_tf_mip_frag[] = "uniform sampler3D baseTexture;\n"
|
||||
"uniform sampler1D tfTexture;\n"
|
||||
"uniform float sampleDensity;\n"
|
||||
"uniform float transparency;\n"
|
||||
"uniform float SampleDensityValue;\n"
|
||||
"uniform float TransparencyValue;\n"
|
||||
"uniform float AlphaFuncValue;\n"
|
||||
"\n"
|
||||
"varying vec4 cameraPos;\n"
|
||||
@ -59,7 +59,7 @@ char volume_tf_mip_frag[] = "uniform sampler3D baseTexture;\n"
|
||||
" }\n"
|
||||
"\n"
|
||||
" const float max_iteratrions = 2048.0;\n"
|
||||
" float num_iterations = ceil(length(te-t0)/sampleDensity);\n"
|
||||
" float num_iterations = ceil(length(te-t0)/SampleDensityValue);\n"
|
||||
" if (num_iterations<2.0) num_iterations = 2.0;\n"
|
||||
" \n"
|
||||
" if (num_iterations>max_iteratrions) \n"
|
||||
@ -84,7 +84,7 @@ char volume_tf_mip_frag[] = "uniform sampler3D baseTexture;\n"
|
||||
" --num_iterations;\n"
|
||||
" }\n"
|
||||
"\n"
|
||||
" fragColor.w *= transparency;\n"
|
||||
" fragColor.w *= TransparencyValue;\n"
|
||||
"\n"
|
||||
" if (fragColor.w>1.0) fragColor.w = 1.0; \n"
|
||||
" if (fragColor.w<AlphaFuncValue) discard;\n"
|
||||
|
@ -1,107 +0,0 @@
|
||||
char volume_tf_n_frag[] = "uniform sampler3D baseTexture;\n"
|
||||
"uniform sampler3D normalMap;\n"
|
||||
"uniform sampler1D tfTexture;\n"
|
||||
"uniform float sampleDensity;\n"
|
||||
"uniform float transparency;\n"
|
||||
"uniform float AlphaFuncValue;\n"
|
||||
"\n"
|
||||
"varying vec4 cameraPos;\n"
|
||||
"varying vec4 vertexPos;\n"
|
||||
"varying mat4 texgen;\n"
|
||||
"\n"
|
||||
"void main(void)\n"
|
||||
"{ \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"
|
||||
" {\n"
|
||||
" // do nothing... te inside volume\n"
|
||||
" }\n"
|
||||
" else\n"
|
||||
" {\n"
|
||||
" if (te.x<0.0)\n"
|
||||
" {\n"
|
||||
" float r = -te.x / (t0.x-te.x);\n"
|
||||
" te = te + (t0-te)*r;\n"
|
||||
" }\n"
|
||||
"\n"
|
||||
" if (te.x>1.0)\n"
|
||||
" {\n"
|
||||
" float r = (1.0-te.x) / (t0.x-te.x);\n"
|
||||
" te = te + (t0-te)*r;\n"
|
||||
" }\n"
|
||||
"\n"
|
||||
" if (te.y<0.0)\n"
|
||||
" {\n"
|
||||
" float r = -te.y / (t0.y-te.y);\n"
|
||||
" te = te + (t0-te)*r;\n"
|
||||
" }\n"
|
||||
"\n"
|
||||
" if (te.y>1.0)\n"
|
||||
" {\n"
|
||||
" float r = (1.0-te.y) / (t0.y-te.y);\n"
|
||||
" te = te + (t0-te)*r;\n"
|
||||
" }\n"
|
||||
"\n"
|
||||
" if (te.z<0.0)\n"
|
||||
" {\n"
|
||||
" float r = -te.z / (t0.z-te.z);\n"
|
||||
" te = te + (t0-te)*r;\n"
|
||||
" }\n"
|
||||
"\n"
|
||||
" if (te.z>1.0)\n"
|
||||
" {\n"
|
||||
" float r = (1.0-te.z) / (t0.z-te.z);\n"
|
||||
" te = te + (t0-te)*r;\n"
|
||||
" }\n"
|
||||
" }\n"
|
||||
"\n"
|
||||
" const float max_iteratrions = 2048.0;\n"
|
||||
" float num_iterations = ceil(length(te-t0)/sampleDensity);\n"
|
||||
" if (num_iterations<2.0) num_iterations = 2.0;\n"
|
||||
" \n"
|
||||
" if (num_iterations>max_iteratrions) \n"
|
||||
" {\n"
|
||||
" num_iterations = max_iteratrions;\n"
|
||||
" }\n"
|
||||
"\n"
|
||||
" vec3 deltaTexCoord=(te-t0)/float(num_iterations-1.0);\n"
|
||||
" vec3 texcoord = t0;\n"
|
||||
"\n"
|
||||
" vec4 fragColor = vec4(0.0, 0.0, 0.0, 0.0); \n"
|
||||
" while(num_iterations>0.0)\n"
|
||||
" {\n"
|
||||
" vec4 normal = texture3D( normalMap, texcoord);\n"
|
||||
" float v = normal.a; // texture3D( baseTexture, texcoord).s;\n"
|
||||
" vec4 color = texture1D( tfTexture, v);\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"
|
||||
"\n"
|
||||
" float r = normal[3]*transparency;\n"
|
||||
" if (r>AlphaFuncValue)\n"
|
||||
" {\n"
|
||||
" fragColor.xyz = fragColor.xyz*(1.0-r)+color.xyz*r;\n"
|
||||
" fragColor.w += r;\n"
|
||||
" }\n"
|
||||
" texcoord += deltaTexCoord; \n"
|
||||
"\n"
|
||||
" --num_iterations;\n"
|
||||
" }\n"
|
||||
"\n"
|
||||
" if (fragColor.w>1.0) fragColor.w = 1.0; \n"
|
||||
" if (fragColor.w==0.0) discard;\n"
|
||||
" gl_FragColor = fragColor;\n"
|
||||
"}\n"
|
||||
"\n";
|
Loading…
Reference in New Issue
Block a user