Drive the viewport display color
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 viewport display color.
... but still have the texture viewable in 'Rendered' or 'Material Preview' mode.
Comments
Hi, I've found that add-on.
https://www.blendernation.com/2020/03/06/free-addon-to-set-viewport-color-based-on-nodetree/
cool!... will give it a spin.
hmm... doesn't seem to work on my side (blender 4.1). It just sets the viewport display color to white.
:-( sry
@Gorgious provided some insight as well, here: https://blender.stackexchange.com/a/316981/97239
any errors?
Hey I'll expand a bit on my BSE answer and try and answer the concerns here.
What the addon does if I understood correctly is aggregate the default values of the color input of all the principled bsdfs of each material, and then set the viewport color accordingly. It does not work if you plug in a noodle coming from a texture node in the color input of the principled bsdf, so it will never work if you're using a PBR based workflow. The reason is because plugging in the noodle tells the node to ditch the default value and wait for the previous node to evaluate its output. For technical and optimization reasons this information is not available to the API. You can see the noodles as a pipeline, and you can only tweak the leftmost "default" values and you can only access the rightmost output from the material, and even then only if you bake the result to a texture. The Blender version won't change this fact, sorry.
The information is not statically available. You need to actively analyse the data from the texture map if you want to achieve your goal. I think the simplest way is as described in my answer, read the pixel colors and average them. This could be turned into an addon but I advise against running this script continuously, even if
foreach_get
is extremely fast, the information is not bound to change until the texture map itself changes so a button seems more reasonable.Cheers
Thanks @Gorgious !
Let's say you have a texture that is predominantly a red color, and you use a blue color in a 'color ramp' node.
Is there a clever way to set the viewport display color as the resultant purple color? It would seem not, from your explanation above, but wanted to ask just in case.
I guess i should say something like a 'mix node', not a 'color ramp'--same concept though.
Something like the following example. Possible to get the average color at .5 factor, for example?
...
Everything is possible in Blender :) The only problem is how to tackle the issue. For very specific scenarii you'll need to write specific scripts. I omitted try/except and if/else clauses so this will throw error on other materials.
While I was writing this I noticed that the material icon in the material list updated when you changed the factor. There might be a way to tap into the material icon system to get the icon color. I unfortunately don't know much about it but that's a lead. I think the icons are dynamically re-rendered at very low resolution every time you change the material.
Yeah, that would be less than ideal, as the shader node setup changes a lot, from one material definition to the next.
That would be awesome.
For what it's worth. :)
https://devtalk.blender.org/t/access-the-overall-average-color-from-the-material-icon/34353
Whoops, i got reprimanded by the development coordinator. Guess it wasn't a 'developer-enough' question. :)
let's try again. :)
https://blender.stackexchange.com/questions/317164/programmatically-access-the-overall-average-rgb-color-from-the-material-icon
Hehe, people can be a bit blunt, don't get discouraged. :)