I'm populating spheres off of a csv file and in theory adding a hex color as the base color from the same spreadsheet. While I've looked at other questions that make it clear that a RGB-> hex is problematic due to color management and gamma, that isn't my current problem.

I'm using the Principled BSDF shader and getting an emissive material by default when my emission is set to 0 and I'm using a dielectric material... Any help is appreciated.enter image description here

import bpy, csv 

def hex_to_rgb( hex_value ): 
    rgb = list(tuple(int(h[i:i+2], 16) for i in (0, 2, 4)))
    r = rgb.pop(0)
    g = rgb.pop(1)
    b = rgb.pop()
    return r, g, b

def add_material(obj, material_name, h):
    material = bpy.data.materials.get(material_name)

if material is None:
    material = bpy.data.materials.new(material_name)

material.use_nodes = True
principled_bsdf = material.node_tree.nodes.get('Principled BSDF')

if principled_bsdf is not None:
    principled_bsdf.inputs[0].default_value = (*hex_to_rgb(h), 1) #RGBA  
    principled_bsdf.inputs[4].default_value = (0) #metallic =1 dielectric=0 
    principled_bsdf.inputs[7].default_value = (0) #roughness
    principled_bsdf.inputs[17].default_value = (0,0,0,0) #emission  

obj.active_material = material

path = "//points_hex.csv" #opens hex color spreadsheet

with open(path) as csvfile:
    content = csv.reader(csvfile, delimiter=',', dialect='excel')
    hexcolors = [] 
    names =()
    for i, row in enumerate(content) :
        if i == 0: continue #skip header
        id = row[0] 
        x,y,z = row [1], row[2], row[3]
        group = row [4]
        h = row [5] 
        bpy.ops.mesh.primitive_uv_sphere_add(radius = 0.5, location = (float(x), float(y) ,float(z)))
        bpy.context.active_object.name = id
        obj = bpy.context.object
        newmaterialname = (str(h)+ "_G" + str(i)) 
        print (newmaterialname)
        add_material(obj, newmaterialname ,h) 

1 Answer 1


The RGBA values have to be normalized to a $\left[0,1\right]$ range. The shaders will produce strange results when input values exceed the intended range, such as the glow effect you're seeing.


You must log in to answer this question.

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