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:
authorSergey Sharybin <sergey.vfx@gmail.com>2015-12-04 18:17:25 +0300
committerSergey Sharybin <sergey.vfx@gmail.com>2015-12-05 23:21:14 +0300
commited5dbb0a7b2bc7bef3776d31eaf466ec8740560f (patch)
tree37c12781edd198932cdd4e47c950460d9f4271cc /intern/cycles/blender/blender_util.h
parent258564a7b4b26098dc2fabc28aa5a203d2754eff (diff)
Cycles: Implement extrapolation for RGB curves
Previously RGB Curves node will clamp input to 0..1 which is rather useless when one wants to use HDR image textures and do bit of correction on them. Now kernel code supports extrapolation of baked LUT based on first/last two table points and performs linear extrapolation. The only tricky part is to guess the range to bake the LUT for. Currently it's using simple approach -- minmax of the input curves. While this behaves ok for the simple cases it's easy to trick the system up causing incorrect results. Not sure we can solve those issues in a general case and since the new code is giving more expected results it's not that bad actually. In the worst case artist migh always create explicit point to make sure LUT is created for the needed HDR range. Reviewers: brecht, juicyfruit Subscribers: sebastian_k Differential Revision: https://developer.blender.org/D1658
Diffstat (limited to 'intern/cycles/blender/blender_util.h')
-rw-r--r--intern/cycles/blender/blender_util.h50
1 files changed, 47 insertions, 3 deletions
diff --git a/intern/cycles/blender/blender_util.h b/intern/cycles/blender/blender_util.h
index 2e9e9266404..029d0af0fd2 100644
--- a/intern/cycles/blender/blender_util.h
+++ b/intern/cycles/blender/blender_util.h
@@ -62,6 +62,29 @@ static inline void colorramp_to_array(BL::ColorRamp ramp, float4 *data, int size
}
}
+static inline void curvemap_minmax_curve(/*const*/ BL::CurveMap& curve,
+ float *min_x,
+ float *max_x)
+{
+ *min_x = min(*min_x, curve.points[0].location()[0]);
+ *max_x = max(*max_x, curve.points[curve.points.length() - 1].location()[0]);
+}
+
+static inline void curvemapping_minmax(/*const*/ BL::CurveMapping& cumap,
+ bool rgb_curve,
+ float *min_x,
+ float *max_x)
+{
+ /* const int num_curves = cumap.curves.length(); */ /* Gives linking error so far. */
+ const int num_curves = rgb_curve? 4: 3;
+ *min_x = FLT_MAX;
+ *max_x = -FLT_MAX;
+ for(int i = 0; i < num_curves; ++i) {
+ BL::CurveMap map(cumap.curves[i]);
+ curvemap_minmax_curve(map, min_x, max_x);
+ }
+}
+
static inline void curvemapping_to_array(BL::CurveMapping cumap, float *data, int size)
{
cumap.update();
@@ -72,8 +95,29 @@ static inline void curvemapping_to_array(BL::CurveMapping cumap, float *data, in
}
}
-static inline void curvemapping_color_to_array(BL::CurveMapping cumap, float4 *data, int size, bool rgb_curve)
+static inline void curvemapping_color_to_array(BL::CurveMapping cumap,
+ float4 *data,
+ int size,
+ bool rgb_curve)
{
+ float min_x = 0.0f, max_x = 1.0f;
+ /* TODO(sergey): Vector curve mapping is still clipping to 0..1. */
+ if(rgb_curve) {
+ /* TODO(sergey): There is no easy way to automatically guess what is
+ * the range to be used here for the case when mapping is applied on
+ * top of another mapping (i.e. R curve applied on top of common
+ * one).
+ *
+ * Using largest possible range form all curves works correct for the
+ * cases like vector curves and should be good enough heuristic for
+ * the color curves as well.
+ *
+ * There might be some better estimations here tho.
+ */
+ curvemapping_minmax(cumap, rgb_curve, &min_x, &max_x);
+ }
+ const float range_x = max_x - min_x;
+
cumap.update();
BL::CurveMap mapR = cumap.curves[0];
@@ -84,7 +128,7 @@ static inline void curvemapping_color_to_array(BL::CurveMapping cumap, float4 *d
BL::CurveMap mapI = cumap.curves[3];
for(int i = 0; i < size; i++) {
- float t = (float)i/(float)(size-1);
+ float t = min_x + (float)i/(float)(size-1) * range_x;
data[i][0] = mapR.evaluate(mapI.evaluate(t));
data[i][1] = mapG.evaluate(mapI.evaluate(t));
@@ -93,7 +137,7 @@ static inline void curvemapping_color_to_array(BL::CurveMapping cumap, float4 *d
}
else {
for(int i = 0; i < size; i++) {
- float t = (float)i/(float)(size-1);
+ float t = min_x + (float)i/(float)(size-1) * range_x;
data[i][0] = mapR.evaluate(t);
data[i][1] = mapG.evaluate(t);