Files
test/source/blender/blenkernel/intern/texture.cc

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

678 lines
16 KiB
C++
Raw Normal View History

/* SPDX-FileCopyrightText: 2001-2002 NaN Holding BV. All rights reserved.
*
* SPDX-License-Identifier: GPL-2.0-or-later */
2002-10-12 11:37:38 +00:00
/** \file
* \ingroup bke
2011-02-27 20:40:57 +00:00
*/
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <optional>
2002-10-12 11:37:38 +00:00
#include "MEM_guardedalloc.h"
#include "BLI_kdopbvh.hh"
#include "BLI_listbase.h"
#include "BLI_math_matrix.h"
#include "BLI_math_rotation.h"
#include "BLI_math_vector.h"
#include "BLI_utildefines.h"
2002-10-12 11:37:38 +00:00
#include "BLT_translation.hh"
/* Allow using deprecated functionality for .blend file I/O. */
#define DNA_DEPRECATED_ALLOW
#include "BKE_node_legacy_types.hh"
#include "DNA_brush_types.h"
#include "DNA_color_types.h"
#include "DNA_defaults.h"
#include "DNA_linestyle_types.h"
2002-10-12 11:37:38 +00:00
#include "DNA_material_types.h"
#include "DNA_node_types.h"
#include "DNA_particle_types.h"
#include "DNA_texture_types.h"
2002-10-12 11:37:38 +00:00
#include "BKE_brush.hh"
#include "BKE_colorband.hh"
#include "BKE_colortools.hh"
#include "BKE_icons.h"
#include "BKE_idtype.hh"
#include "BKE_image.hh"
2024-01-15 12:44:04 -05:00
#include "BKE_lib_id.hh"
#include "BKE_lib_query.hh"
#include "BKE_node_runtime.hh"
#include "BKE_preview_image.hh"
#include "BKE_texture.h"
#include "NOD_texture.h"
#include "RE_texture.h"
2002-10-12 11:37:38 +00:00
2024-01-05 11:16:57 -05:00
#include "DRW_engine.hh"
#include "BLO_read_write.hh"
static void texture_init_data(ID *id)
{
Tex *texture = (Tex *)id;
BLI_assert(MEMCMP_STRUCT_AFTER_IS_ZERO(texture, id));
MEMCPY_STRUCT_AFTER(texture, DNA_struct_default_get(Tex), id);
BKE_imageuser_default(&texture->iuser);
}
static void texture_copy_data(Main *bmain,
std::optional<Library *> owner_library,
ID *id_dst,
const ID *id_src,
const int flag)
{
Tex *texture_dst = (Tex *)id_dst;
const Tex *texture_src = (const Tex *)id_src;
const bool is_localized = (flag & LIB_ID_CREATE_LOCAL) != 0;
/* Never handle user-count here for own sub-data. */
const int flag_subdata = flag | LIB_ID_CREATE_NO_USER_REFCOUNT;
/* Always need allocation of the embedded ID data. */
const int flag_embedded_id_data = flag_subdata & ~LIB_ID_CREATE_NO_ALLOCATE;
if (!BKE_texture_is_image_user(texture_src)) {
texture_dst->ima = nullptr;
}
if (texture_dst->coba) {
texture_dst->coba = static_cast<ColorBand *>(MEM_dupallocN(texture_dst->coba));
}
if (texture_src->nodetree) {
if (texture_src->nodetree->runtime->execdata) {
ntreeTexEndExecTree(texture_src->nodetree->runtime->execdata);
}
if (is_localized) {
texture_dst->nodetree = blender::bke::node_tree_localize(texture_src->nodetree,
&texture_dst->id);
}
else {
BKE_id_copy_in_lib(bmain,
owner_library,
&texture_src->nodetree->id,
&texture_dst->id,
reinterpret_cast<ID **>(&texture_dst->nodetree),
flag_embedded_id_data);
}
}
if ((flag & LIB_ID_COPY_NO_PREVIEW) == 0) {
BKE_previewimg_id_copy(&texture_dst->id, &texture_src->id);
}
else {
texture_dst->preview = nullptr;
}
}
static void texture_free_data(ID *id)
{
Tex *texture = (Tex *)id;
/* is no lib link block, but texture extension */
if (texture->nodetree) {
blender::bke::node_tree_free_embedded_tree(texture->nodetree);
MEM_freeN(texture->nodetree);
texture->nodetree = nullptr;
}
MEM_SAFE_FREE(texture->coba);
BKE_icon_id_delete((ID *)texture);
BKE_previewimg_free(&texture->preview);
}
static void texture_foreach_id(ID *id, LibraryForeachIDData *data)
{
Tex *texture = reinterpret_cast<Tex *>(id);
const int flag = BKE_lib_query_foreachid_process_flags_get(data);
if (texture->nodetree) {
/* nodetree **are owned by IDs**, treat them as mere sub-data and not real ID! */
BKE_LIB_FOREACHID_PROCESS_FUNCTION_CALL(
data, BKE_library_foreach_ID_embedded(data, (ID **)&texture->nodetree));
}
BKE_LIB_FOREACHID_PROCESS_IDSUPER(data, texture->ima, IDWALK_CB_USER);
if (flag & IDWALK_DO_DEPRECATED_POINTERS) {
BKE_LIB_FOREACHID_PROCESS_ID_NOCHECK(data, texture->ipo, IDWALK_CB_USER);
}
}
static void texture_blend_write(BlendWriter *writer, ID *id, const void *id_address)
{
Tex *tex = (Tex *)id;
/* write LibData */
BLO_write_id_struct(writer, Tex, id_address, &tex->id);
BKE_id_blend_write(writer, &tex->id);
/* direct data */
if (tex->coba) {
BLO_write_struct(writer, ColorBand, tex->coba);
}
/* nodetree is integral part of texture, no libdata */
if (tex->nodetree) {
BLO_Write_IDBuffer temp_embedded_id_buffer{tex->nodetree->id, writer};
BLO_write_struct_at_address(writer, bNodeTree, tex->nodetree, temp_embedded_id_buffer.get());
blender::bke::node_tree_blend_write(
writer, reinterpret_cast<bNodeTree *>(temp_embedded_id_buffer.get()));
}
BKE_previewimg_blend_write(writer, tex->preview);
}
static void texture_blend_read_data(BlendDataReader *reader, ID *id)
{
Tex *tex = (Tex *)id;
BLO_read_struct(reader, ColorBand, &tex->coba);
BLO_read_struct(reader, PreviewImage, &tex->preview);
BKE_previewimg_blend_read(reader, tex->preview);
tex->iuser.scene = nullptr;
tex->runtime.last_update = 0;
}
IDTypeInfo IDType_ID_TE = {
/*id_code*/ Tex::id_type,
/*id_filter*/ FILTER_ID_TE,
/*dependencies_id_types*/ FILTER_ID_IM | FILTER_ID_OB,
/*main_listbase_index*/ INDEX_ID_TE,
/*struct_size*/ sizeof(Tex),
/*name*/ "Texture",
/*name_plural*/ N_("textures"),
/*translation_context*/ BLT_I18NCONTEXT_ID_TEXTURE,
/*flags*/ IDTYPE_FLAGS_APPEND_IS_REUSABLE,
/*asset_type_info*/ nullptr,
/*init_data*/ texture_init_data,
/*copy_data*/ texture_copy_data,
/*free_data*/ texture_free_data,
/*make_local*/ nullptr,
/*foreach_id*/ texture_foreach_id,
/*foreach_cache*/ nullptr,
/*foreach_path*/ nullptr,
/*owner_pointer_get*/ nullptr,
/*blend_write*/ texture_blend_write,
/*blend_read_data*/ texture_blend_read_data,
/*blend_read_after_liblink*/ nullptr,
/*blend_read_undo_preserve*/ nullptr,
/*lib_override_apply_post*/ nullptr,
};
void BKE_texture_mtex_foreach_id(LibraryForeachIDData *data, MTex *mtex)
{
BKE_LIB_FOREACHID_PROCESS_IDSUPER(data, mtex->object, IDWALK_CB_NOP);
BKE_LIB_FOREACHID_PROCESS_IDSUPER(data, mtex->tex, IDWALK_CB_USER);
}
/* ****************** Mapping ******************* */
2015-03-29 03:16:55 +11:00
TexMapping *BKE_texture_mapping_add(int type)
{
TexMapping *texmap = MEM_callocN<TexMapping>("TexMapping");
2018-06-17 17:05:51 +02:00
2015-03-29 03:16:55 +11:00
BKE_texture_mapping_default(texmap, type);
2018-06-17 17:05:51 +02:00
return texmap;
}
2015-03-29 03:16:55 +11:00
void BKE_texture_mapping_default(TexMapping *texmap, int type)
{
*texmap = TexMapping{};
texmap->size[0] = texmap->size[1] = texmap->size[2] = 1.0f;
texmap->max[0] = texmap->max[1] = texmap->max[2] = 1.0f;
unit_m4(texmap->mat);
texmap->projx = PROJ_X;
texmap->projy = PROJ_Y;
texmap->projz = PROJ_Z;
texmap->mapping = MTEX_FLAT;
texmap->type = type;
}
2015-03-29 03:16:55 +11:00
void BKE_texture_mapping_init(TexMapping *texmap)
{
float smat[4][4], rmat[4][4], tmat[4][4], proj[4][4], size[3];
if (texmap->projx == PROJ_X && texmap->projy == PROJ_Y && texmap->projz == PROJ_Z &&
is_zero_v3(texmap->loc) && is_zero_v3(texmap->rot) && is_one_v3(texmap->size))
{
unit_m4(texmap->mat);
texmap->flag |= TEXMAP_UNIT_MATRIX;
}
else {
/* axis projection */
zero_m4(proj);
proj[3][3] = 1.0f;
if (texmap->projx != PROJ_N) {
proj[texmap->projx - 1][0] = 1.0f;
}
if (texmap->projy != PROJ_N) {
proj[texmap->projy - 1][1] = 1.0f;
}
if (texmap->projz != PROJ_N) {
proj[texmap->projz - 1][2] = 1.0f;
}
/* scale */
copy_v3_v3(size, texmap->size);
if (ELEM(texmap->type, TEXMAP_TYPE_TEXTURE, TEXMAP_TYPE_NORMAL)) {
/* keep matrix invertible */
if (fabsf(size[0]) < 1e-5f) {
size[0] = signf(size[0]) * 1e-5f;
}
if (fabsf(size[1]) < 1e-5f) {
size[1] = signf(size[1]) * 1e-5f;
}
if (fabsf(size[2]) < 1e-5f) {
size[2] = signf(size[2]) * 1e-5f;
}
}
size_to_mat4(smat, texmap->size);
/* rotation */
eul_to_mat4(rmat, texmap->rot);
/* translation */
unit_m4(tmat);
copy_v3_v3(tmat[3], texmap->loc);
if (texmap->type == TEXMAP_TYPE_TEXTURE) {
/* to transform a texture, the inverse transform needs
* to be applied to the texture coordinate */
mul_m4_series(texmap->mat, tmat, rmat, smat);
invert_m4(texmap->mat);
}
else if (texmap->type == TEXMAP_TYPE_POINT) {
/* forward transform */
mul_m4_series(texmap->mat, tmat, rmat, smat);
}
else if (texmap->type == TEXMAP_TYPE_VECTOR) {
/* no translation for vectors */
mul_m4_m4m4(texmap->mat, rmat, smat);
}
else if (texmap->type == TEXMAP_TYPE_NORMAL) {
/* no translation for normals, and inverse transpose */
mul_m4_m4m4(texmap->mat, rmat, smat);
invert_m4(texmap->mat);
transpose_m4(texmap->mat);
}
/* projection last */
mul_m4_m4m4(texmap->mat, texmap->mat, proj);
texmap->flag &= ~TEXMAP_UNIT_MATRIX;
}
}
ColorMapping *BKE_texture_colormapping_add()
{
ColorMapping *colormap = MEM_callocN<ColorMapping>("ColorMapping");
2018-06-17 17:05:51 +02:00
2015-03-29 03:16:55 +11:00
BKE_texture_colormapping_default(colormap);
2018-06-17 17:05:51 +02:00
return colormap;
}
2015-03-29 03:16:55 +11:00
void BKE_texture_colormapping_default(ColorMapping *colormap)
{
*colormap = ColorMapping{};
2017-12-07 15:52:59 +11:00
BKE_colorband_init(&colormap->coba, true);
colormap->bright = 1.0;
colormap->contrast = 1.0;
colormap->saturation = 1.0;
colormap->blend_color[0] = 0.8f;
colormap->blend_color[1] = 0.8f;
colormap->blend_color[2] = 0.8f;
colormap->blend_type = MA_RAMP_BLEND;
colormap->blend_factor = 0.0f;
}
2002-10-12 11:37:38 +00:00
/* ******************* TEX ************************ */
/* ------------------------------------------------------------------------- */
2015-03-29 03:16:55 +11:00
void BKE_texture_default(Tex *tex)
2002-10-12 11:37:38 +00:00
{
texture_init_data(&tex->id);
2002-10-12 11:37:38 +00:00
}
2015-03-29 03:16:55 +11:00
void BKE_texture_type_set(Tex *tex, int type)
{
tex->type = type;
}
2002-10-12 11:37:38 +00:00
/* ------------------------------------------------------------------------- */
2015-03-29 03:16:55 +11:00
Tex *BKE_texture_add(Main *bmain, const char *name)
2002-10-12 11:37:38 +00:00
{
Tex *tex;
tex = BKE_id_new<Tex>(bmain, name);
2018-06-17 17:05:51 +02:00
2002-10-12 11:37:38 +00:00
return tex;
}
/* ------------------------------------------------------------------------- */
2015-03-29 03:16:55 +11:00
void BKE_texture_mtex_default(MTex *mtex)
2002-10-12 11:37:38 +00:00
{
*mtex = blender::dna::shallow_copy(*DNA_struct_default_get(MTex));
2002-10-12 11:37:38 +00:00
}
/* ------------------------------------------------------------------------- */
MTex *BKE_texture_mtex_add()
2002-10-12 11:37:38 +00:00
{
MTex *mtex;
2018-06-17 17:05:51 +02:00
mtex = MEM_callocN<MTex>("BKE_texture_mtex_add");
2018-06-17 17:05:51 +02:00
2015-03-29 03:16:55 +11:00
BKE_texture_mtex_default(mtex);
2018-06-17 17:05:51 +02:00
2002-10-12 11:37:38 +00:00
return mtex;
}
2015-03-29 03:16:55 +11:00
MTex *BKE_texture_mtex_add_id(ID *id, int slot)
{
MTex **mtex_ar;
short act;
give_active_mtex(id, &mtex_ar, &act);
if (mtex_ar == nullptr) {
return nullptr;
}
if (slot == -1) {
/* find first free */
int i;
for (i = 0; i < MAX_MTEX; i++) {
if (!mtex_ar[i]) {
slot = i;
break;
}
}
if (slot == -1) {
return nullptr;
}
}
else {
/* make sure slot is valid */
if (slot < 0 || slot >= MAX_MTEX) {
return nullptr;
}
}
if (mtex_ar[slot]) {
id_us_min((ID *)mtex_ar[slot]->tex);
MEM_freeN(mtex_ar[slot]);
mtex_ar[slot] = nullptr;
}
2015-03-29 03:16:55 +11:00
mtex_ar[slot] = BKE_texture_mtex_add();
return mtex_ar[slot];
}
2002-10-12 11:37:38 +00:00
/* ------------------------------------------------------------------------- */
Tex *give_current_linestyle_texture(FreestyleLineStyle *linestyle)
{
MTex *mtex = nullptr;
Tex *tex = nullptr;
if (linestyle) {
mtex = linestyle->mtex[int(linestyle->texact)];
if (mtex) {
tex = mtex->tex;
}
}
return tex;
}
void set_current_linestyle_texture(FreestyleLineStyle *linestyle, Tex *newtex)
{
int act = linestyle->texact;
if (linestyle->mtex[act] && linestyle->mtex[act]->tex) {
id_us_min(&linestyle->mtex[act]->tex->id);
}
if (newtex) {
if (!linestyle->mtex[act]) {
2015-03-29 03:16:55 +11:00
linestyle->mtex[act] = BKE_texture_mtex_add();
linestyle->mtex[act]->texco = TEXCO_STROKE;
}
linestyle->mtex[act]->tex = newtex;
id_us_plus(&newtex->id);
}
2021-08-06 13:59:38 +10:00
else {
MEM_SAFE_FREE(linestyle->mtex[act]);
}
}
bool give_active_mtex(ID *id, MTex ***mtex_ar, short *act)
2009-10-12 16:00:39 +00:00
{
switch (GS(id->name)) {
case ID_LS:
*mtex_ar = ((FreestyleLineStyle *)id)->mtex;
if (act) {
*act = (((FreestyleLineStyle *)id)->texact);
}
break;
case ID_PA:
*mtex_ar = ((ParticleSettings *)id)->mtex;
if (act) {
*act = (((ParticleSettings *)id)->texact);
}
break;
default:
*mtex_ar = nullptr;
if (act) {
*act = 0;
}
return false;
2009-10-12 16:00:39 +00:00
}
return true;
2009-10-12 16:00:39 +00:00
}
void set_active_mtex(ID *id, short act)
{
if (act < 0) {
act = 0;
}
else if (act >= MAX_MTEX) {
act = MAX_MTEX - 1;
}
2009-10-12 16:00:39 +00:00
switch (GS(id->name)) {
case ID_LS:
((FreestyleLineStyle *)id)->texact = act;
break;
case ID_PA:
((ParticleSettings *)id)->texact = act;
break;
default:
break;
2009-10-12 16:00:39 +00:00
}
}
Tex *give_current_brush_texture(Brush *br)
{
return br->mtex.tex;
}
void set_current_brush_texture(Brush *br, Tex *newtex)
{
if (br->mtex.tex) {
id_us_min(&br->mtex.tex->id);
}
if (newtex) {
br->mtex.tex = newtex;
id_us_plus(&newtex->id);
}
BKE_brush_tag_unsaved_changes(br);
}
Tex *give_current_particle_texture(ParticleSettings *part)
{
MTex *mtex = nullptr;
Tex *tex = nullptr;
2018-06-17 17:05:51 +02:00
if (!part) {
return nullptr;
}
2018-06-17 17:05:51 +02:00
mtex = part->mtex[int(part->texact)];
if (mtex) {
tex = mtex->tex;
}
2018-06-17 17:05:51 +02:00
return tex;
}
void set_current_particle_texture(ParticleSettings *part, Tex *newtex)
{
int act = part->texact;
if (part->mtex[act] && part->mtex[act]->tex) {
id_us_min(&part->mtex[act]->tex->id);
}
if (newtex) {
if (!part->mtex[act]) {
2015-03-29 03:16:55 +11:00
part->mtex[act] = BKE_texture_mtex_add();
part->mtex[act]->texco = TEXCO_ORCO;
part->mtex[act]->blendtype = MTEX_MUL;
}
2018-06-17 17:05:51 +02:00
part->mtex[act]->tex = newtex;
id_us_plus(&newtex->id);
}
2021-08-06 13:59:38 +10:00
else {
MEM_SAFE_FREE(part->mtex[act]);
}
}
Giant commit! A full detailed description of this will be done later... is several days of work. Here's a summary: Render: - Full cleanup of render code, removing *all* globals and bad level calls all over blender. Render module is now not called abusive anymore - API-fied calls to rendering - Full recode of internal render pipeline. Is now rendering tiles by default, prepared for much smarter 'bucket' render later. - Each thread now can render a full part - Renders were tested with 4 threads, goes fine, apart from some lookup tables in softshadow and AO still - Rendering is prepared to do multiple layers and passes - No single 32 bits trick in render code anymore, all 100% floats now. Writing images/movies - moved writing images to blender kernel (bye bye 'schrijfplaatje'!) - made a new Movie handle system, also in kernel. This will enable much easier use of movies in Blender PreviewRender: - Using new render API, previewrender (in buttons) now uses regular render code to generate images. - new datafile 'preview.blend.c' has the preview scenes in it - previews get rendered in exact displayed size (1 pixel = 1 pixel) 3D Preview render - new; press Pkey in 3d window, for a panel that continuously renders (pkey is for games, i know... but we dont do that in orange now!) - this render works nearly identical to buttons-preview render, so it stops rendering on any event (mouse, keyboard, etc) - on moving/scaling the panel, the render code doesn't recreate all geometry - same for shifting/panning view - all other operations (now) regenerate the full render database still. - this is WIP... but big fun, especially for simple scenes! Compositor - Using same node system as now in use for shaders, you can composit images - works pretty straightforward... needs much more options/tools and integration with rendering still - is not threaded yet, nor is so smart to only recalculate changes... will be done soon! - the "Render Result" node will get all layers/passes as output sockets - The "Output" node renders to a builtin image, which you can view in the Image window. (yes, output nodes to render-result, and to files, is on the list!) The Bad News - "Unified Render" is removed. It might come back in some stage, but this system should be built from scratch. I can't really understand this code... I expect it is not much needed, especially with advanced layer/passes control - Panorama render, Field render, Motion blur, is not coded yet... (I had to recode every single feature in render, so...!) - Lens Flare is also not back... needs total revision, might become composit effect though (using zbuffer for visibility) - Part render is gone! (well, thats obvious, its default now). - The render window is only restored with limited functionality... I am going to check first the option to render to a Image window, so Blender can become a true single-window application. :) For example, the 'Spare render buffer' (jkey) doesnt work. - Render with border, now default creates a smaller image - No zbuffers are written yet... on the todo! - Scons files and MSVC will need work to get compiling again OK... thats what I can quickly recall. Now go compiling!
2006-01-23 22:05:47 +00:00
/* ------------------------------------------------------------------------- */
bool BKE_texture_is_image_user(const Tex *tex)
{
switch (tex->type) {
case TEX_IMAGE: {
return true;
}
}
return false;
}
* Volume Rendering: Voxel data This commit introduces a new texture ('Voxel Data'), used to load up saved voxel data sets for rendering, contributed by Raúl 'farsthary' Fernández Hernández with some additional tweaks. Thanks, Raúl! The texture works similar to the existing point density texture, currently it only provides intensity information, which can then be mapped (for example) to density in a volume material. This is an early version, intended to read the voxel format saved by Raúl's command line simulators, in future revisions there's potential for making a more full-featured 'Blender voxel file format', and also for supporting other formats too. Note: Due to some subtleties in Raúl's existing released simulators, in order to load them correctly the voxel data texture, you'll need to raise the 'resolution' value by 2. So if you baked out the simulation at resolution 50, enter 52 for the resolution in the texture panel. This can possibly be fixed in the simulator later on. Right now, the way the texture is mapped is just in the space 0,0,0 <-> 1,1,1 and it can appear rotated 90 degrees incorrectly. This will be tackled, for now, probably the easiest way to map it is with and empty, using Map Input -> Object. Smoke test: http://www.vimeo.com/2449270 One more note, trilinear interpolation seems a bit slow at the moment, we'll look into this. For curiosity, while testing/debugging this, I made a script that exports a mesh to voxel data. Here's a test of grogan (www.kajimba.com) converted to voxels, rendered as a volume: http://www.vimeo.com/2512028 The script is available here: http://mke3.net/projects/bpython/export_object_voxeldata.py * Another smaller thing, brought back early ray termination (was disabled previously for debugging) and made it user configurable. It now appears as a new value in the volume material: 'Depth Cutoff'. For some background info on what this does, check: http://farsthary.wordpress.com/2008/12/11/cutting-down-render-times/ * Also some disabled work-in-progess code for light cache
2008-12-13 05:41:34 +00:00
bool BKE_texture_dependsOnTime(const Tex *texture)
{
if (texture->ima && BKE_image_is_animated(texture->ima)) {
2014-12-01 17:11:18 +01:00
return true;
}
if (texture->adt) {
2012-07-07 22:51:57 +00:00
/* assume anything in adt means the texture is animated */
2014-12-01 17:11:18 +01:00
return true;
}
if (texture->type == TEX_NOISE) {
2012-07-07 22:51:57 +00:00
/* noise always varies with time */
2014-12-01 17:11:18 +01:00
return true;
}
2014-12-01 17:11:18 +01:00
return false;
}
/* ------------------------------------------------------------------------- */
void BKE_texture_get_value_ex(Tex *texture,
const float *tex_co,
TexResult *texres,
ImagePool *pool,
bool use_color_management)
{
/* no node textures for now */
const int result_type = multitex_ext_safe(
texture, tex_co, texres, pool, use_color_management, false);
/* if the texture gave an RGB value, we assume it didn't give a valid
* intensity, since this is in the context of modifiers don't use perceptual color conversion.
* if the texture didn't give an RGB value, copy the intensity across
*/
if (result_type & TEX_RGB) {
2022-01-28 13:28:31 +01:00
texres->tin = (1.0f / 3.0f) * (texres->trgba[0] + texres->trgba[1] + texres->trgba[2]);
}
else {
2022-01-28 13:28:31 +01:00
copy_v3_fl(texres->trgba, texres->tin);
}
}
void BKE_texture_get_value(Tex *texture,
const float *tex_co,
TexResult *texres,
bool use_color_management)
{
BKE_texture_get_value_ex(texture, tex_co, texres, nullptr, use_color_management);
}
static void texture_nodes_fetch_images_for_pool(Tex *texture, bNodeTree *ntree, ImagePool *pool)
{
for (bNode *node : ntree->all_nodes()) {
if (node->type_legacy == SH_NODE_TEX_IMAGE && node->id != nullptr) {
Image *image = (Image *)node->id;
BKE_image_pool_acquire_ibuf(image, &texture->iuser, pool);
}
else if (node->is_group() && node->id != nullptr) {
/* TODO(sergey): Do we need to control recursion here? */
bNodeTree *nested_tree = (bNodeTree *)node->id;
texture_nodes_fetch_images_for_pool(texture, nested_tree, pool);
}
}
}
void BKE_texture_fetch_images_for_pool(Tex *texture, ImagePool *pool)
{
if (texture->nodetree != nullptr) {
texture_nodes_fetch_images_for_pool(texture, texture->nodetree, pool);
}
else {
if (texture->type == TEX_IMAGE) {
if (texture->ima != nullptr) {
BKE_image_pool_acquire_ibuf(texture->ima, &texture->iuser, pool);
}
}
}
}