Access Shader Parameters

From Odwiki

Jump to: navigation, search

Contents

Access Shader Parameters

When working with HDK in Houdini 8.2 you might want to be able to retrieve the information that a shader stores. This tutorial will show you how you can access that certain information from the vm_surface (Parms in the Shader network).

vm_surface

When normally working in Houdini and adding a SHOP to the object, you will get the following primitive attributes:

shop_mi_material[1]
ogl_shop[1]
shop_ri_surface[1]
shop_vm_surface[1]


When looking in the 'shop_vm_surface' attrivbute you will probably get a string with something like:

obj/model/shopnet1/v_layered1

Which you cant do much with. Atleast when it comes to access the parameters from the vm_surface.

Setup Houdini

First you need to a minor change in Houdini to get the "right" kind of surface you need to get the parameters.

  1. LMB on the Shop where you declare the shader information.
  2. At the top left corner you will have a "use indirect references" option.
  3. Uncheck the option "use indirect references".

Now looking in the information in Houdini, you will have a 'vm_surface' attribute. This is the attribute we are gonna use.


Using HDK to access the attribute

Now when we know what attribute we need to use, we need to actually get the attribute pointer from the HDK.

// Get the Attribute
GB_AttributeHandle Attribute = GuDetail.getAttribute(GEO_PRIMITIVE_DICT, "vm_surface");
// Get the string with all the parameters UT_String ShaderString;
// Get the string from the Attribute, this string will have all the parameters as a single long UT_String Attribute.getString(ShaderString);


So now we have the String with all the parameters. The UT_String will have ALL parameters available in one single string. So now we have the data, but now we need to seperate (or split) the whole string into single strings or tokens.
There are lots of different ways to split a string in C++. As far as I know the HDK doesn't have any function to do this. Below is my way of splitting the above string into useable tokens.

// "Steal" the string, so we have it as a char instead of a UT_String
char *pStolenCharString = ShaderString.steal();
// Create a temp char char *pStrTokChar;
// This shows the function to split when it finds a blankspace (" ") pStrTokChar = strtok(pStolenCharString," ");
while(pStrTokChar != NULL) { // Here we get out the current string from the main string, or a "token" pStrTokChar = strtok(NULL, " "); }

The strok function above breaks when it finds a blankspace (" ") and then you can take that string and do whatever you want with it. The function parses numerical values as a char aswell. So if you have a numerical value you need to use another function to change it from char to int, float etc.

References

strtok() function information on cplusplus.com

© 2009 od[force].net | advertise