示例#1
0
def default_world():
    light = PointLight(point(-10, 10, -10), white)
    m = Material(color=color(0.8, 1.0, 0.6), diffuse=0.7, specular=0.2)
    s1 = Sphere(material=m)
    s2 = Sphere(transformation=scaling(0.5, 0.5, 0.5))

    return World(light, s1, s2)
def test_lighting_with_the_surface_in_shadow(material, position):
    eyev = vector(0, 0, -1)
    normalv = vector(0, 0, -1)
    light = PointLight(point(0, 0, -10), color(1, 1, 1))
    in_shadow = True

    result = material.lighting(light, position, eyev, normalv, in_shadow)
    assert (np.allclose(color(0.1, 0.1, 0.1), result))
def test_lighting_with_the_light_behind_the_surface(material, position):
    eyev = vector(0, 0, -1)
    normalv = vector(0, 0, -1)
    light = PointLight(point(0, 0, 10), color(1, 1, 1))

    result = material.lighting(light, position, eyev, normalv, False)

    assert (np.array_equal(color(0.1, 0.1, 0.1), result))
def test_lighting_with_the_eye_in_the_path_of_the_reflection_vector(
        material, position):
    eyev = vector(0, -math.sqrt(2) / 2, -math.sqrt(2) / 2)
    normalv = vector(0, 0, -1)
    light = PointLight(point(0, 10, -10), color(1, 1, 1))

    result = material.lighting(light, position, eyev, normalv, False)

    assert (np.allclose(color(1.6364, 1.6364, 1.6364), result))
def test_lighting_with_the_eye_opposite_surface_light_offest_45_degrees(
        material, position):
    eyev = vector(0, 0, -1)
    normalv = vector(0, 0, -1)
    light = PointLight(point(0, 10, -10), color(1, 1, 1))

    result = material.lighting(light, position, eyev, normalv, False)

    assert (np.allclose(color(0.7364, 0.7364, 0.7364), result))
def test_lighting_with_the_eye_between_the_light_and_the_surface_and_wyw_offset_45_degrees(
        material, position):
    eyev = vector(0, math.sqrt(2) / 2, -math.sqrt(2) / 2)
    normalv = vector(0, 0, -1)
    light = PointLight(point(0, 0, -10), color(1, 1, 1))

    result = material.lighting(light, position, eyev, normalv, False)

    assert (np.array_equal(color(1.0, 1.0, 1.0), result))
示例#7
0
def test_shading_an_intersection_from_the_inside():
    w = default_world()
    w._light = PointLight(point(0, 0.25, 0), color(1, 1, 1))
    r = Ray(point(0, 0, 0), vector(0, 0, 1))
    shape = w[1]
    i = Intersection(0.5, shape)

    comps = i.prepare_computations(r)
    c = w.shade_hit(comps)

    assert(np.allclose(color(0.90498, 0.90498, 0.90498), c))
示例#8
0
def test_shade_hit_is_given_an_intersection_in_shadow():
    light = PointLight(point(0, 0, -10), color(1, 1, 1))
    s1 = Sphere()
    s2 = Sphere(transformation=translation(0, 0, 10))
    w = World(light, s1, s2)
    r = Ray(point(0, 0, 5), vector(0, 0, 1))
    i = Intersection(4, s2)
    comps = i.prepare_computations(r)
    c = w.shade_hit(comps)

    assert(np.allclose(color(0.1, 0.1, 0.1), c))
示例#9
0
                                  scaling(10, 0.01, 10))
left_wall = Sphere(transformation=left_wall_transformation,
                   material=floor_material)

right_wall_transform = concat(translation(0, 0, 5), rotation_y(math.pi / 4),
                              rotation_x(math.pi / 2), scaling(10, 0.01, 10))
right_wall = Sphere(transformation=right_wall_transform,
                    material=floor_material)

middle_transform = translation(-0.5, 1, 0.5)
middle_material = Material(color=color(0.1, 1, 0.5), diffuse=0.7, specular=0.3)
middle = Sphere(material=middle_material, transformation=middle_transform)

right_transform = concat(translation(1.5, 0.5, -0.5), scaling(0.5, 0.5, 0.5))
right_material = Material(color=color(0.5, 1, 0.1), diffuse=0.7, specular=0.3)
right = Sphere(material=right_material, transformation=right_transform)

left_transform = concat(translation(-1.5, 0.33, -0.75),
                        scaling(0.33, 0.33, 0.33))
lef_material = Material(color=color(1, 0.8, 0.1), diffuse=0.7, specular=0.3)
left = Sphere(material=lef_material, transformation=left_transform)

camera_transform = view_transformation(point(0, 1.5, -5), point(0, 1, 0),
                                       vector(0, 1, 0))
camera = Camera(1000, 500, math.pi / 3, transform=camera_transform)

light = PointLight(point(-10, 10, -10), color(1, 1, 1))
world = World(light, floor, left_wall, right_wall, middle, left, right)

print(camera.render(world).to_PPM())