pyrender
pyrender copied to clipboard
Possible to disable lighting (directly render base RGB)?
Hi, thanks for setting up this amazing library!! I was wondering if its possible to render a scene without the need for adding lights. For example, since a mesh has an associated set of face colors and vertex colors, we should be able to directly render those RGB colors.
I noticed that OpenGL supported disabling lighting glDisable(GL_LIGHTING)
; however, I couldn't figure out how to add this functionality to pyrender -- in the even that you don't already support this :)
I think I've figured out the trick:
- turn off all external light sources
- instantiate the scene with white ambient light:
scene = pyrender.Scene(ambient_light=[1., 1., 1.])
- change the
baseColorFactor
of the mesh material to be RGBA white:baseColorFactor=[1., 1., 1., 1.]
Thanks!
Closing this issue. If anyone else has a better solution please let me know!
I think this doesn't solve the problem. If I want to render a mesh with face_colors=[0,200,0], what I get is [0,228,0] (same for vertex_colors).
@mmatl it would be great to have an option to disable PBR since people can use the color to simulate segmentation labels. Also would be great to have an option to disable anti-aliasing for the same purpose.
I think I've figured out the trick:
- turn off all external light sources
- instantiate the scene with white ambient light:
scene = pyrender.Scene(ambient_light=[1., 1., 1.])
- change the
baseColorFactor
of the mesh material to be RGBA white:baseColorFactor=[1., 1., 1., 1.]
Thanks!
Oh, forget about my previous comment. Just notice this post: https://github.com/mmatl/pyrender/issues/15#issuecomment-480400477
Thanks again for this great library.
@simbaforrest do you have a sample of code replicating the problem you see (with [0,200,0] becoming [0,228,0])? The comment in #15 is a solution only in the context of semantic segmentation and would require iterating over the number of objects -- which is certainly not a computationally ideal solution either.
I guess what you need is the albedo pass, which is not implemented in the code.
I am looking for this feature too. :)
@simbaforrest do you have a sample of code replicating the problem you see (with [0,200,0] becoming [0,228,0])? The comment in #15 is a solution only in the context of semantic segmentation and would require iterating over the number of objects -- which is certainly not a computationally ideal solution either.
Sorry, my code is a mess now. But you should be able to try this easily with your own code.
@simbaforrest do you have a sample of code replicating the problem...
Hi, I just came across the same issue @simbaforrest had a while ago. I would like to render a mesh with the exact colors specified in the vertex colors, without any additional lighting etc. Find below a code snippet that shows the problem. In this test I'm coloring all vertices with a constant color (e.g. [10,20,30]). The rendered image shows the object with constant color, but completely different color values. I also played around with the material properties but couldn't find a setting that renders the vertex colors correctly. Maybe I'm using the lighting/material in a wrong way?
#load from trimesh
trimesh_mesh = trimesh.load_mesh(path)
#colorize all vertices with testcolor
for idx in range(len(trimesh_mesh.vertices)):
trimesh_mesh.visual.vertex_colors[idx, :3] = [10, 20, 30]
material = pyrender.MetallicRoughnessMaterial(
baseColorFactor=[1, 1, 1, 1.],
metallicFactor=0.0,
roughnessFactor=0.0,
smooth=False,
alphaMode='OPAQUE')
pyrender_mesh = pyrender.Mesh.from_trimesh(trimesh_mesh, material=material)
camera = pyrender.IntrinsicsCamera(320, 240, 320, 320, znear=1, zfar=1000)
renderer = pyrender.OffscreenRenderer(viewport_width=320, viewport_height=320)
scene = pyrender.Scene(bg_color=np.zeros(4), ambient_light=np.ones(3))
scene.add(pyrender_mesh, pose=np.eye(4))
scene.add(camera, pose=camera_pose)
img, _ = renderer.render(scene)
I encounter the same problems as @markus-sp, also after specifying the face colors as in the case of @simbaforrest. Any news on this issue?
It seems like flat shading, as also referenced in #15, was added a while ago but the documentation wasn't updated. You can enable it using the render flags:
color, depth = r.render(scene, flags=pyrender.constants.RenderFlags.FLAT)
Ideally what would fix this is a new flag that disables GL_MUTLISAMPLE in this line. Althought my quick test on this hasn't completely fixed this problem for me, but its a big step in the right direction. There still seems to be some strange blurring/blending of pixel values at certain points on the model.
still no update on this?
My method is : 1)turn off all external light sources 2) instantiate the scene with white ambient light: scene = pyrender.Scene(ambient_light=[1., 1., 1.]) 3) do not pass Material variable and use color, depth = r.render(scene, flags=pyrender.constants.RenderFlags.FLAT).