diff options
-rw-r--r-- | source/blender/blenkernel/intern/material.c | 261 |
1 files changed, 115 insertions, 146 deletions
diff --git a/source/blender/blenkernel/intern/material.c b/source/blender/blenkernel/intern/material.c index fa0e886b784..ecf74b1d8e1 100644 --- a/source/blender/blenkernel/intern/material.c +++ b/source/blender/blenkernel/intern/material.c @@ -1178,8 +1178,7 @@ int object_remove_material_slot(Object *ob) } -/* r g b = current value, col = new value, fac==0 is no change */ -/* if g==NULL, it only does r channel */ +/* r_col = current value, col = new value, fac==0 is no change */ void ramp_blend(int type, float r_col[3], const float fac, const float col[3]) { float tmp, facm= 1.0f-fac; @@ -1187,165 +1186,137 @@ void ramp_blend(int type, float r_col[3], const float fac, const float col[3]) switch (type) { case MA_RAMP_BLEND: r_col[0] = facm*(r_col[0]) + fac*col[0]; - if(r_col[1]) { - r_col[1] = facm*(r_col[1]) + fac*col[1]; - r_col[2] = facm*(r_col[2]) + fac*col[2]; - } - break; + r_col[1] = facm*(r_col[1]) + fac*col[1]; + r_col[2] = facm*(r_col[2]) + fac*col[2]; + break; case MA_RAMP_ADD: r_col[0] += fac*col[0]; - if(r_col[1]) { - r_col[1] += fac*col[1]; - r_col[2] += fac*col[2]; - } - break; + r_col[1] += fac*col[1]; + r_col[2] += fac*col[2]; + break; case MA_RAMP_MULT: r_col[0] *= (facm + fac*col[0]); - if(r_col[1]) { - r_col[1] *= (facm + fac*col[1]); - r_col[2] *= (facm + fac*col[2]); - } - break; + r_col[1] *= (facm + fac*col[1]); + r_col[2] *= (facm + fac*col[2]); + break; case MA_RAMP_SCREEN: r_col[0] = 1.0f - (facm + fac*(1.0f - col[0])) * (1.0f - r_col[0]); - if(r_col[1]) { - r_col[1] = 1.0f - (facm + fac*(1.0f - col[1])) * (1.0f - r_col[1]); - r_col[2] = 1.0f - (facm + fac*(1.0f - col[2])) * (1.0f - r_col[2]); - } - break; + r_col[1] = 1.0f - (facm + fac*(1.0f - col[1])) * (1.0f - r_col[1]); + r_col[2] = 1.0f - (facm + fac*(1.0f - col[2])) * (1.0f - r_col[2]); + break; case MA_RAMP_OVERLAY: if(r_col[0] < 0.5f) r_col[0] *= (facm + 2.0f*fac*col[0]); else r_col[0] = 1.0f - (facm + 2.0f*fac*(1.0f - col[0])) * (1.0f - r_col[0]); - if(r_col[1]) { - if(r_col[1] < 0.5f) - r_col[1] *= (facm + 2.0f*fac*col[1]); - else - r_col[1] = 1.0f - (facm + 2.0f*fac*(1.0f - col[1])) * (1.0f - r_col[1]); - if(r_col[2] < 0.5f) - r_col[2] *= (facm + 2.0f*fac*col[2]); - else - r_col[2] = 1.0f - (facm + 2.0f*fac*(1.0f - col[2])) * (1.0f - r_col[2]); - } - break; + if(r_col[1] < 0.5f) + r_col[1] *= (facm + 2.0f*fac*col[1]); + else + r_col[1] = 1.0f - (facm + 2.0f*fac*(1.0f - col[1])) * (1.0f - r_col[1]); + if(r_col[2] < 0.5f) + r_col[2] *= (facm + 2.0f*fac*col[2]); + else + r_col[2] = 1.0f - (facm + 2.0f*fac*(1.0f - col[2])) * (1.0f - r_col[2]); + break; case MA_RAMP_SUB: r_col[0] -= fac*col[0]; - if(r_col[1]) { - r_col[1] -= fac*col[1]; - r_col[2] -= fac*col[2]; - } - break; + r_col[1] -= fac*col[1]; + r_col[2] -= fac*col[2]; + break; case MA_RAMP_DIV: if(col[0]!=0.0f) r_col[0] = facm*(r_col[0]) + fac*(r_col[0])/col[0]; - if(r_col[1]) { - if(col[1]!=0.0f) - r_col[1] = facm*(r_col[1]) + fac*(r_col[1])/col[1]; - if(col[2]!=0.0f) - r_col[2] = facm*(r_col[2]) + fac*(r_col[2])/col[2]; - } - break; + if(col[1]!=0.0f) + r_col[1] = facm*(r_col[1]) + fac*(r_col[1])/col[1]; + if(col[2]!=0.0f) + r_col[2] = facm*(r_col[2]) + fac*(r_col[2])/col[2]; + break; case MA_RAMP_DIFF: r_col[0] = facm*(r_col[0]) + fac*fabsf(r_col[0]-col[0]); - if(r_col[1]) { - r_col[1] = facm*(r_col[1]) + fac*fabsf(r_col[1]-col[1]); - r_col[2] = facm*(r_col[2]) + fac*fabsf(r_col[2]-col[2]); - } - break; + r_col[1] = facm*(r_col[1]) + fac*fabsf(r_col[1]-col[1]); + 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); + tmp=col[0]+((1-col[0])*facm); if(tmp < r_col[0]) r_col[0]= tmp; - if(r_col[1]) { - 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; - } - break; + 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; + break; case MA_RAMP_LIGHT: tmp= fac*col[0]; if(tmp > r_col[0]) r_col[0]= tmp; - if(r_col[1]) { - tmp= fac*col[1]; - if(tmp > r_col[1]) r_col[1]= tmp; - tmp= fac*col[2]; - if(tmp > r_col[2]) r_col[2]= tmp; - } - break; - case MA_RAMP_DODGE: - - + tmp= fac*col[1]; + if(tmp > r_col[1]) r_col[1]= tmp; + tmp= fac*col[2]; + if(tmp > r_col[2]) r_col[2]= tmp; + break; + case MA_RAMP_DODGE: if(r_col[0] !=0.0f){ tmp = 1.0f - fac*col[0]; if(tmp <= 0.0f) r_col[0] = 1.0f; else if ((tmp = (r_col[0]) / tmp)> 1.0f) r_col[0] = 1.0f; - else + else r_col[0] = tmp; } - if(r_col[1]) { - if(r_col[1] !=0.0f){ - tmp = 1.0f - fac*col[1]; - if(tmp <= 0.0f ) - r_col[1] = 1.0f; - else if ((tmp = (r_col[1]) / tmp) > 1.0f ) - r_col[1] = 1.0f; - else - r_col[1] = tmp; - } - if(r_col[2] !=0.0f){ - tmp = 1.0f - fac*col[2]; - if(tmp <= 0.0f) - r_col[2] = 1.0f; - else if ((tmp = (r_col[2]) / tmp) > 1.0f ) - r_col[2] = 1.0f; - else - r_col[2] = tmp; - } - + if(r_col[1] !=0.0f){ + tmp = 1.0f - fac*col[1]; + if(tmp <= 0.0f ) + r_col[1] = 1.0f; + else if ((tmp = (r_col[1]) / tmp) > 1.0f ) + r_col[1] = 1.0f; + else + r_col[1] = tmp; } - break; + if(r_col[2] !=0.0f){ + tmp = 1.0f - fac*col[2]; + if(tmp <= 0.0f) + r_col[2] = 1.0f; + else if ((tmp = (r_col[2]) / tmp) > 1.0f ) + r_col[2] = 1.0f; + else + r_col[2] = tmp; + } + break; case MA_RAMP_BURN: - tmp = facm + fac*col[0]; - + if(tmp <= 0.0f) r_col[0] = 0.0f; else if (( tmp = (1.0f - (1.0f - (r_col[0])) / tmp )) < 0.0f) r_col[0] = 0.0f; else if (tmp > 1.0f) r_col[0]=1.0f; - else + else r_col[0] = tmp; - if(r_col[1]) { - tmp = facm + fac*col[1]; - if(tmp <= 0.0f) + tmp = facm + fac*col[1]; + if(tmp <= 0.0f) + r_col[1] = 0.0f; + else if (( tmp = (1.0f - (1.0f - (r_col[1])) / tmp )) < 0.0f ) r_col[1] = 0.0f; - else if (( tmp = (1.0f - (1.0f - (r_col[1])) / tmp )) < 0.0f ) - r_col[1] = 0.0f; - else if(tmp >1.0f) - r_col[1]=1.0f; - else - r_col[1] = tmp; + else if(tmp >1.0f) + r_col[1]=1.0f; + else + r_col[1] = tmp; - tmp = facm + fac*col[2]; - if(tmp <= 0.0f) + tmp = facm + fac*col[2]; + if(tmp <= 0.0f) + r_col[2] = 0.0f; + else if (( tmp = (1.0f - (1.0f - (r_col[2])) / tmp )) < 0.0f ) r_col[2] = 0.0f; - else if (( tmp = (1.0f - (1.0f - (r_col[2])) / tmp )) < 0.0f ) - r_col[2] = 0.0f; - else if(tmp >1.0f) - r_col[2]= 1.0f; - else - r_col[2] = tmp; - } - break; - case MA_RAMP_HUE: - if(r_col[1]){ + else if(tmp >1.0f) + r_col[2]= 1.0f; + else + r_col[2] = tmp; + break; + case MA_RAMP_HUE: + { float rH,rS,rV; - float colH,colS,colV; + float colH,colS,colV; float tmpr,tmpg,tmpb; rgb_to_hsv(col[0],col[1],col[2],&colH,&colS,&colV); if(colS!=0 ){ @@ -1356,9 +1327,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*tmpb; } } - break; - case MA_RAMP_SAT: - if(r_col[1]){ + break; + case MA_RAMP_SAT: + { float rH,rS,rV; float colH,colS,colV; rgb_to_hsv(r_col[0],r_col[1],r_col[2],&rH,&rS,&rV); @@ -1367,18 +1338,18 @@ void ramp_blend(int type, float r_col[3], const float fac, const float col[3]) hsv_to_rgb( rH, (facm*rS +fac*colS), rV, r_col+0, r_col+1, r_col+2); } } - break; - case MA_RAMP_VAL: - if(r_col[1]){ + break; + case MA_RAMP_VAL: + { float rH,rS,rV; float colH,colS,colV; rgb_to_hsv(r_col[0],r_col[1],r_col[2],&rH,&rS,&rV); rgb_to_hsv(col[0],col[1],col[2],&colH,&colS,&colV); hsv_to_rgb( rH, rS, (facm*rV +fac*colV), r_col+0, r_col+1, r_col+2); } - break; - case MA_RAMP_COLOR: - if(r_col[1]){ + break; + case MA_RAMP_COLOR: + { float rH,rS,rV; float colH,colS,colV; float tmpr,tmpg,tmpb; @@ -1391,12 +1362,12 @@ void ramp_blend(int type, float r_col[3], const float fac, const float col[3]) r_col[2] = facm*(r_col[2]) + fac*tmpb; } } - break; - case MA_RAMP_SOFT: - if (r_col[1]){ - float scr, scg, scb; + break; + case MA_RAMP_SOFT: + { + float scr, scg, scb; - /* first calculate non-fac based Screen mix */ + /* first calculate non-fac based Screen mix */ scr = 1.0f - (1.0f - col[0]) * (1.0f - r_col[0]); scg = 1.0f - (1.0f - col[1]) * (1.0f - r_col[1]); scb = 1.0f - (1.0f - col[2]) * (1.0f - r_col[2]); @@ -1404,25 +1375,23 @@ void ramp_blend(int type, float r_col[3], const float fac, const float col[3]) r_col[0] = facm*(r_col[0]) + fac*(((1.0f - r_col[0]) * col[0] * (r_col[0])) + (r_col[0] * scr)); r_col[1] = facm*(r_col[1]) + fac*(((1.0f - r_col[1]) * col[1] * (r_col[1])) + (r_col[1] * scg)); r_col[2] = facm*(r_col[2]) + fac*(((1.0f - r_col[2]) * col[2] * (r_col[2])) + (r_col[2] * scb)); - } - break; - case MA_RAMP_LINEAR: - if (col[0] > 0.5f) + } + break; + case MA_RAMP_LINEAR: + if (col[0] > 0.5f) r_col[0] = r_col[0] + fac*(2.0f*(col[0]-0.5f)); - else + else r_col[0] = r_col[0] + fac*(2.0f*(col[0]) - 1.0f); - if (r_col[1]){ - if (col[1] > 0.5f) - r_col[1] = r_col[1] + fac*(2.0f*(col[1]-0.5f)); - else - r_col[1] = r_col[1] + fac*(2.0f*(col[1]) -1.0f); - if (col[2] > 0.5f) - r_col[2] = r_col[2] + fac*(2.0f*(col[2]-0.5f)); - else - r_col[2] = r_col[2] + fac*(2.0f*(col[2]) - 1.0f); - } - break; - } + if (col[1] > 0.5f) + r_col[1] = r_col[1] + fac*(2.0f*(col[1]-0.5f)); + else + r_col[1] = r_col[1] + fac*(2.0f*(col[1]) -1.0f); + if (col[2] > 0.5f) + r_col[2] = r_col[2] + fac*(2.0f*(col[2]-0.5f)); + else + r_col[2] = r_col[2] + fac*(2.0f*(col[2]) - 1.0f); + break; + } } /* copy/paste buffer, if we had a propper py api that would be better */ |