1
$\begingroup$

The following video shows how to 'drive' an object's viewport display color by its base color. https://www.dropbox.com/scl/fi/ucdvh12ak1trpcipbmbcp/2024-04-22_06-56-25.mp4?rlkey=a3kseg8n8722rd7nmgzga99dy&dl=0

Is there a way, however, to 'drive' an object's viewport display color by the result color from a 'Combine Color' node, for example? Basically want to average all the colors of a texture, and apply that color to the object's viewport display color.

... but still have the texture viewable in 'Rendered' or 'Material Preview' mode.

$\endgroup$
3
  • $\begingroup$ Hi Ryan, i am not sure, but it looks like that you didn't understand the vector input node of the image texture node. The input is not (!) a color, but a UV coordinate. This UV coordinate will be used to determine the color of the output, which is the color of the image at that UV coordinate. So you don't get the color of a combine color node by your node setup. You have to plugin the combine color directly in the color input of your principled bsdf node for that behaviour. $\endgroup$
    – Chris
    Commented Apr 22 at 12:58
  • $\begingroup$ ...and one more thing: you asked already some questions here as you can see: [1]: i.sstatic.net/LHRjxIdr.png. As you notice there is nothing green there, green means: you clicked on the checkmark left of an answer to 1) reward the one who answers for his effort and 2) tell everybody else that the answer is useful. So please be a good citizen and click on that checkmark for all answers which helped you and which also shows that you aren't totally unthankful. thx. $\endgroup$
    – Chris
    Commented Apr 22 at 13:01
  • $\begingroup$ will do. A lot of those questions did not have answers per se but I usually up vote comments, etc. I will look back just to make sure. $\endgroup$ Commented Apr 22 at 14:06

1 Answer 1

1
$\begingroup$

The information is unfortunately not available because it is computed at runtime and delivered straight to the GPU.

When you manually input a rgb color in the color field (or a float value in a float field, ...), you set up the "default value" of the field, which is statically available from the API and which you can use to setup a driver.

When you draw a link from socket to socket, you tell the field to ditch the default value and wait for the previous node to be evaluated to compute its own value.

However you can setup a simple script to read the values of the pixels of an image and tweak a material viewport color.

Reference : https://blender.stackexchange.com/a/214510/86891

import bpy
import numpy as np


img = bpy.data.images["Image.png"]  # Case sensitive
x, y = img.size
pixels = np.empty(x * y << 2, dtype=np.float32)
img.pixels.foreach_get(pixels)
mean_color_rgb = np.mean(pixels.reshape((x, y, 4))[:, :, :3], axis=(0, 1))  # Don't average alpha value

mat = bpy.data.materials["Material"]  # Case sensitive
mat.diffuse_color = list(mean_color_rgb) + [1]  # Add alpha value to the mean
$\endgroup$
4
  • $\begingroup$ Thanks @Gorgious! Can this script be made into a shader node? Or would you have to run this externally, for every material definition? $\endgroup$ Commented Apr 22 at 14:56
  • 1
    $\begingroup$ @RyanSchultz This can't be made into a shader node, because only OSL is supported (you would also lose supported for GPU) and the shader doesn't have any links nor can it change the values of properties outside of its scope. and for performance reasons you don't want it to run continually so I think making it into its own script and adding it to a button in the interface or a handy add-on would make sense. $\endgroup$
    – Gorgious
    Commented Apr 22 at 15:33
  • $\begingroup$ Okay, good to know! For what it's worth, as you probably saw on the OSarch forum, stefanm2 suggested the following plugin, but doesn't seem to work with 4.1: blendernation.com/2020/03/06/… $\endgroup$ Commented Apr 22 at 16:31
  • $\begingroup$ for those following, @Gorgious provided further insight here: community.osarch.org/discussion/comment/20276/#Comment_20276 $\endgroup$ Commented Apr 24 at 16:54

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .