Commit 767a85df authored by Jan Möbius's avatar Jan Möbius

Get material for the new renderers from the last material node.

refs #901

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@15757 383ad7c9-94d9-4d36-a494-682f7c89f535
parent aa4f2a31
...@@ -52,7 +52,7 @@ ...@@ -52,7 +52,7 @@
#include <ACG/GL/VertexDeclaration.hh> #include <ACG/GL/VertexDeclaration.hh>
#include <ACG/GL/GLState.hh> #include <ACG/GL/GLState.hh>
#include <ACG/Scenegraph/DrawModes.hh> #include <ACG/Scenegraph/DrawModes.hh>
#include <ACG/Scenegraph/MaterialNode.hh>
namespace ACG namespace ACG
{ {
...@@ -141,6 +141,20 @@ void RenderObject::setupShaderGenFromDrawmode( const DrawModes::DrawModeProperti ...@@ -141,6 +141,20 @@ void RenderObject::setupShaderGenFromDrawmode( const DrawModes::DrawModeProperti
} }
} }
void RenderObject::setMaterial( const SceneGraph::Material* _mat )
{
for (int i = 0; i < 3; ++i)
{
diffuse[i] = _mat->diffuseColor()[i];
ambient[i] = _mat->ambientColor()[i];
specular[i] = _mat->specularColor()[i];
emissive[i] = _mat->baseColor()[i];
}
shininess = _mat->shininess();
alpha = _mat->diffuseColor()[3];
}
RenderObject::RenderObject() RenderObject::RenderObject()
{ {
memset(this, 0, sizeof(RenderObject)); memset(this, 0, sizeof(RenderObject));
......
...@@ -59,6 +59,7 @@ namespace SceneGraph { ...@@ -59,6 +59,7 @@ namespace SceneGraph {
namespace DrawModes { namespace DrawModes {
class DrawModeProperties; class DrawModeProperties;
} }
class Material;
} }
...@@ -260,6 +261,8 @@ struct ACGDLLEXPORT RenderObject ...@@ -260,6 +261,8 @@ struct ACGDLLEXPORT RenderObject
*/ */
void initFromState(GLState* _glState); void initFromState(GLState* _glState);
void setMaterial(const SceneGraph::Material* _mat);
/** \brief Fills out ShaderGenDesc parameters based on Drawmode properties /** \brief Fills out ShaderGenDesc parameters based on Drawmode properties
*/ */
void setupShaderGenFromDrawmode(const SceneGraph::DrawModes::DrawModeProperties* _props); void setupShaderGenFromDrawmode(const SceneGraph::DrawModes::DrawModeProperties* _props);
......
...@@ -71,7 +71,6 @@ ...@@ -71,7 +71,6 @@
#include <iostream> #include <iostream>
#include <ACG/Scenegraph/DrawModes.hh> #include <ACG/Scenegraph/DrawModes.hh>
//== NAMESPACES =============================================================== //== NAMESPACES ===============================================================
...@@ -81,6 +80,8 @@ class IRenderer; ...@@ -81,6 +80,8 @@ class IRenderer;
namespace SceneGraph { namespace SceneGraph {
// prototype declaration to avoid include-loop
class Material;
//== CLASS DEFINITION ========================================================= //== CLASS DEFINITION =========================================================
...@@ -189,9 +190,12 @@ public: ...@@ -189,9 +190,12 @@ public:
* *
* Add any renderable geometry to the renderer via _renderer->addRenderObject() * Add any renderable geometry to the renderer via _renderer->addRenderObject()
* *
* The material is fetched from the last active material node and may be used to setup Renderobjects,
* but may as well be ignored.
*
* \note You should not draw anything yourself in this function. * \note You should not draw anything yourself in this function.
*/ */
virtual void getRenderObjects(IRenderer* /*_renderer*/, GLState& /* _state */, const DrawModes::DrawMode& /* _drawMode */) {} virtual void getRenderObjects(IRenderer* /*_renderer*/, GLState& /* _state */, const DrawModes::DrawMode& /* _drawMode */, const Material* /*_mat*/) {}
/** The leave function is used to restore GL states the have been changed. /** The leave function is used to restore GL states the have been changed.
This function must restore the status before enter() ! This function must restore the status before enter() !
......
...@@ -425,7 +425,7 @@ draw(GLState& _state , const DrawModes::DrawMode& /*_drawMode*/) ...@@ -425,7 +425,7 @@ draw(GLState& _state , const DrawModes::DrawMode& /*_drawMode*/)
void CoordsysNode::getRenderObjects( IRenderer* _renderer, GLState& _state, const DrawModes::DrawMode& _drawMode ) void CoordsysNode::getRenderObjects( IRenderer* _renderer, GLState& _state, const DrawModes::DrawMode& _drawMode, const Material* _mat )
{ {
// Init state - changes when mode_ != POSITION // Init state - changes when mode_ != POSITION
Vec3d pos3D(0.0,0.0,0.0); Vec3d pos3D(0.0,0.0,0.0);
...@@ -437,6 +437,7 @@ void CoordsysNode::getRenderObjects( IRenderer* _renderer, GLState& _state, cons ...@@ -437,6 +437,7 @@ void CoordsysNode::getRenderObjects( IRenderer* _renderer, GLState& _state, cons
RenderObject ro; RenderObject ro;
memset(&ro, 0, sizeof(RenderObject)); memset(&ro, 0, sizeof(RenderObject));
ro.initFromState(&_state); ro.initFromState(&_state);
ro.setMaterial(_mat);
ro.depthTest = true; ro.depthTest = true;
......
...@@ -122,7 +122,7 @@ public: ...@@ -122,7 +122,7 @@ public:
void draw(GLState& _state, const DrawModes::DrawMode& _drawMode); void draw(GLState& _state, const DrawModes::DrawMode& _drawMode);
/// add renderobjects for shader pipeline renderer /// add renderobjects for shader pipeline renderer
void getRenderObjects(IRenderer* _renderer, GLState& _state, const DrawModes::DrawMode& _drawMode); void getRenderObjects(IRenderer* _renderer, GLState& _state, const DrawModes::DrawMode& _drawMode, const Material* _mat);
/// draw Coordsys for object picking /// draw Coordsys for object picking
void pick(GLState& _state, PickTarget _target); void pick(GLState& _state, PickTarget _target);
......
...@@ -579,7 +579,7 @@ draw(GLState& _state, const DrawModes::DrawMode& _drawMode) { ...@@ -579,7 +579,7 @@ draw(GLState& _state, const DrawModes::DrawMode& _drawMode) {
template <class Mesh> template <class Mesh>
void ACG::SceneGraph::MeshNodeT<Mesh>::getRenderObjects( IRenderer* _renderer, GLState& _state, const DrawModes::DrawMode& _drawMode ) void ACG::SceneGraph::MeshNodeT<Mesh>::getRenderObjects( IRenderer* _renderer, GLState& _state, const DrawModes::DrawMode& _drawMode, const Material* _mat )
{ {
RenderObject ro; RenderObject ro;
ro.initFromState(&_state); ro.initFromState(&_state);
...@@ -596,6 +596,7 @@ void ACG::SceneGraph::MeshNodeT<Mesh>::getRenderObjects( IRenderer* _renderer, G ...@@ -596,6 +596,7 @@ void ACG::SceneGraph::MeshNodeT<Mesh>::getRenderObjects( IRenderer* _renderer, G
ro.depthTest = true; // some previous node disabled depth testing ro.depthTest = true; // some previous node disabled depth testing
ro.depthWrite = true; ro.depthWrite = true;
ro.depthFunc = GL_LESS; ro.depthFunc = GL_LESS;
ro.setMaterial(_mat);
// ------------------------ // ------------------------
...@@ -666,6 +667,9 @@ void ACG::SceneGraph::MeshNodeT<Mesh>::getRenderObjects( IRenderer* _renderer, G ...@@ -666,6 +667,9 @@ void ACG::SceneGraph::MeshNodeT<Mesh>::getRenderObjects( IRenderer* _renderer, G
ro.shaderDesc.shadeMode = SG_SHADE_UNLIT; ro.shaderDesc.shadeMode = SG_SHADE_UNLIT;
drawMesh_->disableColors(); drawMesh_->disableColors();
// use specular color for lines
ro.emissive = ro.specular;
add_line_RenderObjects(_renderer, &ro); add_line_RenderObjects(_renderer, &ro);
} }
...@@ -705,6 +709,9 @@ void ACG::SceneGraph::MeshNodeT<Mesh>::getRenderObjects( IRenderer* _renderer, G ...@@ -705,6 +709,9 @@ void ACG::SceneGraph::MeshNodeT<Mesh>::getRenderObjects( IRenderer* _renderer, G
ro.depthRange = Vec2f(0.0f, 1.0f); ro.depthRange = Vec2f(0.0f, 1.0f);
// use specular color for lines
ro.emissive = ro.specular;
add_line_RenderObjects(_renderer, &ro); add_line_RenderObjects(_renderer, &ro);
} }
...@@ -717,6 +724,9 @@ void ACG::SceneGraph::MeshNodeT<Mesh>::getRenderObjects( IRenderer* _renderer, G ...@@ -717,6 +724,9 @@ void ACG::SceneGraph::MeshNodeT<Mesh>::getRenderObjects( IRenderer* _renderer, G
ro.vertexDecl = drawMesh_->getEdgeColoredVertexDeclaration(); ro.vertexDecl = drawMesh_->getEdgeColoredVertexDeclaration();
ro.glDrawArrays(GL_LINES, 0, mesh_.n_edges() * 2); ro.glDrawArrays(GL_LINES, 0, mesh_.n_edges() * 2);
// use specular color for lines
ro.emissive = ro.specular;
_renderer->addRenderObject(&ro); _renderer->addRenderObject(&ro);
// skip other edge primitives for this drawmode layer // skip other edge primitives for this drawmode layer
...@@ -733,6 +743,9 @@ void ACG::SceneGraph::MeshNodeT<Mesh>::getRenderObjects( IRenderer* _renderer, G ...@@ -733,6 +743,9 @@ void ACG::SceneGraph::MeshNodeT<Mesh>::getRenderObjects( IRenderer* _renderer, G
else else
ro.vertexDecl = drawMesh_->getHalfedgeColoredVertexDeclaration(); ro.vertexDecl = drawMesh_->getHalfedgeColoredVertexDeclaration();
// use specular color for lines
ro.emissive = ro.specular;
ro.glDrawArrays(GL_LINES, 0, mesh_.n_halfedges() * 2); ro.glDrawArrays(GL_LINES, 0, mesh_.n_halfedges() * 2);
_renderer->addRenderObject(&ro); _renderer->addRenderObject(&ro);
...@@ -747,7 +760,12 @@ void ACG::SceneGraph::MeshNodeT<Mesh>::getRenderObjects( IRenderer* _renderer, G ...@@ -747,7 +760,12 @@ void ACG::SceneGraph::MeshNodeT<Mesh>::getRenderObjects( IRenderer* _renderer, G
switch (props->primitive()) switch (props->primitive())
{ {
case DrawModes::PRIMITIVE_POINT: add_point_RenderObjects(_renderer, &ro); break; case DrawModes::PRIMITIVE_POINT: add_point_RenderObjects(_renderer, &ro); break;
case DrawModes::PRIMITIVE_EDGE: add_line_RenderObjects(_renderer, &ro); break; case DrawModes::PRIMITIVE_EDGE:
{
// use specular color for lines
ro.emissive = ro.specular;
add_line_RenderObjects(_renderer, &ro);
} break;
case DrawModes::PRIMITIVE_POLYGON: add_face_RenderObjects(_renderer, &ro); break; case DrawModes::PRIMITIVE_POLYGON: add_face_RenderObjects(_renderer, &ro); break;
default: break; default: break;
} }
......
...@@ -272,7 +272,7 @@ public: ...@@ -272,7 +272,7 @@ public:
/** \brief Draws the object deferred /** \brief Draws the object deferred
* *
*/ */
void getRenderObjects(IRenderer* _renderer, GLState& _state, const DrawModes::DrawMode& _drawMode); void getRenderObjects(IRenderer* _renderer, GLState& _state, const DrawModes::DrawMode& _drawMode, const Material* _mat);
/** \brief return available draw modes /** \brief return available draw modes
* *
......
...@@ -770,7 +770,8 @@ GLMatrixd TranslationManipulatorNode::computeWorldMatrix() ...@@ -770,7 +770,8 @@ GLMatrixd TranslationManipulatorNode::computeWorldMatrix()
void TranslationManipulatorNode::getRenderObjects(IRenderer* _renderer, void TranslationManipulatorNode::getRenderObjects(IRenderer* _renderer,
GLState& _state, GLState& _state,
const DrawModes::DrawMode& _drawMode) const DrawModes::DrawMode& _drawMode,
const Material* _mat)
{ {
if (draw_manipulator_) if (draw_manipulator_)
{ {
......
...@@ -195,7 +195,7 @@ public: ...@@ -195,7 +195,7 @@ public:
void draw(GLState& _state, const DrawModes::DrawMode& _drawMode); void draw(GLState& _state, const DrawModes::DrawMode& _drawMode);
/// create renderobjects for shaderpipeline renderer /// create renderobjects for shaderpipeline renderer
void getRenderObjects(IRenderer* _renderer, GLState& _state, const DrawModes::DrawMode& _drawMode); void getRenderObjects(IRenderer* _renderer, GLState& _state, const DrawModes::DrawMode& _drawMode, const Material* _mat);
/// computes world matrix, transforms from model to world space /// computes world matrix, transforms from model to world space
GLMatrixd computeWorldMatrix(); GLMatrixd computeWorldMatrix();
......
...@@ -754,7 +754,8 @@ bool SkeletonNodeT<SkeletonType>::coordFramesVisible() ...@@ -754,7 +754,8 @@ bool SkeletonNodeT<SkeletonType>::coordFramesVisible()
template <class SkeletonType> template <class SkeletonType>
void SkeletonNodeT<SkeletonType>::getRenderObjects(IRenderer* _renderer, void SkeletonNodeT<SkeletonType>::getRenderObjects(IRenderer* _renderer,
GLState& _state, GLState& _state,
const DrawModes::DrawMode& _drawMode) const DrawModes::DrawMode& _drawMode,
const Material* _mat)
{ {
RenderObject ro; RenderObject ro;
ro.initFromState(&_state); ro.initFromState(&_state);
...@@ -772,72 +773,113 @@ void SkeletonNodeT<SkeletonType>::getRenderObjects(IRenderer* _renderer, ...@@ -772,72 +773,113 @@ void SkeletonNodeT<SkeletonType>::getRenderObjects(IRenderer* _renderer,
typename SkeletonType::Iterator it; typename SkeletonType::Iterator it;
Vec4f jointColor;
getJointColor(_state.base_color(), jointColor);
// draw bones
// // draw points
// if ( (_drawMode == DrawModes::WIREFRAME)
// || (_drawMode == DrawModes::SOLID_FLAT_SHADED) for (unsigned int i = 0; i < _drawMode.getNumLayers(); ++i)
// || (_drawMode == DrawModes::SOLID_FACES_COLORED)
// || (_drawMode == DrawModes::SOLID_FACES_COLORED_FLAT_SHADED) )
{ {
const DrawModes::DrawModeProperties* props = _drawMode.getLayer(i);
Vec4f baseColor = _state.base_color(); ro.setupShaderGenFromDrawmode(props);
ro.setupShaderGenFromDrawmode(_drawMode.getDrawModeProperties()); switch (props->primitive())
{
// draw the bones case DrawModes::PRIMITIVE_POINT:
for(it = skeleton_.begin(); it != skeleton_.end(); ++it) { {
Vec3f oldSpecular = ro.specular;
Vec3f oldDiffuse = ro.diffuse;
//joint is the (unique) tail joint of the bone for(it = skeleton_.begin(); it != skeleton_.end(); ++it)
Joint* joint = *it; {
Joint* parent = joint->parent(); // If the vertex is selected, it will be always red
// If it is not selected,
if ( (*it)->selected() )
{
ro.diffuse = Vec3f(1.0f, 0.0f, 0.0f);
ro.specular = Vec3f(1.0f, 0.0f, 0.0f);
}
else {
// If it is the root joint, it will get some kind of orange color
// Otherwise the the Base color is used
if ( (*it)->isRoot() )
{
ro.diffuse = Vec3f(1.0f, 0.66f, 0.0f);
ro.specular = Vec3f(1.0f, 0.66f, 0.0f);
}
else {
ro.diffuse = Vec3f(jointColor[0], jointColor[1] , jointColor[2]);
ro.specular = Vec3f(jointColor[0], jointColor[1] , jointColor[2]);
}
}
//---------------------------------------------------
// Simulate glPointSize(12) with a sphere
//---------------------------------------------------
// 1. Project point to screen
ACG::Vec3d projected = _state.project( pose->globalTranslation( (*it)->id() ) );
// 2. Shift it by the requested point size
// glPointSize defines the diameter but we want the radius, so we divide it by two
ACG::Vec3d shifted = projected;
shifted[0] = shifted[0] + (double)_state.point_size() / 2.0 ;
// 3. un-project into 3D
ACG::Vec3d unProjectedShifted = _state.unproject( shifted );
// 4. The difference vector defines the radius in 3D for the sphere
ACG::Vec3d difference = unProjectedShifted - pose->globalTranslation( (*it)->id() );
const double sphereSize = difference.norm();
sphere_->addToRenderer(_renderer, &ro, sphereSize, ACG::Vec3f(pose->globalTranslation( (*it)->id() )));
}
// root can be ignored // reset material colors in case skeleton polygons are rendered later
// we only want to draw bones from (parent -> joint) ro.specular = oldSpecular;
if (parent == 0) ro.diffuse = oldDiffuse;
continue;
//select joint color } break;
ro.emissive = Vec3f(baseColor[0], baseColor[1], baseColor[2]);
Vec3d parentPos = pose->globalTranslation(parent->id());
Vec3d jointPos = pose->globalTranslation(joint->id());
Vec3d boneVector = (jointPos - parentPos); default:
{
Vec4f baseColor = _state.base_color();
addBoneToRenderer(_renderer, ro, parentPos, boneVector); // draw the bones
} for(it = skeleton_.begin(); it != skeleton_.end(); ++it) {
//joint is the (unique) tail joint of the bone
Joint* joint = *it;
Joint* parent = joint->parent();
// root can be ignored
// we only want to draw bones from (parent -> joint)
if (parent == 0)
continue;
// //select joint color
// // draw the local coordinate frames ro.emissive = Vec3f(baseColor[0], baseColor[1], baseColor[2]);
// if(bCoordFramesVisible_)
// { Vec3d parentPos = pose->globalTranslation(parent->id());
// ACG::GLState::disable(GL_COLOR_MATERIAL); Vec3d jointPos = pose->globalTranslation(joint->id());
// ACG::GLState::disable(GL_LIGHTING);
// Vec3d boneVector = (jointPos - parentPos);
// glLineWidth(3.0);
// glBegin(GL_LINES); addBoneToRenderer(_renderer, ro, parentPos, boneVector);
// for(it = skeleton_.begin(); it != skeleton_.end(); ++it) }
// {
// unsigned int index = (*it)->id();
// typename SkeletonType::Matrix global = pose->globalMatrix(index); }
// NormalizeCoordinateFrame(global); }
// glColor3f(0.8, 0.2, 0.2);
// glVertex( pose->globalTranslation(index));
// glVertex( global.transform_point(Point(fFrameSize_, 0, 0)) );
// glColor3f(0.2, 0.8, 0.2);
// glVertex( pose->globalTranslation(index));
// glVertex( global.transform_point(Point(0, fFrameSize_, 0)) );
// glColor3f(0.2, 0.2, 0.8);
// glVertex( pose->globalTranslation(index));
// glVertex( global.transform_point(Point(0, 0, fFrameSize_)) );
// }
// glEnd();
// glLineWidth(_state.line_width());
// }
} }
} }
......
...@@ -105,7 +105,7 @@ public: ...@@ -105,7 +105,7 @@ public:
void pick(GLState& _state, PickTarget _target); void pick(GLState& _state, PickTarget _target);
/// Adds renderobjects to renderer for flexible shader pipeline /// Adds renderobjects to renderer for flexible shader pipeline
void getRenderObjects(IRenderer* _renderer, GLState& _state, const DrawModes::DrawMode& _drawMode); void getRenderObjects(IRenderer* _renderer, GLState& _state, const DrawModes::DrawMode& _drawMode, const Material* _mat);
/// Set the pose which should be rendered /// Set the pose which should be rendered
void setActivePose(const AnimationHandle &_hAni); void setActivePose(const AnimationHandle &_hAni);
......
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