This has been a great tool, thanks a lot for providing it. I'm having a minor issue with transparent objects casting shadows darker than I would expect. For example, if I set the opacity to zero, I would expect the object to essentially be invisible, but this isn't what I'm seeing. Below is an example of what I mean, adapted from one of the provided examples.
import numpy as np
from plotoptix import NpOptiX
from plotoptix.enums import Geometry
from plotoptix.materials import m_transparent_diffuse
import threading
import copy
from PIL import Image
class params:
done = threading.Event()
def accum_done(rt: NpOptiX) -> None:
params.done.set()
def main():
rt = NpOptiX(on_rt_accum_done=accum_done, width=1000, height=300)
rt.set_param(min_accumulation_step=500, max_accumulation_frames=500)
# geometry setup
box_size = 1.5
panel_size = 1.0
z = box_size + 0.1 # offset panels a bit in front of boxes
spacing = (box_size - panel_size) / 2
vertices = np.array([[0, 0, z], [0, panel_size, z], [panel_size, panel_size, z], [panel_size, 0, z]], np.float32)
faces = np.array([[0, 1, 2], [2, 3, 0]])
uvmap = np.array([[0, 0], [0, 1], [1, 1], [1, 0]], np.float32)
pos = [[0, 0, 0]] # add a box at origin with no panel in front
# blueish panel in front of boxes with increasing opacity
colors = np.ones((2, 2, 4), dtype=np.float32) * 0.5
colors[:, :, 0] = 0.0
alphas = [0.0, 0.02, 0.1, 0.5]
# add the boxes and panels
for idx, alpha in enumerate(alphas):
colors[:, :, 3] = alpha
rt.set_texture_2d(f"mesh_tex_{idx}", colors)
mat = copy.deepcopy(m_transparent_diffuse)
mat["ColorTextures"] = [f"mesh_tex_{idx}"]
rt.setup_material(f"mesh_mat_{idx}", mat)
x_pos = (idx + 1) * (box_size + spacing)
rt.set_mesh(
f"mesh_{idx}",
pos=vertices + np.array([x_pos + spacing, spacing, 0.0], dtype=np.float32),
faces=faces,
uvmap=uvmap,
mat=f"mesh_mat_{idx}",
)
pos.append([x_pos, 0.0, 0.0])
rt.set_data(
"plot",
geom=Geometry.ParallelepipedsConstSize,
pos=np.array(pos, dtype=np.float32),
r=box_size,
c=0.75
)
rt.set_ambient(0.9)
x_camera = ((len(alphas) + 1) * (box_size + spacing)) / 2
rt.setup_camera(
name="camera1",
eye=[x_camera, box_size / 2, 10.0],
target=[x_camera, box_size / 2, 0],
fov=20
)
rt.start()
if params.done.wait(10):
print("frame 1 done")
else:
print("timeout")
Image.fromarray(np.array(rt._raw_rgba * 255, dtype=np.uint8), mode="RGBA").save("frame_1.png")
params.done.clear()
rt.close()
if __name__ == "__main__":
main()
This has been a great tool, thanks a lot for providing it. I'm having a minor issue with transparent objects casting shadows darker than I would expect. For example, if I set the opacity to zero, I would expect the object to essentially be invisible, but this isn't what I'm seeing. Below is an example of what I mean, adapted from one of the provided examples.