Does RSL support #define?

Alex
2007-05-13
2013-04-25
  • Alex

    Alex - 2007-05-13

    I am just wondering the answer to this simple question.

    Also -- does RSL support an integer type? IIRC the spec only mentions float for all numbers, but I think integers would be useful. Either that or enum's.

     
    • Okan Arikan

      Okan Arikan - 2007-05-13

          Hi Alex,

          The Pixie sdrc supports C/C++ preprocessor features (#define, #ifdef etc.).

          sdrc does not support integer type.

          This was a deliberate choice made in the design of the RenderMan shading language. Can you tell us a little bit about why you're interested in this feature?

          Okan

       
    • Alex

      Alex - 2007-05-13

      Hi Okan, thanks for the quick response.

      The reason I would like an enum type, is because, let's say I have a light shader.

      The light has a decay type. One of { NONE, INVERSE, INVERSE_SQUARE }. I would like to be able to model this in RSL. I have resorted to using the float type to represent this, and #define macros for the numbers. I am concerned that due to floating-point approximation I could easily miss a code path.

      I would prefer to have something like C:

      enum DECAY_TYPE { DECAY_NONE, DECAY_INVERSE, DECAY_INVSQR };

      enum DECAY_TYPE decay;

      switch (decay) {
      case DECAY_NONE: // do something
      break;
      case DECAY_INVERSE: // do something else

      ...

      // etc.
      }

      While an enum would be ideal, an integer type would be usable too, with #defines.

       
      • Okan Arikan

        Okan Arikan - 2007-05-13

           Hi Alex,

           This is a good point. Don't worry about the performance or rounding issues for this particular use (i.e., selecting between different light source types). The sdrc and rndr will do the right thing here.

           However, this doesn't mean that there may be inherent problems in mixing integer comparisons to float arithmetic. In general, the shader writer needs to be aware of the inherent all-float operations going on under the hood (which I know is not a very good answer).

           Okan

         
        • Natacha

          Natacha - 2007-05-13

          How about something like:

          ///////////////////////////////////////////////

          #define DECAY_NONE 0.0
          #define DECAY_INVERSE 1.0
          #define DECAY_INVSQR 2.0

          // assignement stuff

          decay = DECAY_WHATEVER + 0.5;

          // comparison stuff

          if (decay > DECAY_INVSQR) { /*code*/ }
          else if (decay > DECAY_INVERSE) { /*code*/ }
          else if (decau > DECAY_NONE) { /*code*/ }

          ////////////////////////////////////////////////

          I think it gives the proper result, even if there is floating-point errors (unless you have so many #defines that you fill all the significant bits, but that's quite a lot of line to type anyway). I don't really know what kind of overhead is associated with that, but I always thought switch () was linear, hence equivalent to a series of "else if" (except for that "fall through" thingy). So the only difference with an integer switch () solution would be the slower comparison of floats compared to integer, but I don't think that kind of difference is ever the bottleneck.

          Have I missed something here ?

          Natacha

           

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks