示例#1
0
def get_small_world() -> World:
    mat_ground = Lambertian(Color(.8, .8, .3))
    ground = Sphere(Vector(0, -100.5, -1), 100, mat_ground)

    mat_center = Lambertian(Color(.7, .3, .3))
    center = Sphere(Vector(0, 0, -1), .5, mat_center)

    mat_left = Metal(Color(.8, .8, .8))
    left = Sphere(Vector(-1, 0, -1), .5, mat_left)

    mat_right = Dielectric(1.5)
    right = Sphere(Vector(1, 0, -1), .5, mat_right)

    return World([ground, center, left, right])
示例#2
0
    def __init__(self):
        self.objects = [Plane(Point3D(0, -.5, 0),
                              Vector3D(0, 1, 0),
                              color=Color(1, 1, 1)),
                        Sphere(Point3D(0, 0, -1.0), 0.1,
                               color=Color(1.0, 0, 0))]

        self.lights = [UniformPointLight(Point3D(-.5, 0, -1),
                                         Color(100, 100, 100))]
示例#3
0
def generate_new_shapes_test(model):
    shapes = [Cone(), Cube(), Cylinder(), Sphere(), Torus()]
    p = []
    l = []
    for e, s in enumerate(shapes):
        for _ in tqdm(range(100)):
            p.append(s.build())
            l.append(e)
    p = np.stack(p)
    print(np.mean(l == np.argmax(model(p), axis=1)))
    model.summary()
示例#4
0
def get_world() -> World:
    world = []
    glass = Dielectric(1.5)

    # Ground
    ground_mat = Lambertian(Color(0.5, 0.5, 0.5))
    world.append(Sphere(Vector(0, -1000, 0), 1000, ground_mat))

    # Marbles
    for x in range(-11, 11):
        for z in range(-11, 11):
            choose_material = random()
            material: Material

            center = Vector(x + .9 * random(), .2, z + .9 * random())

            if (center - Vector(4, .2, 0)).norm() <= .9:
                continue

            if choose_material < .8:
                # Diffuse
                albedo = Color(*(random(3) * random(3)))
                material = Lambertian(albedo)
            elif choose_material < .95:
                # Metal
                albedo = Color(*(random(3) * .5 + .5))
                fuzz = random() * .4
                material = Metal(albedo, fuzziness=fuzz)
            else:
                # Glass
                material = glass

            world.append(Sphere(center, .2, material))

    # Big Spheres
    world.append(Sphere(Vector(4, 1, 0),  1.0, glass))
    world.append(Sphere(Vector(-4, 1, 0), 1.0, Lambertian(Color(.6, .1, .1))))
    world.append(Sphere(Vector(0, 1, 0),  1.0, Metal(Color(.7, .6, .5))))

    return World(world)
                                           objRfractIdx)
                return np.multiply(
                    k, R * reflectionColor + (1.0 - R) * refractionColor)
    else:
        dir = ray.direction
        dir = dir / np.linalg.norm(dir)
        phi = (np.pi + np.arctan2(dir[1], dir[0])) / (2 * np.pi)
        theta = (-np.pi + np.arccos(dir[2])) / np.pi
        return map[int(theta * mapWidth), int(phi * mapHeight)]


# Scene definition

scene = []

scene.append(Sphere(np.array([0.0,0.0,0.0]),\
    2.0, np.array([1.0, 1.0, 1.0]), 0.0, 0.5, 0.5, 32))

#scene.append(Sphere(np.array([0.0,-2.0,0.0]),\
#    1.0, np.array([1.0, 1.0, 1.0]), 0.0, 0.5, 0.5, 32))

# Lights
lights = []
lights.append(PointLight(np.array([0.0, 0.0, 3.0]),\
    np.array([1.0, 1.0, 1.0])))

# Sphere map
map = cv2.imread("resources/autumnCubeMap.hdr", -1)
tonemapReinhard = cv2.createTonemapReinhard(1.5, 1.0, 0.0, 1.0)
map = tonemapReinhard.process(map)
mapHeight = map.shape[1]
mapWidth = map.shape[0]
示例#6
0
文件: ray.py 项目: timpauls/raypy
from tracer import SimpleRayTracer, SimpleShadowRayTracer, ShadingShadowRayTracer, RecursiveRayTracer, PathTracer
from material import Material, Color
from window import Window

if __name__ == "__main__":
    p1 = Plane([0, 5, 0], [0, -1, 0], Material(Color(255, 0, 0), 1, 0, 0.1))
    p2 = Plane([0, -5, 0], [0, 1, 0], Material(Color(0, 255, 0), 1, 0, 0.1))
    p3 = Plane([5, 0, 0], [-1, 0, 0], Material(Color(0, 0, 255), 1, 0, 0.1))
    p4 = Plane([-5, 0, 0], [1, 0, 0], Material(Color(255, 255, 0), 1, 0, 0.1))
    p5 = Plane([0, 0, 5], [0, 0, -1], Material(Color(255, 0, 255), 1, 0, 0.1))
    p6 = Plane([0, 0, -5], [0, 0, 1], Material(Color(0, 255, 255), 1, 0, 0.1))

    s1 = Sphere([0, 3, 2], 2,
                Material(Color(100, 100, 100),
                         1,
                         0,
                         0.1,
                         refractive=False,
                         n=1.52))
    s2 = Sphere([4, 2, 1], 0.5,
                Material(Color(100, 100, 100),
                         1,
                         0,
                         0.1,
                         refractive=False,
                         n=1.52))
    s3 = Sphere([-3, 2, 1], 1,
                Material(Color(100, 100, 100),
                         1,
                         0,
                         0.1,
示例#7
0
文件: main.py 项目: tehzwen/pythongl
    # sm.add_object(my_cube2)

    my_light = Pointlight("light1",
                          strength=15.0,
                          position=glm.vec3(30.0, 35.0, 0.0),
                          color=glm.vec3(0.5, 0.0, 0.0))
    sm.add_point_light(my_light)

    my_dir_light = DirectionalLight("dirLight1",
                                    direction=glm.vec3(-1, -0.25, 0),
                                    position=glm.vec3(200, 150, 0),
                                    strength=2)
    sm.add_directional_light(my_dir_light)
    my_sphere = Sphere("lightSphere",
                       10,
                       10,
                       10,
                       material=Material(nVal=200),
                       model=Model(position=glm.vec3(200, 150, 0)))
    my_sphere.shader.load_frag_source(file_name="lightObject")
    my_sphere.shader.load_vert_source(file_name="lightObject")
    my_sphere.shader.init()
    my_sphere.setup()
    # my_sphere.scale(glm.vec3(50, 1, 50))
    sm.add_object(my_sphere)

    scene_axis = Axis()
    for line in scene_axis.get_lines():
        sm.add_line(line)

    sm.axis = scene_axis