shaders#

Module: shaders.base#

SHADERS_DIR

str(object='') -> str str(bytes_or_buffer[, encoding[, errors]]) -> str

compose_shader(glsl_code)

Merge GLSL shader code from a list of strings.

import_fury_shader(shader_file)

Import a Fury shader.

load_shader(shader_file)

Load a shader from a file.

load(filename)

Load a Fury shader file.

shader_to_actor(actor, shader_type, *[, ...])

Apply your own substitutions to the shader creation process.

replace_shader_in_actor(actor, shader_type, code)

Set and replace the shader template with a new one.

add_shader_callback(actor, callback, *[, ...])

Add a shader callback to the actor.

shader_apply_effects(window, actor, effects, *)

This applies a specific opengl state (effect) or a list of effects just before the actor's shader is executed.

attribute_to_actor(actor, arr, attr_name, *)

Link a numpy array with vertex attribute.

SHADERS_DIR#

fury.shaders.base.SHADERS_DIR#

str(object=’’) -> str str(bytes_or_buffer[, encoding[, errors]]) -> str

Create a new string object from the given object. If encoding or errors is specified, then the object must expose a data buffer that will be decoded using the given encoding and error handler. Otherwise, returns the result of object.__str__() (if defined) or repr(object). encoding defaults to sys.getdefaultencoding(). errors defaults to ‘strict’.

compose_shader#

fury.shaders.base.compose_shader(glsl_code)[source]#

Merge GLSL shader code from a list of strings.

Parameters:
glsl_codelist of str (code or filenames).
Returns:
codestr

GLSL shader code.

import_fury_shader#

fury.shaders.base.import_fury_shader(shader_file)[source]#

Import a Fury shader.

Parameters:
shader_filestr

Filename of shader. The file must be in the fury/shaders directory and must have the one of the supported extensions specified by the Khronos Group (KhronosGroup/glslang).

Returns:
codestr

GLSL shader code.

load_shader#

fury.shaders.base.load_shader(shader_file)[source]#

Load a shader from a file.

Parameters:
shader_filestr

Full path to a shader file ending with one of the file extensions defined by the Khronos Group (KhronosGroup/glslang).

Returns:
codestr

GLSL shader code.

load#

fury.shaders.base.load(filename)[source]#

Load a Fury shader file.

Load function has been reimplemented as import_fury_shader.

  • deprecated from version: 0.8.1

  • Raises <class ‘fury.deprecator.ExpiredDeprecationError’> as of version: 0.9.0

Parameters:
filenamestr

Filename of the shader file.

Returns:
code: str

Shader code.

shader_to_actor#

fury.shaders.base.shader_to_actor(actor, shader_type, *, impl_code='', decl_code='', block='valuepass', keep_default=True, replace_first=True, replace_all=False, debug=False)[source]#

Apply your own substitutions to the shader creation process.

A set of string replacements is applied to a shader template. This function let’s apply custom string replacements.

Parameters:
actorvtkActor

Fury actor you want to set the shader code to.

shader_typestr

Shader type: vertex, fragment

impl_codestr, optional

Shader implementation code, should be a string or filename. Default None.

decl_codestr, optional

Shader declaration code, should be a string or filename. Default None.

blockstr, optional

Section name to be replaced. VTK use of heavy string replacements to insert shader and make it flexible. Each section of the shader template have a specific name. For more information: https://vtk.org/Wiki/Shaders_In_VTK. The possible values are: position, normal, light, tcoord, color, clip, camera, prim_id, valuepass. by default valuepass

keep_defaultbool, optional

Keep the default block tag to let VTK replace it with its default behavior. Default True.

replace_firstbool, optional

If True, apply this change before the standard VTK replacements. Default True.

replace_allbool, optional

[description], by default False

debugbool, optional

Introduce a small error to debug shader code. Default False.

replace_shader_in_actor#

fury.shaders.base.replace_shader_in_actor(actor, shader_type, code)[source]#

Set and replace the shader template with a new one.

Parameters:
actorvtkActor

Fury actor you want to set the shader code to.

shader_typestr

Shader type: vertex, geometry, fragment.

codestr

New shader template code.

add_shader_callback#

fury.shaders.base.add_shader_callback(actor, callback, *, priority=0.0)[source]#

Add a shader callback to the actor.

Parameters:
actorvtkActor

Fury actor you want to add the callback to.

callbackcallable

Function or class that contains 3 parameters: caller, event, calldata. This callback will be trigger at each UpdateShaderEvent event.

priorityfloat, optional

Commands with a higher priority are called first.

Returns:
id_observerint

An unsigned Int tag which can be used later to remove the event or retrieve the vtkCommand used in the observer. See more at: https://vtk.org/doc/nightly/html/classvtkObject.html

Examples

add_shader_callback(actor, func_call1)
id_observer = add_shader_callback(actor, func_call2)
actor.GetMapper().RemoveObserver(id_observer)

Priority calls

test_values = []
def callbackLow(_caller, _event, calldata=None):
    program = calldata
    if program is not None:
        test_values.append(0)

def callbackHigh(_caller, _event, calldata=None):
    program = calldata
    if program is not None:
        test_values.append(999)

def callbackMean(_caller, _event, calldata=None):
    program = calldata
    if program is not None:
        test_values.append(500)

fs.add_shader_callback(
        actor, callbackHigh, priority=999)
fs.add_shader_callback(
        actor, callbackLow, priority=0)
id_mean = fs.add_shader_callback(
        actor, callbackMean, priority=500)

showm.start()
# test_values = [999, 500, 0, 999, 500, 0, ...]

shader_apply_effects#

fury.shaders.base.shader_apply_effects(window, actor, effects, *, priority=0)[source]#

This applies a specific opengl state (effect) or a list of effects just before the actor’s shader is executed.

Parameters:
windowRenderWindow

For example, this is provided by the ShowManager.window attribute.

actoractor
effectsa function or a list of functions
priorityfloat, optional

Related with the shader callback command. Effects with a higher priority are applied first and can be override by the others.

Returns:
id_observerint

An unsigned Int tag which can be used later to remove the event or retrieve the vtkCommand used in the observer. See more at: https://vtk.org/doc/nightly/html/classvtkObject.html

attribute_to_actor#

fury.shaders.base.attribute_to_actor(actor, arr, attr_name, *, deep=True)[source]#

Link a numpy array with vertex attribute.

Parameters:
actorvtkActor

Fury actor you want to add the vertex attribute to.

arrndarray

Array to link to vertices.

attr_namestr

Vertex attribute name. The vtk array will take the same name as the attribute.

deepbool, optional

If True a deep copy is applied, otherwise a shallow copy is applied. Default True.