Commit 38e2994f authored by Sebastian Eichelbaum's avatar Sebastian Eichelbaum

[CHANGE #312] Effects now use properties for config. GUI still missing; added next.

parent 4b88f878
......@@ -38,7 +38,6 @@
#include <osgGA/TerrainManipulator>
#include <osgViewer/ViewerEventHandlers>
#include <osgViewer/View>
#include <osg/Depth>
#include <osgDB/ReadFile>
......@@ -48,11 +47,8 @@
#include "WGENoOpManipulator.h"
#include "WGEZoomTrackballManipulator.h"
#include "WPickHandler.h"
#include "WGEGeodeUtils.h"
#include "shaders/WGEShader.h"
#include "../common/WConditionOneShot.h"
#include "../common/WThreadedRunner.h"
#include "WGEViewer.h"
......@@ -64,7 +60,10 @@ WGEViewer::WGEViewer( std::string name, osg::ref_ptr<osg::Referenced> wdata, int
m_name( name ),
m_rendered( WBoolFlag::SPtr( new WBoolFlag( new WConditionOneShot(), false ) ) ),
m_screenCapture( new WGEScreenCapture() ),
m_inAnimationMode( false )
m_inAnimationMode( false ),
m_effectHorizon( new WGEViewerEffectHorizon() ),
m_effectVignette( new WGEViewerEffectVignette() ),
m_effectImageOverlay( new WGEViewerEffectImageOverlay() )
{
try
{
......@@ -165,101 +164,10 @@ void WGEViewer::setScene( osg::ref_ptr< WGEGroupNode > node )
m_View->setSceneData( node );
m_scene = node;
/*
// vignetting cam
{
osg::ref_ptr< osg::Camera > bkCam = new osg::Camera();
bkCam->setClearMask( GL_DEPTH_BUFFER_BIT );
bkCam->setRenderOrder( osg::Camera::POST_RENDER );
bkCam->setReferenceFrame( osg::Transform::ABSOLUTE_RF );
bkCam->setProjectionMatrixAsOrtho2D( 0.0, 1.0, 0.0, 1.0 );
bkCam->setViewMatrix( osg::Matrixd::identity() );
osg::StateSet* state = bkCam->getOrCreateStateSet();
state->setMode( GL_DEPTH_TEST, osg::StateAttribute::OFF );
state->setMode( GL_LIGHTING, osg::StateAttribute::PROTECTED );
state->setMode( GL_LIGHTING, osg::StateAttribute::OFF );
state->setMode( GL_BLEND, osg::StateAttribute::PROTECTED );
state->setMode( GL_BLEND, osg::StateAttribute::ON );
osg::ref_ptr< osg::Geode > geode = wge::genFinitePlane( osg::Vec3( 0.0, 0.0, 0.0 ),
osg::Vec3( 1.0, 0.0, 0.0 ),
osg::Vec3( 0.0, 1.0, 0.0 ) );
osg::ref_ptr< WGEShader > vignetteShader = new WGEShader( "WGECameraVignette" );
vignetteShader->apply( geode );
// add the slice to the geode
bkCam->addChild( geode );
node->insert( bkCam );
}
// overlay texture cam
{
osg::ref_ptr< osg::Camera > bkCam = new osg::Camera();
bkCam->setClearMask( GL_DEPTH_BUFFER_BIT );
bkCam->setRenderOrder( osg::Camera::POST_RENDER );
bkCam->setReferenceFrame( osg::Transform::ABSOLUTE_RF );
bkCam->setProjectionMatrixAsOrtho2D( 0.0, 1.0, 0.0, 1.0 );
bkCam->setViewMatrix( osg::Matrixd::identity() );
osg::StateSet* state = bkCam->getOrCreateStateSet();
state->setMode( GL_DEPTH_TEST, osg::StateAttribute::OFF );
state->setMode( GL_LIGHTING, osg::StateAttribute::PROTECTED );
state->setMode( GL_LIGHTING, osg::StateAttribute::OFF );
state->setMode( GL_BLEND, osg::StateAttribute::PROTECTED );
state->setMode( GL_BLEND, osg::StateAttribute::ON );
osg::ref_ptr< osg::Geode > geode = wge::genFinitePlane( osg::Vec3( 0.0, 0.0, 0.0 ),
osg::Vec3( 1.0, 0.0, 0.0 ),
osg::Vec3( 0.0, 1.0, 0.0 ) );
osg::ref_ptr< WGEShader > vignetteShader = new WGEShader( "WGECameraOverlayTexture" );
vignetteShader->apply( geode );
// some logo
osg::ref_ptr< osg::Texture2D > logoTexture = new osg::Texture2D;
osg::Image* logoImage = osgDB::readImageFile( "/home/seth/CameraOverlay.png" );
if ( logoImage )
{
// Assign the texture to the image we read from file:
logoTexture->setImage( logoImage );
state->setTextureAttributeAndModes( 0, logoTexture, osg::StateAttribute::ON );
}
// add the slice to the geode
bkCam->addChild( geode );
node->insert( bkCam );
}
// horizon background cam
{
osg::ref_ptr< osg::Camera > bkCam = new osg::Camera();
bkCam->setClearMask( GL_DEPTH_BUFFER_BIT );
bkCam->setRenderOrder( osg::Camera::NESTED_RENDER, 0 );
bkCam->setReferenceFrame( osg::Transform::ABSOLUTE_RF );
bkCam->setProjectionMatrixAsOrtho2D( 0.0, 1.0, 0.0, 1.0 );
bkCam->setViewMatrix( osg::Matrixd::identity() );
osg::StateSet* state = bkCam->getOrCreateStateSet();
state->setMode( GL_DEPTH_TEST, osg::StateAttribute::OFF );
state->setMode( GL_LIGHTING, osg::StateAttribute::PROTECTED );
state->setMode( GL_LIGHTING, osg::StateAttribute::OFF );
state->setMode( GL_BLEND, osg::StateAttribute::PROTECTED );
state->setMode( GL_BLEND, osg::StateAttribute::ON );
osg::Depth* depth = new osg::Depth;
depth->setWriteMask( false );
state->setAttributeAndModes( depth, osg::StateAttribute::ON );
osg::ref_ptr< osg::Geode > geode = wge::genFinitePlane( osg::Vec3( 0.0, 0.0, 0.0 ),
osg::Vec3( 1.0, 0.0, 0.0 ),
osg::Vec3( 0.0, 1.0, 0.0 ) );
osg::ref_ptr< WGEShader > horizonShader = new WGEShader( "WGECameraHorizon" );
horizonShader->apply( geode );
// add the slice to the geode
bkCam->addChild( geode );
node->insert( bkCam );
}
*/
// add effects:
node->insert( m_effectVignette );
node->insert( m_effectImageOverlay );
node->insert( m_effectHorizon );
}
osg::ref_ptr< WGEGroupNode > WGEViewer::getScene()
......@@ -394,3 +302,32 @@ bool WGEViewer::isAnimationMode() const
return m_inAnimationMode;
}
WGEViewerEffectHorizon::SPtr WGEViewer::getBackground()
{
return m_effectHorizon;
}
WGEViewerEffectImageOverlay::SPtr WGEViewer::getImageOverlay()
{
return m_effectImageOverlay;
}
WGEViewerEffectVignette::SPtr WGEViewer::getVignette()
{
return m_effectVignette;
}
WGEViewerEffectHorizon::ConstSPtr WGEViewer::getBackground() const
{
return m_effectHorizon;
}
WGEViewerEffectImageOverlay::ConstSPtr WGEViewer::getImageOverlay() const
{
return m_effectImageOverlay;
}
WGEViewerEffectVignette::ConstSPtr WGEViewer::getVignette() const
{
return m_effectVignette;
}
......@@ -59,13 +59,17 @@ class WGEGroupNode;
class WPickHandler;
#include "animation/WGEAnimationManipulator.h"
#include "WGEViewerEffectHorizon.h"
#include "WGEViewerEffectVignette.h"
#include "WGEViewerEffectImageOverlay.h"
/**
* Class for managing one view to the scene. This includes viewport, camera and graphics context.
* It is, besides WGraphicsEngine, the ONLY entry point for each widget for accessing the graphics engine.
* \ingroup ge
*/
class WGEViewer: public WGEGraphicsWindow,
public boost::enable_shared_from_this< WGEViewer >
public boost::enable_shared_from_this< WGEViewer >
{
public:
/**
......@@ -183,6 +187,9 @@ public:
/**
* Determine the color of the viewer's background.
*
* \note This is only useful when the background effect is disabled.
*
* \param bgColor the new background color
*/
void setBgColor( const WColor& bgColor );
......@@ -237,6 +244,48 @@ public:
*/
bool isAnimationMode() const;
/**
* Return the background render effect for modification.
*
* \return the effect
*/
WGEViewerEffectHorizon::SPtr getBackground();
/**
* Return the overlay render effect for modification.
*
* \return the effect
*/
WGEViewerEffectImageOverlay::SPtr getImageOverlay();
/**
* Return the vignette render effect for modification.
*
* \return the effect
*/
WGEViewerEffectVignette::SPtr getVignette();
/**
* Return the background render effect for modification.
*
* \return the effect
*/
WGEViewerEffectHorizon::ConstSPtr getBackground() const;
/**
* Return the overlay render effect for modification.
*
* \return the effect
*/
WGEViewerEffectImageOverlay::ConstSPtr getImageOverlay() const;
/**
* Return the vignette render effect for modification.
*
* \return the effect
*/
WGEViewerEffectVignette::ConstSPtr getVignette() const;
protected:
/**
* The OpenSceneGraph view used in this (Composite)Viewer.
......@@ -338,6 +387,20 @@ protected:
*/
osg::ref_ptr<osgGA::MatrixManipulator> m_animationModeManipulatorBackup;
/**
* Horizon effect.
*/
WGEViewerEffectHorizon::SPtr m_effectHorizon;
/**
* Vignette effect.
*/
WGEViewerEffectVignette::SPtr m_effectVignette;
/**
* Image overlay effect.
*/
WGEViewerEffectImageOverlay::SPtr m_effectImageOverlay;
private:
};
......
//---------------------------------------------------------------------------
//
// 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/>.
//
//---------------------------------------------------------------------------
#include <osg/Depth>
#include "WGEGeodeUtils.h"
#include "shaders/WGEShader.h"
#include "callbacks/WGENodeMaskCallback.h"
#include "WGEViewerEffect.h"
WGEViewerEffect::WGEViewerEffect( std::string name, std::string description, const char** icon ):
WObjectNDIP( name, description, icon )
{
// setup camera
setClearMask( GL_DEPTH_BUFFER_BIT );
setRenderOrder( osg::Camera::POST_RENDER );
setReferenceFrame( osg::Transform::ABSOLUTE_RF );
setProjectionMatrixAsOrtho2D( 0.0, 1.0, 0.0, 1.0 );
setViewMatrix( osg::Matrixd::identity() );
// some state options
m_state = getOrCreateStateSet();
m_state->setMode( GL_DEPTH_TEST, osg::StateAttribute::OFF );
m_state->setMode( GL_LIGHTING, osg::StateAttribute::PROTECTED );
m_state->setMode( GL_LIGHTING, osg::StateAttribute::OFF );
m_state->setMode( GL_BLEND, osg::StateAttribute::PROTECTED );
m_state->setMode( GL_BLEND, osg::StateAttribute::ON );
osg::Depth* depth = new osg::Depth;
depth->setWriteMask( false );
m_state->setAttributeAndModes( depth, osg::StateAttribute::ON );
m_geode = wge::genFinitePlane( osg::Vec3( 0.0, 0.0, 0.0 ),
osg::Vec3( 1.0, 0.0, 0.0 ),
osg::Vec3( 0.0, 1.0, 0.0 ) );
// add the slice to the geode
addChild( m_geode );
// Configure properties
m_active = m_properties->addProperty( "Active", "Activate this effect?", false );
// let this control the nodemask
addUpdateCallback( new WGENodeMaskCallback( m_active ) );
}
WGEViewerEffect::~WGEViewerEffect()
{
// cleanup
}
bool WGEViewerEffect::isEnabled() const
{
return m_active->get();
}
void WGEViewerEffect::setEnabled( bool enable )
{
m_active->set( enable );
}
//---------------------------------------------------------------------------
//
// 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/>.
//
//---------------------------------------------------------------------------
#ifndef WGEVIEWEREFFECT_H
#define WGEVIEWEREFFECT_H
#include <string>
#include <osg/Camera>
#include <osg/Geode>
#include <osg/StateSet>
#include "core/common/WObjectNDIP.h"
#include "core/common/WProperties.h"
/**
* Base class for implementing basic fullscreen effects for the WGEViewer. It uses properties for configuration.
*/
class WGEViewerEffect: public WObjectNDIP< osg::Camera >
{
public:
/**
* Convenience typedef for a boost::shared_ptr< WGEViewerEffect >.
*/
typedef osg::ref_ptr< WGEViewerEffect > SPtr;
/**
* Convenience typedef for a boost::shared_ptr< const WGEViewerEffect >.
*/
typedef osg::ref_ptr< const WGEViewerEffect > ConstSPtr;
/**
* Create the effect.
*
* \param name the name
* \param description the description
* \param icon an icon in XPM format. Can be NULL if no icon is required.
*/
WGEViewerEffect( std::string name, std::string description, const char** icon = NULL );
/**
* Destructor.
*/
virtual ~WGEViewerEffect();
/**
* Check whether the effect is active or not.
*
* \return true if active
*/
bool isEnabled() const;
/**
* Set the effect enabled.
*
* \param enable true to enable. False to disable.
*/
void setEnabled( bool enable = true );
protected:
/**
* The fullscreen quad
*/
osg::ref_ptr< osg::Geode > m_geode;
/**
* The stateset of the cam
*/
osg::ref_ptr< osg::StateSet > m_state;
/**
* Enable or disable effect.
*/
WPropBool m_active;
private:
};
#endif // WGEVIEWEREFFECT_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/>.
//
//---------------------------------------------------------------------------
#include "../common/WProperties.h"
#include "shaders/WGEShader.h"
#include "shaders/WGEPropertyUniform.h"
#include "WGEViewerEffectHorizon.h"
WGEViewerEffectHorizon::WGEViewerEffectHorizon():
WGEViewerEffect( "Horizon", "Configurable horizon background effect." )
{
WPropColor bottom1Color = m_properties->addProperty( "First Bottom Color", "Bottom color gradient: first color.",
WColor( 0.65, 0.65, 0.65, 1.0 ) );
WPropColor bottom2Color = m_properties->addProperty( "Second Bottom Color", "Bottom color gradient: second color.",
WColor( 1.0, 1.0, 1.0, 1.0 ) );
WPropColor top1Color = m_properties->addProperty( "First Top Color", "Top color gradient: first color.",
WColor( 1.0, 1.0, 1.0, 1.0 ) );
WPropColor top2Color = m_properties->addProperty( "Second Top Color", "Top color gradient: second color.",
WColor( 1.0, 1.0, 1.0, 1.0 ) );
WPropDouble horizonLine = m_properties->addProperty( "Horizon in %", "Horizon line in percent.", 33.0 );
horizonLine->setMin( 0.0 );
horizonLine->setMax( 100.0 );
m_state->addUniform( new WGEPropertyUniform< WPropDouble >( "u_horizon", horizonLine ) );
m_state->addUniform( new WGEPropertyUniform< WPropColor >( "u_bottom1Color", bottom1Color ) );
m_state->addUniform( new WGEPropertyUniform< WPropColor >( "u_bottom2Color", bottom2Color ) );
m_state->addUniform( new WGEPropertyUniform< WPropColor >( "u_top1Color", top1Color ) );
m_state->addUniform( new WGEPropertyUniform< WPropColor >( "u_top2Color", top2Color ) );
// default cam is a post render cam. The Horizon needs to be done BEFORE everything else
setRenderOrder( osg::Camera::NESTED_RENDER, 0 );
osg::ref_ptr< WGEShader > horizonShader = new WGEShader( "WGECameraHorizon" );
horizonShader->apply( m_geode );
}
WGEViewerEffectHorizon::~WGEViewerEffectHorizon()
{
// cleanup
}
//---------------------------------------------------------------------------
//
// 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/>.
//
//---------------------------------------------------------------------------
#ifndef WGEVIEWEREFFECTHORIZON_H
#define WGEVIEWEREFFECTHORIZON_H
#include "WGEViewerEffect.h"
/**
* Horizon Effect.
*/
class WGEViewerEffectHorizon: public WGEViewerEffect
{
public:
/**
* Convenience typedef for a boost::shared_ptr< WGEViewerEffectHorizon >.
*/
typedef osg::ref_ptr< WGEViewerEffectHorizon > SPtr;
/**
* Convenience typedef for a boost::shared_ptr< const WGEViewerEffectHorizon >.
*/
typedef osg::ref_ptr< const WGEViewerEffectHorizon > ConstSPtr;
/**
* Default constructor.
*/
WGEViewerEffectHorizon();
/**
* Destructor.
*/
virtual ~WGEViewerEffectHorizon();
protected:
private:
};
#endif // WGEVIEWEREFFECTHORIZON_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/>.
//
//---------------------------------------------------------------------------
#include <osg/Texture2D>
#include <osgDB/ReadFile>
#include "../common/WPathHelper.h"
#include "../common/WProperties.h"
#include "../common/WLogger.h"
#include "callbacks/WGEFunctorCallback.h"
#include "shaders/WGEShader.h"
#include "shaders/WGEPropertyUniform.h"
#include "WGEViewerEffectImageOverlay.h"
WGEViewerEffectImageOverlay::WGEViewerEffectImageOverlay():
WGEViewerEffect( "Image Overlay", "Blend in some arbitrary image." )
{
WPropFilename imageFn = m_properties->addProperty( "Image", "The Image to use.", WPathHelper::getSharePath() / "GE" / "overlay.png" );
WPropDouble scale = m_properties->addProperty( "Scale", "Scale the image in percent.", 50.0 );
scale->setMin( 0.0 );
scale->setMax( 100.0 );
WPropBool moveToTop = m_properties->addProperty( "Move to Top", "Move the image to the top.", false );
WPropBool moveToRight = m_properties->addProperty( "Move to Right", "Move the image to the right.", true );
osg::ref_ptr< WGEShader > overlayShader = new WGEShader( "WGECameraOverlayTexture" );
overlayShader->apply( m_geode );
// some logo
osg::ref_ptr< osg::Texture2D > logoTexture = new osg::Texture2D;
osg::Image* logoImage = osgDB::readImageFile( ( WPathHelper::getSharePath() / "GE" / "overlay.png" ).string() );
if ( logoImage )
{
// Assign the texture to the image we read from file:
logoTexture->setImage( logoImage );
// no wrapping
logoTexture->setWrap( osg::Texture::WRAP_S, osg::Texture::CLAMP_TO_BORDER );
logoTexture->setWrap( osg::Texture::WRAP_T, osg::Texture::CLAMP_TO_BORDER );
logoTexture->setDataVariance( osg::Object::DYNAMIC );
// texture width and height
m_overlayWidth = new osg::Uniform( "u_overlayWidth"