Commit 8efa20e1 authored by Mathias Goldau's avatar Mathias Goldau
Browse files

[MERGE]

parents d56037ab a9b8c090
......@@ -46,11 +46,14 @@ WGEPostprocessingNode::WGEPostprocessingNode( osg::ref_ptr< osg::Camera > refere
// link them together with the corresponding textures
osg::ref_ptr< osg::Texture2D > renderColorTexture = m_render->attach( osg::Camera::COLOR_BUFFER0 );
osg::ref_ptr< osg::Texture2D > renderNormalTexture = m_render->attach( osg::Camera::COLOR_BUFFER1 );
osg::ref_ptr< osg::Texture2D > renderNormalTexture = m_render->attach( osg::Camera::COLOR_BUFFER1, GL_RGB );
osg::ref_ptr< osg::Texture2D > renderParameterTexture = m_render->attach( osg::Camera::COLOR_BUFFER2, GL_LUMINANCE );
osg::ref_ptr< osg::Texture2D > renderTangentTexture = m_render->attach( osg::Camera::COLOR_BUFFER3, GL_RGB );
osg::ref_ptr< osg::Texture2D > renderDepthTexture = m_render->attach( osg::Camera::DEPTH_BUFFER );
m_postprocess->bind( renderColorTexture, 0 );
m_postprocess->bind( renderNormalTexture, 1 );
m_postprocess->bind( renderDepthTexture, 2 );
m_postprocess->bind( renderParameterTexture, 2 );
m_postprocess->bind( renderDepthTexture, 3 );
// add the offscreen renderer and the original node to the switch
addChild( m_childs );
......@@ -101,6 +104,12 @@ WGEPostprocessingNode::WGEPostprocessingNode( osg::ref_ptr< osg::Camera > refere
m_offscreen->getTextureHUD()->addUpdateCallback( new WGENodeMaskCallback( m_showHUD ) );
// let the activePostprocessors property control the options in the shader:
m_postProcessShader->addPreprocessor( activePostprocessorsOpts );
// some of the post-processors need some white noise, like the ssao
const size_t size = 64;
osg::ref_ptr< WGETexture2D > randTex = wge::genWhiteNoiseTexture( size, size, 3 );
m_postprocess->bind( randTex, 4 );
m_postprocess->bind( renderTangentTexture, 5 );
}
WGEPostprocessingNode::~WGEPostprocessingNode()
......
......@@ -38,15 +38,38 @@
// * Sometimes, the normal might not be needed in your own code. In this case, use #ifdef WGE_POSTPROCESSING_ENABLED to only calculate it in
// the case post-processing is enabled
// * You can use getGradient amd getGradientViewAligned in WGEShadingTools.glsl to calculate the normal in a 3D texture
// * Set a fragment zoom factor. This represents the zoom of your modelview matrix. It is needed by some post-processors to provide
// zoom-invariant effects.
// * Needs to be scaled by 0.1
// * Can be calculated this way: wge_FragZoom = 0.1 * length( ( gl_ModelViewMatrix * normalize( vec4( 1.0, 1.0, 1.0, 0.0 ) ) ).xyz );
// * Simpler: call wge_FragZoom = 0.1 * getModelViewScale();
#ifdef WGE_POSTPROCESSING_ENABLED
#define wge_FragNormal gl_FragData[1].rgb
#define wge_FragColor gl_FragData[0]
#define wge_FragZoom gl_FragData[2].r
#define wge_FragTangent gl_FragData[3].rgb
#else
vec3 WGE_POSTPROCESSING_ENABLED_dummyVec3;
float WGE_POSTPROCESSING_ENABLED_dummyFloat;
#define wge_FragNormal WGE_POSTPROCESSING_ENABLED_dummyVec3
#define wge_FragColor gl_FragData[0]
#define wge_FragZoom WGE_POSTPROCESSING_ENABLED_dummyFloat
#define wge_FragTangent WGE_POSTPROCESSING_ENABLED_dummyVec3
#endif
/**
* This initializes the G-Buffer (Geometry Buffer). You need to call this before using one of the output variables wge_FragXYZ.
* \note: a G-Buffer is basically a term for several textures storing per-pixel geometry information like normals and positions and similar.
*/
void wgeInitGBuffer()
{
// we need to initialize all output buffers with an alpha value or they will be blended away if blending is on.
gl_FragData[0] = vec4( vec3( 0.0 ), 1.0 );
gl_FragData[1] = vec4( vec3( 0.0 ), 1.0 );
gl_FragData[2] = vec4( vec3( 0.0 ), 1.0 );
gl_FragData[3] = vec4( vec3( 0.0 ), 1.0 );
}
#endif // WGEPOSTPROCESSING_GLSL
//---------------------------------------------------------------------------
//
// Project: OpenWalnut ( http://www.openwalnut.org )
......@@ -39,21 +40,37 @@
* The texture Unit for the original color field
*/
uniform sampler2D u_texture0Sampler;
#define u_colorSampler u_texture0Sampler
/**
* The texture Unit for the Normal Map
*/
uniform sampler2D u_texture1Sampler;
#define u_normalSampler u_texture1Sampler
/**
* The depth texture
* The additional parameters from the source
*/
uniform sampler2D u_texture2Sampler;
#define u_parameterSampler u_texture2Sampler
/**
* The white-noise 3 channel texture: sampler
* The depth texture
*/
uniform sampler2D u_texture3Sampler;
#define u_depthSampler u_texture3Sampler
/**
* The white-noise 3 channel texture: sampler
*/
uniform sampler2D u_texture4Sampler;
#define u_noiseSampler u_texture4Sampler
/**
* The tangent data
*/
uniform sampler2D u_texture5Sampler;
#define u_tangentSampler u_texture5Sampler
/**
* The white-noise 3 channel texture: size in x direction
......@@ -130,7 +147,7 @@ const vec2 zeroOneList = vec2( 1.0, 0.0 );
*/
vec4 getColor( in vec2 where )
{
return texture2D( u_texture0Sampler, where );
return texture2D( u_colorSampler, where );
}
/**
......@@ -154,7 +171,7 @@ vec4 getColor()
*/
vec4 getNormal( in vec2 where )
{
return normalize( texture2DUnscaled( u_texture1Sampler, where, -1.0, 2.0 ).xyz ).xyzz * zeroOneList.xxxy + zeroOneList.yyyx;
return normalize( texture2DUnscaled( u_normalSampler, where, -1.0, 2.0 ).xyz ).xyzz * zeroOneList.xxxy + zeroOneList.yyyx;
}
/**
......@@ -169,6 +186,30 @@ vec4 getNormal()
return getNormal( pixelCoord );
}
/**
* Grabs the normal at the specified point. The returned normal has been de-scaled to [-1,1] and normalized The w component is 1.
*
* \param where the pixel to grab
*
* \return the normal
*/
vec4 getTangent( in vec2 where )
{
return normalize( texture2DUnscaled( u_tangentSampler, where, -1.0, 2.0 ).xyz ).xyzz * zeroOneList.xxxy + zeroOneList.yyyx;
}
/**
* Grabs the normal at the current pixel. The returned normal has been de-scaled to [-1,1]. The w component is 1.
*
* \note GLSL does not officially allow default values for function arguments which is why we need this additional function.
*
* \return the normal
*/
vec4 getTangent()
{
return getNormal( pixelCoord );
}
/**
* Grabs the depth at the specified point.
*
......@@ -178,7 +219,7 @@ vec4 getNormal()
*/
float getDepth( in vec2 where )
{
return texture2D( u_texture2Sampler, where ).r;
return texture2D( u_depthSampler, where ).r;
}
/**
......@@ -193,6 +234,29 @@ float getDepth()
return getDepth( pixelCoord );
}
/**
* Returns the zoom factor for the current pixel if set by the output shader of the geometry getting post-processed here.
*
* \param where the pixel to grab
*
* \return the zoom factor
*/
float getZoom( in vec2 where )
{
// TODO(ebaum): somehow remove this scaler
return texture2D( u_parameterSampler, pixelCoord ).r * 10.0;
}
/**
* Returns the zoom factor for the current pixel if set by the output shader of the geometry getting post-processed here.
*
* \return the zoom factor
*/
float getZoom()
{
return getZoom( pixelCoord );
}
/**
* Blends the specified color to the current overall-color.
*
......@@ -244,23 +308,25 @@ void blendAdd( in float f )
* Phong based Per-Pixel-Lighting.
*
* \param normal the surface normal. Normalized.
* \param lightParams the ligh parameters
*
* \return the intensity.
*/
float getPPLPhong( vec3 normal )
float getPPLPhong( in wge_LightIntensityParameter lightParams, in vec3 normal )
{
// TODO(ebaum): provide properties/uniforms for the scaling factors here
return blinnPhongIlluminationIntensity(
0.2 , // material ambient
0.75, // material diffuse
0.5, // material specular
100.0, // shinines
1.0, // light diffuse
0.3, // light ambient
normal, // normal
vec4( 0.0, 0.0, 1.0, 1.0 ).xyz, // view direction // in world space, this always is the view-dir
gl_LightSource[0].position.xyz // light source position
);
return blinnPhongIlluminationIntensity( lightParams, normal );
}
/**
* Phong based Per-Pixel-Lighting.
*
* \param normal the surface normal. Normalized.
*
* \return the intensity.
*/
float getPPLPhong( in vec3 normal )
{
return blinnPhongIlluminationIntensity( normal );
}
/**
......@@ -273,6 +339,18 @@ float getPPLPhong()
return getPPLPhong( getNormal().xyz );
}
/**
* Phong based Per-Pixel-Lighting based on the specified color.
*
* \param lightParams the ligh parameters
*
* \return the intensity.
*/
float getPPLPhong( in wge_LightIntensityParameter lightParams )
{
return getPPLPhong( lightParams, getNormal().xyz );
}
/**
* Apply laplace-filter to depth buffer. An edge is > 0.0.
*
......@@ -435,7 +513,7 @@ float getDepthFading( vec2 where )
{
// TODO(ebaum): add uniforms for this limits
float invD = ( 1.0 - getDepth( where ) );
return smoothstep( 0.20, 0.5, invD );
return smoothstep( 0.2, 0.5, invD );
}
/**
......@@ -502,7 +580,7 @@ void main()
#endif
#ifdef WGE_POSTPROCESSOR_NORMAL
blend( getNormal() );
blend( abs( getNormal() ) );
#endif
#ifdef WGE_POSTPROCESSOR_CUSTOM
......
......@@ -140,10 +140,15 @@ private:
WProperties::SPtr m_fibProps;
/**
* The shader used for clipping of fibers using an arbitrary plane.
* The shader used for actually drawing the fake tubes or lines.
*/
osg::ref_ptr< WGEShader > m_shader;
/**
* The shader used for drawing end cap sprites if in tube mode.
*/
osg::ref_ptr< WGEShader > m_endCapShader;
/**
* Illumination.
*/
......@@ -194,6 +199,11 @@ private:
*/
WPropBool m_tubeEnable;
/**
* Property denoting whether to use end-caps on tubes
*/
WPropBool m_tubeEndCapsEnable;
/**
* Prop denoting whether tubes can be zoomed or not.
*/
......@@ -215,6 +225,21 @@ private:
*/
WPropGroup m_tubeGroup;
/**
* Group containing line specific properties
*/
WPropGroup m_lineGroup;
/**
* Line width.
*/
WPropDouble m_lineWidth;
/**
* Line smoothing.
*/
WPropBool m_lineSmooth;
/**
* Update the transform node to provide an cue were the plane actually is.
*
......@@ -230,18 +255,26 @@ private:
osg::ref_ptr< osg::Node > createClipPlane() const;
/**
* Creates a geode containing the fiber geometry.
* Creates a geode containing the fiber geometry
*
* \param fibers the fiber dataset to render
*
* \return the geode
* \param fibers the fiber data
* \param fibGeode the geode with the fibers as tube strip or lines
* \param endCapGeode the end cap sprites. Not used if not in tube mode.
*/
osg::ref_ptr< osg::Node > createFiberGeode( WDataSetFibers::SPtr fibers );
void createFiberGeode( boost::shared_ptr< WDataSetFibers > fibers, osg::ref_ptr< osg::Geode > fibGeode,
osg::ref_ptr< osg::Geode > endCapGeode );
/**
* The plane node.
*/
osg::ref_ptr< osg::Node > m_plane;
/**
* Callback for the line geode to allow interactive modification of line smooth and width states.
*
* \param state the state
*/
void lineGeodeStateCallback( osg::StateSet* state );
};
#endif // WMFIBERDISPLAYSIMPLE_H
......
//---------------------------------------------------------------------------
//
// Project: OpenWalnut ( http://www.openwalnut.org )
//
// Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
// For more information see http://www.openwalnut.org/copying
//
// This file is part of OpenWalnut.
//
// OpenWalnut is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// OpenWalnut is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
//
//---------------------------------------------------------------------------
#version 120
#extension GL_EXT_geometry_shader4 : enable
#include "WGEShadingTools.glsl"
#include "WGETextureTools.glsl"
#include "WGEPostprocessing.glsl"
/////////////////////////////////////////////////////////////////////////////
// Uniforms
/////////////////////////////////////////////////////////////////////////////
/**
* The size of the tube
*/
uniform float u_tubeSize;
/////////////////////////////////////////////////////////////////////////////
// Attributes
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Varyings
/////////////////////////////////////////////////////////////////////////////
/**
* The normal in world-space
*/
varying vec3 v_normalWorld;
/**
* The vertex coordinate in world-space
*/
varying vec4 v_vertex;
/**
* The scaling component of the modelview matrix.
*/
varying float v_worldScale;
/////////////////////////////////////////////////////////////////////////////
// Variables
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Functions
/////////////////////////////////////////////////////////////////////////////
/**
* Main entry point of the fragment shader.
*/
void main()
{
// it should be round
float c = ( gl_TexCoord[0].x * gl_TexCoord[0].x ) + ( gl_TexCoord[0].y * gl_TexCoord[0].y );
// clip everything outside the sphere
float outside = 1.0 - step( 1.0, c );
// the normal
vec3 normal = 0.5 * u_tubeSize * v_normalWorld;
// light
float light = 1.0;
#ifdef ILLUMINATION_ENABLED
light = blinnPhongIlluminationIntensity( wge_DefaultLightIntensityLessDiffuse, normalize( normal ) );
#endif
// calculate some kind of "round" depth value
// NOTE: gl_TexCoord[0].w is 0.0 if the front of the cap is seen
vec3 v = v_vertex.xyz + ( 1.0 - gl_TexCoord[0].w ) * ( normal ) * ( 1.0 - c );
// apply standard projection:
vec4 vProj = gl_ProjectionMatrix * vec4( v.xyz, 1.0 );
float depth = ( 0.5 * vProj.z / vProj.w ) + 0.5;
float w = gl_TexCoord[0].w * ( 1.0 - abs( gl_TexCoord[0].x ) ) + ( 1.0 - gl_TexCoord[0].w );
// done
wge_FragColor = vec4( light * w * gl_Color.rgb, outside * gl_Color.a );
wge_FragNormal = textureNormalize( normalize( normal ) );
wge_FragZoom = v_worldScale;
gl_FragDepth = depth;
}
//---------------------------------------------------------------------------
//
// Project: OpenWalnut ( http://www.openwalnut.org )
//
// Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
// For more information see http://www.openwalnut.org/copying
//
// This file is part of OpenWalnut.
//
// OpenWalnut is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// OpenWalnut is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
//
//---------------------------------------------------------------------------
#version 120
#extension GL_EXT_geometry_shader4 : enable
#include "WGETransformationTools.glsl"
/////////////////////////////////////////////////////////////////////////////
// Uniforms
/////////////////////////////////////////////////////////////////////////////
/**
* A point on the plane.
*/
uniform vec3 u_planePoint;
/**
* The normal vector of the plane
*/
uniform vec3 u_planeVector;
/**
* The max distance allowed
*/
uniform float u_distance = 1.0;
/**
* The size of the tube
*/
uniform float u_tubeSize;
/////////////////////////////////////////////////////////////////////////////
// Attributes
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Varyings
/////////////////////////////////////////////////////////////////////////////
/**
* The normal/tangent in scene-space
*/
varying in vec3 v_normal[];
/**
* The output normal for the fragment shader in world-space
*/
varying out vec3 v_normalWorld;
/**
* The vertex coordinates in world-space
*/
varying out vec4 v_vertex;
/**
* The scaling component of the modelview matrix.
*/
varying out float v_worldScale;
/////////////////////////////////////////////////////////////////////////////
// Variables
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Functions
/////////////////////////////////////////////////////////////////////////////
/**
* Main entry point of the geometry shader.
*/
void main()
{
#ifdef CLIPPLANE_ENABLED
// define the plane
vec3 n = normalize( u_planeVector );
float d = dot( u_planePoint, n );
float dist = dot( gl_PositionIn[0].xyz, n ) - d;
if ( abs( dist ) >= u_distance )
{
return;
}
#endif // CLIPPLANE_ENABLED
#if !( defined( ENDCAPS_ENABLED ) )
// no endcaps?
// do not emit any vertex
return;
#endif // ENDCAPS_ENABLED
// discard the caps if in ribbon mode or non-zoomable mode. it not yet works.
#if !( defined( RIBBON_ENABLED ) || !defined( ZOOMABLE_ENABLED ) )
// grab the info we got from the vertex array:
vec3 tangent = normalize( v_normal[0] );
vec4 vertex = gl_PositionIn[0];
// camera view direction
vec3 view = normalize( ( gl_ModelViewMatrixInverse * vec4( 0.0, 0.0, -1.0, 0.0 ) ).xyz );
float angle = step( 0.0, sign( dot( view, tangent ) ) );
// the plane of the sprite is determined by the tangent ond two orthogonal vectors a and b
vec4 a = 0.2 * u_tubeSize * vec4( normalize( cross( tangent, view ) ), 0.0 );
vec4 b = 0.2 * u_tubeSize * vec4( normalize( cross( tangent, a.xyz ) ), 0.0 );
gl_FrontColor = gl_FrontColorIn[0];