[Bf-blender-cvs] [255b076] master: Color managed luminance for shader ramp-in-energy

Campbell Barton noreply at git.blender.org
Thu Mar 19 03:11:49 CET 2015


Commit: 255b07681acfe2ce8dd3af7d5b032d3c759cb93e
Author: Campbell Barton
Date:   Thu Mar 19 12:59:36 2015 +1100
Branches: master
https://developer.blender.org/rB255b07681acfe2ce8dd3af7d5b032d3c759cb93e

Color managed luminance for shader ramp-in-energy

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

M	source/blender/render/intern/source/shadeoutput.c

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

diff --git a/source/blender/render/intern/source/shadeoutput.c b/source/blender/render/intern/source/shadeoutput.c
index 586345d..b29038b 100644
--- a/source/blender/render/intern/source/shadeoutput.c
+++ b/source/blender/render/intern/source/shadeoutput.c
@@ -962,7 +962,7 @@ static void ramp_diffuse_result(float *diff, ShadeInput *shi)
 }
 
 /* r,g,b denote energy, ramp is used with different values to make new material color */
-static void add_to_diffuse(float *diff, ShadeInput *shi, float is, float r, float g, float b)
+static void add_to_diffuse(float diff[3], const ShadeInput *shi, const float is, const float rgb[3])
 {
 	Material *ma= shi->mat;
 
@@ -971,9 +971,9 @@ static void add_to_diffuse(float *diff, ShadeInput *shi, float is, float r, floa
 		/* MA_RAMP_IN_RESULT is exceptional */
 		if (ma->rampin_col==MA_RAMP_IN_RESULT) {
 			/* normal add */
-			diff[0] += r * shi->r;
-			diff[1] += g * shi->g;
-			diff[2] += b * shi->b;
+			diff[0] += rgb[0] * shi->r;
+			diff[1] += rgb[1] * shi->g;
+			diff[2] += rgb[2] * shi->b;
 		}
 		else {
 			float colt[3], col[4];
@@ -982,40 +982,37 @@ static void add_to_diffuse(float *diff, ShadeInput *shi, float is, float r, floa
 			/* input */
 			switch (ma->rampin_col) {
 			case MA_RAMP_IN_ENERGY:
-				/* should use 'IMB_colormanagement_get_luminance' but we only have a vector version */
-				fac= 0.3f*r + 0.58f*g + 0.12f*b;
+				fac = IMB_colormanagement_get_luminance(rgb);
 				break;
 			case MA_RAMP_IN_SHADER:
-				fac= is;
+				fac = is;
 				break;
 			case MA_RAMP_IN_NOR:
-				fac= shi->view[0]*shi->vn[0] + shi->view[1]*shi->vn[1] + shi->view[2]*shi->vn[2];
+				fac = dot_v3v3(shi->view, shi->vn);
 				break;
 			default:
-				fac= 0.0f;
+				fac = 0.0f;
 				break;
 			}
 	
 			do_colorband(ma->ramp_col, fac, col);
 			
 			/* blending method */
-			fac= col[3]*ma->rampfac_col;
-			colt[0]= shi->r;
-			colt[1]= shi->g;
-			colt[2]= shi->b;
+			fac = col[3] * ma->rampfac_col;
+			copy_v3_v3(colt, &shi->r);
 
 			ramp_blend(ma->rampblend_col, colt, fac, col);
 
 			/* output to */
-			diff[0] += r * colt[0];
-			diff[1] += g * colt[1];
-			diff[2] += b * colt[2];
+			diff[0] += rgb[0] * colt[0];
+			diff[1] += rgb[1] * colt[1];
+			diff[2] += rgb[2] * colt[2];
 		}
 	}
 	else {
-		diff[0] += r * shi->r;
-		diff[1] += g * shi->g;
-		diff[2] += b * shi->b;
+		diff[0] += rgb[0] * shi->r;
+		diff[1] += rgb[1] * shi->g;
+		diff[2] += rgb[2] * shi->b;
 	}
 }
 
@@ -1484,20 +1481,42 @@ static void shade_one_light(LampRen *lar, ShadeInput *shi, ShadeResult *shr, int
 		/* in case 'no diffuse' we still do most calculus, spec can be in shadow.*/
 		if (!(lar->mode & LA_NO_DIFF)) {
 			if (i>0.0f) {
-				if (ma->mode & MA_SHADOW_TRA)
-					add_to_diffuse(shr->shad, shi, is, i*shadfac[0]*lacol[0], i*shadfac[1]*lacol[1], i*shadfac[2]*lacol[2]);
-				else
-					add_to_diffuse(shr->shad, shi, is, i*lacol[0], i*lacol[1], i*lacol[2]);
+				if (ma->mode & MA_SHADOW_TRA) {
+					const float tcol[3] = {
+					    i * shadfac[0] * lacol[0],
+					    i * shadfac[1] * lacol[1],
+					    i * shadfac[2] * lacol[2],
+					};
+					add_to_diffuse(shr->shad, shi, is, tcol);
+				}
+				else {
+					const float tcol[3] = {
+					    i * lacol[0],
+					    i * lacol[1],
+					    i * lacol[2],
+					};
+					add_to_diffuse(shr->shad, shi, is, tcol);
+				}
 			}
 			/* add light for colored shadow */
 			if (i_noshad>i && !(lashdw[0]==0 && lashdw[1]==0 && lashdw[2]==0)) {
-				add_to_diffuse(shr->shad, shi, is, lashdw[0]*(i_noshad-i)*lacol[0], lashdw[1]*(i_noshad-i)*lacol[1], lashdw[2]*(i_noshad-i)*lacol[2]);
+				const float tcol[3] = {
+				    lashdw[0] * (i_noshad - i) * lacol[0],
+				    lashdw[1] * (i_noshad - i) * lacol[1],
+				    lashdw[2] * (i_noshad - i) * lacol[2],
+				};
+				add_to_diffuse(shr->shad, shi, is, tcol);
 			}
 			if (i_noshad>0.0f) {
 				if (passflag & (SCE_PASS_DIFFUSE|SCE_PASS_SHADOW) ||
 				    ((passflag & SCE_PASS_COMBINED) && !(shi->combinedflag & SCE_PASS_SHADOW)))
 				{
-					add_to_diffuse(shr->diff, shi, is, i_noshad*lacol[0], i_noshad*lacol[1], i_noshad*lacol[2]);
+					const float tcol[3] = {
+					    i_noshad * lacol[0],
+					    i_noshad * lacol[1],
+					    i_noshad * lacol[2]
+					};
+					add_to_diffuse(shr->diff, shi, is, tcol);
 				}
 				else {
 					copy_v3_v3(shr->diff, shr->shad);




More information about the Bf-blender-cvs mailing list