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

Sphere Rendered with Non-reflective Material Not Appearing Black #266

Open
yangwangpku opened this issue Sep 6, 2023 · 0 comments
Open

Comments

@yangwangpku
Copy link

Description:

I am attempting to render a sphere with a non-reflective black material using pyrender. Despite configuring the material properties to create a non-reflective material (base color factor, metallic factor, and roughness factor), the sphere is not appearing black in the rendered image.

Here is the code snippet that reproduces the issue:

import pyrender
from PIL import Image
import trimesh
import numpy as np

# Create a scene
scene = pyrender.Scene(bg_color=[0.0, 0.0, 0.0, 1.0])

# Create a non-reflective material: black color, no metallic, high roughness
material = pyrender.MetallicRoughnessMaterial(
    baseColorFactor=(0.0, 0.0, 0.0, 1.0),
    metallicFactor=0.0,
    roughnessFactor=1.0
)

# Create a sphere mesh using trimesh
sphere_trimesh = trimesh.creation.icosphere(radius=1.0, subdivisions=3)

# Convert the trimesh object to a pyrender mesh
sphere_mesh = pyrender.Mesh.from_trimesh(sphere_trimesh, material=material)

# Add the mesh to the scene
scene.add(sphere_mesh)

# Create a light source and add it to the scene
light = pyrender.DirectionalLight(color=[1.0, 1.0, 1.0], intensity=10.0)
light_node = pyrender.Node(light=light, translation=[0, 3, -3])
scene.add_node(light_node)


# Create an orthographic camera with the calculated frustum size
camera = pyrender.OrthographicCamera(xmag=1, ymag=1)

# Set up a camera pose to center the mesh in the frame
camera_pose = np.array([
    [1.0, 0.0, 0.0, 0.0],  # Centering the mesh in the x-axis
    [0.0, 1.0, 0.0, 0.0],  # Centering the mesh in the y-axis
    [0.0, 0.0, 1.0, 5.0],  # Placing the camera a reasonable distance away in the z-axis
    [0.0, 0.0, 0.0, 1.0]
])


scene.add(camera, pose=camera_pose)

osmesa = pyrender.OffscreenRenderer(512,512)
color, depth = osmesa.render(scene)

# Save the rendered image
rendered_image = Image.fromarray(color)
rendered_image.save(f'sphere.jpg')

osmesa.delete()

Expected Result:

The sphere should appear black in the rendered image, given the non-reflective material properties (0.0 for base color and metallic factor, and 1.0 for roughness).

Actual Result:

The sphere does not appear black in the rendered image, indicating it is still reflecting some light.
sphere

Environment:

pyrender version: 0.1.45
OS: Linux
trimesh version: 3.23.5

I would appreciate any guidance or suggestions to achieve the desired result. Thank you!

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

No branches or pull requests

1 participant