Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pyrender OffScreen set Alpha channel get only 3 channels output #209

Open
lucasjinreal opened this issue Jan 8, 2022 · 2 comments · May be fixed by #218
Open

pyrender OffScreen set Alpha channel get only 3 channels output #209

lucasjinreal opened this issue Jan 8, 2022 · 2 comments · May be fixed by #218

Comments

@lucasjinreal
Copy link

I have tested serveral script, all others are normal, except on program, somehow I set RenderFlags to RGBA, and set scence background color to 4 channels, but get returned result were 3 channels without Alpha.

Part of code:

def render(self, img, verts, cam, angle=None, axis=None, mesh_filename=None, color=[1.0, 1.0, 0.9], rotate=False):
        mesh = trimesh.Trimesh(vertices=verts, faces=self.faces, process=False)

        Rx = trimesh.transformations.rotation_matrix(
            math.radians(180), [1, 0, 0])
        mesh.apply_transform(Rx)

        if rotate:
            rot = trimesh.transformations.rotation_matrix(
                np.radians(60), [0, 1, 0])
            mesh.apply_transform(rot)

        if angle and axis:
            R = trimesh.transformations.rotation_matrix(
                math.radians(angle), axis)
            mesh.apply_transform(R)

        if mesh_filename is not None:
            mesh.export(mesh_filename)

        sx, sy, tx, ty = cam

        camera = WeakPerspectiveCamera(
            scale=[sx, sy],
            translation=[tx, ty],
            zfar=1000.
        )

        material = pyrender.MetallicRoughnessMaterial(
            metallicFactor=0.0,
            alphaMode='OPAQUE',
            smooth=True,
            wireframe=True,
            roughnessFactor=1.0,
            emissiveFactor=(0.1, 0.1, 0.1),
            baseColorFactor=(color[0], color[1], color[2], 1.0)
        )

        mesh = pyrender.Mesh.from_trimesh(mesh, material=material)
        mesh_node = self.scene.add(mesh, 'mesh')

        camera_pose = np.eye(4)
        cam_node = self.scene.add(camera, pose=camera_pose)

        if self.wireframe:
            render_flags = RenderFlags.RGBA | RenderFlags.ALL_WIREFRAME
        else:
            render_flags = RenderFlags.RGBA
        print(render_flags)
        rgb, _ = self.renderer.render(self.scene, flags=render_flags)
        print('rended rgb: ', rgb.shape)
        cv2.imshow('aa', rgb)
        cv2.waitKey(0)
        valid_mask = (rgb[:, :, -1] > 0)[:, :, np.newaxis]
        output_img = rgb[:, :, :-1] * valid_mask + (1 - valid_mask) * img
        image = output_img.astype(np.uint8)

log out:

rended rgb:  (1920, 1080, 3)

this is really so weired, it should be rended rgb: (1920, 1080, 4)

@shubham-goel
Copy link

I’m running into the same issue!

eyllanesc added a commit to eyllanesc/pyrender that referenced this issue Mar 19, 2022
@eyllanesc eyllanesc linked a pull request Mar 19, 2022 that will close this issue
@alon-ne
Copy link

alon-ne commented Apr 5, 2022

I also have this issue

charisoudis added a commit to charisoudis/pyrender that referenced this issue Jan 4, 2024
alessiocancian added a commit to alessiocancian/pyrender that referenced this issue Mar 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants