Allows fury to deal with Uniforms in shaders and change them dynamically
An uniform variable should be chosen when we have any kind of information which act as constants, at least during the draw call.
This commit implements the following behaviors: 1 - avoids creating an observable-vtk for each uniform variable 2 - allows the update of an uniform variable dynamically
Here it's a simple example
markerUniforms = [
Uniform(name='edgeColor', type='3f', value=edgeColor),
Uniform(name='edgeWidth', type='f', value=edgeWidth),
Uniform(name='edgeOpacity', type='f', value=edgeOpacity),
Uniform(name='markerOpacity', type='f', value=markerOpacity),
]
CustomUniforms = Uniforms(markerUniforms)
observerId = add_shader_callback(
sq_actor, CustomUniforms)
CustomUniforms.observerId = observerId
sq_actor.CustomUniforms = CustomUniforms
sq_actor.CustomUniforms.edgeWidth = 0.5
Hello @devmessias! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:
- In the file
fury/shaders/__init__.py:
- In the file
fury/shaders/base.py:
Line 207:64: W291 trailing whitespace
Comment last updated at 2021-04-26 23:08:44 UTC
Here is an example of a shader actor with those modifications
# marker billboard from pull #422 using this new Uniform API
nodes_actor = actor.marker_billboard(
centers,
markers=markers,
edgeWidth=edgeWidth,
edgeColor=edgeColor.data,
colors=colors,
scales=.1,
)
scene = window.Scene()
scene.add(nodes_actor)
interactive = True
showm = window.ShowManager(scene,
size=(900, 768), reset_camera=False,
order_transparent=True)
showm.initialize()
counter = itertools.count()
def timer_callback(obj, event):
nodes_actor.CustomUniforms.edgeWidth.value = np.random.choice([0.2, 1, 0.5])
nodes_actor.CustomUniforms.edgeColor.value = np.random.randint(0, 255, size=3)
cnt = next(counter)
showm.render()
if cnt == 100:
showm.exit()
showm.add_timer_callback(True, 200, timer_callback)
showm.start()
Hi @devmessias,
Could you add some unit tests? Also, can you complete the documentation? Last point, can you switch from C/C++ style to python style concerning variable/class names. Global comment for all your PR. Thank you !
Yes, of course! I'll do it.