void MainWindow::update_override_shading_menu_item() { const ParamArray project_params = get_project_params("interactive"); const ParamArray shading_engine_params = project_params.child("shading_engine"); if (shading_engine_params.dictionaries().exist("override_shading")) { const string shading_mode = shading_engine_params.child("override_shading").get_optional<string>("mode", "coverage"); for (const_each<QList<QAction*> > i = m_ui->menu_diagnostics_override_shading->actions(); i; ++i) { QAction* action = *i; if (action->data().toString().toStdString() == shading_mode) { action->activate(QAction::Trigger); break; } } } else { m_ui->action_diagnostics_override_shading_no_override->activate(QAction::Trigger); } }
void ShadingEngine::create_diagnostic_surface_shader(const ParamArray& params) { if (params.dictionaries().exist("override_shading")) { m_diagnostic_surface_shader = DiagnosticSurfaceShaderFactory().create( "__diagnostic_surface_shader", params.child("override_shading")); } }
ObjectInstance::ObjectInstance( const char* name, const ParamArray& params, const char* object_name, const Transformd& transform, const StringDictionary& front_material_mappings, const StringDictionary& back_material_mappings) : Entity(g_class_uid, params) , impl(new Impl()) { set_name(name); impl->m_transform = transform; impl->m_object_name = object_name; impl->m_front_material_mappings = front_material_mappings; impl->m_back_material_mappings = back_material_mappings; const EntityDefMessageContext message_context("object instance", this); // Retrieve visibility flags. m_vis_flags = VisibilityFlags::parse(params.child("visibility"), message_context); // Retrieve medium priority. m_medium_priority = params.get_optional<uint8>("medium_priority", 0); // Retrieve ray bias method. const string ray_bias_method = params.get_optional<string>( "ray_bias_method", "none", make_vector("none", "normal", "incoming_direction", "outgoing_direction"), message_context); if (ray_bias_method == "none") m_ray_bias_method = RayBiasMethodNone; else if (ray_bias_method == "normal") m_ray_bias_method = RayBiasMethodNormal; else if (ray_bias_method == "incoming_direction") m_ray_bias_method = RayBiasMethodIncomingDirection; else m_ray_bias_method = RayBiasMethodOutgoingDirection; // Retrieve ray bias distance. m_ray_bias_distance = params.get_optional<double>("ray_bias_distance", 0.0); // No bound object yet. m_object = 0; }
// Initialize rendering components and render a frame. IRendererController::Status initialize_and_render_frame() { // Construct an abort switch that will allow to abort initialization or rendering. RendererControllerAbortSwitch abort_switch(*m_renderer_controller); // Create the texture store. TextureStore texture_store( *m_project.get_scene(), m_params.child("texture_store")); // Initialize OSL's shading system. if (!initialize_osl_shading_system(texture_store, abort_switch) || abort_switch.is_aborted()) { // If it wasn't an abort, it was a failure. return abort_switch.is_aborted() ? m_renderer_controller->get_status() : IRendererController::AbortRendering; } // Let scene entities perform their pre-render actions. Don't proceed if that failed. // This is done before creating renderer components because renderer components need // to access the scene's render data such as the scene's bounding box. OnRenderBeginRecorder recorder; if (!m_project.get_scene()->on_render_begin(m_project, nullptr, recorder, &abort_switch) || abort_switch.is_aborted()) { recorder.on_render_end(m_project); return m_renderer_controller->get_status(); } // Create renderer components. RendererComponents components( m_project, m_params, m_tile_callback_factory, texture_store, *m_texture_system, *m_shading_system); if (!components.create()) { recorder.on_render_end(m_project); return IRendererController::AbortRendering; } // Print renderer components settings. components.print_settings(); // Report whether Embree is used or not. #ifdef APPLESEED_WITH_EMBREE const bool use_embree = m_params.get_optional<bool>("use_embree", false); m_project.set_use_embree(use_embree); #else const bool use_embree = false; #endif if (use_embree) RENDERER_LOG_INFO("using Intel Embree ray tracing kernel."); else RENDERER_LOG_INFO("using built-in ray tracing kernel."); // Updating the trace context causes ray tracing acceleration structures to be updated or rebuilt. m_project.update_trace_context(); // Load the checkpoint if any. Frame& frame = *m_project.get_frame(); const size_t pass_count = m_params.get_optional<size_t>("passes", 1); if (!frame.load_checkpoint(&components.get_shading_result_framebuffer_factory(), pass_count)) { recorder.on_render_end(m_project); return IRendererController::AbortRendering; } // Let renderer components perform their pre-render actions. Don't proceed if that failed. if (!components.on_render_begin(recorder, &abort_switch) || abort_switch.is_aborted()) { recorder.on_render_end(m_project); return m_renderer_controller->get_status(); } // Execute the main rendering loop. const auto status = render_frame(components, abort_switch); // Perform post-render actions. recorder.on_render_end(m_project); // End light path recording. const CanvasProperties& props = m_project.get_frame()->image().properties(); m_project.get_light_path_recorder().finalize( props.m_canvas_width, props.m_canvas_height); // Print texture store performance statistics. RENDERER_LOG_DEBUG("%s", texture_store.get_statistics().to_string().c_str()); return status; }
// Initialize OSL's shading system. bool initialize_osl_shading_system( TextureStore& texture_store, IAbortSwitch& abort_switch) { // Construct a search paths string from the project's search paths. const string project_search_paths = to_string(m_project.search_paths().to_string_reversed(SearchPaths::osl_path_separator())); // Initialize OIIO. const size_t texture_cache_size_bytes = m_params.child("texture_store").get_optional<size_t>( "max_size", TextureStore::get_default_size()); RENDERER_LOG_INFO( "setting oiio texture cache size to %s.", pretty_size(texture_cache_size_bytes).c_str()); const float texture_cache_size_mb = static_cast<float>(texture_cache_size_bytes) / (1024 * 1024); m_texture_system->attribute("max_memory_MB", texture_cache_size_mb); // Set OIIO search paths. string prev_oiio_search_path; m_texture_system->getattribute("searchpath", prev_oiio_search_path); if (prev_oiio_search_path != project_search_paths) { RENDERER_LOG_INFO("setting oiio search paths to %s", project_search_paths.c_str()); m_texture_system->invalidate_all(true); m_texture_system->attribute("searchpath", project_search_paths); } // Also use the project search paths to look for OpenImageIO plugins. m_texture_system->attribute("plugin_searchpath", project_search_paths); // Initialize OSL. m_renderer_services->initialize(texture_store); // Set OSL search paths. string prev_osl_search_paths; m_shading_system->getattribute("searchpath:shader", prev_osl_search_paths); if (prev_osl_search_paths != project_search_paths) { RENDERER_LOG_INFO("setting osl shader search paths to %s", project_search_paths.c_str()); m_project.get_scene()->release_optimized_osl_shader_groups(); m_shading_system->attribute("searchpath:shader", project_search_paths); } // Initialize the shader compiler, if the OSL headers are found. if (m_resource_search_paths.exist("stdosl.h")) { const APIString stdosl_path = m_resource_search_paths.qualify("stdosl.h"); RENDERER_LOG_INFO("found OSL headers in %s", stdosl_path.c_str()); m_osl_compiler = ShaderCompilerFactory::create(stdosl_path.c_str()); } else RENDERER_LOG_INFO("OSL headers not found."); // Re-optimize shader groups that need updating. return m_project.get_scene()->create_optimized_osl_shader_groups( *m_shading_system, m_osl_compiler.get(), &abort_switch); }