Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New edge shader technique #886

Draft
wants to merge 74 commits into
base: production
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
74 commits
Select commit Hold shift + click to select a range
28f4a8f
Added custom lights and disable viewer default light
Aug 5, 2020
7605b62
Remove
Aug 5, 2020
1fbe50a
work in progress: creating multi pass render pipeline
Aug 6, 2020
1dd0087
Work in progress creating outline pipeline
Aug 6, 2020
cffb947
First functional version of normal shader using GLSL es
Aug 7, 2020
8e2470c
Basic normal shader render to texture with multisample2d texture atta…
Aug 7, 2020
fe124c0
Work in progress, trying to render the second pass texture to the scr…
Aug 7, 2020
7330c9d
First sucess in using OSG FBO RTT and Qt
Aug 10, 2020
d957454
Unsuccessful in using Multisamples.. basic edge detection
Aug 10, 2020
f6d10a6
work in progress, created basic pipeline
Aug 11, 2020
52bd665
Finished basic version of outline and highlight selection
Aug 12, 2020
eef8fee
Fixed rendering of edges for transparent objects
Aug 12, 2020
8c18220
Fixed close geometry unique color id for edge detection
Aug 13, 2020
25992ab
Renamed variable and made selection visible behind other objects
Aug 13, 2020
ff87498
Added fix for OSG + QOpenGLWidget interoperability using FBOs
Aug 13, 2020
be59c23
Added debug and configuration options
Aug 13, 2020
860ffe8
Added more configuration options
Aug 13, 2020
d7e89db
Moved global state to OutlinePipeline class
Aug 13, 2020
1a921fe
Decrease sample buffer size
Aug 13, 2020
620edb9
Removed unused code
Aug 13, 2020
de40ade
Simplified unique color id function
Aug 13, 2020
949ef32
Work in progres new edget technique
Aug 14, 2020
16b345a
Implemented new technique for edges
Aug 14, 2020
e8ea801
Generalized the pipeline
Aug 17, 2020
90e6324
Fixed pipeline by disabling msaa and using two color buffers
Aug 18, 2020
a30e39c
Fixed resize
Aug 18, 2020
8d08299
Now work in progress for reloading shaders on the fly
Aug 18, 2020
3a928ae
Finished auto reload shaders
Aug 18, 2020
5494a48
Added offset to show each viewport separatelly
Aug 19, 2020
cf7df7f
save check point: smooth edges, need to make 1 px thick
Aug 19, 2020
00f1101
work in progress implementig canny filter
Aug 20, 2020
0d0e770
fixed identation
Aug 20, 2020
bace9e4
Fixed linear filter and shader reload problem
Aug 20, 2020
9a18712
work in progress: implementing canny filter
Aug 20, 2020
657fa0c
Renamed functions to upper case first letter
Aug 20, 2020
28a3dfa
Finished basic non maximum supression for gradient
Aug 20, 2020
8131b2e
Fixed outline shader and packed pre-render into one texture
Aug 21, 2020
1008f3a
Finished basic outline shader
Aug 21, 2020
c16ffa1
Finished basic outline
Aug 21, 2020
011b4c9
w i p: trying two pass rendering for transparent objects
Aug 25, 2020
f27ade1
Finished basic outline working version
Aug 25, 2020
ab21f2d
Removed unused shader c ode
Aug 25, 2020
1a9051f
Removed unused shader file
Aug 25, 2020
1603c34
Cleared unused code
Aug 25, 2020
d9aa1ce
Packed pre render shader information into one single color buffer
Aug 25, 2020
ceda69c
work in progress: testing new osg version
Aug 27, 2020
8e29171
Trying to make adaptative filters for on screen edge detection
Aug 28, 2020
dfad718
Fixed transparent object color
Aug 28, 2020
0b6efde
Fixed fbo resize issue
Aug 28, 2020
a4f7a36
Removed expensive mix with gradient field
Aug 28, 2020
0793813
Disable multisamples by default since its slow on on-board cards
Aug 28, 2020
c478198
Removed unused varying
Aug 28, 2020
ab155f6
Added flag for enabling/disabling outline and light
Aug 31, 2020
a4b8944
Now resizing FBOs using osg camera resize()
Aug 31, 2020
83afdce
Added option for changing compatibility mode
Aug 31, 2020
7932fb2
Embedded shaders in code
Aug 31, 2020
02ad489
Added comments and removed lights group
Aug 31, 2020
2690995
restored osg version
Sep 1, 2020
b485078
Added command to dynamically enable/disable rendering shaders
Sep 9, 2020
85a51f3
Improved outline shaders effienciency by preventing some texture acce…
Sep 11, 2020
b5a57d9
Added command for dynamically disabling/enabling advanced rendering s…
Sep 11, 2020
9fedafd
Renamed and commented method
Sep 11, 2020
4f55f2f
Synced shader file with embedded shader code
Sep 11, 2020
d8412be
Added optional switch between shader code / shader file
Sep 11, 2020
721181e
Added missing files to cmake
Sep 11, 2020
3f2a350
Removed debug forced stats show
Sep 11, 2020
d2f9e25
Merge branch 'production' into newEdgeShaderTechnique
Sep 11, 2020
69d0013
Tell OR downstreams to pick RapidJSON headers
PeterBowman Sep 1, 2020
0477f31
Merge remote-tracking branch 'origin/master' into newEdgeShaderTechnique
Sep 25, 2020
0d059e2
Merge remote-tracking branch 'origin/production' into newEdgeShaderTe…
Sep 25, 2020
8bcde09
Disabled default text labels since in screenspace they conflict if sh…
Sep 28, 2020
b3c0322
Merge branch 'production' into newEdgeShaderTechnique
bucketzxm Oct 21, 2020
272211e
Merge remote-tracking branch 'origin/production' into newEdgeShaderTe…
braineo Jun 8, 2023
24678cf
add priority for shader switching command
braineo Jun 8, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion plugins/qtosgrave/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ if (Qt5Gui_FOUND AND Qt5Core_FOUND AND Qt5Widgets_FOUND AND Qt5OpenGL_FOUND AND

link_directories(${OPENRAVE_LINK_DIRS})

set(QTOSG_SRCS objecttree.cpp osgcartoon.cpp osgviewerwidget.cpp osgviewerwidget.h osgpick.cpp osgpick.h qtreemodel.cpp qtreemodel.h osgrenderitem.cpp osgrenderitem.h qtreeitem.cpp qtreeitem.h qtosgviewer.cpp qtosgrave.cpp osgskybox.cpp osgskybox.h osglodlabel.cpp osglodlabel.h)
set(QTOSG_SRCS objecttree.cpp osgcartoon.cpp osgviewerwidget.cpp osgviewerwidget.h osgpick.cpp osgpick.h qtreemodel.cpp qtreemodel.h osgrenderitem.cpp osgrenderitem.h qtreeitem.cpp qtreeitem.h qtosgviewer.cpp qtosgrave.cpp osgskybox.cpp osgskybox.h osglodlabel.cpp osglodlabel.h outlineshaderpipeline.h outlineshaderpipeline.cpp)
set(QTOSG_MOCS qtosgviewer.h qtreemodel.h)
set(QTOSG_RCCS qtosgviewer.qrc)

Expand Down
22 changes: 11 additions & 11 deletions plugins/qtosgrave/osgcartoon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,17 +74,17 @@ class OGLSL_Technique : public Technique {
"void main( void )\n"
"{\n"
" vec4 LightPosition = gl_LightSource["<<_lightnum<<"].position;\n"
" vec3 LightDirection;\n"
" if (LightPosition[3]!=0.0) { \n"
" vec4 eye_space_position = gl_ModelViewMatrix * gl_Vertex;\n"
" LightDirection = (LightPosition.xyz-eye_space_position.xyz);\n"
" } else {\n"
" LightDirection = LightPosition.xyz;\n"
" }\n"
" vec3 eye_space_normal = normalize(gl_NormalMatrix * gl_Normal);\n"
" CartoonTexCoord = max(0.0, dot(normalize(LightDirection), eye_space_normal));\n"
" gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;\n"
"}\n";
" vec3 LightDirection;\n"
" if (LightPosition[3]!=0.0) { \n"
" vec4 eye_space_position = gl_ModelViewMatrix * gl_Vertex;\n"
" LightDirection = (LightPosition.xyz-eye_space_position.xyz);\n"
" } else {\n"
" LightDirection = LightPosition.xyz;\n"
" }\n"
" vec3 eye_space_normal = normalize(gl_NormalMatrix * gl_Normal);\n"
" CartoonTexCoord = max(0.0, dot(normalize(LightDirection), eye_space_normal));\n"
" gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;\n"
"}\n";

const char * frag_source =
"uniform sampler1D CartoonTexUnit;"
Expand Down
131 changes: 31 additions & 100 deletions plugins/qtosgrave/osgrenderitem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,12 @@ OSGGroupPtr CreateOSGXYZAxes(double len, double axisthickness)

// set a diffuse color
osg::ref_ptr<osg::StateSet> state = psep->getOrCreateStateSet();

osg::ref_ptr<osg::Material> mat = new osg::Material;
mat->setDiffuse(osg::Material::FRONT, colors[i]);
mat->setAmbient(osg::Material::FRONT, colors[i]);
state->addUniform(new osg::Uniform("osg_MaterialDiffuseColor", colors[i]));
state->addUniform(new osg::Uniform("osg_MaterialAmbientColor", colors[i]));
state->setAttribute( mat );

osg::Matrix matrix;
Expand Down Expand Up @@ -97,7 +100,6 @@ OSGGroupPtr CreateOSGXYZAxes(double len, double axisthickness)
return proot;
}


// Visitor to return the coordinates of a node with respect to another node
class WorldCoordOfNodeVisitor : public osg::NodeVisitor
{
Expand Down Expand Up @@ -151,6 +153,7 @@ Item::Item(OSGGroupPtr osgSceneRoot, OSGGroupPtr osgFigureRoot) : _osgSceneRoot(
_osgWorldTransform->addChild(_osgdata);

_osgSceneRoot->addChild(_osgWorldTransform);
_osgSceneRoot->getOrCreateStateSet()->addUniform(new osg::Uniform("isSelected", 0));
}

Item::~Item()
Expand All @@ -168,67 +171,9 @@ bool Item::ContainsOSGNode(OSGNodePtr pNode)
void Item::SetVisualizationMode(const std::string& visualizationmode)
{
if( _visualizationmode != visualizationmode ) {

// have to undo the previous mode
if( !!_osgwireframe ) {
_osgWorldTransform->removeChild(_osgwireframe);
_osgwireframe.release();
}

// start the new node
_visualizationmode = visualizationmode;

if( _visualizationmode == "selected" ) {
_osgwireframe = new osg::Group;
_osgWorldTransform->addChild(_osgwireframe);
_osgwireframe->addChild(_osgdata);

// set up the state so that the underlying color is not seen through
// and that the drawing mode is changed to wireframe, and a polygon offset
// is added to ensure that we see the wireframe itself, and turn off
// so texturing too.
osg::ref_ptr<osg::StateSet> stateset = new osg::StateSet;
osg::ref_ptr<osg::PolygonOffset> polyoffset = new osg::PolygonOffset;
polyoffset->setFactor(-1.0f);
polyoffset->setUnits(-1.0f);
osg::ref_ptr<osg::PolygonMode> polymode = new osg::PolygonMode;
polymode->setMode(osg::PolygonMode::FRONT_AND_BACK,osg::PolygonMode::LINE);
stateset->setAttributeAndModes(polyoffset,osg::StateAttribute::OVERRIDE|osg::StateAttribute::ON);
stateset->setAttributeAndModes(polymode,osg::StateAttribute::OVERRIDE|osg::StateAttribute::ON);

#if 1
osg::ref_ptr<osg::Material> material = new osg::Material;
material->setDiffuse(osg::Material::FRONT_AND_BACK,osg::Vec4f(0,1,0,1));
material->setAmbient(osg::Material::FRONT_AND_BACK,osg::Vec4f(0,1,0,1));

stateset->setAttributeAndModes(material,osg::StateAttribute::OVERRIDE|osg::StateAttribute::ON);
stateset->setMode(GL_LIGHTING,osg::StateAttribute::OVERRIDE|osg::StateAttribute::OFF);
#else
// version which sets the color of the wireframe.
osg::ref_ptr<osg::Material> material = new osg::Material;
material->setColorMode(osg::Material::OFF); // switch glColor usage off
// turn all lighting off
material->setAmbient(osg::Material::FRONT_AND_BACK, osg::Vec4(0.0,0.0f,0.0f,1.0f));
material->setDiffuse(osg::Material::FRONT_AND_BACK, osg::Vec4(0.0,0.0f,0.0f,1.0f));
material->setSpecular(osg::Material::FRONT_AND_BACK, osg::Vec4(0.0,0.0f,0.0f,1.0f));
// except emission... in which we set the color we desire
material->setEmission(osg::Material::FRONT_AND_BACK, osg::Vec4(0.0,1.0f,0.0f,1.0f));
stateset->setAttributeAndModes(material,osg::StateAttribute::OVERRIDE|osg::StateAttribute::ON);
stateset->setMode(GL_LIGHTING,osg::StateAttribute::OVERRIDE|osg::StateAttribute::ON);
#endif

stateset->setTextureMode(0,GL_TEXTURE_2D,osg::StateAttribute::OVERRIDE|osg::StateAttribute::OFF);

osg::ref_ptr<osg::LineStipple> linestipple = new osg::LineStipple;
linestipple->setFactor(1);
linestipple->setPattern(0xf0f0);
stateset->setAttributeAndModes(linestipple,osg::StateAttribute::OVERRIDE|osg::StateAttribute::ON);

_osgwireframe->setStateSet(stateset);
}
else if( _visualizationmode.size() > 0 ) {
RAVELOG_INFO_FORMAT("unknown visualization type %s", visualizationmode);
}
// need to force cast int to match correct function call so to match shader uniform type
_osgdata->getOrCreateStateSet()->addUniform(new osg::Uniform("isSelected", (int)(_visualizationmode == "selected") ));
}
}

Expand Down Expand Up @@ -278,6 +223,8 @@ void KinBodyItem::Load()

posglinkroot->addChild(posglinktrans);

posglinkroot->getOrCreateStateSet()->addUniform(new osg::Uniform("outlineEnabled", true));

// std::vector< boost::shared_ptr<KinBody::Link> > vParentLinks;
// porlink->GetParentLinks(vParentLinks);
// if( vParentLinks.size() > 0 ) {
Expand Down Expand Up @@ -342,72 +289,56 @@ void KinBodyItem::Load()
if( !bSucceeded || _viewmode == VG_RenderCollision ) {
float x,y,z,w;

// set a diffuse color
osg::ref_ptr<osg::Material> mat = new osg::Material;
float transparency = orgeom->GetTransparency();
if( _viewmode == VG_RenderCollision && (bSucceeded || !orgeom->IsVisible()) ) {
mat->setDiffuse(osg::Material::FRONT_AND_BACK,osg::Vec4f(0.6f,0.6f,1.0f,1.0f));
mat->setAmbient(osg::Material::FRONT_AND_BACK,osg::Vec4f(0.4f,0.4f,1.0f,1.0f));
transparency = 0.5f;
}

// create custom
if( !pgeometrydata ) {
pgeometrydata = new osg::Group();
}

// set a diffuse color
osg::ref_ptr<osg::StateSet> state = pgeometrydata->getOrCreateStateSet();

x = orgeom->GetDiffuseColor().x;
y = orgeom->GetDiffuseColor().y;
z = orgeom->GetDiffuseColor().z;
w = 1;

mat->setDiffuse( osg::Material::FRONT, osg::Vec4f(x,y,z,w) );
mat->setDiffuse( osg::Material::FRONT_AND_BACK, osg::Vec4f(x,y,z,w) );
state->addUniform(new osg::Uniform("osg_MaterialDiffuseColor", osg::Vec4f(x,y,z,1 - transparency)));

x = orgeom->GetAmbientColor().x;
y = orgeom->GetAmbientColor().y;
z = orgeom->GetAmbientColor().z;
w = 1.0f;

mat->setAmbient( osg::Material::FRONT_AND_BACK, osg::Vec4f(x,y,z,w) );
state->addUniform(new osg::Uniform("osg_MaterialAmbientColor", osg::Vec4f(x,y,z,w)));


if( _viewmode == VG_RenderCollision && (bSucceeded || !orgeom->IsVisible()) ) {
mat->setDiffuse(osg::Material::FRONT_AND_BACK,osg::Vec4f(0.6f,0.6f,1.0f,1.0f));
mat->setAmbient(osg::Material::FRONT_AND_BACK,osg::Vec4f(0.4f,0.4f,1.0f,1.0f));
state->addUniform(new osg::Uniform("osg_MaterialDiffuseColor", osg::Vec4f(0.6f,0.6f,1.0f, 0.5f)));
state->addUniform(new osg::Uniform("osg_MaterialAmbientColor", osg::Vec4f(0.4f,0.4f,1.0f, 0.5f)));
transparency = 0.5f;
}

//mat->setShininess( osg::Material::FRONT, 25.0);
mat->setEmission(osg::Material::FRONT, osg::Vec4(0.0, 0.0, 0.0, 1.0));

pgeometrydata->setNodeMask(~TRANSPARENT_ITEM_MASK);
// getting the object to be displayed with transparency
if (transparency > 0) {
mat->setTransparency(osg::Material::FRONT_AND_BACK, transparency);
state->setAttributeAndModes(new osg::BlendFunc(osg::BlendFunc::SRC_ALPHA, osg::BlendFunc::ONE_MINUS_SRC_ALPHA ));
state->setMode(GL_BLEND, osg::StateAttribute::ON);
state->setRenderingHint(osg::StateSet::TRANSPARENT_BIN);

pgeometrydata->setNodeMask(TRANSPARENT_ITEM_MASK);
osg::Depth* depth = new osg::Depth;
depth->setWriteMask( false );
state->setAttributeAndModes( depth, osg::StateAttribute::ON);

if( 1 ) {
// fast
state->setMode(GL_BLEND, osg::StateAttribute::ON);
state->setRenderingHint(osg::StateSet::TRANSPARENT_BIN);
}
else {
// slow
//state->setAttribute(mat,osg::StateAttribute::ON | osg::StateAttribute::OVERRIDE);
//state->setRenderBinDetails(0, "transparent");
//ss->setRenderBinDetails(10, "RenderBin", osg::StateSet::USE_RENDERBIN_DETAILS);

// Enable blending, select transparent bin.
state->setMode( GL_BLEND, osg::StateAttribute::ON );
state->setRenderingHint( osg::StateSet::TRANSPARENT_BIN );

// Enable depth test so that an opaque polygon will occlude a transparent one behind it.
state->setMode( GL_DEPTH_TEST, osg::StateAttribute::ON );

// Conversely, disable writing to depth buffer so that
// a transparent polygon will allow polygons behind it to shine thru.
// OSG renders transparent polygons after opaque ones.
osg::Depth* depth = new osg::Depth;
depth->setWriteMask( false );
state->setAttributeAndModes( depth, osg::StateAttribute::ON );

// Disable conflicting modes.
state->setMode( GL_LIGHTING, osg::StateAttribute::OFF );
}
}
state->setAttributeAndModes(mat, osg::StateAttribute::ON | osg::StateAttribute::OVERRIDE);
//pgeometrydata->setStateSet(state);
Expand Down Expand Up @@ -562,7 +493,6 @@ void KinBodyItem::Load()
pgeometryroot->setName(str(boost::format("geom%d")%igeom));
// Apply external transform to local transform
posglinktrans->addChild(pgeometryroot);

_vecgeoms[linkindex][igeom] = GeomNodes(pgeometrydata, pgeometryroot); // overwrite
}
}
Expand Down Expand Up @@ -600,7 +530,8 @@ void KinBodyItem::Load()
// have to add the left over links to the root group
for(size_t ilink = 0; ilink < addedlinks.size(); ++ilink) {
if( addedlinks[ilink] == 0 ) {
_osgdata->addChild(_veclinks.at(ilink).first);
OSGGroupPtr osgLink = _veclinks.at(ilink).first;
_osgdata->addChild(osgLink);
}
}

Expand Down
Loading