code cleanup: color/bw conversion - use BLI color function.
change modifier to use the average of the RGB since perceptual conversion isn't really needed for modifiers.
This commit is contained in:
@@ -1301,14 +1301,12 @@ unsigned int *BKE_brush_gen_texture_cache(Brush *br, int half_side)
|
||||
* if the texture didn't give an RGB value, copy the intensity across
|
||||
*/
|
||||
if (hasrgb & TEX_RGB)
|
||||
texres.tin = (0.35f * texres.tr + 0.45f *
|
||||
texres.tg + 0.2f * texres.tb);
|
||||
texres.tin = rgb_to_grayscale(&texres.tr);
|
||||
|
||||
texres.tin = texres.tin * 255.0f;
|
||||
((char *)texcache)[(iy * side + ix) * 4] = (char)texres.tin;
|
||||
((char *)texcache)[(iy * side + ix) * 4 + 1] = (char)texres.tin;
|
||||
((char *)texcache)[(iy * side + ix) * 4 + 2] = (char)texres.tin;
|
||||
((char *)texcache)[(iy * side + ix) * 4 + 3] = (char)texres.tin;
|
||||
((char *)texcache)[(iy * side + ix) * 4] =
|
||||
((char *)texcache)[(iy * side + ix) * 4 + 1] =
|
||||
((char *)texcache)[(iy * side + ix) * 4 + 2] =
|
||||
((char *)texcache)[(iy * side + ix) * 4 + 3] = (char)(texres.tin * 255.0f);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -186,7 +186,7 @@ float paint_get_tex_pixel(Brush *br, float u, float v)
|
||||
hasrgb = multitex_ext(br->mtex.tex, co, NULL, NULL, 0, &texres);
|
||||
|
||||
if (hasrgb & TEX_RGB)
|
||||
texres.tin = (0.35f * texres.tr + 0.45f * texres.tg + 0.2f * texres.tb) * texres.ta;
|
||||
texres.tin = rgb_to_grayscale(&texres.tr) * texres.ta;
|
||||
|
||||
return texres.tin;
|
||||
}
|
||||
|
||||
@@ -77,14 +77,15 @@ void get_texture_value(Tex *texture, float *tex_co, TexResult *texres)
|
||||
result_type = multitex_ext_safe(texture, tex_co, texres);
|
||||
|
||||
/* if the texture gave an RGB value, we assume it didn't give a valid
|
||||
* intensity, so calculate one (formula from do_material_tex).
|
||||
* intensity, since this is in the context of modifiers don't use perceptual color conversion.
|
||||
* if the texture didn't give an RGB value, copy the intensity across
|
||||
*/
|
||||
if (result_type & TEX_RGB)
|
||||
texres->tin = (0.35f * texres->tr + 0.45f * texres->tg
|
||||
+ 0.2f * texres->tb);
|
||||
else
|
||||
texres->tr = texres->tg = texres->tb = texres->tin;
|
||||
if (result_type & TEX_RGB) {
|
||||
texres->tin= (1.0f / 3.0f) * (texres->tr + texres->tg + texres->tb);
|
||||
}
|
||||
else {
|
||||
copy_v3_fl(&texres->tr, texres->tin);
|
||||
}
|
||||
}
|
||||
|
||||
void get_texture_coords(MappingInfoModifierData *dmd, Object *ob,
|
||||
|
||||
@@ -73,11 +73,11 @@ static void texture_procedural(CompBuf *cbuf, float *out, float xco, float yco)
|
||||
col[3]= texres.tin;
|
||||
|
||||
if ((retval & TEX_RGB)) {
|
||||
col[0]= texres.tr;
|
||||
col[1]= texres.tg;
|
||||
col[2]= texres.tb;
|
||||
copy_v3_v3(col, &texres.tr);
|
||||
}
|
||||
else {
|
||||
copy_v3_fl(col, col[3]);
|
||||
}
|
||||
else col[0]= col[1]= col[2]= col[3];
|
||||
}
|
||||
else {
|
||||
copy_v3_v3(col, nor);
|
||||
|
||||
@@ -100,17 +100,13 @@ static void node_shader_exec_texture(void *data, bNode *node, bNodeStack **in, b
|
||||
else
|
||||
out[0]->vec[0]= texres.tin;
|
||||
|
||||
if ((retval & TEX_RGB)==0) {
|
||||
out[1]->vec[0]= out[0]->vec[0];
|
||||
out[1]->vec[1]= out[0]->vec[0];
|
||||
out[1]->vec[2]= out[0]->vec[0];
|
||||
out[1]->vec[3]= 1.0f;
|
||||
if ((retval & TEX_RGB) == 0) {
|
||||
copy_v3_fl(out[1]->vec, out[0]->vec[0]);
|
||||
out[1]->vec[3] = 1.0f;
|
||||
}
|
||||
else {
|
||||
out[1]->vec[0]= texres.tr;
|
||||
out[1]->vec[1]= texres.tg;
|
||||
out[1]->vec[2]= texres.tb;
|
||||
out[1]->vec[3]= 1.0f;
|
||||
copy_v3_v3(out[1]->vec, &texres.tr);
|
||||
out[1]->vec[3] = 1.0f;
|
||||
}
|
||||
|
||||
copy_v3_v3(out[2]->vec, nor);
|
||||
|
||||
@@ -54,8 +54,6 @@
|
||||
&texres->tr, &texres->tg, &texres->tb); \
|
||||
} \
|
||||
|
||||
#define RGBTOBW(r,g,b) ( r*0.35f + g*0.45f + b*0.2f ) /* keep this in sync with gpu_shader_material.glsl:rgbtobw */
|
||||
|
||||
struct HaloRen;
|
||||
struct ShadeInput;
|
||||
struct TexResult;
|
||||
|
||||
@@ -476,14 +476,14 @@ static int magic(Tex *tex, float *texvec, TexResult *texres)
|
||||
y/= turb;
|
||||
z/= turb;
|
||||
}
|
||||
texres->tr= 0.5f-x;
|
||||
texres->tg= 0.5f-y;
|
||||
texres->tb= 0.5f-z;
|
||||
texres->tr = 0.5f - x;
|
||||
texres->tg = 0.5f - y;
|
||||
texres->tb = 0.5f - z;
|
||||
|
||||
texres->tin= 0.3333f*(texres->tr+texres->tg+texres->tb);
|
||||
texres->tin= (1.0f / 3.0f) * (texres->tr + texres->tg + texres->tb);
|
||||
|
||||
BRICONTRGB;
|
||||
texres->ta= 1.0;
|
||||
texres->ta = 1.0f;
|
||||
|
||||
return TEX_RGB;
|
||||
}
|
||||
@@ -798,16 +798,10 @@ static int plugintex(Tex *tex, float *texvec, float *dxt, float *dyt, int osatex
|
||||
|
||||
if (rgbnor & TEX_RGB) {
|
||||
if (pit->version < 6) {
|
||||
texres->tr = pit->result[1];
|
||||
texres->tg = pit->result[2];
|
||||
texres->tb = pit->result[3];
|
||||
texres->ta = pit->result[4];
|
||||
copy_v4_v4(&texres->tr, pit->result + 1);
|
||||
}
|
||||
else {
|
||||
texres->tr = result[1];
|
||||
texres->tg = result[2];
|
||||
texres->tb = result[3];
|
||||
texres->ta = result[4];
|
||||
copy_v4_v4(&texres->tr, result + 1);
|
||||
}
|
||||
|
||||
BRICONTRGB;
|
||||
@@ -2012,14 +2006,14 @@ static int ntap_bump_compute(NTapBump *ntap_bump, ShadeInput *shi, MTex *mtex, T
|
||||
|
||||
// use texres for the center sample, set rgbnor
|
||||
rgbnor = multitex_mtex(shi, mtex, STll, dxt, dyt, texres);
|
||||
Hll = (fromrgb)? RGBTOBW(texres->tr, texres->tg, texres->tb) : texres->tin;
|
||||
Hll = (fromrgb) ? rgb_to_grayscale(&texres->tr) : texres->tin;
|
||||
|
||||
// use ttexr for the other 2 taps
|
||||
multitex_mtex(shi, mtex, STlr, dxt, dyt, &ttexr);
|
||||
Hlr = (fromrgb)? RGBTOBW(ttexr.tr, ttexr.tg, ttexr.tb) : ttexr.tin;
|
||||
Hlr = (fromrgb) ? rgb_to_grayscale(&ttexr.tr) : ttexr.tin;
|
||||
|
||||
multitex_mtex(shi, mtex, STul, dxt, dyt, &ttexr);
|
||||
Hul = (fromrgb)? RGBTOBW(ttexr.tr, ttexr.tg, ttexr.tb) : ttexr.tin;
|
||||
Hul = (fromrgb) ? rgb_to_grayscale(&ttexr.tr) : ttexr.tin;
|
||||
|
||||
dHdx = Hscale*(Hlr - Hll);
|
||||
dHdy = Hscale*(Hul - Hll);
|
||||
@@ -2050,17 +2044,17 @@ static int ntap_bump_compute(NTapBump *ntap_bump, ShadeInput *shi, MTex *mtex, T
|
||||
|
||||
// use texres for the center sample, set rgbnor
|
||||
rgbnor = multitex_mtex(shi, mtex, STc, dxt, dyt, texres);
|
||||
/* Hc = (fromrgb)? RGBTOBW(texres->tr, texres->tg, texres->tb) : texres->tin; */ /* UNUSED */
|
||||
/* Hc = (fromrgb) ? rgb_to_grayscale(&texres->tr) : texres->tin; */ /* UNUSED */
|
||||
|
||||
// use ttexr for the other taps
|
||||
multitex_mtex(shi, mtex, STl, dxt, dyt, &ttexr);
|
||||
Hl = (fromrgb)? RGBTOBW(ttexr.tr, ttexr.tg, ttexr.tb) : ttexr.tin;
|
||||
Hl = (fromrgb) ? rgb_to_grayscale(&ttexr.tr) : ttexr.tin;
|
||||
multitex_mtex(shi, mtex, STr, dxt, dyt, &ttexr);
|
||||
Hr = (fromrgb)? RGBTOBW(ttexr.tr, ttexr.tg, ttexr.tb) : ttexr.tin;
|
||||
Hr = (fromrgb) ? rgb_to_grayscale(&ttexr.tr) : ttexr.tin;
|
||||
multitex_mtex(shi, mtex, STd, dxt, dyt, &ttexr);
|
||||
Hd = (fromrgb)? RGBTOBW(ttexr.tr, ttexr.tg, ttexr.tb) : ttexr.tin;
|
||||
Hd = (fromrgb) ? rgb_to_grayscale(&ttexr.tr) : ttexr.tin;
|
||||
multitex_mtex(shi, mtex, STu, dxt, dyt, &ttexr);
|
||||
Hu = (fromrgb)? RGBTOBW(ttexr.tr, ttexr.tg, ttexr.tb) : ttexr.tin;
|
||||
Hu = (fromrgb) ? rgb_to_grayscale(&ttexr.tr) : ttexr.tin;
|
||||
|
||||
dHdx = Hscale*(Hr - Hl);
|
||||
dHdy = Hscale*(Hu - Hd);
|
||||
@@ -2356,8 +2350,8 @@ void do_material_tex(ShadeInput *shi, Render *re)
|
||||
/* texture output */
|
||||
|
||||
if ( (rgbnor & TEX_RGB) && (mtex->texflag & MTEX_RGBTOINT)) {
|
||||
texres.tin= (0.35f*texres.tr+0.45f*texres.tg+0.2f*texres.tb);
|
||||
rgbnor-= TEX_RGB;
|
||||
texres.tin = rgb_to_grayscale(&texres.tr);
|
||||
rgbnor -= TEX_RGB;
|
||||
}
|
||||
if (mtex->texflag & MTEX_NEGATIVE) {
|
||||
if (rgbnor & TEX_RGB) {
|
||||
@@ -2387,9 +2381,7 @@ void do_material_tex(ShadeInput *shi, Render *re)
|
||||
if ((rgbnor & TEX_NOR)==0) {
|
||||
/* make our own normal */
|
||||
if (rgbnor & TEX_RGB) {
|
||||
texres.nor[0]= texres.tr;
|
||||
texres.nor[1]= texres.tg;
|
||||
texres.nor[2]= texres.tb;
|
||||
copy_v3_v3(texres.nor, &texres.tr);
|
||||
}
|
||||
else {
|
||||
float co_nor= 0.5*cos(texres.tin-0.5f);
|
||||
@@ -2437,22 +2429,21 @@ void do_material_tex(ShadeInput *shi, Render *re)
|
||||
}
|
||||
|
||||
/* mapping */
|
||||
if (mtex->mapto & (MAP_COL+MAP_COLSPEC+MAP_COLMIR)) {
|
||||
if (mtex->mapto & (MAP_COL | MAP_COLSPEC | MAP_COLMIR)) {
|
||||
float tcol[3];
|
||||
|
||||
/* stencil maps on the texture control slider, not texture intensity value */
|
||||
|
||||
tcol[0]=texres.tr; tcol[1]=texres.tg; tcol[2]=texres.tb;
|
||||
|
||||
if ((rgbnor & TEX_RGB)==0) {
|
||||
tcol[0]= mtex->r;
|
||||
tcol[1]= mtex->g;
|
||||
tcol[2]= mtex->b;
|
||||
copy_v3_v3(tcol, &texres.tr);
|
||||
|
||||
if ((rgbnor & TEX_RGB) == 0) {
|
||||
copy_v3_v3(tcol, &mtex->r);
|
||||
}
|
||||
else if (mtex->mapto & MAP_ALPHA) {
|
||||
texres.tin= stencilTin;
|
||||
texres.tin = stencilTin;
|
||||
}
|
||||
else {
|
||||
texres.tin = texres.ta;
|
||||
}
|
||||
else texres.tin= texres.ta;
|
||||
|
||||
/* inverse gamma correction */
|
||||
if (tex->type==TEX_IMAGE) {
|
||||
@@ -2595,7 +2586,7 @@ void do_material_tex(ShadeInput *shi, Render *re)
|
||||
}
|
||||
|
||||
if (rgbnor & TEX_RGB) {
|
||||
texres.tin= (0.35f*texres.tr+0.45f*texres.tg+0.2f*texres.tb);
|
||||
texres.tin = rgb_to_grayscale(&texres.tr);
|
||||
}
|
||||
|
||||
factt= (0.5f-texres.tin)*mtex->dispfac*stencilTin; facmm= 1.0f-factt;
|
||||
@@ -2622,8 +2613,8 @@ void do_material_tex(ShadeInput *shi, Render *re)
|
||||
/* stencil maps on the texture control slider, not texture intensity value */
|
||||
|
||||
if (rgbnor & TEX_RGB) {
|
||||
if (texres.talpha) texres.tin= texres.ta;
|
||||
else texres.tin= (0.35f*texres.tr+0.45f*texres.tg+0.2f*texres.tb);
|
||||
if (texres.talpha) texres.tin = texres.ta;
|
||||
else texres.tin = rgb_to_grayscale(&texres.tr);
|
||||
}
|
||||
|
||||
if (mtex->mapto & MAP_REF) {
|
||||
@@ -2777,8 +2768,8 @@ void do_volume_tex(ShadeInput *shi, const float *xyz, int mapto_flag, float *col
|
||||
/* texture output */
|
||||
|
||||
if ( (rgbnor & TEX_RGB) && (mtex->texflag & MTEX_RGBTOINT)) {
|
||||
texres.tin= (0.35f*texres.tr+0.45f*texres.tg+0.2f*texres.tb);
|
||||
rgbnor-= TEX_RGB;
|
||||
texres.tin = rgb_to_grayscale(&texres.tr);
|
||||
rgbnor -= TEX_RGB;
|
||||
}
|
||||
if (mtex->texflag & MTEX_NEGATIVE) {
|
||||
if (rgbnor & TEX_RGB) {
|
||||
@@ -2807,17 +2798,14 @@ void do_volume_tex(ShadeInput *shi, const float *xyz, int mapto_flag, float *col
|
||||
|
||||
/* stencil maps on the texture control slider, not texture intensity value */
|
||||
|
||||
if ((rgbnor & TEX_RGB)==0) {
|
||||
tcol[0]= mtex->r;
|
||||
tcol[1]= mtex->g;
|
||||
tcol[2]= mtex->b;
|
||||
if ((rgbnor & TEX_RGB) == 0) {
|
||||
copy_v3_v3(tcol, &mtex->r);
|
||||
}
|
||||
else {
|
||||
tcol[0]=texres.tr;
|
||||
tcol[1]=texres.tg;
|
||||
tcol[2]=texres.tb;
|
||||
if (texres.talpha)
|
||||
copy_v3_v3(tcol, &texres.tr);
|
||||
if (texres.talpha) {
|
||||
texres.tin= texres.ta;
|
||||
}
|
||||
}
|
||||
|
||||
/* used for emit */
|
||||
@@ -2843,8 +2831,8 @@ void do_volume_tex(ShadeInput *shi, const float *xyz, int mapto_flag, float *col
|
||||
/* convert RGB to intensity if intensity info isn't provided */
|
||||
if (!(rgbnor & TEX_INT)) {
|
||||
if (rgbnor & TEX_RGB) {
|
||||
if (texres.talpha) texres.tin= texres.ta;
|
||||
else texres.tin= (0.35f*texres.tr+0.45f*texres.tg+0.2f*texres.tb);
|
||||
if (texres.talpha) texres.tin = texres.ta;
|
||||
else texres.tin = rgb_to_grayscale(&texres.tr);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user