specList_final[mid] = spec
        roughnessList_final[mid] = roughness

    lightPool = pickle.load(open(lightpool_file, 'rb'))
    lightNormPool = {}

#    precompute auto-exposure factor
    normal_one = np.dstack((np.ones((256,256)), np.ones((256,256)), np.ones((256,256))))
    for m in specList_final.keys():
        lightNormPool[m] = np.zeros((len(lightID), 10, 3))
        for id, lid in enumerate(lightID):
            for v in range(0, lightPool[m].shape[1]):
                AugmentRender.SetEnvLightByID(lid + 1, lightPool[m][id, v, 0], lightPool[m][id, v, 1])
                AugmentRender.SetAlbedoValue([1.0, 1.0, 1.0])
                AugmentRender.SetSpecValue([0.0, 0.0, 0.0])
                AugmentRender.SetRoughnessValue(0)
                AugmentRender.SetNormalMap(normal_one)
                img_diffuse = AugmentRender.Render()
                norm = np.mean(img_diffuse, axis = (0,1))
                lightNormPool[m][id, v] = norm

    with open(params_global['envMapFolder'] + r'/lightNormPool_{}.dat'.format(data_tag), 'wb') as f:
        pickle.dump(lightNormPool, f)

    print('Factor done.\n')

    #render training
    if(renderTag == 'train' or renderTag == 'all'):
        make_dir(rendered_labeled_out)
        path, file = os.path.split(labeled_file_in)
        dataset = DataLoaderSVBRDF(path, file, 384, 384, True)
    print('Rendering Training data...\n')
    ftrain = open(out_root + r'/train_envlight/train_full.txt', 'w')
    for aid, a in enumerate(trainAlbedo):
        for sid, s in enumerate(trainSpec):
            for rid, r in enumerate(trainRoughness):
                lightMatrix = np.zeros((len(lightID), 9, 2))
                print('...{}_{}_{}\n'.format(aid, sid, rid))

                trainCube[aid, sid, rid] = [a, s, r]
                brdfFolder = out_root + r'/train_envlight/{}_{}_{}'.format(
                    aid, sid, rid)
                make_dir(brdfFolder)

                OnlineRender.SetAlbedoValue([a, a, a])
                OnlineRender.SetSpecValue([s, s, s])
                OnlineRender.SetRoughnessValue(r)

                for lid, l in enumerate(lightID):
                    OnlineRender.SetEnvLightByID(l + 1)
                    lightView, lightX, lightY = getLightTransList(3, 3)
                    for vid, v in enumerate(lightView):
                        OnlineRender.SetLightXform(lightX[vid], lightY[vid])
                        img = OnlineRender.Render()
                        save_pfm(brdfFolder + r'/{}_{}.pfm'.format(lid, vid),
                                 img)
                        ftrain.write('{}_{}_{}_{}_{}\n'.format(
                            aid, sid, rid, lid, vid))
                        lightMatrix[lid, vid, 0] = lightX[vid]
                        lightMatrix[lid, vid, 1] = lightY[vid]

                np.savetxt(