Commit 2c78ee1f authored by Max Lyon's avatar Max Lyon

Added phong rendering for OpenVolumeMesh

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@16762 383ad7c9-94d9-4d36-a494-682f7c89f535
parent 35d07dcf
......@@ -329,7 +329,8 @@ void VolumeMeshBufferManager<VolumeMesh>::setOptionsFromDrawMode(ACG::SceneGraph
enablePerHalffaceNormals();
else if (_drawMode & (mDrawModes.facesFlatShaded))
enablePerFaceNormals();
else if (_drawMode & (mDrawModes.cellsSmoothShaded | mDrawModes.facesSmoothShaded | mDrawModes.halffacesSmoothShaded))
else if (_drawMode & (mDrawModes.cellsSmoothShaded | mDrawModes.facesSmoothShaded | mDrawModes.halffacesSmoothShaded |
mDrawModes.cellsPhongShaded | mDrawModes.facesPhongShaded | mDrawModes.halffacesPhongShaded))
enablePerVertexNormals();
else
disableNormals();
......
......@@ -56,6 +56,7 @@ public:
:
cellsFlatShaded(ACG::SceneGraph::DrawModes::addDrawMode("Cells (flat shaded)", true)),
cellsSmoothShaded(ACG::SceneGraph::DrawModes::addDrawMode("Cells (smooth shaded)")),
cellsPhongShaded(ACG::SceneGraph::DrawModes::addDrawMode("Cells (phong shaded)")),
cellsColoredPerCell(ACG::SceneGraph::DrawModes::addDrawMode("Cells (colored per cell)")),
cellsColoredPerFace(ACG::SceneGraph::DrawModes::addDrawMode("Cells (colored per face)")),
cellsColoredPerHalfface(ACG::SceneGraph::DrawModes::addDrawMode("Cells (colored per halfface)")),
......@@ -64,6 +65,7 @@ public:
facesFlatShaded(ACG::SceneGraph::DrawModes::addDrawMode("Faces (flat shaded)")),
facesSmoothShaded(ACG::SceneGraph::DrawModes::addDrawMode("Faces (smooth shaded)")),
facesPhongShaded(ACG::SceneGraph::DrawModes::addDrawMode("Faces (phong shaded)")),
facesColoredPerFace(ACG::SceneGraph::DrawModes::addDrawMode("Faces (colored per face)")),
facesColoredPerVertex(ACG::SceneGraph::DrawModes::addDrawMode("Faces (colored per vertex)")),
facesOnCells(ACG::SceneGraph::DrawModes::addDrawMode("Faces (on cells)")),
......@@ -71,6 +73,7 @@ public:
halffacesFlatShaded(ACG::SceneGraph::DrawModes::addDrawMode("Halffaces (flat shaded)")),
halffacesSmoothShaded(ACG::SceneGraph::DrawModes::addDrawMode("Halffaces (smooth shaded)")),
halffacesPhongShaded(ACG::SceneGraph::DrawModes::addDrawMode("Halffaces (phong shaded)")),
halffacesColoredPerHalfface(ACG::SceneGraph::DrawModes::addDrawMode("Halffaces (colored per halfface)")),
halffacesColoredPerVertex(ACG::SceneGraph::DrawModes::addDrawMode("Halffaces (colored per vertex)")),
......@@ -90,10 +93,10 @@ public:
irregularInnerEdges(ACG::SceneGraph::DrawModes::addDrawMode("Irregular edges")),
irregularOuterEdges(ACG::SceneGraph::DrawModes::addDrawMode("Irregular outer valence 2 edges")),
cellBasedDrawModes(cellsFlatShaded | cellsSmoothShaded | cellsColoredPerCell | cellsColoredPerFace
cellBasedDrawModes(cellsFlatShaded | cellsSmoothShaded | cellsPhongShaded | cellsColoredPerCell | cellsColoredPerFace
| cellsColoredPerHalfface | cellsColoredPerVertex | cellsTransparent),
faceBasedDrawModes(facesFlatShaded | facesSmoothShaded | facesColoredPerFace | facesColoredPerVertex | hiddenLineBackgroundFaces),
halffaceBasedDrawModes(halffacesFlatShaded | halffacesSmoothShaded | halffacesColoredPerHalfface
faceBasedDrawModes(facesFlatShaded | facesSmoothShaded | facesPhongShaded | facesColoredPerFace | facesColoredPerVertex | hiddenLineBackgroundFaces),
halffaceBasedDrawModes(halffacesFlatShaded | halffacesSmoothShaded | halffacesPhongShaded | halffacesColoredPerHalfface
| halffacesColoredPerVertex),
edgeBasedDrawModes(edgesWireframe | edgesHiddenLine | edgesColoredPerEdge | irregularInnerEdges | irregularOuterEdges | edgesOnCells),
halfedgeBasedDrawModes(halfedgesWireframe | halfedgesHiddenLine | halfedgesColoredPerHalfedge),
......@@ -104,6 +107,7 @@ public:
ACG::SceneGraph::DrawModes::DrawMode cellsFlatShaded;
ACG::SceneGraph::DrawModes::DrawMode cellsSmoothShaded;
ACG::SceneGraph::DrawModes::DrawMode cellsPhongShaded;
ACG::SceneGraph::DrawModes::DrawMode cellsColoredPerCell;
ACG::SceneGraph::DrawModes::DrawMode cellsColoredPerFace;
ACG::SceneGraph::DrawModes::DrawMode cellsColoredPerHalfface;
......@@ -112,6 +116,7 @@ public:
ACG::SceneGraph::DrawModes::DrawMode facesFlatShaded;
ACG::SceneGraph::DrawModes::DrawMode facesSmoothShaded;
ACG::SceneGraph::DrawModes::DrawMode facesPhongShaded;
ACG::SceneGraph::DrawModes::DrawMode facesColoredPerFace;
ACG::SceneGraph::DrawModes::DrawMode facesColoredPerVertex;
ACG::SceneGraph::DrawModes::DrawMode facesOnCells;
......@@ -119,6 +124,7 @@ public:
ACG::SceneGraph::DrawModes::DrawMode halffacesFlatShaded;
ACG::SceneGraph::DrawModes::DrawMode halffacesSmoothShaded;
ACG::SceneGraph::DrawModes::DrawMode halffacesPhongShaded;
ACG::SceneGraph::DrawModes::DrawMode halffacesColoredPerHalfface;
ACG::SceneGraph::DrawModes::DrawMode halffacesColoredPerVertex;
......@@ -155,6 +161,7 @@ public:
{
if (cellsFlatShaded & _drawMode) return cellsFlatShaded;
if (cellsSmoothShaded & _drawMode) return cellsSmoothShaded;
if (cellsPhongShaded & _drawMode) return cellsPhongShaded;
if (cellsColoredPerCell & _drawMode) return cellsColoredPerCell;
if (cellsColoredPerFace & _drawMode) return cellsColoredPerFace;
if (cellsColoredPerHalfface & _drawMode) return cellsColoredPerHalfface;
......@@ -172,12 +179,14 @@ public:
{
if (facesFlatShaded & _drawMode) return facesFlatShaded;
if (facesSmoothShaded & _drawMode) return facesSmoothShaded;
if (facesPhongShaded & _drawMode) return facesPhongShaded;
if (facesColoredPerFace & _drawMode) return facesColoredPerFace;
if (facesColoredPerFace & _drawMode) return facesColoredPerFace;
if (facesColoredPerVertex & _drawMode) return facesColoredPerVertex;
if (halffacesFlatShaded & _drawMode) return halffacesFlatShaded;
if (halffacesSmoothShaded & _drawMode) return halffacesSmoothShaded;
if (halffacesPhongShaded & _drawMode) return halffacesPhongShaded;
if (halffacesColoredPerHalfface & _drawMode) return halffacesColoredPerHalfface;
if (halffacesColoredPerVertex & _drawMode) return halffacesColoredPerVertex;
......
......@@ -149,7 +149,7 @@ DrawModes::DrawMode VolumeMeshNodeT<VolumeMeshT>::availableDrawModes() const {
if (normalAttrib_.face_normals_available())
result |= drawModes_.cellsFlatShaded;
if (normalAttrib_.vertex_normals_available())
result |= drawModes_.cellsSmoothShaded;
result |= (drawModes_.cellsSmoothShaded | drawModes_.cellsPhongShaded);
if (colorAttrib_.vertex_colors_available())
result |= drawModes_.cellsColoredPerVertex;
if (colorAttrib_.halfface_colors_available())
......@@ -165,7 +165,7 @@ DrawModes::DrawMode VolumeMeshNodeT<VolumeMeshT>::availableDrawModes() const {
if (normalAttrib_.face_normals_available())
result |= drawModes_.facesFlatShaded;
if (normalAttrib_.vertex_normals_available())
result |= drawModes_.facesSmoothShaded;
result |= (drawModes_.facesSmoothShaded | drawModes_.facesPhongShaded);
if (colorAttrib_.vertex_colors_available())
result |= drawModes_.facesColoredPerVertex;
if (colorAttrib_.face_colors_available())
......@@ -177,7 +177,7 @@ DrawModes::DrawMode VolumeMeshNodeT<VolumeMeshT>::availableDrawModes() const {
if (normalAttrib_.face_normals_available())
result |= drawModes_.halffacesFlatShaded;
if (normalAttrib_.vertex_normals_available())
result |= drawModes_.halffacesSmoothShaded;
result |= (drawModes_.halffacesSmoothShaded | drawModes_.halffacesPhongShaded);
if (colorAttrib_.vertex_colors_available())
result |= drawModes_.halffacesColoredPerVertex;
if (colorAttrib_.halfface_colors_available())
......@@ -443,6 +443,12 @@ template<class VolumeMeshT>
void VolumeMeshNodeT<VolumeMeshT>::drawSelection(GLState& _state, const DrawModes::DrawMode& _drawMode)
{
//save current shader
GLint currentProgramm;
glGetIntegerv(GL_CURRENT_PROGRAM, &currentProgramm);
//disable shader for drawing of the selecttion
glUseProgram(0);
GLState::enable(GL_DEPTH_TEST);
GLState::depthFunc(GL_LEQUAL);
_state.set_color( selection_color_ );
......@@ -503,6 +509,8 @@ void VolumeMeshNodeT<VolumeMeshT>::drawSelection(GLState& _state, const DrawMode
glLineWidth(_state.line_width());
glUseProgram(currentProgramm);
}
template<class VolumeMeshT>
......
......@@ -49,6 +49,7 @@
#include <ACG/Math/VectorT.hh>
#include <ACG/Scenegraph/SeparatorNode.hh>
#include <ACG/Scenegraph/StatusNodesT.hh>
#include <ACG/Scenegraph/ShaderNode.hh>
#include <OpenFlipper/common/GlobalDefines.hh>
#include <OpenFlipper/common/BaseObjectData.hh>
#include <ObjectTypes/VolumeMeshObject/VolumeMeshNode.hh>
......@@ -158,6 +159,9 @@ public:
public:
/// Return pointer to the shader node
ACG::SceneGraph::ShaderNode* shaderNode();
/// Get the Scenegraph Mesh Node
ACG::SceneGraph::VolumeMeshNodeT<MeshT>* meshNode();
......@@ -171,6 +175,9 @@ public:
/// Scenegraph Mesh Node
ACG::SceneGraph::VolumeMeshNodeT<MeshT>* meshNode_;
/// Scenegraph Shader Node
ACG::SceneGraph::ShaderNode* shaderNode_;
/** @} */
//===========================================================================
......
......@@ -55,6 +55,8 @@
#include <OpenFlipper/common/GlobalOptions.hh>
#include <OpenFlipper/BasePlugin/PluginFunctions.hh>
#include "VolumeMeshDrawModesContainer.hh"
//== TYPEDEFS =================================================================
//== CLASS DEFINITION =========================================================
......@@ -65,10 +67,9 @@ VolumeMeshObject<MeshT>::VolumeMeshObject(const VolumeMeshObject& _object) :
statusAttrib_(*mesh_),
colorAttrib_(*mesh_),
normalAttrib_(*mesh_),
meshNode_((OpenFlipper::Options::nogui() ?
NULL :
new ACG::SceneGraph::VolumeMeshNodeT<MeshT>(*mesh_, statusAttrib_, colorAttrib_,
normalAttrib_, materialNode(), materialNode(), "NEW VolumeMeshNode"))) {
meshNode_(NULL),
shaderNode_(NULL)
{
init();
......@@ -81,10 +82,9 @@ VolumeMeshObject<MeshT>::VolumeMeshObject(DataType _typeId) :
statusAttrib_(*mesh_),
colorAttrib_(*mesh_, ACG::Vec4f(1.0f, 1.0f, 1.0f, 1.0f) /* Default color */),
normalAttrib_(*mesh_),
meshNode_((OpenFlipper::Options::nogui() ?
NULL :
new ACG::SceneGraph::VolumeMeshNodeT<MeshT>(*mesh_, statusAttrib_, colorAttrib_,
normalAttrib_, materialNode(), materialNode(), "NEW VolumeMeshNode"))) {
meshNode_(NULL),
shaderNode_(NULL)
{
setDataType(_typeId);
init();
......@@ -102,6 +102,7 @@ VolumeMeshObject<MeshT>::~VolumeMeshObject() {
// No need to delete the scenegraph nodes as this will be managed by baseplugin
meshNode_ = 0;
shaderNode_ = 0;
}
/** Cleanup function for mesh objects. Deletes the contents of the whole object and
......@@ -113,6 +114,7 @@ void VolumeMeshObject<MeshT>::cleanup() {
BaseObjectData::cleanup();
meshNode_ = 0;
shaderNode_ = 0;
init();
}
......@@ -127,6 +129,11 @@ void VolumeMeshObject<MeshT>::init() {
if(OpenFlipper::Options::nogui())
return;
shaderNode_ = new ACG::SceneGraph::ShaderNode(materialNode() , "NEW ShaderNode for ");
meshNode_ = new ACG::SceneGraph::VolumeMeshNodeT<MeshT>(*mesh_, statusAttrib_, colorAttrib_,
normalAttrib_, materialNode(), shaderNode(), "NEW VolumeMeshNode");
if(manipulatorNode() == NULL)
std::cerr << "Error when creating volume mesh object! Manipulator node is NULL!" << std::endl;
......@@ -134,7 +141,22 @@ void VolumeMeshObject<MeshT>::init() {
std::cerr << "Error when creating mesh object! Material node is NULL!" << std::endl;
materialNode()->set_point_size(12.0f);
meshNode_->set_parent(materialNode());
QString shaderDir = OpenFlipper::Options::shaderDirStr() + OpenFlipper::Options::dirSeparator();
std::string shaderDirectory = std::string( shaderDir.toUtf8() );
shaderNode_->setShaderDir( shaderDirectory );
VolumeMeshDrawModesContainer drawModes;
if ( QFile( shaderDir + "Phong/Vertex.glsl").exists() && QFile( shaderDir + "Phong/Fragment.glsl" ).exists() )
{
shaderNode_->setShader(drawModes.cellsPhongShaded, "Phong/Vertex.glsl" , "Phong/Fragment.glsl" );
shaderNode_->setShader(drawModes.facesPhongShaded, "Phong/Vertex.glsl" , "Phong/Fragment.glsl" );
shaderNode_->setShader(drawModes.halffacesPhongShaded,"Phong/Vertex.glsl" , "Phong/Fragment.glsl" );
}
else
std::cerr << "Shader Files for Phong not found!" << std::endl;
// Update all nodes
update();
......@@ -155,8 +177,11 @@ void VolumeMeshObject<MeshT>::setName(QString _name) {
if(OpenFlipper::Options::nogui())
return;
std::string nodename = std::string("VolumeMeshNode for mesh " + _name.toUtf8());
meshNode_->name(nodename);
std::string meshnodename = std::string("VolumeMeshNode for mesh " + _name.toUtf8());
meshNode_->name(meshnodename);
std::string shadernodename = std::string("Shadernode for mesh " + _name.toUtf8());
shaderNode_->name(shadernodename);
}
// ===============================================================================
......@@ -244,6 +269,12 @@ BaseObject* VolumeMeshObject<MeshT>::copy() {
return dynamic_cast<BaseObject*> (object);
}
template<class MeshT>
ACG::SceneGraph::ShaderNode* VolumeMeshObject<MeshT>::shaderNode()
{
return shaderNode_;
}
// ===============================================================================
// Visualization
// ===============================================================================
......@@ -305,7 +336,7 @@ QString VolumeMeshObject<MeshT>::getObjectinfo() {
// Picking
// ===============================================================================
/** Given an node index from PluginFunctions::scenegraphPick this function can be used to
/** Given a node index from PluginFunctions::scenegraphPick this function can be used to
* check if the meshNode of the object has been picked.
*
* @param _node_idx Index of the picked mesh node
......@@ -322,6 +353,7 @@ void VolumeMeshObject<MeshT>::enablePicking(bool _enable) {
return;
meshNode_->enablePicking(_enable);
shaderNode_->enablePicking(_enable);
}
template<class MeshT>
......
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