Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLukas Stockner <lukas.stockner@freenet.de>2018-06-14 18:48:19 +0300
committerLukas Stockner <lukas.stockner@freenet.de>2018-06-14 23:21:37 +0300
commit3ee606621cf53a2a4897e534e7e04d3632f419f8 (patch)
treee8ffff99f0ceeea46aa170298853d8034a1acf1d /intern/cycles/render
parent064e701472ac430c8063ab5d577b5014eecf9ad5 (diff)
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
Diffstat (limited to 'intern/cycles/render')
-rw-r--r--intern/cycles/render/constant_fold.cpp4
-rw-r--r--intern/cycles/render/constant_fold.h5
-rw-r--r--intern/cycles/render/graph.cpp6
-rw-r--r--intern/cycles/render/graph.h2
-rw-r--r--intern/cycles/render/nodes.cpp7
-rw-r--r--intern/cycles/render/shader.cpp52
-rw-r--r--intern/cycles/render/shader.h7
7 files changed, 74 insertions, 9 deletions
diff --git a/intern/cycles/render/constant_fold.cpp b/intern/cycles/render/constant_fold.cpp
index 943b218f0e4..98c3e99996c 100644
--- a/intern/cycles/render/constant_fold.cpp
+++ b/intern/cycles/render/constant_fold.cpp
@@ -22,8 +22,8 @@
CCL_NAMESPACE_BEGIN
-ConstantFolder::ConstantFolder(ShaderGraph *graph, ShaderNode *node, ShaderOutput *output)
-: graph(graph), node(node), output(output)
+ConstantFolder::ConstantFolder(ShaderGraph *graph, ShaderNode *node, ShaderOutput *output, Scene *scene)
+: graph(graph), node(node), output(output), scene(scene)
{
}
diff --git a/intern/cycles/render/constant_fold.h b/intern/cycles/render/constant_fold.h
index 33f93b8c0ab..cc24d614206 100644
--- a/intern/cycles/render/constant_fold.h
+++ b/intern/cycles/render/constant_fold.h
@@ -22,6 +22,7 @@
CCL_NAMESPACE_BEGIN
+class Scene;
class ShaderGraph;
class ShaderInput;
class ShaderNode;
@@ -33,7 +34,9 @@ public:
ShaderNode *const node;
ShaderOutput *const output;
- ConstantFolder(ShaderGraph *graph, ShaderNode *node, ShaderOutput *output);
+ Scene *scene;
+
+ ConstantFolder(ShaderGraph *graph, ShaderNode *node, ShaderOutput *output, Scene *scene);
bool all_inputs_constant() const;
diff --git a/intern/cycles/render/graph.cpp b/intern/cycles/render/graph.cpp
index e1c09373004..8b179f742c4 100644
--- a/intern/cycles/render/graph.cpp
+++ b/intern/cycles/render/graph.cpp
@@ -496,7 +496,7 @@ void ShaderGraph::remove_proxy_nodes()
* Try to constant fold some nodes, and pipe result directly to
* the input socket of connected nodes.
*/
-void ShaderGraph::constant_fold()
+void ShaderGraph::constant_fold(Scene *scene)
{
ShaderNodeSet done, scheduled;
queue<ShaderNode*> traverse_queue;
@@ -536,7 +536,7 @@ void ShaderGraph::constant_fold()
}
}
/* Optimize current node. */
- ConstantFolder folder(this, node, output);
+ ConstantFolder folder(this, node, output, scene);
node->constant_fold(folder);
}
}
@@ -734,7 +734,7 @@ void ShaderGraph::clean(Scene *scene)
/* Graph simplification */
/* NOTE: Remove proxy nodes was already done. */
- constant_fold();
+ constant_fold(scene);
simplify_settings(scene);
deduplicate_nodes();
verify_volume_output();
diff --git a/intern/cycles/render/graph.h b/intern/cycles/render/graph.h
index 2c134932b3c..5d986ae4827 100644
--- a/intern/cycles/render/graph.h
+++ b/intern/cycles/render/graph.h
@@ -285,7 +285,7 @@ protected:
/* Graph simplification routines. */
void clean(Scene *scene);
- void constant_fold();
+ void constant_fold(Scene *scene);
void simplify_settings(Scene *scene);
void deduplicate_nodes();
void verify_volume_output();
diff --git a/intern/cycles/render/nodes.cpp b/intern/cycles/render/nodes.cpp
index 3dad4d1a346..0f2581b2a2e 100644
--- a/intern/cycles/render/nodes.cpp
+++ b/intern/cycles/render/nodes.cpp
@@ -14,6 +14,7 @@
* limitations under the License.
*/
+#include "render/film.h"
#include "render/image.h"
#include "render/integrator.h"
#include "render/light.h"
@@ -1673,7 +1674,8 @@ RGBToBWNode::RGBToBWNode()
void RGBToBWNode::constant_fold(const ConstantFolder& folder)
{
if(folder.all_inputs_constant()) {
- folder.make_constant(linear_rgb_to_gray(color));
+ float val = folder.scene->shader_manager->linear_rgb_to_gray(color);
+ folder.make_constant(val);
}
}
@@ -1769,7 +1771,8 @@ void ConvertNode::constant_fold(const ConstantFolder& folder)
if(to == SocketType::FLOAT) {
if(from == SocketType::COLOR) {
/* color to float */
- folder.make_constant(linear_rgb_to_gray(value_color));
+ float val = folder.scene->shader_manager->linear_rgb_to_gray(value_color);
+ folder.make_constant(val);
}
else {
/* vector/point/normal to float */
diff --git a/intern/cycles/render/shader.cpp b/intern/cycles/render/shader.cpp
index ec52c51e337..e34f272d9b6 100644
--- a/intern/cycles/render/shader.cpp
+++ b/intern/cycles/render/shader.cpp
@@ -31,6 +31,11 @@
#include "util/util_foreach.h"
+#ifdef WITH_OCIO
+# include <OpenColorIO/OpenColorIO.h>
+namespace OCIO = OCIO_NAMESPACE;
+#endif
+
CCL_NAMESPACE_BEGIN
thread_mutex ShaderManager::lookup_table_mutex;
@@ -338,6 +343,40 @@ ShaderManager::ShaderManager()
{
need_update = true;
beckmann_table_offset = TABLE_OFFSET_INVALID;
+
+ xyz_to_r = make_float3( 3.2404542f, -1.5371385f, -0.4985314f);
+ xyz_to_g = make_float3(-0.9692660f, 1.8760108f, 0.0415560f);
+ xyz_to_b = make_float3( 0.0556434f, -0.2040259f, 1.0572252f);
+ rgb_to_y = make_float3( 0.2126729f, 0.7151522f, 0.0721750f);
+
+#ifdef WITH_OCIO
+ OCIO::ConstConfigRcPtr config = OCIO::GetCurrentConfig();
+ if(config) {
+ if(config->hasRole("XYZ") && config->hasRole("scene_linear")) {
+ OCIO::ConstProcessorRcPtr to_rgb_processor = config->getProcessor("XYZ", "scene_linear");
+ OCIO::ConstProcessorRcPtr to_xyz_processor = config->getProcessor("scene_linear", "XYZ");
+ if(to_rgb_processor && to_xyz_processor) {
+ float r[] = {1.0f, 0.0f, 0.0f};
+ float g[] = {0.0f, 1.0f, 0.0f};
+ float b[] = {0.0f, 0.0f, 1.0f};
+ to_xyz_processor->applyRGB(r);
+ to_xyz_processor->applyRGB(g);
+ to_xyz_processor->applyRGB(b);
+ rgb_to_y = make_float3(r[1], g[1], b[1]);
+
+ float x[] = {1.0f, 0.0f, 0.0f};
+ float y[] = {0.0f, 1.0f, 0.0f};
+ float z[] = {0.0f, 0.0f, 1.0f};
+ to_rgb_processor->applyRGB(x);
+ to_rgb_processor->applyRGB(y);
+ to_rgb_processor->applyRGB(z);
+ xyz_to_r = make_float3(x[0], y[0], z[0]);
+ xyz_to_g = make_float3(x[1], y[1], z[1]);
+ xyz_to_b = make_float3(x[2], y[2], z[2]);
+ }
+ }
+ }
+#endif
}
ShaderManager::~ShaderManager()
@@ -518,6 +557,14 @@ void ShaderManager::device_update_common(Device *device,
kintegrator->use_volumes = has_volumes;
/* TODO(sergey): De-duplicate with flags set in integrator.cpp. */
kintegrator->transparent_shadows = has_transparent_shadow;
+
+ /* film */
+ KernelFilm *kfilm = &dscene->data.film;
+ /* color space, needs to be here because e.g. displacement shaders could depend on it */
+ kfilm->xyz_to_r = xyz_to_r;
+ kfilm->xyz_to_g = xyz_to_g;
+ kfilm->xyz_to_b = xyz_to_b;
+ kfilm->rgb_to_y = rgb_to_y;
}
void ShaderManager::device_free_common(Device *, DeviceScene *dscene, Scene *scene)
@@ -643,5 +690,10 @@ void ShaderManager::free_memory()
beckmann_table.free_memory();
}
+float ShaderManager::linear_rgb_to_gray(float3 c)
+{
+ return dot(c, rgb_to_y);
+}
+
CCL_NAMESPACE_END
diff --git a/intern/cycles/render/shader.h b/intern/cycles/render/shader.h
index abd483caabc..0353da90013 100644
--- a/intern/cycles/render/shader.h
+++ b/intern/cycles/render/shader.h
@@ -195,6 +195,8 @@ public:
static void free_memory();
+ float linear_rgb_to_gray(float3 c);
+
protected:
ShaderManager();
@@ -211,6 +213,11 @@ protected:
DeviceRequestedFeatures *requested_features);
thread_spin_lock attribute_lock_;
+
+ float3 xyz_to_r;
+ float3 xyz_to_g;
+ float3 xyz_to_b;
+ float3 rgb_to_y;
};
CCL_NAMESPACE_END