Announcement

Collapse
No announcement yet.

VRay Maya OSL Texture UV Global variable problem

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

  • VRay Maya OSL Texture UV Global variable problem


    Hello, I wanted to learn how to write OSL Code for VRay in Maya. My goal was to write code rather than having to put together tons of nodes in maya just to do simple mathematical vector operations for example. The graph gets way too messy very quickly and not even speaking about accidentally hitting the wrong button or adding a node and suddenly the whole graph gets messed up.
    So I wanna use OSL to define texture and numerical inputs, do stuff with them through code and then output a color. So I'm using the OSL-Texture node for that. Then I wanna use that output in a standard VRay-Material for example. (I don't wanna use an OSL Material, I just wanna modify a texture and use it in the standard materials.)

    Now to my actual problem, I'm basically still stuck at square one regarding textures, because the "u" and "v" global variables seem to be not accessible. I've tried to simply just output the uvs by having my output = color(u, v, 0); yet it still only shows black. In the Open Shading Language specifications it says that "float u" and "float v" should be global variables that are "The 2D parametric coordinates of P (on the particular geometric primitive you are shading)."
    I was trying to go around this, by defining a vector input and plugging in the uvOut from a placement-node in x and y and I also tried plugging the samplerinfo uvCoords in there, but it always just shows black.
    My Test mesh does have a UV-Layout called map1.

    For anyone to recreate, here is the simplest osl-code involving uvs that is already not working for me. I would expect this to be a red-green uv gradient, but instead it shows black. Use it in a Vray OSL-Texture node and plug it into the Diffuse or Self-Illumination Color of a VRay Standard Material:
    Code:
    shader uvTest (
    output color result = color(0.5)
    )
    {
    result = color(u, v, 0);
    }
    So I'm wondering if I could be just doing something wrong or if there is something not right in OSL in the versions of maya or vray I'm using.

    Maya version is 2018.7
    V-Ray 5 for Maya, update 1.2
    (v5.10.22 from Sep 29 2021)

    Thank you for any help.


  • #2
    Hello! Can you attach the scene? Your shader is correct and you definitely do not need any additional inputs to feed it with UVs, these are accessible via the "u" and "v" variables as you already noticed. The only reason for the black result I can think of is wrong or missing UV mapping. Does it work with a simple plane? Another test would be assigning an OSL material to the geometry and feeding it with the following shader:
    Code:
    shader uvTest()
    {
        color result =color(u,v,0);
        Ci= result *diffuse(N);
    }
    Best regards,
    Ivan
    Last edited by ikomitov; 23-11-2021, 11:29 AM.

    Comment


    • #3
      Hello, thanks for the suggestion. I was trying to prepare a new scene with a plane and my OSL Texture setup to send to you and who would've guessed, it actually works now! I can see the UV-gradient being rendered.
      So I think that narrows it down to the specific scene that I was using and something preventing it from working in there. Unfortunately I can not send that scene itself, because it is confidential. But at least I know now that it definitely can work in these versions of Maya and VRay. I will dabble a bit more with the scene and maybe get it slimmed down to send here or narrowing down the problem itself during cleanup.

      Best,
      Johannes

      Comment


      • #4
        Ok, I found the issue. For whatever reason I had animcurves connected to the hidden attributes of the VRayOSLTex. So especially the uCoord and the vCoord attributes were overwritten by a keyed value. After deleting the curves it worked.
        I can only explain it that at some point I must've hit "s" accidentally while having the node selected, but it only keyed hidden attributes so I didn't notice visually.

        Thank you for the help.

        Comment


        • #5
          Hi, that's good news. Thanks for sharing the reason, I'm including it in my troubleshooting list

          Best regards,
          Ivan

          Comment

          Working...
          X