pygfx.renderers.wgpu.BaseShader
- class pygfx.renderers.wgpu.BaseShader(wobject, **template_vars)
Bases:
ShaderInterface
Base shader object to compose and template shaders using jinja2.
Templating variables can be passed kwargs, set(and get) as attributes, or passed as kwargs to
generate_wgsl()
. They should only be set in __init__() and get_bindings_info().The template variables affect the hash. After pipeline.py calls get_bindings_info(), it checks the hash to see if the shader has changed, and recompiles the wgsl if it has.
- get_bindings_info(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_code()
Implement this to compose the total (but still templated) shader. This method is called by
generate_wgsl()
.
- generate_wgsl(**more_template_vars)
Generate the final WGSL. Calls get_code() and then resolves the templating variables, varyings, and depth output.
- define_bindings(bindgroup, bindings_dict)
Define a collection of bindings organized in a dict.
- define_binding(bindgroup, index, binding)
Define a uniform, buffer, sampler, or texture.
The binding must be a Binding object. The code that defines the binding will be inserted in
pygfx.std.wgsl
.
- define_generic_colormap(map, texcoords)
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.For colormaps in mesh, line, points. Supports 1D/2D/3D textures, different texture formats.
- define_img_colormap(map)
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.