Esempio n. 1
0
import tensorflow as tf
tf.compat.v1.enable_eager_execution()
import pyredner_tensorflow as pyredner
import redner

# Automatic UV mapping example adapted from tutorial 2

# Use GPU if available
pyredner.set_use_gpu(
    tf.test.is_gpu_available(cuda_only=True, min_cuda_compute_capability=None))

# Set up the pyredner scene for rendering:
with tf.device(pyredner.get_device_name()):
    material_map, mesh_list, light_map = pyredner.load_obj('scenes/teapot.obj')
    for _, mesh in mesh_list:
        mesh.normals = pyredner.compute_vertex_normal(mesh.vertices,
                                                      mesh.indices)
        mesh.uvs, mesh.uv_indices = pyredner.compute_uvs(
            mesh.vertices, mesh.indices)

# Setup camera
with tf.device('/device:cpu:' + str(pyredner.get_cpu_device_id())):
    cam = pyredner.Camera(
        position=tf.Variable([0.0, 30.0, 200.0], dtype=tf.float32),
        look_at=tf.Variable([0.0, 30.0, 0.0], dtype=tf.float32),
        up=tf.Variable([0.0, 1.0, 0.0], dtype=tf.float32),
        fov=tf.Variable([45.0], dtype=tf.float32),  # in degree
        clip_near=1e-2,  # needs to > 0
        resolution=(256, 256),
        fisheye=False)

# Setup materials
tf.compat.v1.enable_eager_execution()  # redner only supports eager mode
import pyredner_tensorflow as pyredner

objects = pyredner.load_obj('scenes/teapot.obj', return_objects=True)
camera = pyredner.automatic_camera_placement(objects, resolution=(512, 512))
scene = pyredner.Scene(camera=camera, objects=objects)

light = pyredner.PointLight(position=(camera.position + tf.constant(
    (0.0, 0.0, 100.0))),
                            intensity=tf.constant((20000.0, 30000.0, 20000.0)))

img = pyredner.render_deferred(scene=scene, lights=[light])
pyredner.imwrite(img,
                 'results/test_compute_vertex_normals/no_vertex_normal.exr')

for obj in objects:
    obj.normals = pyredner.compute_vertex_normal(obj.vertices, obj.indices,
                                                 'max')
scene = pyredner.Scene(camera=camera, objects=objects)
img = pyredner.render_deferred(scene=scene, lights=[light])
pyredner.imwrite(img,
                 'results/test_compute_vertex_normals/max_vertex_normal.exr')

for obj in objects:
    obj.normals = pyredner.compute_vertex_normal(obj.vertices, obj.indices,
                                                 'cotangent')
scene = pyredner.Scene(camera=camera, objects=objects)
img = pyredner.render_deferred(scene=scene, lights=[light])
pyredner.imwrite(
    img, 'results/test_compute_vertex_normals/cotangent_vertex_normal.exr')
Esempio n. 3
0
tf.compat.v1.enable_eager_execution()
import pyredner_tensorflow as pyredner
import redner

# Optimize depth and normal of a teapot

# Use GPU if available
pyredner.set_use_gpu(
    tf.test.is_gpu_available(cuda_only=True, min_cuda_compute_capability=None))

# Set up the pyredner scene for rendering:
with tf.device(pyredner.get_device_name()):
    material_map, mesh_list, light_map = pyredner.load_obj('scenes/teapot.obj')
    for _, mesh in mesh_list:
        mesh.normals = pyredner.compute_vertex_normal(mesh.vertices,
                                                      mesh.indices)

# Setup camera
with tf.device('/device:cpu:' + str(pyredner.get_cpu_device_id())):
    cam = pyredner.Camera(
        position=tf.Variable([0.0, 30.0, 200.0], dtype=tf.float32),
        look_at=tf.Variable([0.0, 30.0, 0.0], dtype=tf.float32),
        up=tf.Variable([0.0, 1.0, 0.0], dtype=tf.float32),
        fov=tf.Variable([45.0], dtype=tf.float32),  # in degree
        clip_near=1e-2,  # needs to > 0
        resolution=(256, 256),
        fisheye=False)

# Setup materials
material_id_map = {}
materials = []