[Bf-blender-cvs] [70a39f484f8] tmp-workbench-rewrite2: textures

Miguel Pozo noreply at git.blender.org
Tue Oct 11 21:33:08 CEST 2022


Commit: 70a39f484f8ca34a05f4d0418f74373669ed709b
Author: Miguel Pozo
Date:   Tue Oct 11 19:29:42 2022 +0200
Branches: tmp-workbench-rewrite2
https://developer.blender.org/rB70a39f484f8ca34a05f4d0418f74373669ed709b

textures

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

M	source/blender/draw/engines/workbench/workbench_engine.cc
M	source/blender/draw/engines/workbench/workbench_mesh_passes.cc
M	source/blender/draw/engines/workbench/workbench_private.hh

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

diff --git a/source/blender/draw/engines/workbench/workbench_engine.cc b/source/blender/draw/engines/workbench/workbench_engine.cc
index 3f3d35aad1b..ab20ad49e6a 100644
--- a/source/blender/draw/engines/workbench/workbench_engine.cc
+++ b/source/blender/draw/engines/workbench/workbench_engine.cc
@@ -225,7 +225,7 @@ class Instance {
           }
           ResourceHandle handle = manager.resource_handle(ob_ref);
           resources.material_buf.get_or_resize(handle.resource_index()) = Material(*mat);
-          pipeline_get(ob_ref, mat).draw(batches[i], handle);
+          pipeline_get(ob_ref, mat, i + 1).draw(batches[i], handle);
         }
       }
     }
@@ -254,10 +254,12 @@ class Instance {
     }
   }
 
-  PassMain::Sub &pipeline_get(ObjectRef &ob_ref, ::Material *material = nullptr)
+  PassMain::Sub &pipeline_get(ObjectRef &ob_ref,
+                              ::Material *material = nullptr,
+                              int material_index = 0)
   {
     return opaque_ps.gbuffer_ps_.sub_pass_get(
-        geometry_type_from_object(ob_ref.object), ob_ref, material);
+        geometry_type_from_object(ob_ref.object), ob_ref, material, material_index);
   }
 
   Span<GPUBatch *> geometry_get(ObjectRef &ob_ref, int material_count)
diff --git a/source/blender/draw/engines/workbench/workbench_mesh_passes.cc b/source/blender/draw/engines/workbench/workbench_mesh_passes.cc
index b5ea221ac9f..de1558d6d78 100644
--- a/source/blender/draw/engines/workbench/workbench_mesh_passes.cc
+++ b/source/blender/draw/engines/workbench/workbench_mesh_passes.cc
@@ -2,6 +2,13 @@
 
 #include "workbench_private.hh"
 
+/* get_image */
+#include "DNA_node_types.h"
+#include "ED_uvedit.h"
+//#include "BKE_image.h"
+#include "BKE_node.h"
+/* get_image */
+
 namespace blender::workbench {
 
 MeshPass::MeshPass(const char *name) : PassMain(name){};
@@ -38,20 +45,77 @@ void MeshPass::init(ePipelineType pipeline,
   }
 }
 
+void get_image(Object *ob,
+               int material_index,
+               ::Image *&image,
+               GPUTexture *&texture,
+               GPUTexture *&tilemap,
+               eGPUSamplerState &sampler_state)
+{
+  ::bNode *node = nullptr;
+  ImageUser *user = nullptr;
+
+  ED_object_get_active_image(ob, material_index, &image, &user, &node, nullptr);
+  if (node && image) {
+    switch (node->type) {
+      case SH_NODE_TEX_IMAGE: {
+        NodeTexImage *storage = static_cast<NodeTexImage *>(node->storage);
+        const bool use_filter = (storage->interpolation != SHD_INTERP_CLOSEST);
+        const bool use_repeat = (storage->extension == SHD_IMAGE_EXTENSION_REPEAT);
+        const bool use_clip = (storage->extension == SHD_IMAGE_EXTENSION_CLIP);
+        SET_FLAG_FROM_TEST(sampler_state, use_filter, GPU_SAMPLER_FILTER);
+        SET_FLAG_FROM_TEST(sampler_state, use_repeat, GPU_SAMPLER_REPEAT);
+        SET_FLAG_FROM_TEST(sampler_state, use_clip, GPU_SAMPLER_CLAMP_BORDER);
+        break;
+      }
+      case SH_NODE_TEX_ENVIRONMENT: {
+        NodeTexEnvironment *storage = static_cast<NodeTexEnvironment *>(node->storage);
+        const bool use_filter = (storage->interpolation != SHD_INTERP_CLOSEST);
+        SET_FLAG_FROM_TEST(sampler_state, use_filter, GPU_SAMPLER_FILTER);
+        break;
+      }
+      default:
+        BLI_assert_msg(0, "Node type not supported by workbench");
+    }
+  }
+
+  if (image) {
+    if (image->source == IMA_SRC_TILED) {
+      texture = BKE_image_get_gpu_tiles(image, user, nullptr);
+      tilemap = BKE_image_get_gpu_tilemap(image, user, nullptr);
+    }
+    else {
+      texture = BKE_image_get_gpu_texture(image, user, nullptr);
+    }
+  }
+}
+
 PassMain::Sub &MeshPass::sub_pass_get(eGeometryType geometry_type,
-                                      ObjectRef & /*ref*/,
-                                      ::Material * /*material*/)
+                                      ObjectRef &ref,
+                                      ::Material * /*material*/,
+                                      int material_index)
 {
   if (color_type_ == eColorType::TEXTURE) {
     /* TODO(fclem): Always query a layered texture so we can use only a single shader. */
-    GPUTexture *texture = nullptr;  // ref.object->texture_get();
-    GPUTexture *tilemap = nullptr;  // ref.object->texture_get();
+    ::Image *image = nullptr;
+    GPUTexture *texture = nullptr;
+    GPUTexture *tilemap = nullptr;
+    eGPUSamplerState sampler_state = GPU_SAMPLER_DEFAULT;
+    StringRefNull name = "Null Texture";
+    get_image(ref.object, material_index, image, texture, tilemap, sampler_state);
+    if (image) {
+      /* TODO(pragma37): Should be lib.name + name ??? */
+      name = image->id.name;
+    }
 
     auto add_cb = [&] {
       PassMain::Sub *sub_pass = geometry_passes_[static_cast<int>(geometry_type)];
-      sub_pass = &sub_pass->sub("Blender Texture Name" /* texture.name */);
-      sub_pass->bind_texture(WB_TEXTURE_SLOT, texture);
+      sub_pass = &sub_pass->sub(name.c_str());
+      sub_pass->bind_texture(WB_TEXTURE_SLOT, texture, sampler_state);
       sub_pass->bind_texture(WB_TILEMAP_SLOT, tilemap);
+      sub_pass->push_constant("imagePremult", image && image->alpha_mode == IMA_ALPHA_PREMUL);
+      /*TODO(pragma37): What's the point? This could be a constant in the shader. */
+      sub_pass->push_constant("imageTransparencyCutoff", 0.1f);
       return sub_pass;
     };
 
diff --git a/source/blender/draw/engines/workbench/workbench_private.hh b/source/blender/draw/engines/workbench/workbench_private.hh
index 73e3d12387e..e5037c31ee5 100644
--- a/source/blender/draw/engines/workbench/workbench_private.hh
+++ b/source/blender/draw/engines/workbench/workbench_private.hh
@@ -76,7 +76,10 @@ class MeshPass : public PassMain {
             SceneResources &resources,
             DRWState state);
 
-  PassMain::Sub &sub_pass_get(eGeometryType geometry_type, ObjectRef &ref, ::Material *material);
+  PassMain::Sub &sub_pass_get(eGeometryType geometry_type,
+                              ObjectRef &ref,
+                              ::Material *material,
+                              int material_index = 0);
 };
 
 class OpaquePass {



More information about the Bf-blender-cvs mailing list