Commit e5e8b62f authored by Mathias Goldau's avatar Mathias Goldau
Browse files

[CHANGE] FiberStipple module shaders adopted to new module design. Basically...

[CHANGE] FiberStipple module shaders adopted to new module design. Basically many things, such as focal points of the stipples are now calculated on GPU instead of CPU
parent afa68935
......@@ -44,93 +44,50 @@ varying vec4 diffusionDirection;
float minimum_distance( vec3 v, vec3 w, vec3 p )
{
// Return minimum distance between line segment vw and point p
float len = length( v - w );
if( len == 0.0 ) // v == w case
{
return distance( p, v );
}
// Consider the line extending the segment, parameterized as v + t (w - v).
// We find projection of point p onto the line.
// It falls where t = [(p-v) . (w-v)] / |w-v|^2
float t = dot( p - v, w - v ) / ( len * len );
if( t < 0.0 ) // Beyond the 'v' end of the segment
{
return distance( p, v );
}
else if( t > 1.0 ) // Beyond the 'w' end of the segment
{
return distance( p, w );
}
vec3 projection = v + t * ( w - v ); // Projection falls on the segment
return distance( p, projection );
// Return minimum distance between line segment vw and point p
float len = length( v - w );
if( len == 0.0 ) // v == w case
{
return distance( p, v );
}
// Consider the line extending the segment, parameterized as v + t (w - v).
// We find projection of point p onto the line.
// It falls where t = [(p-v) . (w-v)] / |w-v|^2
float t = dot( p - v, w - v ) / ( len * len );
if( t < 0.0 ) // Beyond the 'v' end of the segment
{
return distance( p, v );
}
else if( t > 1.0 ) // Beyond the 'w' end of the segment
{
return distance( p, w );
}
vec3 projection = v + t * ( w - v ); // Projection falls on the segment
return distance( p, projection );
}
void main()
{
// ellipsoiden scheiss
// if( ( length( gl_TexCoord[0] - gl_TexCoord[1] ) + length( gl_TexCoord[0] - gl_TexCoord[2] ) ) < 1.2 )
// determine if this is a long or short line stipple
// u_glyphSize controls the area each line stipple must use, radius is then derived from that.
float area = u_glyphSize * u_glyphSize / 10.0;
// Old radius driven behaviour:
// ############################
// generally the area of a line stipple is a circle with radius R (each half for the endings of the line stipple) plus
// a quad with height 2R and width length of the focalPoints v and w. hence we have this equation in R to solve:
//
// float scaleFactor = 1 - length( gl_TexCoord[1].xyz - gl_TexCoord[2].xyz ) / u_glyphSize;
// scaleFactor = 1 + scaleFactor * scaleFactor;
// R^2*PI + 2R*length(v, w) - A = 0
//
// // line stipple
//// if( minimum_distance( gl_TexCoord[1].xyz, gl_TexCoord[2].xyz, gl_TexCoord[0].xyz ) < scaleFactor * u_glyphThickness )
// if( minimum_distance( gl_TexCoord[1].xyz, gl_TexCoord[2].xyz, gl_TexCoord[0].xyz ) < u_glyphThickness )
// {
// gl_FragColor = gl_Color;
// }
// else
// {
// discard;
// }
// New approach: u_glyphSize controls the area each line stipple must use, radius is then derived from that.
// #########################################################################################################
// // Tried to calc optimal area...
// float optRadius = u_glyphSize / 16.0;
// float optLength = u_glyphSize - 2 * optRadius;
// float optArea = 2 * optRadius * sqrt( 2 * optLength * optLength ) + 3.14159265 * optRadius * optRadius;
// // Scalar values for zoom pansen
// float magicZoom = length( ( gl_ModelViewMatrix * normalize( vec4( 1.0, 1.0, 1.0, 0.0 ) ) ).xyz );
// float area = u_glyphSize * u_glyphSize / 10.0; // 10 * u_glyphThickness * 1.0 / (2 * u_glyphSize) * optArea;
//
// // generally the area of a line stipple is a circle with radius R (each half for the endings of the line stipple) plus
// // a quad with height 2R and width length of the focalPoints v and w. hence we have this equation in R to solve:
// //
// // R^2*PI + 2R*length(v, w) - A = 0
// //
// // where A is the area to fill.
//
// float l = distance( 0.8 * gl_TexCoord[1].xyz, 0.8 * gl_TexCoord[2].xyz );
// float p2 = -l / 3.14159265;
// float q = area / 3.14159265;
// float r1 = p2 + sqrt( p2 * p2 + q );
// float r2 = p2 - sqrt( p2 * p2 + q );
// float radius = max( r1, r2 );
//
// vec3 focalPoint1 = 0.8 * gl_TexCoord[1].xyz;
// vec3 focalPoint2 = 0.8 * gl_TexCoord[2].xyz;
// vec3 focalPoint1 = gl_TexCoord[1].xyz - normalize( gl_TexCoord[1].xyz ) * radius;
// vec3 focalPoint2 = gl_TexCoord[2].xyz - normalize( gl_TexCoord[2].xyz ) * radius;
// float f_l = distance( focalPoint1, focalPoint2 );
// float f_p2 = -l / 3.14159265;
// float f_q = area / 3.14159265;
// float f_r1 = p2 + sqrt( p2 * p2 + q );
// float f_r2 = p2 - sqrt( p2 * p2 + q );
// float f_radius = max( r1, r2 );
// where A is the area to fill.
focalPoint1 = 0.8 * focalPoint1;
focalPoint2 = 0.8 * focalPoint1;
float l = distance( focalPoint1, focalPoint2 );
float p2 = -l / 3.14159265;
float q = area / 3.14159265;
float r1 = p2 + sqrt( p2 * p2 + q );
float r2 = p2 - sqrt( p2 * p2 + q );
float radius = max( r1, r2 );
// vec4 direction = abs( texture3DUnscaled( u_vectorsSampler, gl_TexCoord[0].xyz, u_vectorsMin, u_vectorsScale ) );
// vec4 probRGBA = texture3D( u_probTractSampler, gl_TexCoord[0].xyz );
......@@ -144,29 +101,28 @@ void main()
// gl_FragColor = 0.8 * probRGBA + 0.2 * direction;
// // if( minimum_distance( gl_TexCoord[1].xyz, gl_TexCoord[2].xyz, gl_TexCoord[0].xyz ) < radius )
// if( minimum_distance( focalPoint1, focalPoint2, gl_TexCoord[0].xyz ) < u_glyphThickness * radius )
// {
// gl_FragColor = gl_Color;
// }
// else
// {
// // if( minimum_distance( focalPoint1, focalPoint2, gl_TexCoord[0].xyz ) < u_glyphThickness * ( radius + 0.01 ) )
// // {
// // gl_FragColor = vec4( 1.0, 1.0, 1.0, gl_Color.w );
// // }
//
// discard;
//
// // // Draw quad and inner cricle
// //
// // gl_FragColor = vec4( 1.0, 1.0, 1.0, 1.0 );
// // float lp = length( gl_TexCoord[0].xyz );
// // if( lp >= ( u_glyphSize / 2.0 ) )
// // {
// // gl_FragColor = vec4( 0.7, 0.7, 1.0, 1.0 ); // discard;
// // }
// }
if( minimum_distance( focalPoint1, focalPoint2, gl_TexCoord[1].xyz ) < u_glyphThickness * radius )
{
gl_FragColor = gl_Color;
}
else
{
// if( minimum_distance( focalPoint1, focalPoint2, gl_TexCoord[0].xyz ) < u_glyphThickness * ( radius + 0.01 ) )
// {
// gl_FragColor = vec4( 1.0, 1.0, 1.0, gl_Color.w );
// }
discard;
// // Draw quad and inner cricle
//
// gl_FragColor = vec4( 1.0, 1.0, 1.0, 1.0 );
// float lp = length( gl_TexCoord[0].xyz );
// if( lp >= ( u_glyphSize / 2.0 ) )
// {
// gl_FragColor = vec4( 0.7, 0.7, 1.0, 1.0 ); // discard;
// }
}
// // display middle point
// if( length( gl_TexCoord[0].xyz ) <= 0.01 )
......
......@@ -69,7 +69,7 @@ void main()
texturePosition.y = ( u_WorldTransform[3] / u_probTractSizeY ).y;
if( texture3D( u_probTractSampler, texturePosition ).r > 0.01 ) // rgb are the same
{
// transform position, the 4th component must be explicitly set, as otherwise they would have been scaled
// transform position, the 4th component must be explicitly set, as otherwise they would have been scaled
gl_Position = gl_ModelViewProjectionMatrix * ( vec4( gl_TexCoord[0].xyz + gl_Vertex.xyz, 1.0 ) );
}
else
......@@ -79,4 +79,13 @@ void main()
// get principal diffusion direction
diffusionDirection = abs( texture3DUnscaled( u_vectorsSampler, texturePosition, u_vectorsMin, u_vectorsScale ) ).xyz;
diffusionDirection = normalize( diffusionDirection );
// project into plane (given by two vectors aVec and bVec)
vec3 normal = normalize( cross( aVec, bVec ) );
vec3 projectedDirection = diffusionDirection - dot( diffusionDirection, normal ) * normal;
vec3 middlePoint = vec3( 0.5, 0.5, 0.0 ); // in texture coordinates
focalPoint1 = middlePoint + projectedDirection;
focalPoint2 = middlePoint - projectedDirection;
}
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