Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update psdr_enzyme connector #34

Merged
merged 2 commits into from
May 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion irtk/connectors/psdr_enzyme_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ def process_integrator(name, scene):

integrator_dict = {
'path2': psdr_cpu.Path2,
'pathwas': psdr_cpu.PathWAS,
}
if integrator['type'] in integrator_dict:
cache['integrators'][name] = integrator_dict[integrator['type']]()
Expand Down Expand Up @@ -202,7 +203,7 @@ def process_perspective_camera(name, scene):
props.set('fov', float(camera['fov']))
# temporary fix of the to_world matrix
# psdr-enzyme uses left-hand coordinate
to_world = to_numpy(camera['to_world'])
to_world = to_numpy(camera['to_world'].clone())
to_world[:3, 0] *= -1
props.set('to_world', to_world)
props.set('rfilter', {'type': 'box'})
Expand Down Expand Up @@ -340,6 +341,21 @@ def process_rough_dielectric_bsdf(name, scene):

return []

@PSDREnzymeConnector.register(RoughConductorBRDF)
def process_rough_conductor_bsdf(name, scene):
bsdf = scene[name]
cache = scene.cached['psdr_enzyme']

# Create the object if it has not been created
if name not in cache['name_map']:
bsdf_id = len(cache['ctx']['bsdfs'])
psdr_bsdf = psdr_cpu.RoughConductorBSDF(bsdf['alpha_u'].item(), to_numpy(bsdf['eta']), to_numpy(bsdf['k']))
cache['ctx']['bsdfs'].append(psdr_bsdf)
cache['name_map'][name] = ("bsdfs", bsdf_id)
cache['mat_id_map'][name] = bsdf_id

return []

@PSDREnzymeConnector.register(EnvironmentLight)
def process_environment_light(name, scene):
emitter = scene[name]
Expand Down
42 changes: 40 additions & 2 deletions irtk/scene.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,14 +190,45 @@ def from_file(cls, d_filename, s_filename, r_filename, d_is_srgb=None, s_is_srgb
r_texture = read_image(r_filename, r_is_srgb)[..., 0:1]

return cls(d_texture, s_texture, r_texture)


class SmoothDielectricBRDF(ParamGroup):

def __init__(self, int_ior, ext_ior, s_reflect, s_transmit):
super().__init__()

self.add_param('int_ior', int_ior, is_tensor=False, is_diff=False, help_msg='interior index of refraction')
self.add_param('ext_ior', ext_ior, is_tensor=False, is_diff=False, help_msg='exterior index of refraction')
self.add_param('s_reflect', to_torch_f(s_reflect), is_tensor=True, is_diff=False, help_msg='specular reflection component')
self.add_param('s_transmit', to_torch_f(s_transmit), is_tensor=True, is_diff=False, help_msg='specular transmission component')

class RoughDielectricBSDF(ParamGroup):

def __init__(self, alpha, i_ior, e_ior):
super().__init__()
self.add_param('alpha', to_torch_f(alpha), help_msg='roughness')
self.add_param('i_ior', to_torch_f(i_ior), help_msg='interior index of refraction')
self.add_param('e_ior', to_torch_f(e_ior), help_msg='exterior index of refraction')

class RoughConductorBRDF(ParamGroup):

def __init__(self, alpha_u, alpha_v, eta, k, s):
super().__init__()

self.add_param('alpha_u', to_torch_f(alpha_u), is_tensor=True, is_diff=True, help_msg='alpha_u')
self.add_param('alpha_v', to_torch_f(alpha_v), is_tensor=True, is_diff=True, help_msg='alpha_v')
self.add_param('eta', to_torch_f(eta), is_tensor=True, is_diff=True, help_msg='eta')
self.add_param('k', to_torch_f(k), is_tensor=True, is_diff=True, help_msg='k')
self.add_param('s', to_torch_f(s), is_tensor=True, is_diff=True, help_msg='specular reflectance')

# @classmethod
# def from_file(cls, d_filename, s_filename, r_filename, d_is_srgb=None, s_is_srgb=None, r_is_srgb=None):
# d_texture = read_image(d_filename, d_is_srgb)
# s_texture = read_image(s_filename, s_is_srgb)
# r_texture = read_image(r_filename, r_is_srgb)[..., 0:1]

# return cls(d_texture, s_texture, r_texture)



class EnvironmentLight(ParamGroup):

Expand All @@ -211,4 +242,11 @@ def __init__(self, radiance, to_world=torch.eye(4)):
def from_file(cls, radiance_filename, radiance_is_srgb=None, to_world=torch.eye(4)):
radiance_texture = read_image(radiance_filename, radiance_is_srgb)

return cls(radiance_texture, to_world)
return cls(radiance_texture, to_world)

class PointLight(ParamGroup):
def __init__(self, radiance, position):
super().__init__()

self.add_param('radiance', to_torch_f(radiance), is_tensor=True, is_diff=False, help_msg='point light radiance')
self.add_param('position', to_torch_f(position), is_tensor=True, is_diff=True, help_msg='point light position')