diff options
author | Jeroen Bakker <jeroen@blender.org> | 2022-01-28 15:28:31 +0300 |
---|---|---|
committer | Jeroen Bakker <jeroen@blender.org> | 2022-01-28 15:28:31 +0300 |
commit | cdcbdf8ce46d14c753d68ee8dfa533c642376805 (patch) | |
tree | 8557864b1f75f6a0a2c80df48692a7723c9e0300 | |
parent | 7c48196056c88c17c551e3177ef7b6f276f01d77 (diff) |
Remove compilation warnings TexResult.
19 files changed, 272 insertions, 284 deletions
diff --git a/source/blender/blenkernel/intern/dynamicpaint.c b/source/blender/blenkernel/intern/dynamicpaint.c index 64e0427a810..ef789d3e39b 100644 --- a/source/blender/blenkernel/intern/dynamicpaint.c +++ b/source/blender/blenkernel/intern/dynamicpaint.c @@ -1518,7 +1518,7 @@ static void dynamic_paint_set_init_color_tex_to_vcol_cb( multitex_ext_safe(tex, uv, &texres, pool, scene_color_manage, false); if (texres.tin > pPoint[vert].color[3]) { - copy_v3_v3(pPoint[vert].color, &texres.tr); + copy_v3_v3(pPoint[vert].color, texres.trgba); pPoint[vert].color[3] = texres.tin; } } @@ -1559,7 +1559,7 @@ static void dynamic_paint_set_init_color_tex_to_imseq_cb( multitex_ext_safe(tex, uv_final, &texres, NULL, scene_color_manage, false); /* apply color */ - copy_v3_v3(pPoint[i].color, &texres.tr); + copy_v3_v3(pPoint[i].color, texres.trgba); pPoint[i].color[3] = texres.tin; } diff --git a/source/blender/blenkernel/intern/effect.c b/source/blender/blenkernel/intern/effect.c index bbf9e9edfd2..1f1915f60ca 100644 --- a/source/blender/blenkernel/intern/effect.c +++ b/source/blender/blenkernel/intern/effect.c @@ -908,9 +908,9 @@ static void do_texture_effector(EffectorCache *eff, eff->pd->tex, tex_co, NULL, NULL, 0, result, 0, NULL, scene_color_manage, false); if (hasrgb && mode == PFIELD_TEX_RGB) { - force[0] = (0.5f - result->tr) * strength; - force[1] = (0.5f - result->tg) * strength; - force[2] = (0.5f - result->tb) * strength; + force[0] = (0.5f - result->trgba[0]) * strength; + force[1] = (0.5f - result->trgba[1]) * strength; + force[2] = (0.5f - result->trgba[2]) * strength; } else if (nabla != 0) { strength /= nabla; @@ -933,7 +933,8 @@ static void do_texture_effector(EffectorCache *eff, /* generate intensity if texture only has rgb value */ if (hasrgb & TEX_RGB) { for (int i = 0; i < 4; i++) { - result[i].tin = (1.0f / 3.0f) * (result[i].tr + result[i].tg + result[i].tb); + result[i].tin = (1.0f / 3.0f) * + (result[i].trgba[0] + result[i].trgba[1] + result[i].trgba[2]); } } force[0] = (result[0].tin - result[1].tin) * strength; @@ -943,12 +944,12 @@ static void do_texture_effector(EffectorCache *eff, else { /*PFIELD_TEX_CURL*/ float dbdy, dgdz, drdz, dbdx, dgdx, drdy; - dbdy = result[2].tb - result[0].tb; - dgdz = result[3].tg - result[0].tg; - drdz = result[3].tr - result[0].tr; - dbdx = result[1].tb - result[0].tb; - dgdx = result[1].tg - result[0].tg; - drdy = result[2].tr - result[0].tr; + dbdy = result[2].trgba[2] - result[0].trgba[2]; + dgdz = result[3].trgba[1] - result[0].trgba[1]; + drdz = result[3].trgba[0] - result[0].trgba[0]; + dbdx = result[1].trgba[2] - result[0].trgba[2]; + dgdx = result[1].trgba[1] - result[0].trgba[1]; + drdy = result[2].trgba[0] - result[0].trgba[0]; force[0] = (dbdy - dgdz) * strength; force[1] = (drdz - dbdx) * strength; diff --git a/source/blender/blenkernel/intern/texture.c b/source/blender/blenkernel/intern/texture.c index 37d5d732a70..c37e2fb6144 100644 --- a/source/blender/blenkernel/intern/texture.c +++ b/source/blender/blenkernel/intern/texture.c @@ -723,10 +723,10 @@ void BKE_texture_get_value_ex(const Scene *scene, * if the texture didn't give an RGB value, copy the intensity across */ if (result_type & TEX_RGB) { - texres->tin = (1.0f / 3.0f) * (texres->tr + texres->tg + texres->tb); + texres->tin = (1.0f / 3.0f) * (texres->trgba[0] + texres->trgba[1] + texres->trgba[2]); } else { - copy_v3_fl(&texres->tr, texres->tin); + copy_v3_fl(texres->trgba, texres->tin); } } diff --git a/source/blender/blenlib/intern/math_interp.c b/source/blender/blenlib/intern/math_interp.c index 54beb74abca..7225ca5fc94 100644 --- a/source/blender/blenlib/intern/math_interp.c +++ b/source/blender/blenlib/intern/math_interp.c @@ -709,6 +709,6 @@ void BLI_ewa_filter(const int width, /* d should hopefully never be zero anymore */ d = 1.0f / d; mul_v3_fl(result, d); - /* clipping can be ignored if alpha used, texr->ta already includes filtered edge */ + /* clipping can be ignored if alpha used, texr->trgba[3] already includes filtered edge */ result[3] = use_alpha ? result[3] * d : 1.0f; } diff --git a/source/blender/compositor/operations/COM_TextureOperation.cc b/source/blender/compositor/operations/COM_TextureOperation.cc index a4990993d73..069d00b5e66 100644 --- a/source/blender/compositor/operations/COM_TextureOperation.cc +++ b/source/blender/compositor/operations/COM_TextureOperation.cc @@ -133,11 +133,9 @@ void TextureBaseOperation::execute_pixel_sampled(float output[4], retval = multitex_ext( texture_, vec, nullptr, nullptr, 0, &texres, thread_id, pool_, scene_color_manage_, false); - output[3] = texres.talpha ? texres.ta : texres.tin; + output[3] = texres.talpha ? texres.trgba[3] : texres.tin; if (retval & TEX_RGB) { - output[0] = texres.tr; - output[1] = texres.tg; - output[2] = texres.tb; + copy_v3_v3(output, texres.trgba); } else { output[0] = output[1] = output[2] = output[3]; @@ -186,11 +184,9 @@ void TextureBaseOperation::update_memory_buffer_partial(MemoryBuffer *output, scene_color_manage_, false); - it.out[3] = tex_result.talpha ? tex_result.ta : tex_result.tin; + it.out[3] = tex_result.talpha ? tex_result.trgba[3] : tex_result.tin; if (retval & TEX_RGB) { - it.out[0] = tex_result.tr; - it.out[1] = tex_result.tg; - it.out[2] = tex_result.tb; + copy_v3_v3(it.out, tex_result.trgba); } else { it.out[0] = it.out[1] = it.out[2] = it.out[3]; diff --git a/source/blender/editors/render/render_preview.cc b/source/blender/editors/render/render_preview.cc index 79c3b2f7ac6..df078bbd890 100644 --- a/source/blender/editors/render/render_preview.cc +++ b/source/blender/editors/render/render_preview.cc @@ -1061,11 +1061,11 @@ static void shader_preview_texture(ShaderPreview *sp, Tex *tex, Scene *sce, Rend /* Evaluate texture at tex_coord. */ TexResult texres = {0}; BKE_texture_get_value_ex(sce, tex, tex_coord, &texres, img_pool, color_manage); - - rect_float[0] = texres.tr; - rect_float[1] = texres.tg; - rect_float[2] = texres.tb; - rect_float[3] = texres.talpha ? texres.ta : 1.0f; + copy_v4_fl4(rect_float, + texres.trgba[0], + texres.trgba[1], + texres.trgba[2], + texres.talpha ? texres.trgba[3] : 1.0f); rect_float += 4; } diff --git a/source/blender/makesrna/intern/rna_texture_api.c b/source/blender/makesrna/intern/rna_texture_api.c index 0920fe6679a..2a4cdaebcee 100644 --- a/source/blender/makesrna/intern/rna_texture_api.c +++ b/source/blender/makesrna/intern/rna_texture_api.c @@ -32,6 +32,7 @@ # include "BKE_context.h" # include "BKE_global.h" +# include "BLI_math.h" # include "DNA_scene_types.h" # include "IMB_imbuf.h" # include "IMB_imbuf_types.h" @@ -40,14 +41,12 @@ static void texture_evaluate(struct Tex *tex, float value[3], float r_color[4]) { - TexResult texres = {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0, NULL}; + TexResult texres = {0.0f}; /* TODO(sergey): always use color management now. */ multitex_ext(tex, value, NULL, NULL, 1, &texres, 0, NULL, true, false); - r_color[0] = texres.tr; - r_color[1] = texres.tg; - r_color[2] = texres.tb; + copy_v3_v3(r_color, texres.trgba); r_color[3] = texres.tin; } diff --git a/source/blender/modifiers/intern/MOD_displace.c b/source/blender/modifiers/intern/MOD_displace.c index 010292d2ebb..c81e6cafa39 100644 --- a/source/blender/modifiers/intern/MOD_displace.c +++ b/source/blender/modifiers/intern/MOD_displace.c @@ -262,9 +262,9 @@ static void displaceModifier_do_task(void *__restrict userdata, } break; case MOD_DISP_DIR_RGB_XYZ: - local_vec[0] = texres.tr - dmd->midlevel; - local_vec[1] = texres.tg - dmd->midlevel; - local_vec[2] = texres.tb - dmd->midlevel; + local_vec[0] = texres.trgba[0] - dmd->midlevel; + local_vec[1] = texres.trgba[1] - dmd->midlevel; + local_vec[2] = texres.trgba[2] - dmd->midlevel; if (use_global_direction) { mul_transposed_mat3_m4_v3(data->local_mat, local_vec); } diff --git a/source/blender/modifiers/intern/MOD_volume_displace.cc b/source/blender/modifiers/intern/MOD_volume_displace.cc index a1ca29f454c..af3a502162d 100644 --- a/source/blender/modifiers/intern/MOD_volume_displace.cc +++ b/source/blender/modifiers/intern/MOD_volume_displace.cc @@ -183,7 +183,7 @@ template<typename GridType> struct DisplaceOp { TexResult texture_result = {0}; BKE_texture_get_value( nullptr, this->texture, const_cast<float *>(pos.asV()), &texture_result, false); - return {texture_result.tr, texture_result.tg, texture_result.tb}; + return {texture_result.trgba[0], texture_result.trgba[1], texture_result.trgba[2]}; } }; diff --git a/source/blender/modifiers/intern/MOD_weightvg_util.c b/source/blender/modifiers/intern/MOD_weightvg_util.c index cd9e5162527..eedaea9d403 100644 --- a/source/blender/modifiers/intern/MOD_weightvg_util.c +++ b/source/blender/modifiers/intern/MOD_weightvg_util.c @@ -186,28 +186,32 @@ void weightvg_do_mask(const ModifierEvalContext *ctx, org_w[i] = (new_w[i] * texres.tin * fact) + (org_w[i] * (1.0f - (texres.tin * fact))); break; case MOD_WVG_MASK_TEX_USE_RED: - org_w[i] = (new_w[i] * texres.tr * fact) + (org_w[i] * (1.0f - (texres.tr * fact))); + org_w[i] = (new_w[i] * texres.trgba[0] * fact) + + (org_w[i] * (1.0f - (texres.trgba[0] * fact))); break; case MOD_WVG_MASK_TEX_USE_GREEN: - org_w[i] = (new_w[i] * texres.tg * fact) + (org_w[i] * (1.0f - (texres.tg * fact))); + org_w[i] = (new_w[i] * texres.trgba[1] * fact) + + (org_w[i] * (1.0f - (texres.trgba[1] * fact))); break; case MOD_WVG_MASK_TEX_USE_BLUE: - org_w[i] = (new_w[i] * texres.tb * fact) + (org_w[i] * (1.0f - (texres.tb * fact))); + org_w[i] = (new_w[i] * texres.trgba[2] * fact) + + (org_w[i] * (1.0f - (texres.trgba[2] * fact))); break; case MOD_WVG_MASK_TEX_USE_HUE: - rgb_to_hsv_v(&texres.tr, hsv); + rgb_to_hsv_v(texres.trgba, hsv); org_w[i] = (new_w[i] * hsv[0] * fact) + (org_w[i] * (1.0f - (hsv[0] * fact))); break; case MOD_WVG_MASK_TEX_USE_SAT: - rgb_to_hsv_v(&texres.tr, hsv); + rgb_to_hsv_v(texres.trgba, hsv); org_w[i] = (new_w[i] * hsv[1] * fact) + (org_w[i] * (1.0f - (hsv[1] * fact))); break; case MOD_WVG_MASK_TEX_USE_VAL: - rgb_to_hsv_v(&texres.tr, hsv); + rgb_to_hsv_v(texres.trgba, hsv); org_w[i] = (new_w[i] * hsv[2] * fact) + (org_w[i] * (1.0f - (hsv[2] * fact))); break; case MOD_WVG_MASK_TEX_USE_ALPHA: - org_w[i] = (new_w[i] * texres.ta * fact) + (org_w[i] * (1.0f - (texres.ta * fact))); + org_w[i] = (new_w[i] * texres.trgba[3] * fact) + + (org_w[i] * (1.0f - (texres.trgba[3] * fact))); break; default: org_w[i] = (new_w[i] * texres.tin * fact) + (org_w[i] * (1.0f - (texres.tin * fact))); diff --git a/source/blender/nodes/geometry/nodes/legacy/node_geo_legacy_attribute_sample_texture.cc b/source/blender/nodes/geometry/nodes/legacy/node_geo_legacy_attribute_sample_texture.cc index ae034d152be..a71431bdf8e 100644 --- a/source/blender/nodes/geometry/nodes/legacy/node_geo_legacy_attribute_sample_texture.cc +++ b/source/blender/nodes/geometry/nodes/legacy/node_geo_legacy_attribute_sample_texture.cc @@ -93,7 +93,7 @@ static void execute_on_component(GeometryComponent &component, const GeoNodeExec /* For legacy reasons we have to map [0, 1] to [-1, 1] to support uv mappings. */ const float3 remapped_position = position * 2.0f - float3(1.0f); BKE_texture_get_value(nullptr, texture, remapped_position, &texture_result, false); - colors[i] = {texture_result.tr, texture_result.tg, texture_result.tb, texture_result.ta}; + copy_v4_v4(colors[i], texture_result.trgba); } }); diff --git a/source/blender/nodes/texture/nodes/node_texture_output.c b/source/blender/nodes/texture/nodes/node_texture_output.c index 4911ab7ba9e..59c2d2766d0 100644 --- a/source/blender/nodes/texture/nodes/node_texture_output.c +++ b/source/blender/nodes/texture/nodes/node_texture_output.c @@ -49,10 +49,10 @@ static void exec(void *data, params_from_cdata(¶ms, cdata); if (in[1] && in[1]->hasinput && !in[0]->hasinput) { - tex_input_rgba(&target->tr, in[1], ¶ms, cdata->thread); + tex_input_rgba(target->trgba, in[1], ¶ms, cdata->thread); } else { - tex_input_rgba(&target->tr, in[0], ¶ms, cdata->thread); + tex_input_rgba(target->trgba, in[0], ¶ms, cdata->thread); } } else { @@ -61,9 +61,9 @@ static void exec(void *data, TexParams params; params_from_cdata(¶ms, cdata); - tex_input_rgba(&target->tr, in[0], ¶ms, cdata->thread); + tex_input_rgba(target->trgba, in[0], ¶ms, cdata->thread); - target->tin = (target->tr + target->tg + target->tb) / 3.0f; + target->tin = (target->trgba[0] + target->trgba[1] + target->trgba[2]) / 3.0f; target->talpha = true; if (target->nor) { diff --git a/source/blender/nodes/texture/nodes/node_texture_proc.c b/source/blender/nodes/texture/nodes/node_texture_proc.c index 8c294b5954d..38e4f0268e8 100644 --- a/source/blender/nodes/texture/nodes/node_texture_proc.c +++ b/source/blender/nodes/texture/nodes/node_texture_proc.c @@ -72,7 +72,7 @@ static void do_proc(float *result, } if (textype & TEX_RGB) { - copy_v4_v4(result, &texres.tr); + copy_v4_v4(result, texres.trgba); } else { copy_v4_v4(result, col1); diff --git a/source/blender/nodes/texture/nodes/node_texture_texture.c b/source/blender/nodes/texture/nodes/node_texture_texture.c index 083ae67ccb6..f8f8f25cb5a 100644 --- a/source/blender/nodes/texture/nodes/node_texture_texture.c +++ b/source/blender/nodes/texture/nodes/node_texture_texture.c @@ -71,7 +71,7 @@ static void colorfn(float *out, TexParams *p, bNode *node, bNodeStack **in, shor textype = multitex_nodes(nodetex, co, dxt, dyt, p->osatex, &texres, thread, 0, p->mtex, NULL); if (textype & TEX_RGB) { - copy_v4_v4(out, &texres.tr); + copy_v4_v4(out, texres.trgba); } else { copy_v4_v4(out, col1); diff --git a/source/blender/render/RE_texture.h b/source/blender/render/RE_texture.h index d71c793f300..c6ccc547ff4 100644 --- a/source/blender/render/RE_texture.h +++ b/source/blender/render/RE_texture.h @@ -99,10 +99,11 @@ void RE_point_density_fix_linking(void); /** * Texture evaluation result. - * \note `tr tg tb ta` have to remain in this order for array access. */ typedef struct TexResult { - float tin, tr, tg, tb, ta; + float tin; + float trgba[4]; + /* Is acually a bool true->use alpha, false->set alpha to 1.0. */ int talpha; float *nor; } TexResult; diff --git a/source/blender/render/intern/texture_common.h b/source/blender/render/intern/texture_common.h index 5fc3af6153f..43487439228 100644 --- a/source/blender/render/intern/texture_common.h +++ b/source/blender/render/intern/texture_common.h @@ -40,34 +40,38 @@ extern "C" { ((void)0) #define BRICONTRGB \ - texres->tr = tex->rfac * ((texres->tr - 0.5f) * tex->contrast + tex->bright - 0.5f); \ - texres->tg = tex->gfac * ((texres->tg - 0.5f) * tex->contrast + tex->bright - 0.5f); \ - texres->tb = tex->bfac * ((texres->tb - 0.5f) * tex->contrast + tex->bright - 0.5f); \ + texres->trgba[0] = tex->rfac * \ + ((texres->trgba[0] - 0.5f) * tex->contrast + tex->bright - 0.5f); \ + texres->trgba[1] = tex->gfac * \ + ((texres->trgba[1] - 0.5f) * tex->contrast + tex->bright - 0.5f); \ + texres->trgba[2] = tex->bfac * \ + ((texres->trgba[2] - 0.5f) * tex->contrast + tex->bright - 0.5f); \ if (!(tex->flag & TEX_NO_CLAMP)) { \ - if (texres->tr < 0.0f) { \ - texres->tr = 0.0f; \ + if (texres->trgba[0] < 0.0f) { \ + texres->trgba[0] = 0.0f; \ } \ - if (texres->tg < 0.0f) { \ - texres->tg = 0.0f; \ + if (texres->trgba[1] < 0.0f) { \ + texres->trgba[1] = 0.0f; \ } \ - if (texres->tb < 0.0f) { \ - texres->tb = 0.0f; \ + if (texres->trgba[2] < 0.0f) { \ + texres->trgba[2] = 0.0f; \ } \ } \ if (tex->saturation != 1.0f) { \ float _hsv[3]; \ - rgb_to_hsv(texres->tr, texres->tg, texres->tb, _hsv, _hsv + 1, _hsv + 2); \ + rgb_to_hsv(texres->trgba[0], texres->trgba[1], texres->trgba[2], _hsv, _hsv + 1, _hsv + 2); \ _hsv[1] *= tex->saturation; \ - hsv_to_rgb(_hsv[0], _hsv[1], _hsv[2], &texres->tr, &texres->tg, &texres->tb); \ + hsv_to_rgb( \ + _hsv[0], _hsv[1], _hsv[2], &texres->trgba[0], &texres->trgba[1], &texres->trgba[2]); \ if ((tex->saturation > 1.0f) && !(tex->flag & TEX_NO_CLAMP)) { \ - if (texres->tr < 0.0f) { \ - texres->tr = 0.0f; \ + if (texres->trgba[0] < 0.0f) { \ + texres->trgba[0] = 0.0f; \ } \ - if (texres->tg < 0.0f) { \ - texres->tg = 0.0f; \ + if (texres->trgba[1] < 0.0f) { \ + texres->trgba[1] = 0.0f; \ } \ - if (texres->tb < 0.0f) { \ - texres->tb = 0.0f; \ + if (texres->trgba[2] < 0.0f) { \ + texres->trgba[2] = 0.0f; \ } \ } \ } \ diff --git a/source/blender/render/intern/texture_image.c b/source/blender/render/intern/texture_image.c index 6ded799b773..914fc22ecaf 100644 --- a/source/blender/render/intern/texture_image.c +++ b/source/blender/render/intern/texture_image.c @@ -108,7 +108,7 @@ int imagewrap(Tex *tex, int x, y, retval; int xi, yi; /* original values */ - texres->tin = texres->ta = texres->tr = texres->tg = texres->tb = 0.0f; + texres->tin = texres->trgba[3] = texres->trgba[0] = texres->trgba[1] = texres->trgba[2] = 0.0f; /* we need to set retval OK, otherwise texture code generates normals itself... */ retval = texres->nor ? (TEX_RGB | TEX_NOR) : TEX_RGB; @@ -269,7 +269,7 @@ int imagewrap(Tex *tex, (tex->extend == TEX_EXTEND)); } else { /* no filtering */ - ibuf_get_color(&texres->tr, ibuf, x, y); + ibuf_get_color(texres->trgba, ibuf, x, y); } if (texres->nor) { @@ -281,13 +281,13 @@ int imagewrap(Tex *tex, * the normal used in the renderer points inward. It is generated * this way in calc_vertexnormals(). Should this ever change * this negate must be removed. */ - texres->nor[0] = -2.0f * (texres->tr - 0.5f); - texres->nor[1] = 2.0f * (texres->tg - 0.5f); - texres->nor[2] = 2.0f * (texres->tb - 0.5f); + texres->nor[0] = -2.0f * (texres->trgba[0] - 0.5f); + texres->nor[1] = 2.0f * (texres->trgba[1] - 0.5f); + texres->nor[2] = 2.0f * (texres->trgba[2] - 0.5f); } else { /* bump: take three samples */ - val1 = texres->tr + texres->tg + texres->tb; + val1 = texres->trgba[0] + texres->trgba[1] + texres->trgba[2]; if (x < ibuf->x - 1) { float col[4]; @@ -314,26 +314,26 @@ int imagewrap(Tex *tex, } if (texres->talpha) { - texres->tin = texres->ta; + texres->tin = texres->trgba[3]; } else if (tex->imaflag & TEX_CALCALPHA) { - texres->ta = texres->tin = max_fff(texres->tr, texres->tg, texres->tb); + texres->trgba[3] = texres->tin = max_fff(texres->trgba[0], texres->trgba[1], texres->trgba[2]); } else { - texres->ta = texres->tin = 1.0; + texres->trgba[3] = texres->tin = 1.0; } if (tex->flag & TEX_NEGALPHA) { - texres->ta = 1.0f - texres->ta; + texres->trgba[3] = 1.0f - texres->trgba[3]; } /* de-premul, this is being pre-multiplied in shade_input_do_shade() * do not de-premul for generated alpha, it is already in straight */ - if (texres->ta != 1.0f && texres->ta > 1e-4f && !(tex->imaflag & TEX_CALCALPHA)) { - fx = 1.0f / texres->ta; - texres->tr *= fx; - texres->tg *= fx; - texres->tb *= fx; + if (texres->trgba[3] != 1.0f && texres->trgba[3] > 1e-4f && !(tex->imaflag & TEX_CALCALPHA)) { + fx = 1.0f / texres->trgba[3]; + texres->trgba[0] *= fx; + texres->trgba[1] *= fx; + texres->trgba[2] *= fx; } if (ima) { @@ -546,10 +546,10 @@ static void boxsampleclip(struct ImBuf *ibuf, rctf *rf, TexResult *texres) } if (starty == endy && startx == endx) { - ibuf_get_color(&texres->tr, ibuf, startx, starty); + ibuf_get_color(texres->trgba, ibuf, startx, starty); } else { - div = texres->tr = texres->tg = texres->tb = texres->ta = 0.0; + div = texres->trgba[0] = texres->trgba[1] = texres->trgba[2] = texres->trgba[3] = 0.0; for (y = starty; y <= endy; y++) { muly = 1.0; @@ -570,11 +570,7 @@ static void boxsampleclip(struct ImBuf *ibuf, rctf *rf, TexResult *texres) mulx = muly; ibuf_get_color(col, ibuf, startx, y); - - texres->ta += mulx * col[3]; - texres->tr += mulx * col[0]; - texres->tg += mulx * col[1]; - texres->tb += mulx * col[2]; + madd_v4_v4fl(texres->trgba, col, mulx); div += mulx; } else { @@ -588,19 +584,14 @@ static void boxsampleclip(struct ImBuf *ibuf, rctf *rf, TexResult *texres) } ibuf_get_color(col, ibuf, x, y); - + /* TODO(jbakker): No need to do manual optimization. Branching is slower than multiplying + * with 1. */ if (mulx == 1.0f) { - texres->ta += col[3]; - texres->tr += col[0]; - texres->tg += col[1]; - texres->tb += col[2]; + add_v4_v4(texres->trgba, col); div += 1.0f; } else { - texres->ta += mulx * col[3]; - texres->tr += mulx * col[0]; - texres->tg += mulx * col[1]; - texres->tb += mulx * col[2]; + madd_v4_v4fl(texres->trgba, col, mulx); div += mulx; } } @@ -609,13 +600,10 @@ static void boxsampleclip(struct ImBuf *ibuf, rctf *rf, TexResult *texres) if (div != 0.0f) { div = 1.0f / div; - texres->tb *= div; - texres->tg *= div; - texres->tr *= div; - texres->ta *= div; + mul_v4_fl(texres->trgba, div) } else { - texres->tr = texres->tg = texres->tb = texres->ta = 0.0f; + zero_v4(texres->trgba); } } } @@ -663,7 +651,7 @@ static void boxsample(ImBuf *ibuf, alphaclip = clipx_rctf(rf, 0.0, (float)(ibuf->x)); if (alphaclip <= 0.0f) { - texres->tr = texres->tb = texres->tg = texres->ta = 0.0; + texres->trgba[0] = texres->trgba[2] = texres->trgba[1] = texres->trgba[3] = 0.0; return; } } @@ -679,33 +667,33 @@ static void boxsample(ImBuf *ibuf, alphaclip *= clipy_rctf(rf, 0.0, (float)(ibuf->y)); if (alphaclip <= 0.0f) { - texres->tr = texres->tb = texres->tg = texres->ta = 0.0; + texres->trgba[0] = texres->trgba[2] = texres->trgba[1] = texres->trgba[3] = 0.0; return; } } if (count > 1) { - tot = texres->tr = texres->tb = texres->tg = texres->ta = 0.0; + tot = texres->trgba[0] = texres->trgba[2] = texres->trgba[1] = texres->trgba[3] = 0.0; while (count--) { boxsampleclip(ibuf, rf, &texr); opp = square_rctf(rf); tot += opp; - texres->tr += opp * texr.tr; - texres->tg += opp * texr.tg; - texres->tb += opp * texr.tb; + texres->trgba[0] += opp * texr.trgba[0]; + texres->trgba[1] += opp * texr.trgba[1]; + texres->trgba[2] += opp * texr.trgba[2]; if (texres->talpha) { - texres->ta += opp * texr.ta; + texres->trgba[3] += opp * texr.trgba[3]; } rf++; } if (tot != 0.0f) { - texres->tr /= tot; - texres->tg /= tot; - texres->tb /= tot; + texres->trgba[0] /= tot; + texres->trgba[1] /= tot; + texres->trgba[2] /= tot; if (texres->talpha) { - texres->ta /= tot; + texres->trgba[3] /= tot; } } } @@ -714,15 +702,15 @@ static void boxsample(ImBuf *ibuf, } if (texres->talpha == 0) { - texres->ta = 1.0; + texres->trgba[3] = 1.0; } if (alphaclip != 1.0f) { /* premul it all */ - texres->tr *= alphaclip; - texres->tg *= alphaclip; - texres->tb *= alphaclip; - texres->ta *= alphaclip; + texres->trgba[0] *= alphaclip; + texres->trgba[1] *= alphaclip; + texres->trgba[2] *= alphaclip; + texres->trgba[3] *= alphaclip; } } @@ -850,7 +838,7 @@ static void area_sample(TexResult *texr, ImBuf *ibuf, float fx, float fy, afdata ysam = CLAMPIS(ysam, minsam, ibuf->y * 2); xsd = 1.0f / xsam; ysd = 1.0f / ysam; - texr->tr = texr->tg = texr->tb = texr->ta = 0.0f; + texr->trgba[0] = texr->trgba[1] = texr->trgba[2] = texr->trgba[3] = 0.0f; for (ys = 0; ys < ysam; ys++) { for (xs = 0; xs < xsam; xs++) { const float su = (xs + ((ys & 1) + 0.5f) * 0.5f) * xsd - 0.5f; @@ -861,18 +849,18 @@ static void area_sample(TexResult *texr, ImBuf *ibuf, float fx, float fy, afdata tc, ibuf, pu * ibuf->x, pv * ibuf->y, AFD->intpol, AFD->extflag); clip |= out; cw += out ? 0.0f : 1.0f; - texr->tr += tc[0]; - texr->tg += tc[1]; - texr->tb += tc[2]; - texr->ta += texr->talpha ? tc[3] : 0.0f; + texr->trgba[0] += tc[0]; + texr->trgba[1] += tc[1]; + texr->trgba[2] += tc[2]; + texr->trgba[3] += texr->talpha ? tc[3] : 0.0f; } } xsd *= ysd; - texr->tr *= xsd; - texr->tg *= xsd; - texr->tb *= xsd; - /* clipping can be ignored if alpha used, texr->ta already includes filtered edge */ - texr->ta = texr->talpha ? texr->ta * xsd : (clip ? cw * xsd : 1.0f); + texr->trgba[0] *= xsd; + texr->trgba[1] *= xsd; + texr->trgba[2] *= xsd; + /* clipping can be ignored if alpha used, texr->trgba[3] already includes filtered edge */ + texr->trgba[3] = texr->talpha ? texr->trgba[3] * xsd : (clip ? cw * xsd : 1.0f); } typedef struct ReadEWAData { @@ -901,7 +889,7 @@ static void ewa_eval(TexResult *texr, ImBuf *ibuf, float fx, float fy, afdata_t AFD->dyt, ewa_read_pixel_cb, &data, - &texr->tr); + texr->trgba); } static void feline_eval(TexResult *texr, ImBuf *ibuf, float fx, float fy, afdata_t *AFD) @@ -919,7 +907,7 @@ static void feline_eval(TexResult *texr, ImBuf *ibuf, float fx, float fy, afdata /* have to use same scaling for du/dv here as for Ux/Vx/Uy/Vy (*after* D calc.) */ du *= AFD->dusc; dv *= AFD->dvsc; - d = texr->tr = texr->tb = texr->tg = texr->ta = 0.0f; + d = texr->trgba[0] = texr->trgba[2] = texr->trgba[1] = texr->trgba[3] = 0.0f; for (n = -maxn; n <= maxn; n += 2) { float tc[4]; const float hn = n * 0.5f; @@ -934,19 +922,20 @@ static void feline_eval(TexResult *texr, ImBuf *ibuf, float fx, float fy, afdata tc, ibuf, ibuf->x * u, ibuf->y * v, AFD->intpol, AFD->extflag); /* TXF alpha: `clip |= out;` * TXF alpha: `cw += out ? 0.0f : wt;` */ - texr->tr += tc[0] * wt; - texr->tg += tc[1] * wt; - texr->tb += tc[2] * wt; - texr->ta += texr->talpha ? tc[3] * wt : 0.0f; + texr->trgba[0] += tc[0] * wt; + texr->trgba[1] += tc[1] * wt; + texr->trgba[2] += tc[2] * wt; + texr->trgba[3] += texr->talpha ? tc[3] * wt : 0.0f; d += wt; } d = 1.0f / d; - texr->tr *= d; - texr->tg *= d; - texr->tb *= d; - /* Clipping can be ignored if alpha used, `texr->ta` already includes filtered edge */ - texr->ta = texr->talpha ? texr->ta * d : 1.0f; /* TXF alpha: `(clip ? cw*d : 1.0f);` */ + texr->trgba[0] *= d; + texr->trgba[1] *= d; + texr->trgba[2] *= d; + /* Clipping can be ignored if alpha used, `texr->trgba[3]` already includes filtered edge */ + texr->trgba[3] = texr->talpha ? texr->trgba[3] * d : + 1.0f; /* TXF alpha: `(clip ? cw*d : 1.0f);` */ } #undef EWA_MAXIDX @@ -971,10 +960,10 @@ static void alpha_clip_aniso( if (alphaclip != 1.0f) { /* premul it all */ - texres->tr *= alphaclip; - texres->tg *= alphaclip; - texres->tb *= alphaclip; - texres->ta *= alphaclip; + texres->trgba[0] *= alphaclip; + texres->trgba[1] *= alphaclip; + texres->trgba[2] *= alphaclip; + texres->trgba[3] *= alphaclip; } } } @@ -1033,7 +1022,7 @@ static int imagewraposa_aniso(Tex *tex, filterfunc = area_sample; } - texres->tin = texres->ta = texres->tr = texres->tg = texres->tb = 0.0f; + texres->tin = texres->trgba[3] = texres->trgba[0] = texres->trgba[1] = texres->trgba[2] = 0.0f; /* we need to set retval OK, otherwise texture code generates normals itself... */ retval = texres->nor ? (TEX_RGB | TEX_NOR) : TEX_RGB; @@ -1332,27 +1321,27 @@ static int imagewraposa_aniso(Tex *tex, if (texres->nor && ((tex->imaflag & TEX_NORMALMAP) == 0)) { /* color & normal */ filterfunc(texres, curibuf, fx, fy, &AFD); - val1 = texres->tr + texres->tg + texres->tb; + val1 = texres->trgba[0] + texres->trgba[1] + texres->trgba[2]; filterfunc(&texr, curibuf, fx + dxt[0], fy + dxt[1], &AFD); - val2 = texr.tr + texr.tg + texr.tb; + val2 = texr.trgba[0] + texr.trgba[1] + texr.trgba[2]; filterfunc(&texr, curibuf, fx + dyt[0], fy + dyt[1], &AFD); - val3 = texr.tr + texr.tg + texr.tb; + val3 = texr.trgba[0] + texr.trgba[1] + texr.trgba[2]; /* don't switch x or y! */ texres->nor[0] = val1 - val2; texres->nor[1] = val1 - val3; if (previbuf != curibuf) { /* interpolate */ filterfunc(&texr, previbuf, fx, fy, &AFD); /* rgb */ - texres->tr += levf * (texr.tr - texres->tr); - texres->tg += levf * (texr.tg - texres->tg); - texres->tb += levf * (texr.tb - texres->tb); - texres->ta += levf * (texr.ta - texres->ta); + texres->trgba[0] += levf * (texr.trgba[0] - texres->trgba[0]); + texres->trgba[1] += levf * (texr.trgba[1] - texres->trgba[1]); + texres->trgba[2] += levf * (texr.trgba[2] - texres->trgba[2]); + texres->trgba[3] += levf * (texr.trgba[3] - texres->trgba[3]); /* normal */ - val1 += levf * ((texr.tr + texr.tg + texr.tb) - val1); + val1 += levf * ((texr.trgba[0] + texr.trgba[1] + texr.trgba[2]) - val1); filterfunc(&texr, previbuf, fx + dxt[0], fy + dxt[1], &AFD); - val2 += levf * ((texr.tr + texr.tg + texr.tb) - val2); + val2 += levf * ((texr.trgba[0] + texr.trgba[1] + texr.trgba[2]) - val2); filterfunc(&texr, previbuf, fx + dyt[0], fy + dyt[1], &AFD); - val3 += levf * ((texr.tr + texr.tg + texr.tb) - val3); + val3 += levf * ((texr.trgba[0] + texr.trgba[1] + texr.trgba[2]) - val3); texres->nor[0] = val1 - val2; /* vals have been interpolated above! */ texres->nor[1] = val1 - val3; } @@ -1361,10 +1350,10 @@ static int imagewraposa_aniso(Tex *tex, filterfunc(texres, curibuf, fx, fy, &AFD); if (previbuf != curibuf) { /* interpolate */ filterfunc(&texr, previbuf, fx, fy, &AFD); - texres->tr += levf * (texr.tr - texres->tr); - texres->tg += levf * (texr.tg - texres->tg); - texres->tb += levf * (texr.tb - texres->tb); - texres->ta += levf * (texr.ta - texres->ta); + texres->trgba[0] += levf * (texr.trgba[0] - texres->trgba[0]); + texres->trgba[1] += levf * (texr.trgba[1] - texres->trgba[1]); + texres->trgba[2] += levf * (texr.trgba[2] - texres->trgba[2]); + texres->trgba[3] += levf * (texr.trgba[3] - texres->trgba[3]); } if (tex->texfilter != TXF_EWA) { @@ -1402,11 +1391,11 @@ static int imagewraposa_aniso(Tex *tex, if (texres->nor && ((tex->imaflag & TEX_NORMALMAP) == 0)) { /* color & normal */ filterfunc(texres, ibuf, fx, fy, &AFD); - val1 = texres->tr + texres->tg + texres->tb; + val1 = texres->trgba[0] + texres->trgba[1] + texres->trgba[2]; filterfunc(&texr, ibuf, fx + dxt[0], fy + dxt[1], &AFD); - val2 = texr.tr + texr.tg + texr.tb; + val2 = texr.trgba[0] + texr.trgba[1] + texr.trgba[2]; filterfunc(&texr, ibuf, fx + dyt[0], fy + dyt[1], &AFD); - val3 = texr.tr + texr.tg + texr.tb; + val3 = texr.trgba[0] + texr.trgba[1] + texr.trgba[2]; /* don't switch x or y! */ texres->nor[0] = val1 - val2; texres->nor[1] = val1 - val3; @@ -1420,13 +1409,14 @@ static int imagewraposa_aniso(Tex *tex, } if (tex->imaflag & TEX_CALCALPHA) { - texres->ta = texres->tin = texres->ta * max_fff(texres->tr, texres->tg, texres->tb); + texres->trgba[3] = texres->tin = texres->trgba[3] * + max_fff(texres->trgba[0], texres->trgba[1], texres->trgba[2]); } else { - texres->tin = texres->ta; + texres->tin = texres->trgba[3]; } if (tex->flag & TEX_NEGALPHA) { - texres->ta = 1.0f - texres->ta; + texres->trgba[3] = 1.0f - texres->trgba[3]; } if (texres->nor && (tex->imaflag & TEX_NORMALMAP)) { /* normal from color */ @@ -1436,9 +1426,9 @@ static int imagewraposa_aniso(Tex *tex, * the normal used in the renderer points inward. It is generated * this way in calc_vertexnormals(). Should this ever change * this negate must be removed. */ - texres->nor[0] = -2.0f * (texres->tr - 0.5f); - texres->nor[1] = 2.0f * (texres->tg - 0.5f); - texres->nor[2] = 2.0f * (texres->tb - 0.5f); + texres->nor[0] = -2.0f * (texres->trgba[0] - 0.5f); + texres->nor[1] = 2.0f * (texres->trgba[1] - 0.5f); + texres->nor[2] = 2.0f * (texres->trgba[2] - 0.5f); } /* de-premul, this is being pre-multiplied in shade_input_do_shade() @@ -1449,11 +1439,11 @@ static int imagewraposa_aniso(Tex *tex, /* brecht: tried to fix this, see "TXF alpha" comments */ /* do not de-premul for generated alpha, it is already in straight */ - if (texres->ta != 1.0f && texres->ta > 1e-4f && !(tex->imaflag & TEX_CALCALPHA)) { - fx = 1.0f / texres->ta; - texres->tr *= fx; - texres->tg *= fx; - texres->tb *= fx; + if (texres->trgba[3] != 1.0f && texres->trgba[3] > 1e-4f && !(tex->imaflag & TEX_CALCALPHA)) { + fx = 1.0f / texres->trgba[3]; + texres->trgba[0] *= fx; + texres->trgba[1] *= fx; + texres->trgba[2] *= fx; } if (ima) { @@ -1490,7 +1480,7 @@ int imagewraposa(Tex *tex, return imagewraposa_aniso(tex, ima, ibuf, texvec, dxt, dyt, texres, pool, skip_load_image); } - texres->tin = texres->ta = texres->tr = texres->tg = texres->tb = 0.0f; + texres->tin = texres->trgba[3] = texres->trgba[0] = texres->trgba[1] = texres->trgba[2] = 0.0f; /* we need to set retval OK, otherwise texture code generates normals itself... */ retval = texres->nor ? (TEX_RGB | TEX_NOR) : TEX_RGB; @@ -1795,7 +1785,7 @@ int imagewraposa(Tex *tex, boxsample( curibuf, fx - minx, fy - miny, fx + minx, fy + miny, texres, imaprepeat, imapextend); - val1 = texres->tr + texres->tg + texres->tb; + val1 = texres->trgba[0] + texres->trgba[1] + texres->trgba[2]; boxsample(curibuf, fx - minx + dxt[0], fy - miny + dxt[1], @@ -1804,7 +1794,7 @@ int imagewraposa(Tex *tex, &texr, imaprepeat, imapextend); - val2 = texr.tr + texr.tg + texr.tb; + val2 = texr.trgba[0] + texr.trgba[1] + texr.trgba[2]; boxsample(curibuf, fx - minx + dyt[0], fy - miny + dyt[1], @@ -1813,7 +1803,7 @@ int imagewraposa(Tex *tex, &texr, imaprepeat, imapextend); - val3 = texr.tr + texr.tg + texr.tb; + val3 = texr.trgba[0] + texr.trgba[1] + texr.trgba[2]; /* don't switch x or y! */ texres->nor[0] = (val1 - val2); @@ -1827,20 +1817,20 @@ int imagewraposa(Tex *tex, /* calc rgb */ dx = 2.0f * (pixsize - maxd) / pixsize; if (dx >= 1.0f) { - texres->ta = texr.ta; - texres->tb = texr.tb; - texres->tg = texr.tg; - texres->tr = texr.tr; + texres->trgba[3] = texr.trgba[3]; + texres->trgba[2] = texr.trgba[2]; + texres->trgba[1] = texr.trgba[1]; + texres->trgba[0] = texr.trgba[0]; } else { dy = 1.0f - dx; - texres->tb = dy * texres->tb + dx * texr.tb; - texres->tg = dy * texres->tg + dx * texr.tg; - texres->tr = dy * texres->tr + dx * texr.tr; - texres->ta = dy * texres->ta + dx * texr.ta; + texres->trgba[2] = dy * texres->trgba[2] + dx * texr.trgba[2]; + texres->trgba[1] = dy * texres->trgba[1] + dx * texr.trgba[1]; + texres->trgba[0] = dy * texres->trgba[0] + dx * texr.trgba[0]; + texres->trgba[3] = dy * texres->trgba[3] + dx * texr.trgba[3]; } - val1 = dy * val1 + dx * (texr.tr + texr.tg + texr.tb); + val1 = dy * val1 + dx * (texr.trgba[0] + texr.trgba[1] + texr.trgba[2]); boxsample(previbuf, fx - minx + dxt[0], fy - miny + dxt[1], @@ -1849,7 +1839,7 @@ int imagewraposa(Tex *tex, &texr, imaprepeat, imapextend); - val2 = dy * val2 + dx * (texr.tr + texr.tg + texr.tb); + val2 = dy * val2 + dx * (texr.trgba[0] + texr.trgba[1] + texr.trgba[2]); boxsample(previbuf, fx - minx + dyt[0], fy - miny + dyt[1], @@ -1858,17 +1848,17 @@ int imagewraposa(Tex *tex, &texr, imaprepeat, imapextend); - val3 = dy * val3 + dx * (texr.tr + texr.tg + texr.tb); + val3 = dy * val3 + dx * (texr.trgba[0] + texr.trgba[1] + texr.trgba[2]); texres->nor[0] = (val1 - val2); /* vals have been interpolated above! */ texres->nor[1] = (val1 - val3); if (dx < 1.0f) { dy = 1.0f - dx; - texres->tb = dy * texres->tb + dx * texr.tb; - texres->tg = dy * texres->tg + dx * texr.tg; - texres->tr = dy * texres->tr + dx * texr.tr; - texres->ta = dy * texres->ta + dx * texr.ta; + texres->trgba[2] = dy * texres->trgba[2] + dx * texr.trgba[2]; + texres->trgba[1] = dy * texres->trgba[1] + dx * texr.trgba[1]; + texres->trgba[0] = dy * texres->trgba[0] + dx * texr.trgba[0]; + texres->trgba[3] = dy * texres->trgba[3] + dx * texr.trgba[3]; } } texres->nor[0] *= bumpscale; @@ -1888,17 +1878,17 @@ int imagewraposa(Tex *tex, fx = 2.0f * (pixsize - maxd) / pixsize; if (fx >= 1.0f) { - texres->ta = texr.ta; - texres->tb = texr.tb; - texres->tg = texr.tg; - texres->tr = texr.tr; + texres->trgba[3] = texr.trgba[3]; + texres->trgba[2] = texr.trgba[2]; + texres->trgba[1] = texr.trgba[1]; + texres->trgba[0] = texr.trgba[0]; } else { fy = 1.0f - fx; - texres->tb = fy * texres->tb + fx * texr.tb; - texres->tg = fy * texres->tg + fx * texr.tg; - texres->tr = fy * texres->tr + fx * texr.tr; - texres->ta = fy * texres->ta + fx * texr.ta; + texres->trgba[2] = fy * texres->trgba[2] + fx * texr.trgba[2]; + texres->trgba[1] = fy * texres->trgba[1] + fx * texr.trgba[1]; + texres->trgba[0] = fy * texres->trgba[0] + fx * texr.trgba[0]; + texres->trgba[3] = fy * texres->trgba[3] + fx * texr.trgba[3]; } } } @@ -1917,7 +1907,7 @@ int imagewraposa(Tex *tex, if (texres->nor && (tex->imaflag & TEX_NORMALMAP) == 0) { boxsample(ibuf, fx - minx, fy - miny, fx + minx, fy + miny, texres, imaprepeat, imapextend); - val1 = texres->tr + texres->tg + texres->tb; + val1 = texres->trgba[0] + texres->trgba[1] + texres->trgba[2]; boxsample(ibuf, fx - minx + dxt[0], fy - miny + dxt[1], @@ -1926,7 +1916,7 @@ int imagewraposa(Tex *tex, &texr, imaprepeat, imapextend); - val2 = texr.tr + texr.tg + texr.tb; + val2 = texr.trgba[0] + texr.trgba[1] + texr.trgba[2]; boxsample(ibuf, fx - minx + dyt[0], fy - miny + dyt[1], @@ -1935,7 +1925,7 @@ int imagewraposa(Tex *tex, &texr, imaprepeat, imapextend); - val3 = texr.tr + texr.tg + texr.tb; + val3 = texr.trgba[0] + texr.trgba[1] + texr.trgba[2]; /* don't switch x or y! */ texres->nor[0] = (val1 - val2); @@ -1947,14 +1937,15 @@ int imagewraposa(Tex *tex, } if (tex->imaflag & TEX_CALCALPHA) { - texres->ta = texres->tin = texres->ta * max_fff(texres->tr, texres->tg, texres->tb); + texres->trgba[3] = texres->tin = texres->trgba[3] * + max_fff(texres->trgba[0], texres->trgba[1], texres->trgba[2]); } else { - texres->tin = texres->ta; + texres->tin = texres->trgba[3]; } if (tex->flag & TEX_NEGALPHA) { - texres->ta = 1.0f - texres->ta; + texres->trgba[3] = 1.0f - texres->trgba[3]; } if (texres->nor && (tex->imaflag & TEX_NORMALMAP)) { @@ -1963,15 +1954,15 @@ int imagewraposa(Tex *tex, * It needs to be done because in Blender the normal used in the renderer points inward. * It is generated this way in #calc_vertexnormals(). * Should this ever change this negate must be removed. */ - texres->nor[0] = -2.0f * (texres->tr - 0.5f); - texres->nor[1] = 2.0f * (texres->tg - 0.5f); - texres->nor[2] = 2.0f * (texres->tb - 0.5f); + texres->nor[0] = -2.0f * (texres->trgba[0] - 0.5f); + texres->nor[1] = 2.0f * (texres->trgba[1] - 0.5f); + texres->nor[2] = 2.0f * (texres->trgba[2] - 0.5f); } /* de-premul, this is being pre-multiplied in shade_input_do_shade() */ /* do not de-premul for generated alpha, it is already in straight */ - if (texres->ta != 1.0f && texres->ta > 1e-4f && !(tex->imaflag & TEX_CALCALPHA)) { - mul_v3_fl(&texres->tr, 1.0f / texres->ta); + if (texres->trgba[3] != 1.0f && texres->trgba[3] > 1e-4f && !(tex->imaflag & TEX_CALCALPHA)) { + mul_v3_fl(texres->trgba, 1.0f / texres->trgba[3]); } if (ima) { @@ -1996,7 +1987,7 @@ void image_sample( texres.talpha = true; /* boxsample expects to be initialized */ boxsample(ibuf, fx, fy, fx + dx, fy + dy, &texres, 0, 1); - copy_v4_v4(result, &texres.tr); + copy_v4_v4(result, texres.trgba); ima->flag |= IMA_USED_FOR_RENDER; @@ -2020,5 +2011,5 @@ void ibuf_sample(ImBuf *ibuf, float fx, float fy, float dx, float dy, float resu ewa_eval(&texres, ibuf, fx, fy, &AFD); - copy_v4_v4(result, &texres.tr); + copy_v4_v4(result, texres.trgba); } diff --git a/source/blender/render/intern/texture_pointdensity.c b/source/blender/render/intern/texture_pointdensity.c index 683260f86cb..9abaeb3739f 100644 --- a/source/blender/render/intern/texture_pointdensity.c +++ b/source/blender/render/intern/texture_pointdensity.c @@ -687,7 +687,7 @@ static int pointdensity(PointDensity *pd, static void pointdensity_color( PointDensity *pd, TexResult *texres, float age, const float vec[3], const float col[3]) { - texres->tr = texres->tg = texres->tb = texres->ta = 1.0f; + copy_v4_fl(texres->trgba, 1.0f); if (pd->source == TEX_PD_PSYS) { float rgba[4]; @@ -697,9 +697,9 @@ static void pointdensity_color( if (pd->coba) { if (BKE_colorband_evaluate(pd->coba, age, rgba)) { texres->talpha = true; - copy_v3_v3(&texres->tr, rgba); + copy_v3_v3(texres->trgba, rgba); texres->tin *= rgba[3]; - texres->ta = texres->tin; + texres->trgba[3] = texres->tin; } } break; @@ -709,17 +709,17 @@ static void pointdensity_color( if (pd->coba) { if (BKE_colorband_evaluate(pd->coba, speed, rgba)) { texres->talpha = true; - copy_v3_v3(&texres->tr, rgba); + copy_v3_v3(texres->trgba, rgba); texres->tin *= rgba[3]; - texres->ta = texres->tin; + texres->trgba[3] = texres->tin; } } break; } case TEX_PD_COLOR_PARTVEL: texres->talpha = true; - mul_v3_v3fl(&texres->tr, vec, pd->speed_scale); - texres->ta = texres->tin; + mul_v3_v3fl(texres->trgba, vec, pd->speed_scale); + texres->trgba[3] = texres->tin; break; case TEX_PD_COLOR_CONSTANT: default: @@ -732,24 +732,24 @@ static void pointdensity_color( switch (pd->ob_color_source) { case TEX_PD_COLOR_VERTCOL: texres->talpha = true; - copy_v3_v3(&texres->tr, col); - texres->ta = texres->tin; + copy_v3_v3(texres->trgba, col); + texres->trgba[3] = texres->tin; break; case TEX_PD_COLOR_VERTWEIGHT: texres->talpha = true; if (pd->coba && BKE_colorband_evaluate(pd->coba, col[0], rgba)) { - copy_v3_v3(&texres->tr, rgba); + copy_v3_v3(texres->trgba, rgba); texres->tin *= rgba[3]; } else { - copy_v3_v3(&texres->tr, col); + copy_v3_v3(texres->trgba, col); } - texres->ta = texres->tin; + texres->trgba[3] = texres->tin; break; case TEX_PD_COLOR_VERTNOR: texres->talpha = true; - copy_v3_v3(&texres->tr, col); - texres->ta = texres->tin; + copy_v3_v3(texres->trgba, col); + texres->trgba[3] = texres->tin; break; case TEX_PD_COLOR_CONSTANT: default: @@ -915,7 +915,7 @@ static void point_density_sample_func(void *__restrict data_v, pointdensity(pd, texvec, &texres, vec, &age, col); pointdensity_color(pd, &texres, age, vec, col); - copy_v3_v3(&values[index * 4 + 0], &texres.tr); + copy_v3_v3(&values[index * 4 + 0], texres.trgba); values[index * 4 + 3] = texres.tin; } } diff --git a/source/blender/render/intern/texture_procedural.c b/source/blender/render/intern/texture_procedural.c index c894d8d9f48..ee45810f445 100644 --- a/source/blender/render/intern/texture_procedural.c +++ b/source/blender/render/intern/texture_procedural.c @@ -212,23 +212,23 @@ static int clouds(const Tex *tex, const float texvec[3], TexResult *texres) if (tex->stype == TEX_COLOR) { /* in this case, int. value should really be computed from color, * and bumpnormal from that, would be too slow, looks ok as is */ - texres->tr = texres->tin; - texres->tg = BLI_noise_generic_turbulence(tex->noisesize, - texvec[1], - texvec[0], - texvec[2], - tex->noisedepth, - (tex->noisetype != TEX_NOISESOFT), - tex->noisebasis); - texres->tb = BLI_noise_generic_turbulence(tex->noisesize, - texvec[1], - texvec[2], - texvec[0], - tex->noisedepth, - (tex->noisetype != TEX_NOISESOFT), - tex->noisebasis); + texres->trgba[0] = texres->tin; + texres->trgba[1] = BLI_noise_generic_turbulence(tex->noisesize, + texvec[1], + texvec[0], + texvec[2], + tex->noisedepth, + (tex->noisetype != TEX_NOISESOFT), + tex->noisebasis); + texres->trgba[2] = BLI_noise_generic_turbulence(tex->noisesize, + texvec[1], + texvec[2], + texvec[0], + tex->noisedepth, + (tex->noisetype != TEX_NOISESOFT), + tex->noisebasis); BRICONTRGB; - texres->ta = 1.0; + texres->trgba[3] = 1.0; return (rv | TEX_RGB); } @@ -453,14 +453,14 @@ static int magic(const Tex *tex, const float texvec[3], TexResult *texres) y /= turb; z /= turb; } - texres->tr = 0.5f - x; - texres->tg = 0.5f - y; - texres->tb = 0.5f - z; + texres->trgba[0] = 0.5f - x; + texres->trgba[1] = 0.5f - y; + texres->trgba[2] = 0.5f - z; - texres->tin = (1.0f / 3.0f) * (texres->tr + texres->tg + texres->tb); + texres->tin = (1.0f / 3.0f) * (texres->trgba[0] + texres->trgba[1] + texres->trgba[2]); BRICONTRGB; - texres->ta = 1.0f; + texres->trgba[3] = 1.0f; return TEX_RGB; } @@ -767,21 +767,21 @@ static int voronoiTex(const Tex *tex, const float texvec[3], TexResult *texres) if (tex->vn_coltype) { float ca[3]; /* cell color */ BLI_noise_cell_v3(pa[0], pa[1], pa[2], ca); - texres->tr = aw1 * ca[0]; - texres->tg = aw1 * ca[1]; - texres->tb = aw1 * ca[2]; + texres->trgba[0] = aw1 * ca[0]; + texres->trgba[1] = aw1 * ca[1]; + texres->trgba[2] = aw1 * ca[2]; BLI_noise_cell_v3(pa[3], pa[4], pa[5], ca); - texres->tr += aw2 * ca[0]; - texres->tg += aw2 * ca[1]; - texres->tb += aw2 * ca[2]; + texres->trgba[0] += aw2 * ca[0]; + texres->trgba[1] += aw2 * ca[1]; + texres->trgba[2] += aw2 * ca[2]; BLI_noise_cell_v3(pa[6], pa[7], pa[8], ca); - texres->tr += aw3 * ca[0]; - texres->tg += aw3 * ca[1]; - texres->tb += aw3 * ca[2]; + texres->trgba[0] += aw3 * ca[0]; + texres->trgba[1] += aw3 * ca[1]; + texres->trgba[2] += aw3 * ca[2]; BLI_noise_cell_v3(pa[9], pa[10], pa[11], ca); - texres->tr += aw4 * ca[0]; - texres->tg += aw4 * ca[1]; - texres->tb += aw4 * ca[2]; + texres->trgba[0] += aw4 * ca[0]; + texres->trgba[1] += aw4 * ca[1]; + texres->trgba[2] += aw4 * ca[2]; if (tex->vn_coltype >= 2) { float t1 = (da[1] - da[0]) * 10; if (t1 > 1) { @@ -793,14 +793,14 @@ static int voronoiTex(const Tex *tex, const float texvec[3], TexResult *texres) else { t1 *= sc; } - texres->tr *= t1; - texres->tg *= t1; - texres->tb *= t1; + texres->trgba[0] *= t1; + texres->trgba[1] *= t1; + texres->trgba[2] *= t1; } else { - texres->tr *= sc; - texres->tg *= sc; - texres->tb *= sc; + texres->trgba[0] *= sc; + texres->trgba[1] *= sc; + texres->trgba[2] *= sc; } } @@ -821,7 +821,7 @@ static int voronoiTex(const Tex *tex, const float texvec[3], TexResult *texres) if (tex->vn_coltype) { BRICONTRGB; - texres->ta = 1.0; + texres->trgba[3] = 1.0; return (rv | TEX_RGB); } @@ -1270,10 +1270,7 @@ static int multitex(Tex *tex, float col[4]; if (BKE_colorband_evaluate(tex->coba, texres->tin, col)) { texres->talpha = true; - texres->tr = col[0]; - texres->tg = col[1]; - texres->tb = col[2]; - texres->ta = col[3]; + copy_v4_v4(texres->trgba, col); retval |= TEX_RGB; } } @@ -1330,7 +1327,7 @@ static int multitex_nodes_intern(Tex *tex, /* don't linearize float buffers, assumed to be linear */ if (ibuf != NULL && ibuf->rect_float == NULL && (rgbnor & TEX_RGB) && scene_color_manage) { - IMB_colormanagement_colorspace_to_scene_linear_v3(&texres->tr, ibuf->rect_colorspace); + IMB_colormanagement_colorspace_to_scene_linear_v3(texres->trgba, ibuf->rect_colorspace); } BKE_image_pool_release_ibuf(tex->ima, ibuf, pool); @@ -1375,7 +1372,7 @@ static int multitex_nodes_intern(Tex *tex, /* don't linearize float buffers, assumed to be linear */ if (ibuf != NULL && ibuf->rect_float == NULL && (rgbnor & TEX_RGB) && scene_color_manage) { - IMB_colormanagement_colorspace_to_scene_linear_v3(&texres->tr, ibuf->rect_colorspace); + IMB_colormanagement_colorspace_to_scene_linear_v3(texres->trgba, ibuf->rect_colorspace); } BKE_image_pool_release_ibuf(tex->ima, ibuf, pool); @@ -1768,19 +1765,14 @@ bool RE_texture_evaluate(const MTex *mtex, true); if (rgb) { - texr.tin = IMB_colormanagement_get_luminance(&texr.tr); + texr.tin = IMB_colormanagement_get_luminance(texr.trgba); } else { - texr.tr = mtex->r; - texr.tg = mtex->g; - texr.tb = mtex->b; + copy_v3_fl3(texr.trgba, mtex->r, mtex->g, mtex->b); } *r_intensity = texr.tin; - r_rgba[0] = texr.tr; - r_rgba[1] = texr.tg; - r_rgba[2] = texr.tb; - r_rgba[3] = texr.ta; + copy_v4_v4(r_rgba, texr.trgba); return (rgb != 0); } |