Commit c9808d6d authored by Sebastian Eichelbaum's avatar Sebastian Eichelbaum
Browse files

[CHANGE] you can now force fixed size render targets in offscreen nodes and postprocessors

parent 4b86ba83
......@@ -41,12 +41,20 @@ class WGEViewportCallback: public osg::NodeCallback
{
public:
/**
* Creates new instance of viewport callback.
* Creates new instance of viewport callback and sets the viewport size to the reference camera size
*
* \param reference set the viewport to the one of the reference camera.
*/
explicit WGEViewportCallback( osg::ref_ptr< Source > reference );
/**
* Creates new instance of viewport callback and sets the viewport size to the specified size
*
* \param width viewport width
* \param height viewport height
*/
WGEViewportCallback( size_t width, size_t height );
/**
* Destructor.
*/
......@@ -66,12 +74,34 @@ private:
* The reference camera to use.
*/
osg::ref_ptr< Source > m_reference;
/**
* Forced viewport width
*/
size_t m_width;
/**
* Forced viewport height
*/
size_t m_height;
};
template < typename T, typename Source >
WGEViewportCallback< T, Source >::WGEViewportCallback( osg::ref_ptr< Source > reference ):
osg::NodeCallback(),
m_reference( reference )
m_reference( reference ),
m_width( 0 ),
m_height( 0 )
{
// initialize members
}
template < typename T, typename Source >
WGEViewportCallback< T, Source >::WGEViewportCallback( size_t width, size_t height ):
osg::NodeCallback(),
m_reference( NULL ),
m_width( width ),
m_height( height )
{
// initialize members
}
......@@ -88,9 +118,14 @@ void WGEViewportCallback< T, Source >::operator()( osg::Node* node, osg::NodeVis
osg::ref_ptr< T > t = dynamic_cast< T* >( node );
if( t )
{
t->setViewport( m_reference->getViewport() );
// NOTE: you want to use a fixed size for the offscreen textures? Try this:
// t->setViewport( new osg::Viewport( 0, 0, 3840, 2160 ) );
if( m_reference )
{
t->setViewport( m_reference->getViewport() );
}
else
{
t->setViewport( new osg::Viewport( 0, 0, m_width, m_height ) );
}
}
traverse( node, nv );
}
......
......@@ -46,7 +46,8 @@ WGEOffscreenRenderNode::WGEOffscreenRenderNode( osg::ref_ptr< osg::Camera > refe
m_hud(),
m_textureWidth( width ),
m_textureHeight( height ),
m_nextPassNum( 0 )
m_nextPassNum( 0 ),
m_forceViewportTextureSize( false )
{
WAssert( checkTextureSize( width ) && checkTextureSize( height ), "Invalid offscreen texture size. Must be power of two and in [8,4096]." );
......@@ -124,3 +125,14 @@ size_t WGEOffscreenRenderNode::getTextureHeight() const
{
return m_textureHeight;
}
void WGEOffscreenRenderNode::setLinkViewportToTextureSize( bool vp )
{
m_forceViewportTextureSize = vp;
}
bool WGEOffscreenRenderNode::getLinkViewportToTextureSize() const
{
return m_forceViewportTextureSize;
}
......@@ -191,6 +191,21 @@ public:
*/
size_t getTextureHeight() const;
/**
* If true, the viewport has the size of the resulting texture. This is very interesting if you want to force large scale renderings and want
* to decouple your offscreen pass from the reference camera viewport.
*
* \param vp if true, viewport is forced to be the whole texture size
*/
void setLinkViewportToTextureSize( bool vp = true );
/**
* The flag denotes whether the viewport is linked to the texture size or the reference camera. See \ref setViewportToTextureSize for
* details.
*
* \return the flag.
*/
bool getLinkViewportToTextureSize() const;
protected:
private:
/**
......@@ -218,6 +233,11 @@ private:
* The number of the next pass getting added.
*/
size_t m_nextPassNum;
/**
* Flag denotes whether the viewport is coupled to the reference camera or the texture size
*/
bool m_forceViewportTextureSize;
};
template < typename T >
......@@ -232,7 +252,14 @@ osg::ref_ptr< T > WGEOffscreenRenderNode::addRenderPass( std::string name )
insert( pass ); // insert into this group
// ensure proper propagation of viewport changes
pass->addUpdateCallback( new WGEViewportCallback< T >( m_referenceCamera ) );
if( m_forceViewportTextureSize )
{
pass->addUpdateCallback( new WGEViewportCallback< T >( m_textureWidth, m_textureHeight ) );
}
else
{
pass->addUpdateCallback( new WGEViewportCallback< T >( m_referenceCamera ) );
}
// set clear mask and color according to reference cam
pass->setClearMask( m_referenceCamera->getClearMask() );
......
......@@ -64,6 +64,9 @@ WGEPostprocessingNode::WGEPostprocessingNode( osg::ref_ptr< osg::Camera > refere
osg::ref_ptr< WGEOffscreenRenderNode > offscreen( new WGEOffscreenRenderNode( reference, width, height, noHud ) );
offscreen->getTextureHUD()->addUpdateCallback( textureHudCallback );
// if the specific postprocessor requires us to fix the viewport size to the result-texture size:
offscreen->setLinkViewportToTextureSize( ( *iter )->getFixedViewportSize() );
// the geometry render step
osg::ref_ptr< WGEOffscreenRenderPass > render = offscreen->addGeometryRenderPass(
m_childs,
......
......@@ -173,3 +173,7 @@ const std::string WGEPostprocessor::getDescription() const
return m_description;
}
bool WGEPostprocessor::getFixedViewportSize() const
{
return false;
}
......@@ -232,6 +232,17 @@ public:
* \return the description
*/
virtual const std::string getDescription() const;
/**
* When this returns true, the viewport size is fixed to the size of the target texture. This is very useful if you want to process high resolution
* images offscreen. You can implement this function in your postprocessor to modify this. Please be aware that this does not modify the
* camera's projection matrix. This is especially important for correct aspect ratios. You can modify the camera dynamically by using
* callbacks.
*
* \return true if fixed.
*/
virtual bool getFixedViewportSize() const;
protected:
/**
* The textures contain the result. Add at least one result texture
......
......@@ -33,6 +33,9 @@
#include <osg/LineWidth>
#include <osg/Point>
#include <osg/PointSprite>
#include <osgDB/Export>
#include <osgDB/Registry>
#include <osgDB/WriteFile>
#include "core/common/WPropertyHelper.h"
#include "core/common/WPropertyObserver.h"
......@@ -40,6 +43,8 @@
#include "core/dataHandler/WDataSetFiberClustering.h"
#include "core/dataHandler/WDataSetFibers.h"
#include "core/graphicsEngine/WGEColormapping.h"
#include "core/graphicsEngine/WGEUtils.h"
#include "core/graphicsEngine/WGEGeodeUtils.h"
#include "core/graphicsEngine/callbacks/WGEFunctorCallback.h"
#include "core/graphicsEngine/callbacks/WGENodeMaskCallback.h"
#include "core/graphicsEngine/postprocessing/WGEPostprocessingNode.h"
......@@ -256,8 +261,6 @@ void WMFiberDisplaySimple::moduleMain()
// Remember the condition provided to some properties in properties()? The condition can now be used with this condition set.
m_moduleState.add( m_propCondition );
ready();
// create the post-processing node which actually does the nice stuff to the rendered image
osg::ref_ptr< WGEPostprocessingNode > postNode = new WGEPostprocessingNode(
WKernel::getRunningKernel()->getGraphicsEngine()->getViewer()->getCamera()
......@@ -275,6 +278,8 @@ void WMFiberDisplaySimple::moduleMain()
rootState->addUniform( tubeSizeUniform );
rootState->addUniform( colormapRationUniform );
ready();
// needed to observe the properties of the input connector data
boost::shared_ptr< WPropertyObserver > propObserver = WPropertyObserver::create();
m_moduleState.add( propObserver );
......
......@@ -31,9 +31,10 @@
#include "core/kernel/WModuleInputData.h"
#include "core/kernel/WModuleOutputData.h"
#include "core/dataHandler/WDataSetFiberClustering.h"
#include "core/dataHandler/WDataSetFibers.h"
// forward declarations
class WDataSetFibers;
class WDataSetFiberClustering;
class WGEShader;
/**
......
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