Blender V5.0
workbench_materials.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
6
7#include "BLI_ghash.h"
8#include "BLI_hash.h"
9#include "BLI_math_color.h"
10
12
13/* get_image */
15#include "DNA_material_types.h"
16#include "DNA_node_types.h"
17#include "ED_uvedit.hh"
18/* get_image */
19
20namespace blender::workbench {
21
22Material::Material(::Object &ob, bool random)
23{
24 if (random) {
26 if (ob.id.lib) {
28 }
29 float3 hsv = float3(BLI_hash_int_01(hash), 0.5f, 0.8f);
32 }
33 else {
34 base_color = ob.color;
35 }
36 packed_data = Material::pack_data(0.0f, 0.4f, ob.color[3]);
37}
38
40{
41 const ::bNode *node = nullptr;
42
43 ::Image *image = nullptr;
44 ImageUser *user = nullptr;
45 ED_object_get_active_image(ob, material_index + 1, &image, &user, &node, nullptr);
46 if (!node || !image) {
47 return;
48 }
49
50 switch (node->type_legacy) {
51 case SH_NODE_TEX_IMAGE: {
52 const NodeTexImage *storage = static_cast<NodeTexImage *>(node->storage);
53 const bool use_filter = (storage->interpolation != SHD_INTERP_CLOSEST);
54 sampler_state.set_filtering_flag_from_test(GPU_SAMPLER_FILTERING_LINEAR, use_filter);
55 switch (storage->extension) {
57 default:
60 break;
64 break;
68 break;
72 break;
73 }
74 break;
75 }
77 const NodeTexEnvironment *storage = static_cast<NodeTexEnvironment *>(node->storage);
78 const bool use_filter = (storage->interpolation != SHD_INTERP_CLOSEST);
79 sampler_state.set_filtering_flag_from_test(GPU_SAMPLER_FILTERING_LINEAR, use_filter);
80 break;
81 }
82 default:
83 BLI_assert_msg(0, "Node type not supported by workbench");
84 }
85
86 gpu = BKE_image_get_gpu_material_texture(image, user, true);
89 name = image->id.name;
90}
91
99
100} // namespace blender::workbench
ImageGPUTextures BKE_image_get_gpu_material_texture(Image *image, ImageUser *iuser, const bool use_tile_mapping)
Definition image_gpu.cc:506
#define SH_NODE_TEX_IMAGE
#define SH_NODE_TEX_ENVIRONMENT
#define BLI_assert_msg(a, msg)
Definition BLI_assert.h:53
unsigned int BLI_ghashutil_strhash_p_murmur(const void *ptr)
BLI_INLINE float BLI_hash_int_01(unsigned int k)
Definition BLI_hash.h:92
void hsv_to_rgb_v(const float hsv[3], float r_rgb[3])
Definition math_color.cc:57
unsigned int uint
#define ELEM(...)
@ IMA_ALPHA_IGNORE
@ IMA_ALPHA_PREMUL
@ IMA_ALPHA_CHANNEL_PACKED
@ SHD_INTERP_CLOSEST
@ SHD_IMAGE_EXTENSION_MIRROR
@ SHD_IMAGE_EXTENSION_CLIP
@ SHD_IMAGE_EXTENSION_REPEAT
@ SHD_IMAGE_EXTENSION_EXTEND
bool ED_object_get_active_image(Object *ob, int mat_nr, Image **r_ima, ImageUser **r_iuser, const bNode **r_node, const bNodeTree **r_ntree)
@ GPU_SAMPLER_EXTEND_MODE_MIRRORED_REPEAT
@ GPU_SAMPLER_EXTEND_MODE_REPEAT
@ GPU_SAMPLER_EXTEND_MODE_EXTEND
@ GPU_SAMPLER_EXTEND_MODE_CLAMP_TO_BORDER
@ GPU_SAMPLER_FILTERING_LINEAR
BLI_INLINE void IMB_colormanagement_rec709_to_scene_linear(float scene_linear[3], const float rec709[3])
IMETHOD void random(Vector &a)
addDelta operator for displacement rotational velocity.
Definition frames.inl:1282
VecBase< float, 3 > float3
#define hash
Definition noise_c.cc:154
struct Library * lib
Definition DNA_ID.h:420
char name[258]
Definition DNA_ID.h:432
char alpha_mode
char filepath[1024]
Definition DNA_ID.h:552
float color[4]