コード例 #1
0
import torch
import math

# Estimate the pose of a teapot object.
# This tutorial demonstrates:
# 1. how to render G buffer, such as depth, normal, albedo
# 2. how to use G buffer to do "deferred rendering" in pytorch, which bypasses the main path tracing
#    process in redner, resulting in fast approximate rendering
# You might want to read the wikipedia page first if you are not familiar with the concept
# of deferred rendering: https://en.wikipedia.org/wiki/Deferred_shading
#
# Like the second tutorial, we first render a target image, then perturb the
# rotation/translation parameters and optimize to match the target.

# Use GPU if available
pyredner.set_use_gpu(torch.cuda.is_available())

# Load from the teapot Wavefront object file just like tutorial 02
material_map, mesh_list, light_map = pyredner.load_obj('teapot.obj')
# Compute shading normal
for _, mesh in mesh_list:
    mesh.normals = pyredner.compute_vertex_normal(mesh.vertices, mesh.indices)

# Setup camera
cam = pyredner.Camera(
    position=torch.tensor([0.0, 30.0, 200.0]),
    look_at=torch.tensor([0.0, 30.0, 0.0]),
    up=torch.tensor([0.0, 1.0, 0.0]),
    fov=torch.tensor([45.0]),  # in degree
    clip_near=1e-2,  # needs to > 0
    resolution=(256, 256),
コード例 #2
0
ファイル: test_texture.py プロジェクト: mtlong/redner
import pyredner
import numpy as np
import torch

# Optimize four vertices of a textured patch

# Use GPU if available
pyredner.set_use_gpu(torch.cuda.is_available())

# Set up the scene using Pytorch tensor
position = torch.tensor([0.0, 0.0, -5.0])
look_at = torch.tensor([0.0, 0.0, 0.0])
up = torch.tensor([0.0, 1.0, 0.0])
fov = torch.tensor([45.0])
clip_near = 1e-2

resolution = (256, 256)
cam = pyredner.Camera(position = position,
                     look_at = look_at,
                     up = up,
                     fov = fov,
                     clip_near = clip_near,
                     resolution = resolution)

checkerboard_texture = pyredner.imread('checkerboard.exr')
if pyredner.get_use_gpu():
	checkerboard_texture = checkerboard_texture.cuda(device = pyredner.get_device())

mat_checkerboard = pyredner.Material(\
    diffuse_reflectance = checkerboard_texture)
mat_black = pyredner.Material(\
コード例 #3
0
import os

import torch

import pyredner

from util.render_util import LearnMesh
from util.misc_util import *

pyredner.set_use_gpu(False)
pyredner.set_device(torch.device('cpu'))

MESHES_PATH = './datasets/meshes/full'
OUTPUT_PATH = './datasets/meshes/serialized'


def main():
    if not os.path.exists(OUTPUT_PATH):
        os.makedirs(OUTPUT_PATH)

    mesh_path_list = get_child_paths(MESHES_PATH, ext='obj')
    for path in mesh_path_list:
        print(f'Serializing mesh {path}')
        mesh = LearnMesh.load_obj(path)
        torch.save(mesh.state_dict(),
                   os.path.join(OUTPUT_PATH, f'{get_fn(path)}.pth'))


if __name__ == '__main__':
    main()