[Bf-blender-cvs] [1dcf956] master: Fix for wrong behavior of 'darken' blend mode with factor.

Kevin Dietrich noreply at git.blender.org
Tue Apr 29 14:03:19 CEST 2014


Commit: 1dcf95684929806e80e3d0b514c8690cd757b1bd
Author: Kevin Dietrich
Date:   Mon Apr 28 17:38:34 2014 +0200
https://developer.blender.org/rB1dcf95684929806e80e3d0b514c8690cd757b1bd

Fix for wrong behavior of 'darken' blend mode with factor.

The formula was not consistent across Blender and behaved strangely, now it is
a simple linear blend between color1 and min(color1, color2).

Reviewed By: brecht

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

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

M	intern/cycles/kernel/shaders/node_mix.osl
M	intern/cycles/kernel/svm/svm_mix.h
M	source/blender/blenkernel/intern/material.c
M	source/blender/compositor/operations/COM_MixOperation.cpp
M	source/blender/gpu/shaders/gpu_shader_material.glsl
M	source/blender/render/intern/source/render_texture.c

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

diff --git a/intern/cycles/kernel/shaders/node_mix.osl b/intern/cycles/kernel/shaders/node_mix.osl
index c2c397c..dd54fd8 100644
--- a/intern/cycles/kernel/shaders/node_mix.osl
+++ b/intern/cycles/kernel/shaders/node_mix.osl
@@ -88,7 +88,7 @@ color node_mix_diff(float t, color col1, color col2)
 
 color node_mix_dark(float t, color col1, color col2)
 {
-	return min(col1, col2 * t);
+	return min(col1, col2) * t + col1 * (1.0 - t);
 }
 
 color node_mix_light(float t, color col1, color col2)
diff --git a/intern/cycles/kernel/svm/svm_mix.h b/intern/cycles/kernel/svm/svm_mix.h
index 4e834b7..015925a 100644
--- a/intern/cycles/kernel/svm/svm_mix.h
+++ b/intern/cycles/kernel/svm/svm_mix.h
@@ -89,7 +89,7 @@ ccl_device float3 svm_mix_diff(float t, float3 col1, float3 col2)
 
 ccl_device float3 svm_mix_dark(float t, float3 col1, float3 col2)
 {
-	return min(col1, col2*t);
+	return min(col1, col2)*t + col1*(1.0 - t);
 }
 
 ccl_device float3 svm_mix_light(float t, float3 col1, float3 col2)
diff --git a/source/blender/blenkernel/intern/material.c b/source/blender/blenkernel/intern/material.c
index b0b9a4f..c8ad920 100644
--- a/source/blender/blenkernel/intern/material.c
+++ b/source/blender/blenkernel/intern/material.c
@@ -1359,12 +1359,9 @@ void ramp_blend(int type, float r_col[3], const float fac, const float col[3])
 			r_col[2] = facm * (r_col[2]) + fac * fabsf(r_col[2] - col[2]);
 			break;
 		case MA_RAMP_DARK:
-			tmp = col[0] + ((1 - col[0]) * facm);
-			if (tmp < r_col[0]) r_col[0] = tmp;
-			tmp = col[1] + ((1 - col[1]) * facm);
-			if (tmp < r_col[1]) r_col[1] = tmp;
-			tmp = col[2] + ((1 - col[2]) * facm);
-			if (tmp < r_col[2]) r_col[2] = tmp;
+			r_col[0] = min_ff(r_col[0], col[0]) * fac + r_col[0] * facm;
+			r_col[1] = min_ff(r_col[1], col[1]) * fac + r_col[1] * facm;
+			r_col[2] = min_ff(r_col[2], col[2]) * fac + r_col[2] * facm;
 			break;
 		case MA_RAMP_LIGHT:
 			tmp = fac * col[0];
diff --git a/source/blender/compositor/operations/COM_MixOperation.cpp b/source/blender/compositor/operations/COM_MixOperation.cpp
index 247880c..0402532 100644
--- a/source/blender/compositor/operations/COM_MixOperation.cpp
+++ b/source/blender/compositor/operations/COM_MixOperation.cpp
@@ -292,17 +292,9 @@ void MixDarkenOperation::executePixelSampled(float output[4], float x, float y,
 		value *= inputColor2[3];
 	}
 	float valuem = 1.0f - value;
-	float tmp;
-	tmp = inputColor2[0] + ((1.0f - inputColor2[0]) * valuem);
-	if (tmp < inputColor1[0]) output[0] = tmp;
-	else output[0] = inputColor1[0];
-	tmp = inputColor2[1] + ((1.0f - inputColor2[1]) * valuem);
-	if (tmp < inputColor1[1]) output[1] = tmp;
-	else output[1] = inputColor1[1];
-	tmp = inputColor2[2] + ((1.0f - inputColor2[2]) * valuem);
-	if (tmp < inputColor1[2]) output[2] = tmp;
-	else output[2] = inputColor1[2];
-
+	output[0] = min_ff(inputColor1[0], inputColor2[0]) * value + inputColor1[0] * valuem;
+	output[1] = min_ff(inputColor1[1], inputColor2[1]) * value + inputColor1[1] * valuem;
+	output[2] = min_ff(inputColor1[2], inputColor2[2]) * value + inputColor1[2] * valuem;
 	output[3] = inputColor1[3];
 
 	clampIfNeeded(output);
diff --git a/source/blender/gpu/shaders/gpu_shader_material.glsl b/source/blender/gpu/shaders/gpu_shader_material.glsl
index 7edb5ec..4452d4e 100644
--- a/source/blender/gpu/shaders/gpu_shader_material.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_material.glsl
@@ -944,12 +944,9 @@ void mtex_rgb_dark(vec3 outcol, vec3 texcol, float fact, float facg, out vec3 in
 	fact *= facg;
 	facm = 1.0-fact;
 
-	col= texcol.r + ((1.0 -texcol.r)*facm);
-	if(col < outcol.r) incol.r = col; else incol.r = outcol.r;
-	col= texcol.g + ((1.0 -texcol.g)*facm);
-	if(col < outcol.g) incol.g = col; else incol.g = outcol.g;
-	col= texcol.b + ((1.0 -texcol.b)*facm);
-	if(col < outcol.b) incol.b = col; else incol.b = outcol.b;
+	incol.r = min(outcol.r, texcol.r) * fact + outcol.r * facm;
+	incol.g = min(outcol.g, texcol.g) * fact + outcol.g * facm;
+	incol.b = min(outcol.b, texcol.b) * fact + outcol.b * facm;
 }
 
 void mtex_rgb_light(vec3 outcol, vec3 texcol, float fact, float facg, out vec3 incol)
@@ -1078,8 +1075,7 @@ void mtex_value_dark(float outcol, float texcol, float fact, float facg, out flo
 	float facm;
 	mtex_value_vars(fact, facg, facm);
 
-	float col = fact*texcol;
-	if(col < outcol) incol = col; else incol = outcol;
+	incol = facm*outcol + fact*min(outcol, texcol);
 }
 
 void mtex_value_light(float outcol, float texcol, float fact, float facg, out float incol)
diff --git a/source/blender/render/intern/source/render_texture.c b/source/blender/render/intern/source/render_texture.c
index 9c7c673..3936305 100644
--- a/source/blender/render/intern/source/render_texture.c
+++ b/source/blender/render/intern/source/render_texture.c
@@ -1420,12 +1420,9 @@ void texture_rgb_blend(float in[3], const float tex[3], const float out[3], floa
 		fact*= facg;
 		facm= 1.0f-fact;
 		
-		col= tex[0]+((1-tex[0])*facm);
-		if (col < out[0]) in[0]= col; else in[0]= out[0];
-		col= tex[1]+((1-tex[1])*facm);
-		if (col < out[1]) in[1]= col; else in[1]= out[1];
-		col= tex[2]+((1-tex[2])*facm);
-		if (col < out[2]) in[2]= col; else in[2]= out[2];
+		in[0] = min_ff(out[0], tex[0])*fact + out[0]*facm;
+		in[1] = min_ff(out[1], tex[1])*fact + out[1]*facm;
+		in[2] = min_ff(out[2], tex[2])*fact + out[2]*facm;
 		break;
 
 	case MTEX_LIGHT:
@@ -1522,8 +1519,7 @@ float texture_value_blend(float tex, float out, float fact, float facg, int blen
 		break;
 
 	case MTEX_DARK:
-		col= fact*tex;
-		if (col < out) in= col; else in= out;
+		in = min_ff(out, tex)*fact + out*facm;
 		break;
 
 	case MTEX_LIGHT:




More information about the Bf-blender-cvs mailing list