Skip to main content

Shader Clip

The clip shader feature: the fragment-stage test that discards the fragments lying on the far side of any client-supplied plane.

Overview

A clip plane cuts a model open. The client names a plane; everything on the far side of it stops being drawn, so the interior becomes visible without anything being rebuilt. Moving the plane is a uniform update, not a change to geometry.

A plane is the four numbers of a plane equation — the unit normal in xyz, the signed offset in w — and a fragment survives when it is on the near side of every plane bound. One plane is a single cut, two facing planes a slab, six a box; the feature applies whatever set is bound and names none of those shapes. Binding no planes keeps everything, which is how clipping is turned off without a second shader.

This package is the declaration of that feature: the Slang that performs the test, a Python mirror of the same arithmetic, and the ShaderDefinition and uniform specs saying what a build step must bind for it to work. It computes nothing at import and draws nothing at runtime. Building a shader from the declaration, and running it, belong elsewhere.

Installation

pip install vcti-shader-clip

In requirements.txt

vcti-shader-clip>=1.0.0

In pyproject.toml dependencies

dependencies = [
    "vcti-shader-clip>=1.0.0",
]

Quick Start

Build a plane, and ask what it keeps:

from vcti.shader.clip import clip_keeps, plane_through

# The normal points into the half that survives, so this keeps z >= 0.
cut = plane_through(point=(0.0, 0.0, 0.0), normal=(0.0, 0.0, 1.0))

assert clip_keeps((0.0, 0.0, 5.0), [cut])
assert not clip_keeps((0.0, 0.0, -5.0), [cut])

# A point exactly on the plane is kept: the comparison is >= 0.
assert clip_keeps((0.0, 0.0, 0.0), [cut])

Two facing planes are a slab, and no planes at all keep everything:

slab = [
    plane_through((0.0, 0.0, -1.0), (0.0, 0.0, 1.0)),
    plane_through((0.0, 0.0, 1.0), (0.0, 0.0, -1.0)),
]
assert clip_keeps((0.0, 0.0, 0.5), slab)
assert not clip_keeps((0.0, 0.0, 9.0), slab)

assert clip_keeps((0.0, 0.0, 9.0), [])

What a build step binds, and the values to bind:

from vcti.shader.clip import DEFINITION, clip_uniforms, fragment_uniforms

assert DEFINITION.id == "clip"
assert [spec.name for spec in fragment_uniforms()] == ["u_clipPlanes", "u_clipPlaneCount"]

uniforms = clip_uniforms(slab)
assert uniforms["u_clipPlaneCount"] == 2
assert len(uniforms["u_clipPlanes"]) == 6  # padded to the declared length

In a composed fragment stage, the Slang side is one line. The module exports a predicate; the layer composing features emits the discard, which is what lets it place the test ahead of shading work a discard would waste:

if (!clipKeeps(position, u_clipPlanes, u_clipPlaneCount)) { discard; }

The one obligation a client can miss: the planes must be expressed in whatever space position arrives in. Binding world-space planes against eye-space positions produces a picture that looks plausible and cuts in the wrong place. See docs/design.md.


Key API

Name What it is
DEFINITION The ShaderDefinition — id clip, fragment stage, capability clip
MAX_PLANES The fixed length of the uniform array — six, because six planes is a box
SLANG_DIR Where clip.slang installed, for the compiler's import search path
fragment_uniforms() The two UniformSpecs a build step binds
Plane A plane as (nx, ny, nz, offset), with .normal and .flipped()
plane_through(point, normal) A plane through point, normal normalized
clip_keeps(point, planes) Whether point survives them all — the CPU mirror
plane_distance(plane, point) The signed distance; positive on the surviving side
check_plane / check_planes The bind-time validation the shader does not do
clip_uniforms(planes) The two uniform values, padded and validated

Dependencies

vcti-shader-base — the zero-dependency ShaderDefinition, StageRole and UniformSpec types — and nothing else at runtime. Declaring a feature is pure data.

vcti-shader-compiler and numpy are test-only: the suite compiles and runs the shader to diff it against the Python mirror, but declaring the feature needs neither.


Documentation

If you want to… Read
Understand the architecture and design decisions docs/design.md
See practical, real-world usage docs/patterns.md
Navigate and understand the source docs/source-guide.md

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

vcti_shader_clip-1.0.0.tar.gz (40.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

vcti_shader_clip-1.0.0-py3-none-any.whl (15.3 kB view details)

Uploaded Python 3

File details

Details for the file vcti_shader_clip-1.0.0.tar.gz.

File metadata

  • Download URL: vcti_shader_clip-1.0.0.tar.gz
  • Upload date:
  • Size: 40.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for vcti_shader_clip-1.0.0.tar.gz
Algorithm Hash digest
SHA256 3950b1cba1b026365ef598661818c60fb7ee565babc62a9295bc8f420d855127
MD5 9478eb40b5401779e9bd867796470119
BLAKE2b-256 235e05a7fd22cebebaefb5c75f339f368171e1d6a80585bcf29a418201e60b17

See more details on using hashes here.

Provenance

The following attestation bundles were made for vcti_shader_clip-1.0.0.tar.gz:

Publisher: release.yml on vcollab/vcti-python-shader-clip

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file vcti_shader_clip-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for vcti_shader_clip-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b69a92bd71f333be8ec153ce7c2a052d9166f3baea0d06a377dac37c61bffb5a
MD5 f2c34733068b497e3286f483ff9add80
BLAKE2b-256 b6e28779ab16934fe6afe4e2be1bc04241e14251e048bc3416cbc09a7491c48f

See more details on using hashes here.

Provenance

The following attestation bundles were made for vcti_shader_clip-1.0.0-py3-none-any.whl:

Publisher: release.yml on vcollab/vcti-python-shader-clip

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 files

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