Commit 3e206b7c authored by Sebastian Eichelbaum's avatar Sebastian Eichelbaum
Browse files

[ADD] - fiberDisplaySimple can now provide illuminated lines + illuminated...

[ADD] - fiberDisplaySimple can now provide illuminated lines + illuminated ribbons. Illuminated tubes follow.
parent da519607
......@@ -91,6 +91,8 @@ void WMFiberDisplaySimple::properties()
{
m_propCondition = boost::shared_ptr< WCondition >( new WCondition() );
m_illuminationEnable = m_properties->addProperty( "Illumination", "Enable line illumination.", true );
m_clipPlaneGroup = m_properties->addPropertyGroup( "Clipping", "Clip the fiber data basing on an arbitrary plane." );
m_clipPlaneEnabled = m_clipPlaneGroup->addProperty( "Enabled", "If set, clipping of fibers is done using an arbitrary plane and plane distance.",
false );
......@@ -137,8 +139,14 @@ void enableTransparency( osg::StateSet* state )
void WMFiberDisplaySimple::moduleMain()
{
// initialize clipping shader
m_shader = osg::ref_ptr< WGEShader > ( new WGEShader( "WMFiberDisplaySimple", m_localPath ) );
// initialize illumination shader
m_shader->addPreprocessor( WGEShaderPreprocessor::SPtr(
new WGEShaderPropertyDefineOptions< WPropBool >( m_illuminationEnable, "ILLUMINATION_DISABLED", "ILLUMINATION_ENABLED" ) )
);
// initialize clipping shader
osg::ref_ptr< WGEPropertyUniform< WPropPosition > > clipPlanePointUniform = new WGEPropertyUniform< WPropPosition >( "u_planePoint",
m_clipPlanePoint );
osg::ref_ptr< WGEPropertyUniform< WPropPosition > > clipPlaneVectorUniform = new WGEPropertyUniform< WPropPosition >( "u_planeVector",
......@@ -150,6 +158,9 @@ void WMFiberDisplaySimple::moduleMain()
);
// init tube shader
m_shader->addPreprocessor( WGEShaderPreprocessor::SPtr(
new WGEShaderPropertyDefineOptions< WPropBool >( m_tubeEnable, "TUBE_DISABLED", "TUBE_ENABLED" ) )
);
m_shader->addPreprocessor( WGEShaderPreprocessor::SPtr(
new WGEShaderPropertyDefineOptions< WPropBool >( m_tubeZoomable, "ZOOMABLE_DISABLED", "ZOOMABLE_ENABLED" ) )
);
......
......@@ -118,6 +118,11 @@ private:
*/
osg::ref_ptr< WGEShader > m_shader;
/**
* Illumination.
*/
WPropBool m_illuminationEnable;
/**
* A property group for all the clipping related props.
*/
......
......@@ -76,7 +76,12 @@ void main()
}
#endif
float light = blinnPhongIlluminationIntensity( normalize( v_normal ) );
gl_FragColor = vec4( vec3( (1.5- gl_FragCoord.z)*light ), 1.0 ); //gl_Color;
#ifdef ILLUMINATION_ENABLED
float light = blinnPhongIlluminationIntensity( wge_DefaultLightIntensityLessDiffuse, normalize( v_normal ) );
#else
float light = 1.0;
#endif
gl_FragColor = vec4( vec3( gl_Color.xyz * light ), gl_Color.a );
}
......@@ -81,18 +81,31 @@ void main()
vec3 n = normalize( u_planeVector );
float d = dot( u_planePoint, n );
dist = dot( gl_Vertex.xyz, n ) - d;
#endif
#endif // CLIPPLANE_ENABLED
// The same accounds for the vertex. Transfer it to world-space.
vec4 vertex = gl_ModelViewMatrix * gl_Vertex;
#if ( defined ILLUMINATION_ENABLED || defined TUBE_ENABLED )
// Grab the tangent. We have uploaded it normalized in gl_Normal per vertex
// We need to transfer it to the world-space ass all further operations are done there.
vec3 tangent = normalize( ( gl_ModelViewMatrix * vec4( gl_Normal, 0.0 ) ).xyz );
// The same accounds for the vertex. Transfer it to world-space.
vec4 vertex = gl_ModelViewMatrix * gl_Vertex;
// The view direction in world-space. In OpenGL this is always defined by this vector
vec3 view = vec3( 0.0, 0.0, -1.0 );
// Each vertex on the quad which are on the same position have a texture coordinate to differentiate them. But only if the tube mode is
// active.
float upDownIndicator = gl_MultiTexCoord0.s;
#ifndef TUBE_ENABLED
upDownIndicator = 1.0;
#endif // !TUBE_ENABLED
// To enforce that each quad's normal points towards the user, we move the two vertex (which are at the same point currently) according to
// the direction stored in gl_MultiTexCoord0
vec3 offset = normalize( upDownIndicator * cross( view, tangent ) );
#ifdef TUBE_ENABLED
#ifdef ZOOMABLE_ENABLED
// To avoid that the quad strip gets thinner and thinner when zooming in (or the other way around: to avoid the quad strip always occupies
// the same screen space), we need to calculate the zoom factor involved in OpenWalnut's current camera.
......@@ -103,24 +116,22 @@ void main()
// additional uniform u_tubeSize allows the user to scale the tubes.
// We clamp the value to ensure a minimum width of the quadstrip of 1px on screen:
worldScale = clamp( u_tubeSize * worldScale, 1.0, 1000000.0 );
#else
#else // ZOOMABLE_ENABLED
// In this mode, the tubes should not be zoomed. Just use the user defined size here.
float worldScale = clamp( u_tubeSize, 1.0, 1000000.0 );
#endif
// To enforce that each quad's normal points towards the user, we move the two vertex (which are at the same point currently) according to
// the direction stored in gl_MultiTexCoord0
vec3 offset = normalize( gl_MultiTexCoord0.s * cross( view, tangent ) );
// Apply the offset and scale correctly.
vertex.xyz += 0.1 * worldScale * offset;
#endif // TUBE_ENABLED
// with the tangent and the view vector we got the offset vector. We can noch get the normal using the tangent and the offset.
v_normal = cross( offset, tangent );
v_normal *= sign( dot( v_normal, vec3(0.0, 0.0, 1.0 ) ) );
#endif // ( defined ILLUMINATION_ENABLED || defined TUBE_ENABLED )
// Simply project the vertex afterwards
gl_Position = gl_ProjectionMatrix * vertex;
gl_FrontColor = vec4( vec3( gl_MultiTexCoord0.s ), 1.0 );
gl_FrontColor = gl_Color;
}
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