Commit a58751fe authored by Alexander Wiebel's avatar Alexander Wiebel
Browse files

Merge remote-tracking branch 'origin/747-fix-fiber-end-caps'

parents c1ca955b f207c76d
......@@ -265,9 +265,6 @@ void WMFiberDisplay::moduleMain()
m_shader->addPreprocessor( defineTmp );
m_endCapShader->addPreprocessor( defineTmp );
m_shader->addBindAttribLocation( "a_primitiveID", 15 );
m_endCapShader->addBindAttribLocation( "a_primitiveID", 15 );
// get notified about data changes
m_moduleState.setResetable( true, true );
m_moduleState.add( m_fiberInput->getDataChangedCondition() );
......@@ -529,7 +526,7 @@ void WMFiberDisplay::createFiberGeode( std::shared_ptr< WDataSetFibers > fibers,
state->setMode( GL_LIGHTING, osg::StateAttribute::OFF | osg::StateAttribute::PROTECTED );
// create everything needed for the line_strip drawable
osg::ref_ptr< osg::Vec3Array > vertices = osg::ref_ptr< osg::Vec3Array >( new osg::Vec3Array );
osg::ref_ptr< osg::Vec4Array > vertices = osg::ref_ptr< osg::Vec4Array >( new osg::Vec4Array );
osg::ref_ptr< osg::Vec4Array > colors = osg::ref_ptr< osg::Vec4Array >( new osg::Vec4Array );
osg::ref_ptr< osg::Vec3Array > tangents = osg::ref_ptr< osg::Vec3Array >( new osg::Vec3Array );
osg::ref_ptr< osg::FloatArray > texcoords = osg::ref_ptr< osg::FloatArray >( new osg::FloatArray );
......@@ -564,25 +561,26 @@ void WMFiberDisplay::createFiberGeode( std::shared_ptr< WDataSetFibers > fibers,
state->setTextureAttributeAndModes( 8, m_bitfieldTexture, osg::StateAttribute::ON );
state->addUniform( new osg::Uniform( "bitfieldSampler", static_cast< int >( 8 ) ) );
state->addUniform( new osg::Uniform( "bitfieldSize", static_cast< int >( imgSize ) ) );
endState->setTextureAttributeAndModes( 8, m_bitfieldTexture, osg::StateAttribute::ON );
endState->addUniform( new osg::Uniform( "bitfieldSampler", static_cast< int >( 8 ) ) );
endState->addUniform( new osg::Uniform( "bitfieldSize", static_cast< int >( imgSize ) ) );
state->setTextureAttributeAndModes( 9, m_selColorTexture, osg::StateAttribute::ON );
state->addUniform( new osg::Uniform( "selColorSampler", static_cast< int >( 9 ) ) );
state->addUniform( new osg::Uniform( "selColorSize", static_cast< int >( imgSize ) ) );
// new attribute array
m_primitiveID = new osg::IntArray( m_fibers->getNbVertices() * ( tubeMode ? 2 : 1 ) );
m_primitiveID->setNormalize( false );
m_primitiveID->setPreserveDataType( true );
endState->setTextureAttributeAndModes( 9, m_selColorTexture, osg::StateAttribute::ON );
endState->addUniform( new osg::Uniform( "selColorSampler", static_cast< int >( 9 ) ) );
endState->addUniform( new osg::Uniform( "selColorSize", static_cast< int >( imgSize ) ) );
// this is needed for the end- sprites
osg::ref_ptr< osg::Vec3Array > endVertices = osg::ref_ptr< osg::Vec3Array >( new osg::Vec3Array );
osg::ref_ptr< osg::Vec4Array > endVertices = osg::ref_ptr< osg::Vec4Array >( new osg::Vec4Array );
osg::ref_ptr< osg::Vec4Array > endColors = osg::ref_ptr< osg::Vec4Array >( new osg::Vec4Array );
osg::ref_ptr< osg::Vec3Array > endTangents = osg::ref_ptr< osg::Vec3Array >( new osg::Vec3Array );
osg::ref_ptr< osg::Geometry > endGeometry = osg::ref_ptr< osg::Geometry >( new osg::Geometry );
// this is needed for the end- sprites
// NOTE: we handle start caps and end caps separately here since the vertex attributes are per line so we need to have one cap per line.
osg::ref_ptr< osg::Vec3Array > startVertices = osg::ref_ptr< osg::Vec3Array >( new osg::Vec3Array );
osg::ref_ptr< osg::Vec4Array > startVertices = osg::ref_ptr< osg::Vec4Array >( new osg::Vec4Array );
osg::ref_ptr< osg::Vec4Array > startColors = osg::ref_ptr< osg::Vec4Array >( new osg::Vec4Array );
osg::ref_ptr< osg::Vec3Array > startTangents = osg::ref_ptr< osg::Vec3Array >( new osg::Vec3Array );
osg::ref_ptr< osg::Geometry > startGeometry = osg::ref_ptr< osg::Geometry >( new osg::Geometry );
......@@ -628,7 +626,6 @@ void WMFiberDisplay::createFiberGeode( std::shared_ptr< WDataSetFibers > fibers,
debugLog() << "Number of vertices: " << fibVerts->size() / 3;
size_t currentStart = 0;
size_t vidx = 0;
for( size_t fidx = 0; fidx < fibStart->size() ; ++fidx )
{
++*progress1;
......@@ -666,9 +663,9 @@ void WMFiberDisplay::createFiberGeode( std::shared_ptr< WDataSetFibers > fibers,
osg::Vec3 startNormal = firstVert - secondVert;
osg::Vec3 endNormal = lastVert - secondLastVert;
startTangents->push_back( startNormal );
startVertices->push_back( firstVert );
startVertices->push_back( osg::Vec4( firstVert, fidx ) );
endTangents->push_back( endNormal );
endVertices->push_back( lastVert );
endVertices->push_back( osg::Vec4( lastVert, fidx ) );
}
osg::Vec2 tc = index2Vec2( fidx, m_bitfieldImage->s() );
......@@ -678,9 +675,10 @@ void WMFiberDisplay::createFiberGeode( std::shared_ptr< WDataSetFibers > fibers,
// walk along the fiber
for( size_t k = 0; k < len; ++k )
{
osg::Vec3 vert = osg::Vec3( fibVerts->at( ( 3 * k ) + sidx ),
osg::Vec4 vert = osg::Vec4( fibVerts->at( ( 3 * k ) + sidx ),
fibVerts->at( ( 3 * k ) + sidx + 1 ),
fibVerts->at( ( 3 * k ) + sidx + 2 ) );
fibVerts->at( ( 3 * k ) + sidx + 2 ),
fidx );
osg::Vec3 tangent = osg::Vec3( fibTangents->at( ( 3 * k ) + sidx ),
fibTangents->at( ( 3 * k ) + sidx + 1 ),
......@@ -701,9 +699,6 @@ void WMFiberDisplay::createFiberGeode( std::shared_ptr< WDataSetFibers > fibers,
colors->push_back( color );
tangents->push_back( tangent );
( *m_primitiveID )[ vidx ] = static_cast< int >( fidx );
vidx++;
if( tubeMode )
{
// if in tube-mode, some final sprites are needed to provide some kind of ending for the tube
......@@ -725,14 +720,8 @@ void WMFiberDisplay::createFiberGeode( std::shared_ptr< WDataSetFibers > fibers,
// This saves some mem.
texcoords->push_back( 1.0 );
texcoords->push_back( -1.0 );
// tubes have twice as much vertices
( *m_primitiveID )[ vidx ] = static_cast< int >( fidx );
vidx++;
}
}
m_bitfieldImage->dirty();
m_selColorImage->dirty();
// add the above line-strip
if( tubeMode )
......@@ -757,6 +746,9 @@ void WMFiberDisplay::createFiberGeode( std::shared_ptr< WDataSetFibers > fibers,
currentStart += len;
}
m_bitfieldImage->dirty();
m_selColorImage->dirty();
geometry->addPrimitiveSet( indices );
// combine these arrays to the geometry
......@@ -797,20 +789,20 @@ void WMFiberDisplay::createFiberGeode( std::shared_ptr< WDataSetFibers > fibers,
endGeometry->setUseDisplayList( false );
endGeometry->setUseVertexBufferObjects( true );
// bind the attribute
geometry->setVertexAttribArray( 15, m_primitiveID );
// the attributes are define per line strip, thus we bind the array accordingly
geometry->setVertexAttribBinding( 15, osg::Geometry::BIND_PER_VERTEX );
// geometry->setSecondaryColorBinding( osg::Geometry::BIND_PER_VERTEX );
if( tubeMode )
{
// we have one vertex per line, so bind the attribute array per vertex
startGeometry->setVertexAttribArray( 15, m_primitiveID );
startGeometry->setVertexAttribBinding( 15, osg::Geometry::BIND_PER_VERTEX );
endGeometry->setVertexAttribArray( 15, m_primitiveID );
endGeometry->setVertexAttribBinding( 15, osg::Geometry::BIND_PER_VERTEX );
}
// // bind the attribute
// geometry->setVertexAttribArray( 15, m_primitiveID );
// // the attributes are define per line strip, thus we bind the array accordingly
// geometry->setVertexAttribBinding( 15, osg::Geometry::BIND_PER_VERTEX );
// // geometry->setSecondaryColorBinding( osg::Geometry::BIND_PER_VERTEX );
// if( tubeMode )
// {
// // we have one vertex per line, so bind the attribute array per vertex
// startGeometry->setVertexAttribArray( 15, m_primitiveID );
// startGeometry->setVertexAttribBinding( 15, osg::Geometry::BIND_PER_VERTEX );
// endGeometry->setVertexAttribArray( 15, m_primitiveID );
// endGeometry->setVertexAttribBinding( 15, osg::Geometry::BIND_PER_VERTEX );
// }
// add an update callback which later handles several things like the filter attribute array
geometry->setUpdateCallback( new WGEFunctorCallback< osg::Drawable >( boost::bind( &WMFiberDisplay::geometryUpdate,
......
......@@ -328,11 +328,6 @@ private:
*/
void roiUpdate();
/**
* Contains the normalized primitive id
*/
osg::ref_ptr< osg::IntArray > m_primitiveID;
/**
* Ratio between dataset color and ROI color.
*/
......
......@@ -133,7 +133,7 @@ void main()
// finalColor = mix( v_clusterColor, osg_Color, u_roiFilterColorOverride );
// FIXME_ somehow, the secondary color array does not arrive at the vertex shader although it is bound. We make endcaps transparent in the
// case
finalColor = mix( vec4( 0.0 ), v_colorOut, u_roiFilterColorOverride );
finalColor = mix( v_clusterColor, v_colorOut, u_roiFilterColorOverride );
#endif
#endif
......
......@@ -32,17 +32,18 @@
// Uniforms
/////////////////////////////////////////////////////////////////////////////
#ifdef BITFIELD_ENABLED
uniform sampler2D bitfieldSampler;
uniform int bitfieldSize;
uniform sampler2D selColorSampler;
uniform int selColorSize;
#endif
/////////////////////////////////////////////////////////////////////////////
// Attributes
/////////////////////////////////////////////////////////////////////////////
/**
* This vertex attribute is the bitmask denoting whether to show the fiber or not
*/
#ifdef BITFIELD_ENABLED
in float a_bitfield;
#endif
/////////////////////////////////////////////////////////////////////////////
// Varyings
/////////////////////////////////////////////////////////////////////////////
......@@ -96,13 +97,26 @@ out vec4 v_colorIn;
// Functions
/////////////////////////////////////////////////////////////////////////////
/**
* Converts an index to a vec2
* \param idx the index
* \param size the size of the quadratic texture
*
* \return The x and y coordinates of the index
*/
ivec2 index2Vec2( int idx, int size )
{
return ivec2( idx % size, idx / size );
}
/**
* Main entry point of the vertex shader.
*/
void main()
{
#ifdef BITFIELD_ENABLED
v_discard = 1.0 - a_bitfield;
v_discard = 1.0 - texelFetch( bitfieldSampler, index2Vec2( int( osg_Vertex.w ), bitfieldSize ), 0 ).r;
v_secondaryColor = texelFetch( selColorSampler, index2Vec2( int( osg_Vertex.w ), selColorSize ), 0 );
#endif
// Init with defaults
......@@ -111,11 +125,9 @@ void main()
v_worldScale = 1.0;
v_clusterColor = vec4( 1.0 );
v_secondaryColor = vec4( osg_SecondaryColor.rgb, 1.0 );
// forward to geometry shader
v_normal = osg_Normal;
v_colorIn = osg_Color;
gl_Position = osg_Vertex;
gl_Position = vec4( osg_Vertex.xyz, 1.0 );
}
......@@ -123,13 +123,6 @@ uniform float u_tubeSize;
// Attributes
/////////////////////////////////////////////////////////////////////////////
/**
* This vertex attribute is the bitmask denoting whether to show the fiber or not
*/
#ifdef BITFIELD_ENABLED
in int a_primitiveID;
#endif
/////////////////////////////////////////////////////////////////////////////
// Variables
/////////////////////////////////////////////////////////////////////////////
......@@ -163,7 +156,7 @@ void main()
#endif // CLIPPLANE_ENABLED
// The same accounds for the vertex. Transfer it to world-space.
v_vertex = osg_ModelViewMatrix * osg_Vertex;
v_vertex = osg_ModelViewMatrix * vec4( osg_Vertex.xyz, 1.0 );
// fill this varying with a dummy. Not always needed.
v_normal = vec3( 1.0, 0.0, 0.0 );
......@@ -222,8 +215,8 @@ void main()
#endif
#ifdef BITFIELD_ENABLED
v_discard = 1.0 - texelFetch( bitfieldSampler, index2Vec2( a_primitiveID, bitfieldSize ), 0 ).r;
v_clusterColor = texelFetch( selColorSampler, index2Vec2( a_primitiveID, selColorSize ), 0 );
v_discard = 1.0 - texelFetch( bitfieldSampler, index2Vec2( int( osg_Vertex.w ), bitfieldSize ), 0 ).r;
v_clusterColor = texelFetch( selColorSampler, index2Vec2( int( osg_Vertex.w ), selColorSize ), 0 );
#endif
// Simply project the vertex afterwards
......
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