Page MenuHome

Cycles: Add custom object properties as usable attributes
Needs RevisionPublic

Authored by Lukas Stockner (lukasstockner97) on Jun 17 2016, 3:35 AM.

Details

Summary

This patch allows the user to type a property name into the Attribute node,
which will then output the value of the property for each individual object,
allowing to customize e.g. customize shaders by object without duplicating the shader.

Both custom properties that are added in the UI as well as Python-based properties
are supported, the type has to be Float, Integer or 3-component Float Array property.

Diff Detail

Repository
rB Blender
Branch
master

Event Timeline

Sergey Sharybin (sergey) requested changes to this revision.Jun 17 2016, 10:00 AM
Sergey Sharybin (sergey) edited edge metadata.

Not real fan of all those "flexibility" nodes which only allows to blindly type in something, without knowing what's right and what's wrong and not having a good visualization of where issue is coming from when debugging shaders (which happens every so often in a team work).

I can leave with that if it's really gets addressed sooner than later, but the patch has two big issues so far:

  • Seems instancing is not working here. Think for such flexibilities it's important to support instances. Solving this for those attributes will likely unify code base with OSL attributes.
  • This lacks support of GLSL. Think it is now important to keep GLSL shading as much supported as possible. I don't think actual GLSL code will be changed too much for this, might need to do some tricks for uniform binding. But that's a really nice project since it'll indicate all weak points in current design and will help us see what the system should move here. That's from coder perspective POV, who nobody cares about actually :) What's most important -- artists should fully get an idea what scene will look like in render looking into GLSL viewport.

Note: not saying you're left alone to deal with GLSL, i can guide you through or just work on this, but it's an important gap to be filled.

intern/cycles/blender/blender_mesh.cpp
657

Not sure why do we handle those differently. For other attributes we iterate them and see if they are needed. Here it could work in the same manner.

665

Please always use parenthesis. Saves diff noise, makes code more more uniform and avoids possible bugs (which do happen just because of parenthesis :S)

667

Debug print?

671

Such errors fully worth reporting to user, meaning fprintf(stderr, ...) is more appropriate here.

Ideally we need to report such things back to interface somehow..

676

Currently ATTR_ELEMENT_OBJECT is only used by OSL and it's creating attributes in a map associated with an object (attribute_map in OSLGlobals). You are creating attribute in a mesh domain which i can't see how will work together with instancing. From quick look seems attribute will be used from a first instanced object.

This revision now requires changes to proceed.Jun 17 2016, 10:00 AM

I think this is a useful feature to have.

Support for boolean properties would be good.

Not real fan of all those "flexibility" nodes which only allows to blindly type in something, without knowing what's right and what's wrong and not having a good visualization of where issue is coming from when debugging shaders (which happens every so often in a team work).

Personally I like it to just have a text field to enter your custom Attribute. If the shader doesn't react to it, it either means you have a typo-error, or the attribute doesn't exist on that object. Pretty easy to track down.
On the other hand if you generate a dropdown list with attributes that are available on all objects that are connected to that material, you have to refresh that list all the time and that might be prone to errors.
Just my 2cent

Hey, where are we on this?

My use case for this feature: a scene where the material is roughly the same everywhere except there is a lot of variations in one attribute, say the color. Think of LEGOs for instance.
Similar question: https://blender.stackexchange.com/questions/55989/how-can-i-give-an-array-of-objects-a-variety-of-colors

I'd have a look at the patch to take sergey's remarks into account only if this patch still makes sense in the current architecture. I'm asking since the patch is now 2 years old.