Commit 3eab9b64 authored by Dirk Albrecht's avatar Dirk Albrecht
Browse files

[ADD]Uniforms for boundingbox positions to compute fibersize. Defines are used...

[ADD]Uniforms for boundingbox positions to compute fibersize. Defines are used to switch between pointsprites and quadstrips.
parent 0cee8749
......@@ -304,6 +304,7 @@ void WMFiberDisplay::updateRenderModes()
m_tubeDrawable->setUseTubes( true );
m_tubeDrawable->setRootState(rootState);
m_shaderTubes->apply( m_osgNode );
m_tubeDrawable->setWShader(m_shaderTubes);
rootState->addUniform( osg::ref_ptr<osg::Uniform>( new osg::Uniform( "globalColor", 1 ) ) );
m_uniformTubeThickness = osg::ref_ptr<osg::Uniform>( new osg::Uniform( "u_thickness", static_cast<float>( m_tubeThickness->get() ) ) );
rootState->addUniform( m_uniformTubeThickness );
......
......@@ -184,64 +184,12 @@ void WTubeDrawable::setDataset( boost::shared_ptr< const WDataSetFibers > datase
}
}
/*
m_tubeVerts = boost::shared_ptr< std::vector< float > >(new std::vector< float >());
m_tubeTangents = boost::shared_ptr< std::vector< float > >(new std::vector< float >());
m_tubeTexCoords = boost::shared_ptr< std::vector< float > >(new std::vector< float >());
m_pointTexCoords = boost::shared_ptr< std::vector< float > >(new std::vector< float >());
m_tubeColors = boost::shared_ptr< std::vector< float > >(new std::vector< float >());
m_tubeVerts->resize(2*verts->size());
m_tubeTangents->resize(2*verts->size());
m_tubeTexCoords->resize(4*verts->size()/3);
m_tubeColors->resize(2*verts->size());
m_pointTexCoords->resize(2*verts->size()/3);
size_t tmp = 0;
size_t tmpTex = 0;
size_t tmpTexPoints = 0;
int stride = 3;
std::vector< size_t >::iterator itPointsPerLine = pointsPerLine->begin();
int k = (*itPointsPerLine);
for ( size_t i = 0; i < verts->size(); ++i )
{
if(stride == 0)
{
m_tubeTexCoords->at( tmpTex ) = -1.0f;
m_tubeTexCoords->at( tmpTex + 1) = 0.0f;
m_tubeTexCoords->at( tmpTex + 2 ) = 1.0f;
m_tubeTexCoords->at( tmpTex + 3 ) = 1.0f;
if(k == 1 || k == (*itPointsPerLine))
{
m_tubeTexCoords->at( tmpTexPoints ) = 0.0f;
m_tubeTexCoords->at( tmpTexPoints + 1) = 0.0f;
}
else
{
m_tubeTexCoords->at( tmpTexPoints ) = 0.0f;
m_tubeTexCoords->at( tmpTexPoints + 1) = 1.0f;
}
tmp += 3;
tmpTex += 4;
stride = 3;
}
m_tubeVerts->at(tmp) = verts->at(i);
m_tubeVerts->at(tmp+3) = verts->at(i);
m_tubeTangents->at(tmp) = tangents->at(i);
m_tubeTangents->at(tmp+3) = tangents->at(i);
m_tubeColors->at(tmp) = colors->at(i);
m_tubeColors->at(tmp+3) = colors->at(i);
--stride;
}
*/
}
void WTubeDrawable::setUseTubes( bool flag )
{
m_useTubes = flag;
}
void WTubeDrawable::setColoringMode( bool globalColoring )
......@@ -259,6 +207,11 @@ void WTubeDrawable::setCustomColoring( bool custom )
m_customColoring = custom;
}
void WTubeDrawable::setWShader(osg::ref_ptr< WShader > shaderTubes)
{
m_shaderTubes = shaderTubes;
}
void WTubeDrawable::setBoundingBox( const osg::BoundingBox & bb )
{
setBound( bb );
......@@ -310,6 +263,12 @@ void WTubeDrawable::createTextures(osg::StateSet* m_rootState) const
create2DTexDiffuseLightning(m_rootState);
create2DTexSpecularLightning(m_rootState);
const osg::BoundingBox & bb = this->getBound();
osg::Uniform* nearPos = new osg::Uniform("nearPos",osg::Vec3(bb.xMin(),bb.yMin(),bb.zMin()));
osg::Uniform* farPos = new osg::Uniform("farPos",osg::Vec3(bb.xMax(),bb.yMax(),bb.zMax()));
m_rootState->addUniform(nearPos);
m_rootState->addUniform(farPos);
}
void WTubeDrawable::create2DTexDiffuseLightning(osg::StateSet* m_rootState) const
......@@ -432,7 +391,6 @@ void WTubeDrawable::create1DTextureRectLightning(osg::StateSet* m_rootState) con
m_rootState->setTextureAttribute(1,texture,osg::StateAttribute::OVERRIDE);
m_rootState->setTextureMode(1,GL_TEXTURE_1D,osg::StateAttribute::ON|osg::StateAttribute::OVERRIDE);
m_rootState->addUniform(osg::ref_ptr<osg::Uniform>( new osg::Uniform( "texture", 1 ) ) );
}
......@@ -509,7 +467,8 @@ void WTubeDrawable::drawTubes( osg::RenderInfo& renderInfo ) const
}
m_uniformViewportHeight->set( static_cast<int>( (*renderInfo.getCurrentCamera()->getViewport()).height() ) );
m_uniformViewportWidth->set( static_cast<int>( (*renderInfo.getCurrentCamera()->getViewport()).width() ) );
m_rootState->addUniform(m_uniformViewportHeight);
m_rootState->addUniform(m_uniformViewportWidth);
osg::State& state = *renderInfo.getState();
......@@ -524,6 +483,8 @@ void WTubeDrawable::drawTubes( osg::RenderInfo& renderInfo ) const
glDisable(GL_LIGHTING);
glEnable(GL_BLEND);
//m_shaderTubes->setDefine(USE_QUADSTRIP);
for ( size_t i = 0; i < active->size(); ++i )
{
if ( (*active)[i] )
......@@ -532,6 +493,8 @@ void WTubeDrawable::drawTubes( osg::RenderInfo& renderInfo ) const
}
}
//m_shaderTubes->eraseDefine(USE_QUADSTRIP);
//osg::TexEnv* texEnvPS = new osg::TexEnv( osg::TexEnv::REPLACE);
//osg::AlphaFunc* alphaFunc = new osg::AlphaFunc(osg::AlphaFunc::NOTEQUAL,0.0f);
......@@ -539,6 +502,8 @@ void WTubeDrawable::drawTubes( osg::RenderInfo& renderInfo ) const
//state.setModeValidity(GL_ALPHA_TEST, osg::StateAttribute::ON);
//state.setModeValidity(GL_POINT_SPRITE, osg::StateAttribute::ON);
m_shaderTubes->setDefine("USE_POINTSPRITE");
glEnable(GL_VERTEX_PROGRAM_POINT_SIZE);
glEnable(GL_ALPHA_TEST);
glEnable(GL_POINT_SPRITE);
......@@ -567,6 +532,7 @@ void WTubeDrawable::drawTubes( osg::RenderInfo& renderInfo ) const
state.disableVertexPointer();
state.disableColorPointer();
m_shaderTubes->eraseDefine("USE_POINTSPRITE");
/*
boost::shared_ptr< std::vector< size_t > > startIndexes = m_dataset->getLineStartIndexes();
......
......@@ -32,6 +32,7 @@
#include <osg/Drawable>
#include <osg/ShapeDrawable>
#include <osg/Group>
#include "../../../graphicsEngine/WShader.h"
#include "../../WExportKernel.h"
......@@ -150,6 +151,8 @@ public:
void setRootState(osg::StateSet* m_rootState);
void setWShader(osg::ref_ptr< WShader > m_shaderTubes);
protected:
private:
/**
......@@ -175,6 +178,8 @@ private:
osg::Vec3Array* m_tubeColors;
osg::VectorGLuint* m_tubeStartIndexes;
osg::ref_ptr< WShader > m_shaderTubes;
/*
boost::shared_ptr< std::vector< float > > m_tubeVerts;
boost::shared_ptr< std::vector< float > > m_tubeTangents;
......
......@@ -14,6 +14,8 @@ varying vec3 normal;
varying float endPoint;
uniform gl_DepthRangeParameters gl_DepthRange;
varying float z;
varying float zNear;
varying float zFar;
void main()
{
......@@ -37,8 +39,9 @@ void main()
lt = dot(L, T);
//compute rotation in imageplane for pointsprite
if(usePointSprite < 0.8)
{
#ifdef USE_POINTSPRITE
//if(usePointSprite < 0.8)
//{
vec2 imageTangentNorm = normalize(imageTangent);
vec2 newTexCoords;
newTexCoords.x = (imageTangentNorm.y * (gl_PointCoord.y - 0.5) + imageTangentNorm.x * (gl_PointCoord.x - 0.5)) + 0.5;
......@@ -52,12 +55,14 @@ void main()
}
gl_FragColor.a = color.z;
}
else
{
#else
//}
//else
//{
color = texture1D(texture, gl_TexCoord[1].s);
gl_FragColor.a = tubeColor.a;
}
//}
#endif
/* compute the specular term if NdotL is larger than zero */
if (NdotL > 0.0) {
......@@ -70,7 +75,7 @@ void main()
specular = pow(NdotHV,2) * color.y * tubeColor.rgb;
}
float depthCueingFactor = 1.0 - (z + gl_DepthRange.near)/(gl_DepthRange.far + gl_DepthRange.near);
float depthCueingFactor = (1 - (z+zNear)/(zNear+zFar));
gl_FragColor.rgb = tubeColor.rgb * (color.x) * depthCueingFactor + specular;
}
......@@ -14,6 +14,10 @@ varying vec3 normal;
varying float endPoint;
uniform gl_DepthRangeParameters gl_DepthRange;
varying float z;
uniform vec3 nearPos;
uniform vec3 farPos;
varying float zNear;
varying float zFar;
void main()
{
......@@ -27,6 +31,9 @@ void main()
pos = gl_ModelViewProjectionMatrix * gl_Vertex;
z = pos.z;
zNear = (gl_ModelViewProjectionMatrix * vec4(nearPos,0)).z;
zFar = (gl_ModelViewProjectionMatrix * vec4(farPos,0)).z;
view = - pos.xyz;
//lightDir = normalize(gl_LightSource[0].position.xyz - view);
......@@ -45,7 +52,7 @@ void main()
vec3 tangent = (gl_ModelViewProjectionMatrix * vec4(gl_Normal,0.)).xyz; // transform our tangent vector
//define thickness of tubes
thickness = u_thickness * 0.0001; //* (1 - (abs(pos.z)+gl_DepthRange.near)/(gl_DepthRange.near+gl_DepthRange.far));
thickness = u_thickness * 0.0001 * (1 - (z+zNear)/(zNear+zFar));
// color of tube
tubeColor = gl_Color;
......@@ -62,8 +69,9 @@ void main()
offset.y *= thickness;
//decide wether point sprite or triangle strip to render
if(s_param == 0.0)
{
#ifdef USE_POINTSPRITE
//if(s_param == 0.0)
//{
//calculation for pointsprites
if(tmp > 0.93 || gl_MultiTexCoord0.t == 0.0)
......@@ -77,8 +85,8 @@ void main()
imageTangent.xy = (pos2p.x/pos2p.w - pos1p.x/pos1p.w, pos1p.y/pos1p.w - pos2p.y/pos2p.w);
// compute size with u_viewportWidth and u_viewportHeight;
gl_PointSize = 1000 * offset.x;
//gl_PointSize = 20;
//gl_PointSize = tangent_dot_view * u_viewportWidth;
gl_PointSize = 20;
usePointSprite = 0.0;
endPoint = gl_MultiTexCoord0.t;
......@@ -89,9 +97,10 @@ void main()
pos.w = 0.0;
}
}
else
{
#else
//}
//else
//{
// don't draw quad strip //decide wether point sprite or triangle strip to render
if(tmp >= 0.98)
{
......@@ -105,6 +114,7 @@ void main()
// TexCoord for 1D texture
gl_TexCoord[1] = gl_MultiTexCoord0.t;
}
}
//}
#endif
gl_Position = pos; //< store final position
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment