I'm using a Python script to generate a star-field using data from ~9k of the brightest stars (data is taken from here) Spheres are generated equidistant from the camera (eventually these will be filled circle billboards), and I'm hoping to adjust their magnitudes using an emission shader.
Is there a way to adjust the emission strength of each individual sphere without creating 9000+ separate textures?
My first run at the code was able to change the emission strength of the material, but it's changing it for all of the spheres each time. The code is below:
...
# Load star data from file
starData = np.loadtxt('/stars/catalog_text')
distanceMultiplier = 1000 * 5
# Create base stare
star1 = Star(starData[0])
starMesh = star1.getMesh()
# Duplicate mesh for every star in the data
i = 0
for star in starData:
i += 1
# Set Location variables from data
magnitude = star[2]
x = star[3] * distanceMultiplier
y = star[4] * distanceMultiplier
z = star[5] * distanceMultiplier
# Set star magnitude from data
# (convertMagnitude maps the magnitude value to an emission strength value in Blender)
emission = bpy.context.active_object.active_material.node_tree.nodes.get("Emission")
emission.inputs[1].default_value = convertMagnitude(magnitude)
# Create a copy of our base star
newOb = starMesh.copy()
# Assign unique name and location to mesh
newOb.name = "star_" + str(i)
newOb.location = (x, y, z)
# Link mesh to the scene
bpy.context.scene.objects.link(newOb)
bpy.context.scene.update()