[Bf-blender-cvs] [a083b23cebe] temp-xr-virtual-camera-experiment: First iteration of a virtual camera node.

Jeroen Bakker noreply at git.blender.org
Wed Nov 2 13:17:50 CET 2022


Commit: a083b23cebee4a35c7b658ce6f5c15bd7db9db58
Author: Jeroen Bakker
Date:   Wed Nov 2 13:17:35 2022 +0100
Branches: temp-xr-virtual-camera-experiment
https://developer.blender.org/rBa083b23cebee4a35c7b658ce6f5c15bd7db9db58

First iteration of a virtual camera node.

===================================================================

M	source/blender/blenkernel/BKE_node.h
M	source/blender/blenkernel/intern/camera.c
M	source/blender/blenkernel/intern/node.cc
M	source/blender/draw/intern/draw_manager_data.cc
M	source/blender/editors/space_node/drawnode.cc
M	source/blender/gpu/CMakeLists.txt
M	source/blender/gpu/GPU_material.h
M	source/blender/gpu/intern/gpu_codegen.cc
M	source/blender/gpu/intern/gpu_node_graph.c
A	source/blender/gpu/shaders/material/gpu_shader_material_virtual_camera.glsl
M	source/blender/makesdna/DNA_camera_types.h
M	source/blender/makesrna/intern/rna_nodetree.c
M	source/blender/nodes/NOD_shader.h
M	source/blender/nodes/NOD_static_types.h
M	source/blender/nodes/shader/CMakeLists.txt
A	source/blender/nodes/shader/nodes/node_shader_virtual_camera.cc

===================================================================

diff --git a/source/blender/blenkernel/BKE_node.h b/source/blender/blenkernel/BKE_node.h
index ecf7a556459..cf78c954e44 100644
--- a/source/blender/blenkernel/BKE_node.h
+++ b/source/blender/blenkernel/BKE_node.h
@@ -1222,6 +1222,7 @@ void BKE_nodetree_remove_layer_n(struct bNodeTree *ntree, struct Scene *scene, i
 #define SH_NODE_COMBINE_COLOR 711
 #define SH_NODE_SEPARATE_COLOR 712
 #define SH_NODE_MIX 713
+#define SH_NODE_VIRTUAL_CAMERA 714
 
 /** \} */
 
diff --git a/source/blender/blenkernel/intern/camera.c b/source/blender/blenkernel/intern/camera.c
index 7c1193d80ab..71ef05e9a4f 100644
--- a/source/blender/blenkernel/intern/camera.c
+++ b/source/blender/blenkernel/intern/camera.c
@@ -137,6 +137,8 @@ static void camera_blend_read_data(BlendDataReader *reader, ID *id)
       bgpic->flag &= ~CAM_BGIMG_FLAG_OVERRIDE_LIBRARY_LOCAL;
     }
   }
+  ca->runtime.virtual_camera_stage = false;
+  ca->runtime.virtual_display_texture = NULL;
 }
 
 static void camera_blend_read_lib(BlendLibReader *reader, ID *id)
diff --git a/source/blender/blenkernel/intern/node.cc b/source/blender/blenkernel/intern/node.cc
index 8f8cd02e119..d6beb423b5a 100644
--- a/source/blender/blenkernel/intern/node.cc
+++ b/source/blender/blenkernel/intern/node.cc
@@ -4667,6 +4667,8 @@ static void registerShaderNodes()
   register_node_type_sh_tex_pointdensity();
   register_node_type_sh_tex_ies();
   register_node_type_sh_tex_white_noise();
+
+  register_node_type_sh_virtual_camera();
 }
 
 static void registerTextureNodes()
diff --git a/source/blender/draw/intern/draw_manager_data.cc b/source/blender/draw/intern/draw_manager_data.cc
index 4aa27e2288c..bae99a945d2 100644
--- a/source/blender/draw/intern/draw_manager_data.cc
+++ b/source/blender/draw/intern/draw_manager_data.cc
@@ -1835,6 +1835,11 @@ void DRW_shgroup_add_material_resources(DRWShadingGroup *grp, GPUMaterial *mater
       DRW_shgroup_uniform_texture_ex(
           grp, tex->sampler_name, *tex->sky, eGPUSamplerState(tex->sampler_state));
     }
+    else if (tex->camera) {
+      /* Sky */
+      DRW_shgroup_uniform_texture_ex(
+          grp, tex->sampler_name, *tex->camera, eGPUSamplerState(tex->sampler_state));
+    }
   }
 
   GPUUniformBuf *ubo = GPU_material_uniform_buffer_get(material);
diff --git a/source/blender/editors/space_node/drawnode.cc b/source/blender/editors/space_node/drawnode.cc
index df31a0342cb..b713b225638 100644
--- a/source/blender/editors/space_node/drawnode.cc
+++ b/source/blender/editors/space_node/drawnode.cc
@@ -432,6 +432,20 @@ static void node_shader_buts_tex_environment(uiLayout *layout, bContext *C, Poin
   node_buts_image_user(layout, C, &iuserptr, &imaptr, &iuserptr, false, true);
 }
 
+static void node_shader_buts_virtual_camera(uiLayout *layout, bContext *C, PointerRNA *ptr)
+{
+  uiTemplateID(layout,
+               C,
+               ptr,
+               "camera",
+               nullptr,
+               nullptr,
+               nullptr,
+               UI_TEMPLATE_ID_FILTER_ALL,
+               false,
+               nullptr);
+}
+
 static void node_shader_buts_tex_environment_ex(uiLayout *layout, bContext *C, PointerRNA *ptr)
 {
   PointerRNA iuserptr = RNA_pointer_get(ptr, "image_user");
@@ -499,6 +513,9 @@ static void node_shader_set_butfunc(bNodeType *ntype)
       ntype->draw_buttons = node_shader_buts_tex_environment;
       ntype->draw_buttons_ex = node_shader_buts_tex_environment_ex;
       break;
+    case SH_NODE_VIRTUAL_CAMERA:
+      ntype->draw_buttons = node_shader_buts_virtual_camera;
+      break;
     case SH_NODE_DISPLACEMENT:
     case SH_NODE_VECTOR_DISPLACEMENT:
       ntype->draw_buttons = node_shader_buts_displacement;
diff --git a/source/blender/gpu/CMakeLists.txt b/source/blender/gpu/CMakeLists.txt
index bfbbf1be225..a636fcb86f0 100644
--- a/source/blender/gpu/CMakeLists.txt
+++ b/source/blender/gpu/CMakeLists.txt
@@ -506,6 +506,7 @@ set(GLSL_SRC
   shaders/material/gpu_shader_material_vector_rotate.glsl
   shaders/material/gpu_shader_material_velvet.glsl
   shaders/material/gpu_shader_material_vertex_color.glsl
+  shaders/material/gpu_shader_material_virtual_camera.glsl
   shaders/material/gpu_shader_material_volume_absorption.glsl
   shaders/material/gpu_shader_material_volume_principled.glsl
   shaders/material/gpu_shader_material_volume_scatter.glsl
diff --git a/source/blender/gpu/GPU_material.h b/source/blender/gpu/GPU_material.h
index 3dad2a1a19a..48eb53d662f 100644
--- a/source/blender/gpu/GPU_material.h
+++ b/source/blender/gpu/GPU_material.h
@@ -35,6 +35,7 @@ struct Material;
 struct Scene;
 struct bNode;
 struct bNodeTree;
+struct Camera;
 
 typedef struct GPUMaterial GPUMaterial;
 typedef struct GPUNode GPUNode;
@@ -178,6 +179,9 @@ GPUNodeLink *GPU_image_sky(GPUMaterial *mat,
                            const float *pixels,
                            float *layer,
                            eGPUSamplerState sampler_state);
+GPUNodeLink *GPU_image_camera(GPUMaterial *mat,
+                              struct Camera *camera,
+                              eGPUSamplerState sampler_state);
 GPUNodeLink *GPU_color_band(GPUMaterial *mat, int size, float *pixels, float *row);
 
 /**
@@ -322,6 +326,7 @@ typedef struct GPUMaterialTexture {
   bool iuser_available;
   struct GPUTexture **colorband;
   struct GPUTexture **sky;
+  struct GPUTexture **camera;
   char sampler_name[32];       /* Name of sampler in GLSL. */
   char tiled_mapping_name[32]; /* Name of tile mapping sampler in GLSL. */
   int users;
diff --git a/source/blender/gpu/intern/gpu_codegen.cc b/source/blender/gpu/intern/gpu_codegen.cc
index 4adeac1b49a..2ce03f88693 100644
--- a/source/blender/gpu/intern/gpu_codegen.cc
+++ b/source/blender/gpu/intern/gpu_codegen.cc
@@ -392,6 +392,10 @@ void GPUCodegen::generate_resources()
       const char *name = info.name_buffer.append_sampler_name(tex->sampler_name);
       info.sampler(0, ImageType::FLOAT_2D_ARRAY, name, Frequency::BATCH);
     }
+    else if (tex->camera) {
+      const char *name = info.name_buffer.append_sampler_name(tex->sampler_name);
+      info.sampler(0, ImageType::FLOAT_2D, name, Frequency::PASS);
+    }
     else if (tex->tiled_mapping_name[0] != '\0') {
       const char *name = info.name_buffer.append_sampler_name(tex->sampler_name);
       info.sampler(slot++, ImageType::FLOAT_2D_ARRAY, name, Frequency::BATCH);
diff --git a/source/blender/gpu/intern/gpu_node_graph.c b/source/blender/gpu/intern/gpu_node_graph.c
index c72e7097b33..17136308cdd 100644
--- a/source/blender/gpu/intern/gpu_node_graph.c
+++ b/source/blender/gpu/intern/gpu_node_graph.c
@@ -12,6 +12,7 @@
 
 #include "MEM_guardedalloc.h"
 
+#include "DNA_camera_types.h"
 #include "DNA_node_types.h"
 
 #include "BLI_ghash.h"
@@ -470,6 +471,7 @@ static GPUMaterialTexture *gpu_node_graph_add_texture(GPUNodeGraph *graph,
                                                       ImageUser *iuser,
                                                       struct GPUTexture **colorband,
                                                       struct GPUTexture **sky,
+                                                      struct GPUTexture **camera,
                                                       GPUNodeLinkType link_type,
                                                       eGPUSamplerState sampler_state)
 {
@@ -478,7 +480,7 @@ static GPUMaterialTexture *gpu_node_graph_add_texture(GPUNodeGraph *graph,
   GPUMaterialTexture *tex = graph->textures.first;
   for (; tex; tex = tex->next) {
     if (tex->ima == ima && tex->colorband == colorband && tex->sky == sky &&
-        tex->sampler_state == sampler_state) {
+        tex->camera == camera && tex->sampler_state == sampler_state) {
       break;
     }
     num_textures++;
@@ -625,7 +627,23 @@ GPUNodeLink *GPU_image(GPUMaterial *mat,
   GPUNodeLink *link = gpu_node_link_create();
   link->link_type = GPU_NODE_LINK_IMAGE;
   link->texture = gpu_node_graph_add_texture(
-      graph, ima, iuser, NULL, NULL, link->link_type, sampler_state);
+      graph, ima, iuser, NULL, NULL, NULL, link->link_type, sampler_state);
+  return link;
+}
+
+GPUNodeLink *GPU_image_camera(GPUMaterial *mat, Camera *camera, eGPUSamplerState sampler_state)
+{
+  GPUNodeGraph *graph = gpu_material_node_graph(mat);
+  GPUNodeLink *link = gpu_node_link_create();
+  link->link_type = GPU_NODE_LINK_IMAGE;
+  link->texture = gpu_node_graph_add_texture(graph,
+                                             NULL,
+                                             NULL,
+                                             NULL,
+                                             NULL,
+                                             &camera->runtime.virtual_display_texture,
+                                             link->link_type,
+                                             sampler_state);
   return link;
 }
 
@@ -642,7 +660,7 @@ GPUNodeLink *GPU_image_sky(GPUMaterial *mat,
   GPUNodeLink *link = gpu_node_link_create();
   link->link_type = GPU_NODE_LINK_IMAGE_SKY;
   link->texture = gpu_node_graph_add_texture(
-      graph, NULL, NULL, NULL, sky, link->link_type, sampler_state);
+      graph, NULL, NULL, NULL, sky, NULL, link->link_type, sampler_state);
   return link;
 }
 
@@ -655,7 +673,7 @@ GPUNodeLink *GPU_image_tiled(GPUMaterial *mat,
   GPUNodeLink *link = gpu_node_link_create();
   link->link_type = GPU_NODE_LINK_IMAGE_TILED;
   link->texture = gpu_node_graph_add_texture(
-      graph, ima, iuser, NULL, NULL, link->link_type, sampler_state);
+      graph, ima, iuser, NULL, NULL, NULL, link->link_type, sampler_state);
   return link;
 }
 
@@ -665,7 +683,7 @@ GPUNodeLink *GPU_image_tiled_mapping(GPUMaterial *mat, Image *ima, ImageUser *iu
   GPUNodeLink *link = gpu_node_link_create();
   link->link_type = GPU_NODE_LINK_IMAGE_TILED_MAPPING;
   link->texture = gpu_node_graph_add_texture(
-      graph, ima, iuser, NULL, NULL, link->link_type, GPU_SAMPLER_MAX);
+      graph, ima, iuser, NULL, NULL, NULL, link->link_type, GPU_SAMPLER_MAX);
   return link;
 }
 
@@ -678,7 +696,7 @@ GPUNodeLink *GPU_color_band(GPUMaterial *mat, int size, float *pixels, float *ro
   GPUNodeLink *link = gpu_node_link_create();
   link->link_type = GPU_NODE_LINK_COLORBAND;
   link->textur

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list