Skip to main content

vcti-shader-derive

The derived-value shader feature: the fragment-stage math that reduces a multi-component result to one scalar.

Overview

A CAE solver reports vectors and tensors — a displacement per node, a stress tensor per element. A colormap needs a single number. Turning one into the other is what vcti-shader-derive does, on the GPU, at draw time: given a stress tensor it produces von Mises, or a principal, or the xy component, and the fringe feature colours whatever comes out.

Doing it in the shader rather than ahead of it is the point. The result buffer is uploaded once, and switching from von Mises to max principal, or from one component order to another, sets a uniform — no re-upload, no CPU pass, no rebuilt shader.

The package ships one Slang module per data family:

Family Components What it derives
scalar 1 identity, absolute, unit conversions
vector 3 components, magnitude
dof6 6 translational and rotational components and magnitudes
symtensor 6 components, mean, von Mises, equivalent strain, principals, max shear, intensity, deviatoric principals

Around that math the package declares two things: the specs saying what each family needs supplied — which attributes, which uniforms — and the ShaderDefinition saying what the feature is. Both are plain data. Nothing here compiles or runs a shader; a build step does that, using what this package declares.

The math also exists on the CPU, in vcti-derived, which is where value ranges, legends and exports get the same numbers. Two implementations can disagree, so the test suite runs every dispatch case of every family headlessly on a real GPU — through the compiler's render_readback — and diffs it against the catalog. That is test machinery, and it ships with the source, not with the package.

Installation

pip install vcti-shader-derive

Requires Python 3.12, 3.13, or 3.14, matching vcti-shader-base and vcti-derived. Nothing native is built on that path, and nothing native is built by [test] either — only the [gl] extra pulls a GL binding, and only on 3.14 does that compile from source for want of a cp314 wheel.

In requirements.txt

vcti-shader-derive>=2.1.0

In pyproject.toml dependencies

dependencies = [
    "vcti-shader-derive>=2.1.0",
]

Quick Start

What the feature is

from vcti.shader.derive import DEFINITION

DEFINITION.id, DEFINITION.role.value      # ('derive', 'fragment')
DEFINITION.capabilities                   # ('scalar', 'vector', 'dof6', 'symtensor')
len(DEFINITION.slang_modules)             # 4 — one per family

DEFINITION is built at import, so importing the package is all it takes to have one. Its capabilities are one tag per data family, not one for the feature: a shader over a stress tensor takes different inputs from one over a displacement vector, and the two are not interchangeable, so a build step selects on the family it has data for.

Which derived types a family offers

Every derived type a family can produce is a case of one u_derivedType integer, and the table is built from the vcti-derived catalog rather than listed here:

from vcti.derived import DataFamily
from vcti.shader.derive import build_dispatch_table, default_case, dispatch_case

cases = build_dispatch_table()[DataFamily.SYMTENSOR]
[(c.value, c.name) for c in cases][:4]
# [(0, 'xx'), (1, 'yy'), (2, 'zz'), (3, 'xy')]

dispatch_case(DataFamily.SYMTENSOR, "von_mises").value   # 7 — write this to u_derivedType
default_case(DataFamily.SYMTENSOR).name                  # 'von_mises' — before the user picks

dispatch_case raises listing the family's names if you ask for one it does not have, and default_case returns what the vcti-derived catalog nominates per family — identity, magnitude, translation_magnitude, von_mises — which is what to select when nothing has been chosen yet. A product preferring something else (max principal rather than von Mises, say) overrides it; the catalog's answer is a starting point, not a rule.

Not everything in the catalog is here. A derived type ships as a GPU case only if it produces a scalar and all of its parameters have defaults — so principal directions and traction vectors are absent, because there is nothing to colour and a plane normal is field data rather than a uniform.

Take the value from the table, never from a literal. A u_derivedType that names no case returns NaN, which fringe colours with u_nanColor — chosen so a stale or miscomputed selector shows up instead of quietly rendering some other quantity.

These integers are a wire contract. They are compiled into the switch in each .slang, written into built shaders, and stored by whatever selected one, so they are append-only. The value is vcti-derived's dispatch_id, declared upstream and read here rather than assigned, so a catalog reordering renumbers nothing; tests/test_dispatch.py pins the whole table as a cross-check that the declared values still match the Slang this package ships.

What its math needs supplied

Pick a family, and the specs follow from it:

from vcti.shader.derive import (
    component_order_uniform, derived_type_uniform, parameter_uniforms, result_attributes,
)

[(a.name, a.type, a.semantic) for a in result_attributes(DataFamily.SYMTENSOR)]
# [('a_result0', 'vec3', 'result.0'), ('a_result1', 'vec3', 'result.1')]

component_order_uniform(DataFamily.SYMTENSOR).gl_type          # 'int[6]'
derived_type_uniform({c.name: c.value for c in cases}).name      # 'u_derivedType'
[u.name for u in parameter_uniforms(p for c in cases for p in c.parameters)]
# ['u_nu'] — equivalent strain's Poisson ratio, the family's one parameter

Three things are worth knowing about that.

Results arrive packed. Multi-component data goes into vec3 attributes — ceil(n / 3) of them, zero-padded — because a vertex attribute is at most four components wide and a six-component tensor does not fit in one. The scalar family is the exception and uses a single float.

Component order is a uniform, not a repack. u_componentOrder maps each canonical slot to the lane the host actually packed it into, mirroring vcti-derived's ComponentOrder. A solver that writes (xx, xy, yy, …) is drawn by setting six integers rather than by rewriting the buffer.

Parameters are uniforms too. A defaultable parameter — equivalent strain's nu, an affine conversion's scale and offset — becomes u_<name>, so the derived type stays one dispatch case instead of one shader per value.

Seed every uniform, then override

An unset uniform is not an error in GL: it reads as zero, and zero is a plausible answer nearly everywhere here. u_nu at 0 turns equivalent strain into von Mises exactly; an all-zero u_componentOrder reads every canonical slot from lane 0, so a tensor reads xx six times. Neither raises, and neither looks wrong on screen.

So bind this first and override what the user actually chose:

from vcti.shader.derive import uniform_defaults

uniform_defaults(DataFamily.SYMTENSOR)
# {'u_derivedType': 7, 'u_componentOrder': (0, 1, 2, 3, 4, 5), 'u_nu': 0.5}

uniform_defaults(DataFamily.SCALAR)
# {'u_derivedType': 0, 'u_scale': 1.0, 'u_offset': 0.0}

That is the family's default derived type, the identity component order, and every parameter at its catalog default — enough to draw a correct picture without choosing anything. The component order is the one to replace as soon as you know the buffer's real layout.

Building a shader from it

This package does not compile anything, so the last step belongs to a build step:

# 1. Give the compiler somewhere to resolve `import derive_symtensor;` from.
include_dirs = [DEFINITION.slang_dir]

# 2. Declare what this feature's math reads.
attributes = result_attributes(DataFamily.SYMTENSOR)

Step 2 is half of the interface. A complete shader also carries the vertex-stage feature's attributes — a_position, and a_deformation if it deforms — which come from that feature's builders, because a feature never imports another feature. Merging the two lists, and dropping whatever both declare, is the build step's job.

slang_dir is the field with teeth: the .slang files install inside this package, so only this package can resolve where they are.


Dependencies

  • vcti-shader-base — the zero-dependency vocabulary this feature declares itself with (ShaderDefinition, StageRole, AttributeSpec, UniformSpec).
  • vcti-derived — the catalog of derived fields. Unlike its sibling features, derive cannot describe itself without a second dependency: the dispatch table, the capability tags and the contract builders are all read off the catalog at import. The feature is a mirror of that catalog's GPU-supported subset, and the dependency is what keeps the mirror from drifting.

The rest are test-only — needed to run the shader, not to declare the feature, and split across two extras:

  • [test] — vcti-shader-compiler>=3.0, whose render_readback the suite drives to run the emitted math headlessly. The test module imports the compiler at module scope, so without it the tests fail to collect rather than skip — which is why it sits here and not under [gl].
  • [gl] — vcti-shader-compiler[gl], the GL binding that makes the probes actually run. Every shader package defines a gl extra meaning "what I need to execute shaders"; ci-shader.yml installs .[test,gl] on that contract.

Without [gl] the probe tests skip and everything else passes, which is the right default: compiling a GL binding is a cost only the machines that run shaders should pay.

Nothing that combines or discovers features: this package describes one feature and stops there. Choosing which features go into a shader, and finding them, belong to a build step. (Choosing a derived type within this feature is different, and is what dispatch_case and default_case are for.)


Documentation

If you want to… Read
Get started using the package Quick Start above
Understand the derived-value model and the design decisions docs/design.md
Navigate or modify the source, including the Slang docs/source-guide.md

The full API reference is generated from the source docstrings and published in the unified VCollab docs.

Metadata

Release files for vcti-shader-derive 2.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for vcti-shader-derive 2.1.0
File Size Uploaded Provenance Actions
vcti_shader_derive-2.1.0.tar.gz 54.0 kB With provenance Details for vcti_shader_derive-2.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for vcti-shader-derive 2.1.0
File Interpreter ABI Platform Actions
vcti_shader_derive-2.1.0-py3-none-any.whl Python 3 none any Details for vcti_shader_derive-2.1.0-py3-none-any.whl

Total release size: 79.6 kB

Release files / vcti_shader_derive-2.1.0.tar.gz

Download URL vcti_shader_derive-2.1.0.tar.gz
Size 54.0 kB
Tags Source
SHA-256 checksum
How to use checksums
2e1b9130076b5396ececea56d393d84ced8f2a2f7b693c2567d08963754feb83
BLAKE2b-256 checksum
How to use checksums
f283981da8913e28fb643b5b8c65d5e1ce22813b0277efcb05249874edcf6abc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 7, 2026.

Transparency log

Release files / vcti_shader_derive-2.1.0-py3-none-any.whl

Download URL vcti_shader_derive-2.1.0-py3-none-any.whl
Size 25.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8f94deebc5e72db36a5ad49b378230328707a4411b82869bb36e0e5a3face1e4
BLAKE2b-256 checksum
How to use checksums
7a8bbbe1e4de2bc84159f762dfb9e421274ac7d7917d3fb67439ad2fd1a07bda
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 7, 2026.

Transparency log

Security for vcti-shader-derive 2.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for vcti_shader_derive-2.1.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 7, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page