-
Notifications
You must be signed in to change notification settings - Fork 185
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TEST: updated tests for
material
and shader
- Loading branch information
Showing
2 changed files
with
67 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import numpy as np | ||
from pygfx import Mesh | ||
from pygfx.renderers.wgpu import register_wgpu_render_function | ||
from tests.renderers.test_shader_composer import LocalBaseShader | ||
|
||
from fury.actor import sphere | ||
from fury.io import load_wgsl | ||
from fury.material import MeshBasicMaterial | ||
from fury.shader import MeshBasicShader, MeshPhongShader | ||
|
||
|
||
def test_shader(): | ||
|
||
class CustomBasicMaterial(MeshBasicMaterial): | ||
def __init__(self, **kwargs): | ||
super().__init__(**kwargs) | ||
|
||
class CustomPhongMaterial(MeshBasicMaterial): | ||
def __init__(self, **kwargs): | ||
super().__init__(**kwargs) | ||
|
||
register_wgpu_render_function(Mesh, CustomBasicMaterial)(MeshBasicShader) | ||
register_wgpu_render_function(Mesh, CustomPhongMaterial)(MeshPhongShader) | ||
|
||
try: | ||
register_wgpu_render_function(Mesh, CustomBasicMaterial)(MeshBasicShader) | ||
register_wgpu_render_function(Mesh, CustomPhongMaterial)(MeshPhongShader) | ||
except ValueError: | ||
... | ||
else: | ||
raise AssertionError("Shoudn't be able to register the same material twice.") | ||
|
||
|
||
def test_wgsl(): | ||
|
||
shader_code = load_wgsl("mesh.wgsl") | ||
|
||
assert isinstance(shader_code, str) | ||
assert "fn vs_main" in shader_code | ||
assert "fn fs_main" in shader_code | ||
|
||
|
||
class CustomShader(LocalBaseShader): | ||
def __init__(self, **kwargs): | ||
super().__init__(**kwargs) | ||
|
||
def get_code(self): | ||
return load_wgsl("mesh.wgsl") | ||
|
||
actor = sphere(centers=np.array([[0, 0, 0]]), colors=np.array([[1, 0, 0]])) | ||
kwargs = { | ||
"blending_code": "placeholder", | ||
"write_pick": True, | ||
"indexer": None, | ||
"used_uv": {"uv": None}, | ||
} | ||
cs = MeshBasicShader(actor) | ||
|
||
|
||
assert isinstance(cs.get_code(), str) | ||
|
||
gen_sh_code = cs.generate_wgsl(**kwargs) | ||
assert isinstance(gen_sh_code, str) | ||
|
||
assert "placeholder" in gen_sh_code |