Пример #1
0
void InputBinder::build_assembly_symbol_table(
    const Assembly&                 assembly,
    SymbolTable&                    symbols)
{
    try
    {
        insert_entities(symbols, assembly.colors(), SymbolTable::SymbolColor);
        insert_entities(symbols, assembly.textures(), SymbolTable::SymbolTexture);
        insert_entities(symbols, assembly.texture_instances(), SymbolTable::SymbolTextureInstance);
        insert_entities(symbols, assembly.bsdfs(), SymbolTable::SymbolBSDF);
        insert_entities(symbols, assembly.bssrdfs(), SymbolTable::SymbolBSSRDF);
        insert_entities(symbols, assembly.edfs(), SymbolTable::SymbolEDF);
#ifdef APPLESEED_WITH_OSL
        insert_entities(symbols, assembly.shader_groups(), SymbolTable::SymbolShaderGroup);
#endif
        insert_entities(symbols, assembly.surface_shaders(), SymbolTable::SymbolSurfaceShader);
        insert_entities(symbols, assembly.materials(), SymbolTable::SymbolMaterial);
        insert_entities(symbols, assembly.lights(), SymbolTable::SymbolLight);
        insert_entities(symbols, assembly.objects(), SymbolTable::SymbolObject);
        insert_entities(symbols, assembly.object_instances(), SymbolTable::SymbolObjectInstance);
    }
    catch (const SymbolTable::ExceptionDuplicateSymbol& e)
    {
        RENDERER_LOG_ERROR("duplicate entity \"%s\".", e.string());
        ++m_error_count;
    }
}
Пример #2
0
void InputBinder::bind_assembly_entity_to_input(
    const Scene&                    scene,
    const SymbolTable&              scene_symbols,
    const Assembly&                 assembly,
    const SymbolTable&              assembly_symbols,
    const char*                     entity_type,
    const char*                     entity_name,
    const char*                     param_value,
    InputArray::iterator&           input)
{
    switch (assembly_symbols.lookup(param_value))
    {
      case SymbolTable::SymbolColor:
        bind_color_to_input(
            assembly.colors(),
            param_value,
            input);
        break;

      case SymbolTable::SymbolTextureInstance:
        bind_texture_instance_to_input(
            assembly.textures(),
            assembly.texture_instances(),
            assembly.get_uid(),
            entity_type,
            entity_name,
            param_value,
            input);
        break;

      case SymbolTable::SymbolNotFound:
        // No entity with this name was found in this scope.
        // Attempt to bind the input to a scene entity.
        bind_scene_entity_to_input(
            scene,
            scene_symbols,
            entity_type,
            entity_name,
            param_value,
            input);
        break;

      default:
        RENDERER_LOG_ERROR(
            "while defining %s \"%s\": cannot bind \"%s\" to parameter \"%s\".",
            entity_type,
            entity_name,
            param_value,
            input.name());
        ++m_error_count;
        break;
    }
}
Пример #3
0
    void collect_relations_from_assembly(Assembly& assembly)
    {
        collect_relations_from(assembly.colors());
        collect_relations_from(assembly.textures());
        collect_relations_from(assembly.texture_instances());
        collect_relations_from(assembly.shader_groups());
        collect_relations_from(assembly.assembly_instances());

        collect_relations_from(assembly.bsdfs());
        collect_relations_from(assembly.bssrdfs());
        collect_relations_from(assembly.edfs());
        collect_relations_from(assembly.surface_shaders());
        collect_relations_from(assembly.materials());
        collect_relations_from(assembly.lights());
        collect_relations_from(assembly.objects());
        collect_relations_from(assembly.object_instances());
        collect_relations_from(assembly.volumes());

        for (auto& child_assembly : assembly.assemblies())
            collect_relations_from_assembly(child_assembly);

        // Lights are implicitly referenced by their parent assembly.
        for (auto& light : assembly.lights())
        {
            const InputBinder::ReferencedEntity referenced_entity(assembly.lights(), &light);
            insert_relation(referenced_entity, assembly);
        }

        // Object instances are implicitly referenced by their parent assembly.
        for (auto& object_instance : assembly.object_instances())
        {
            const InputBinder::ReferencedEntity referenced_entity(assembly.object_instances(), &object_instance);
            insert_relation(referenced_entity, assembly);
        }

        // Assembly instances are implicitly referenced by their parent assembly.
        for (auto& assembly_instance : assembly.assembly_instances())
        {
            const InputBinder::ReferencedEntity referenced_entity(assembly.assembly_instances(), &assembly_instance);
            insert_relation(referenced_entity, assembly);
        }
    }
Пример #4
0
    void remove_unused_entities_from_assembly(Assembly& assembly)
    {
        remove_unused_entities_from(assembly.colors());
        remove_unused_entities_from(assembly.textures());
        remove_unused_entities_from(assembly.texture_instances());
        remove_unused_entities_from(assembly.shader_groups());
        remove_unused_entities_from(assembly.assembly_instances());

        remove_unused_entities_from(assembly.bsdfs());
        remove_unused_entities_from(assembly.bssrdfs());
        remove_unused_entities_from(assembly.edfs());
        remove_unused_entities_from(assembly.surface_shaders());
        remove_unused_entities_from(assembly.materials());
        remove_unused_entities_from(assembly.lights());
        remove_unused_entities_from(assembly.objects());
        remove_unused_entities_from(assembly.object_instances());
        remove_unused_entities_from(assembly.volumes());

        for (auto& child_assembly : assembly.assemblies())
            remove_unused_entities_from_assembly(child_assembly);
    }
Пример #5
0
bool InputBinder::try_bind_assembly_entity_to_input(
    const Scene&                    scene,
    const SymbolTable&              scene_symbols,
    const Assembly&                 assembly,
    const SymbolTable&              assembly_symbols,
    const char*                     entity_type,
    const char*                     entity_name,
    const char*                     param_value,
    InputArray::iterator&           input)
{
    if (input.format() == InputFormatEntity)
    {
        #define BIND(symbol, collection)                        \
            case symbol:                                        \
              input.bind(collection.get_by_name(param_value));  \
              return true

        switch (assembly_symbols.lookup(param_value))
        {
          BIND(SymbolTable::SymbolColor, assembly.colors());
          BIND(SymbolTable::SymbolTexture, assembly.textures());
          BIND(SymbolTable::SymbolTextureInstance, assembly.texture_instances());
          BIND(SymbolTable::SymbolBSDF, assembly.bsdfs());
          BIND(SymbolTable::SymbolBSSRDF, assembly.bssrdfs());
          BIND(SymbolTable::SymbolEDF, assembly.edfs());
#ifdef APPLESEED_WITH_OSL
          BIND(SymbolTable::SymbolShaderGroup, assembly.shader_groups());
#endif
          BIND(SymbolTable::SymbolSurfaceShader, assembly.surface_shaders());
          BIND(SymbolTable::SymbolMaterial, assembly.materials());
          BIND(SymbolTable::SymbolLight, assembly.lights());
          BIND(SymbolTable::SymbolObject, assembly.objects());
          BIND(SymbolTable::SymbolObjectInstance, assembly.object_instances());
        }

        #undef BIND
    }
    else
    {
        switch (assembly_symbols.lookup(param_value))
        {
          case SymbolTable::SymbolColor:
            bind_color_to_input(
                assembly.colors(),
                param_value,
                input);
            return true;

          case SymbolTable::SymbolTextureInstance:
            bind_texture_instance_to_input(
                assembly.texture_instances(),
                assembly.get_uid(),
                entity_type,
                entity_name,
                param_value,
                input);
            return true;
        }
    }

    return false;
}
Пример #6
0
void InputBinder::bind_assembly_entities_inputs(
    const Scene&                    scene,
    const SymbolTable&              scene_symbols,
    const Assembly&                 assembly)
{
    // Build the symbol table of the assembly.
    SymbolTable assembly_symbols;
    build_assembly_symbol_table(assembly, assembly_symbols);

    // Push the assembly and its symbol table to the stack.
    AssemblyInfo info;
    info.m_assembly = &assembly;
    info.m_assembly_symbols = &assembly_symbols;
    m_assembly_info.push_back(info);

    // Bind textures to texture instances.
    // Other entities might need to access the textures bound to texture instances,
    // so binding of textures to texture instances must come first.
    for (each<TextureInstanceContainer> i = assembly.texture_instances(); i; ++i)
    {
        i->unbind_texture();

        for (AssemblyInfoIt j = m_assembly_info.rbegin(); j != m_assembly_info.rend(); ++j)
            i->bind_texture(j->m_assembly->textures());

        i->bind_texture(scene.textures());

        i->check_texture();
    }

    // Bind BSDFs inputs.
    for (each<BSDFContainer> i = assembly.bsdfs(); i; ++i)
    {
        bind_assembly_entity_inputs(
            scene,
            scene_symbols,
            SymbolTable::symbol_name(SymbolTable::SymbolBSDF),
            *i);
    }

    // Bind BSSRDFs inputs.
    for (each<BSSRDFContainer> i = assembly.bssrdfs(); i; ++i)
    {
        bind_assembly_entity_inputs(
            scene,
            scene_symbols,
            SymbolTable::symbol_name(SymbolTable::SymbolBSSRDF),
            *i);
    }

    // Bind EDFs inputs.
    for (each<EDFContainer> i = assembly.edfs(); i; ++i)
    {
        bind_assembly_entity_inputs(
            scene,
            scene_symbols,
            SymbolTable::symbol_name(SymbolTable::SymbolEDF),
            *i);
    }

#ifdef APPLESEED_WITH_OSL
    // Bind ShaderGroups inputs.
    for (each<ShaderGroupContainer> i = assembly.shader_groups(); i; ++i)
    {
        bind_assembly_entity_inputs(
            scene,
            scene_symbols,
            SymbolTable::symbol_name(SymbolTable::SymbolShaderGroup),
            *i);
    }
#endif

    // Bind surface shaders inputs.
    for (each<SurfaceShaderContainer> i = assembly.surface_shaders(); i; ++i)
    {
        bind_assembly_entity_inputs(
            scene,
            scene_symbols,
            SymbolTable::symbol_name(SymbolTable::SymbolSurfaceShader),
            *i);
    }

    // Bind materials inputs.
    for (each<MaterialContainer> i = assembly.materials(); i; ++i)
    {
        bind_assembly_entity_inputs(
            scene,
            scene_symbols,
            SymbolTable::symbol_name(SymbolTable::SymbolMaterial),
            *i);
    }

    // Bind lights inputs.
    for (each<LightContainer> i = assembly.lights(); i; ++i)
    {
        bind_assembly_entity_inputs(
            scene,
            scene_symbols,
            SymbolTable::symbol_name(SymbolTable::SymbolLight),
            *i);
    }

    // Bind objects inputs.
    for (each<ObjectContainer> i = assembly.objects(); i; ++i)
    {
        bind_assembly_entity_inputs(
            scene,
            scene_symbols,
            SymbolTable::symbol_name(SymbolTable::SymbolObject),
            *i);
    }

    // Bind objects to object instances. This must be done before binding materials.
    for (each<ObjectInstanceContainer> i = assembly.object_instances(); i; ++i)
    {
        i->unbind_object();

        for (AssemblyInfoIt j = m_assembly_info.rbegin(); j != m_assembly_info.rend(); ++j)
            i->bind_object(j->m_assembly->objects());

        i->check_object();
    }

    // Bind materials to object instances.
    for (each<ObjectInstanceContainer> i = assembly.object_instances(); i; ++i)
    {
        i->unbind_materials();

        for (AssemblyInfoIt j = m_assembly_info.rbegin(); j != m_assembly_info.rend(); ++j)
            i->bind_materials(j->m_assembly->materials());

        i->check_materials();
    }

    // Bind assemblies to assembly instances.
    for (each<AssemblyInstanceContainer> i = assembly.assembly_instances(); i; ++i)
    {
        i->unbind_assembly();

        for (AssemblyInfoIt j = m_assembly_info.rbegin(); j != m_assembly_info.rend(); ++j)
            i->bind_assembly(j->m_assembly->assemblies());

        i->bind_assembly(scene.assemblies());

        i->check_assembly();
    }

    // Recurse into child assemblies.
    for (const_each<AssemblyContainer> i = assembly.assemblies(); i; ++i)
        bind_assembly_entities_inputs(scene, scene_symbols, *i);

    // Pop the information about this assembly from the stack.
    m_assembly_info.pop_back();
}
Пример #7
0
    void initialize_assembly(
        Project&            project,
        Assembly&           assembly,
        const size_t        image_width,
        const size_t        image_height) override
    {
        assembly.textures().insert(
            DiskTexture2dFactory().create(
                "cubes_texture",
                ParamArray()
                    .insert("filename", "heightfield.png")
                    .insert("color_space", "srgb"),
                project.search_paths()));

        assembly.texture_instances().insert(
            TextureInstanceFactory::create(
                "cubes_texture_instance",
                ParamArray()
                    .insert("filtering_mode", "nearest")
                    .insert("addressing_mode", "wrap"),
                "cubes_texture"));

        assembly.bsdfs().insert(
            DisneyBRDFFactory().create(
                "cubes_brdf",
                ParamArray()
                    .insert("anisotropic", 0.0)
                    .insert("base_color", "cubes_texture_instance")
                    .insert("clearcoat", 1.0)
                    .insert("clearcoat_gloss", 0.9)
                    .insert("metallic", 0.0)
                    .insert("roughness", 0.3)
                    .insert("sheen", 0.0)
                    .insert("sheen_tint", 0.0)
                    .insert("specular", 0.9)
                    .insert("specular_tint", 1.0)
                    .insert("subsurface", 1.0)));

        assembly.surface_shaders().insert(
            PhysicalSurfaceShaderFactory().create(
                "physical_surface_shader",
                ParamArray()));

        assembly.materials().insert(
            GenericMaterialFactory().create(
                "cubes_material",
                ParamArray()
                    .insert("surface_shader", "physical_surface_shader")
                    .insert("bsdf", "cubes_brdf")));

        // Load the cube mesh object from disk.
        MeshObjectArray objects;
        MeshObjectReader::read(
            project.search_paths(),
            "cube",
            ParamArray()
                .insert("filename", "cube.obj"),
            objects);
        assert(objects.size() == 1);
        m_cube.reset(objects[0]);

        // Create the baked mesh object.
        m_mesh = MeshObjectFactory().create("cubes", ParamArray());

        // Reserve memory into the baked mesh object.
        const size_t cube_count = image_width * image_height;
        m_mesh->reserve_vertices(m_cube->get_vertex_count() * cube_count);
        m_mesh->reserve_vertex_normals(m_cube->get_vertex_normal_count() * cube_count);
        m_mesh->reserve_tex_coords(cube_count);
        m_mesh->reserve_triangles(m_cube->get_triangle_count() * cube_count);
    }