Commit 04a8e73e authored by Dirk Albrecht's avatar Dirk Albrecht

[CHANGE] Minor changes for lighting. Bad style in code corrected. Doc completed.

parent a7ef1a85
......@@ -405,41 +405,50 @@ private:
* of a tube from aside
* \param rootState The uniforms will be applied to this state.
*/
void create1DTextureRectLightning( osg::StateSet* rootState ) const;
void create1DTextureRectLighting( osg::StateSet* rootState ) const;
/**
* Creates a texture to simmulate diffuse and specular lightning
* of a tube from top or bottom
* \param rootState The uniforms will be applied to this state.
*/
void create2DTextureCycleLightning( osg::StateSet* rootState ) const;
void create2DTextureCycleLighting( osg::StateSet* rootState ) const;
/**
* Creates a texture to simmulate diffuse and specular lightning
* of a tube from top or bottom
* \param rootState The uniforms will be applied to this state.
*/
void create2DTexDiffuseLightning( osg::StateSet* rootState ) const;
void create2DTexturesBlinn( osg::StateSet* rootState ) const;
/**
* Creates a texture to simmulate diffuse and specular lightning
* of a tube from top or bottom
* \param rootState The uniforms will be applied to this state.
*/
void create2DTexSpecularLightning( osg::StateSet* rootState ) const;
void createTextures( osg::StateSet* rootState ) const;
/**
* Creates a texture to simmulate diffuse and specular lightning
* of a tube from top or bottom
* \param rootState The uniforms will be applied to this state.
*/
void createTextures( osg::StateSet* rootState ) const;
void createTubeData();
/**
* Creates a texture to simmulate diffuse and specular lightning
* of a tube from top or bottom
* Computes integrand for specular blinn lighting texture
* \param beta
* \param n specular exponent
* \param theta
*/
void createTubeData();
double computeIntegrand( double beta, int n, double theta ) const;
/**
* Computes integral for specular blinn lighting texture
* \param alpha
* \param beta
* \param n specular exponent
*/
double computeSpecIntegral( double alpha, double beta, int n ) const;
/**
* Wrapper class for userData to prevent cyclic destructor calls
......
......@@ -80,35 +80,9 @@ void WTubeGeometry::drawImplementation( osg::RenderInfo& renderInfo ) const
if (checkForGLErrors) state.checkGLErrors( "start of Geometry::drawImplementation()" );
bool useFastPath = areFastPathsUsed();
useFastPath = false;
bool usingVertexBufferObjects = _useVertexBufferObjects && state.isVertexBufferObjectSupported();
bool handleVertexAttributes = !_vertexAttribList.empty();
osg::ArrayDispatchers& arrayDispatchers = state.getArrayDispatchers();
arrayDispatchers.reset();
arrayDispatchers.setUseVertexAttribAlias(useFastPath && state.getUseVertexAttributeAliasing());
arrayDispatchers.setUseGLBeginEndAdapter(!useFastPath);
arrayDispatchers.activateNormalArray(_normalData.binding, _normalData.array.get(), _normalData.indices.get());
arrayDispatchers.activateColorArray(_colorData.binding, _colorData.array.get(), _colorData.indices.get());
arrayDispatchers.activateSecondaryColorArray(_secondaryColorData.binding, _secondaryColorData.array.get(), _secondaryColorData.indices.get());
arrayDispatchers.activateFogCoordArray(_fogCoordData.binding, _fogCoordData.array.get(), _fogCoordData.indices.get());
if (handleVertexAttributes)
{
for(unsigned int unit=0;unit<_vertexAttribList.size();++unit)
{
arrayDispatchers.activateVertexAttribArray(_vertexAttribList[unit].binding,
unit, _vertexAttribList[unit].array.get(), _vertexAttribList[unit].indices.get());
}
}
state.disableAllVertexArrays();
// dispatch any attributes that are bound overall
arrayDispatchers.dispatch(BIND_OVERALL,0);
state.lazyDisablingOfVertexAttributes();
// set up arrays
......@@ -137,9 +111,6 @@ void WTubeGeometry::drawImplementation( osg::RenderInfo& renderInfo ) const
state.applyDisablingOfVertexAttributes();
bool bindPerPrimitiveSetActive = arrayDispatchers.active(BIND_PER_PRIMITIVE_SET);
bool bindPerPrimitiveActive = arrayDispatchers.active(BIND_PER_PRIMITIVE);
unsigned int primitiveNum = 0;
if ( checkForGLErrors ) state.checkGLErrors("Geometry::drawImplementation() after vertex arrays setup.");
......@@ -169,8 +140,7 @@ void WTubeGeometry::drawImplementation( osg::RenderInfo& renderInfo ) const
{
glDisable( GL_VERTEX_PROGRAM_POINT_SIZE );
glDisable( GL_POINT_SPRITE );
glEnable( GL_ALPHA_TEST );
glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
glDisable( GL_ALPHA_TEST );
glAlphaFunc( GL_NOTEQUAL, 0.0 );
break;
}
......@@ -181,18 +151,18 @@ void WTubeGeometry::drawImplementation( osg::RenderInfo& renderInfo ) const
boost::shared_ptr< std::vector< bool > > active = WKernel::getRunningKernel()->getRoiManager()->getBitField();
boost::shared_ptr< std::vector< size_t > > pointsPerLine = m_dataset->getLineLengths();
//useFastPath = false;
if ( useFastPath )
{
for( unsigned int primitiveSetNum = 0; primitiveSetNum != _primitives.size(); ++primitiveSetNum )
{
// dispatch any attributes that are bound per primitive
//if (bindPerPrimitiveSetActive) arrayDispatchers.dispatch(BIND_PER_PRIMITIVE_SET, primitiveSetNum);
const osg::PrimitiveSet* primitiveset = _primitives[primitiveSetNum].get();
if( (*active)[primitiveSetNum] )
{
primitiveset->draw( state, true );
}
}
}
else
{
for ( size_t i = 0; i < active->size(); ++i )
......
varying vec3 tangentR3; // Tangent vector in world space
varying float tangent_dot_view;
uniform bool globalColor;
uniform sampler1D texture;
uniform sampler2D texturePS;
......@@ -11,6 +9,7 @@ varying float NdotL;
varying vec3 normal;
varying vec3 halfVector;
varying float endPoint;
varying vec3 tangentR3;
varying float z;
varying float zNear;
......@@ -21,20 +20,29 @@ uniform bool useLightModel;
uniform bool usePointSprites;
uniform bool useQuadStripes;
uniform bool useProjection;
uniform float lowerDepthCueingFactor;
uniform float upperDepthCueingFactor;
varying vec3 eyeDirection;
varying vec3 lightDirection;
void main()
{
vec3 L, V, T, N, halfV;
vec3 specular = 0.0;
vec3 L,V, T, N, halfV;
float specular = 0.0;
float NdotL,NdotHV;
float alpha, beta, lt;
T = normalize(tangentR3);
V = normalize(view);
L = normalize(lightDir);
V = normalize(eyeDirection);
L = normalize(lightDirection);
N = normalize(normal);
float depthCueingFactor = 1.0;
NdotL = max(dot(N,L),0.0);
NdotL = saturate(dot(N, L));
vec3 eyeDir = normalize(eyeDirection);
vec4 color;
vec2 newTexCoords;
if ( useLightModel )
{
......@@ -43,25 +51,27 @@ void main()
beta = dot(halfVector,N) / sqrt( 1 - pow( dot(halfVector, T), 2));
lt = dot(L, T);
}
else
{
//compute rotation in imageplane for pointsprite
vec2 imageTangentNorm = normalize(imageTangent);
newTexCoords.x = (imageTangentNorm.y * (gl_PointCoord.y - 0.5) + imageTangentNorm.x * (gl_PointCoord.x - 0.5)) + 0.5;
newTexCoords.y = (imageTangentNorm.y * (gl_PointCoord.x - 0.5) - imageTangentNorm.x * (gl_PointCoord.y - 0.5)) + 0.5;
color = texture2D(texturePS, newTexCoords.xy);
gl_FragColor.a = color.z;
if ( useDepthCueing )
{
depthCueingFactor = clamp(( 1 - z + zNear ) / ( zNear + zFar ), lowerDepthCueingFactor, upperDepthCueingFactor );
}
if(endPoint == 0.0)
{
color = texture2D(texturePS, newTexCoords.xy);
color.x = 1.0;
gl_FragDepth = gl_FragCoord.z - 0.01;
gl_FragColor.rgb = (vec3(0.2,0.2,0.2)+vec3(0.6,0.6,0.6)*NdotL) * tubeColor.rgb * depthCueingFactor * depthCueingFactor;
}
else
{
color = texture2D(texturePS, newTexCoords.xy);
}
gl_FragColor.a = color.z;
/* compute the specular term if NdotL is larger than zero */
if (NdotL > 0.0)
{
......@@ -69,13 +79,10 @@ void main()
// cosine (dot product) with the normal
halfV = normalize(halfVector);
NdotHV = max(dot(normal, halfV),0.0);
specular = pow(NdotHV,16) * color.y;
}
NdotHV = saturate(dot(N, halfV));
specular = pow(NdotHV,16)*color.y;
if ( useDepthCueing )
{
depthCueingFactor = clamp((1 - (z+zNear)/(zNear+zFar)),0.5,0.8);
}
gl_FragColor.rgb = tubeColor.rgb * ((color.x) + specular) * depthCueingFactor * depthCueingFactor;
gl_FragColor.rgb = (tubeColor.rgb * ((vec3(0.2,0.2,0.2)+vec3(0.6,0.6,0.6)*NdotL*color.r) + vec3(0.6,0.6,0.6)*specular )) * depthCueingFactor * depthCueingFactor;
}
}
......@@ -28,23 +28,36 @@ uniform bool useLightModel;
uniform bool usePointSprites;
uniform bool useQuadStripes;
uniform bool useProjection;
uniform float lowerDepthCueingFactor;
uniform float upperDepthCueingFactor;
// Auch die Richtung zum Betrachter ist in der Regel
// für jedes Fragment unterschiedlich.
varying vec3 eyeDirection;
varying vec3 lightDirection;
void main()
{
float thickness;
vec4 pos = gl_ModelViewProjectionMatrix * gl_Vertex;
vec3 tangent = (gl_ModelViewProjectionMatrix * vec4(gl_Normal,0.)).xyz; // transform our tangent vector
float tmp = dot(-pos.xyz, tangent);
gl_ClipVertex = gl_ModelViewMatrix * gl_Vertex; // make clipping planes work
vec3 tangent = ( gl_ModelViewProjectionMatrix * vec4(gl_Normal, 1. ) ).xyz; //!< transform our tangent vector
vec3 tangentR3 = normalize(gl_NormalMatrix * gl_Normal);
vec3 eyeDir = normalize(-(gl_ModelViewMatrix * gl_Vertex).xyz);
gl_ClipVertex = gl_ModelViewMatrix * gl_Vertex;//!< make clipping planes work
//scalar product between viewDir and tangent
float tmp = dot( tangent, eyeDir);
//calculation for pointsprites
if(tmp > 0.93 ||psTexCoords.t == 0.0 )
if(tmp > 0.93 ||psTexCoords.t == 0.0 || !useQuadStripes)
{
vec3 lightPosition = vec3(0., 0., -1.);
tangentR3 = gl_Normal;
float thickness;
vec3 lightPos = vec3(0., 0., 0.);
vec3 lightDir = normalize(lightPos+eyeDir);
vec3 ez = vec3(0., 0., -1.0);
endPoint = 1.0;
if ( useDepthCueing )
if ( useDepthCueing || useProjection )
{
z = pos.z;
float z1 =0.5 + 0.5 * ( ( gl_ModelViewProjectionMatrix * vec4( nearPos, 1.0 ) ).z );
......@@ -60,43 +73,35 @@ void main()
zNear = min( z1, min( z2, min( z3, min( z4, min( z5, min( z6, min( z7,z8)))))));
}
view = - pos.xyz;
vec3 cameraPosition = vec3(gl_ModelViewProjectionMatrix * vec4(0.0, 0.0, 1.0, 0.0));
vec3 referencePosition = vec3(gl_ModelViewProjectionMatrix * vec4(0.0, 0.0, -1.0, 0.0));
lightDir = normalize( lightPosition - pos.xyz);
halfVector = normalize( eyeDir + lightDir );
vec3 binormal = normalize( cross( tangentR3, eyeDir ) );
normal = normalize( cross( binormal, tangentR3));
vec3 cameraPosition = vec3(gl_ModelViewMatrixInverse * vec4(0,0,0,1.0));
vec3 cameraVector = cameraPosition - gl_Vertex.xyz;
vec3 referencePosition = vec3(gl_ModelViewProjectionMatrix * vec4(1.0, 1.0, 1.0, 0.0));
halfVector = normalize(cross(view,tangent));
normal = cross( halfVector, tangent);
lightDirection = lightDir;
eyeDirection = eyeDir;
// color of tube
tubeColor = gl_Color;
vec3 offsetNN;
vec3 offset = normalize(cross( eyeDir, tangentR3));
if ( useProjection )
{
offsetNN = cross( (tangent.xyz), vec3(.0, .0, -1.));
}
else
{
offsetNN = cross( normalize(tangent.xyz), vec3(.0, .0, -1.));
thickness *= clamp(( 1 - z + zNear ) / ( zNear + zFar ), lowerDepthCueingFactor, upperDepthCueingFactor );
}
vec3 offset = normalize(offsetNN);
tangent_dot_view = length(offsetNN);
//scalar product between viewDir and tangent
// compute thickness
thickness *= length(referencePosition) * u_thickness * 0.001;
thickness = max(distance(referencePosition, cameraPosition), 0.1) * u_thickness * 0.001;
offset.x *= thickness*u_viewportWidth;
offset.y *= thickness*u_viewportHeight;
vec4 pos1 = gl_Vertex;
vec4 pos2 = gl_Vertex + vec4(gl_Normal,1);
vec4 pos1p = gl_ModelViewProjectionMatrix * pos1.xyzw;
vec4 pos2p = gl_ModelViewProjectionMatrix * pos2.xyzw;
vec4 pos1p = gl_ModelViewProjectionMatrix * pos1;
vec4 pos2p = gl_ModelViewProjectionMatrix * pos2;
imageTangent.xy = (pos2p.x/pos2p.w - pos1p.x/pos1p.w, pos1p.y/pos1p.w - pos2p.y/pos2p.w);
imageTangent = normalize(imageTangent);
......
varying vec3 tangentR3; // Tangent vector in world space
varying float s_param; // s parameter of texture [-1..1]
varying float tangent_dot_view;
uniform bool globalColor;
uniform sampler1D texture;
uniform sampler2D texturePS;
varying float usePointSprite;
varying vec2 imageTangent;
uniform sampler2D textureDiff2D;
uniform sampler2D textureSpec2D;
varying vec4 tubeColor;
varying vec3 view;
varying vec3 lightDir;
......@@ -16,6 +13,7 @@ varying float endPoint;
varying float z;
varying float zNear;
varying float zFar;
varying vec3 tangentR3;
uniform bool useDepthCueing;
uniform bool useLightModel;
......@@ -23,34 +21,51 @@ uniform bool usePointSprites;
uniform bool useQuadStripes;
uniform bool useProjection;
uniform float lowerDepthCueingFactor;
uniform float upperDepthCueingFactor;
varying vec3 eyeDirection;
varying vec3 lightDirection;
void main()
{
vec3 L,V, T, N, halfV;
vec3 specular = 0.0;
float specular = 0.0;
float NdotL,NdotHV;
float alpha, beta, lt;
T = normalize(tangentR3);
V = normalize(view);
L = normalize(lightDir);
V = normalize(eyeDirection);
L = normalize(lightDirection);
N = normalize(normal);
float depthCueingFactor = 1.0;
//NdotL = max(dot(N,L),0.0);
vec4 color;
NdotL = saturate(dot(N, L));
if ( useDepthCueing )
{
depthCueingFactor = clamp( ( 1 - z + zNear ) / ( zNear + zFar ), lowerDepthCueingFactor, upperDepthCueingFactor );
}
if ( useLightModel )
{
// koordinaten für illuminated lines texturen
halfV = normalize(halfVector);
alpha = dot(L,N) / sqrt(1 - pow( dot(L,T),2));
beta = dot(halfVector,N) / sqrt( 1 - pow( dot(halfVector, T), 2));
float ht = sqrt( 1 - pow( dot(halfV, T), 2));
beta = dot(halfV,N) / ht;
lt = dot(L, T);
vec4 colorDiff = texture2D(textureDiff2D, vec2( alpha, lt ));
vec4 colorSpec = texture2D(textureSpec2D, vec2( alpha, beta ));
gl_FragColor.rgb = (tubeColor.rgb * ((vec3(0.2,0.2,0.2)+vec3(0.6,0.6,0.6)*pow(ht,64)*colorDiff.x) + vec3(0.6,0.6,0.6)*colorSpec.x )) * depthCueingFactor * depthCueingFactor;
}
else
{
color = texture1D(texture, gl_TexCoord[1].s);
vec4 color = texture1D(texture, (gl_TexCoord[1].s ));
gl_FragColor.a = tubeColor.a;
}
/* compute the specular term if NdotL is larger than zero */
if (NdotL > 0.0)
{
......@@ -58,13 +73,10 @@ void main()
// cosine (dot product) with the normal
halfV = normalize(halfVector);
NdotHV = max(dot(N, halfV),0.0);
NdotHV = saturate(dot(N, halfV));
specular = pow(NdotHV,16) * color.y;
}
if ( useDepthCueing )
{
depthCueingFactor = clamp((1 - (z+zNear)/(zNear+zFar)),0.5,0.8);
}
gl_FragColor.rgb = ( tubeColor.rgb * color.x + specular ) * depthCueingFactor * depthCueingFactor;
gl_FragColor.rgb = (tubeColor.rgb * ((vec3(0.2,0.2,0.2)+vec3(0.6,0.6,0.6)*NdotL*color.r) + vec3(0.6,0.6,0.6)*specular )) * depthCueingFactor * depthCueingFactor;
}
}
......@@ -11,6 +11,10 @@ varying vec3 normal;
varying vec3 halfVector;
varying float endPoint;
// Auch die Richtung zum Betrachter ist in der Regel
// für jedes Fragment unterschiedlich.
varying vec3 eyeDirection;
varying vec3 lightDirection;
varying float z;
varying float zNear;
......@@ -30,15 +34,20 @@ uniform bool useLightModel;
uniform bool usePointSprites;
uniform bool useQuadStripes;
uniform bool useProjection;
uniform float lowerDepthCueingFactor;
uniform float upperDepthCueingFactor;
void main()
{
vec4 pos = gl_ModelViewProjectionMatrix * gl_Vertex;
vec3 tangent = ( gl_ModelViewProjectionMatrix * vec4(gl_Normal, 0. ) ).xyz; //!< transform our tangent vector
gl_ClipVertex = gl_ModelViewMatrix * gl_Vertex; //!< make clipping planes work
vec4 posWorld = gl_ModelViewMatrix * gl_Vertex;
vec3 tangent = ( gl_ModelViewProjectionMatrix * vec4(gl_Normal, 1. ) ).xyz; //!< transform our tangent vector
vec3 tangentR3 = normalize((gl_NormalMatrix * gl_Normal));
vec3 eyeDir = normalize(-(gl_ModelViewMatrix * gl_Vertex).xyz);
gl_ClipVertex = gl_ModelViewMatrix * gl_Vertex;//!< make clipping planes work
//scalar product between viewDir and tangent
float tmp = dot(-pos.xyz, tangent);
float tmp = dot( tangentR3, eyeDir);
//decide wether point sprite or triangle strip to render
// don't draw quad strip //decide wether point sprite or triangle strip to render
......@@ -49,12 +58,11 @@ void main()
else
{
float thickness;
vec3 lightPos = vec3(0., 0., -1000.);
vec3 lightPos = vec3(0., 0., 0.);
vec3 lightDir = normalize(lightPos+eyeDir);
vec3 ez = vec3(0., 0., -1.0);
tangentR3 = gl_NormalMatrix * gl_Normal;
if ( useDepthCueing )
if ( useDepthCueing || useProjection )
{
z = pos.z;
float z1 =0.5 + 0.5 * ( ( gl_ModelViewProjectionMatrix * vec4( nearPos, 1.0 ) ).z );
......@@ -69,40 +77,35 @@ void main()
zFar = max( z1, max( z2, max( z3, max( z4, max( z5, max( z6, max( z7,z8)))))));
zNear = min( z1, min( z2, min( z3, min( z4, min( z5, min( z6, min( z7,z8)))))));
}
light = lightPos - pos;
vec3 cameraPosition = vec3(gl_ModelViewMatrixInverse * vec4(0.0, 0.0, 0.0, 1.0));
vec3 referencePosition = vec3(gl_ModelViewProjectionMatrix * vec4(1.0, 1.0, 1.0, 0.0));
halfVector = normalize( -pos + light );
vec3 binormal = normalize( cross( tangent, -pos ) );
normal = cross( binormal, tangentR3);
NdotL = max(dot(normal, light), 0.0);
//define thickness of tubes
thickness = u_thickness * 0.001; //* cross( cameraPosition, referencePosition );
vec3 cameraPosition = vec3(gl_ModelViewProjectionMatrix * vec4(0.0, 0.0, 1.0, 0.0));
vec3 referencePosition = vec3(gl_ModelViewProjectionMatrix * vec4(0.0, 0.0, -1.0, 0.0));
// color of tube
tubeColor = gl_Color;
vec3 offsetNN;
vec3 offset = normalize(cross( eyeDir, tangentR3));
//define thickness of tubes
thickness = u_thickness * 0.001;
if ( useProjection )
{
offsetNN = cross( (tangent.xyz), vec3(.0, .0, -1.));
}
else
{
offsetNN = cross( normalize(tangent.xyz), vec3(.0, .0, -1.));
thickness *= clamp( ( 1 - z + zNear ) / ( zNear + zFar ), lowerDepthCueingFactor, upperDepthCueingFactor );
}
vec3 offset = normalize(offsetNN);
tangent_dot_view = length(offsetNN);
thickness *= length(referencePosition);
offset.x *= thickness;
offset.y *= thickness;
thickness *= max(distance(referencePosition, cameraPosition), 0.1);
offset.xy *= thickness;
// transform quad points to position
pos.xyz += offset * qsTexCoords.s; //< add offset in y-direction (eye-space)
halfVector = normalize( ( eyeDir + lightDir ));
vec3 binormal = normalize( cross( tangentR3, eyeDir ) );
normal = cross( binormal, tangentR3);
lightDirection = lightDir;
eyeDirection = eyeDir;
// TexCoord for 1D texture
gl_TexCoord[1].s = qsTexCoords.t;
}
......
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