Announcement

Collapse
No announcement yet.

how to read custom attributes in OSL?

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

  • how to read custom attributes in OSL?

    hi,
    I have some user attributes that I can access via VRayUserScalar node. I'm trying to get access to them in my custom OSL shader.
    A desperate attempt to connect VrayUserScalar nodes to inputs of VRayTexOSL didn't work and they are not available in the global scope in the shader. What is the trick to read them?

  • #2
    It seems that the only way to access them is to declare a color texture input in your shader.

    See this example shader http://docs.chaosgroup.com/display/V...le:CarbonFiber

    1. Name the input myScalar, for example.
    2. Load the shader in the VRayOSLTex.
    3. Make sure that myScalar is available as input in the AttributeEditor.
    4. Connect the outAlpha of attribute of the VRayUserScalar texture to the R,G,B components of the vray_myScalar attribute in the OSL texture.
    5. Then in the shader you can use the "texture" function to lookup the value of the texture either as float or color.

    Hope it helps.
    If you have more questions don't hesitate to ask them.
    V-Ray developer

    Comment


    • #3
      Originally posted by t.petrov View Post
      It seems that the only way to access them is to declare a color texture input in your shader.

      See this example shader http://docs.chaosgroup.com/display/V...le:CarbonFiber

      1. Name the input myScalar, for example.
      2. Load the shader in the VRayOSLTex.
      3. Make sure that myScalar is available as input in the AttributeEditor.
      4. Connect the outAlpha of attribute of the VRayUserScalar texture to the R,G,B components of the vray_myScalar attribute in the OSL texture.
      5. Then in the shader you can use the "texture" function to lookup the value of the texture either as float or color.

      Hope it helps.
      If you have more questions don't hesitate to ask them.
      thank you mate.
      I tried that before asking the question here. It seems that the custom inputs of VRayOSLTex node (as declared by an OSL shader) are evaluated once and the value is passed to the shader only once. From my tests is looks like the connection to other nodes is not retained.
      As a super basic test I made an OSL shader with one colour input that is directly passed to its output. Then I attached maya checker to it and it renders grey. So the value of the texture is not evaluated per pixel and is not passes through the shader. I assumed this is the limitation of the node but maybe I'm wrong.
      I also tried connecting VrayUserScalar to another simple test shader to render passed user scalars as simple ramps for debugging. No luck there either. I get one constant value over the entire surface.
      Basically any input to VRayOSLTex has constant value over the entire shaded area.

      Pawel

      btw: maya 2015 with most recent vray 3 on windows.

      Comment


      • #4
        Code:
        shader simple_color_tex
        (
        	string input_tex = "input_tex",
        	output color result = color(0.0, 0.0, 0.0),
        	output float alpha = 1.0
        )
        {
        	result = texture(input_tex, u, v);
        	alpha = 1.0;
        }
        This simple shader works for me.
        I can connect a checker to it and it will render as expected.
        V-Ray developer

        Comment


        • #5
          thank you. I had no idea I had to evaluate texture inputs with 'texture' statements. I assumed that was handled outside of the shader and the value was just provided. This way is much better giving me full control. cheers mate. appreciate your help!

          Comment

          Working...
          X