From 6513fae6690dca92475bf40386b5fb8e53f0408a Mon Sep 17 00:00:00 2001 From: ansgar <ansgar@5a81b35b-ba03-0410-adc8-b2c5c5119f08> Date: Fri, 30 Apr 2010 01:39:18 +0000 Subject: [PATCH] reimplemented transparency; fixed shadow mapping; worked on multi-pass rendering; some minor code cleanup git-svn-id: https://dng.biozentrum.unibas.ch/svn/openstructure/branches/new_gfx@2136 5a81b35b-ba03-0410-adc8-b2c5c5119f08 --- modules/gfx/src/CMakeLists.txt | 4 +- modules/gfx/src/entity.cc | 94 +++++++------------ modules/gfx/src/entity.hh | 8 ++ modules/gfx/src/gfx_object.cc | 63 ++++++++++--- modules/gfx/src/gfx_object.hh | 7 +- modules/gfx/src/gfx_object_base.hh | 3 + modules/gfx/src/impl/cpk_renderer.cc | 2 +- modules/gfx/src/impl/cpk_renderer.hh | 2 +- modules/gfx/src/impl/debug_renderer.cc | 2 - modules/gfx/src/impl/debug_renderer.hh | 1 - modules/gfx/src/impl/entity_renderer.hh | 2 +- modules/gfx/src/impl/line_trace_renderer.cc | 4 - modules/gfx/src/impl/line_trace_renderer.hh | 1 - modules/gfx/src/map_iso.cc | 30 +++--- modules/gfx/src/map_slab.cc | 9 +- modules/gfx/src/prim_list.cc | 6 +- modules/gfx/src/primitives.cc | 2 +- modules/gfx/src/render_pass.hh | 7 +- modules/gfx/src/scene.cc | 17 +++- modules/gfx/src/scene.hh | 2 +- modules/gfx/src/shader.cc | 8 +- ...raglight_lfs_fs.glsl => fraglight_fs.glsl} | 67 +++++++------ ...raglight_lfs_vs.glsl => fraglight_vs.glsl} | 11 +++ modules/gfx/src/surface.cc | 12 ++- modules/gfx/src/vertex_array.cc | 11 +++ modules/gfx/src/vertex_array.hh | 2 + 26 files changed, 220 insertions(+), 157 deletions(-) rename modules/gfx/src/shader/{fraglight_lfs_fs.glsl => fraglight_fs.glsl} (68%) rename modules/gfx/src/shader/{fraglight_lfs_vs.glsl => fraglight_vs.glsl} (68%) diff --git a/modules/gfx/src/CMakeLists.txt b/modules/gfx/src/CMakeLists.txt index 9f3d471ff..e21c2cbec 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 25d63fd4a..b9956105f 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 c0b3c3a9f..10930da73 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 4231be8dc..e2aadfae3 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 0b9322542..878601c80 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 bcbf4613f..c18022b47 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 fc3b2b916..0dabd7360 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 81372f2d0..e5d0503f0 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 574dad2d3..bd8f883f0 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 3a2b6e79a..499a5d18c 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 b80bd9ecd..c43bd5d33 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 45e2b63fa..efd916706 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 fc2a2ad87..39f1e0e10 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 20736f6c9..462237c79 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 32da5912c..3656eec4d 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 4c2395c14..72047adde 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 712a9077a..b649c17f0 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 00c5f7c23..2105b9bb5 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 4ded0a30c..b81d4b0cf 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 6c88204d2..42e9c9857 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 e7d1cd5b7..9f1cbb803 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 d6a9580e7..d4ed6cb6f 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 7052797e3..3eb7006e7 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 40db431fe..f5142f569 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 06d9123ee..1e870c105 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 3279eafad..c11de523f 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(); -- GitLab