From 6ed84cad845f2a3decd01217e7bc61ff869c019a Mon Sep 17 00:00:00 2001
From: Michael Migliore <mcmigliore@gmail.com>
Date: Wed, 25 Oct 2023 09:37:53 +0200
Subject: [PATCH] Use quad instead of triangle to bound the gaussian splat

---
 ...estCompositeDataPointGaussianSelection.cxx |  2 +-
 .../Cxx/TestPointGaussianSelection.cxx        |  2 +-
 .../OpenGL2/glsl/vtkPointGaussianGS.glsl      | 30 ++++++++-----------
 3 files changed, 15 insertions(+), 19 deletions(-)

diff --git a/Rendering/OpenGL2/Testing/Cxx/TestCompositeDataPointGaussianSelection.cxx b/Rendering/OpenGL2/Testing/Cxx/TestCompositeDataPointGaussianSelection.cxx
index 345739dcf69..41b4d3e61c7 100644
--- a/Rendering/OpenGL2/Testing/Cxx/TestCompositeDataPointGaussianSelection.cxx
+++ b/Rendering/OpenGL2/Testing/Cxx/TestCompositeDataPointGaussianSelection.cxx
@@ -129,7 +129,7 @@ int TestCompositeDataPointGaussianSelection(int argc, char* argv[])
       result->GetNode(0)->GetProperties()->Get(vtkSelectionNode::PROP()) == actor.Get() &&
       result->GetNode(0)->GetProperties()->Get(vtkSelectionNode::COMPOSITE_INDEX()) == 305 &&
       result->GetNode(2)->GetProperties()->Get(vtkSelectionNode::COMPOSITE_INDEX()) == 340 &&
-      selIds && selIds->GetNumberOfTuples() == 5 && selIds->GetValue(2) == 56)
+      selIds && selIds->GetNumberOfTuples() == 4 && selIds->GetValue(2) == 70)
     {
       goodPick = true;
     }
diff --git a/Rendering/OpenGL2/Testing/Cxx/TestPointGaussianSelection.cxx b/Rendering/OpenGL2/Testing/Cxx/TestPointGaussianSelection.cxx
index 9598b32068b..92a30f2918e 100644
--- a/Rendering/OpenGL2/Testing/Cxx/TestPointGaussianSelection.cxx
+++ b/Rendering/OpenGL2/Testing/Cxx/TestPointGaussianSelection.cxx
@@ -115,7 +115,7 @@ int TestPointGaussianSelection(int argc, char* argv[])
     if (node->GetProperties()->Has(vtkSelectionNode::PROP_ID()) &&
       node->GetProperties()->Get(vtkSelectionNode::PROP()) == actor.Get() &&
       node->GetProperties()->Get(vtkSelectionNode::COMPOSITE_INDEX()) == 1 && selIds &&
-      selIds->GetNumberOfTuples() == 14 && selIds->GetValue(4) == 227)
+      selIds->GetNumberOfTuples() == 12 && selIds->GetValue(3) == 227)
     {
       goodPick = true;
     }
diff --git a/Rendering/OpenGL2/glsl/vtkPointGaussianGS.glsl b/Rendering/OpenGL2/glsl/vtkPointGaussianGS.glsl
index 1ac160f7fe4..ba8ff42ff60 100644
--- a/Rendering/OpenGL2/glsl/vtkPointGaussianGS.glsl
+++ b/Rendering/OpenGL2/glsl/vtkPointGaussianGS.glsl
@@ -11,7 +11,7 @@
 //VTK::Color::Dec
 
 layout(points) in;
-layout(triangle_strip, max_vertices = 3) out;
+layout(triangle_strip, max_vertices = 4) out;
 
 uniform int cameraParallel;
 uniform float triangleScale;
@@ -41,7 +41,7 @@ void main()
   vec4 base1 = vec4(1.0,0.0,0.0,0.0);
   vec4 base2 = vec4(0.0,1.0,0.0,0.0);
 
-  // make the triangle face the camera
+  // make the quad face the camera
   if (cameraParallel == 0)
   {
     vec3 dir = normalize(-gl_in[0].gl_Position.xyz);
@@ -55,25 +55,21 @@ void main()
 
   //VTK::Color::Impl
 
-  // note 1.73205 = 2.0*cos(30)
-
-  offset = vec2(-1.73205*radiusVCVSOutput[0], -radiusVCVSOutput[0]);
-
   //VTK::Picking::Impl
 
-  offsetVCGSOutput = offset/radius;
-  gl_Position = VCDCMatrix * (gl_in[0].gl_Position + offset.x*base1 + offset.y*base2);
-  EmitVertex();
+  vec2 offsets[4] = vec2[](vec2(-1., -1.),
+                           vec2(1., -1.),
+                           vec2(-1., 1.),
+                           vec2(1., 1.));
 
-  offset = vec2(1.73205*radiusVCVSOutput[0], -radiusVCVSOutput[0]);
-  offsetVCGSOutput = offset/radius;
-  gl_Position = VCDCMatrix * (gl_in[0].gl_Position + offset.x*base1 + offset.y*base2);
-  EmitVertex();
+  for (int i = 0; i < 4; i++)
+  {
+    vec2 offset = offsets[i] * radiusVCVSOutput[0];
 
-  offset = vec2(0.0, 2.0*radiusVCVSOutput[0]);
-  offsetVCGSOutput = offset/radius;
-  gl_Position = VCDCMatrix * (gl_in[0].gl_Position + offset.x*base1 + offset.y*base2);
-  EmitVertex();
+    offsetVCGSOutput = offset/radius;
+    gl_Position = VCDCMatrix * (gl_in[0].gl_Position + offset.x*base1 + offset.y*base2);
+    EmitVertex();
+  }
 
   EndPrimitive();
 }
-- 
GitLab