# vtkPointGaussianMapper with Shader replacement

**URL:** https://discourse.vtk.org/t/vtkpointgaussianmapper-with-shader-replacement/16438
**Category:** Development
**Tags:** code
**Created:** [May 28, 2026, 8:00am UTC](https://discourse.vtk.org/t/vtkpointgaussianmapper-with-shader-replacement/16438 "2026-05-28T08:00:28Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Sandipan](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/s/7cd45c/32.png) [@Sandipan](https://discourse.vtk.org/u/Sandipan)
#### Post date: [May 28, 2026, 8:00am UTC](https://discourse.vtk.org/t/vtkpointgaussianmapper-with-shader-replacement/16438/1 "2026-05-28T08:00:28Z")

</div>

am using ActiViz / VTK 9.5 in a .NET desktop application for large point-cloud visualization. I am trying to implement fast class visibility toggling for LAS-style classification data.

Current data model:

- vtkPolyData

- vtkPointGaussianMapper

- point arrays:

- display modes: Classification, RGB, Elevation, Intensity

The goal is to toggle visibility by class without rebuilding a per-point visibility mask for large datasets.

**What Works**

This works visually, but appears to take time on large datasets because VTK likely remaps opacity per point:

mapper.SetOpacityArray(“Classification”)

mapper.SetOpacityArrayComponent(0)

mapper.SetOpacityTableSize(256)

Dim pwf = vtkPiecewiseFunction.[New]()

pwf.ClampingOn()

For i = 0 To 255

```
Dim alpha As Double = If(classVisible(i), 1.0, 0.0)

pwf.AddPoint(CDbl(i), alpha)

```

Next

mapper.SetScalarOpacityFunction(pwf)

Dim mi = mapper.GetType().GetMethod(“SetUseOpacityArray”)

If mi IsNot Nothing Then mi.Invoke(mapper, New Object() {True})

This correctly preserves RGB/elevation/intensity coloring while using Classification as opacity. However, with large datasets, class toggling is not instant.

**Attempt 1: Classification LUT Alpha**

This worked only when display mode was Classification:

Dim lut = vtkLookupTable.[New]()

lut.SetNumberOfTableValues(256)

lut.SetTableRange(0.0, 255.0)

lut.Build()

For cid = 0 To 255

```
Dim alpha = If(classVisible(cid), 1.0, 0.0)

lut.SetTableValue(cid, r, g, b, alpha)

```

Next

mapper.SetScalarModeToUsePointFieldData()

mapper.SetColorModeToMapScalars()

mapper.ColorByArrayComponent(“Classification”, 0)

mapper.SetLookupTable(lut)

This does not help RGB/elevation/intensity modes because color scalar is no longer Classification.

**Attempt 2: Shader Replacement**

I tried mapping Classification as a vertex attribute and using a fragment shader uniform table:

mapper.MapDataArrayToVertexAttribute(

```
"aplcClassAttr",

"Classification",

vtkDataObject.FieldAssociations.FIELD_ASSOCIATION_POINTS,

-1)

```

Dim sp = actor.GetShaderProperty()

sp.AddVertexShaderReplacement(“//VTK::System::Dec”, False,

"in float aplcClassAttr;

out float aplcClassId;", False)

sp.AddVertexShaderReplacement(“//VTK::Normal::Impl”, False,

" aplcClassId = aplcClassAttr;", False)

sp.AddFragmentShaderReplacement(“//VTK::System::Dec”, False,

"in float aplcClassId;

uniform int uAplcClassVisEnabled;

uniform float uAplcClassVis[256];", False)

sp.AddFragmentShaderReplacement(“//VTK::Color::Impl”, False,

" if (uAplcClassVisEnabled != 0) {

```
int cid = int(clamp(floor(aplcClassId + 0.5), 0.0, 255.0));

if (uAplcClassVis\[cid\] < 0.5) { discard; }

```

}", False)

Uniform upload:

Dim values(255) As Single

For i = 0 To 255

```
values(i) = If(classVisible(i), 1.0F, 0.0F)

```

Next

Dim handle = GCHandle.Alloc(values, GCHandleType.Pinned)

Try

```
Dim fu = sp.GetFragmentCustomUniforms()

fu.SetUniformi("uAplcClassVisEnabled", 1)

fu.SetUniform1fv("uAplcClassVis", values.Length, handle.AddrOfPinnedObject())

fu.Modified()

sp.Modified()

```

Finally

```
handle.Free()

```

End Try

This compiles, but the render view becomes blank.

---

<div class="post-metadata">

### Author: ![lgivord](https://discourse.vtk.org/user_avatar/discourse.vtk.org/lgivord/32/3543_2.png) [@lgivord](https://discourse.vtk.org/u/lgivord)
#### Post date: [May 28, 2026, 8:31am UTC](https://discourse.vtk.org/t/vtkpointgaussianmapper-with-shader-replacement/16438/2 "2026-05-28T08:31:39Z")

</div>

FYI @LucasGandel
