# vtkSlang: typed shader customization for VTK’s WebGPU backend

**URL:** <https://discourse.vtk.org/t/vtkslang-typed-shader-customization-for-vtk-s-webgpu-backend/16586>\
**Category:** Development\
**Created:** [November 4, 2026, 3:58am UTC](https://discourse.vtk.org/t/vtkslang-typed-shader-customization-for-vtk-s-webgpu-backend/16586 "2026-11-04T03:58:42Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![sankhesh](https://discourse.vtk.org/user_avatar/discourse.vtk.org/sankhesh/32/73_2.png) [@sankhesh](https://discourse.vtk.org/u/sankhesh)\
**Post date:** [November 4, 2026, 3:58am UTC](https://discourse.vtk.org/t/vtkslang-typed-shader-customization-for-vtk-s-webgpu-backend/16586/1 "2026-11-04T03:58:42Z")

</div>

Hi all,

I’d like to introduce [vtkSlang](https://github.com/sankhesh/vtkSlang), a library for typed shader customization in WebGPU renderers. Write a Slang type, select it by name, and let the compiler check the contract.

VTK’s OpenGL backend supports shader customization through string replacements at tags such as `//VTK::Color::Impl`. These are flexible, but a mistyped tag can silently do nothing, available variables depend on mapper state, and compilation errors point into generated GLSL. vtkSlang gives customization points explicit interfaces and reports invalid implementations in the supplied module.

I’m proposing its integration into VTK’s WebGPU backend and would love your feedback on the architecture.

**Give your actor some stripes**

```cpp
prop->SetSlangModule(R"(
  module my_hooks;
  import vtkslang_hooks;
  public struct Stripes : IShaderHooks {
    float3 tint;
    public override void color(inout FragmentContext f) {
      if (frac(f.positionVC.y * 4.f) > 0.5f)
        f.diffuseColor = tint;
    }
  };)");
prop->SetSlangSpecialization("IShaderHooks", "Stripes");

const float rgb[3] = { 0.08f, 0.65f, 0.90f };
prop->GetFragmentCustomUniforms()->SetUniform3f("hooks.tint", rgb);

```

 ![stripes-comparison](https://discourse.vtk.org/uploads/default/original/2X/7/733837d4f2483d82d8fb261fb214581944a52bf1.jpeg)

_Same geometry, camera and lighting. Default shading on the left; the `Stripes` hook with a blue tint on the right._

Rename `color` to `colour`, and the compiler points straight to the invalid override:

```cpp
error[E30854]: 'colour' marked as 'override' is not overriding any base declarations
 --> vtkslang-embedded:/my_hooks.slang:6:26
  |
6 | public override void colour(inout FragmentContext f) {
  | ^^^^^^ 'colour' marked as 'override' is not overriding any base declarations

```

That’s line 6, column 26 in the supplied module. One less mystery to hunt through generated shader code.

Hooks handle small adjustments; interfaces such as `IMaterial` and `ILightingModel` replace entire stages. Fields become named parameters, and `[Range]` and `[Label]` attributes supply metadata for UI controls.

**Three pieces, clear responsibilities**

- **vtkSlang** is a BSD-3-Clause C++17 library, currently at 0.1.0. It owns the shared shader interfaces and shading sequence, compilation, reflection and parameter packing. It makes no WebGPU calls.
- **`VTK::RenderingSlang`** wraps it through `vtkSlangShaderManager`, with `VTK::CommonCore` as its VTK dependency. It builds a stub when `VTK_USE_SLANG` is off.
- **`VTK::RenderingWebGPU`** owns VTK’s shader programs, binding policy and GPU objects.

The separate library also serves [anari-webgpu](https://github.com/sankhesh/anari-webgpu), allowing compatible materials and hooks to travel between renderers. Sharing the parameter packer has already fixed a matrix-layout bug in that integration.

The [architecture document](https://github.com/sankhesh/vtkSlang/blob/main/ARCHITECTURE.md) covers the interfaces, runtime flow, binding layout and API changes. Feedback on the design is welcome, and thanks to everyone who has helped shape it so far!

Sankhesh

---

<div class="post-metadata">

**Author:** ![Louis\_Gombert](https://discourse.vtk.org/user_avatar/discourse.vtk.org/louis_gombert/32/7766_2.png) [@Louis\_Gombert](https://discourse.vtk.org/u/Louis_Gombert)\
**Post date:** [November 4, 2026, 9:04am UTC](https://discourse.vtk.org/t/vtkslang-typed-shader-customization-for-vtk-s-webgpu-backend/16586/2 "2026-11-04T09:04:48Z")

</div>

Hi Sakhesh, this is a really cool project, I love to see a solution to replace string replacement in shaders. Could it also help long term to share more code between the OpenGL and WebGPU rendering back-ends?
