[Bf-blender-cvs] [c9e4453] compositor-2016: Added a prototype for the blur node, to test the needs for sampling

Jeroen Bakker noreply at git.blender.org
Wed Jun 1 20:30:14 CEST 2016


Commit: c9e445313ce7bc45e208715d2255b7dda6e5a08a
Author: Jeroen Bakker
Date:   Tue May 24 22:46:19 2016 +0200
Branches: compositor-2016
https://developer.blender.org/rBc9e445313ce7bc45e208715d2255b7dda6e5a08a

Added a prototype for the blur node, to test the needs for sampling

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

M	source/blender/compositor/cmp/cmp_compositor.cpp
M	source/blender/compositor/cmp/cmp_node.cpp
M	source/blender/compositor/device/device_cpu.cpp
A	source/blender/compositor/kernel/cvm/cvm_node_blur.h
M	source/blender/compositor/kernel/cvm/cvm_node_renderlayer.h
M	source/blender/compositor/kernel/cvm/cvm_nodes.h
M	source/blender/compositor/kernel/kernel_functions.h

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

diff --git a/source/blender/compositor/cmp/cmp_compositor.cpp b/source/blender/compositor/cmp/cmp_compositor.cpp
index a4251b8..6829c17 100644
--- a/source/blender/compositor/cmp/cmp_compositor.cpp
+++ b/source/blender/compositor/cmp/cmp_compositor.cpp
@@ -64,7 +64,7 @@ void COM_execute(RenderData *rd, Scene *scene, bNodeTree *editingtree, int rende
         if (y_max > height) y_max = height;
 
         Compositor::Device::Task* task = new Compositor::Device::Task(node, x, y, x_max, y_max, &output);
-        task->max_iteration = 5;
+        task->max_iteration = 100;
         tasks[tile_index++] = task;
       }
     }
diff --git a/source/blender/compositor/cmp/cmp_node.cpp b/source/blender/compositor/cmp/cmp_node.cpp
index 7cb9673..aaf4747 100644
--- a/source/blender/compositor/cmp/cmp_node.cpp
+++ b/source/blender/compositor/cmp/cmp_node.cpp
@@ -39,6 +39,15 @@ namespace Compositor {
         this->var_int_0 = node->custom1;
         break;
 
+      case CMP_NODE_BLUR:
+        {
+          NodeBlurData *data = (NodeBlurData *)node->storage;
+          // TODO: other elemetns in the data including needed conversions.
+          this->var_float_0 = data->percentx/100.f;
+          this->var_float_1 = data->percenty/100.f;
+        }
+        break;
+
       case CMP_NODE_VALUE:
         PointerRNA ptr;
         RNA_pointer_create((ID *)node_tree, &RNA_NodeSocket, node->outputs.first, &ptr);
diff --git a/source/blender/compositor/device/device_cpu.cpp b/source/blender/compositor/device/device_cpu.cpp
index f3f873f..be030e6 100644
--- a/source/blender/compositor/device/device_cpu.cpp
+++ b/source/blender/compositor/device/device_cpu.cpp
@@ -92,7 +92,7 @@ namespace Compositor {
       // perform task
       KernelGlobal globals;
       globals.phase = KG_PHASE_REFINE;
-      globals.subpixel_samples_xy = 2;
+      globals.subpixel_samples_xy = 1;
 
       Node* node = task->node;
       const int curr_iteration = task->iteration;
diff --git a/source/blender/compositor/kernel/cvm/cvm_node_blur.h b/source/blender/compositor/kernel/cvm/cvm_node_blur.h
new file mode 100644
index 0000000..4e17ca4
--- /dev/null
+++ b/source/blender/compositor/kernel/cvm/cvm_node_blur.h
@@ -0,0 +1,12 @@
+
+CVM_float4_node_start(blur)
+
+  float blur_size = 100.f * node.var_float_0;
+  float2 move = (rand_float2(xy) * 2.f - 1.f) * blur_size;
+  if (length(move) <= blur_size)
+    return CVM_float4_node_call(0, xy+move);
+
+  // return CVM_float4_node_call(0, xy);
+  return make_float4(0.f, 0.f, 0.f, 0.f);
+
+CVM_float4_node_end
diff --git a/source/blender/compositor/kernel/cvm/cvm_node_renderlayer.h b/source/blender/compositor/kernel/cvm/cvm_node_renderlayer.h
index b5661dc..f7cee8b 100644
--- a/source/blender/compositor/kernel/cvm/cvm_node_renderlayer.h
+++ b/source/blender/compositor/kernel/cvm/cvm_node_renderlayer.h
@@ -1,6 +1,13 @@
 CVM_float4_node_start(renderlayer)
   // TODO: make generic for GLSL and CPU.
-  int offset = ((int)xy.y) * textures[node.texture_index].width + ((int)xy.x);
+  int width = textures[node.texture_index].width;
+  int height = textures[node.texture_index].height;
+
+  if (xy.x < 0 || xy.y < 0 || xy.x >= width || xy.y >= height) {
+    return make_float4(0.0,0.0,0.0,0.0);
+  }
+
+  int offset = ((int)xy.y) * width + ((int)xy.x);
   offset *= 4;
   return make_float4(
     textures[node.texture_index].buffer[offset+0],
diff --git a/source/blender/compositor/kernel/cvm/cvm_nodes.h b/source/blender/compositor/kernel/cvm/cvm_nodes.h
index c9d42d3..05b953a 100644
--- a/source/blender/compositor/kernel/cvm/cvm_nodes.h
+++ b/source/blender/compositor/kernel/cvm/cvm_nodes.h
@@ -21,6 +21,7 @@ float4 node_execute_float4(KernelGlobal global, int node_offset, float2 xy);
 #include "cvm_node_mix.h"
 #include "cvm_node_viewer.h"
 #include "cvm_node_dummy.h"
+#include "cvm_node_blur.h"
 #include "cvm_node_renderlayer.h"
 
 #ifdef CMP_DEVICE_CPU
@@ -39,7 +40,10 @@ float4 node_execute_float4(KernelGlobal global, int node_offset, float2 xy) {
       return node_execute_color(global, node, xy);
 
     case CMP_NODE_MIX_RGB:
-        return node_execute_mix(global, node, xy);
+      return node_execute_mix(global, node, xy);
+
+    case CMP_NODE_BLUR:
+      return node_execute_blur(global, node, xy);
 
     default:
       return CVM_ERROR;
diff --git a/source/blender/compositor/kernel/kernel_functions.h b/source/blender/compositor/kernel/kernel_functions.h
index 67d662b..c365ba3 100644
--- a/source/blender/compositor/kernel/kernel_functions.h
+++ b/source/blender/compositor/kernel/kernel_functions.h
@@ -6,12 +6,23 @@ __cvm_inline float2 make_float2(float x, float y) { return (float2){x, y}; }
 __cvm_inline float4 make_float4(float x, float y, float z, float w) { return (float4){x, y, z, w}; }
 
 
+__cvm_inline float2 operator*(const float2 a, float f) { return make_float2(a.x*f, a.y*f); }
+__cvm_inline float2 operator+(const float2 a, const float2 b) { return make_float2(a.x+b.x, a.y+b.y); }
+__cvm_inline float2 operator-(const float2 a, float f) { return make_float2(a.x-f, a.y-f); }
+#include <cmath>
+__cvm_inline float length(float2 a) { return std::sqrt(a.x*a.x + a.y*a.y); }
+
 __cvm_inline float4 operator*(const float4 a, float f) { return make_float4(a.x*f, a.y*f, a.z*f, a.w*f); }
 __cvm_inline float4 operator/(const float4 a, int i) { return make_float4(a.x/i, a.y/i, a.z/i, a.w/i); }
 __cvm_inline float4 operator/(const float4 a, float f) { return make_float4(a.x/f, a.y*f, a.z*f, a.w*f); }
 __cvm_inline float4 operator+(const float4 a, const float4 b) { return make_float4(a.x+b.x, a.y+b.y, a.z+b.z, a.w+b.w); }
 __cvm_inline float4 operator+=(float4& a, const float4& b) { return a = a + b; }
 
+
+#include <cstdlib>
+float rand_float(float2 uv) { return static_cast <float> (std::rand()) / static_cast <float> (RAND_MAX); }
+float2 rand_float2(float2 uv) { return make_float2(rand_float(uv), rand_float(uv)); }
+
 #ifndef node_stack
 Node node_stack[CMP_MAX_NODE_STACK];
 Texture textures[CMP_MAX_TEXTURES];




More information about the Bf-blender-cvs mailing list