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

[ADD #312] added camera background shading.

parent b14992ae
......@@ -38,6 +38,7 @@
#include <osgGA/TerrainManipulator>
#include <osgViewer/ViewerEventHandlers>
#include <osgViewer/View>
#include <osg/Depth>
#include <osgDB/ReadFile>
......@@ -50,7 +51,6 @@
#include "WGEGeodeUtils.h"
#include "shaders/WGEShader.h"
#include "../common/WConditionOneShot.h"
#include "../common/WThreadedRunner.h"
......@@ -165,31 +165,62 @@ 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 );
}
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 );
// 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 );
}
}
osg::ref_ptr< WGEGroupNode > WGEViewer::getScene()
......
//---------------------------------------------------------------------------
//
// Project: OpenWalnut ( http://www.openwalnut.org )
//
// Copyright 2009 OpenWalnut Community, BSV-Leipzig and CNCF-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
// Bottom Gradient
uniform vec3 u_bottom1Color = vec3( 0.65 );
uniform vec3 u_bottom2Color = vec3( 1.0 );
// Top Gradient
uniform vec3 u_top1Color = vec3( 1.0 );
uniform vec3 u_top2Color = vec3( 0.95 );
// Where to split between bottom and top
uniform float u_horizon = 0.33;
/**
* Pixel position in [0,1]
*/
varying vec2 v_pos;
void main()
{
#ifdef WGE_PLAIN_COLOR
discard;
#else
// is 1 when below horizon line
float bottom = float( v_pos.y <= u_horizon );
float horizon = u_horizon + 0.0001; // NOTE: this prevents div by 0
float topScale = ( v_pos.y - horizon ) / ( 1.0 - horizon );
vec3 color = bottom * mix( u_bottom1Color, u_bottom2Color, v_pos.y / horizon ) +
( 1.0 - bottom ) * mix( u_top1Color, u_top2Color, topScale );
// use texture coordinate to mix along the cylinder
gl_FragColor = vec4( color, 1.0 );
#endif
}
//---------------------------------------------------------------------------
//
// Project: OpenWalnut ( http://www.openwalnut.org )
//
// Copyright 2009 OpenWalnut Community, BSV-Leipzig and CNCF-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
/**
* Pixel position in [0,1]
*/
varying vec2 v_pos;
void main()
{
v_pos = gl_MultiTexCoord0.st;
// apply standard pipeline
gl_FrontColor = gl_Color;
gl_Position = ftransform();
}
......@@ -24,7 +24,7 @@
#version 120
uniform float u_vignetteIntensity = 0.0;
uniform float u_vignetteIntensity = 0.5;
/**
* Pixel position in [0,1]
......
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