[Bf-blender-cvs] [3ee606621cf] master: Cycles: Query XYZ to/from Scene Linear conversion from OCIO instead of assuming sRGB

Lukas Stockner noreply at git.blender.org
Thu Jun 14 22:30:58 CEST 2018


Commit: 3ee606621cf53a2a4897e534e7e04d3632f419f8
Author: Lukas Stockner
Date:   Thu Jun 14 17:48:19 2018 +0200
Branches: master
https://developer.blender.org/rB3ee606621cf53a2a4897e534e7e04d3632f419f8

Cycles: Query XYZ to/from Scene Linear conversion from OCIO instead of assuming sRGB

I've limited it to just the RGB<->XYZ stuff for now, correct image handling is the next step.

Reviewers: brecht, sergey

Differential Revision: https://developer.blender.org/D3478

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

M	intern/cycles/CMakeLists.txt
M	intern/cycles/app/CMakeLists.txt
M	intern/cycles/blender/blender_curves.cpp
M	intern/cycles/blender/blender_mesh.cpp
M	intern/cycles/blender/blender_session.cpp
M	intern/cycles/cmake/external_libs.cmake
A	intern/cycles/kernel/kernel_color.h
M	intern/cycles/kernel/kernel_film.h
M	intern/cycles/kernel/kernel_types.h
M	intern/cycles/kernel/kernels/cpu/kernel_cpu_impl.h
M	intern/cycles/kernel/kernels/cuda/kernel.cu
M	intern/cycles/kernel/kernels/opencl/kernel.cl
M	intern/cycles/kernel/osl/osl_services.cpp
M	intern/cycles/kernel/shaders/node_color.h
M	intern/cycles/kernel/split/kernel_split_common.h
M	intern/cycles/kernel/svm/svm.h
M	intern/cycles/kernel/svm/svm_closure.h
M	intern/cycles/kernel/svm/svm_convert.h
M	intern/cycles/kernel/svm/svm_image.h
M	intern/cycles/kernel/svm/svm_math_util.h
M	intern/cycles/kernel/svm/svm_sky.h
M	intern/cycles/kernel/svm/svm_wavelength.h
M	intern/cycles/render/constant_fold.cpp
M	intern/cycles/render/constant_fold.h
M	intern/cycles/render/graph.cpp
M	intern/cycles/render/graph.h
M	intern/cycles/render/nodes.cpp
M	intern/cycles/render/shader.cpp
M	intern/cycles/render/shader.h
M	intern/cycles/test/CMakeLists.txt
M	intern/cycles/util/util_color.h
M	release/datafiles/colormanagement/config.ocio

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

diff --git a/intern/cycles/CMakeLists.txt b/intern/cycles/CMakeLists.txt
index 100a52625d1..233bc639fd8 100644
--- a/intern/cycles/CMakeLists.txt
+++ b/intern/cycles/CMakeLists.txt
@@ -326,6 +326,14 @@ if(WITH_CYCLES_NETWORK)
 	add_definitions(-DWITH_NETWORK)
 endif()
 
+if(WITH_OPENCOLORIO)
+	add_definitions(-DWITH_OCIO)
+	include_directories(
+		SYSTEM
+		${OPENCOLORIO_INCLUDE_DIRS}
+	)
+endif()
+
 if(WITH_CYCLES_STANDALONE OR WITH_CYCLES_NETWORK OR WITH_CYCLES_CUBIN_COMPILER)
 	add_subdirectory(app)
 endif()
diff --git a/intern/cycles/app/CMakeLists.txt b/intern/cycles/app/CMakeLists.txt
index d1f86a5fe7d..cfca45600a5 100644
--- a/intern/cycles/app/CMakeLists.txt
+++ b/intern/cycles/app/CMakeLists.txt
@@ -80,6 +80,10 @@ macro(cycles_target_link_libraries target)
 	if(WITH_CYCLES_OPENSUBDIV)
 		target_link_libraries(${target} ${OPENSUBDIV_LIBRARIES})
 	endif()
+	if(WITH_OPENCOLORIO)
+		link_directories(${OPENCOLORIO_LIBPATH})
+		target_link_libraries(${target} ${OPENCOLORIO_LIBRARIES})
+	endif()
 	target_link_libraries(
 		${target}
 		${OPENIMAGEIO_LIBRARIES}
diff --git a/intern/cycles/blender/blender_curves.cpp b/intern/cycles/blender/blender_curves.cpp
index 81d6a21cd13..5fd3455061d 100644
--- a/intern/cycles/blender/blender_curves.cpp
+++ b/intern/cycles/blender/blender_curves.cpp
@@ -784,17 +784,18 @@ static void ExportCurveTriangleVcol(ParticleCurveData *CData,
 
 			for(int curvekey = CData->curve_firstkey[curve]; curvekey < CData->curve_firstkey[curve] + CData->curve_keynum[curve] - 1; curvekey++) {
 				for(int section = 0; section < resol; section++) {
-					cdata[vertexindex] = color_float_to_byte(color_srgb_to_scene_linear_v3(CData->curve_vcol[curve]));
+					/* Encode vertex color using the sRGB curve. */
+					cdata[vertexindex] = color_float_to_byte(color_srgb_to_linear_v3(CData->curve_vcol[curve]));
 					vertexindex++;
-					cdata[vertexindex] = color_float_to_byte(color_srgb_to_scene_linear_v3(CData->curve_vcol[curve]));
+					cdata[vertexindex] = color_float_to_byte(color_srgb_to_linear_v3(CData->curve_vcol[curve]));
 					vertexindex++;
-					cdata[vertexindex] = color_float_to_byte(color_srgb_to_scene_linear_v3(CData->curve_vcol[curve]));
+					cdata[vertexindex] = color_float_to_byte(color_srgb_to_linear_v3(CData->curve_vcol[curve]));
 					vertexindex++;
-					cdata[vertexindex] = color_float_to_byte(color_srgb_to_scene_linear_v3(CData->curve_vcol[curve]));
+					cdata[vertexindex] = color_float_to_byte(color_srgb_to_linear_v3(CData->curve_vcol[curve]));
 					vertexindex++;
-					cdata[vertexindex] = color_float_to_byte(color_srgb_to_scene_linear_v3(CData->curve_vcol[curve]));
+					cdata[vertexindex] = color_float_to_byte(color_srgb_to_linear_v3(CData->curve_vcol[curve]));
 					vertexindex++;
-					cdata[vertexindex] = color_float_to_byte(color_srgb_to_scene_linear_v3(CData->curve_vcol[curve]));
+					cdata[vertexindex] = color_float_to_byte(color_srgb_to_linear_v3(CData->curve_vcol[curve]));
 					vertexindex++;
 				}
 			}
@@ -1010,9 +1011,10 @@ void BlenderSync::sync_curves(Mesh *mesh,
 				if(fdata) {
 					size_t i = 0;
 
+					/* Encode vertex color using the sRGB curve. */
 					for(size_t curve = 0; curve < CData.curve_vcol.size(); curve++)
 						if(!(CData.curve_keynum[curve] <= 1 || CData.curve_length[curve] == 0.0f))
-							fdata[i++] = color_srgb_to_scene_linear_v3(CData.curve_vcol[curve]);
+							fdata[i++] = color_srgb_to_linear_v3(CData.curve_vcol[curve]);
 				}
 			}
 		}
diff --git a/intern/cycles/blender/blender_mesh.cpp b/intern/cycles/blender/blender_mesh.cpp
index 76d17bc1ae6..8d2ade1e30b 100644
--- a/intern/cycles/blender/blender_mesh.cpp
+++ b/intern/cycles/blender/blender_mesh.cpp
@@ -401,7 +401,8 @@ static void attr_create_vertex_color(Scene *scene,
 				int n = p->loop_total();
 				for(int i = 0; i < n; i++) {
 					float3 color = get_float3(l->data[p->loop_start() + i].color());
-					*(cdata++) = color_float_to_byte(color_srgb_to_scene_linear_v3(color));
+					/* Encode vertex color using the sRGB curve. */
+					*(cdata++) = color_float_to_byte(color_srgb_to_linear_v3(color));
 				}
 			}
 		}
@@ -424,12 +425,13 @@ static void attr_create_vertex_color(Scene *scene,
 				int tri_a[3], tri_b[3];
 				face_split_tri_indices(face_flags[i], tri_a, tri_b);
 
+				/* Encode vertex color using the sRGB curve. */
 				uchar4 colors[4];
-				colors[0] = color_float_to_byte(color_srgb_to_scene_linear_v3(get_float3(c->color1())));
-				colors[1] = color_float_to_byte(color_srgb_to_scene_linear_v3(get_float3(c->color2())));
-				colors[2] = color_float_to_byte(color_srgb_to_scene_linear_v3(get_float3(c->color3())));
+				colors[0] = color_float_to_byte(color_srgb_to_linear_v3(get_float3(c->color1())));
+				colors[1] = color_float_to_byte(color_srgb_to_linear_v3(get_float3(c->color2())));
+				colors[2] = color_float_to_byte(color_srgb_to_linear_v3(get_float3(c->color3())));
 				if(nverts[i] == 4) {
-					colors[3] = color_float_to_byte(color_srgb_to_scene_linear_v3(get_float3(c->color4())));
+					colors[3] = color_float_to_byte(color_srgb_to_linear_v3(get_float3(c->color4())));
 				}
 
 				cdata[0] = colors[tri_a[0]];
diff --git a/intern/cycles/blender/blender_session.cpp b/intern/cycles/blender/blender_session.cpp
index 00d23b9095e..4affd0479b0 100644
--- a/intern/cycles/blender/blender_session.cpp
+++ b/intern/cycles/blender/blender_session.cpp
@@ -139,6 +139,10 @@ void BlenderSession::create_session()
 	scene->image_manager->builtin_image_pixels_cb = function_bind(&BlenderSession::builtin_image_pixels, this, _1, _2, _3, _4, _5);
 	scene->image_manager->builtin_image_float_pixels_cb = function_bind(&BlenderSession::builtin_image_float_pixels, this, _1, _2, _3, _4, _5);
 
+#ifdef WITH_OCIO
+	scene->film->set_color_config(OCIO_getCurrentConfig());
+#endif
+
 	session->scene = scene;
 
 	/* create sync */
diff --git a/intern/cycles/cmake/external_libs.cmake b/intern/cycles/cmake/external_libs.cmake
index 8d04025e6fd..2e386a6bfc5 100644
--- a/intern/cycles/cmake/external_libs.cmake
+++ b/intern/cycles/cmake/external_libs.cmake
@@ -97,6 +97,12 @@ if(CYCLES_STANDALONE_REPOSITORY)
 		find_package(LLVM REQUIRED)
 	endif()
 
+	####
+	# OpenColorIO
+	if(WITH_OPENCOLORIO)
+		find_package(OpenColorIO REQUIRED)
+	endif()
+
 	####
 	# Boost
 	set(__boost_packages filesystem regex system thread date_time)
diff --git a/intern/cycles/kernel/kernel_color.h b/intern/cycles/kernel/kernel_color.h
new file mode 100644
index 00000000000..d1c3dac824d
--- /dev/null
+++ b/intern/cycles/kernel/kernel_color.h
@@ -0,0 +1,38 @@
+/*
+ * Copyright 2011-2018 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.
+ */
+
+#ifndef __KERNEL_COLOR_H__
+#define __KERNEL_COLOR_H__
+
+#include "util/util_color.h"
+
+CCL_NAMESPACE_BEGIN
+
+ccl_device float3 xyz_to_rgb(KernelGlobals *kg, float3 xyz)
+{
+    return make_float3(dot(kernel_data.film.xyz_to_r, xyz),
+                       dot(kernel_data.film.xyz_to_g, xyz),
+                       dot(kernel_data.film.xyz_to_b, xyz));
+}
+
+ccl_device float linear_rgb_to_gray(KernelGlobals *kg, float3 c)
+{
+    return dot(c, kernel_data.film.rgb_to_y);
+}
+
+CCL_NAMESPACE_END
+
+#endif /* __KERNEL_COLOR_H__ */
\ No newline at end of file
diff --git a/intern/cycles/kernel/kernel_film.h b/intern/cycles/kernel/kernel_film.h
index f9e9b413898..94815601179 100644
--- a/intern/cycles/kernel/kernel_film.h
+++ b/intern/cycles/kernel/kernel_film.h
@@ -22,9 +22,9 @@ ccl_device float4 film_map(KernelGlobals *kg, float4 irradiance, float scale)
 	float4 result = irradiance*scale;
 
 	/* conversion to srgb */
-	result.x = color_scene_linear_to_srgb(result.x*exposure);
-	result.y = color_scene_linear_to_srgb(result.y*exposure);
-	result.z = color_scene_linear_to_srgb(result.z*exposure);
+	result.x = color_linear_to_srgb(result.x*exposure);
+	result.y = color_linear_to_srgb(result.y*exposure);
+	result.z = color_linear_to_srgb(result.z*exposure);
 
 	/* clamp since alpha might be > 1.0 due to russian roulette */
 	result.w = saturate(result.w);
diff --git a/intern/cycles/kernel/kernel_types.h b/intern/cycles/kernel/kernel_types.h
index 5382213e6f7..633518c7926 100644
--- a/intern/cycles/kernel/kernel_types.h
+++ b/intern/cycles/kernel/kernel_types.h
@@ -1272,6 +1272,11 @@ typedef struct KernelFilm {
 	int pass_denoising_clean;
 	int denoising_flags;
 
+	float3 xyz_to_r;
+	float3 xyz_to_g;
+	float3 xyz_to_b;
+	float3 rgb_to_y;
+
 	int pad1, pad2, pad3;
 
 #ifdef __KERNEL_DEBUG__
diff --git a/intern/cycles/kernel/kernels/cpu/kernel_cpu_impl.h b/intern/cycles/kernel/kernels/cpu/kernel_cpu_impl.h
index ccca023a15f..5ec1655ab05 100644
--- a/intern/cycles/kernel/kernels/cpu/kernel_cpu_impl.h
+++ b/intern/cycles/kernel/kernels/cpu/kernel_cpu_impl.h
@@ -30,6 +30,7 @@
 #    include "kernel/split/kernel_split_data.h"
 #    include "kernel/kernel_globals.h"
 
+#    include "kernel/kernel_color.h"
 #    include "kernel/kernels/cpu/kernel_cpu_image.h"
 #    include "kernel/kernel_film.h"
 #    include "kernel/kernel_path.h"
diff --git a/intern/cycles/kernel/kernels/cuda/kernel.cu b/intern/cycles/kernel/kernels/cuda/kernel.cu
index 3c93e00ccf1..8a180a509e8 100644
--- a/intern/cycles/kernel/kernels/cuda/kernel.cu
+++ b/intern/cycles/kernel/kernels/cuda/kernel.cu
@@ -26,6 +26,7 @@
 #include "kernel/kernel_math.h"
 #include "kernel/kernel_types.h"
 #include "kernel/kernel_globals.h"
+#include "kernel/kernel_color.h"
 #include "kernel/kernels/cuda/kernel_cuda_image.h"
 #include "kernel/kernel_film.h"
 #include "kernel/kernel_path.h"
diff --git a/intern/cycles/kernel/kernels/opencl/kernel.cl b/intern/cycles/kernel/kernels/opencl/kernel.cl
index 9d5d784e140..63128d0aecf 100644
--- a/intern/cycle

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list