pygfx.renderers.wgpu.WorldObjectShader

class pygfx.renderers.wgpu.WorldObjectShader(wobject, **kwargs)

Bases: BaseShader

A base shader for world objects. Must be subclassed to implement a shader for a specific material. This class also implements common functions that can be used in all material-specific renderers.

get_bindings(wobject, shared)

Subclasses must return a dict describing the buffers and textures used by this shader.

The result must be a dict of dicts with binding objects (group_slot -> binding_slot -> binding)

get_pipeline_info(wobject, shared)

Subclasses must return a dict describing pipeline details.

Fields for a compute shader: empty

Fields for a render shader:
  • “cull_mode”

  • “primitive_topology”

get_render_info(wobject, shared)

Subclasses must return a dict describing render details.

Fields for a compute shader:
  • “indices” (3 ints)

Fields for a render shader:
  • “render_mask”

  • “indices” (list of 2 or 4 ints).

define_texcoords_and_colormap(texture, texcoords, interpolation='linear')

Define the given texture as the colormap to be used to lookup the final color from the (per-vertex or per-face) texcoords. In the WGSL the colormap can be sampled using sample_colormap(). Returns a list of bindings.

define_img_colormap(texture, interpolation='linear')

Define the given texture view as the colormap to be used to lookup the final color from the image data. In the WGSL the colormap can be sampled using sample_colormap(). Returns a list of bindings.

code_common()

Get the WGSL functions that are pygfx-builtin. These are functions that re used by (about) every WorldObject. More advanced functions, e.g. for lighting calculations, should be loaded from the shaderlib.