Commit 3ee738af authored by Sebastian Eichelbaum's avatar Sebastian Eichelbaum
Browse files

[ADD] - some kind of isosurface volume renderer. Yet very simple.

parent 87800c90
......@@ -82,6 +82,7 @@ osg::ref_ptr< osg::Geometry > wge::createUnitCube( const WColor& color )
// create the unit cube manually as the ShapeDrawable and osg::Box does not provide 3D texture coordinates
osg::ref_ptr< osg::Geometry > cube = new osg::Geometry();
osg::ref_ptr< osg::Vec3Array > vertices = osg::ref_ptr< osg::Vec3Array >( new osg::Vec3Array );
osg::ref_ptr< osg::Vec3Array > normals = osg::ref_ptr< osg::Vec3Array >( new osg::Vec3Array );
osg::ref_ptr< osg::Vec4Array > colors = osg::ref_ptr< osg::Vec4Array >( new osg::Vec4Array );
// front face
......@@ -89,36 +90,42 @@ osg::ref_ptr< osg::Geometry > wge::createUnitCube( const WColor& color )
vertices->push_back( osg::Vec3( 1.0, 0.0, 0.0 ) );
vertices->push_back( osg::Vec3( 1.0, 1.0, 0.0 ) );
vertices->push_back( osg::Vec3( 0.0, 1.0, 0.0 ) );
normals->push_back( osg::Vec3( 0.0, 0.0, -1.0 ) );
// back face
vertices->push_back( osg::Vec3( 0.0, 0.0, 1.0 ) );
vertices->push_back( osg::Vec3( 1.0, 0.0, 1.0 ) );
vertices->push_back( osg::Vec3( 1.0, 1.0, 1.0 ) );
vertices->push_back( osg::Vec3( 0.0, 1.0, 1.0 ) );
normals->push_back( osg::Vec3( 0.0, 0.0, 1.0 ) );
// left
vertices->push_back( osg::Vec3( 0.0, 0.0, 0.0 ) );
vertices->push_back( osg::Vec3( 0.0, 1.0, 0.0 ) );
vertices->push_back( osg::Vec3( 0.0, 1.0, 1.0 ) );
vertices->push_back( osg::Vec3( 0.0, 0.0, 1.0 ) );
normals->push_back( osg::Vec3( -1.0, 0.0, 0.0 ) );
// right
vertices->push_back( osg::Vec3( 1.0, 0.0, 0.0 ) );
vertices->push_back( osg::Vec3( 1.0, 1.0, 0.0 ) );
vertices->push_back( osg::Vec3( 1.0, 1.0, 1.0 ) );
vertices->push_back( osg::Vec3( 1.0, 0.0, 1.0 ) );
normals->push_back( osg::Vec3( 1.0, 0.0, 0.0 ) );
// bottom
vertices->push_back( osg::Vec3( 0.0, 0.0, 0.0 ) );
vertices->push_back( osg::Vec3( 1.0, 0.0, 0.0 ) );
vertices->push_back( osg::Vec3( 1.0, 0.0, 1.0 ) );
vertices->push_back( osg::Vec3( 0.0, 0.0, 1.0 ) );
normals->push_back( osg::Vec3( 0.0, -1.0, 0.0 ) );
// top
vertices->push_back( osg::Vec3( 0.0, 1.0, 0.0 ) );
vertices->push_back( osg::Vec3( 1.0, 1.0, 0.0 ) );
vertices->push_back( osg::Vec3( 1.0, 1.0, 1.0 ) );
vertices->push_back( osg::Vec3( 0.0, 1.0, 1.0 ) );
normals->push_back( osg::Vec3( 0.0, 1.0, 0.0 ) );
// set it up and set arrays
cube->addPrimitiveSet( new osg::DrawArrays( osg::PrimitiveSet::QUADS, 0, vertices->size() ) );
......@@ -127,6 +134,10 @@ osg::ref_ptr< osg::Geometry > wge::createUnitCube( const WColor& color )
// set 3D texture coordinates here.
cube->setTexCoordArray( 0, vertices );
// set normals
cube->setNormalArray( normals );
cube->setNormalBinding( osg::Geometry::BIND_PER_PRIMITIVE );
// finally, the colors
colors->push_back( wge::osgColor( color ) );
cube->setColorArray( colors );
......
......@@ -32,6 +32,7 @@
#include <osg/StateAttribute>
#include "../../kernel/WKernel.h"
#include "../../dataHandler/WDataTexture3D.h"
#include "../../common/WColor.h"
#include "../../graphicsEngine/WGEUtils.h"
#include "../../graphicsEngine/WGEGeodeUtils.h"
......@@ -149,6 +150,14 @@ void WMDirectVolumeRendering::moduleMain()
osg::ref_ptr< osg::Node > cube = wge::generateSolidBoundingBoxNode( bb.first, bb.second, WColor( 0.0, 0.0, 0.0, 1.0 ) );
m_shader->apply( cube );
// bind the texture to the node
osg::ref_ptr< osg::Texture3D > texture3D = m_dataSet->getTexture()->getTexture();
osg::StateSet* rootState = cube->getOrCreateStateSet();
rootState->setTextureAttributeAndModes( 0, texture3D, osg::StateAttribute::ON );
// for the texture, also bind the appropriate uniforms
rootState->addUniform( new osg::Uniform( "tex0", 0 ) );
// update node
WKernel::getRunningKernel()->getGraphicsEngine()->getScene()->remove( m_rootNode );
m_rootNode = cube;
......
......@@ -22,14 +22,21 @@
//
//---------------------------------------------------------------------------
#version 120
/////////////////////////////////////////////////////////////////////////////
// Varyings
/////////////////////////////////////////////////////////////////////////////
#include "DVRRaycast.varyings"
/////////////////////////////////////////////////////////////////////////////
// Uniforms
/////////////////////////////////////////////////////////////////////////////
// texture containing the data
uniform sampler3D tex0;
/////////////////////////////////////////////////////////////////////////////
// Attributes
/////////////////////////////////////////////////////////////////////////////
......@@ -38,6 +45,8 @@
// Variables
/////////////////////////////////////////////////////////////////////////////
vec3 rayStart;
/////////////////////////////////////////////////////////////////////////////
// Functions
/////////////////////////////////////////////////////////////////////////////
......@@ -47,7 +56,30 @@
*/
void main()
{
vec4 col = vec4( 0.0, 0.0, 1.0, 0.0 );
gl_FragColor = col;
// please do not laugh, it is a very very very simple "isosurface" shader
vec3 curPoint = v_rayStart;
float value;
int i = 0;
while ( i < 750 )
{
i++;
value = texture3D( tex0, curPoint ).r;
if ( value >= 0.275 )
{
break;
}
else
{
curPoint += 0.001 * v_ray;
}
}
if ( i >= 750 )
{
discard;
}
gl_FragColor = vec4( vec3( 1.0 - i/750.0 ), 1.0 );//texture3D( tex0, curPoint );
}
//---------------------------------------------------------------------------
//
// 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/>.
//
//---------------------------------------------------------------------------
/////////////////////////////////////////////////////////////////////////////
// Varyings
// Used in vertex and fragment shader
/////////////////////////////////////////////////////////////////////////////
// The ray's starting point in texture space
varying vec3 v_rayStart;
// The ray direction in texture space
varying vec3 v_ray;
......@@ -22,14 +22,21 @@
//
//---------------------------------------------------------------------------
#version 120
/////////////////////////////////////////////////////////////////////////////
// Varyings
/////////////////////////////////////////////////////////////////////////////
#include "DVRRaycast.varyings"
/////////////////////////////////////////////////////////////////////////////
// Uniforms
/////////////////////////////////////////////////////////////////////////////
// texture containing the data
uniform sampler3D tex0;
/////////////////////////////////////////////////////////////////////////////
// Attributes
/////////////////////////////////////////////////////////////////////////////
......@@ -47,6 +54,15 @@
*/
void main()
{
// for easy access to texture coordinates
gl_TexCoord[0] = gl_MultiTexCoord0;
// in texture space, the starting point simply is the current surface point in texture space
v_rayStart = gl_TexCoord[0].xyz;
// transform the ray direction to texture space
v_ray = normalize( gl_ModelViewMatrixInverse * -gl_TexCoord[0] ).xyz;
// Simply project the vertex
gl_Position = ftransform();
}
......
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