[Bf-blender-cvs] [6792499] soc-2016-cycles_denoising: Cycles: Move denoising utility functions into a separate file
Lukas Stockner
noreply at git.blender.org
Wed Aug 10 03:22:20 CEST 2016
Commit: 6792499894b68642539137554b80fe741554e9d8
Author: Lukas Stockner
Date: Mon Aug 8 23:57:27 2016 +0200
Branches: soc-2016-cycles_denoising
https://developer.blender.org/rB6792499894b68642539137554b80fe741554e9d8
Cycles: Move denoising utility functions into a separate file
===================================================================
M intern/cycles/kernel/CMakeLists.txt
M intern/cycles/kernel/kernel_filter.h
A intern/cycles/kernel/kernel_filter_util.h
===================================================================
diff --git a/intern/cycles/kernel/CMakeLists.txt b/intern/cycles/kernel/CMakeLists.txt
index ced16b1..0c44530 100644
--- a/intern/cycles/kernel/CMakeLists.txt
+++ b/intern/cycles/kernel/CMakeLists.txt
@@ -57,6 +57,7 @@ set(SRC_HEADERS
kernel_film.h
kernel_filter.h
kernel_filter_pre.h
+ kernel_filter_util.h
kernel_globals.h
kernel_jitter.h
kernel_light.h
diff --git a/intern/cycles/kernel/kernel_filter.h b/intern/cycles/kernel/kernel_filter.h
index 7a847d6..81d52d9 100644
--- a/intern/cycles/kernel/kernel_filter.h
+++ b/intern/cycles/kernel/kernel_filter.h
@@ -14,8 +14,8 @@
* limitations under the License.
*/
-#include "util_math_matrix.h"
#include "kernel_filter_pre.h"
+#include "kernel_filter_util.h"
CCL_NAMESPACE_BEGIN
@@ -23,114 +23,6 @@ CCL_NAMESPACE_BEGIN
#define NORM_FEATURE_OFFSET 2
#define NORM_FEATURE_NUM 8
-#define ccl_get_feature(pass) buffer[(pass)*pass_stride]
-
-#define FOR_PIXEL_WINDOW pixel_buffer = buffer + (low.y - rect.y)*buffer_w + (low.x - rect.x); \
- for(int py = low.y; py < high.y; py++) { \
- for(int px = low.x; px < high.x; px++, pixel_buffer++) {
-
-#define END_FOR_PIXEL_WINDOW } \
- pixel_buffer += buffer_w - (high.x - low.x); \
- }
-
-/*
-#define FOR_PIXEL_WINDOW pre_buffer = prefiltered + (low.y - prefilter_rect.y)*prefilter_w + (low.x - prefilter_rect.x); \
- for(int py = low.y; py < high.y; py++) { \
- int ytile = (py < tile_y[1])? 0: ((py < tile_y[2])? 1: 2); \
- for(int px = low.x; px < high.x; px++, pre_buffer++) { \
- int xtile = (px < tile_x[1])? 0: ((px < tile_x[2])? 1: 2); \
- int tile = ytile*3+xtile; \
- buffer = buffers[tile] + (offset[tile] + py*stride[tile] + px)*kernel_data.film.pass_stride + kernel_data.film.pass_denoising;
-
-#define END_FOR_PIXEL_WINDOW } \
- pre_buffer += prefilter_w - (high.x - low.x); \
- }
-*/
-
-#define FEATURE_PASSES 8 /* Normals, Albedo, Depth, Shadow */
-
-ccl_device_inline void filter_get_features(int x, int y, float *buffer, float *features, float *mean, int pass_stride)
-{
- features[0] = x;
- features[1] = y;
- features[2] = ccl_get_feature(0);
- features[3] = ccl_get_feature(2);
- features[4] = ccl_get_feature(4);
- features[5] = ccl_get_feature(6);
- features[6] = ccl_get_feature(8);
- features[7] = ccl_get_feature(10);
- features[8] = ccl_get_feature(12);
- features[9] = ccl_get_feature(14);
- if(mean) {
- for(int i = 0; i < DENOISE_FEATURES; i++)
- features[i] -= mean[i];
- }
-#ifdef DENOISE_SECOND_ORDER_SCREEN
- features[10] = features[0]*features[0];
- features[11] = features[1]*features[1];
- features[12] = features[0]*features[1];
-#endif
-}
-
-ccl_device_inline void filter_get_feature_variance(int x, int y, float *buffer, float *features, float *scale, int pass_stride)
-{
- features[0] = 0.0f;
- features[1] = 0.0f;
- features[2] = ccl_get_feature(1);
- features[3] = ccl_get_feature(3);
- features[4] = ccl_get_feature(5);
- features[5] = ccl_get_feature(7);
- features[6] = ccl_get_feature(9);
- features[7] = ccl_get_feature(11);
- features[8] = ccl_get_feature(13);
- features[9] = ccl_get_feature(15);
-#ifdef DENOISE_SECOND_ORDER_SCREEN
- features[10] = 0.0f;
- features[11] = 0.0f;
- features[12] = 0.0f;
-#endif
- for(int i = 0; i < DENOISE_FEATURES; i++)
- features[i] *= scale[i]*scale[i];
-}
-
-ccl_device_inline float3 filter_get_pixel_color(float *buffer, int pass_stride)
-{
- return make_float3(ccl_get_feature(16), ccl_get_feature(18), ccl_get_feature(20));
-}
-
-ccl_device_inline float filter_get_pixel_variance(float *buffer, int pass_stride)
-{
- return average(make_float3(ccl_get_feature(17), ccl_get_feature(19), ccl_get_feature(21)));
-}
-
-ccl_device_inline float filter_fill_design_row(float *features, int rank, float *design_row, float *feature_transform, float *bandwidth_factor)
-{
- design_row[0] = 1.0f;
- float weight = 1.0f;
- for(int d = 0; d < rank; d++) {
- float x = math_dot(features, feature_transform + d*DENOISE_FEATURES, DENOISE_FEATURES);
- float x2 = x*x;
- if(bandwidth_factor) x2 *= bandwidth_factor[d]*bandwidth_factor[d];
- if(x2 < 1.0f) {
- /* Pixels are weighted by Epanechnikov kernels. */
- weight *= 0.75f * (1.0f - x2);
- }
- else {
- weight = 0.0f;
- break;
- }
- design_row[1+d] = x;
- if(!bandwidth_factor) design_row[1+rank+d] = x2;
- }
- return weight;
-}
-
-ccl_device_inline bool filter_firefly_rejection(float3 pixel_color, float pixel_variance, float3 center_color, float sqrt_center_variance)
-{
- float color_diff = average(fabs(pixel_color - center_color));
- float variance = sqrt_center_variance + sqrtf(pixel_variance) + 0.005f;
- return (color_diff > 3.0f*variance);
-}
diff --git a/intern/cycles/kernel/kernel_filter_util.h b/intern/cycles/kernel/kernel_filter_util.h
new file mode 100644
index 0000000..5194cfc
--- /dev/null
+++ b/intern/cycles/kernel/kernel_filter_util.h
@@ -0,0 +1,116 @@
+/*
+ * Copyright 2011-2016 Blender Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "util_math_matrix.h"
+
+CCL_NAMESPACE_BEGIN
+
+#define ccl_get_feature(pass) buffer[(pass)*pass_stride]
+
+/* Loop over the pixels in the range [low.x, high.x) x [low.y, high.y).
+ * pixel_buffer always points to the current pixel in the first pass. */
+#define FOR_PIXEL_WINDOW pixel_buffer = buffer + (low.y - rect.y)*buffer_w + (low.x - rect.x); \
+ for(int py = low.y; py < high.y; py++) { \
+ for(int px = low.x; px < high.x; px++, pixel_buffer++) {
+
+#define END_FOR_PIXEL_WINDOW } \
+ pixel_buffer += buffer_w - (high.x - low.x); \
+ }
+
+ccl_device_inline void filter_get_features(int x, int y, float *buffer, float *features, float *mean, int pass_stride)
+{
+ features[0] = x;
+ features[1] = y;
+ features[2] = ccl_get_feature(0);
+ features[3] = ccl_get_feature(2);
+ features[4] = ccl_get_feature(4);
+ features[5] = ccl_get_feature(6);
+ features[6] = ccl_get_feature(8);
+ features[7] = ccl_get_feature(10);
+ features[8] = ccl_get_feature(12);
+ features[9] = ccl_get_feature(14);
+ if(mean) {
+ for(int i = 0; i < DENOISE_FEATURES; i++)
+ features[i] -= mean[i];
+ }
+#ifdef DENOISE_SECOND_ORDER_SCREEN
+ features[10] = features[0]*features[0];
+ features[11] = features[1]*features[1];
+ features[12] = features[0]*features[1];
+#endif
+}
+
+ccl_device_inline void filter_get_feature_variance(int x, int y, float *buffer, float *features, float *scale, int pass_stride)
+{
+ features[0] = 0.0f;
+ features[1] = 0.0f;
+ features[2] = ccl_get_feature(1);
+ features[3] = ccl_get_feature(3);
+ features[4] = ccl_get_feature(5);
+ features[5] = ccl_get_feature(7);
+ features[6] = ccl_get_feature(9);
+ features[7] = ccl_get_feature(11);
+ features[8] = ccl_get_feature(13);
+ features[9] = ccl_get_feature(15);
+#ifdef DENOISE_SECOND_ORDER_SCREEN
+ features[10] = 0.0f;
+ features[11] = 0.0f;
+ features[12] = 0.0f;
+#endif
+ for(int i = 0; i < DENOISE_FEATURES; i++)
+ features[i] *= scale[i]*scale[i];
+}
+
+ccl_device_inline float3 filter_get_pixel_color(float *buffer, int pass_stride)
+{
+ return make_float3(ccl_get_feature(16), ccl_get_feature(18), ccl_get_feature(20));
+}
+
+ccl_device_inline float filter_get_pixel_variance(float *buffer, int pass_stride)
+{
+ return average(make_float3(ccl_get_feature(17), ccl_get_feature(19), ccl_get_feature(21)));
+}
+
+ccl_device_inline float filter_fill_design_row(float *features, int rank, float *design_row, float *feature_transform, float *bandwidth_factor)
+{
+ design_row[0] = 1.0f;
+ float weight = 1.0f;
+ for(int d = 0; d < rank; d++) {
+ float x = math_dot(features, feature_transform + d*DENOISE_FEATURES, DENOISE_FEATURES);
+ float x2 = x*x;
+ if(bandwidth_factor) x2 *= bandwidth_factor[d]*bandwidth_factor[d];
+ if(x2 < 1.0f) {
+ /* Pixels are weighted by Epanechnikov kernels. */
+ weight *= 0.75f * (1.0f - x2);
+ }
+ else {
+ weight = 0.0f;
+ break;
+ }
+ design_row[1+d] = x;
+ if(!bandwidth_factor) design_row[1+rank+d] = x2;
+ }
+ return weight;
+}
+
+ccl_device_inline bool filter_firefly_rejection(float3 pixel_color, float pixel_variance, float3 center_color, float sqrt_center_variance)
+{
+ float color_diff = average(fabs(pixel_color - center_color));
+ float variance = sqrt_center_variance + sqrtf(pixel_variance) + 0.005f;
+ return (color_diff > 3.0f*variance);
+}
+
+CCL_NAMESPACE_END
More information about the Bf-blender-cvs
mailing list