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 @@ ...@@ -22,6 +22,9 @@
// //
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
#include <cstdlib>
#include <cmath>
#include <list> #include <list>
#include <string> #include <string>
#include <vector> #include <vector>
...@@ -32,6 +35,8 @@ ...@@ -32,6 +35,8 @@
#include <osg/Geometry> #include <osg/Geometry>
#include <osg/Texture1D> #include <osg/Texture1D>
#include <osg/Texture2D> #include <osg/Texture2D>
#include <osgDB/ReadFile>
#include <osgDB/WriteFile>
#include "../../../common/WColor.h" #include "../../../common/WColor.h"
#include "../../../common/WLogger.h" #include "../../../common/WLogger.h"
...@@ -44,6 +49,8 @@ ...@@ -44,6 +49,8 @@
#include "fiberdisplay.xpm" #include "fiberdisplay.xpm"
#include "WMFiberDisplay.h" #include "WMFiberDisplay.h"
#define PI 3.141592653589793
bool WMFiberDisplay::m_fiberDisplayRunning = false; bool WMFiberDisplay::m_fiberDisplayRunning = false;
WMFiberDisplay::WMFiberDisplay() WMFiberDisplay::WMFiberDisplay()
...@@ -210,7 +217,7 @@ void WMFiberDisplay::create() ...@@ -210,7 +217,7 @@ void WMFiberDisplay::create()
m_tubeGeometryPointSprite->setUseDisplayList( false ); m_tubeGeometryPointSprite->setUseDisplayList( false );
m_tubeGeometryPointSprite->setUseVertexBufferObjects( true ); m_tubeGeometryPointSprite->setUseVertexBufferObjects( true );
osg::VertexBufferObject* m_vboPS = m_tubeGeometryPointSprite->getOrCreateVertexBufferObject(); 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_tubeGeometryPointSprite->setDataVariance( osg::Object::DYNAMIC );
m_geodePointSprite = osg::ref_ptr< osg::Geode >( new osg::Geode ); m_geodePointSprite = osg::ref_ptr< osg::Geode >( new osg::Geode );
m_geodePointSprite->addDrawable( m_tubeGeometryPointSprite ); m_geodePointSprite->addDrawable( m_tubeGeometryPointSprite );
...@@ -220,7 +227,7 @@ void WMFiberDisplay::create() ...@@ -220,7 +227,7 @@ void WMFiberDisplay::create()
m_tubeGeometryQuadStripes->setUseDisplayList( false ); m_tubeGeometryQuadStripes->setUseDisplayList( false );
m_tubeGeometryQuadStripes->setUseVertexBufferObjects( true ); m_tubeGeometryQuadStripes->setUseVertexBufferObjects( true );
osg::VertexBufferObject* m_vboQS = m_tubeGeometryQuadStripes->getOrCreateVertexBufferObject(); 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_tubeGeometryQuadStripes->setDataVariance( osg::Object::DYNAMIC );
m_geodeQuadStripes = osg::ref_ptr< osg::Geode >( new osg::Geode ); m_geodeQuadStripes = osg::ref_ptr< osg::Geode >( new osg::Geode );
m_geodeQuadStripes->addDrawable( m_tubeGeometryQuadStripes ); m_geodeQuadStripes->addDrawable( m_tubeGeometryQuadStripes );
...@@ -298,12 +305,16 @@ void WMFiberDisplay::properties() ...@@ -298,12 +305,16 @@ void WMFiberDisplay::properties()
m_tubeThickness->setMax( 300 ); m_tubeThickness->setMax( 300 );
m_depthCueing = m_properties->addProperty( "Use depth cueing", "Activates depth cueing for the shaders.", true ); 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_usePointSprites = m_properties->addProperty( "Use PointSprites", "", true );
m_useQuadStripes = m_properties->addProperty( "Use QuadStripes", "", true ); m_useQuadStripes = m_properties->addProperty( "Use QuadStripes", "", true );
m_useProjection = m_properties->addProperty( "Projection or Orthogonal", "", false ); m_useProjection = m_properties->addProperty( "Use projection", "", false );
//m_lowDepthCueingFactor; m_lowDepthCueingFactor = m_properties->addProperty( "Lower DCF", "Adjusts the thickness of the tubes.", 50. );
//m_upperDepthCueingFactor; 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_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() ); m_saveFileName = m_properties->addProperty( "File name", "", WPathHelper::getAppPath() );
...@@ -381,18 +392,23 @@ void WMFiberDisplay::updateRenderModes() ...@@ -381,18 +392,23 @@ void WMFiberDisplay::updateRenderModes()
m_uniformDepthCueing->set( m_depthCueing->get( true ) ); 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_uniformUsePointSprites->set( m_usePointSprites->get( true ) );
m_osgNode->setChildValue( m_geodePointSprite, m_usePointSprites->get() ); 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_uniformUseQuadStripes->set( m_useQuadStripes->get( true ) );
m_osgNode->setChildValue( m_geodeQuadStripes, m_useQuadStripes->get() ); m_osgNode->setChildValue( m_geodeQuadStripes, m_useQuadStripes->get() );
...@@ -549,8 +565,8 @@ void WMFiberDisplay::initUniforms( osg::StateSet* rootState ) ...@@ -549,8 +565,8 @@ void WMFiberDisplay::initUniforms( osg::StateSet* rootState )
m_uniformLightModel= osg::ref_ptr<osg::Uniform>( new osg::Uniform( "useLightModel", false ) ); 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_uniformUsePointSprites = osg::ref_ptr<osg::Uniform>( new osg::Uniform( "usePointSprites", true ) );
m_uniformUseQuadStripes = osg::ref_ptr<osg::Uniform>( new osg::Uniform( "useQuadStripes", 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_uniformLowDepthCueingFactor = osg::ref_ptr<osg::Uniform>( new osg::Uniform( "lowerDepthCueingFactor", 0.5f ) );
m_uniformUpperDepthCueingFactor = osg::ref_ptr<osg::Uniform>( new osg::Uniform( "upperDepthCueingFactor", 0.8f ) ); 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 ) ); m_uniformUseProjection = osg::ref_ptr<osg::Uniform>( new osg::Uniform( "useProjection", false ) );
rootState->addUniform( m_uniformDepthCueing ); rootState->addUniform( m_uniformDepthCueing );
...@@ -610,92 +626,139 @@ void WMFiberDisplay::userData::toggleColoring() ...@@ -610,92 +626,139 @@ void WMFiberDisplay::userData::toggleColoring()
parent->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! stretchDiff = ( 4.0 / PI );
image->allocateImage( noPixels, noPixels, 1, GL_RGBA, GL_FLOAT );
image->setInternalTextureFormat( GL_RGBA );
float stepAlpha = M_PI / 4 * static_cast<float>( noPixels ); double factor = 1.0;
float stepLt = M_PI / 2 * static_cast<float>( noPixels ); while ( n > 0 )
float alpha, lt, diffuse = 0.0f; {
factor *= ( double )( n + 1 ) / ( double ) n;
n -= 2;
}
// fill in the image data. if( ( n % 2 ) == 0 )
osg::Vec4* dataPtr = ( osg::Vec4* )image->data();
osg::Vec4 color;
for( int i = 0; i < noPixels; ++i )
{ {
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 ); // no divisions by zero
diffuse = sqrt( 1 - pow( lt, 2 ) ) * ( sin( alpha ) + ( M_PI - alpha ) * cos( alpha ) ) / 4; s = ( ( double ) x + 0.5 ) / ( double ) texDim;
color = osg::Vec4( diffuse, 0.0f, 0.0f, 0.0f ); t = ( ( double ) y + 0.5 ) / ( double ) texDim;
*dataPtr++ = color; 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->setTextureMode( 5, GL_TEXTURE_2D, osg::StateAttribute::ON|osg::StateAttribute::OVERRIDE );
m_rootState->addUniform( osg::ref_ptr<osg::Uniform>( new osg::Uniform( "textureDiff2D", 5 ) ) ); 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 steps = 10;
int noExponents = 64; 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! for ( int i = 0; i < 2 * steps; i += 2 )
image->allocateImage( noPixels, noPixels, 1, GL_RGBA, GL_FLOAT ); {
image->setInternalTextureFormat( GL_RGBA ); 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 ); // f(a) added twice
float stepLt = M_PI / 2 * static_cast<float>( noPixels ); integral -= computeIntegrand( beta, n, lowerBorder );
float alpha, lt, diffuse = 0.0f;
// fill in the image data. integral *= currentIntPos / 3.0;
osg::Vec4* dataPtr = ( osg::Vec4* )image->data();
osg::Vec4 color;
for( int i = 0; i < noPixels; ++i )
{
alpha = static_cast<float>( i * stepAlpha );
for( int j = 0; j < noPixels; ++j ) return (integral);
{ }
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; 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 ); return ( pow( y, n ) * ( cos( theta ) / 2.0 ) );
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 ) ) );
} }
void WMFiberDisplay::create1DTextureRectLightning( osg::StateSet* m_rootState ) const void WMFiberDisplay::create1DTextureRectLighting( osg::StateSet* m_rootState ) const
{ {
osg::Image* image = new osg::Image; osg::Image* image = new osg::Image;
...@@ -703,7 +766,6 @@ void WMFiberDisplay::create1DTextureRectLightning( osg::StateSet* m_rootState ) ...@@ -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! // 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->allocateImage( noPixels, 1, 1, GL_RGBA, GL_FLOAT );
image->setInternalTextureFormat( GL_RGBA );
float step = M_PI / static_cast<float>( noPixels ); float step = M_PI / static_cast<float>( noPixels );
float diffuse, specular = 0.0f; float diffuse, specular = 0.0f;
...@@ -732,30 +794,27 @@ void WMFiberDisplay::create1DTextureRectLightning( osg::StateSet* m_rootState ) ...@@ -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; int noPixels = 64;
// allocate the image data, noPixels x noPixels x 1 with 4 rgba floats - equivalent to a Vec4! // 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 step = M_PI / static_cast<float>( noPixels );
float alpha, diffuse, specular = 0.0f; float alpha, diffuse, specular = 0.0f;
float check; float check, border;
const size_t resX = 64; const size_t resX = 64;
osg::ref_ptr< osg::Image > randImage = new osg::Image(); osg::ref_ptr< osg::Image > randImage = new osg::Image();
randImage->allocateImage( resX, resX, 1, GL_RGBA, GL_UNSIGNED_BYTE ); randImage->allocateImage( resX, resX, 1, GL_RGBA, GL_UNSIGNED_BYTE );
unsigned char *randomLuminance = randImage->data(); // should be 4 megs unsigned char *randomLuminance = randImage->data();
for( unsigned int x = 0; x < resX; x++ ) 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 ); 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 ) + 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 ); pow( 2.0 * ( static_cast< float >( y ) / static_cast< float >( resX ) ) - 1.0, 2.0 );
if( check > 1.0 ) if( check > 1.0 )
...@@ -764,13 +823,17 @@ void WMFiberDisplay::create2DTextureCycleLightning( osg::StateSet* m_rootState ) ...@@ -764,13 +823,17 @@ void WMFiberDisplay::create2DTextureCycleLightning( osg::StateSet* m_rootState )
} }
else else
{ {
if( check > 0.9 )
{
border = 0.0;
}
alpha = 1.0f; alpha = 1.0f;
} }
randomLuminance[ ( 4 * y * resX ) + ( 4 * x ) + 0 ] = static_cast< unsigned char >( diffuse * 255.0 ); 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 ) + 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 ) + 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; osg::Texture2D* texture = new osg::Texture2D;
...@@ -780,6 +843,7 @@ void WMFiberDisplay::create2DTextureCycleLightning( osg::StateSet* m_rootState ) ...@@ -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::MIN_FILTER, osg::Texture2D::LINEAR_MIPMAP_LINEAR );
texture->setFilter( osg::Texture2D::MAG_FILTER, osg::Texture2D::LINEAR ); texture->setFilter( osg::Texture2D::MAG_FILTER, osg::Texture2D::LINEAR );
texture->setImage( randImage ); texture->setImage( randImage );
//osgDB::writeImageFile( *randImage, "share/file.png" );
m_rootState->setTextureAttribute( 6, texture, osg::StateAttribute::OVERRIDE ); m_rootState->setTextureAttribute( 6, texture, osg::StateAttribute::OVERRIDE );
m_rootState->setTextureMode( 6, GL_TEXTURE_2D, osg::StateAttribute::ON | 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 ) ...@@ -788,11 +852,10 @@ void WMFiberDisplay::create2DTextureCycleLightning( osg::StateSet* m_rootState )
void WMFiberDisplay::createTextures( osg::StateSet* m_rootState ) const void WMFiberDisplay::createTextures( osg::StateSet* m_rootState ) const
{ {
create1DTextureRectLightning( m_rootState ); create1DTextureRectLighting( m_rootState );
create2DTextureCycleLightning( m_rootState ); create2DTextureCycleLighting( m_rootState );
create2DTexDiffuseLightning( m_rootState ); create2DTexturesBlinn( m_rootState );
create2DTexSpecularLightning( m_rootState );
} }
void WMFiberDisplay::createTubeData() void WMFiberDisplay::createTubeData()
......
...@@ -405,41 +405,50 @@ private: ...@@ -405,41 +405,50 @@ private:
* of a tube from aside * of a tube from aside
* \param rootState The uniforms will be applied to this state. * \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 * Creates a texture to simmulate diffuse and specular lightning
* of a tube from top or bottom * of a tube from top or bottom
* \param rootState The uniforms will be applied to this state. * \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 * Creates a texture to simmulate diffuse and specular lightning
* of a tube from top or bottom * of a tube from top or bottom
* \param rootState The uniforms will be applied to this state. * \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 * Creates a texture to simmulate diffuse and specular lightning
* of a tube from top or bottom * of a tube from top or bottom
* \param rootState The uniforms will be applied to this state. * \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 * Creates a texture to simmulate diffuse and specular lightning
* of a tube from top or bottom * 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 * Computes integrand for specular blinn lighting texture
* of a tube from top or bottom * \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;