From 5429d79e4aeae4fbf39caf574350c23ca3bb0c54 Mon Sep 17 00:00:00 2001 From: "John W. Terrell" Date: Wed, 21 Jan 2026 09:56:47 -0800 Subject: [PATCH 1/5] Added initial implementation of UseVertexAttributeAliasing class --- src/include/osgTools/GraphicsOperations.h | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 src/include/osgTools/GraphicsOperations.h diff --git a/src/include/osgTools/GraphicsOperations.h b/src/include/osgTools/GraphicsOperations.h new file mode 100644 index 0000000..3487cd5 --- /dev/null +++ b/src/include/osgTools/GraphicsOperations.h @@ -0,0 +1,23 @@ +#pragma once + +#include + +// +// Graphics Operations +// + +// UseVertexAttributeAliasing +// +// Enable with: +// viewer.setRealizeOperation(new UseVertexAttributeAliasing()); +// +class UseVertexAttributeAliasing : public osg::GraphicsOperation { +public: + UseVertexAttributeAliasing() + : osg::Referenced(true), + osg::GraphicsOperation("GraphicsOperation", false) {} + + virtual void operator()(osg::GraphicsContext* gc) { + gc->getState()->setUseVertexAttributeAliasing(true); + } +}; From 29933dbeb6f450146628859be49da10e640a0e46 Mon Sep 17 00:00:00 2001 From: "John W. Terrell" Date: Wed, 21 Jan 2026 10:03:52 -0800 Subject: [PATCH 2/5] Added new header to public headers declaration --- src/CMakeLists.txt | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index ad83623..8a61743 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,6 +1,7 @@ add_library( - osgTools STATIC osgTools/StatsHandler.cpp include/osgTools/StatsHandler.h - include/osgTools/Version.h) + osgTools STATIC + osgTools/StatsHandler.cpp include/osgTools/GraphicsOperations.h + include/osgTools/StatsHandler.h include/osgTools/Version.h) add_library(osgTools::osgTools ALIAS osgTools) @@ -12,6 +13,7 @@ target_sources( BASE_DIRS include FILES + include/osgTools/GraphicsOperations.h include/osgTools/StatsHandler.h include/osgTools/Version.h) From 06ea2a041005f788865e4a29a60a1d294aad1520 Mon Sep 17 00:00:00 2001 From: "John W. Terrell" Date: Wed, 21 Jan 2026 10:19:25 -0800 Subject: [PATCH 3/5] Added missing namespace --- src/include/osgTools/GraphicsOperations.h | 36 ++++++++++++----------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/src/include/osgTools/GraphicsOperations.h b/src/include/osgTools/GraphicsOperations.h index 3487cd5..72897ab 100644 --- a/src/include/osgTools/GraphicsOperations.h +++ b/src/include/osgTools/GraphicsOperations.h @@ -2,22 +2,24 @@ #include -// -// Graphics Operations -// +namespace osgTools { + // + // Graphics Operations + // -// UseVertexAttributeAliasing -// -// Enable with: -// viewer.setRealizeOperation(new UseVertexAttributeAliasing()); -// -class UseVertexAttributeAliasing : public osg::GraphicsOperation { -public: - UseVertexAttributeAliasing() - : osg::Referenced(true), - osg::GraphicsOperation("GraphicsOperation", false) {} + // UseVertexAttributeAliasing + // + // Enable with: + // viewer.setRealizeOperation(new UseVertexAttributeAliasing()); + // + class UseVertexAttributeAliasing : public osg::GraphicsOperation { + public: + UseVertexAttributeAliasing() + : osg::Referenced(true), + osg::GraphicsOperation("GraphicsOperation", false) {} - virtual void operator()(osg::GraphicsContext* gc) { - gc->getState()->setUseVertexAttributeAliasing(true); - } -}; + virtual void operator()(osg::GraphicsContext* gc) { + gc->getState()->setUseVertexAttributeAliasing(true); + } + }; +} // namespace osgTools From 5441d3fd74565fbca5e5bc7b9bba4fcf0ff3f284 Mon Sep 17 00:00:00 2001 From: "John W. Terrell" Date: Thu, 22 Jan 2026 13:22:51 -0800 Subject: [PATCH 4/5] Added PointShaderProgram --- src/CMakeLists.txt | 21 +++----- src/include/osgTools/PointShaderProgram.h | 8 +++ src/osgTools/PointShaderProgram.cpp | 60 +++++++++++++++++++++++ 3 files changed, 75 insertions(+), 14 deletions(-) create mode 100644 src/include/osgTools/PointShaderProgram.h create mode 100644 src/osgTools/PointShaderProgram.cpp diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 8a61743..12cef6d 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,21 +1,14 @@ -add_library( - osgTools STATIC - osgTools/StatsHandler.cpp include/osgTools/GraphicsOperations.h - include/osgTools/StatsHandler.h include/osgTools/Version.h) +set(PUBLIC_HEADERS + include/osgTools/GraphicsOperations.h include/osgTools/PointShaderProgram.h + include/osgTools/StatsHandler.h include/osgTools/Version.h) +add_library(osgTools STATIC osgTools/PointShaderProgram.cpp + osgTools/StatsHandler.cpp "${PUBLIC_HEADERS}") add_library(osgTools::osgTools ALIAS osgTools) target_link_libraries(osgTools PUBLIC ${OPENSCENEGRAPH_LIBRARIES}) -target_sources( - osgTools - PUBLIC FILE_SET - HEADERS - BASE_DIRS - include - FILES - include/osgTools/GraphicsOperations.h - include/osgTools/StatsHandler.h - include/osgTools/Version.h) +target_sources(osgTools PUBLIC FILE_SET HEADERS BASE_DIRS include FILES + "${PUBLIC_HEADERS}") install( TARGETS osgTools diff --git a/src/include/osgTools/PointShaderProgram.h b/src/include/osgTools/PointShaderProgram.h new file mode 100644 index 0000000..8d32489 --- /dev/null +++ b/src/include/osgTools/PointShaderProgram.h @@ -0,0 +1,8 @@ +#pragma once + +#include +#include + +namespace osgTools { + osg::ref_ptr createPointShaderProgram(osg::Node *targetNode); +}; diff --git a/src/osgTools/PointShaderProgram.cpp b/src/osgTools/PointShaderProgram.cpp new file mode 100644 index 0000000..340faa8 --- /dev/null +++ b/src/osgTools/PointShaderProgram.cpp @@ -0,0 +1,60 @@ +#include + +using namespace osgTools; + +const char* vertexShaderSource = R"( + #version 330 core + + in vec4 osg_Vertex; + in vec4 osg_Color; + + uniform mat4 osg_ModelViewProjectionMatrix; + + out vec4 vertexColor; + + void main(void) { + gl_Position = osg_ModelViewProjectionMatrix * osg_Vertex; + + vertexColor = osg_Color; + + // Be sure and call `StateSet::setMode(GL_PROGRAM_POINT_SIZE, osg::StateAttribute::ON)`, or + // this will be a no-op! IMPORTANT! + gl_PointSize = 10.0; + } +)"; + +const char* fragmentShaderSource = R"( + #version 330 core + in vec4 vertexColor; + + out vec4 color; + + void main(void) { + // Convert to [-1, 1] so (0,0) is the center of the point. + vec2 p = gl_PointCoord * 2.0 - 1.0; + + // This gives us a radial coordinate without a costly sqrt(), supposedly. + float r2 = dot(p, p); + + // This explicitly recreates legacy FFP point behavior... + float alpha = exp(-r2 * 2.5); + color = vec4(vertexColor.rgb * alpha, vertexColor.a * alpha); + } +)"; + +osg::ref_ptr osgTools::createPointShaderProgram( + osg::Node* target) { + osg::ref_ptr prg = new osg::Program(); + + prg->addShader(new osg::Shader(osg::Shader::VERTEX, vertexShaderSource)); + prg->addShader( + new osg::Shader(osg::Shader::FRAGMENT, fragmentShaderSource)); + + if (target) { + auto stateSet = target->getOrCreateStateSet(); + stateSet->setAttributeAndModes(prg); + stateSet->setMode(GL_PROGRAM_POINT_SIZE, osg::StateAttribute::ON); + } + + return prg; +} From a4d549191110fe5e01ffa59f00ba538bda22ae56 Mon Sep 17 00:00:00 2001 From: "John W. Terrell" Date: Thu, 22 Jan 2026 13:29:41 -0800 Subject: [PATCH 5/5] Fixed point size to 1.0 --- src/osgTools/PointShaderProgram.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/osgTools/PointShaderProgram.cpp b/src/osgTools/PointShaderProgram.cpp index 340faa8..91491bc 100644 --- a/src/osgTools/PointShaderProgram.cpp +++ b/src/osgTools/PointShaderProgram.cpp @@ -19,7 +19,7 @@ const char* vertexShaderSource = R"( // Be sure and call `StateSet::setMode(GL_PROGRAM_POINT_SIZE, osg::StateAttribute::ON)`, or // this will be a no-op! IMPORTANT! - gl_PointSize = 10.0; + gl_PointSize = 1.0; } )";