def convert_envmap_emitter(scene, emitter_name, element): filepath = element.find("string[@name='filename']").attrib["value"] texture_instance_name = create_texture(scene, "environment_map", filepath) env_edf = asr.EnvironmentEDF("latlong_map_environment_edf", "environment_edf", {"radiance": texture_instance_name}) matrix_element = element.find("transform[@name='toWorld']/matrix") if matrix_element is not None: matrix = get_matrix(matrix_element) roty = asr.Matrix4d.make_rotation(asr.Vector3d(0.0, 1.0, 0.0), math.radians(-90.0)) matrix = matrix * roty env_edf.transform_sequence().set_transform(0.0, asr.Transformd(matrix)) scene.environment_edfs().insert(env_edf) scene.environment_shaders().insert( asr.EnvironmentShader("edf_environment_shader", "environment_shader", {"environment_edf": 'environment_edf'})) scene.set_environment( asr.Environment( "environment", { "environment_edf": "environment_edf", "environment_shader": "environment_shader" }))
def create_entities(self, depsgraph): logger.debug("appleseed: Creating world entity") as_world = self.bl_world.appleseed_sky self.__as_env_type = as_world.env_type if self.__as_env_type != 'none': self.__as_env_type = as_world.env_type if as_world.env_type != 'sunsky' else as_world.sun_model self.__set_colors() self.__as_edf_params = self.__create_params() self.__as_env_edf = asr.EnvironmentEDF( self.__as_env_type + "_environment_edf", "sky_edf", self.__as_edf_params) self.__as_env_shader = asr.EnvironmentShader( "edf_environment_shader", "sky_shader", { 'environment_edf': 'sky_edf', 'alpha_value': as_world.env_alpha }) self.__as_env = asr.Environment("sky", { "environment_edf": "sky_edf", "environment_shader": "sky_shader" }) else: self.__as_env = asr.Environment("environment", {})
def convert_constant_emitter(scene, emitter_name, element): radiance = element.find("*[@name='radiance']") scene.environment_edfs().insert(asr.EnvironmentEDF("constant_environment_edf", "environment_edf", { "radiance": convert_colormap(scene, emitter_name, radiance) })) scene.environment_shaders().insert(asr.EnvironmentShader("edf_environment_shader", "environment_shader", { "environment_edf": 'environment_edf' })) scene.set_environment(asr.Environment("environment", { "environment_edf": "environment_edf", "environment_shader": "environment_shader" }))
def convert_sunsky_emitter(scene, assembly, emitter_name, element): turbidity_element = element.find("float[@name='turbidity']") if turbidity_element is not None: turbidity = float(turbidity_element.attrib["value"]) - 2.0 else: turbidity = 1.0 # Sky. sun_direction = element.find("vector[@name='sunDirection']") if sun_direction is not None: d = get_vector(sun_direction) sun_theta = math.acos(d[1]) sun_phi = math.atan2(d[2], d[0]) else: sun_theta = 0.0 sun_phi = 0.0 env_edf = asr.EnvironmentEDF( "hosek_environment_edf", "environment_edf", { "sun_theta": math.degrees(sun_theta), "sun_phi": math.degrees(sun_phi), "turbidity": turbidity }) scene.environment_edfs().insert(env_edf) scene.environment_shaders().insert( asr.EnvironmentShader("edf_environment_shader", "environment_shader", {"environment_edf": 'environment_edf'})) scene.set_environment( asr.Environment( "environment", { "environment_edf": "environment_edf", "environment_shader": "environment_shader" })) # Sun. sun_params = {"environment_edf": "environment_edf", "turbidity": turbidity} sun_scale = element.find("float[@name='sunScale']") if sun_scale is not None: sun_params["radiance_multiplier"] = float(sun_scale.attrib["value"]) sun = asr.Light("sun_light", "sun_light", sun_params) assembly.lights().insert(sun)
def build_project(): # Create an empty project. project = asr.Project('test project') paths = project.get_search_paths() paths.append('data') project.set_search_paths(paths) # Add default configurations to the project. project.add_default_configurations() # Set the number of samples. This is basically the quality parameter: the higher the number # of samples, the smoother the image but the longer the rendering time. # todo: fix. conf = project.configurations()['final'] conf.insert_path('uniform_pixel_renderer.samples', 25) # Create a scene. scene = asr.Scene() # Create an assembly. assembly = asr.Assembly("assembly") #------------------------------------------------------------------------ # Materials #------------------------------------------------------------------------ # Create a color called "gray" and insert it into the assembly. GrayReflectance = [0.5, 0.5, 0.5] assembly.colors().insert( asr.ColorEntity("gray", {'color_space': 'srgb'}, GrayReflectance)) # Create a BRDF called "diffuse_gray_brdf" and insert it into the assembly. assembly.bsdfs().insert( asr.BSDF("lambertian_brdf", "diffuse_gray_brdf", {'reflectance': 'gray'})) # Create a physical surface shader and insert it into the assembly. assembly.surface_shaders().insert( asr.SurfaceShader("physical_surface_shader", "physical_surface_shader")) # Create a material called "gray_material" and insert it into the assembly. assembly.materials().insert( asr.Material( "gray_material", { "surface_shader": "physical_surface_shader", "bsdf": "diffuse_gray_brdf" })) #------------------------------------------------------------------------ # Geometry #------------------------------------------------------------------------ # Load the scene geometry from disk. objects = asr.MeshObjectReader.read(project.get_search_paths(), "cube", {'filename': 'scene.obj'}) # Insert all the objects into the assembly. for object in objects: # Create an instance of this object and insert it into the assembly. instance_name = object.get_name() + "_inst" material_names = { "default": "gray_material", "default2": "gray_material" } instance = asr.ObjectInstance(instance_name, {}, object.get_name(), asr.Transformd(asr.Matrix4d.identity()), material_names) assembly.object_instances().insert(instance) # Insert this object into the scene. assembly.objects().insert(object) #------------------------------------------------------------------------ # Light #------------------------------------------------------------------------ # Create a color called "light_intensity" and insert it into the assembly. LightRadiance = [1.0, 1.0, 1.0] assembly.colors().insert( asr.ColorEntity("light_intensity", { 'color_space': 'srgb', 'multiplier': 30.0 }, LightRadiance)) # Create a point light called "light" and insert it into the assembly. light = asr.Light("point_light", "light", {'intensity': 'light_intensity'}) light.set_transform( asr.Transformd(asr.Matrix4d.translation(asr.Vector3d(0.6, 2.0, 1.0)))) assembly.lights().insert(light) # Create an instance of the assembly and insert it into the scene. assembly_inst = asr.AssemblyInstance("assembly_inst", {}, assembly.get_name()) assembly_inst.transform_sequence().set_transform( 0.0, asr.Transformd(asr.Matrix4d.identity())) scene.assembly_instances().insert(assembly_inst) # Insert the assembly into the scene. scene.assemblies().insert(assembly) #------------------------------------------------------------------------ # Environment #------------------------------------------------------------------------ # Create a color called "sky_radiance" and insert it into the scene. SkyRadiance = [0.75, 0.80, 1.0] scene.colors().insert( asr.ColorEntity("sky_radiance", { 'color_space': 'srgb', 'multiplier': 0.5 }, SkyRadiance)) # Create an environment EDF called "sky_edf" and insert it into the scene. scene.environment_edfs().insert( asr.EnvironmentEDF("constant_environment_edf", "sky_edf", {'radiance': 'sky_radiance'})) # Create an environment shader called "sky_shader" and insert it into the scene. scene.environment_shaders().insert( asr.EnvironmentShader("edf_environment_shader", "sky_shader", {'environment_edf': 'sky_edf'})) # Create an environment called "sky" and bind it to the scene. scene.set_environment( asr.Environment("sky", { "environment_edf": "sky_edf", "environment_shader": "sky_shader" })) #------------------------------------------------------------------------ # Camera #------------------------------------------------------------------------ # Create a pinhole camera with film dimensions 0.980 x 0.735 in (24.892 x 18.669 mm). params = { 'film_dimensions': asr.Vector2f(0.024892, 0.018669), 'focal_length': 0.035 } camera = asr.Camera("pinhole_camera", "camera", params) # Place and orient the camera. By default cameras are located in (0.0, 0.0, 0.0) # and are looking toward Z- (0.0, 0.0, -1.0). mat = asr.Matrix4d.rotation(asr.Vector3d(1.0, 0.0, 0.0), math.radians(-20.0)) mat = mat * asr.Matrix4d.translation(asr.Vector3d(0.0, 0.8, 11.0)) camera.transform_sequence().set_transform(0.0, asr.Transformd(mat)) # Bind the camera to the scene. scene.set_camera(camera) #------------------------------------------------------------------------ # Frame #------------------------------------------------------------------------ # Create a frame and bind it to the project. params = { 'camera': scene.get_camera().get_name(), 'resolution': asr.Vector2i(640, 480), 'color_space': 'srgb' } project.set_frame(asr.Frame("beauty", params)) # Bind the scene to the project. project.set_scene(scene) return project
def build_project(): # Create an empty project. project = asr.Project('test project') # Add default configurations to the project. project.add_default_configurations() # Set the number of samples. This is basically the quality parameter: the higher the number # of samples, the smoother the image but the longer the rendering time. # todo: fix. conf = project.configurations()['final'] conf.insert_path('uniform_pixel_renderer.samples', 16) # Create a scene. scene = asr.Scene() # Create an assembly. assembly = asr.Assembly("assembly") #------------------------------------------------------------------------ # Materials #------------------------------------------------------------------------ for i in range(0, 10): assembly.bsdfs().insert( asr.BSDF( "glossy_brdf", "glossy" + str(i), { "mdf": "ggx", "reflectance": 1.0, "roughness": i / 9.0, "energy_compensation": 0.0 })) assembly.bsdfs().insert( asr.BSDF( "glossy_brdf", "glossy_ec" + str(i), { "mdf": "ggx", "reflectance": 1.0, "roughness": i / 9.0, "energy_compensation": 1.0 })) for i in range(0, 10): assembly.materials().insert( asr.Material("generic_material", "mat" + str(i), {"bsdf": "glossy" + str(i)})) assembly.materials().insert( asr.Material("generic_material", "mat_ec" + str(i), {"bsdf": "glossy_ec" + str(i)})) #------------------------------------------------------------------------ # Geometry #------------------------------------------------------------------------ object_name = "sphere" object = asr.MeshObject(object_name, { "primitive": "sphere", "radius": 0.4 }) assembly.objects().insert(object) obj_instance_params = {'visibility': {"glossy": False, "shadow": False}} for i in range(0, 10): instance_name = object_name + "_inst" + str(i) material_names = {"default": "mat" + str(i)} mat = asr.Matrix4d.make_translation(asr.Vector3d(-5.0 + i, -0.5, 0.0)) instance = asr.ObjectInstance(instance_name, obj_instance_params, object_name, asr.Transformd(mat), material_names) assembly.object_instances().insert(instance) for i in range(0, 10): instance_name = object_name + "_ec_inst" + str(i) material_names = {"default": "mat_ec" + str(i)} mat = asr.Matrix4d.make_translation(asr.Vector3d(-5.0 + i, 0.5, 0.0)) instance = asr.ObjectInstance(instance_name, obj_instance_params, object_name, asr.Transformd(mat), material_names) assembly.object_instances().insert(instance) #------------------------------------------------------------------------ # Assembly instance #------------------------------------------------------------------------ # Create an instance of the assembly and insert it into the scene. assembly_inst = asr.AssemblyInstance("assembly_inst", {}, assembly.get_name()) assembly_inst.transform_sequence().set_transform( 0.0, asr.Transformd(asr.Matrix4d.identity())) scene.assembly_instances().insert(assembly_inst) # Insert the assembly into the scene. scene.assemblies().insert(assembly) #------------------------------------------------------------------------ # Environment #------------------------------------------------------------------------ # Create a color called "gray" and insert it into the scene. Gray = [0.5, 0.5, 0.5] scene.colors().insert( asr.ColorEntity("gray", { 'color_space': 'linear_rgb', 'multiplier': 1.0 }, Gray)) # Create an environment EDF called "gray_edf" and insert it into the scene. scene.environment_edfs().insert( asr.EnvironmentEDF("constant_environment_edf", "gray_edf", {'radiance': 'gray'})) # Create an environment shader called "gray_shader" and insert it into the scene. scene.environment_shaders().insert( asr.EnvironmentShader("edf_environment_shader", "gray_shader", {'environment_edf': 'gray_edf'})) # Create an environment called "sky" and bind it to the scene. scene.set_environment( asr.Environment("sky", { "environment_edf": "gray_edf", "environment_shader": "gray_shader" })) #------------------------------------------------------------------------ # Camera #------------------------------------------------------------------------ params = { 'film_dimensions': asr.Vector2f(0.0640, 0.0200), 'focal_length': 0.035 } camera = asr.Camera("pinhole_camera", "camera", params) mat = asr.Matrix4d.make_translation( asr.Vector3d(-0.444315058060864, -0.071277492791890, 5.674764299781837)) camera.transform_sequence().set_transform(0.0, asr.Transformd(mat)) # Bind the camera to the scene. scene.cameras().insert(camera) #------------------------------------------------------------------------ # Frame #------------------------------------------------------------------------ # Create a frame and bind it to the project. params = {'camera': 'camera', 'resolution': asr.Vector2i(640, 200)} project.set_frame(asr.Frame("beauty", params)) # Bind the scene to the project. project.set_scene(scene) return project
def create_entities(self, scene): as_sky = self.bl_scene.world.appleseed_sky env_type = as_sky.env_type if env_type == 'sunsky': env_type = as_sky.sun_model if env_type == 'constant': self.__colors.append( asr.ColorEntity( 'horizon_radiance_color', {'color_space': 'linear_rgb'}, self._convert_color(self.bl_scene.world.horizon_color))) elif env_type in ('gradient', 'constant_hemisphere'): self.__colors.append( asr.ColorEntity( 'horizon_radiance_color', {'color_space': 'srgb'}, self._convert_color(self.bl_scene.world.horizon_color))) self.__colors.append( asr.ColorEntity( 'zenith_radiance_color', {'color_space': 'linear_rgb'}, self._convert_color(self.bl_scene.world.zenith_color))) if env_type in ('latlong_map', 'mirrorball_map'): try: filename = self.asset_handler.process_path( as_sky.env_tex.filepath, AssetType.TEXTURE_ASSET) except: logger.warning("No Texture Selected!") filename = "" tex_inst_params = { 'addressing_mode': 'wrap', 'filtering_mode': 'bilinear' } self.__env_tex = asr.Texture( 'disk_texture_2d', 'environment_tex', { 'filename': filename, 'color_space': as_sky.env_tex_colorspace }, []) self.__env_tex_inst = asr.TextureInstance( 'environment_tex_inst', tex_inst_params, 'environment_tex', asr.Transformf(asr.Matrix4f.identity())) if env_type == 'latlong_map': edf_params = { 'radiance': "environment_tex_inst", 'radiance_multiplier': as_sky.env_tex_mult, 'exposure': as_sky.env_exposure } elif env_type == 'mirrorball_map': edf_params = { 'radiance': "environment_tex_inst", 'exposure': as_sky.env_exposure, 'radiance_multiplier': as_sky.env_tex_mult } elif env_type == 'constant': edf_params = {'radiance': 'horizon_radiance_color'} elif env_type == 'gradient': edf_params = { 'horizon_radiance': "horizon_radiance_color", 'zenith_radiance': "zenith_radiance_color" } elif env_type == 'constant_hemisphere': edf_params = { 'lower_hemi_radiance': "horizon_radiance_color", 'upper_hemi_radiance': "zenith_radiance_color" } else: edf_params = { 'ground_albedo': as_sky.ground_albedo, 'sun_phi': as_sky.sun_phi, 'sun_theta': as_sky.sun_theta, 'turbidity': as_sky.turbidity, 'turbidity_multiplier': as_sky.turbidity_multiplier, 'luminance_multiplier': as_sky.luminance_multiplier, 'luminance_gamma': as_sky.luminance_gamma, 'saturation_multiplier': as_sky.saturation_multiplier, 'horizon_shift': as_sky.horizon_shift } self.__as_env_edf = asr.EnvironmentEDF(env_type + "_environment_edf", "sky_edf", edf_params) self.__as_env_shader = asr.EnvironmentShader( "edf_environment_shader", "sky_shader", { 'environment_edf': 'sky_edf', 'alpha_value': as_sky.env_alpha }) self.__as_env = asr.Environment("sky", { "environment_edf": "sky_edf", "environment_shader": "sky_shader" }) self.__as_env_edf.transform_sequence().set_transform( 0.0, asr.Transformd(self._convert_matrix(asr.Matrix4d.identity())))