mmatl / pyrender

Easy-to-use glTF 2.0-compliant OpenGL renderer for visualization of 3D scenes.
http://pyrender.readthedocs.io/
MIT License
1.31k stars 225 forks source link

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

Open yangwangpku opened 1 year ago

yangwangpku commented 1 year ago

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!