Is it possible to create an enum for osl, like how the glass shader offers choices for the formula used to render the glass? I've been doing some research but I have been unable to find any documentation regarding what I am looking for.

  • 3
    $\begingroup$ you can use a string array, or some struct... internally it's common to use Ints... For the UI, there's the metadata option, but it's still not working in blender. Shader Wood(int pattern = 0 [[ string widget = "mapper", string options = "oak:0|elm:1|walnut:2" ]]) $\endgroup$
    – Secrop
    Commented Mar 23, 2017 at 21:01
  • $\begingroup$ I did try that. it allowed text input and did not show the popup I am looking for. $\endgroup$
    – RWolfe
    Commented Mar 25, 2017 at 21:42
  • $\begingroup$ As I said, Metadata is still not working in blender. But this is the correct way to do it in OSL. If you still want this to work, you need to script the node with python, and add that enum in the ui. $\endgroup$
    – Secrop
    Commented Mar 26, 2017 at 13:07

1 Answer 1


While the OSL specification provides a way to specify a list of values that may be presented to the user as a popup menu, blender does not (yet) implement support for this feature.

For now we can use an integer input and branch based on that value. A comment can then be used to list the purpose of each value.

   Mode: 0: option one
         1: option two
         2: option three

shader options(
  int Mode = 0, /* 0: option one 1:option two 2:option three */
  output color Color = 0 )
    if (Mode == 0) {
      // do this
    else if (Mode == 1) {
      // do that
    else {
      // any other value does this


It is also possible to use a string input but that can also allow more bad input values.

shader textoption( string Mode = "One" )

You must log in to answer this question.

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