Blender V4.3
node_shader_preview.cc File Reference
#include "BLI_string.h"
#include "DNA_camera_types.h"
#include "DNA_material_types.h"
#include "DNA_world_types.h"
#include "RNA_access.hh"
#include "RNA_prototypes.hh"
#include "BKE_colortools.hh"
#include "BKE_compute_contexts.hh"
#include "BKE_context.hh"
#include "BKE_global.hh"
#include "BKE_layer.hh"
#include "BKE_lib_id.hh"
#include "BKE_main.hh"
#include "BKE_material.h"
#include "BKE_node.hh"
#include "BKE_node_runtime.hh"
#include "BKE_node_tree_update.hh"
#include "DEG_depsgraph.hh"
#include "IMB_imbuf.hh"
#include "WM_api.hh"
#include "ED_node_preview.hh"
#include "ED_render.hh"
#include "ED_screen.hh"
#include "node_intern.hh"

Go to the source code of this file.

Classes

struct  blender::ed::space_node::ShaderNodesPreviewJob
 

Namespaces

namespace  blender
 
namespace  blender::ed
 
namespace  blender::ed::space_node
 

Typedefs

Local Structs
using blender::ed::space_node::NodeSocketPair = std::pair<bNode *, bNodeSocket *>
 

Functions

Compute Context functions
static void blender::ed::space_node::ensure_nodetree_previews (const bContext &C, NestedTreePreviews &tree_previews, Material &material, ListBase &treepath)
 
static std::optional< ComputeContextHashblender::ed::space_node::get_compute_context_hash_for_node_editor (const SpaceNode &snode)
 
NestedTreePreviewsblender::ed::space_node::get_nested_previews (const bContext &C, SpaceNode &snode)
 
Preview scene
static Materialblender::ed::space_node::duplicate_material (const Material &mat)
 
static Sceneblender::ed::space_node::preview_prepare_scene (const Main *bmain, const Scene *scene_orig, Main *pr_main, Material *mat_copy, ePreviewType preview_type)
 
Preview rendering
static bNodeSocketblender::ed::space_node::node_find_preview_socket (bNodeTree &ntree, bNode &node)
 
static bool blender::ed::space_node::socket_use_aov (const bNodeSocket *socket)
 
static bool blender::ed::space_node::node_use_aov (bNodeTree &ntree, const bNode *node)
 
static ImBufblender::ed::space_node::get_image_from_viewlayer_and_pass (RenderResult &rr, const char *layer_name, const char *pass_name)
 
ImBufblender::ed::space_node::node_preview_acquire_ibuf (bNodeTree &ntree, NestedTreePreviews &tree_previews, const bNode &node)
 
void blender::ed::space_node::node_release_preview_ibuf (NestedTreePreviews &tree_previews)
 
static void blender::ed::space_node::connect_nested_node_to_node (const Span< bNodeTreePath * > treepath, bNode &nested_node, bNodeSocket &nested_socket, bNode &final_node, bNodeSocket &final_socket, const char *route_name)
 
static void blender::ed::space_node::connect_node_to_surface_output (const Span< bNodeTreePath * > treepath, NodeSocketPair nodesocket, bNode &output_node)
 
static void blender::ed::space_node::connect_nodes_to_aovs (const Span< bNodeTreePath * > treepath, const Span< NodeSocketPair > nodesocket_span)
 
static bool blender::ed::space_node::nodetree_previews_break (void *spv)
 
static bool blender::ed::space_node::prepare_viewlayer_update (void *pvl_data, ViewLayer *vl, Depsgraph *depsgraph)
 
static void blender::ed::space_node::all_nodes_preview_update (void *npv, RenderResult *rr, rcti *)
 
static void blender::ed::space_node::preview_render (ShaderNodesPreviewJob &job_data)
 
Preview job management
static void blender::ed::space_node::update_needed_flag (NestedTreePreviews &tree_previews, const bNodeTree &nt, ePreviewType preview_type)
 
static void blender::ed::space_node::shader_preview_startjob (void *customdata, wmJobWorkerStatus *worker_status)
 
static void blender::ed::space_node::shader_preview_free (void *customdata)
 
void blender::ed::space_node::free_previews (wmWindowManager &wm, SpaceNode &snode)
 

Detailed Description

This file implements shader node previews which rely on a structure owned by each SpaceNode. We take advantage of the RenderResult available as ImBuf images to store a Render for every viewed nested node tree present in a SpaceNode. The computation is initiated at the moment of drawing nodes overlays. One render is started for the current nodetree, having a ViewLayer associated with each previewed node.

We separate the previewed nodes in two categories: the shader ones and the non-shader ones.

  • for non-shader nodes, we use AOVs(Arbitrary Output Variable) which highly speed up the rendering process by rendering every non-shader node at the same time. They are rendered in the first ViewLayer.
  • for shader nodes, we render them each in a different ViewLayer, by routing the node to the output of the material in the preview scene.

At the moment of drawing, we take the Render of the viewed node tree and extract the ImBuf of the wanted viewlayer/pass for each previewed node.

Definition in file node_shader_preview.cc.