Forums
You are not logged in.
#1 2012-06-16 10:11:01
- Atom
- Member
- Registered: 2009-06-17
- Posts: 42
Detect Attribute In Shader?
Hi All,
I am wondering if there is a way to detect if an attribute exists in the RIB from the shader level?
Code:
//Expect an attribute.
string name;
if(attribute("identifier:name", name) == 1)What if the attribute is missing at the RIB level.
Do I need some other check in my shader to detect if an attribute exists before I operate upon it?
Atom
Blender 2.6.3
Windows XP64 3Gb
3Delight 9.0
Matt Ebb's 3Delight Exporter 0.76
Offline
#2 2012-06-16 13:10:51
Re: Detect Attribute In Shader?
Hi Atom
It's all in the manual:
Float attribute ( string dataname; output type variable )
Returns the value of the data that is part of the primitive's attribute state. The operation succeeds if dataname is known and the type is correct, in which case 1.0 is returned. Otherwise, 0.0 is returned and variable is unchanged.
Example:
Code:
string name = "";
float doesMyAttributeExist = attribute( "identifier:name", name );
if (doesMyAttributeExist == 0)
printf("please give me a name");Offline
#3 2012-06-18 06:42:29
- olivier
- 3Delight Developer
- Registered: 2007-01-09
- Posts: 1930
Re: Detect Attribute In Shader?
While that is good advice for user attributes, getting "identifier:name" will always succeed because it is a known built-in attribute even if it was not set. You'll have to check to be sure but I believe objects where this hasn't been explicitly set will return the string "<unnamed>".
Offline

