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

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

parent a7ef1a85
......@@ -22,6 +22,9 @@
//
//---------------------------------------------------------------------------
#include <cstdlib>
#include <cmath>
#include <list>
#include <string>
#include <vector>
......@@ -32,6 +35,8 @@
#include <osg/Geometry>
#include <osg/Texture1D>
#include <osg/Texture2D>
#include <osgDB/ReadFile>
#include <osgDB/WriteFile>
#include "../../../common/WColor.h"
#include "../../../common/WLogger.h"
......@@ -44,6 +49,8 @@
#include "fiberdisplay.xpm"
#include "WMFiberDisplay.h"
#define PI 3.141592653589793
bool WMFiberDisplay::m_fiberDisplayRunning = false;
WMFiberDisplay::WMFiberDisplay()
......@@ -210,7 +217,7 @@ void WMFiberDisplay::create()
m_tubeGeometryPointSprite->setUseDisplayList( false );
m_tubeGeometryPointSprite->setUseVertexBufferObjects( true );
osg::VertexBufferObject* m_vboPS = m_tubeGeometryPointSprite->getOrCreateVertexBufferObject();
m_vboPS->setUsage( GL_STREAM_DRAW );
m_vboPS->setUsage( GL_STATIC_DRAW );
m_tubeGeometryPointSprite->setDataVariance( osg::Object::DYNAMIC );
m_geodePointSprite = osg::ref_ptr< osg::Geode >( new osg::Geode );
m_geodePointSprite->addDrawable( m_tubeGeometryPointSprite );
......@@ -220,7 +227,7 @@ void WMFiberDisplay::create()
m_tubeGeometryQuadStripes->setUseDisplayList( false );
m_tubeGeometryQuadStripes->setUseVertexBufferObjects( true );
osg::VertexBufferObject* m_vboQS = m_tubeGeometryQuadStripes->getOrCreateVertexBufferObject();
m_vboQS->setUsage( GL_STREAM_DRAW );
m_vboQS->setUsage( GL_STATIC_DRAW );
m_tubeGeometryQuadStripes->setDataVariance( osg::Object::DYNAMIC );
m_geodeQuadStripes = osg::ref_ptr< osg::Geode >( new osg::Geode );
m_geodeQuadStripes->addDrawable( m_tubeGeometryQuadStripes );
......@@ -298,12 +305,16 @@ void WMFiberDisplay::properties()
m_tubeThickness->setMax( 300 );
m_depthCueing = m_properties->addProperty( "Use depth cueing", "Activates depth cueing for the shaders.", true );
m_lightModel = m_properties->addProperty( "Change lightning", "Changes lightning model", false );
m_lightModel = m_properties->addProperty( "Change lighting", "Changes lighting model", false );
m_usePointSprites = m_properties->addProperty( "Use PointSprites", "", true );
m_useQuadStripes = m_properties->addProperty( "Use QuadStripes", "", true );
m_useProjection = m_properties->addProperty( "Projection or Orthogonal", "", false );
//m_lowDepthCueingFactor;
//m_upperDepthCueingFactor;
m_useProjection = m_properties->addProperty( "Use projection", "", false );
m_lowDepthCueingFactor = m_properties->addProperty( "Lower DCF", "Adjusts the thickness of the tubes.", 50. );
m_lowDepthCueingFactor->setMin( 0 );
m_lowDepthCueingFactor->setMax( 100 );
m_upperDepthCueingFactor = m_properties->addProperty( "Upper DCF", "Adjusts the thickness of the tubes.", 85. );
m_upperDepthCueingFactor->setMin( 0 );
m_upperDepthCueingFactor->setMax( 100 );
m_save = m_properties->addProperty( "Save", "Saves the selected fiber bundles.", false, boost::bind( &WMFiberDisplay::saveSelected, this ) );
m_saveFileName = m_properties->addProperty( "File name", "", WPathHelper::getAppPath() );
......@@ -381,18 +392,23 @@ void WMFiberDisplay::updateRenderModes()
m_uniformDepthCueing->set( m_depthCueing->get( true ) );
}
if ( m_lightModel->changed() )
if ( m_upperDepthCueingFactor->changed() )
{
m_uniformLightModel->set( m_lightModel->get( true ) );
m_uniformUpperDepthCueingFactor->set( static_cast<float>( m_upperDepthCueingFactor->get( true ) * 0.01 ) );
}
if ( m_usePointSprites->changed() && m_useTubesProp->get() && false )
if ( m_lowDepthCueingFactor->changed() )
{
m_uniformLowDepthCueingFactor->set( static_cast<float>( m_lowDepthCueingFactor->get( true ) * 0.01 ) );
}
if ( m_usePointSprites->changed() && m_useTubesProp->get() )
{
m_uniformUsePointSprites->set( m_usePointSprites->get( true ) );
m_osgNode->setChildValue( m_geodePointSprite, m_usePointSprites->get() );
}
if ( m_useQuadStripes->changed() && m_useTubesProp->get() && false )
if ( m_useQuadStripes->changed() && m_useTubesProp->get() )
{
m_uniformUseQuadStripes->set( m_useQuadStripes->get( true ) );
m_osgNode->setChildValue( m_geodeQuadStripes, m_useQuadStripes->get() );
......@@ -549,8 +565,8 @@ void WMFiberDisplay::initUniforms( osg::StateSet* rootState )
m_uniformLightModel= osg::ref_ptr<osg::Uniform>( new osg::Uniform( "useLightModel", false ) );
m_uniformUsePointSprites = osg::ref_ptr<osg::Uniform>( new osg::Uniform( "usePointSprites", true ) );
m_uniformUseQuadStripes = osg::ref_ptr<osg::Uniform>( new osg::Uniform( "useQuadStripes", true ) );
m_uniformLowDepthCueingFactor = osg::ref_ptr<osg::Uniform>( new osg::Uniform( "lowerDepthCueingFactor", 0.2f ) );
m_uniformUpperDepthCueingFactor = osg::ref_ptr<osg::Uniform>( new osg::Uniform( "upperDepthCueingFactor", 0.8f ) );
m_uniformLowDepthCueingFactor = osg::ref_ptr<osg::Uniform>( new osg::Uniform( "lowerDepthCueingFactor", 0.5f ) );
m_uniformUpperDepthCueingFactor = osg::ref_ptr<osg::Uniform>( new osg::Uniform( "upperDepthCueingFactor", 0.85f ) );
m_uniformUseProjection = osg::ref_ptr<osg::Uniform>( new osg::Uniform( "useProjection", false ) );
rootState->addUniform( m_uniformDepthCueing );
......@@ -610,92 +626,139 @@ void WMFiberDisplay::userData::toggleColoring()
parent->toggleColoring();
}
void WMFiberDisplay::create2DTexDiffuseLightning( osg::StateSet* m_rootState ) const
void WMFiberDisplay::create2DTexturesBlinn( osg::StateSet* m_rootState ) const
{
osg::Image* image = new osg::Image;
double s, t;
double lt;
double alpha, beta;
double diffTerm, specTerm;
double stretchDiff, stretchSpec;
int n = 64;
int texDim = 64;
osg::ref_ptr< osg::Image > imageSpec = new osg::Image;
osg::ref_ptr< osg::Image > imageDiff = new osg::Image;
// allocate the image data, texDim x texDim x 1 with 4 rgba floats - equivalent to a Vec4!
imageSpec->allocateImage( texDim, texDim, 1, GL_RGBA, GL_UNSIGNED_BYTE );
imageDiff->allocateImage( texDim, texDim, 1, GL_RGBA, GL_UNSIGNED_BYTE );
int noPixels = 64;
// fill in the image data.
unsigned char *dataPtrSpec = imageSpec->data();
unsigned char *dataPtrDiff = imageDiff->data();
// allocate the image data, noPixels x noPixels x 1 with 4 rgba floats - equivalent to a Vec4!
image->allocateImage( noPixels, noPixels, 1, GL_RGBA, GL_FLOAT );
image->setInternalTextureFormat( GL_RGBA );
stretchDiff = ( 4.0 / PI );
float stepAlpha = M_PI / 4 * static_cast<float>( noPixels );
float stepLt = M_PI / 2 * static_cast<float>( noPixels );
float alpha, lt, diffuse = 0.0f;
double factor = 1.0;
while ( n > 0 )
{
factor *= ( double )( n + 1 ) / ( double ) n;
n -= 2;
}
// fill in the image data.
osg::Vec4* dataPtr = ( osg::Vec4* )image->data();
osg::Vec4 color;
for( int i = 0; i < noPixels; ++i )
if( ( n % 2 ) == 0 )
{
alpha = static_cast<float>( i * stepAlpha );
stretchSpec = factor;
}
else
{
stretchSpec = ( 2.0 / PI ) * factor;
}
for( int j = 0; j < noPixels; ++j )
// compute texture for blinn lighting:
for ( int y = 0; y < texDim; y++ )
{
for ( int x = 0; x < texDim; x++ )
{
lt = static_cast<float>( j * stepLt );
diffuse = sqrt( 1 - pow( lt, 2 ) ) * ( sin( alpha ) + ( M_PI - alpha ) * cos( alpha ) ) / 4;
color = osg::Vec4( diffuse, 0.0f, 0.0f, 0.0f );
*dataPtr++ = color;
// no divisions by zero
s = ( ( double ) x + 0.5 ) / ( double ) texDim;
t = ( ( double ) y + 0.5 ) / ( double ) texDim;
alpha = acos( 2.0 * s - 1.0 );
lt = 2.0 * t - 1.0;
beta = acos( 2.0 * t - 1.0 );
diffTerm = stretchDiff * sqrt( 1.0 - lt * lt )* ( sin( alpha ) + ( PI - alpha ) * cos( alpha ) ) / 4.0;
specTerm = stretchSpec * computeSpecIntegral( alpha, beta, n );
dataPtrDiff[ ( 4 * y * texDim ) + ( 4 * x ) + 0 ] = static_cast< unsigned char >( diffTerm * 255.0 );
dataPtrDiff[ ( 4 * y * texDim ) + ( 4 * x ) + 1 ] = static_cast< unsigned char >( 255.0 );
dataPtrDiff[ ( 4 * y * texDim ) + ( 4 * x ) + 2 ] = static_cast< unsigned char >( 255.0 );
dataPtrDiff[ ( 4 * y * texDim ) + ( 4 * x ) + 3 ] = static_cast< unsigned char >( 255.0 );
dataPtrSpec[ ( 4 * y * texDim ) + ( 4 * x ) + 0 ] = static_cast< unsigned char >( specTerm * 255.0 );
dataPtrSpec[ ( 4 * y * texDim ) + ( 4 * x ) + 1 ] = static_cast< unsigned char >( 255.0 );
dataPtrSpec[ ( 4 * y * texDim ) + ( 4 * x ) + 2 ] = static_cast< unsigned char >( 255.0 );
dataPtrSpec[ ( 4 * y * texDim ) + ( 4 * x ) + 3 ] = static_cast< unsigned char >( 255.0 );
}
}
osg::Texture2D* texture = new osg::Texture2D;
texture->setDataVariance( osg::Object::STATIC );
texture->setWrap( osg::Texture2D::WRAP_S, osg::Texture2D::CLAMP );
texture->setFilter( osg::Texture2D::MIN_FILTER, osg::Texture2D::LINEAR );
texture->setImage( image );
m_rootState->setTextureAttribute( 5, texture, osg::StateAttribute::OVERRIDE );
osg::Texture2D* textureSpec = new osg::Texture2D;
textureSpec->setDataVariance( osg::Object::STATIC );
textureSpec->setWrap( osg::Texture2D::WRAP_S, osg::Texture2D::CLAMP_TO_BORDER );
textureSpec->setWrap( osg::Texture2D::WRAP_T, osg::Texture2D::CLAMP_TO_BORDER );
textureSpec->setFilter( osg::Texture2D::MIN_FILTER, osg::Texture2D::LINEAR_MIPMAP_LINEAR );
textureSpec->setFilter( osg::Texture2D::MAG_FILTER, osg::Texture2D::LINEAR );
textureSpec->setImage( imageSpec );
//osgDB::writeImageFile( *imageSpec, "share/fileSpec.png" );
m_rootState->setTextureAttribute( 4, textureSpec, osg::StateAttribute::OVERRIDE );
m_rootState->setTextureMode( 4, GL_TEXTURE_2D, osg::StateAttribute::ON|osg::StateAttribute::OVERRIDE );
m_rootState->addUniform( osg::ref_ptr<osg::Uniform>( new osg::Uniform( "textureSpec2D", 4 ) ) );
osg::Texture2D* textureDiff = new osg::Texture2D;
textureDiff->setDataVariance( osg::Object::STATIC );
textureDiff->setWrap( osg::Texture2D::WRAP_S, osg::Texture2D::CLAMP_TO_BORDER );
textureDiff->setWrap( osg::Texture2D::WRAP_T, osg::Texture2D::CLAMP_TO_BORDER );
textureDiff->setFilter( osg::Texture2D::MIN_FILTER, osg::Texture2D::LINEAR_MIPMAP_LINEAR );
textureDiff->setFilter( osg::Texture2D::MAG_FILTER, osg::Texture2D::LINEAR );
textureDiff->setImage( imageDiff );
//osgDB::writeImageFile( *imageDiff, "share/fileDiff.png" );
m_rootState->setTextureAttribute( 5, textureDiff, osg::StateAttribute::OVERRIDE );
m_rootState->setTextureMode( 5, GL_TEXTURE_2D, osg::StateAttribute::ON|osg::StateAttribute::OVERRIDE );
m_rootState->addUniform( osg::ref_ptr<osg::Uniform>( new osg::Uniform( "textureDiff2D", 5 ) ) );
}
void WMFiberDisplay::create2DTexSpecularLightning( osg::StateSet* m_rootState ) const
double WMFiberDisplay::computeSpecIntegral( double alpha, double beta, int n ) const
{
osg::Image* image = new osg::Image;
double lowerBorder = alpha - PI / 2.0;
double upperBorder = PI / 2.0;
int noPixels = 64;
int noExponents = 64;
int steps = 10;
double currentIntPos = ( upperBorder - lowerBorder ) / ( 2.0 * steps );
//vector<float> sn;
double integral = 0.0;
double xi;
// allocate the image data, noPixels x noPixels x 1 with 4 rgba floats - equivalent to a Vec4!
image->allocateImage( noPixels, noPixels, 1, GL_RGBA, GL_FLOAT );
image->setInternalTextureFormat( GL_RGBA );
for ( int i = 0; i < 2 * steps; i += 2 )
{
xi = lowerBorder + i * currentIntPos;
integral += 2.0 * computeIntegrand( beta, n, xi );
xi = lowerBorder + ( i + 1 ) * currentIntPos;
integral += 4.0 * computeIntegrand( beta, n, xi );
}
integral += computeIntegrand( beta, n, upperBorder );
float stepAlpha = M_PI / 4 * static_cast<float>( noPixels );
float stepLt = M_PI / 2 * static_cast<float>( noPixels );
float alpha, lt, diffuse = 0.0f;
// f(a) added twice
integral -= computeIntegrand( beta, n, lowerBorder );
// fill in the image data.
osg::Vec4* dataPtr = ( osg::Vec4* )image->data();
osg::Vec4 color;
for( int i = 0; i < noPixels; ++i )
{
alpha = static_cast<float>( i * stepAlpha );
integral *= currentIntPos / 3.0;
for( int j = 0; j < noPixels; ++j )
{
lt = static_cast<float>( j * stepLt );
diffuse = sqrt( 1- pow( lt, 2 ) ) * ( sin( alpha ) + ( M_PI - alpha ) * cos( alpha ) ) / 4;
color = osg::Vec4( diffuse, 0.0f, 0.0f, 0.0f );
return (integral);
}
*dataPtr++ = color;
}
double WMFiberDisplay::computeIntegrand( double beta, int n, double theta ) const
{
double y = cos( theta - beta );
if ( y < 0.0 )
{
y = 0.0;
}
osg::Texture2D* texture = new osg::Texture2D;
texture->setDataVariance( osg::Object::STATIC );
texture->setWrap( osg::Texture2D::WRAP_S, osg::Texture2D::CLAMP );
texture->setFilter( osg::Texture2D::MIN_FILTER, osg::Texture2D::LINEAR );
texture->setImage( image );
m_rootState->setTextureAttribute( 4, texture, osg::StateAttribute::OVERRIDE );
m_rootState->setTextureMode( 4, GL_TEXTURE_2D, osg::StateAttribute::ON|osg::StateAttribute::OVERRIDE );
m_rootState->addUniform( osg::ref_ptr<osg::Uniform>( new osg::Uniform( "textureSpec2D", 4 ) ) );
return ( pow( y, n ) * ( cos( theta ) / 2.0 ) );
}
void WMFiberDisplay::create1DTextureRectLightning( osg::StateSet* m_rootState ) const
void WMFiberDisplay::create1DTextureRectLighting( osg::StateSet* m_rootState ) const
{
osg::Image* image = new osg::Image;
......@@ -703,7 +766,6 @@ void WMFiberDisplay::create1DTextureRectLightning( osg::StateSet* m_rootState )
// allocate the image data, noPixels x 1 x 1 with 4 rgba floats - equivalent to a Vec4!
image->allocateImage( noPixels, 1, 1, GL_RGBA, GL_FLOAT );
image->setInternalTextureFormat( GL_RGBA );
float step = M_PI / static_cast<float>( noPixels );
float diffuse, specular = 0.0f;
......@@ -732,30 +794,27 @@ void WMFiberDisplay::create1DTextureRectLightning( osg::StateSet* m_rootState )
}
void WMFiberDisplay::create2DTextureCycleLightning( osg::StateSet* m_rootState ) const
void WMFiberDisplay::create2DTextureCycleLighting( osg::StateSet* m_rootState ) const
{
osg::Image* image = new osg::Image;
int noPixels = 64;
// allocate the image data, noPixels x noPixels x 1 with 4 rgba floats - equivalent to a Vec4!
image->allocateImage( noPixels, noPixels, 1, GL_RGBA, GL_FLOAT );
image->setInternalTextureFormat( GL_RGBA );
float step = M_PI / static_cast<float>( noPixels );
float alpha, diffuse, specular = 0.0f;
float check;
float check, border;
const size_t resX = 64;
osg::ref_ptr< osg::Image > randImage = new osg::Image();
randImage->allocateImage( resX, resX, 1, GL_RGBA, GL_UNSIGNED_BYTE );
unsigned char *randomLuminance = randImage->data(); // should be 4 megs
for( unsigned int x = 0; x < resX; x++ )
unsigned char *randomLuminance = randImage->data();
for( unsigned int y = 0; y < resX; y++ )
{
diffuse = sin( static_cast<float>( x * step ) );
diffuse = sin( static_cast<float>( y * step ) );
specular = pow( diffuse, 16 );
for( unsigned int y = 0; y < resX; y++ )
for( unsigned int x = 0; x < resX; x++ )
{
border = 1.0;
check = pow( 2.0 * ( static_cast< float >( x ) / static_cast< float >( resX ) ) - 1.0, 2.0 ) +
pow( 2.0 * ( static_cast< float >( y ) / static_cast< float >( resX ) ) - 1.0, 2.0 );
if( check > 1.0 )
......@@ -764,13 +823,17 @@ void WMFiberDisplay::create2DTextureCycleLightning( osg::StateSet* m_rootState )
}
else
{
if( check > 0.9 )
{
border = 0.0;
}
alpha = 1.0f;
}
randomLuminance[ ( 4 * y * resX ) + ( 4 * x ) + 0 ] = static_cast< unsigned char >( diffuse * 255.0 );
randomLuminance[ ( 4 * y * resX ) + ( 4 * x ) + 1 ] = static_cast< unsigned char >( specular * 255.0 );
randomLuminance[ ( 4 * y * resX ) + ( 4 * x ) + 2 ] = static_cast< unsigned char >( alpha * 255.0 );
randomLuminance[ ( 4 * y * resX ) + ( 4 * x ) + 3 ] = 255;
randomLuminance[ ( 4 * y * resX ) + ( 4 * x ) + 3 ] = static_cast< unsigned char >( border * 255.0 );
}
}
osg::Texture2D* texture = new osg::Texture2D;
......@@ -780,6 +843,7 @@ void WMFiberDisplay::create2DTextureCycleLightning( osg::StateSet* m_rootState )
texture->setFilter( osg::Texture2D::MIN_FILTER, osg::Texture2D::LINEAR_MIPMAP_LINEAR );
texture->setFilter( osg::Texture2D::MAG_FILTER, osg::Texture2D::LINEAR );
texture->setImage( randImage );
//osgDB::writeImageFile( *randImage, "share/file.png" );
m_rootState->setTextureAttribute( 6, texture, osg::StateAttribute::OVERRIDE );
m_rootState->setTextureMode( 6, GL_TEXTURE_2D, osg::StateAttribute::ON | osg::StateAttribute::OVERRIDE );
......@@ -788,11 +852,10 @@ void WMFiberDisplay::create2DTextureCycleLightning( osg::StateSet* m_rootState )
void WMFiberDisplay::createTextures( osg::StateSet* m_rootState ) const
{
create1DTextureRectLightning( m_rootState );
create2DTextureCycleLightning( m_rootState );
create1DTextureRectLighting( m_rootState );
create2DTextureCycleLighting( m_rootState );
create2DTexDiffuseLightning( m_rootState );
create2DTexSpecularLightning( m_rootState );
create2DTexturesBlinn( m_rootState );
}
void WMFiberDisplay::createTubeData()
......
......@@ -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,16 +151,16 @@ 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();
primitiveset->draw( state, true );
if( (*active)[primitiveSetNum] )
{
primitiveset->draw( state, true );
}
}
}
else
......
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,39 +51,38 @@ 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 )
{
//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;
depthCueingFactor = clamp(( 1 - z + zNear ) / ( zNear + zFar ), lowerDepthCueingFactor, upperDepthCueingFactor );
}
if(endPoint == 0.0)
{