Announcement

Collapse
No announcement yet.

OSL Support in VRay Next

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • OSL Support in VRay Next

    Hey all,

    I'm setting up a standard shader for our studio and I have some questions about osl support in VRay Next for Maya (Windows 10).
    - Can I pass a string to texture() and expect it to work? I saw an old forum post (https://groups.google.com/forum/#!to...ev/vb0-1Cbvz7o) saying it wasn't supported but I think I've seen examples of working since then? Not sure.
    - While testing texture(), I've been looking for a log file (where printf() might end up). Where would I find that output? When rendering interactively? When batch rendering?
    - When compiling my shaders, I get a warning (.\oslc.exe .\surfaceShader_v1.osl -> .\surfaceShader_v1.osl:0: warning: Unable to find "stdosl.h"), but it compiles and seems to work just fine. Why that warning? What do I need to do to satisfy it? This is in my file (#include "stdosl.h") and without it, it doesn't compile. It's got me scratching my head.

    Thanks!

    Jake

  • #2
    So, I'm feeling pretty sure that arbitrary texture calls like

    Code:
    color fileColor = texture("C:\path\to\some\file.png",u,v);
    aren't supported yet in VRay Next for Maya. Rats. So I'm stuck with still having to wire up maya "file" nodes. We were hoping to put as much as we could into one node. It looks like this is supported for other VRay products (3DSMax, Modo). Any eta on when this would show up for Maya?

    I'm still not sure where shader output goes. It doesn't seem to go to the script editor in maya, but it's doing something because the renders are unbearably slow when I have printfs running (understandable)...

    Still don't know about my stdosl.h warning.

    And I've got a new one, when I try to access a component of a color like

    Code:
    float r = rgb[0];
    it compiles fine, but crashes maya. :\ I don't even need to try to start a render, something about indexing a color component trips up...maybe the little auto run shader ball? And I'm not seeing another way to get access to the components, maybe a dot with a vector?

    Code:
    float r = dot(rgb,vector(1,0,0));
    Hmmm. I'll report back.

    Jake
    Last edited by jakemostly; 20-05-2019, 04:27 PM. Reason: Making code snippets more readable.

    Comment


    • #3
      Ok. So it's not the component access of a color that's a problem. That's working fine.

      The problem is component access of a color that came from a maya "file" node. I'm guessing that behind the scenes the "color" variable that I think I'm dealing with isn't really a color variable but some other struct and when I try to get at its components I run afoul of the abstraction. The dot product idea above also crashed maya. Any ideas of how I might convert the input to a real color variable?

      I'm trying to build in some hue/sat/val manipulation.

      Jake
      Last edited by jakemostly; 20-05-2019, 04:36 PM. Reason: spelling error

      Comment


      • #4
        Hey, Jake

        First which version of VRay are you using?
        1) If you want to sample a texture in OSL with VRay you should do it like this
        Code:
        shader ExampleShader
        (
            string input_texture = "",
        
            output color Col = 0
        )
        {
            Col = texture(input_texture, u, v);
        }
        2) There is a vraylog.txt in your Temp directory. If you want to use the OSLs printf and such, we don't support that for now.
        3) You can ignore the compilation warning if it really compiles. (The version of VRay that you are using has to do with that.)
        Code:
         
         float r = rgb[0];
        If rgb has a type color, this is the way to access the red component.
        If you can send a sample shader to better describe what you are trying to do, that would be great. And I'll be able to help you a lot more.

        Best regards,
        Kiril Kostov

        Comment


        • #5
          Thank for responding Kiril! I really appreciate it.

          What I'm using:
          Maya 2018, cut 201706261615-f9658c4cfc
          VRay Next for Maya, hotfix 2, v4.04.03.00010

          The shader you provided doesn't work for me (which would seem user error, right?). It compiled, I went into maya, added a fresh VRayMtl and a VRayTexOSL, referenced my oso, and connected the output color to the diffuse color on the VRayMtl. I see the parameters I should see on the VRayTexOSL node.

          On the VRayTexOSL node, without adding the filename widget hint, 'input_texture' is just a color that I can wire up to a 'file' node. But I can't get the VRayTexOSL to return anything other than black, with or without the widget hint, even if I hardcode 'Col' to something like color(1,1,1). That's really weird. But in my case I'm trying to do all of this in one node a VRayMatlOSL, so the VRayTexOSL might be a mystery for another day?

          I'm still seeing the maya crash issue when I access the color component of a 'file' node connection. Here is an example shader that shows what I'm doing.

          Code:
          #include "include/stdosl.h"
          #include "include/oslutil.h"
          
          color RGBtoHSV(color rgb) {
              float r = rgb[0];
              float g = rgb[1];
              float b = rgb[2];
              float mincomp = min (r, min (g, b));
              float maxcomp = max (r, max (g, b));
              float delta = maxcomp - mincomp;  // chroma
              float h, s, v;
          
              // Calculate value
              v = maxcomp;
              s = 0;
              h = 0;
          
              // Calculate saturation
                  if ((delta > 0) && (maxcomp > 0)) {
                  s = delta / maxcomp;
              } else {
                  s = 0;
              }
          
              // Calculate hue
              if ((s <= 0) || (delta <= 0)) {
                  h = 0;
              } else {
                  if      (r >= maxcomp) h =     (g-b) / delta;
                  else if (g >= maxcomp) h = 2 + (b-r) / delta;
                  else                   h = 4 + (r-g) / delta;
          
                  // Normalize to 0-1
                  h /= 6;
          
                  // Wrap it around
                  if (h < 0)
                      h += 1;
              }
          
              return color (h, s, v);
          }
          
          color HSVtoRGB (color c) {
              float h = c[0], s = c[1], v = c[2];
              color r;
              if (s < 0.0001) {
                  r = v;
              } else {
                  h = 6 * (h - floor(h));  // expand to [0..6)
                  int hi = (int)h;
                  float f = h - hi;
                  float p = v * (1-s);
                  float q = v * (1-s*f);
                  float t = v * (1-s*(1-f));
                  if      (hi == 0) r = color (v, t, p);
                  else if (hi == 1) r = color (q, v, p);
                  else if (hi == 2) r = color (p, v, t);
                  else if (hi == 3) r = color (p, q, v);
                  else if (hi == 4) r = color (t, p, v);
                  else              r = color (v, p, q);
              }
              return r;
          }
          
          surface TestSurface
          (
          
              color inputColor = color(1.0, 1.0, 1.0)
                  [[ string help   = "Input color, a starting place",
                     string page   = "Color"]],
          
              // Without this widget hint, I don't get a string input, I get a color that I can connect to a maya "file" node.
              // I can set the color to something and it flows through.  If I connect a file node it flows through.
              // If I add this widget hint (filename) I get black from the texture call, which in turn disables the
              // diffuse closure below if I multiply it with the closure.
              string colorFilename = ""
                  [[ string help   = "Filename for the color pass (RGBA), it layers over Base Color and Base Alpha",
                     string page   = "Maps",
                     string widget = "filename"]],
          
              float hueOffset = 0
                  [[ string help   = "Offset on the current global hue value",
                     string page   = "Color",
                     string label  = "Hue Offset"]],
          
              float satMult = 1
                  [[ string help   = "Multiplier on the current global saturation value",
                     string page   = "Color",
                     string label  = "Sat Mult"]],
          
              float valMult = 1
                  [[ string help   = "Multiplier on the current global value value",
                     string page   = "Color",
                     string label  = "Val Mult"]]
          
          )
          {
          
              // If I don't access the compenents of the color, maya doesn't crash, but the result
              // of this texture call is black.
              color fileColor = texture(colorFilename,u,v,"missingcolor",color(1,1,1));
              color accumColor = fileColor;
          
              // Without this line, ie I let 'fileColor' flow through, maya crashes
              // And it crashes whenever I try to access the components of a color
              accumColor = inputColor;
          
              accumColor = RGBtoHSV(accumColor);
              accumColor[0] += hueOffset;
              accumColor[1] = clamp(accumColor[1]*satMult,0,1);
              accumColor[2] = clamp(accumColor[2]*valMult,0,1);
              accumColor = HSVtoRGB(accumColor);
          
              // If I let fileColor be assigned to accumColor, it's black, though I've provided a string.
              // If accumColor is black the diffuse closure is ignored and my surface becomes transparent
              closure color accumClosure = diffuse(N) * accumColor;
          
              Ci = accumClosure;
          }
          Jake

          Comment


          • #6
            Hello, Jake

            It seems that in VRay Next for Maya, hotfix 2, v4.04.03.00010 there is something wrong with the OSL implementation of texture(), but it is fixed in VRay Next for Maya v4.12.

            I modified the colorFilename like this :
            Code:
            string colorFilename = ""
                [[ string help = "Filename for the color pass (RGBA), it layers over Base Color and Base Alpha",
                   string page = "Maps"]],
            And let the fileColor flow through. Removing the line :
            Code:
             
             accumColor = inputColor;
            And using it in Maya with attached fractal texture to that input I got the result that is the attached scene. Is this the result you desired?
            Please tell me if you have problems with version 4.12 and if you have any other questions!

            Best regards,
            Kiril Kostov

            Comment


            • #7
              Thanks Kiril! Unfortunately upgrading to 4.12 didn't solve either of the issues for me. Even the example with the fractal above didn't work for me. I'm almost out of time trying to get the osl to work, so I'm looking at alternative solutions. I've attached a copy of the stack trace of the crash, in case that might be helpful. I appreciate that you took a look.

              Jake
              Attached Files

              Comment


              • #8
                That is quite strange... if you could share the specifications of your machine and a vraylog.txt. And if you want I'll make an example scene and share it with you ?

                Best regards,
                Kiril Kostov

                Comment

                Working...
                X