diff options
author | Brecht Van Lommel <brecht@blender.org> | 2022-03-22 22:41:46 +0300 |
---|---|---|
committer | Brecht Van Lommel <brecht@blender.org> | 2022-04-18 20:14:34 +0300 |
commit | 029b0df81aa116a3e29f405dc8902834242d5338 (patch) | |
tree | b14a14c4480b9ef826c5a786a479a49f0ca9291f /intern/cycles/kernel | |
parent | 41b3feea85cd8c323c1c5030f1ab0bc90438df4f (diff) |
Fix Cycles blackbody shader not taking into account OpenColorIO config
Keep the existing Rec.709 fit and convert to other colorspace if needed, it
seems accurate enough in practice, and keeps the same performance for the
default case.
Diffstat (limited to 'intern/cycles/kernel')
-rw-r--r-- | intern/cycles/kernel/svm/blackbody.h | 2 | ||||
-rw-r--r-- | intern/cycles/kernel/svm/closure.h | 3 | ||||
-rw-r--r-- | intern/cycles/kernel/svm/math_util.h | 4 | ||||
-rw-r--r-- | intern/cycles/kernel/types.h | 7 | ||||
-rw-r--r-- | intern/cycles/kernel/util/color.h | 9 |
5 files changed, 19 insertions, 6 deletions
diff --git a/intern/cycles/kernel/svm/blackbody.h b/intern/cycles/kernel/svm/blackbody.h index 1618341b655..af59c2fe747 100644 --- a/intern/cycles/kernel/svm/blackbody.h +++ b/intern/cycles/kernel/svm/blackbody.h @@ -23,7 +23,7 @@ ccl_device_noinline void svm_node_blackbody(KernelGlobals kg, /* Input */ float temperature = stack_load_float(stack, temperature_offset); - float3 color_rgb = svm_math_blackbody_color(temperature); + float3 color_rgb = rec709_to_rgb(kg, svm_math_blackbody_color_rec709(temperature)); stack_store_float3(stack, col_offset, color_rgb); } diff --git a/intern/cycles/kernel/svm/closure.h b/intern/cycles/kernel/svm/closure.h index 88b44cdbacf..305bd404d27 100644 --- a/intern/cycles/kernel/svm/closure.h +++ b/intern/cycles/kernel/svm/closure.h @@ -1111,7 +1111,8 @@ ccl_device_noinline int svm_node_principled_volume(KernelGlobals kg, if (intensity > CLOSURE_WEIGHT_CUTOFF) { float3 blackbody_tint = stack_load_float3(stack, node.w); - float3 bb = blackbody_tint * intensity * svm_math_blackbody_color(T); + float3 bb = blackbody_tint * intensity * + rec709_to_rgb(kg, svm_math_blackbody_color_rec709(T)); emission_setup(sd, bb); } } diff --git a/intern/cycles/kernel/svm/math_util.h b/intern/cycles/kernel/svm/math_util.h index 2a496aee1e1..9f2d9561e26 100644 --- a/intern/cycles/kernel/svm/math_util.h +++ b/intern/cycles/kernel/svm/math_util.h @@ -189,10 +189,8 @@ ccl_device float svm_math(NodeMathType type, float a, float b, float c) } } -ccl_device float3 svm_math_blackbody_color(float t) +ccl_device float3 svm_math_blackbody_color_rec709(float t) { - /* TODO(lukas): Reimplement in XYZ. */ - /* Calculate color in range 800..12000 using an approximation * a/x+bx+c for R and G and ((at + b)t + c)t + d) for B * Max absolute error for RGB is (0.00095, 0.00077, 0.00057), diff --git a/intern/cycles/kernel/types.h b/intern/cycles/kernel/types.h index db499a1e1bc..422285cd346 100644 --- a/intern/cycles/kernel/types.h +++ b/intern/cycles/kernel/types.h @@ -1117,13 +1117,18 @@ typedef struct KernelFilm { float4 xyz_to_g; float4 xyz_to_b; float4 rgb_to_y; + /* Rec709 to rendering color space. */ + float4 rec709_to_r; + float4 rec709_to_g; + float4 rec709_to_b; + int is_rec709; int pass_bake_primitive; int pass_bake_differential; int use_approximate_shadow_catcher; - int pad1, pad2; + int pad1; } KernelFilm; static_assert_align(KernelFilm, 16); diff --git a/intern/cycles/kernel/util/color.h b/intern/cycles/kernel/util/color.h index 95b6b33795d..28978d873d6 100644 --- a/intern/cycles/kernel/util/color.h +++ b/intern/cycles/kernel/util/color.h @@ -14,6 +14,15 @@ ccl_device float3 xyz_to_rgb(KernelGlobals kg, float3 xyz) dot(float4_to_float3(kernel_data.film.xyz_to_b), xyz)); } +ccl_device float3 rec709_to_rgb(KernelGlobals kg, float3 rec709) +{ + return (kernel_data.film.is_rec709) ? + rec709 : + make_float3(dot(float4_to_float3(kernel_data.film.rec709_to_r), rec709), + dot(float4_to_float3(kernel_data.film.rec709_to_g), rec709), + dot(float4_to_float3(kernel_data.film.rec709_to_b), rec709)); +} + ccl_device float linear_rgb_to_gray(KernelGlobals kg, float3 c) { return dot(c, float4_to_float3(kernel_data.film.rgb_to_y)); |