Пример #1
0
def test_primitive_color_mix(scene_hex_sphere_, generate=False):
    """Test the primitive_color_mix property."""
    geometry = scene_hex_sphere_.geometry[0]
    geometry.material = fresnel.material.Material(solid=1.0,
                                                  color=fresnel.color.linear(
                                                      [1, 0, 0]),
                                                  primitive_color_mix=1.0)

    geometry.color[0] = fresnel.color.linear([1, 0, 0])
    geometry.color[1] = fresnel.color.linear([0, 1, 0])
    geometry.color[2] = fresnel.color.linear([0, 0, 1])
    geometry.color[3] = fresnel.color.linear([1, 0, 1])
    geometry.color[4] = fresnel.color.linear([0, 1, 1])
    geometry.color[5] = fresnel.color.linear([0, 0, 0])

    buf_proxy = fresnel.preview(scene_hex_sphere_,
                                w=100,
                                h=100,
                                anti_alias=False)

    if generate:
        PIL.Image.fromarray(buf_proxy[:], mode='RGBA').save(
            open('output/test_material.test_primitive_color_mix.png', 'wb'),
            'png')
    else:
        conftest.assert_image_approx_equal(
            buf_proxy[:], dir_path / 'reference' /
            'test_material.test_primitive_color_mix.png')
Пример #2
0
def test_camera(scene_hex_sphere_, generate=False):
    """Test the camera property."""
    scene_hex_sphere_.camera = fresnel.camera.Orthographic(position=(1, 0, 10),
                                                           look_at=(1, 0, 0),
                                                           up=(0, 1, 0),
                                                           height=6)

    numpy.testing.assert_array_equal(scene_hex_sphere_.camera.position,
                                     (1, 0, 10))
    numpy.testing.assert_array_equal(scene_hex_sphere_.camera.look_at,
                                     (1, 0, 0))
    numpy.testing.assert_array_equal(scene_hex_sphere_.camera.up, (0, 1, 0))
    assert scene_hex_sphere_.camera.height == 6

    buf_proxy = fresnel.preview(scene_hex_sphere_,
                                w=100,
                                h=100,
                                anti_alias=False)

    if generate:
        PIL.Image.fromarray(buf_proxy[:], mode='RGBA').save(
            open('output/test_scene.test_camera.png', 'wb'), 'png')
    else:
        conftest.assert_image_approx_equal(
            buf_proxy[:],
            dir_path / 'reference' / 'test_scene.test_camera.png')
Пример #3
0
def test_multiple(scene_tetrahedra_, generate=False):
    buf_proxy = fresnel.preview(scene_tetrahedra_, w=100, h=100)

    if generate:
        PIL.Image.fromarray(buf_proxy[:], mode='RGBA').save(
            open('output/test_geometry_mesh.test_multiple.png', 'wb'), 'png')
    else:
        conftest.assert_image_approx_equal(
            buf_proxy[:], 'reference/test_geometry_mesh.test_multiple.png')
Пример #4
0
def test_render(scene_four_spheres_, generate=False):
    buf_proxy = fresnel.preview(scene_four_spheres_, w=150, h=100)

    if generate:
        PIL.Image.fromarray(buf_proxy[:], mode='RGBA').save(
            open('output/test_geometry_sphere.test_render.png', 'wb'), 'png')
    else:
        conftest.assert_image_approx_equal(
            buf_proxy[:], 'reference/test_geometry_sphere.test_render.png')
Пример #5
0
def test_color(scene_hex_sphere_, generate=False):
    geometry = scene_hex_sphere_.geometry[0]
    geometry.material.color = fresnel.color.linear([0,0,1])
    assert geometry.material.color == tuple(fresnel.color.linear([0,0,1]))

    buf_proxy = fresnel.preview(scene_hex_sphere_, w=100, h=100)

    if generate:
        PIL.Image.fromarray(buf_proxy[:], mode='RGBA').save(open('output/test_material.test_color.png', 'wb'), 'png');
    else:
        conftest.assert_image_approx_equal(buf_proxy[:], 'reference/test_material.test_color.png')
Пример #6
0
def test_metal(scene_hex_sphere_, generate=False):
    geometry = scene_hex_sphere_.geometry[0]
    geometry.material.metal = 1.0
    assert geometry.material.metal == 1.0

    buf_proxy = fresnel.preview(scene_hex_sphere_, w=100, h=100)

    if generate:
        PIL.Image.fromarray(buf_proxy[:], mode='RGBA').save(open('output/test_material.test_metal.png', 'wb'), 'png');
    else:
        conftest.assert_image_approx_equal(buf_proxy[:], 'reference/test_material.test_metal.png')
Пример #7
0
def test_render(scene_box_, generate=False):
    """Test that Box renders properly."""
    buf_proxy = fresnel.preview(scene_box_, w=150, h=100, anti_alias=False)

    if generate:
        PIL.Image.fromarray(buf_proxy[:], mode="RGBA").save(
            open("output/test_geometry_box.test_render.png", "wb"), "png")
    else:
        conftest.assert_image_approx_equal(
            buf_proxy[:],
            dir_path / "reference" / "test_geometry_box.test_render.png")
Пример #8
0
def test_outline(scene_one_triangle_, generate=False):
    geometry = scene_one_triangle_.geometry[0]
    geometry.outline_width = 0.1

    buf_proxy = fresnel.preview(scene_one_triangle_, w=100, h=100)

    if generate:
        PIL.Image.fromarray(buf_proxy[:], mode='RGBA').save(
            open('output/test_geometry_mesh.test_outline.png', 'wb'), 'png')
    else:
        conftest.assert_image_approx_equal(
            buf_proxy[:], 'reference/test_geometry_mesh.test_outline.png')
Пример #9
0
def test_light_dir(scene_hex_sphere_, generate=False):
    scene_hex_sphere_.lights[0].direction = (1, 0, 0)
    scene_hex_sphere_.lights[0].color = (0.5, 0.5, 0.5)
    assert scene_hex_sphere_.lights[0].direction == (1, 0, 0)
    assert scene_hex_sphere_.lights[0].color == (0.5, 0.5, 0.5)

    buf_proxy = fresnel.preview(scene_hex_sphere_, w=100, h=100)

    if generate:
        PIL.Image.fromarray(buf_proxy[:], mode='RGBA').save(open('output/test_scene.test_light_dir.png', 'wb'), 'png');
    else:
        conftest.assert_image_approx_equal(buf_proxy[:], 'reference/test_scene.test_light_dir.png')
Пример #10
0
def test_rounded(scene_rounded_polygons_, generate=False):
    geometry = scene_rounded_polygons_.geometry[0]
    geometry.outline_width = 0.1

    buf_proxy = fresnel.preview(scene_rounded_polygons_, w=150, h=100)

    if generate:
        PIL.Image.fromarray(buf_proxy[:], mode='RGBA').save(
            open('output/test_geometry_polygon.test_rounded.png', 'wb'), 'png')
    else:
        conftest.assert_image_approx_equal(
            buf_proxy[:], 'reference/test_geometry_polygon.test_rounded.png')
Пример #11
0
def test_color_interp(scene_one_triangle_, generate=False):
    geometry = scene_one_triangle_.geometry[0]
    geometry.material.primitive_color_mix = 1.0

    buf_proxy = fresnel.preview(scene_one_triangle_, w=100, h=100)

    if generate:
        PIL.Image.fromarray(buf_proxy[:], mode='RGBA').save(
            open('output/test_geometry_mesh.test_color_interp.png', 'wb'),
            'png')
    else:
        conftest.assert_image_approx_equal(
            buf_proxy[:], 'reference/test_geometry_mesh.test_color_interp.png')
Пример #12
0
def test_set_material(scene_hex_sphere_, generate=False):
    geometry = scene_hex_sphere_.geometry[0]
    geometry.material = fresnel.material.Material(solid=0.0, color=fresnel.color.linear([1,0,0]), primitive_color_mix=0.0)
    assert geometry.material.solid == 0.0
    assert geometry.material.color == tuple(fresnel.color.linear([1,0,0]))
    assert geometry.material.primitive_color_mix == 0.0

    buf_proxy = fresnel.preview(scene_hex_sphere_, w=100, h=100)

    if generate:
        PIL.Image.fromarray(buf_proxy[:], mode='RGBA').save(open('output/test_material.test_set_material.png', 'wb'), 'png');
    else:
        conftest.assert_image_approx_equal(buf_proxy[:], 'reference/test_material.test_set_material.png')
Пример #13
0
def test_camera(scene_hex_sphere_, generate=False):
    scene_hex_sphere_.camera = fresnel.camera.orthographic(position=(1, 0, 10), look_at=(1,0,0), up=(0,1,0), height=6)

    assert scene_hex_sphere_.camera.position == (1,0,10)
    assert scene_hex_sphere_.camera.look_at == (1,0,0)
    assert scene_hex_sphere_.camera.up == (0,1,0)
    assert scene_hex_sphere_.camera.height == 6

    buf_proxy = fresnel.preview(scene_hex_sphere_, w=100, h=100)

    if generate:
        PIL.Image.fromarray(buf_proxy[:], mode='RGBA').save(open('output/test_scene.test_camera.png', 'wb'), 'png');
    else:
        conftest.assert_image_approx_equal(buf_proxy[:], 'reference/test_scene.test_camera.png')
Пример #14
0
def test_render(scene_one_triangle_, generate=False):
    """Test that Mesh renders properly."""
    buf_proxy = fresnel.preview(scene_one_triangle_,
                                w=100,
                                h=100,
                                anti_alias=False)

    if generate:
        PIL.Image.fromarray(buf_proxy[:], mode='RGBA').save(
            open('output/test_geometry_mesh.test_render.png', 'wb'), 'png')
    else:
        conftest.assert_image_approx_equal(
            buf_proxy[:],
            dir_path / 'reference' / 'test_geometry_mesh.test_render.png')
Пример #15
0
def test_multiple(scene_tetrahedra_, generate=False):
    """Test that Mesh supports multiple instances."""
    buf_proxy = fresnel.preview(scene_tetrahedra_,
                                w=100,
                                h=100,
                                anti_alias=False)

    if generate:
        PIL.Image.fromarray(buf_proxy[:], mode='RGBA').save(
            open('output/test_geometry_mesh.test_multiple.png', 'wb'), 'png')
    else:
        conftest.assert_image_approx_equal(
            buf_proxy[:],
            dir_path / 'reference' / 'test_geometry_mesh.test_multiple.png')
Пример #16
0
def test_angle(scene_polygons_, generate=False):
    geometry = scene_polygons_.geometry[0]

    a = numpy.array([-0.8, 0.5], dtype=numpy.float32)
    geometry.angle[:] = a
    numpy.testing.assert_array_equal(a, geometry.angle[:])

    buf_proxy = fresnel.preview(scene_polygons_, w=150, h=100)

    if generate:
        PIL.Image.fromarray(buf_proxy[:], mode='RGBA').save(
            open('output/test_geometry_polygon.test_angle.png', 'wb'), 'png')
    else:
        conftest.assert_image_approx_equal(
            buf_proxy[:], 'reference/test_geometry_polygon.test_angle.png')
Пример #17
0
def test_render(scene_hex_sphere_, generate=False):
    tracer = fresnel.tracer.Preview(device=scene_hex_sphere_.device,
                                    w=100,
                                    h=100)
    buf = tracer.output[:]
    assert buf.shape == (100, 100, 4)

    buf_proxy = tracer.render(scene_hex_sphere_)

    if generate:
        PIL.Image.fromarray(buf_proxy[:], mode='RGBA').save(
            open('output/test_tracer_direct.test_render.png', 'wb'), 'png')
    else:
        conftest.assert_image_approx_equal(
            buf_proxy[:], 'reference/test_tracer_direct.test_render.png')
Пример #18
0
def test_render(scene_eight_polyhedra_, generate=False):
    """Test that convex polyhedra render properly."""
    buf_proxy = fresnel.preview(scene_eight_polyhedra_,
                                w=150,
                                h=100,
                                anti_alias=False)

    if generate:
        PIL.Image.fromarray(buf_proxy[:], mode='RGBA').save(
            open('output/test_geometry_convex_polyhedron.test_render.png',
                 'wb'), 'png')
    else:
        conftest.assert_image_approx_equal(
            buf_proxy[:], dir_path / 'reference' /
            'test_geometry_convex_polyhedron.test_render.png')
Пример #19
0
def test_radius(scene_four_spheres_, generate=False):
    geometry = scene_four_spheres_.geometry[0]

    r = numpy.array([0.5, 0.6, 0.8, 1.0], dtype=numpy.float32)
    geometry.radius[:] = r
    numpy.testing.assert_array_equal(r, geometry.radius[:])

    buf_proxy = fresnel.preview(scene_four_spheres_, w=150, h=100)

    if generate:
        PIL.Image.fromarray(buf_proxy[:], mode='RGBA').save(
            open('output/test_geometry_sphere.test_radius.png', 'wb'), 'png')
    else:
        conftest.assert_image_approx_equal(
            buf_proxy[:], 'reference/test_geometry_sphere.test_radius.png')
Пример #20
0
def test_position(scene_four_spheres_, generate=False):
    geometry = scene_four_spheres_.geometry[0]

    p = numpy.array([[1.5, 0, 1], [1.5, 0, -1], [-1.5, 0, 1], [-1.5, 0, -1]],
                    dtype=numpy.float32)
    geometry.position[:] = p
    numpy.testing.assert_array_equal(p, geometry.position[:])

    buf_proxy = fresnel.preview(scene_four_spheres_, w=150, h=100)

    if generate:
        PIL.Image.fromarray(buf_proxy[:], mode='RGBA').save(
            open('output/test_geometry_sphere.test_position.png', 'wb'), 'png')
    else:
        conftest.assert_image_approx_equal(
            buf_proxy[:], 'reference/test_geometry_sphere.test_position.png')
Пример #21
0
def test_render(scene_hex_sphere_, generate=False):
    tracer = fresnel.tracer.Path(device=scene_hex_sphere_.device, w=100, h=100)
    tracer.seed = 11
    buf = tracer.output[:]
    assert buf.shape == (100, 100, 4)

    buf_proxy = tracer.sample(scene_hex_sphere_, samples=64, light_samples=40)

    if generate:
        PIL.Image.fromarray(buf_proxy[:], mode='RGBA').save(
            open('output/test_tracer_path.test_render.png', 'wb'), 'png')
    else:
        conftest.assert_image_approx_equal(
            buf_proxy[:],
            'reference/test_tracer_path.test_render.png',
            tolerance=16)
def test_face_color(scene_eight_polyhedra_, generate=False):
    buf_proxy = fresnel.preview(scene_eight_polyhedra_, w=150, h=100)

    geometry = scene_eight_polyhedra_.geometry[0]
    geometry.color_by_face = 1.0
    geometry.material.primitive_color_mix = 1.0

    buf_proxy = fresnel.preview(scene_eight_polyhedra_, w=150, h=100)

    if generate:
        PIL.Image.fromarray(buf_proxy[:], mode='RGBA').save(
            open('output/test_geometry_convex_polyhedron.test_face_color.png',
                 'wb'), 'png')
    else:
        conftest.assert_image_approx_equal(
            buf_proxy[:],
            'reference/test_geometry_convex_polyhedron.test_face_color.png')
def test_outline(scene_four_spheres_, generate=False):
    """Test that outlines render properly."""
    geometry = scene_four_spheres_.geometry[0]
    geometry.outline_width = 0.1

    buf_proxy = fresnel.preview(scene_four_spheres_,
                                w=150,
                                h=100,
                                anti_alias=False)

    if generate:
        PIL.Image.fromarray(buf_proxy[:], mode='RGBA').save(
            open('output/test_geometry_sphere.test_outline.png', 'wb'), 'png')
    else:
        conftest.assert_image_approx_equal(
            buf_proxy[:],
            dir_path / 'reference' / 'test_geometry_sphere.test_outline.png')
Пример #24
0
def test_box_radius(scene_box_, generate=False):
    """Test the box_radius property."""
    geometry = scene_box_.geometry[0]

    r = 0.1
    geometry.box_radius = r
    assert r == pytest.approx(geometry.box_radius)

    buf_proxy = fresnel.preview(scene_box_, w=150, h=100, anti_alias=False)

    if generate:
        PIL.Image.fromarray(buf_proxy[:], mode="RGBA").save(
            open("output/test_geometry_box.test_box_radius.png", "wb"), "png")
    else:
        conftest.assert_image_approx_equal(
            buf_proxy[:],
            dir_path / "reference" / "test_geometry_box.test_box_radius.png")
Пример #25
0
def test_radius(scene_box_, generate=False):
    """Test the radius property."""
    geometry = scene_box_.geometry[0]

    r = numpy.array(0.1, dtype=numpy.float32)
    geometry.radius[:] = r
    numpy.testing.assert_array_equal(r, geometry.radius[:])

    buf_proxy = fresnel.preview(scene_box_, w=150, h=100, anti_alias=False)

    if generate:
        PIL.Image.fromarray(buf_proxy[:], mode="RGBA").save(
            open("output/test_geometry_box.test_radius.png", "wb"), "png")
    else:
        conftest.assert_image_approx_equal(
            buf_proxy[:],
            dir_path / "reference" / "test_geometry_box.test_radius.png")
Пример #26
0
def test_roughness(scene_hex_sphere_, generate=False):
    """Test the roughness property."""
    geometry = scene_hex_sphere_.geometry[0]
    geometry.material.roughness = 1.0
    assert geometry.material.roughness == 1.0

    buf_proxy = fresnel.preview(scene_hex_sphere_,
                                w=100,
                                h=100,
                                anti_alias=False)

    if generate:
        PIL.Image.fromarray(buf_proxy[:], mode='RGBA').save(
            open('output/test_material.test_roughness.png', 'wb'), 'png')
    else:
        conftest.assert_image_approx_equal(
            buf_proxy[:],
            dir_path / 'reference' / 'test_material.test_roughness.png')
Пример #27
0
def test_render_aa(scene_hex_sphere_, generate=False):
    """Test rendering with anti-aliasing."""
    tracer = fresnel.tracer.Preview(device=scene_hex_sphere_.device,
                                    w=100,
                                    h=100,
                                    anti_alias=True)
    buf = tracer.output[:]
    assert buf.shape == (100, 100, 4)

    buf_proxy = tracer.render(scene_hex_sphere_)

    if generate:
        PIL.Image.fromarray(buf_proxy[:], mode='RGBA').save(
            open('output/test_tracer_direct.test_render_aa.png', 'wb'), 'png')
    else:
        conftest.assert_image_approx_equal(
            buf_proxy[:],
            dir_path / 'reference' / 'test_tracer_direct.test_render_aa.png')
Пример #28
0
def test_points(scene_four_cylinders_, generate=False):
    geometry = scene_four_cylinders_.geometry[0]

    p = numpy.array([[[-5, -5, 0], [-5, 5, 0]], [[-3, 5, 0], [3, 5, 0]],
                     [[5, 5, 0], [5, -5, -0]], [[3, -5, 0], [-3, -5, 0]]],
                    dtype=numpy.float32)
    geometry.points[:] = p
    numpy.testing.assert_array_equal(p, geometry.points[:])

    buf_proxy = fresnel.preview(scene_four_cylinders_, w=150, h=100)

    if generate:
        PIL.Image.fromarray(buf_proxy[:], mode='RGBA').save(
            open('output/test_geometry_clyinder.test_position.png', 'wb'),
            'png')
    else:
        conftest.assert_image_approx_equal(
            buf_proxy[:], 'reference/test_geometry_clyinder.test_position.png')
Пример #29
0
def test_color(scene_box_, generate=False):
    """Test the color property."""
    geometry = scene_box_.geometry[0]
    geometry.material.primitive_color_mix = 1.0

    c = numpy.zeros((12, 2, 3), dtype=numpy.float32) + [1, 0, 0]
    geometry.color[:] = c
    numpy.testing.assert_array_equal(c, geometry.color[:])

    buf_proxy = fresnel.preview(scene_box_, w=150, h=100, anti_alias=False)

    if generate:
        PIL.Image.fromarray(buf_proxy[:], mode="RGBA").save(
            open("output/test_geometry_box.test_color.png", "wb"), "png")
    else:
        conftest.assert_image_approx_equal(
            buf_proxy[:],
            dir_path / "reference" / "test_geometry_box.test_color.png")
Пример #30
0
def test_color_interp(scene_one_triangle_, generate=False):
    """Test that colors are interpolated between vertices."""
    geometry = scene_one_triangle_.geometry[0]
    geometry.material.primitive_color_mix = 1.0

    buf_proxy = fresnel.preview(scene_one_triangle_,
                                w=100,
                                h=100,
                                anti_alias=False)

    if generate:
        PIL.Image.fromarray(buf_proxy[:], mode='RGBA').save(
            open('output/test_geometry_mesh.test_color_interp.png', 'wb'),
            'png')
    else:
        conftest.assert_image_approx_equal(
            buf_proxy[:], dir_path / 'reference' /
            'test_geometry_mesh.test_color_interp.png')