diff --git a/modules/gfx/src/CMakeLists.txt b/modules/gfx/src/CMakeLists.txt index 9f3d471ff3381816efa024a3af871f9460da7527..e21c2cbecedcca362ea28e7887fe949482f05940 100644 --- a/modules/gfx/src/CMakeLists.txt +++ b/modules/gfx/src/CMakeLists.txt @@ -229,8 +229,8 @@ if (USE_SHADER) shader/fraglight_lf_fs.glsl shader/basic_lfs_vs.glsl shader/basic_lfs_fs.glsl - shader/fraglight_lfs_vs.glsl - shader/fraglight_lfs_fs.glsl + shader/fraglight_vs.glsl + shader/fraglight_fs.glsl shader/basic_hf_vs.glsl shader/selfx_vs.glsl shader/selfx_fs.glsl diff --git a/modules/gfx/src/entity.cc b/modules/gfx/src/entity.cc index 25d63fd4ac1864d893f2cf1ce9521317f95b56d7..b9956105f03267502bf0f068bab6451c71ae8d79 100644 --- a/modules/gfx/src/entity.cc +++ b/modules/gfx/src/entity.cc @@ -67,7 +67,11 @@ Entity::Entity(const String& name, const Query& q): GfxObj(name), qv_(q, h), - bbox_(geom::Vec3(), geom::Vec3()) + bbox_(geom::Vec3(), geom::Vec3()), + sel_(), + sel_update_(), + trace_(), + opacity_(1.0) { init(RenderMode::SIMPLE); } @@ -78,7 +82,11 @@ Entity::Entity(const String& name, const Query& q): GfxObj(name), qv_(q, h), - bbox_(geom::Vec3(), geom::Vec3()) + bbox_(geom::Vec3(), geom::Vec3()), + sel_(), + sel_update_(), + trace_(), + opacity_(1.0) { init(m); } @@ -87,7 +95,11 @@ Entity::Entity(const String& name, const EntityView& v): GfxObj(name), qv_(v), - bbox_(geom::Vec3(), geom::Vec3()) + bbox_(geom::Vec3(), geom::Vec3()), + sel_(), + sel_update_(), + trace_(), + opacity_(1.0) { init(RenderMode::SIMPLE); } @@ -97,7 +109,11 @@ Entity::Entity(const String& name, const EntityView& v): GfxObj(name), qv_(v), - bbox_(geom::Vec3(), geom::Vec3()) + bbox_(geom::Vec3(), geom::Vec3()), + sel_(), + sel_update_(), + trace_(), + opacity_(1.0) { init(m); } @@ -312,6 +328,7 @@ bool Entity::UpdateIfNeeded() const renderer->PrepareRendering(); updated=true; } + renderer->VA().SetOpacity(opacity_); } if (updated) { this->CacheBoundingBox(); @@ -340,65 +357,19 @@ void Entity::CustomRenderGL(RenderPass pass) for (RendererMap::iterator i=renderer_.begin(), e=renderer_.end(); i!=e; ++i) { impl::EntityRenderer* r=i->second; - if(r->IsEnabled()){ - if(pass==STANDARD_RENDER_PASS || pass==OPAQUE_RENDER_PASS) { + if(r->IsEnabled()) { + if(pass==STANDARD_RENDER_PASS) { r->Render(pass); - if(pass==STANDARD_RENDER_PASS && outline_flag_) { + if(outline_flag_) { r->VA().SetOutlineMode(outline_mode_); - r->Render(pass); + r->Render(STANDARD_RENDER_PASS); r->VA().SetOutlineMode(0); } - } else if(pass==GLOW_RENDER_PASS && r->HasSelection()) { - r->Render(pass); + } else if(pass==GLOW_RENDER_PASS) { + r->Render(GLOW_RENDER_PASS); } } } - geom::AlignedCuboid bbox=this->GetBoundingBox(); - geom::Vec3 mmin=bbox.GetMin(); - geom::Vec3 mmax=bbox.GetMax(); -#if 0 - glDisable(GL_LIGHTING); - glLineWidth(1.0); - glColor3f(1.0, 1.0, 1.0); - glBegin(GL_LINES); - glVertex3(geom::Vec3(mmin[0], mmin[1], mmin[2])); - glVertex3(geom::Vec3(mmin[0], mmax[1], mmin[2])); - - glVertex3(geom::Vec3(mmin[0], mmax[1], mmin[2])); - glVertex3(geom::Vec3(mmin[0], mmax[1], mmax[2])); - - glVertex3(geom::Vec3(mmin[0], mmax[1], mmax[2])); - glVertex3(geom::Vec3(mmin[0], mmin[1], mmax[2])); - - glVertex3(geom::Vec3(mmin[0], mmin[1], mmax[2])); - glVertex3(geom::Vec3(mmin[0], mmin[1], mmin[2])); - - - glVertex3(geom::Vec3(mmax[0], mmin[1], mmin[2])); - glVertex3(geom::Vec3(mmax[0], mmax[1], mmin[2])); - - glVertex3(geom::Vec3(mmax[0], mmax[1], mmin[2])); - glVertex3(geom::Vec3(mmax[0], mmax[1], mmax[2])); - - glVertex3(geom::Vec3(mmax[0], mmax[1], mmax[2])); - glVertex3(geom::Vec3(mmax[0], mmin[1], mmax[2])); - - glVertex3(geom::Vec3(mmax[0], mmin[1], mmax[2])); - glVertex3(geom::Vec3(mmax[0], mmin[1], mmin[2])); - - glVertex3(geom::Vec3(mmin[0], mmin[1], mmin[2])); - glVertex3(geom::Vec3(mmax[0], mmin[1], mmin[2])); - - glVertex3(geom::Vec3(mmin[0], mmax[1], mmin[2])); - glVertex3(geom::Vec3(mmax[0], mmax[1], mmin[2])); - - glVertex3(geom::Vec3(mmin[0], mmax[1], mmax[2])); - glVertex3(geom::Vec3(mmax[0], mmax[1], mmax[2])); - - glVertex3(geom::Vec3(mmin[0], mmin[1], mmax[2])); - glVertex3(geom::Vec3(mmax[0], mmin[1], mmax[2])); - glEnd(); -#endif } void Entity::CustomRenderPov(PovState& pov) @@ -582,6 +553,13 @@ void Entity::OptionsChanged(RenderMode::Type render_mode) Scene::Instance().ObjectChanged(this->GetName()); } +void Entity::SetOpacity(float f) +{ + opacity_=f; + this->UpdateIfNeeded(); + Scene::Instance().RequestRedraw(); +} + void Entity::OnRenderModeChange() { for (RendererMap::iterator i=renderer_.begin(), @@ -667,7 +645,7 @@ void Entity::SetRenderMode(RenderMode::Type mode, } renderer->UpdateViews(); } - this->ReapplyColorOps(); + this->ReapplyColorOps(); // done in rebuild? this->FlagRebuild(); Scene::Instance().RenderModeChanged(GetName()); } @@ -691,7 +669,7 @@ void Entity::SetVisible(const mol::EntityView& view, bool visible){ renderer->SetVisible(view, visible); renderer->UpdateViews(); } - this->ReapplyColorOps(); + this->ReapplyColorOps(); // done in rebuild? this->FlagRebuild(); } diff --git a/modules/gfx/src/entity.hh b/modules/gfx/src/entity.hh index c0b3c3a9fd48f94bfbfe67e76530f5f5c36f4c06..10930da73d680e19f44eb79844e190ff0a57d93c 100644 --- a/modules/gfx/src/entity.hh +++ b/modules/gfx/src/entity.hh @@ -140,7 +140,13 @@ public: virtual void OptionsChanged(RenderMode::Type mode); + virtual void SetOpacity(float f); + virtual float GetOpacity() const {return opacity_;} + /// \brief rebuild graphical object (see ctor comments) + /* + the naming here is misleading - this method WON'T be called upon FlagRebuild + */ void Rebuild(); /// \brief only grab updated positions, dont rebuild the whole thing @@ -291,6 +297,8 @@ private: typedef boost::ptr_map<RenderMode::Type, impl::EntityRenderer> RendererMap; mutable RendererMap renderer_; + + float opacity_; }; diff --git a/modules/gfx/src/gfx_object.cc b/modules/gfx/src/gfx_object.cc index 4231be8dc6a491c3793c349039246e970ece0c16..e2aadfae3bf37b684e686669656f9631e9f8cb53 100644 --- a/modules/gfx/src/gfx_object.cc +++ b/modules/gfx/src/gfx_object.cc @@ -120,6 +120,9 @@ void GfxObj::RenderGL(RenderPass pass) PreRenderGL(rebuild_); rebuild_=false; refresh_=false; + // there really needs to be a central place + // where the va attributes are re-applied + va_.SetOpacity(opacity_); } } if(IsVisible()) { @@ -136,15 +139,30 @@ void GfxObj::RenderGL(RenderPass pass) } LOGN_TRACE("calling custom render gl pass " << pass); - CustomRenderGL(pass); - - if(pass==0 && outline_flag_>0) { - va_.SetOutlineMode(outline_mode_); - CustomRenderGL(pass); - va_.SetOutlineMode(0); - } - - if(pass==1) { + /* + only STANDARD_RENDER_PASS and GLOW_RENDER_PASS are + passed down to the custom rendering routines + */ + + if(pass==DEPTH_RENDER_PASS) { + render_depth_only(); + } else if(pass==TRANSPARENT_RENDER_PASS) { + if(GetOpacity()<1.0) { + render_depth_only(); + CustomRenderGL(STANDARD_RENDER_PASS); + } + } else if(pass==STANDARD_RENDER_PASS) { + if(GetOpacity()>=1.0) { + CustomRenderGL(STANDARD_RENDER_PASS); + } + if(outline_flag_) { + va_.SetOutlineMode(outline_mode_); + CustomRenderGL(pass); + va_.SetOutlineMode(0); + } + } else if(pass==GLOW_RENDER_PASS) { + CustomRenderGL(GLOW_RENDER_PASS); + } else if(pass==OVERLAY_RENDER_PASS) { LOGN_TRACE("drawing labels"); render_labels(); } @@ -320,7 +338,9 @@ void GfxObj::SetAmbientOcclusionWeight(float w) void GfxObj::SetOpacity(float o) { opacity_=o; - FlagRebuild(); + va_.SetOpacity(opacity_); + FlagRefresh(); + Scene::Instance().RequestRedraw(); } void GfxObj::ColorBy(const mol::EntityView& ev, @@ -578,7 +598,7 @@ void GfxObj::ReapplyColorOps(){ GfxObjP o=dyn_cast<GfxObj>(shared_from_this()); for(boost::ptr_vector<gfx::ColorOp>::iterator it=c_ops_.begin(); it!=c_ops_.end();++it) { - it->ApplyTo(o); + it->ApplyTo(o); } } } @@ -596,4 +616,25 @@ void GfxObj::Debug(unsigned int flags) va_.DrawNormals(flags & 0x1); } +void GfxObj::render_depth_only() +{ + glPushAttrib(GL_ALL_ATTRIB_BITS); + glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); + glDisable(GL_LIGHTING); + glDisable(GL_COLOR_MATERIAL); + glDisable(GL_BLEND); + glDisable(GL_FOG); + glShadeModel(GL_FLAT); + glDisable(GL_LINE_SMOOTH); + glDisable(GL_POINT_SMOOTH); + glDisable(GL_POLYGON_SMOOTH); + glDisable(GL_DITHER); + glDisable(GL_NORMALIZE); + glEnable(GL_DEPTH_TEST); + CustomRenderGL(STANDARD_RENDER_PASS); + glColorMask(GL_TRUE,GL_TRUE,GL_TRUE,GL_TRUE); + glPopAttrib(); +} + + }} // ns diff --git a/modules/gfx/src/gfx_object.hh b/modules/gfx/src/gfx_object.hh index 0b9322542f19f4aebf671f58c68d5fe63af0e1ce..878601c809be14c995ce4bcf8230ab918d36ec23 100644 --- a/modules/gfx/src/gfx_object.hh +++ b/modules/gfx/src/gfx_object.hh @@ -82,6 +82,7 @@ public: virtual void SetAmbientLocalWeight(float w); virtual void SetAmbientOcclusionWeight(float w); virtual void SetOpacity(float f); + virtual float GetOpacity() const {return opacity_;} virtual void ColorBy(const mol::EntityView& ev, const String& prop, const Gradient& g, float minv, float maxv); @@ -108,6 +109,10 @@ public: const mol::Transform& tf) const; // implemented in derived classes for the actual GL rendering + /* + note: only STANDARD_RENDER_PASS and GLOW_RENDER_PASS need to + be implemented, the rest is taken care of by GfxObj::RenderGL + */ virtual void CustomRenderGL(RenderPass pass); // implemented in derived classes for the actual POVray export @@ -158,7 +163,6 @@ public: bool GetAALines() const {return aalines_flag_;} float GetLineWidth() const {return line_width_;} float GetLineHalo() const {return line_halo_;} - float GetOpacity() const {return opacity_;} void SetNormalSmoothFactor(float smoothf); float GetNormalSmoothFactor() const; @@ -190,6 +194,7 @@ public: void CleanColorOps(); void ReapplyColorOps(); void render_labels() const; + void render_depth_only(); IndexedVertexArray va_; RenderMode::Type render_mode_; diff --git a/modules/gfx/src/gfx_object_base.hh b/modules/gfx/src/gfx_object_base.hh index bcbf4613f8e1c7216988845e1f93ccf72e229685..c18022b47e6d071471bf268395b800abff6ce3a4 100644 --- a/modules/gfx/src/gfx_object_base.hh +++ b/modules/gfx/src/gfx_object_base.hh @@ -112,6 +112,9 @@ class DLLEXPORT_OST_GFX GfxObjBase: public GfxNode /// \brief set opacity (1 = no transparency) virtual void SetOpacity(float f) = 0; + /// \brief returns a value smaller than 1.0 if transparency is used in this object + virtual float GetOpacity() const = 0; + /// \brief color each component based on the gradient-mapped property of /// the given entity virtual void ColorBy(const mol::EntityView& ev, diff --git a/modules/gfx/src/impl/cpk_renderer.cc b/modules/gfx/src/impl/cpk_renderer.cc index fc3b2b916170cc0e5dc16e2ea9f3a0b425fb6cdb..0dabd7360082bdac951616c5ea9d0e3b93a0dca1 100644 --- a/modules/gfx/src/impl/cpk_renderer.cc +++ b/modules/gfx/src/impl/cpk_renderer.cc @@ -74,7 +74,7 @@ void CPKRenderer::Render(RenderPass pass) { if(options_!=NULL){ #if OST_SHADER_SUPPORT_ENABLED - if(options_->GetCPKMode()==1 || options_->GetCPKMode()==2) { + if(pass==STANDARD_RENDER_PASS && (options_->GetCPKMode()==1 || options_->GetCPKMode()==2)) { this->RenderCPK2(); return; } diff --git a/modules/gfx/src/impl/cpk_renderer.hh b/modules/gfx/src/impl/cpk_renderer.hh index 81372f2d022127c94df0dfff1cd189cc5ae4a3c4..e5d0503f0be4556429957a3732f63dfca1762512 100644 --- a/modules/gfx/src/impl/cpk_renderer.hh +++ b/modules/gfx/src/impl/cpk_renderer.hh @@ -37,7 +37,7 @@ public: virtual void RenderPov(PovState& pov, const std::string& name); - virtual void Render(RenderPass pass=STANDARD_RENDER_PASS); + virtual void Render(RenderPass pass); virtual bool CanSetOptions(RenderOptionsPtr& render_options); virtual void SetOptions(RenderOptionsPtr& render_options); diff --git a/modules/gfx/src/impl/debug_renderer.cc b/modules/gfx/src/impl/debug_renderer.cc index 574dad2d35a27a1ba71a526d333508ae4f8c57d2..bd8f883f03174ce7807165ecf9deea8e251c9c8f 100644 --- a/modules/gfx/src/impl/debug_renderer.cc +++ b/modules/gfx/src/impl/debug_renderer.cc @@ -104,8 +104,6 @@ void DebugRenderer::PrepareRendering() #endif } -void DebugRenderer::Render(){} - bool DebugRenderer::CanSetOptions(RenderOptionsPtr& render_options){ return render_options.get()->GetRenderMode()==RenderMode::SLINE; } diff --git a/modules/gfx/src/impl/debug_renderer.hh b/modules/gfx/src/impl/debug_renderer.hh index 3a2b6e79a464b780fbb13ef40a794743564f40a4..499a5d18c51703f5fcc3dca832a07d14adbaf398 100644 --- a/modules/gfx/src/impl/debug_renderer.hh +++ b/modules/gfx/src/impl/debug_renderer.hh @@ -33,7 +33,6 @@ public: DebugRenderer(BackboneTrace* trace); virtual void PrepareRendering(); - virtual void Render(); virtual bool CanSetOptions(RenderOptionsPtr& render_options); virtual void SetOptions(RenderOptionsPtr& render_options); diff --git a/modules/gfx/src/impl/entity_renderer.hh b/modules/gfx/src/impl/entity_renderer.hh index b80bd9ecded901e321d76c27cd2e9b181ee955e1..c43bd5d3399ae6cf51bf3debe0aad3c623513c64 100644 --- a/modules/gfx/src/impl/entity_renderer.hh +++ b/modules/gfx/src/impl/entity_renderer.hh @@ -118,7 +118,7 @@ public: /// /// The rendering buffers and vertex arrays should be prepared in /// PrepareRendering() - virtual void Render(RenderPass pass=STANDARD_RENDER_PASS); + virtual void Render(RenderPass pass); ///\brief povray rendering call virtual void RenderPov(PovState& pov, const std::string& name); diff --git a/modules/gfx/src/impl/line_trace_renderer.cc b/modules/gfx/src/impl/line_trace_renderer.cc index 45e2b63fa7e013df3c2e78653764c83312be4693..efd91670667d0aa5d25db71f2c43aecb965ca623 100644 --- a/modules/gfx/src/impl/line_trace_renderer.cc +++ b/modules/gfx/src/impl/line_trace_renderer.cc @@ -86,10 +86,6 @@ void LineTraceRenderer::PrepareRendering(const BackboneTrace& trace_subset, state_=0; } -void LineTraceRenderer::Render() -{ -} - bool LineTraceRenderer::CanSetOptions(RenderOptionsPtr& render_options) { return render_options.get()->GetRenderMode()==RenderMode::LINE_TRACE; diff --git a/modules/gfx/src/impl/line_trace_renderer.hh b/modules/gfx/src/impl/line_trace_renderer.hh index fc2a2ad87b951e4f7e9788f1fb8aa66ff38f28dc..39f1e0e10a60cdd6a740cb2076a90d7991f3d23c 100644 --- a/modules/gfx/src/impl/line_trace_renderer.hh +++ b/modules/gfx/src/impl/line_trace_renderer.hh @@ -46,7 +46,6 @@ public: virtual void PrepareRendering(); virtual void PrepareRendering(const BackboneTrace& trace_subset, IndexedVertexArray& va, bool is_sel); - virtual void Render(); virtual bool CanSetOptions(RenderOptionsPtr& render_options); virtual void SetOptions(RenderOptionsPtr& render_options); diff --git a/modules/gfx/src/map_iso.cc b/modules/gfx/src/map_iso.cc index 20736f6c981ebafc4426a17ff2253355259e3275..462237c79f761c08207c2de78600424d53aa4e44 100644 --- a/modules/gfx/src/map_iso.cc +++ b/modules/gfx/src/map_iso.cc @@ -228,30 +228,22 @@ private: void MapIso::CustomRenderGL(RenderPass pass) { - switch (pass) { - case OPAQUE_RENDER_PASS: - glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); - va_.RenderGL(); - glColorMask(GL_TRUE,GL_TRUE,GL_TRUE,GL_TRUE); - break; - case STANDARD_RENDER_PASS: - va_.RenderGL(); - if (debug_octree_) { - OctreeDebugger d(level_, mh_.IndexToCoord(img::Point(1,1,1))- - mh_.IndexToCoord(img::Point(0,0,0))); - glPushAttrib(GL_ENABLE_BIT); - glDisable(GL_LIGHTING); - octree_.VisitDF(d); - glPopAttrib(); - } - break; - case GLOW_RENDER_PASS: - return; + if(pass==STANDARD_RENDER_PASS) { + va_.RenderGL(); + if (debug_octree_) { + OctreeDebugger d(level_, mh_.IndexToCoord(img::Point(1,1,1))- + mh_.IndexToCoord(img::Point(0,0,0))); + glPushAttrib(GL_ENABLE_BIT); + glDisable(GL_LIGHTING); + octree_.VisitDF(d); + glPopAttrib(); + } } } void MapIso::CustomRenderPov(PovState& pov) { + // TODO: isocontour pov export } void MapIso::OnInput(const InputEvent& e) diff --git a/modules/gfx/src/map_slab.cc b/modules/gfx/src/map_slab.cc index 32da5912cf1a9fee1395c8f65e3e150c84e45670..3656eec4d716b69269167d4a16bdf52c727b2dd6 100644 --- a/modules/gfx/src/map_slab.cc +++ b/modules/gfx/src/map_slab.cc @@ -108,16 +108,9 @@ void MapSlab::CustomRenderGL(RenderPass pass) { if(rebuild_) rebuild_tex(); - if(GetOpacity()<1.0) { - if(pass!=1) return; - glColorMask(GL_FALSE,GL_FALSE,GL_FALSE,GL_FALSE); + if(pass==STANDARD_RENDER_PASS) { render_slab(); - glColorMask(GL_TRUE,GL_TRUE,GL_TRUE,GL_TRUE); - } else { - if(pass!=0) return; } - - render_slab(); } void MapSlab::CustomRenderPov(PovState& pov) diff --git a/modules/gfx/src/prim_list.cc b/modules/gfx/src/prim_list.cc index 4c2395c1400088038a6cf5e4aeb48fab152a6383..72047addeb091fbec674ae9372f1c98125ee67ee 100644 --- a/modules/gfx/src/prim_list.cc +++ b/modules/gfx/src/prim_list.cc @@ -129,12 +129,14 @@ struct AALineEntryLess void PrimList::CustomRenderGL(RenderPass pass) { - if(pass!=STANDARD_RENDER_PASS) return; - va_.RenderGL(); + if(pass==STANDARD_RENDER_PASS || pass==TRANSPARENT_RENDER_PASS) { + va_.RenderGL(); + } } void PrimList::CustomRenderPov(PovState& pov) { + // TODO: add primlist pov export } void PrimList::AddPoint(geom::Vec3& p, const Color& col) diff --git a/modules/gfx/src/primitives.cc b/modules/gfx/src/primitives.cc index 712a9077a58c97fb202179987982e49b572d100b..b649c17f071fe5b17312bd8e96c14943b3486031 100644 --- a/modules/gfx/src/primitives.cc +++ b/modules/gfx/src/primitives.cc @@ -225,7 +225,7 @@ void Quad::RenderGL(RenderPass pass) if (!this->IsVisible()) { return; } - if (!(pass==OPAQUE_RENDER_PASS || pass==STANDARD_RENDER_PASS)) { + if (!(pass==DEPTH_RENDER_PASS || pass==STANDARD_RENDER_PASS)) { return; } glDisable(GL_LIGHTING); diff --git a/modules/gfx/src/render_pass.hh b/modules/gfx/src/render_pass.hh index 00c5f7c23846a4b381b54a0aafdbcbc3d4481e22..2105b9bb550ce939738b2652728efbe280cf6cd6 100644 --- a/modules/gfx/src/render_pass.hh +++ b/modules/gfx/src/render_pass.hh @@ -32,9 +32,12 @@ typedef enum { GLOW_RENDER_PASS, /// \brief renders objects with solid color as used for shadow map /// generation - OPAQUE_RENDER_PASS, + DEPTH_RENDER_PASS, /// \ brief for transparent objects - TRANSPARENT_RENDER_PASS + /// the standard render pass is not supposed to render transparent + /// objects, as they should get drawn after the rest of the scene + TRANSPARENT_RENDER_PASS, + OVERLAY_RENDER_PASS } RenderPass; }} diff --git a/modules/gfx/src/scene.cc b/modules/gfx/src/scene.cc index 4ded0a30cf8471276ac00eba7a59a3c6dafad247..b81d4b0cf211d37df099ec5cf8fd1a2f401a9ca1 100644 --- a/modules/gfx/src/scene.cc +++ b/modules/gfx/src/scene.cc @@ -112,7 +112,7 @@ Scene::Scene(): fog_color_(0.0,0.0,0.0,0.0), shadow_flag_(false), shadow_quality_(1), - texture_id_(), + shadow_texture_id_(), auto_autoslab_(true), offscreen_flag_(false), main_offscreen_buffer_(0), @@ -285,7 +285,7 @@ void Scene::InitGL() Shader::Instance().Setup(); Shader::Instance().Activate("fraglight"); - glGenTextures(1,&texture_id_); + glGenTextures(1,&shadow_texture_id_); #endif prep_glyphs(); @@ -470,7 +470,7 @@ void Scene::RenderGL() #if OST_SHADER_SUPPORT_ENABLED if(shadow_flag_) { prep_shadow_map(); - #if DEBUG_SMAP + #ifdef DEBUG_SMAP return; #endif } @@ -1586,11 +1586,11 @@ void Scene::prep_shadow_map() glMultMatrix(ltrans.GetTransposedMatrix().Data()); // only render non-transparent objects for the shadow map - root_node_->RenderGL(OPAQUE_RENDER_PASS); + root_node_->RenderGL(DEPTH_RENDER_PASS); // now get the shadow map glActiveTexture(GL_TEXTURE0); - glBindTexture(GL_TEXTURE_2D, texture_id_); + glBindTexture(GL_TEXTURE_2D, shadow_texture_id_); glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, 0,0, smap_size,smap_size, 0); @@ -1786,7 +1786,14 @@ void Scene::render_scene_with_glow() glDepthFunc(GL_LEQUAL); glDepthMask(1); glEnable(GL_DEPTH_TEST); + root_node_->RenderGL(STANDARD_RENDER_PASS); + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + root_node_->RenderGL(TRANSPARENT_RENDER_PASS); + glDisable(GL_BLEND); + root_node_->RenderGL(OVERLAY_RENDER_PASS); + glPushAttrib(GL_ENABLE_BIT); glEnable(GL_COLOR_MATERIAL); glShadeModel(GL_FLAT); diff --git a/modules/gfx/src/scene.hh b/modules/gfx/src/scene.hh index 6c88204d22f6bed0291ed1b36fb4650c5eed2a27..42e9c98571d8e851aa577cc3292c44249f1569a1 100644 --- a/modules/gfx/src/scene.hh +++ b/modules/gfx/src/scene.hh @@ -403,7 +403,7 @@ private: Color fog_color_; bool shadow_flag_; int shadow_quality_; - GLuint texture_id_; + GLuint shadow_texture_id_; bool auto_autoslab_; bool offscreen_flag_; // a simple indicator whether in offscreen mode or not diff --git a/modules/gfx/src/shader.cc b/modules/gfx/src/shader.cc index e7d1cd5b73ab2d1a57e2d8be2c9d17c11ad8f7b1..9f1cbb8036c3e503915660422221dea005cda24f 100644 --- a/modules/gfx/src/shader.cc +++ b/modules/gfx/src/shader.cc @@ -137,8 +137,8 @@ void Shader::Setup() {"fraglight_lf_fs.glsl", GL_FRAGMENT_SHADER}, {"basic_lfs_vs.glsl", GL_VERTEX_SHADER}, {"basic_lfs_fs.glsl", GL_FRAGMENT_SHADER}, - {"fraglight_lfs_vs.glsl", GL_VERTEX_SHADER}, - {"fraglight_lfs_fs.glsl", GL_FRAGMENT_SHADER}, + {"fraglight_vs.glsl", GL_VERTEX_SHADER}, + {"fraglight_fs.glsl", GL_FRAGMENT_SHADER}, {"basic_hf_vs.glsl", GL_VERTEX_SHADER}, {"selfx_vs.glsl", GL_VERTEX_SHADER}, {"selfx_fs.glsl", GL_FRAGMENT_SHADER}, @@ -205,8 +205,8 @@ void Shader::Setup() } // fraglight shader with shadow map shader_program_list.clear(); - shader_program_list.push_back(shader_code_map_["fraglight_lfs_vs.glsl"]); - shader_program_list.push_back(shader_code_map_["fraglight_lfs_fs.glsl"]); + shader_program_list.push_back(shader_code_map_["fraglight_vs.glsl"]); + shader_program_list.push_back(shader_code_map_["fraglight_fs.glsl"]); if(link_shader(shader_program_list,"fraglight_shadow",shader_program_id)) { shader_program_map_["fraglight_shadow"]=shader_program_id; } diff --git a/modules/gfx/src/shader/fraglight_lfs_fs.glsl b/modules/gfx/src/shader/fraglight_fs.glsl similarity index 68% rename from modules/gfx/src/shader/fraglight_lfs_fs.glsl rename to modules/gfx/src/shader/fraglight_fs.glsl index d6a9580e70c5d735d1be8913be053ab56d19b8c5..d4ed6cb6f03e2eda9830169532a02672c10105d1 100644 --- a/modules/gfx/src/shader/fraglight_lfs_fs.glsl +++ b/modules/gfx/src/shader/fraglight_fs.glsl @@ -1,34 +1,27 @@ +uniform bool lighting_flag; +uniform bool two_sided_flag; +uniform bool fog_flag; +uniform bool occlusion_flag; +uniform vec2 ambient_weight; +varying vec4 ambient_color; uniform sampler2D shadow_map; uniform bool shadow_flag; uniform float depth_bias; uniform float epsilon; uniform float shadow_multiplier; -uniform bool lighting_flag; -uniform bool two_sided_flag; -uniform bool fog_flag; -// copy from basic_lfs_fs ! -float CalcShadowFactor(in vec4 coord, in vec2 o) -{ - // get original depth value of line projected towards light - float d = texture2D(shadow_map, coord.xy+o*epsilon).x+depth_bias; - return d<=coord.z ? shadow_multiplier : 1.0; -} - -// modified copy from basic_fl_vs ! +// copy from basic_fl_vs ! bool DirectionalLight(in vec3 normal, in float shin, inout vec4 ambient, inout vec4 diffuse, inout vec4 specular, - inout bool lflag) + inout bool lflag) { float n_vp = max(0.0, dot(normal, normalize(gl_LightSource[0].position.xyz))); - lflag = n_vp>0.0; - if(n_vp==0.0 && two_sided_flag) return false; - float pf = 0.0; + lflag = n_vp>0.0; if(n_vp>0.0 && shin>0.0) { float n_hv = max(0.0, dot(normal, normalize(gl_LightSource[0].halfVector.xyz))); pf=pow(n_hv, shin); @@ -41,33 +34,53 @@ bool DirectionalLight(in vec3 normal, return true; } +// copy from basic_lfs_fs ! +float CalcShadowFactor(in vec4 coord, in vec2 o) +{ + // get original depth value of line projected towards light + float d = texture2D(shadow_map, coord.xy+o*epsilon).x+depth_bias; + return d<=coord.z ? shadow_multiplier : 1.0; +} + void main() { bool lflag=false; - if(lighting_flag) { vec3 normal = normalize(gl_TexCoord[0].stp); vec4 amb = vec4(0.0); vec4 diff = vec4(0.0); vec4 spec = vec4(0.0); - vec4 color = vec4(0.0); - + + vec4 color = gl_Color; + if(occlusion_flag) { + /* + For ambient occlusion and local coloring, two effects are possible. + (1) Blending of the original fragment color and the accumulated + color of the neighbouring fragments, by ambient_weight[0]. + (2) Attenuating the resulting color intensity by the ambient occlusion, + modulated by ambient_weight[1] + Only the rgb values are affected, fragment opacity is unchanged + */ + + color.rgb = mix(gl_Color.rgb,ambient_color.rgb,ambient_weight[0]); + color.rgb = mix(color.rgb,ambient_color.aaa*color.rgb,ambient_weight[1]); + } + if(DirectionalLight(normal, gl_FrontMaterial.shininess, amb, diff, spec,lflag)) { - - color = gl_FrontLightModelProduct.sceneColor + - (amb * gl_FrontMaterial.ambient * gl_Color) + - (diff * gl_FrontMaterial.diffuse * gl_Color) + - (spec * gl_FrontMaterial.specular); + + color = gl_FrontLightModelProduct.sceneColor + + (amb * gl_FrontMaterial.ambient * color) + + (diff * gl_FrontMaterial.diffuse * color) + + (spec * gl_FrontMaterial.specular); } else { bool dummy; DirectionalLight(-normal, gl_BackMaterial.shininess, amb, diff, spec, dummy); color = gl_BackLightModelProduct.sceneColor + - (amb * gl_BackMaterial.ambient * gl_Color) + - (diff * gl_BackMaterial.diffuse * gl_Color) + + (amb * gl_BackMaterial.ambient * color) + + (diff * gl_BackMaterial.diffuse * color) + (spec * gl_BackMaterial.specular); - } gl_FragColor = color; diff --git a/modules/gfx/src/shader/fraglight_lfs_vs.glsl b/modules/gfx/src/shader/fraglight_vs.glsl similarity index 68% rename from modules/gfx/src/shader/fraglight_lfs_vs.glsl rename to modules/gfx/src/shader/fraglight_vs.glsl index 7052797e33abc2ce78b547e54a762d52bd0d9aa4..3eb7006e76c0874ffd26a66581b0b4dd6f7c1d5c 100644 --- a/modules/gfx/src/shader/fraglight_lfs_vs.glsl +++ b/modules/gfx/src/shader/fraglight_vs.glsl @@ -1,3 +1,6 @@ +uniform bool occlusion_flag; +varying vec4 ambient_color; + void main() { // transformed position @@ -14,6 +17,14 @@ void main() // shadow map projection coords gl_TexCoord[1] = gl_TextureMatrix[0] * gl_Vertex; + if(occlusion_flag) { + // ambient occlusion and color terms + ambient_color = gl_MultiTexCoord0; + } else { + ambient_color.rgb = gl_Color; + ambient_color.a = 1.0; + } gl_FrontColor=gl_Color; gl_BackColor=gl_Color; } + diff --git a/modules/gfx/src/surface.cc b/modules/gfx/src/surface.cc index 40db431fe9aa9cf3954e2d831d07f45ecc5796ed..f5142f5692ac212ab79ca0f119ae125a0db35196 100644 --- a/modules/gfx/src/surface.cc +++ b/modules/gfx/src/surface.cc @@ -52,8 +52,9 @@ Surface::Surface(const String& name, const mol::SurfaceHandle& sh): void Surface::CustomRenderGL(RenderPass pass) { - if(pass>0) return; - va_.RenderGL(); + if(pass==STANDARD_RENDER_PASS) { + va_.RenderGL(); + } } void Surface::CustomRenderPov(PovState& pov) @@ -269,6 +270,7 @@ void Surface::Apply(const gfx::UniformColorOp& op, bool store){ } FlagRefresh(); } + void Surface::Apply(const gfx::BasicGradientColorOp& op, bool store) { if(store){ @@ -520,9 +522,9 @@ Vec3 RSurface::GetCenter() const void RSurface::CustomRenderGL(RenderPass pass) { - if (!(pass==STANDARD_RENDER_PASS || pass==OPAQUE_RENDER_PASS)) - return; - va_.RenderGL(); + if(pass==STANDARD_RENDER_PASS) { + va_.RenderGL(); + } } geom::AlignedCuboid RSurface::GetBoundingBox() const diff --git a/modules/gfx/src/vertex_array.cc b/modules/gfx/src/vertex_array.cc index 06d9123eee509c02fd87e4f564268cf216e6b308..1e870c10520b15bfa18ad091e38b524bcbca6f04 100644 --- a/modules/gfx/src/vertex_array.cc +++ b/modules/gfx/src/vertex_array.cc @@ -361,6 +361,17 @@ void IndexedVertexArray::SetColor(VertexID id, const Color& c) entry_list_[id].c[3]=c[3]; } +void IndexedVertexArray::SetOpacity(float o) +{ + o=std::max(0.0f,std::min(1.0f,o)); + // this should really just set a value in the shader... + // but we need to support the fixed function pipeline as well + for(EntryList::iterator it=entry_list_.begin();it!=entry_list_.end();++it) { + it->c[3]=o; + } + FlagRefresh(); +} + void IndexedVertexArray::RenderGL() { static bool use_buff=false; diff --git a/modules/gfx/src/vertex_array.hh b/modules/gfx/src/vertex_array.hh index 3279eafad303cc12a34e2950a6fd013574598fa0..c11de523f8c8108d81cf217561922515b751b1d9 100644 --- a/modules/gfx/src/vertex_array.hh +++ b/modules/gfx/src/vertex_array.hh @@ -145,6 +145,8 @@ class DLLEXPORT_OST_GFX IndexedVertexArray { Color GetColor(VertexID id) const; void SetColor(VertexID id, const Color& col); + void SetOpacity(float o); + // OpenGL rendering call void RenderGL();