1
1

Cleanup: removed unused Blender Internal bump/normal mapping texture code

The TexResult.nor output does not appear to be used anywhere.
This commit is contained in:
2022-06-20 17:10:27 +02:00
parent d90b320444
commit 9622dace3e
14 changed files with 61 additions and 738 deletions

View File

@@ -868,8 +868,6 @@ static void do_texture_effector(EffectorCache *eff,
return;
}
result[0].nor = result[1].nor = result[2].nor = result[3].nor = NULL;
strength = eff->pd->f_strength * efd->falloff;
copy_v3_v3(tex_co, point->loc);

View File

@@ -1942,7 +1942,6 @@ static void sample_mesh(FluidFlowSettings *ffs,
tex_co[1] = tex_co[1] * 2.0f - 1.0f;
tex_co[2] = ffs->texture_offset;
}
texres.nor = NULL;
BKE_texture_get_value(NULL, ffs->noise_texture, tex_co, &texres, false);
emission_strength *= texres.tin;
}

View File

@@ -397,8 +397,7 @@ typedef struct ColorMapping {
/* return value */
#define TEX_INT 0
#define TEX_RGB (1 << 0)
#define TEX_NOR (1 << 1)
#define TEX_RGB 1
/* pr_texture in material, world, light. */
#define TEX_PR_TEXTURE 0

View File

@@ -197,7 +197,6 @@ static void displaceModifier_do_task(void *__restrict userdata,
}
if (data->tex_target) {
texres.nor = NULL;
BKE_texture_get_value_ex(
data->scene, data->tex_target, tex_co[iter], &texres, data->pool, false);
delta = texres.tin - dmd->midlevel;

View File

@@ -302,7 +302,6 @@ static void warpModifier_do(WarpModifierData *wmd,
if (tex_co) {
struct Scene *scene = DEG_get_evaluated_scene(ctx->depsgraph);
TexResult texres;
texres.nor = NULL;
BKE_texture_get_value(scene, tex_target, tex_co[i], &texres, false);
fac *= texres.tin;
}

View File

@@ -262,7 +262,6 @@ static void waveModifier_do(WaveModifierData *md,
if (tex_co) {
Scene *scene = DEG_get_evaluated_scene(ctx->depsgraph);
TexResult texres;
texres.nor = NULL;
BKE_texture_get_value(scene, tex_target, tex_co[i], &texres, false);
amplit *= texres.tin;
}

View File

@@ -162,7 +162,6 @@ void weightvg_do_mask(const ModifierEvalContext *ctx,
do_color_manage = tex_use_channel != MOD_WVG_MASK_TEX_USE_INT;
texres.nor = NULL;
BKE_texture_get_value(scene, texture, tex_co[idx], &texres, do_color_manage);
/* Get the good channel value... */
switch (tex_use_channel) {

View File

@@ -324,7 +324,6 @@ int ntreeTexExecTree(bNodeTree *ntree,
MTex *mtex)
{
TexCallData data;
float *nor = target->nor;
int retval = TEX_INT;
bNodeThreadStack *nts = NULL;
bNodeTreeExec *exec = ntree->execdata;
@@ -356,14 +355,7 @@ int ntreeTexExecTree(bNodeTree *ntree,
ntreeExecThreadNodes(exec, nts, &data, thread);
ntreeReleaseThreadStack(nts);
if (target->nor) {
retval |= TEX_NOR;
}
retval |= TEX_RGB;
/* confusing stuff; the texture output node sets this to NULL to indicate no normal socket was
* set however, the texture code checks this for other reasons
* (namely, a normal is required for material). */
target->nor = nor;
return retval;
}

View File

@@ -13,7 +13,6 @@
/* **************** COMPOSITE ******************** */
static bNodeSocketTemplate inputs[] = {
{SOCK_RGBA, N_("Color"), 0.0f, 0.0f, 0.0f, 1.0f},
{SOCK_VECTOR, N_("Normal"), 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, PROP_DIRECTION},
{-1, ""},
};
@@ -32,12 +31,7 @@ static void exec(void *data,
TexParams params;
params_from_cdata(&params, cdata);
if (in[1] && in[1]->hasinput && !in[0]->hasinput) {
tex_input_rgba(target->trgba, in[1], &params, cdata->thread);
}
else {
tex_input_rgba(target->trgba, in[0], &params, cdata->thread);
}
tex_input_rgba(target->trgba, in[0], &params, cdata->thread);
}
else {
/* 0 means don't care, so just use first */
@@ -49,15 +43,6 @@ static void exec(void *data,
target->tin = (target->trgba[0] + target->trgba[1] + target->trgba[2]) / 3.0f;
target->talpha = true;
if (target->nor) {
if (in[1] && in[1]->hasinput) {
tex_input_vec(target->nor, in[1], &params, cdata->thread);
}
else {
target->nor = NULL;
}
}
}
}
}

View File

@@ -14,10 +14,8 @@
* In this file: wrappers to use procedural textures as nodes
*/
static bNodeSocketTemplate outputs_both[] = {
{SOCK_RGBA, N_("Color"), 1.0f, 0.0f, 0.0f, 1.0f},
{SOCK_VECTOR, N_("Normal"), 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, PROP_DIRECTION},
{-1, ""}};
static bNodeSocketTemplate outputs_both[] = {{SOCK_RGBA, N_("Color"), 1.0f, 0.0f, 0.0f, 1.0f},
{-1, ""}};
static bNodeSocketTemplate outputs_color_only[] = {{SOCK_RGBA, N_("Color")}, {-1, ""}};
/* Inputs common to all, #defined because nodes will need their own inputs too */
@@ -34,27 +32,15 @@ static void do_proc(float *result,
TexParams *p,
const float col1[4],
const float col2[4],
char is_normal,
Tex *tex,
const short thread)
{
TexResult texres;
int textype;
if (is_normal) {
texres.nor = result;
}
else {
texres.nor = NULL;
}
textype = multitex_nodes(
tex, p->co, p->dxt, p->dyt, p->osatex, &texres, thread, 0, p->mtex, NULL);
if (is_normal) {
return;
}
if (textype & TEX_RGB) {
copy_v4_v4(result, texres.trgba);
}
@@ -66,13 +52,8 @@ static void do_proc(float *result,
typedef void (*MapFn)(Tex *tex, bNodeStack **in, TexParams *p, const short thread);
static void texfn(float *result,
TexParams *p,
bNode *node,
bNodeStack **in,
char is_normal,
MapFn map_inputs,
short thread)
static void texfn(
float *result, TexParams *p, bNode *node, bNodeStack **in, MapFn map_inputs, short thread)
{
Tex tex = *((Tex *)(node->storage));
float col1[4], col2[4];
@@ -81,7 +62,7 @@ static void texfn(float *result,
map_inputs(&tex, in, p, thread);
do_proc(result, p, col1, col2, is_normal, &tex, thread);
do_proc(result, p, col1, col2, &tex, thread);
}
static int count_outputs(bNode *node)
@@ -106,12 +87,7 @@ static int count_outputs(bNode *node)
static void name##_colorfn( \
float *result, TexParams *p, bNode *node, bNodeStack **in, short thread) \
{ \
texfn(result, p, node, in, 0, &name##_map_inputs, thread); \
} \
static void name##_normalfn( \
float *result, TexParams *p, bNode *node, bNodeStack **in, short thread) \
{ \
texfn(result, p, node, in, 1, &name##_map_inputs, thread); \
texfn(result, p, node, in, &name##_map_inputs, thread); \
} \
static void name##_exec(void *data, \
int UNUSED(thread), \
@@ -124,9 +100,6 @@ static int count_outputs(bNode *node)
if (outs >= 1) { \
tex_output(node, execdata, in, out[0], &name##_colorfn, data); \
} \
if (outs >= 2) { \
tex_output(node, execdata, in, out[1], &name##_normalfn, data); \
} \
}
/* --- VORONOI -- */

View File

@@ -45,13 +45,11 @@ static void colorfn(float *out, TexParams *p, bNode *node, bNodeStack **in, shor
else if (nodetex) {
TexResult texres;
int textype;
float nor[] = {0, 0, 0};
float col1[4], col2[4];
tex_input_rgba(col1, in[0], p, thread);
tex_input_rgba(col2, in[1], p, thread);
texres.nor = nor;
textype = multitex_nodes(nodetex, co, dxt, dyt, p->osatex, &texres, thread, 0, p->mtex, NULL);
if (textype & TEX_RGB) {

View File

@@ -44,8 +44,6 @@ bool RE_texture_evaluate(const struct MTex *mtex,
* \param fact: Texture strength.
* \param facg: Button strength value.
*/
void texture_rgb_blend(
float in[3], const float tex[3], const float out[3], float fact, float facg, int blendtype);
float texture_value_blend(float tex, float out, float fact, float facg, int blendtype);
void RE_texture_rng_init(void);
@@ -89,7 +87,6 @@ typedef struct TexResult {
float trgba[4];
/* Is actually a boolean: When true -> use alpha, false -> set alpha to 1.0. */
int talpha;
float *nor;
} TexResult;
/* This one uses nodes. */

View File

@@ -88,14 +88,13 @@ int imagewrap(Tex *tex,
struct ImagePool *pool,
const bool skip_load_image)
{
float fx, fy, val1, val2, val3;
float fx, fy;
int x, y, retval;
int xi, yi; /* original values */
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;
retval = TEX_RGB;
/* quick tests */
if (ima == NULL) {
@@ -256,47 +255,6 @@ int imagewrap(Tex *tex,
ibuf_get_color(texres->trgba, ibuf, x, y);
}
if (texres->nor) {
if (tex->imaflag & TEX_NORMALMAP) {
/* Normal from color:
* The invert of the red channel is to make
* the normal map compliant with the outside world.
* 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->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->trgba[0] + texres->trgba[1] + texres->trgba[2];
if (x < ibuf->x - 1) {
float col[4];
ibuf_get_color(col, ibuf, x + 1, y);
val2 = (col[0] + col[1] + col[2]);
}
else {
val2 = val1;
}
if (y < ibuf->y - 1) {
float col[4];
ibuf_get_color(col, ibuf, x, y + 1);
val3 = (col[0] + col[1] + col[2]);
}
else {
val3 = val1;
}
/* do not mix up x and y here! */
texres->nor[0] = (val1 - val2);
texres->nor[1] = (val1 - val3);
}
}
if (texres->talpha) {
texres->tin = texres->trgba[3];
}
@@ -989,7 +947,7 @@ static int imagewraposa_aniso(Tex *tex,
{
TexResult texr;
float fx, fy, minx, maxx, miny, maxy;
float maxd, val1, val2, val3;
float maxd;
int curmap, retval, intpol, extflag = 0;
afdata_t AFD;
@@ -1008,8 +966,7 @@ static int imagewraposa_aniso(Tex *tex,
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;
retval = TEX_RGB;
/* quick tests */
if (ibuf == NULL && ima == NULL) {
@@ -1040,7 +997,7 @@ static int imagewraposa_aniso(Tex *tex,
if (ima) {
if ((tex->imaflag & TEX_USEALPHA) && (ima->alpha_mode != IMA_ALPHA_IGNORE)) {
if ((tex->imaflag & TEX_CALCALPHA) == 0) {
texres->talpha = 1;
texres->talpha = true;
}
}
}
@@ -1301,48 +1258,17 @@ static int imagewraposa_aniso(Tex *tex,
}
/* filter functions take care of interpolation themselves, no need to modify dxt/dyt here */
if (texres->nor && ((tex->imaflag & TEX_NORMALMAP) == 0)) {
/* color & normal */
filterfunc(texres, curibuf, fx, fy, &AFD);
val1 = texres->trgba[0] + texres->trgba[1] + texres->trgba[2];
filterfunc(&texr, curibuf, fx + dxt[0], fy + dxt[1], &AFD);
val2 = texr.trgba[0] + texr.trgba[1] + texr.trgba[2];
filterfunc(&texr, curibuf, fx + dyt[0], fy + dyt[1], &AFD);
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->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.trgba[0] + texr.trgba[1] + texr.trgba[2]) - val1);
filterfunc(&texr, previbuf, fx + dxt[0], fy + dxt[1], &AFD);
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.trgba[0] + texr.trgba[1] + texr.trgba[2]) - val3);
texres->nor[0] = val1 - val2; /* vals have been interpolated above! */
texres->nor[1] = val1 - val3;
}
filterfunc(texres, curibuf, fx, fy, &AFD);
if (previbuf != curibuf) { /* interpolate */
filterfunc(&texr, previbuf, fx, fy, &AFD);
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]);
}
else { /* color */
filterfunc(texres, curibuf, fx, fy, &AFD);
if (previbuf != curibuf) { /* interpolate */
filterfunc(&texr, previbuf, fx, fy, &AFD);
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) {
alpha_clip_aniso(ibuf, fx - minx, fy - miny, fx + minx, fy + miny, extflag, texres);
}
if (tex->texfilter != TXF_EWA) {
alpha_clip_aniso(ibuf, fx - minx, fy - miny, fx + minx, fy + miny, extflag, texres);
}
}
else { /* no mipmap */
@@ -1372,23 +1298,9 @@ static int imagewraposa_aniso(Tex *tex,
AFD.dusc = 1.0f / ff;
AFD.dvsc = ff / (float)ibuf->y;
}
if (texres->nor && ((tex->imaflag & TEX_NORMALMAP) == 0)) {
/* color & normal */
filterfunc(texres, ibuf, fx, fy, &AFD);
val1 = texres->trgba[0] + texres->trgba[1] + texres->trgba[2];
filterfunc(&texr, ibuf, fx + dxt[0], fy + dxt[1], &AFD);
val2 = texr.trgba[0] + texr.trgba[1] + texr.trgba[2];
filterfunc(&texr, ibuf, fx + dyt[0], fy + dyt[1], &AFD);
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;
}
else {
filterfunc(texres, ibuf, fx, fy, &AFD);
if (tex->texfilter != TXF_EWA) {
alpha_clip_aniso(ibuf, fx - minx, fy - miny, fx + minx, fy + miny, extflag, texres);
}
filterfunc(texres, ibuf, fx, fy, &AFD);
if (tex->texfilter != TXF_EWA) {
alpha_clip_aniso(ibuf, fx - minx, fy - miny, fx + minx, fy + miny, extflag, texres);
}
}
@@ -1403,18 +1315,6 @@ static int imagewraposa_aniso(Tex *tex,
texres->trgba[3] = 1.0f - texres->trgba[3];
}
if (texres->nor && (tex->imaflag & TEX_NORMALMAP)) { /* normal from color */
/* The invert of the red channel is to make
* the normal map compliant with the outside world.
* 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->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()
* TXF: this currently does not (yet?) work properly, destroys edge AA in clip/checker mode,
* so for now commented out also disabled in imagewraposa()
@@ -1451,7 +1351,7 @@ int imagewraposa(Tex *tex,
{
TexResult texr;
float fx, fy, minx, maxx, miny, maxy, dx, dy, dxt[2], dyt[2];
float maxd, pixsize, val1, val2, val3;
float maxd, pixsize;
int curmap, retval, imaprepeat, imapextend;
/* TXF: since dxt/dyt might be modified here and since they might be needed after imagewraposa()
@@ -1466,8 +1366,7 @@ int imagewraposa(Tex *tex,
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;
retval = TEX_RGB;
/* quick tests */
if (ibuf == NULL && ima == NULL) {
@@ -1762,118 +1661,30 @@ int imagewraposa(Tex *tex,
}
}
if (texres->nor && (tex->imaflag & TEX_NORMALMAP) == 0) {
/* a bit extra filter */
// minx*= 1.35f;
// miny*= 1.35f;
maxx = fx + minx;
minx = fx - minx;
maxy = fy + miny;
miny = fy - miny;
boxsample(
curibuf, fx - minx, fy - miny, fx + minx, fy + miny, texres, imaprepeat, imapextend);
val1 = texres->trgba[0] + texres->trgba[1] + texres->trgba[2];
boxsample(curibuf,
fx - minx + dxt[0],
fy - miny + dxt[1],
fx + minx + dxt[0],
fy + miny + dxt[1],
&texr,
imaprepeat,
imapextend);
val2 = texr.trgba[0] + texr.trgba[1] + texr.trgba[2];
boxsample(curibuf,
fx - minx + dyt[0],
fy - miny + dyt[1],
fx + minx + dyt[0],
fy + miny + dyt[1],
&texr,
imaprepeat,
imapextend);
val3 = texr.trgba[0] + texr.trgba[1] + texr.trgba[2];
boxsample(curibuf, minx, miny, maxx, maxy, texres, imaprepeat, imapextend);
/* don't switch x or y! */
texres->nor[0] = (val1 - val2);
texres->nor[1] = (val1 - val3);
if (previbuf != curibuf) { /* interpolate */
boxsample(previbuf, minx, miny, maxx, maxy, &texr, imaprepeat, imapextend);
if (previbuf != curibuf) { /* interpolate */
fx = 2.0f * (pixsize - maxd) / pixsize;
boxsample(
previbuf, fx - minx, fy - miny, fx + minx, fy + miny, &texr, imaprepeat, imapextend);
/* calc rgb */
dx = 2.0f * (pixsize - maxd) / pixsize;
if (dx >= 1.0f) {
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->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.trgba[0] + texr.trgba[1] + texr.trgba[2]);
boxsample(previbuf,
fx - minx + dxt[0],
fy - miny + dxt[1],
fx + minx + dxt[0],
fy + miny + dxt[1],
&texr,
imaprepeat,
imapextend);
val2 = dy * val2 + dx * (texr.trgba[0] + texr.trgba[1] + texr.trgba[2]);
boxsample(previbuf,
fx - minx + dyt[0],
fy - miny + dyt[1],
fx + minx + dyt[0],
fy + miny + dyt[1],
&texr,
imaprepeat,
imapextend);
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->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];
}
if (fx >= 1.0f) {
texres->trgba[3] = texr.trgba[3];
texres->trgba[2] = texr.trgba[2];
texres->trgba[1] = texr.trgba[1];
texres->trgba[0] = texr.trgba[0];
}
texres->nor[0] *= bumpscale;
texres->nor[1] *= bumpscale;
}
else {
maxx = fx + minx;
minx = fx - minx;
maxy = fy + miny;
miny = fy - miny;
boxsample(curibuf, minx, miny, maxx, maxy, texres, imaprepeat, imapextend);
if (previbuf != curibuf) { /* interpolate */
boxsample(previbuf, minx, miny, maxx, maxy, &texr, imaprepeat, imapextend);
fx = 2.0f * (pixsize - maxd) / pixsize;
if (fx >= 1.0f) {
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->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];
}
else {
fy = 1.0f - fx;
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];
}
}
}
@@ -1889,35 +1700,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->trgba[0] + texres->trgba[1] + texres->trgba[2];
boxsample(ibuf,
fx - minx + dxt[0],
fy - miny + dxt[1],
fx + minx + dxt[0],
fy + miny + dxt[1],
&texr,
imaprepeat,
imapextend);
val2 = texr.trgba[0] + texr.trgba[1] + texr.trgba[2];
boxsample(ibuf,
fx - minx + dyt[0],
fy - miny + dyt[1],
fx + minx + dyt[0],
fy + miny + dyt[1],
&texr,
imaprepeat,
imapextend);
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);
}
else {
boxsample(ibuf, fx - minx, fy - miny, fx + minx, fy + miny, texres, imaprepeat, imapextend);
}
boxsample(ibuf, fx - minx, fy - miny, fx + minx, fy + miny, texres, imaprepeat, imapextend);
}
if (tex->imaflag & TEX_CALCALPHA) {
@@ -1932,17 +1715,6 @@ int imagewraposa(Tex *tex,
texres->trgba[3] = 1.0f - texres->trgba[3];
}
if (texres->nor && (tex->imaflag & TEX_NORMALMAP)) {
/* Normal from color:
* The invert of the red channel is to make the normal map compliant with the outside world.
* 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->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->trgba[3] != 1.0f && texres->trgba[3] > 1e-4f && !(tex->imaflag & TEX_CALCALPHA)) {

View File

@@ -61,34 +61,6 @@ void RE_texture_rng_exit(void)
/* ------------------------------------------------------------------------- */
/* This allows color-banded textures to control normals as well. */
static void tex_normal_derivate(const Tex *tex, TexResult *texres)
{
if (tex->flag & TEX_COLORBAND) {
float col[4];
if (BKE_colorband_evaluate(tex->coba, texres->tin, col)) {
float fac0, fac1, fac2, fac3;
fac0 = (col[0] + col[1] + col[2]);
BKE_colorband_evaluate(tex->coba, texres->nor[0], col);
fac1 = (col[0] + col[1] + col[2]);
BKE_colorband_evaluate(tex->coba, texres->nor[1], col);
fac2 = (col[0] + col[1] + col[2]);
BKE_colorband_evaluate(tex->coba, texres->nor[2], col);
fac3 = (col[0] + col[1] + col[2]);
texres->nor[0] = (fac0 - fac1) / 3.0f;
texres->nor[1] = (fac0 - fac2) / 3.0f;
texres->nor[2] = (fac0 - fac3) / 3.0f;
return;
}
}
texres->nor[0] = texres->tin - texres->nor[0];
texres->nor[1] = texres->tin - texres->nor[1];
texres->nor[2] = texres->tin - texres->nor[2];
}
static int blend(const Tex *tex, const float texvec[3], TexResult *texres)
{
float x, y, t;
@@ -165,37 +137,7 @@ static int clouds(const Tex *tex, const float texvec[3], TexResult *texres)
(tex->noisetype != TEX_NOISESOFT),
tex->noisebasis);
if (texres->nor != NULL) {
/* calculate bumpnormal */
texres->nor[0] = BLI_noise_generic_turbulence(tex->noisesize,
texvec[0] + tex->nabla,
texvec[1],
texvec[2],
tex->noisedepth,
(tex->noisetype != TEX_NOISESOFT),
tex->noisebasis);
texres->nor[1] = BLI_noise_generic_turbulence(tex->noisesize,
texvec[0],
texvec[1] + tex->nabla,
texvec[2],
tex->noisedepth,
(tex->noisetype != TEX_NOISESOFT),
tex->noisebasis);
texres->nor[2] = BLI_noise_generic_turbulence(tex->noisesize,
texvec[0],
texvec[1],
texvec[2] + tex->nabla,
tex->noisedepth,
(tex->noisetype != TEX_NOISESOFT),
tex->noisebasis);
tex_normal_derivate(tex, texres);
rv |= TEX_NOR;
}
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->trgba[0] = texres->tin;
texres->trgba[1] = BLI_noise_generic_turbulence(tex->noisesize,
texvec[1],
@@ -298,15 +240,6 @@ static int wood(const Tex *tex, const float texvec[3], TexResult *texres)
int rv = TEX_INT;
texres->tin = wood_int(tex, texvec[0], texvec[1], texvec[2]);
if (texres->nor != NULL) {
/* calculate bumpnormal */
texres->nor[0] = wood_int(tex, texvec[0] + tex->nabla, texvec[1], texvec[2]);
texres->nor[1] = wood_int(tex, texvec[0], texvec[1] + tex->nabla, texvec[2]);
texres->nor[2] = wood_int(tex, texvec[0], texvec[1], texvec[2] + tex->nabla);
tex_normal_derivate(tex, texres);
rv |= TEX_NOR;
}
BRICONT;
@@ -358,17 +291,6 @@ static int marble(const Tex *tex, const float texvec[3], TexResult *texres)
texres->tin = marble_int(tex, texvec[0], texvec[1], texvec[2]);
if (texres->nor != NULL) {
/* calculate bumpnormal */
texres->nor[0] = marble_int(tex, texvec[0] + tex->nabla, texvec[1], texvec[2]);
texres->nor[1] = marble_int(tex, texvec[0], texvec[1] + tex->nabla, texvec[2]);
texres->nor[2] = marble_int(tex, texvec[0], texvec[1], texvec[2] + tex->nabla);
tex_normal_derivate(tex, texres);
rv |= TEX_NOR;
}
BRICONT;
return rv;
@@ -454,7 +376,7 @@ static int magic(const Tex *tex, const float texvec[3], TexResult *texres)
/* newnoise: stucci also modified to use different noisebasis */
static int stucci(const Tex *tex, const float texvec[3], TexResult *texres)
{
float nor[3], b2, ofs;
float b2, ofs;
int retval = TEX_INT;
b2 = BLI_noise_generic_noise(tex->noisesize,
@@ -469,40 +391,13 @@ static int stucci(const Tex *tex, const float texvec[3], TexResult *texres)
if (tex->stype) {
ofs *= (b2 * b2);
}
nor[0] = BLI_noise_generic_noise(tex->noisesize,
texvec[0] + ofs,
texvec[1],
texvec[2],
(tex->noisetype != TEX_NOISESOFT),
tex->noisebasis);
nor[1] = BLI_noise_generic_noise(tex->noisesize,
texvec[0],
texvec[1] + ofs,
texvec[2],
(tex->noisetype != TEX_NOISESOFT),
tex->noisebasis);
nor[2] = BLI_noise_generic_noise(tex->noisesize,
texvec[0],
texvec[1],
texvec[2] + ofs,
(tex->noisetype != TEX_NOISESOFT),
tex->noisebasis);
texres->tin = nor[2];
if (texres->nor) {
copy_v3_v3(texres->nor, nor);
tex_normal_derivate(tex, texres);
if (tex->stype == TEX_WALLOUT) {
texres->nor[0] = -texres->nor[0];
texres->nor[1] = -texres->nor[1];
texres->nor[2] = -texres->nor[2];
}
retval |= TEX_NOR;
}
texres->tin = BLI_noise_generic_noise(tex->noisesize,
texvec[0],
texvec[1],
texvec[2] + ofs,
(tex->noisetype != TEX_NOISESOFT),
tex->noisebasis);
if (tex->stype == TEX_WALLOUT) {
texres->tin = 1.0f - texres->tin;
@@ -538,36 +433,6 @@ static int mg_mFractalOrfBmTex(const Tex *tex, const float texvec[3], TexResult
tex->mg_octaves,
tex->noisebasis);
if (texres->nor != NULL) {
float ofs = tex->nabla / tex->noisesize; /* also scaling of texvec */
/* calculate bumpnormal */
texres->nor[0] = tex->ns_outscale * mgravefunc(texvec[0] + ofs,
texvec[1],
texvec[2],
tex->mg_H,
tex->mg_lacunarity,
tex->mg_octaves,
tex->noisebasis);
texres->nor[1] = tex->ns_outscale * mgravefunc(texvec[0],
texvec[1] + ofs,
texvec[2],
tex->mg_H,
tex->mg_lacunarity,
tex->mg_octaves,
tex->noisebasis);
texres->nor[2] = tex->ns_outscale * mgravefunc(texvec[0],
texvec[1],
texvec[2] + ofs,
tex->mg_H,
tex->mg_lacunarity,
tex->mg_octaves,
tex->noisebasis);
tex_normal_derivate(tex, texres);
rv |= TEX_NOR;
}
BRICONT;
return rv;
@@ -595,42 +460,6 @@ static int mg_ridgedOrHybridMFTex(const Tex *tex, const float texvec[3], TexResu
tex->mg_gain,
tex->noisebasis);
if (texres->nor != NULL) {
float ofs = tex->nabla / tex->noisesize; /* also scaling of texvec */
/* calculate bumpnormal */
texres->nor[0] = tex->ns_outscale * mgravefunc(texvec[0] + ofs,
texvec[1],
texvec[2],
tex->mg_H,
tex->mg_lacunarity,
tex->mg_octaves,
tex->mg_offset,
tex->mg_gain,
tex->noisebasis);
texres->nor[1] = tex->ns_outscale * mgravefunc(texvec[0],
texvec[1] + ofs,
texvec[2],
tex->mg_H,
tex->mg_lacunarity,
tex->mg_octaves,
tex->mg_offset,
tex->mg_gain,
tex->noisebasis);
texres->nor[2] = tex->ns_outscale * mgravefunc(texvec[0],
texvec[1],
texvec[2] + ofs,
tex->mg_H,
tex->mg_lacunarity,
tex->mg_octaves,
tex->mg_offset,
tex->mg_gain,
tex->noisebasis);
tex_normal_derivate(tex, texres);
rv |= TEX_NOR;
}
BRICONT;
return rv;
@@ -649,39 +478,6 @@ static int mg_HTerrainTex(const Tex *tex, const float texvec[3], TexResult *texr
tex->mg_offset,
tex->noisebasis);
if (texres->nor != NULL) {
float ofs = tex->nabla / tex->noisesize; /* also scaling of texvec */
/* calculate bumpnormal */
texres->nor[0] = tex->ns_outscale * BLI_noise_mg_hetero_terrain(texvec[0] + ofs,
texvec[1],
texvec[2],
tex->mg_H,
tex->mg_lacunarity,
tex->mg_octaves,
tex->mg_offset,
tex->noisebasis);
texres->nor[1] = tex->ns_outscale * BLI_noise_mg_hetero_terrain(texvec[0],
texvec[1] + ofs,
texvec[2],
tex->mg_H,
tex->mg_lacunarity,
tex->mg_octaves,
tex->mg_offset,
tex->noisebasis);
texres->nor[2] = tex->ns_outscale * BLI_noise_mg_hetero_terrain(texvec[0],
texvec[1],
texvec[2] + ofs,
tex->mg_H,
tex->mg_lacunarity,
tex->mg_octaves,
tex->mg_offset,
tex->noisebasis);
tex_normal_derivate(tex, texres);
rv |= TEX_NOR;
}
BRICONT;
return rv;
@@ -694,33 +490,6 @@ static int mg_distNoiseTex(const Tex *tex, const float texvec[3], TexResult *tex
texres->tin = BLI_noise_mg_variable_lacunarity(
texvec[0], texvec[1], texvec[2], tex->dist_amount, tex->noisebasis, tex->noisebasis2);
if (texres->nor != NULL) {
float ofs = tex->nabla / tex->noisesize; /* also scaling of texvec */
/* calculate bumpnormal */
texres->nor[0] = BLI_noise_mg_variable_lacunarity(texvec[0] + ofs,
texvec[1],
texvec[2],
tex->dist_amount,
tex->noisebasis,
tex->noisebasis2);
texres->nor[1] = BLI_noise_mg_variable_lacunarity(texvec[0],
texvec[1] + ofs,
texvec[2],
tex->dist_amount,
tex->noisebasis,
tex->noisebasis2);
texres->nor[2] = BLI_noise_mg_variable_lacunarity(texvec[0],
texvec[1],
texvec[2] + ofs,
tex->dist_amount,
tex->noisebasis,
tex->noisebasis2);
tex_normal_derivate(tex, texres);
rv |= TEX_NOR;
}
BRICONT;
return rv;
@@ -788,21 +557,6 @@ static int voronoiTex(const Tex *tex, const float texvec[3], TexResult *texres)
}
}
if (texres->nor != NULL) {
float ofs = tex->nabla / tex->noisesize; /* also scaling of texvec */
/* calculate bumpnormal */
BLI_noise_voronoi(texvec[0] + ofs, texvec[1], texvec[2], da, pa, tex->vn_mexp, tex->vn_distm);
texres->nor[0] = sc * fabsf(dot_v4v4(&tex->vn_w1, da));
BLI_noise_voronoi(texvec[0], texvec[1] + ofs, texvec[2], da, pa, tex->vn_mexp, tex->vn_distm);
texres->nor[1] = sc * fabsf(dot_v4v4(&tex->vn_w1, da));
BLI_noise_voronoi(texvec[0], texvec[1], texvec[2] + ofs, da, pa, tex->vn_mexp, tex->vn_distm);
texres->nor[2] = sc * fabsf(dot_v4v4(&tex->vn_w1, da));
tex_normal_derivate(tex, texres);
rv |= TEX_NOR;
}
if (tex->vn_coltype) {
BRICONTRGB;
texres->trgba[3] = 1.0;
@@ -1148,7 +902,7 @@ static int multitex(Tex *tex,
const bool use_nodes)
{
float tmpvec[3];
int retval = 0; /* return value, int:0, col:1, nor:2, everything:3 */
int retval = 0; /* return value, TEX_INT or TEX_RGB. */
texres->talpha = false; /* is set when image texture returns alpha (considered premul) */
@@ -1283,14 +1037,14 @@ static int multitex_nodes_intern(Tex *tex,
}
if (tex->type == TEX_IMAGE) {
int rgbnor;
int retval;
if (mtex) {
float texvec_l[3];
copy_v3_v3(texvec_l, texvec);
/* we have mtex, use it for 2d mapping images only */
do_2d_mapping(mtex, texvec_l, NULL, dxt, dyt);
rgbnor = multitex(tex,
retval = multitex(tex,
texvec_l,
dxt,
dyt,
@@ -1307,7 +1061,7 @@ static int multitex_nodes_intern(Tex *tex,
ImBuf *ibuf = BKE_image_pool_acquire_ibuf(tex->ima, &tex->iuser, pool);
/* don't linearize float buffers, assumed to be linear */
if (ibuf != NULL && ibuf->rect_float == NULL && (rgbnor & TEX_RGB) && scene_color_manage) {
if (ibuf != NULL && ibuf->rect_float == NULL && (retval & TEX_RGB) && scene_color_manage) {
IMB_colormanagement_colorspace_to_scene_linear_v3(texres->trgba, ibuf->rect_colorspace);
}
@@ -1335,7 +1089,7 @@ static int multitex_nodes_intern(Tex *tex,
}
do_2d_mapping(&localmtex, texvec_l, NULL, dxt_l, dyt_l);
rgbnor = multitex(tex,
retval = multitex(tex,
texvec_l,
dxt_l,
dyt_l,
@@ -1352,7 +1106,7 @@ static int multitex_nodes_intern(Tex *tex,
ImBuf *ibuf = BKE_image_pool_acquire_ibuf(tex->ima, &tex->iuser, pool);
/* don't linearize float buffers, assumed to be linear */
if (ibuf != NULL && ibuf->rect_float == NULL && (rgbnor & TEX_RGB) && scene_color_manage) {
if (ibuf != NULL && ibuf->rect_float == NULL && (retval & TEX_RGB) && scene_color_manage) {
IMB_colormanagement_colorspace_to_scene_linear_v3(texres->trgba, ibuf->rect_colorspace);
}
@@ -1360,7 +1114,7 @@ static int multitex_nodes_intern(Tex *tex,
}
}
return rgbnor;
return retval;
}
return multitex(tex,
@@ -1456,145 +1210,6 @@ int multitex_ext_safe(Tex *tex,
/* ------------------------------------------------------------------------- */
void texture_rgb_blend(
float in[3], const float tex[3], const float out[3], float fact, float facg, int blendtype)
{
float facm;
switch (blendtype) {
case MTEX_BLEND:
fact *= facg;
facm = 1.0f - fact;
in[0] = (fact * tex[0] + facm * out[0]);
in[1] = (fact * tex[1] + facm * out[1]);
in[2] = (fact * tex[2] + facm * out[2]);
break;
case MTEX_MUL:
fact *= facg;
facm = 1.0f - fact;
in[0] = (facm + fact * tex[0]) * out[0];
in[1] = (facm + fact * tex[1]) * out[1];
in[2] = (facm + fact * tex[2]) * out[2];
break;
case MTEX_SCREEN:
fact *= facg;
facm = 1.0f - fact;
in[0] = 1.0f - (facm + fact * (1.0f - tex[0])) * (1.0f - out[0]);
in[1] = 1.0f - (facm + fact * (1.0f - tex[1])) * (1.0f - out[1]);
in[2] = 1.0f - (facm + fact * (1.0f - tex[2])) * (1.0f - out[2]);
break;
case MTEX_OVERLAY:
fact *= facg;
facm = 1.0f - fact;
if (out[0] < 0.5f) {
in[0] = out[0] * (facm + 2.0f * fact * tex[0]);
}
else {
in[0] = 1.0f - (facm + 2.0f * fact * (1.0f - tex[0])) * (1.0f - out[0]);
}
if (out[1] < 0.5f) {
in[1] = out[1] * (facm + 2.0f * fact * tex[1]);
}
else {
in[1] = 1.0f - (facm + 2.0f * fact * (1.0f - tex[1])) * (1.0f - out[1]);
}
if (out[2] < 0.5f) {
in[2] = out[2] * (facm + 2.0f * fact * tex[2]);
}
else {
in[2] = 1.0f - (facm + 2.0f * fact * (1.0f - tex[2])) * (1.0f - out[2]);
}
break;
case MTEX_SUB:
fact = -fact;
ATTR_FALLTHROUGH;
case MTEX_ADD:
fact *= facg;
in[0] = (fact * tex[0] + out[0]);
in[1] = (fact * tex[1] + out[1]);
in[2] = (fact * tex[2] + out[2]);
break;
case MTEX_DIV:
fact *= facg;
facm = 1.0f - fact;
if (tex[0] != 0.0f) {
in[0] = facm * out[0] + fact * out[0] / tex[0];
}
if (tex[1] != 0.0f) {
in[1] = facm * out[1] + fact * out[1] / tex[1];
}
if (tex[2] != 0.0f) {
in[2] = facm * out[2] + fact * out[2] / tex[2];
}
break;
case MTEX_DIFF:
fact *= facg;
facm = 1.0f - fact;
in[0] = facm * out[0] + fact * fabsf(tex[0] - out[0]);
in[1] = facm * out[1] + fact * fabsf(tex[1] - out[1]);
in[2] = facm * out[2] + fact * fabsf(tex[2] - out[2]);
break;
case MTEX_DARK:
fact *= facg;
facm = 1.0f - fact;
in[0] = min_ff(out[0], tex[0]) * fact + out[0] * facm;
in[1] = min_ff(out[1], tex[1]) * fact + out[1] * facm;
in[2] = min_ff(out[2], tex[2]) * fact + out[2] * facm;
break;
case MTEX_LIGHT:
fact *= facg;
in[0] = max_ff(fact * tex[0], out[0]);
in[1] = max_ff(fact * tex[1], out[1]);
in[2] = max_ff(fact * tex[2], out[2]);
break;
case MTEX_BLEND_HUE:
fact *= facg;
copy_v3_v3(in, out);
ramp_blend(MA_RAMP_HUE, in, fact, tex);
break;
case MTEX_BLEND_SAT:
fact *= facg;
copy_v3_v3(in, out);
ramp_blend(MA_RAMP_SAT, in, fact, tex);
break;
case MTEX_BLEND_VAL:
fact *= facg;
copy_v3_v3(in, out);
ramp_blend(MA_RAMP_VAL, in, fact, tex);
break;
case MTEX_BLEND_COLOR:
fact *= facg;
copy_v3_v3(in, out);
ramp_blend(MA_RAMP_COLOR, in, fact, tex);
break;
case MTEX_SOFT_LIGHT:
fact *= facg;
copy_v3_v3(in, out);
ramp_blend(MA_RAMP_SOFT, in, fact, tex);
break;
case MTEX_LIN_LIGHT:
fact *= facg;
copy_v3_v3(in, out);
ramp_blend(MA_RAMP_LINEAR, in, fact, tex);
break;
}
}
float texture_value_blend(float tex, float out, float fact, float facg, int blendtype)
{
float in = 0.0, facm, col, scf;
@@ -1703,7 +1318,6 @@ bool RE_texture_evaluate(const MTex *mtex,
if (tex == NULL) {
return 0;
}
texr.nor = NULL;
/* placement */
if (mtex->projx) {