Files

40 lines
1.3 KiB
Python

import os
os.environ.setdefault("PYOPENGL_PLATFORM", "egl")
import numpy as np
import pyrender
from cxn.render_utils import add_default_lights
# The four directional light intensities defined in add_default_lights.
BASE_INTENSITIES = [12.0, 6.0, 8.0, 3.0]
def _make_scene(ambient=0.5):
return pyrender.Scene(ambient_light=np.array([ambient, ambient, ambient], dtype=float))
def test_default_scale_is_unchanged():
scene = _make_scene(ambient=0.5)
add_default_lights(scene) # default intensity_scale=1.0
intensities = sorted(light.intensity for light in scene.lights)
assert intensities == sorted(BASE_INTENSITIES)
assert np.allclose(scene.ambient_light, [0.5, 0.5, 0.5])
assert len(scene.lights) == 4
def test_scale_two_doubles_lights_and_ambient():
scene = _make_scene(ambient=0.5)
add_default_lights(scene, 2.0)
intensities = sorted(light.intensity for light in scene.lights)
assert intensities == sorted(v * 2.0 for v in BASE_INTENSITIES)
assert np.allclose(scene.ambient_light, [1.0, 1.0, 1.0])
def test_scale_zero_is_fully_black():
scene = _make_scene(ambient=0.5)
add_default_lights(scene, 0.0)
assert all(light.intensity == 0.0 for light in scene.lights)
assert np.allclose(scene.ambient_light, [0.0, 0.0, 0.0])