Updated shaders

This commit is contained in:
Robert Osfield 2008-09-29 18:30:17 +00:00
parent c03b64731b
commit 66c857b645
4 changed files with 43 additions and 24 deletions

View File

@ -760,7 +760,7 @@ class FollowMouseCallback : public osgGA::GUIEventHandler, public osg::StateSet:
if (_updateSampleDensity && (uniform = stateset->getUniform("sampleDensity"))) if (_updateSampleDensity && (uniform = stateset->getUniform("sampleDensity")))
{ {
float value = powf(v,5); float value = powf(v,5);
osg::notify(osg::NOTICE)<<"sampleDensity = "<<value<<std::endl; osg::notify(osg::INFO)<<"sampleDensity = "<<value<<std::endl;
uniform->set(value); uniform->set(value);
} }
} }
@ -1061,7 +1061,7 @@ osg::Node* createShaderModel(ShadingModel shadingModel,
} }
} }
osg::Uniform* sampleDensity = new osg::Uniform("sampleDensity", 0.01f); osg::Uniform* sampleDensity = new osg::Uniform("sampleDensity", 0.005f);
stateset->addUniform(sampleDensity); stateset->addUniform(sampleDensity);
osg::Uniform* transpancy = new osg::Uniform("transparency",0.5f); osg::Uniform* transpancy = new osg::Uniform("transparency",0.5f);
@ -1794,7 +1794,10 @@ int main( int argc, char **argv )
osg::ref_ptr<osgGA::KeySwitchMatrixManipulator> keyswitchManipulator = new osgGA::KeySwitchMatrixManipulator; osg::ref_ptr<osgGA::KeySwitchMatrixManipulator> keyswitchManipulator = new osgGA::KeySwitchMatrixManipulator;
keyswitchManipulator->addMatrixManipulator( '1', "Trackball", new osgGA::TrackballManipulator() ); keyswitchManipulator->addMatrixManipulator( '1', "Trackball", new osgGA::TrackballManipulator() );
keyswitchManipulator->addMatrixManipulator( '2', "Flight", new osgGA::FlightManipulator() );
osgGA::FlightManipulator* flightManipulator = new osgGA::FlightManipulator();
flightManipulator->setYawControlMode(osgGA::FlightManipulator::NO_AUTOMATIC_YAW);
keyswitchManipulator->addMatrixManipulator( '2', "Flight", flightManipulator );
viewer.setCameraManipulator( keyswitchManipulator.get() ); viewer.setCameraManipulator( keyswitchManipulator.get() );
} }
@ -2082,6 +2085,7 @@ int main( int argc, char **argv )
ySize = (*sizeItr)->t(); ySize = (*sizeItr)->t();
zSize = (*sizeItr)->r(); zSize = (*sizeItr)->r();
++sizeItr; ++sizeItr;
for(;sizeItr != images.end(); ++sizeItr) for(;sizeItr != images.end(); ++sizeItr)
{ {
if ((*sizeItr)->s() != xSize || if ((*sizeItr)->s() != xSize ||
@ -2094,25 +2098,30 @@ int main( int argc, char **argv )
} }
#if 0 #if 1
osg::RefMatrix* matrix = dynamic_cast<osg::RefMatrix*>(image_3d->getUserData()); osg::RefMatrix* matrix = dynamic_cast<osg::RefMatrix*>(images.front()->getUserData());
if (matrix) if (matrix)
{ {
osg::notify(osg::NOTICE)<<"Image has Matrix = "<<*matrix<<std::endl; osg::notify(osg::NOTICE)<<"Image has Matrix = "<<*matrix<<std::endl;
xSize = image_3d->s() * (*matrix)(0,0); xSize = xSize * (*matrix)(0,0);
ySize = image_3d->t() * (*matrix)(1,1); ySize = ySize * (*matrix)(1,1);
zSize = image_3d->r() * (*matrix)(2,2); zSize = zSize * (*matrix)(2,2);
} }
#else
#endif #endif
osg::Vec4 minValue, maxValue; osg::Vec4 minValue, maxValue;
bool computeMinMax = false; bool computeMinMax = false;
for(Images::iterator itr = images.begin(); for(Images::iterator itr = images.begin();
itr != images.end(); itr != images.end();
++itr) ++itr)
{ {
#if 0
osg::RefMatrix* matrix = dynamic_cast<osg::RefMatrix*>((*itr)->getUserData());
if (matrix)
{
std::cout<<"matrix = "<<*matrix<<std::endl;
}
#endif
if (osgVolume::computeMinMax(itr->get(), minValue, maxValue)) computeMinMax = true; if (osgVolume::computeMinMax(itr->get(), minValue, maxValue)) computeMinMax = true;
} }

View File

@ -59,7 +59,7 @@ char volume_frag[] = "uniform sampler3D baseTexture;\n"
"\n" "\n"
" const float max_iteratrions = 2048.0;\n" " const float max_iteratrions = 2048.0;\n"
" float num_iterations = ceil(length(te-t0)/sampleDensity);\n" " float num_iterations = ceil(length(te-t0)/sampleDensity);\n"
" if (num_iterations<2) num_iterations = 2.0;\n" " if (num_iterations<2.0) num_iterations = 2.0;\n"
"\n" "\n"
" if (num_iterations>max_iteratrions) \n" " if (num_iterations>max_iteratrions) \n"
" {\n" " {\n"
@ -79,13 +79,21 @@ char volume_frag[] = "uniform sampler3D baseTexture;\n"
" fragColor.xyz = fragColor.xyz*(1.0-r)+color.xyz*r;\n" " fragColor.xyz = fragColor.xyz*(1.0-r)+color.xyz*r;\n"
" fragColor.w += r;\n" " fragColor.w += r;\n"
" }\n" " }\n"
"\n"
" if (fragColor.w<color.w)\n"
" {\n"
" fragColor = color;\n"
" }\n"
" texcoord += deltaTexCoord; \n" " texcoord += deltaTexCoord; \n"
"\n" "\n"
" --num_iterations;\n" " --num_iterations;\n"
" }\n" " }\n"
"\n" "\n"
" fragColor.w *= transparency;\n"
"\n"
" if (fragColor.w>1.0) fragColor.w = 1.0; \n" " if (fragColor.w>1.0) fragColor.w = 1.0; \n"
" if (fragColor.w==0.0) discard;\n" " if (fragColor.w<alphaCutOff) discard;\n"
" \n"
" gl_FragColor = fragColor;\n" " gl_FragColor = fragColor;\n"
"}\n" "}\n"
"\n"; "\n";

View File

@ -60,34 +60,43 @@ char volume_tf_frag[] = "uniform sampler3D baseTexture;\n"
"\n" "\n"
" const float max_iteratrions = 2048.0;\n" " const float max_iteratrions = 2048.0;\n"
" float num_iterations = ceil(length(te-t0)/sampleDensity);\n" " float num_iterations = ceil(length(te-t0)/sampleDensity);\n"
" if (num_iterations<2) num_iterations = 2.0;\n" " if (num_iterations<2.0) num_iterations = 2.0;\n"
"\n" "\n"
" if (num_iterations>max_iteratrions) \n" " if (num_iterations>max_iteratrions) \n"
" {\n" " {\n"
" num_iterations = max_iteratrions;\n" " num_iterations = max_iteratrions;\n"
" }\n" " }\n"
"\n" "\n"
" vec3 deltaTexCoord=(te-t0)/float(num_iterations-1);\n" " vec3 deltaTexCoord=(te-t0)/float(num_iterations-1.0);\n"
" vec3 texcoord = t0;\n" " vec3 texcoord = t0;\n"
"\n" "\n"
" vec4 fragColor = vec4(0.0, 0.0, 0.0, 0.0); \n" " vec4 fragColor = vec4(0.0, 0.0, 0.0, 0.0); \n"
" while(num_iterations>0.0)\n" " while(num_iterations>0.0)\n"
" {\n" " {\n"
" float v = texture3D( baseTexture, texcoord).s;\n" " float v = texture3D( baseTexture, texcoord).a;\n"
" vec4 color = texture1D( tfTexture, v);\n" " vec4 color = texture1D( tfTexture, v);\n"
"\n"
" float r = color[3]*transparency;\n" " float r = color[3]*transparency;\n"
" if (r>alphaCutOff)\n" " if (r>alphaCutOff)\n"
" {\n" " {\n"
" fragColor.xyz = fragColor.xyz*(1.0-r)+color.xyz*r;\n" " fragColor.xyz = fragColor.xyz*(1.0-r)+color.xyz*r;\n"
" fragColor.w += r;\n" " fragColor.w += r;\n"
" }\n" " }\n"
"\n"
" if (fragColor.w<color.w)\n"
" {\n"
" fragColor = color;\n"
" }\n"
" texcoord += deltaTexCoord; \n" " texcoord += deltaTexCoord; \n"
"\n" "\n"
" --num_iterations;\n" " --num_iterations;\n"
" }\n" " }\n"
"\n" "\n"
" fragColor.w *= transparency;\n"
"\n"
" if (fragColor.w>1.0) fragColor.w = 1.0; \n" " if (fragColor.w>1.0) fragColor.w = 1.0; \n"
" if (fragColor.w==0.0) discard;\n" " if (fragColor.w<alphaCutOff) discard;\n"
" \n"
" gl_FragColor = fragColor;\n" " gl_FragColor = fragColor;\n"
"}\n" "}\n"
"\n"; "\n";

View File

@ -106,16 +106,9 @@ char volume_tf_iso_frag[] = "uniform sampler3D baseTexture;\n"
"\n" "\n"
" float lightScale = 0.1 + abs(dot(normal.xyz, eyeDirection));\n" " float lightScale = 0.1 + abs(dot(normal.xyz, eyeDirection));\n"
" \n" " \n"
" \n"
"#if 0\n"
" color.x *= lightScale;\n" " color.x *= lightScale;\n"
" color.y *= lightScale;\n" " color.y *= lightScale;\n"
" color.z *= lightScale;\n" " color.z *= lightScale;\n"
"#else\n"
" color.x = lightScale;\n"
" color.y = lightScale;\n"
" color.z = lightScale;\n"
"#endif\n"
"\n" "\n"
" fragColor = color;\n" " fragColor = color;\n"
" \n" " \n"