Beispiel #1
0
def parse_scene(node):
    cam = None
    resolution = None
    bsdfs = []
    bsdf_dict = {}
    shapes = []
    lights = []
    medium_dict = {}
    mediums = []
    phases = []
    for child in node:
        if child.tag == 'sensor':
            cam = parse_camera(child, medium_dict)
        elif child.tag == 'bsdf':
            node_id, bsdf = parse_bsdf(child)
            if node_id is not None:
                bsdf_dict[node_id] = len(bsdfs)
                bsdfs.append(bsdf)
        elif child.tag == 'medium':
            node_id, medium, phase = parse_medium(child)
            if node_id is not None:
                medium_dict[node_id] = len(mediums)
                mediums.append(medium)
                medium.phase_id = len(phases)
                phases.append(phase)
        elif child.tag == 'shape':
            shape, light = parse_shape(child, bsdf_dict, medium_dict, len(shapes))
            shapes.append(shape)
            if light is not None:
                lights.append(light)
        elif child.tag == 'integrator':
            if child.attrib['type'] == 'direct':
                integrator = dtrt.DirectIntegrator();
            elif child.attrib['type'] == 'path':
                integrator = dtrt.PathTracer();
            elif child.attrib['type'] == 'volpath_simple':
                integrator = dtrt.VolPathTracerSimple();
            elif child.attrib['type'] == 'volpath':
                integrator = dtrt.VolPathTracer();
            elif child.attrib['type'] == 'directAD':
                integrator = dtrt.DirectAD();
            elif child.attrib['type'] == 'pathAD':
                integrator = dtrt.PathTracerAD();
            elif child.attrib['type'] == 'volpathAD':
                integrator = dtrt.VolPathTracerAD();
            elif child.attrib['type'] == 'ptracer':
                integrator = dtrt.ParticleTracer();
            else:
                raise Exception("Integrator type [ %s ] not supported!" % child.attrib['type'])
            # print("Rendering using [ %s ] ..." % child.attrib['type'])
    return pydtrt.Scene(cam, shapes, bsdfs, mediums, phases, lights), integrator
Beispiel #2
0
transform_list.append([T3])
scene_manager = SceneManager(args_init, transform_list)
init = pydtrt.render_scene(integrator, options, *(scene_manager.args))
pydtrt.imwrite(init[0, :, :, :], direc + 'init.exr')

integrator = dtrt.VolPathTracer()
# target_var = torch.tensor([0.7])
target_var = torch.tensor([-1.6, 1.2, -1.5])

print("Target variable values: ", target_var)
scene_manager.set_arguments(target_var)
target = pydtrt.render_scene(integrator, options, *(scene_manager.args))
target = target[0, :, :, :]
pydtrt.imwrite(target, direc + 'target.exr')

integrator = dtrt.VolPathTracerAD()
scene_manager.reset()
lossFunc = pydtrt.ADLossFunc.apply
optimizer = torch.optim.Adam([var_list], lr=1e-1)
grad_out_range = torch.tensor([0] * dtrt.nder, dtype=torch.float)
if output_loss:
    file1 = open(direc + 'loss.txt', 'w')
if output_loss:
    file2 = open(direc + 'param.txt', 'w')

for t in range(500):
    print('iteration:', t)
    optimizer.zero_grad()
    options.seed = t + 1
    img = lossFunc(scene_manager, integrator, options, var_list,
                   grad_out_range,