committing patch #19252-Soft/Linear Light blend modes+Darken mode bug fix
authorRobert Holcomb <bob_holcomb@hotmail.com>
Thu, 10 Sep 2009 03:00:50 +0000 (03:00 +0000)
committerRobert Holcomb <bob_holcomb@hotmail.com>
Thu, 10 Sep 2009 03:00:50 +0000 (03:00 +0000)
source/blender/blenkernel/intern/material.c
source/blender/editors/space_node/drawnode.c
source/blender/makesdna/DNA_material_types.h
source/blender/makesdna/DNA_texture_types.h
source/blender/makesrna/intern/rna_material.c
source/blender/makesrna/intern/rna_texture.c
source/blender/render/intern/source/texture.c

index 53de570b55e92e9c4d2ee6ce9e47d1e31af82608..e6f9ac2f4047cd269d7043f5cd4b83403781d67d 100644 (file)
@@ -1031,15 +1031,15 @@ void ramp_blend(int type, float *r, float *g, float *b, float fac, float *col)
                        }
                                break;
                case MA_RAMP_DARK:
-                       tmp= fac*col[0];
-                       if(tmp < *r) *r= tmp; 
-                               if(g) {
-                                       tmp= fac*col[1];
-                                       if(tmp < *g) *g= tmp; 
-                                       tmp= fac*col[2];
-                                       if(tmp < *b) *b= tmp; 
-                               }
-                                       break;
+            tmp=col[0]+((1-col[0])*facm); 
+            if(tmp < *r) *r= tmp; 
+            if(g) { 
+                tmp=col[1]+((1-col[1])*facm); 
+                if(tmp < *g) *g= tmp; 
+                tmp=col[2]+((1-col[2])*facm); 
+                if(tmp < *b) *b= tmp; 
+            } 
+                break; 
                case MA_RAMP_LIGHT:
                        tmp= fac*col[0];
                        if(tmp > *r) *r= tmp; 
@@ -1169,8 +1169,37 @@ void ramp_blend(int type, float *r, float *g, float *b, float fac, float *col)
                                }
                        }
                                break;
-       }
-       
+        case MA_RAMP_SOFT: 
+            if (g){ 
+                float scr, scg, scb; 
+                 
+                /* first calculate non-fac based Screen mix */ 
+                scr = 1.0 - ((1.0 - col[0])) * (1.0 - *r); 
+                scg = 1.0 - ((1.0 - col[1])) * (1.0 - *g); 
+                scb = 1.0 - ((1.0 - col[2])) * (1.0 - *b); 
+                 
+                *r = facm*(*r) + fac*(((1.0 - *r) * col[0] * (*r)) + (*r * scr)); 
+                *g = facm*(*g) + fac*(((1.0 - *g) * col[1] * (*g)) + (*g * scg)); 
+                *b = facm*(*b) + fac*(((1.0 - *b) * col[2] * (*b)) + (*b * scb)); 
+            } 
+                break; 
+        case MA_RAMP_LINEAR: 
+            if (col[0] > 0.5)  
+                *r = *r + fac*(2*(col[0]-0.5)); 
+            else  
+                *r = *r + fac*(2*(col[0]) - 1); 
+            if (g){ 
+                if (col[1] > 0.5)  
+                    *g = *g + fac*(2*(col[1]-0.5)); 
+                else  
+                    *g = *g + fac*(2*(col[1]) -1); 
+                if (col[2] > 0.5)  
+                    *b = *b + fac*(2*(col[2]-0.5)); 
+                else  
+                    *b = *b + fac*(2*(col[2]) - 1); 
+            } 
+                break; 
+       }       
 }
 
 
index 2f64108384e4900d46e6c507ab1dc9d86058dbef..7617f328fd95160b719ede8d78bc565cf5ecde05 100644 (file)
@@ -247,7 +247,7 @@ static int node_buts_mix_rgb(uiBlock *block, bNodeTree *ntree, bNode *node, rctf
                
                /* blend type */
                uiBlockBeginAlign(block);
-               bt=uiDefButS(block, MENU, B_NODE_EXEC, "Mix %x0|Add %x1|Subtract %x3|Multiply %x2|Screen %x4|Overlay %x9|Divide %x5|Difference %x6|Darken %x7|Lighten %x8|Dodge %x10|Burn %x11|Color %x15|Value %x14|Saturation %x13|Hue %x12",
+               bt=uiDefButS(block, MENU, B_NODE_EXEC, "Mix %x0|Add %x1|Subtract %x3|Multiply %x2|Screen %x4|Overlay %x9|Divide %x5|Difference %x6|Darken %x7|Lighten %x8|Dodge %x10|Burn %x11|Color %x15|Value %x14|Saturation %x13|Hue %x12|Soft Light %x16|Linear Light %x17", 
                                         (short)butr->xmin, (short)butr->ymin, butr->xmax-butr->xmin -(a_but?20:0), 20, 
                                         &node->custom1, 0, 0, 0, 0, "");
                uiButSetFunc(bt, node_but_title_cb, node, bt);
index f268c11706539fbfeae196e7f4275b9b34bb7321..55e3c9107e49c787ae8019d64ed3635a443374f2 100644 (file)
@@ -279,6 +279,8 @@ typedef struct Material {
 #define MA_RAMP_SAT                    13
 #define MA_RAMP_VAL                    14
 #define MA_RAMP_COLOR          15
+#define MA_RAMP_SOFT        16 
+#define MA_RAMP_LINEAR      17 
 
 /* texco */
 #define TEXCO_ORCO             1
index 4df63ee9cd99d2dca36f2521f7d5941dfa604ebf..c13c0522004cec8b444883a95642629db912af49 100644 (file)
@@ -448,6 +448,8 @@ typedef struct TexMapping {
 #define MTEX_BLEND_VAL         12
 #define MTEX_BLEND_COLOR       13
 #define MTEX_NUM_BLENDTYPES    14
+#define MTEX_SOFT_LIGHT     15 
+#define MTEX_LIN_LIGHT      16
 
 /* brush_map_mode */
 #define MTEX_MAP_MODE_FIXED    0
index 651aeae217e2b3f17a89c056fed68f6a9a469871..cd1159bc1385683948e06c6864f732b6f719bd47 100644 (file)
@@ -616,6 +616,8 @@ static void rna_def_material_colors(StructRNA *srna)
                {MA_RAMP_SAT, "SATURATION", 0, "Saturation", ""},
                {MA_RAMP_VAL, "VALUE", 0, "Value", ""},
                {MA_RAMP_COLOR, "COLOR", 0, "Color", ""},
+        {MA_RAMP_SOFT, "SOFT LIGHT", 0, "Soft Light", ""}, 
+        {MA_RAMP_LINEAR, "LINEAR LIGHT", 0, "Linear Light", ""}, 
                {0, NULL, 0, NULL, NULL}};
 
        static EnumPropertyItem prop_ramp_input_items[] = {
index b11e5c6c12f41397257955d4df8b67a7a3ec03f4..f6835f3e7b5572281f3ad9968317af69e2058762 100644 (file)
@@ -374,6 +374,8 @@ static void rna_def_mtex(BlenderRNA *brna)
                {MTEX_BLEND_SAT, "SATURATION", 0, "Saturation", ""},
                {MTEX_BLEND_VAL, "VALUE", 0, "Value", ""},
                {MTEX_BLEND_COLOR, "COLOR", 0, "Color", ""},
+        {MTEX_SOFT_LIGHT, "SOFT LIGHT", 0, "Soft Light", ""}, 
+        {MTEX_LIN_LIGHT    , "LINEAR LIGHT", 0, "Linear Light", ""}, 
                {0, NULL, 0, NULL, NULL}};
 
        static EnumPropertyItem prop_map_mode_items[] = {
index 4d4a2c0480870b3c2e1b04ad06573b0d89d9da72..2d2c01e0bf14311c8f3b0b85dcfcfb723254f6a0 100644 (file)
@@ -1455,12 +1455,22 @@ void texture_rgb_blend(float *in, float *tex, float *out, float fact, float facg
                VECCOPY(in, out);
                ramp_blend(MA_RAMP_COLOR, in, in+1, in+2, fact, tex);
                break;
+    case MTEX_SOFT_LIGHT: 
+        fact*= facg; 
+        VECCOPY(in, out); 
+        ramp_blend(MA_RAMP_SOFT, in, in+1, in+2, fact, tex); 
+        break; 
+    case MTEX_LIN_LIGHT: 
+        fact*= facg; 
+        VECCOPY(in, out); 
+        ramp_blend(MA_RAMP_LINEAR, in, in+1, in+2, fact, tex); 
+        break; 
        }
 }
 
 float texture_value_blend(float tex, float out, float fact, float facg, int blendtype, int flip)
 {
-       float in=0.0, facm, col;
+       float in=0.0, facm, col, scf;
        
        fact*= facg;
        facm= 1.0-fact;
@@ -1505,6 +1515,19 @@ float texture_value_blend(float tex, float out, float fact, float facg, int blen
                col= fact*tex;
                if(col > out) in= col; else in= out;
                break;
+
+    case MTEX_SOFT_LIGHT: 
+        col= fact*tex; 
+        scf=1.0 - (1.0 - tex) * (1.0 - out); 
+        in= facm*out + fact * ((1.0 - out) * tex * out) + (out * scf); 
+        break;       
+
+    case MTEX_LIN_LIGHT: 
+        if (tex > 0.5) 
+            in = out + fact*(2*(tex - 0.5)); 
+        else 
+            in = out + fact*(2*tex - 1); 
+        break;
        }
        
        return in;