[Bf-blender-cvs] [9a930e97da7] temp-gpencil-bezier-stroke-type: Fix T74680: Incorrect mixing in Glare node

Szymon Ulatowski noreply at git.blender.org
Tue Apr 13 11:29:18 CEST 2021


Commit: 9a930e97da797c4256cae640822deeaebc79ffe6
Author: Szymon Ulatowski
Date:   Mon Apr 12 14:38:20 2021 +0200
Branches: temp-gpencil-bezier-stroke-type
https://developer.blender.org/rB9a930e97da797c4256cae640822deeaebc79ffe6

Fix T74680: Incorrect mixing in Glare node

The mixing function was designed to give correct results for Mix values of
-1, 0, and +1, but the behavior between these points was not linear. This is
unavoidable, because the function depends on both Mix and Mix^2 (by
multiplying value and mf) so they could not cancel out completely.

The new formula simply calculates the weighted sum without trying to invent
a smooth function.
Value for MixGlareOperation is now passed directly without scaling because
it is then easier to use.
Note that the previous formula performed max() twice for both input image
and the result, now there is just one max() per channel because the glare
input can't be negative.

Reviewed By: jbakker

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

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

M	source/blender/compositor/nodes/COM_GlareNode.cc
M	source/blender/compositor/operations/COM_MixOperation.cc

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

diff --git a/source/blender/compositor/nodes/COM_GlareNode.cc b/source/blender/compositor/nodes/COM_GlareNode.cc
index dbe9aaf73ed..0537074552a 100644
--- a/source/blender/compositor/nodes/COM_GlareNode.cc
+++ b/source/blender/compositor/nodes/COM_GlareNode.cc
@@ -63,7 +63,7 @@ void GlareNode::convertToOperations(NodeConverter &converter,
   thresholdOperation->setGlareSettings(glare);
 
   SetValueOperation *mixvalueoperation = new SetValueOperation();
-  mixvalueoperation->setValue(0.5f + glare->mix * 0.5f);
+  mixvalueoperation->setValue(glare->mix);
 
   MixGlareOperation *mixoperation = new MixGlareOperation();
   mixoperation->setResolutionInputSocketIndex(1);
diff --git a/source/blender/compositor/operations/COM_MixOperation.cc b/source/blender/compositor/operations/COM_MixOperation.cc
index 882326a04b1..58fa09fa2a8 100644
--- a/source/blender/compositor/operations/COM_MixOperation.cc
+++ b/source/blender/compositor/operations/COM_MixOperation.cc
@@ -462,27 +462,26 @@ void MixGlareOperation::executePixelSampled(float output[4],
   float inputColor1[4];
   float inputColor2[4];
   float inputValue[4];
-  float value;
+  float value, input_weight, glare_weight;
 
   this->m_inputValueOperation->readSampled(inputValue, x, y, sampler);
   this->m_inputColor1Operation->readSampled(inputColor1, x, y, sampler);
   this->m_inputColor2Operation->readSampled(inputColor2, x, y, sampler);
   value = inputValue[0];
-  float mf = 2.0f - 2.0f * fabsf(value - 0.5f);
-
-  if (inputColor1[0] < 0.0f) {
-    inputColor1[0] = 0.0f;
-  }
-  if (inputColor1[1] < 0.0f) {
-    inputColor1[1] = 0.0f;
+  /* Linear interpolation between 3 cases:
+   *  value=-1:output=input    value=0:output=input+glare   value=1:output=glare
+   */
+  if (value < 0.0f) {
+    input_weight = 1.0f;
+    glare_weight = 1.0f + value;
   }
-  if (inputColor1[2] < 0.0f) {
-    inputColor1[2] = 0.0f;
+  else {
+    input_weight = 1.0f - value;
+    glare_weight = 1.0f;
   }
-
-  output[0] = mf * MAX2(inputColor1[0] + value * (inputColor2[0] - inputColor1[0]), 0.0f);
-  output[1] = mf * MAX2(inputColor1[1] + value * (inputColor2[1] - inputColor1[1]), 0.0f);
-  output[2] = mf * MAX2(inputColor1[2] + value * (inputColor2[2] - inputColor1[2]), 0.0f);
+  output[0] = input_weight * MAX2(inputColor1[0], 0.0f) + glare_weight * inputColor2[0];
+  output[1] = input_weight * MAX2(inputColor1[1], 0.0f) + glare_weight * inputColor2[1];
+  output[2] = input_weight * MAX2(inputColor1[2], 0.0f) + glare_weight * inputColor2[2];
   output[3] = inputColor1[3];
 
   clampIfNeeded(output);



More information about the Bf-blender-cvs mailing list