diff options
Diffstat (limited to 'source/blender/render')
-rw-r--r-- | source/blender/render/RE_pipeline.h | 16 | ||||
-rw-r--r-- | source/blender/render/RE_texture.h | 3 | ||||
-rw-r--r-- | source/blender/render/RE_texture_margin.h | 9 | ||||
-rw-r--r-- | source/blender/render/intern/bake.c | 25 | ||||
-rw-r--r-- | source/blender/render/intern/multires_bake.c | 242 | ||||
-rw-r--r-- | source/blender/render/intern/pipeline.c | 8 | ||||
-rw-r--r-- | source/blender/render/intern/render_result.c | 2 | ||||
-rw-r--r-- | source/blender/render/intern/render_result.h | 2 | ||||
-rw-r--r-- | source/blender/render/intern/texture_image.c | 310 | ||||
-rw-r--r-- | source/blender/render/intern/texture_margin.cc | 9 | ||||
-rw-r--r-- | source/blender/render/intern/texture_pointdensity.c | 7 | ||||
-rw-r--r-- | source/blender/render/intern/texture_procedural.c | 429 |
12 files changed, 219 insertions, 843 deletions
diff --git a/source/blender/render/RE_pipeline.h b/source/blender/render/RE_pipeline.h index 0a8668221ad..548e38d3ef3 100644 --- a/source/blender/render/RE_pipeline.h +++ b/source/blender/render/RE_pipeline.h @@ -74,10 +74,12 @@ typedef struct RenderPass { int pad; } RenderPass; -/* a renderlayer is a full image, but with all passes and samples */ -/* size of the rects is defined in RenderResult */ -/* after render, the Combined pass is in combined, - * for renderlayers read from files it is a real pass */ +/** + * - A render-layer is a full image, but with all passes and samples. + * - The size of the rects is defined in #RenderResult. + * - After render, the Combined pass is in combined, + * for render-layers read from files it is a real pass. + */ typedef struct RenderLayer { struct RenderLayer *next, *prev; @@ -247,15 +249,15 @@ void RE_render_result_full_channel_name(char *fullname, const char *passname, const char *viewname, const char *chan_id, - const int channel); + int channel); struct ImBuf *RE_render_result_rect_to_ibuf(struct RenderResult *rr, const struct ImageFormatData *imf, const float dither, - const int view_id); + int view_id); void RE_render_result_rect_from_ibuf(struct RenderResult *rr, const struct ImBuf *ibuf, - const int view_id); + int view_id); struct RenderLayer *RE_GetRenderLayer(struct RenderResult *rr, const char *name); float *RE_RenderLayerGetPass(struct RenderLayer *rl, const char *name, const char *viewname); diff --git a/source/blender/render/RE_texture.h b/source/blender/render/RE_texture.h index be50eacd7bf..a4e30c917d5 100644 --- a/source/blender/render/RE_texture.h +++ b/source/blender/render/RE_texture.h @@ -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. */ diff --git a/source/blender/render/RE_texture_margin.h b/source/blender/render/RE_texture_margin.h index 0c91abeaddd..023615cea87 100644 --- a/source/blender/render/RE_texture_margin.h +++ b/source/blender/render/RE_texture_margin.h @@ -27,16 +27,13 @@ struct Mesh; */ void RE_generate_texturemargin_adjacentfaces(struct ImBuf *ibuf, char *mask, - const int margin, + int margin, struct Mesh const *me, char const *uv_layer, const float uv_offset[2]); -void RE_generate_texturemargin_adjacentfaces_dm(struct ImBuf *ibuf, - char *mask, - const int margin, - struct DerivedMesh *dm, - const float uv_offset[2]); +void RE_generate_texturemargin_adjacentfaces_dm( + struct ImBuf *ibuf, char *mask, int margin, struct DerivedMesh *dm, const float uv_offset[2]); #ifdef __cplusplus } diff --git a/source/blender/render/intern/bake.c b/source/blender/render/intern/bake.c index 5953c0f0f8f..9ffe2879779 100644 --- a/source/blender/render/intern/bake.c +++ b/source/blender/render/intern/bake.c @@ -96,7 +96,7 @@ typedef struct TriTessFace { const MVert *mverts[3]; const float *vert_normals[3]; const TSpace *tspace[3]; - float *loop_normal[3]; + const float *loop_normal[3]; float normal[3]; /* for flat faces */ bool is_smooth; } TriTessFace; @@ -330,10 +330,10 @@ static bool cast_ray_highpoly(BVHTreeFromMesh *treeData, { int i; int hit_mesh = -1; - float hit_distance = max_ray_distance; - if (hit_distance == 0.0f) { + float hit_distance_squared = max_ray_distance * max_ray_distance; + if (hit_distance_squared == 0.0f) { /* No ray distance set, use maximum. */ - hit_distance = FLT_MAX; + hit_distance_squared = FLT_MAX; } BVHTreeRayHit *hits; @@ -365,16 +365,14 @@ static bool cast_ray_highpoly(BVHTreeFromMesh *treeData, } if (hits[i].index != -1) { - float distance; - float hit_world[3]; - /* distance comparison in world space */ + float hit_world[3]; mul_v3_m4v3(hit_world, highpoly[i].obmat, hits[i].co); - distance = len_squared_v3v3(hit_world, co); + float distance_squared = len_squared_v3v3(hit_world, co); - if (distance < hit_distance) { + if (distance_squared < hit_distance_squared) { hit_mesh = i; - hit_distance = distance; + hit_distance_squared = distance_squared; } } } @@ -453,9 +451,6 @@ static bool cast_ray_highpoly(BVHTreeFromMesh *treeData, static TriTessFace *mesh_calc_tri_tessface(Mesh *me, bool tangent, Mesh *me_eval) { int i; - MVert *mvert; - TSpace *tspace = NULL; - float(*loop_normals)[3] = NULL; const int tottri = poly_to_tri_count(me->totpoly, me->totloop); MLoopTri *looptri; @@ -465,7 +460,7 @@ static TriTessFace *mesh_calc_tri_tessface(Mesh *me, bool tangent, Mesh *me_eval unsigned int mpoly_prev = UINT_MAX; float no[3]; - mvert = CustomData_get_layer(&me->vdata, CD_MVERT); + const MVert *mvert = CustomData_get_layer(&me->vdata, CD_MVERT); looptri = MEM_mallocN(sizeof(*looptri) * tottri, __func__); triangles = MEM_callocN(sizeof(TriTessFace) * tottri, __func__); @@ -482,6 +477,8 @@ static TriTessFace *mesh_calc_tri_tessface(Mesh *me, bool tangent, Mesh *me_eval BKE_mesh_recalc_looptri(me->mloop, me->mpoly, me->mvert, me->totloop, me->totpoly, looptri); } + const TSpace *tspace = NULL; + const float(*loop_normals)[3] = NULL; if (tangent) { BKE_mesh_ensure_normals_for_display(me_eval); BKE_mesh_calc_normals_split(me_eval); diff --git a/source/blender/render/intern/multires_bake.c b/source/blender/render/intern/multires_bake.c index f93397eedab..e3229e20595 100644 --- a/source/blender/render/intern/multires_bake.c +++ b/source/blender/render/intern/multires_bake.c @@ -10,6 +10,7 @@ #include "MEM_guardedalloc.h" #include "DNA_mesh_types.h" +#include "DNA_meshdata_types.h" #include "DNA_object_types.h" #include "DNA_scene_types.h" @@ -464,140 +465,141 @@ static void do_multires_bake(MultiresBakeRender *bkr, const MLoopTri *mlooptri = dm->getLoopTriArray(dm); const int lvl = bkr->lvl; int tot_tri = dm->getNumLoopTri(dm); + if (tot_tri < 1) { + return; + } - if (tot_tri > 0) { - MultiresBakeThread *handles; - MultiresBakeQueue queue; - - MVert *mvert = dm->getVertArray(dm); - MPoly *mpoly = dm->getPolyArray(dm); - MLoop *mloop = dm->getLoopArray(dm); - MLoopUV *mloopuv = dm->getLoopDataArray(dm, CD_MLOOPUV); - float *pvtangent = NULL; - - ListBase threads; - int i, tot_thread = bkr->threads > 0 ? bkr->threads : BLI_system_thread_count(); - - void *bake_data = NULL; - - Mesh *temp_mesh = BKE_mesh_new_nomain( - dm->getNumVerts(dm), dm->getNumEdges(dm), 0, dm->getNumLoops(dm), dm->getNumPolys(dm)); - memcpy(temp_mesh->mvert, dm->getVertArray(dm), temp_mesh->totvert * sizeof(*temp_mesh->mvert)); - memcpy(temp_mesh->medge, dm->getEdgeArray(dm), temp_mesh->totedge * sizeof(*temp_mesh->medge)); - memcpy(temp_mesh->mpoly, dm->getPolyArray(dm), temp_mesh->totpoly * sizeof(*temp_mesh->mpoly)); - memcpy(temp_mesh->mloop, dm->getLoopArray(dm), temp_mesh->totloop * sizeof(*temp_mesh->mloop)); - const float(*vert_normals)[3] = BKE_mesh_vertex_normals_ensure(temp_mesh); - const float(*poly_normals)[3] = BKE_mesh_poly_normals_ensure(temp_mesh); - - if (require_tangent) { - if (CustomData_get_layer_index(&dm->loopData, CD_TANGENT) == -1) { - BKE_mesh_calc_loop_tangent_ex( - dm->getVertArray(dm), - dm->getPolyArray(dm), - dm->getNumPolys(dm), - dm->getLoopArray(dm), - dm->getLoopTriArray(dm), - dm->getNumLoopTri(dm), - &dm->loopData, - true, - NULL, - 0, - vert_normals, - poly_normals, - (const float(*)[3])dm->getLoopDataArray(dm, CD_NORMAL), - (const float(*)[3])dm->getVertDataArray(dm, CD_ORCO), /* may be nullptr */ - /* result */ - &dm->loopData, - dm->getNumLoops(dm), - &dm->tangent_mask); - } - - pvtangent = DM_get_loop_data_layer(dm, CD_TANGENT); + MultiresBakeThread *handles; + MultiresBakeQueue queue; + + MVert *mvert = dm->getVertArray(dm); + MPoly *mpoly = dm->getPolyArray(dm); + MLoop *mloop = dm->getLoopArray(dm); + MLoopUV *mloopuv = dm->getLoopDataArray(dm, CD_MLOOPUV); + float *pvtangent = NULL; + + ListBase threads; + int i, tot_thread = bkr->threads > 0 ? bkr->threads : BLI_system_thread_count(); + + void *bake_data = NULL; + + Mesh *temp_mesh = BKE_mesh_new_nomain( + dm->getNumVerts(dm), dm->getNumEdges(dm), 0, dm->getNumLoops(dm), dm->getNumPolys(dm)); + memcpy(temp_mesh->mvert, dm->getVertArray(dm), temp_mesh->totvert * sizeof(*temp_mesh->mvert)); + memcpy(temp_mesh->medge, dm->getEdgeArray(dm), temp_mesh->totedge * sizeof(*temp_mesh->medge)); + memcpy(temp_mesh->mpoly, dm->getPolyArray(dm), temp_mesh->totpoly * sizeof(*temp_mesh->mpoly)); + memcpy(temp_mesh->mloop, dm->getLoopArray(dm), temp_mesh->totloop * sizeof(*temp_mesh->mloop)); + const float(*vert_normals)[3] = BKE_mesh_vertex_normals_ensure(temp_mesh); + const float(*poly_normals)[3] = BKE_mesh_poly_normals_ensure(temp_mesh); + + if (require_tangent) { + if (CustomData_get_layer_index(&dm->loopData, CD_TANGENT) == -1) { + BKE_mesh_calc_loop_tangent_ex( + dm->getVertArray(dm), + dm->getPolyArray(dm), + dm->getNumPolys(dm), + dm->getLoopArray(dm), + dm->getLoopTriArray(dm), + dm->getNumLoopTri(dm), + &dm->loopData, + true, + NULL, + 0, + vert_normals, + poly_normals, + (const float(*)[3])dm->getLoopDataArray(dm, CD_NORMAL), + (const float(*)[3])dm->getVertDataArray(dm, CD_ORCO), /* may be nullptr */ + /* result */ + &dm->loopData, + dm->getNumLoops(dm), + &dm->tangent_mask); } - /* all threads shares the same custom bake data */ - if (initBakeData) { - bake_data = initBakeData(bkr, ibuf); - } + pvtangent = DM_get_loop_data_layer(dm, CD_TANGENT); + } - if (tot_thread > 1) { - BLI_threadpool_init(&threads, do_multires_bake_thread, tot_thread); - } + /* all threads shares the same custom bake data */ + if (initBakeData) { + bake_data = initBakeData(bkr, ibuf); + } - handles = MEM_callocN(tot_thread * sizeof(MultiresBakeThread), "do_multires_bake handles"); - - init_ccgdm_arrays(bkr->hires_dm); - - /* faces queue */ - queue.cur_tri = 0; - queue.tot_tri = tot_tri; - BLI_spin_init(&queue.spin); - - /* fill in threads handles */ - for (i = 0; i < tot_thread; i++) { - MultiresBakeThread *handle = &handles[i]; - - handle->bkr = bkr; - handle->image = ima; - handle->queue = &queue; - - handle->data.mpoly = mpoly; - handle->data.mvert = mvert; - handle->data.vert_normals = vert_normals; - handle->data.mloopuv = mloopuv; - BKE_image_get_tile_uv(ima, tile->tile_number, handle->data.uv_offset); - handle->data.mlooptri = mlooptri; - handle->data.mloop = mloop; - handle->data.pvtangent = pvtangent; - handle->data.precomputed_normals = poly_normals; /* don't strictly need this */ - handle->data.w = ibuf->x; - handle->data.h = ibuf->y; - handle->data.lores_dm = dm; - handle->data.hires_dm = bkr->hires_dm; - handle->data.lvl = lvl; - handle->data.pass_data = passKnownData; - handle->data.thread_data = handle; - handle->data.bake_data = bake_data; - handle->data.ibuf = ibuf; - - handle->height_min = FLT_MAX; - handle->height_max = -FLT_MAX; - - init_bake_rast(&handle->bake_rast, ibuf, &handle->data, flush_pixel, bkr->do_update); - - if (tot_thread > 1) { - BLI_threadpool_insert(&threads, handle); - } - } + if (tot_thread > 1) { + BLI_threadpool_init(&threads, do_multires_bake_thread, tot_thread); + } + + handles = MEM_callocN(tot_thread * sizeof(MultiresBakeThread), "do_multires_bake handles"); + + init_ccgdm_arrays(bkr->hires_dm); + + /* faces queue */ + queue.cur_tri = 0; + queue.tot_tri = tot_tri; + BLI_spin_init(&queue.spin); + + /* fill in threads handles */ + for (i = 0; i < tot_thread; i++) { + MultiresBakeThread *handle = &handles[i]; + + handle->bkr = bkr; + handle->image = ima; + handle->queue = &queue; + + handle->data.mpoly = mpoly; + handle->data.mvert = mvert; + handle->data.vert_normals = vert_normals; + handle->data.mloopuv = mloopuv; + BKE_image_get_tile_uv(ima, tile->tile_number, handle->data.uv_offset); + handle->data.mlooptri = mlooptri; + handle->data.mloop = mloop; + handle->data.pvtangent = pvtangent; + handle->data.precomputed_normals = poly_normals; /* don't strictly need this */ + handle->data.w = ibuf->x; + handle->data.h = ibuf->y; + handle->data.lores_dm = dm; + handle->data.hires_dm = bkr->hires_dm; + handle->data.lvl = lvl; + handle->data.pass_data = passKnownData; + handle->data.thread_data = handle; + handle->data.bake_data = bake_data; + handle->data.ibuf = ibuf; + + handle->height_min = FLT_MAX; + handle->height_max = -FLT_MAX; + + init_bake_rast(&handle->bake_rast, ibuf, &handle->data, flush_pixel, bkr->do_update); - /* run threads */ if (tot_thread > 1) { - BLI_threadpool_end(&threads); + BLI_threadpool_insert(&threads, handle); } - else { - do_multires_bake_thread(&handles[0]); - } - - /* construct bake result */ - result->height_min = handles[0].height_min; - result->height_max = handles[0].height_max; + } - for (i = 1; i < tot_thread; i++) { - result->height_min = min_ff(result->height_min, handles[i].height_min); - result->height_max = max_ff(result->height_max, handles[i].height_max); - } + /* run threads */ + if (tot_thread > 1) { + BLI_threadpool_end(&threads); + } + else { + do_multires_bake_thread(&handles[0]); + } - BLI_spin_end(&queue.spin); + /* construct bake result */ + result->height_min = handles[0].height_min; + result->height_max = handles[0].height_max; - /* finalize baking */ - if (freeBakeData) { - freeBakeData(bake_data); - } + for (i = 1; i < tot_thread; i++) { + result->height_min = min_ff(result->height_min, handles[i].height_min); + result->height_max = max_ff(result->height_max, handles[i].height_max); + } - MEM_freeN(handles); + BLI_spin_end(&queue.spin); - BKE_id_free(NULL, temp_mesh); + /* finalize baking */ + if (freeBakeData) { + freeBakeData(bake_data); } + + MEM_freeN(handles); + + BKE_id_free(NULL, temp_mesh); } /* mode = 0: interpolate normals, diff --git a/source/blender/render/intern/pipeline.c b/source/blender/render/intern/pipeline.c index 6c06cd663fa..075f1ece647 100644 --- a/source/blender/render/intern/pipeline.c +++ b/source/blender/render/intern/pipeline.c @@ -87,8 +87,6 @@ # include "FRS_freestyle.h" #endif -#include "DEG_depsgraph.h" - /* internal */ #include "pipeline.h" #include "render_result.h" @@ -983,7 +981,7 @@ static void render_result_uncrop(Render *re) render_result_free(re->result); re->result = rres; - /* weak... the display callback wants an active renderlayer pointer... */ + /* Weak, the display callback wants an active render-layer pointer. */ re->result->renlay = render_get_active_layer(re, re->result); BLI_rw_mutex_unlock(&re->resultmutex); @@ -1315,8 +1313,8 @@ static void do_render_sequencer(Render *re) true, &context); - /* the renderresult gets destroyed during the rendering, so we first collect all ibufs - * and then we populate the final renderesult */ + /* The render-result gets destroyed during the rendering, so we first collect all ibufs + * and then we populate the final render-result. */ for (view_id = 0; view_id < tot_views; view_id++) { context.view_id = view_id; diff --git a/source/blender/render/intern/render_result.c b/source/blender/render/intern/render_result.c index 9f4aa642773..9992d1a507f 100644 --- a/source/blender/render/intern/render_result.c +++ b/source/blender/render/intern/render_result.c @@ -825,7 +825,7 @@ void render_result_merge(RenderResult *rr, RenderResult *rrpart) if (rpass->rect == NULL || rpassp->rect == NULL) { continue; } - /* Renderresult have all passes, renderpart only the active view's passes. */ + /* Render-result have all passes, render-part only the active view's passes. */ if (!STREQ(rpassp->fullname, rpass->fullname)) { continue; } diff --git a/source/blender/render/intern/render_result.h b/source/blender/render/intern/render_result.h index 30f49775562..c84e0a04018 100644 --- a/source/blender/render/intern/render_result.h +++ b/source/blender/render/intern/render_result.h @@ -44,7 +44,7 @@ struct RenderResult *render_result_new(struct Render *re, void render_result_passes_allocated_ensure(struct RenderResult *rr); /** - * From imbuf, if a handle was returned and + * From `imbuf`, if a handle was returned and * it's not a single-layer multi-view we convert this to render result. */ struct RenderResult *render_result_new_from_exr( diff --git a/source/blender/render/intern/texture_image.c b/source/blender/render/intern/texture_image.c index 69c24a18f36..7da9e7c3d58 100644 --- a/source/blender/render/intern/texture_image.c +++ b/source/blender/render/intern/texture_image.c @@ -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; } } } @@ -1215,7 +1172,7 @@ static int imagewraposa_aniso(Tex *tex, AFD.intpol = intpol; AFD.extflag = extflag; - /* brecht: added stupid clamping here, large dx/dy can give very large + /* NOTE(@brecht): added stupid clamping here, large dx/dy can give very large * filter sizes which take ages to render, it may be better to do this * more intelligently later in the code .. probably it's not noticeable */ if (AFD.dxt[0] * AFD.dxt[0] + AFD.dxt[1] * AFD.dxt[1] > 2.0f * 2.0f) { @@ -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; - - 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]; - - /* don't switch x or y! */ - texres->nor[0] = (val1 - val2); - texres->nor[1] = (val1 - val3); - - if (previbuf != curibuf) { /* interpolate */ - - 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]; - } - } - texres->nor[0] *= bumpscale; - texres->nor[1] *= bumpscale; - } - else { - maxx = fx + minx; - minx = fx - minx; - maxy = fy + miny; - miny = fy - miny; + maxx = fx + minx; + minx = fx - minx; + maxy = fy + miny; + miny = fy - miny; - boxsample(curibuf, minx, miny, maxx, maxy, texres, imaprepeat, imapextend); + boxsample(curibuf, minx, miny, maxx, maxy, texres, imaprepeat, imapextend); - if (previbuf != curibuf) { /* interpolate */ - boxsample(previbuf, minx, miny, maxx, maxy, &texr, imaprepeat, imapextend); + if (previbuf != curibuf) { /* interpolate */ + boxsample(previbuf, minx, miny, maxx, maxy, &texr, imaprepeat, imapextend); - fx = 2.0f * (pixsize - maxd) / pixsize; + 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]; - } + 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]; } } } @@ -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)) { diff --git a/source/blender/render/intern/texture_margin.cc b/source/blender/render/intern/texture_margin.cc index 2d68148a86a..37ef9213615 100644 --- a/source/blender/render/intern/texture_margin.cc +++ b/source/blender/render/intern/texture_margin.cc @@ -12,6 +12,7 @@ #include "BLI_vector.hh" #include "BKE_DerivedMesh.h" +#include "BKE_customdata.h" #include "BKE_mesh.h" #include "DNA_mesh_types.h" @@ -492,11 +493,11 @@ static void generate_margin(ImBuf *ibuf, MPoly *mpoly; MLoop *mloop; - MLoopUV const *mloopuv; + const MLoopUV *mloopuv; int totpoly, totloop, totedge; int tottri; - MLoopTri const *looptri; + const MLoopTri *looptri; MLoopTri *looptri_mem = nullptr; if (me) { @@ -508,11 +509,11 @@ static void generate_margin(ImBuf *ibuf, mloop = me->mloop; if ((uv_layer == nullptr) || (uv_layer[0] == '\0')) { - mloopuv = static_cast<MLoopUV const *>(CustomData_get_layer(&me->ldata, CD_MLOOPUV)); + mloopuv = static_cast<const MLoopUV *>(CustomData_get_layer(&me->ldata, CD_MLOOPUV)); } else { int uv_id = CustomData_get_named_layer(&me->ldata, CD_MLOOPUV, uv_layer); - mloopuv = static_cast<MLoopUV const *>( + mloopuv = static_cast<const MLoopUV *>( CustomData_get_layer_n(&me->ldata, CD_MLOOPUV, uv_id)); } diff --git a/source/blender/render/intern/texture_pointdensity.c b/source/blender/render/intern/texture_pointdensity.c index 8ba3bac7cad..6e0bae700dc 100644 --- a/source/blender/render/intern/texture_pointdensity.c +++ b/source/blender/render/intern/texture_pointdensity.c @@ -271,7 +271,6 @@ static void pointdensity_cache_vertex_color(PointDensity *pd, { const MLoop *mloop = mesh->mloop; const int totloop = mesh->totloop; - const MLoopCol *mcol; char layername[MAX_CUSTOMDATA_LAYER_NAME]; int i; @@ -282,7 +281,7 @@ static void pointdensity_cache_vertex_color(PointDensity *pd, } CustomData_validate_layer_name( &mesh->ldata, CD_PROP_BYTE_COLOR, pd->vertex_attribute_name, layername); - mcol = CustomData_get_layer_named(&mesh->ldata, CD_PROP_BYTE_COLOR, layername); + const MLoopCol *mcol = CustomData_get_layer_named(&mesh->ldata, CD_PROP_BYTE_COLOR, layername); if (!mcol) { return; } @@ -323,13 +322,12 @@ static void pointdensity_cache_vertex_weight(PointDensity *pd, float *data_color) { const int totvert = mesh->totvert; - const MDeformVert *mdef, *dv; int mdef_index; int i; BLI_assert(data_color); - mdef = CustomData_get_layer(&mesh->vdata, CD_MDEFORMVERT); + const MDeformVert *mdef = CustomData_get_layer(&mesh->vdata, CD_MDEFORMVERT); if (!mdef) { return; } @@ -341,6 +339,7 @@ static void pointdensity_cache_vertex_weight(PointDensity *pd, return; } + const MDeformVert *dv; for (i = 0, dv = mdef; i < totvert; i++, dv++, data_color += 3) { MDeformWeight *dw; int j; diff --git a/source/blender/render/intern/texture_procedural.c b/source/blender/render/intern/texture_procedural.c index 73dbcfdfeab..37605236738 100644 --- a/source/blender/render/intern/texture_procedural.c +++ b/source/blender/render/intern/texture_procedural.c @@ -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) */ @@ -1208,9 +962,8 @@ static int multitex(Tex *tex, case TEX_MUSGRAVE: /* newnoise: musgrave types */ - /* ton: added this, for Blender convention reason. - * artificer: added the use of tmpvec to avoid scaling texvec - */ + /* NOTE(@ton): added this, for Blender convention reason. + * NOTE(@artificer): added the use of tmpvec to avoid scaling texvec. */ copy_v3_v3(tmpvec, texvec); mul_v3_fl(tmpvec, 1.0f / tex->noisesize); @@ -1230,18 +983,16 @@ static int multitex(Tex *tex, break; /* newnoise: voronoi type */ case TEX_VORONOI: - /* ton: added this, for Blender convention reason. - * artificer: added the use of tmpvec to avoid scaling texvec - */ + /* NOTE(@ton): added this, for Blender convention reason. + * NOTE(@artificer): added the use of tmpvec to avoid scaling texvec. */ copy_v3_v3(tmpvec, texvec); mul_v3_fl(tmpvec, 1.0f / tex->noisesize); retval = voronoiTex(tex, tmpvec, texres); break; case TEX_DISTNOISE: - /* ton: added this, for Blender convention reason. - * artificer: added the use of tmpvec to avoid scaling texvec - */ + /* NOTE(@ton): added this, for Blender convention reason. + * NOTE(@artificer): added the use of tmpvec to avoid scaling texvec. */ copy_v3_v3(tmpvec, texvec); mul_v3_fl(tmpvec, 1.0f / tex->noisesize); @@ -1286,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, @@ -1310,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); } @@ -1338,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, @@ -1355,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); } @@ -1363,7 +1114,7 @@ static int multitex_nodes_intern(Tex *tex, } } - return rgbnor; + return retval; } return multitex(tex, @@ -1459,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; @@ -1706,7 +1318,6 @@ bool RE_texture_evaluate(const MTex *mtex, if (tex == NULL) { return 0; } - texr.nor = NULL; /* placement */ if (mtex->projx) { |