Announcement

Collapse
No announcement yet.

An assortment of OSL shaders for your perusal

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

  • #31
    @Vlado, is there any way of creating a scripted interface so we can use maxscript to control properties of an OSL map that are generate from the OSL file? The camera map one for instance is a brilliant map but to build it into some camera mapping tools we have I'd need to be able to set the width/height via maxscript. Any thoughts?

    Great stuff Rens! Carry on!
    Maxscript made easy....
    davewortley.wordpress.com
    Follow me here:
    facebook.com/MaxMadeEasy

    If you don't MaxScript, then have a look at my blog and learn how easy and powerful it can be.

    Comment


    • #32
      I wanted to try and make a scripted plugin for the VRayOSLTex so I could build nice interfaces for the camMapScaleTex with buttons to get the aspect automatically etc....but can't do this without some kind of maxscript support.
      Maxscript made easy....
      davewortley.wordpress.com
      Follow me here:
      facebook.com/MaxMadeEasy

      If you don't MaxScript, then have a look at my blog and learn how easy and powerful it can be.

      Comment


      • #33
        Originally posted by vlado View Post
        Unfortunately, no. What are the differences that you find between the Max and Maya implementations?
        OK. I haven't tested it yet in Maya, sharktacos mentioned he had to adjust the code for Max/Maya, I'm guessing it's the difference in how strings get interpreted.
        For example in other programs, the OSL string gets interpreted as a text input, and color as a texture mappable input... which is then not callable with the texture command. It's all a bit confusing.

        Originally posted by Dave_Wortley View Post
        I wanted to try and make a scripted plugin for the VRayOSLTex so I could build nice interfaces for the camMapScaleTex with buttons to get the aspect automatically etc....but can't do this without some kind of maxscript support.
        One thing I can think of that might help of is object user properties, and then a VRayUserColor. This is then per object, but at least you can set the render size pretty easily. I can adjust the shader to accept maps if that would be helpful.
        Rens Heeren
        Generalist
        WEBSITE - IMDB - LINKEDIN - OSL SHADERS

        Comment


        • #34
          And speaking if what's possible with the texture call in OSL instead of just a straight color input. ; )

          UVTransform
          An OSL shader to transform your textures! Tile, rotate, offset, and flip!

          I'll make a variation on this with randomisation options... random transforms per object for example.
          I'll also post a distortion version, but if you can't wait, you can try playing with the replacement UV map, generate using VRaySamplerInfoTex map set to UVW, mix it with a noise, and plug it in.

          Click image for larger version

Name:	uvtransform_rndr.jpg
Views:	1
Size:	61.4 KB
ID:	862254

          Links
          Page:
          http://www.rensheeren.com/blog/osl-uvtransform/
          Download link:
          http://www.rensheeren.com/osl/UVTransform_tex_v002.osl
          Right-click and save.

          Features
          – Offset, rotate, or tile your textures in the shader.
          – You can insert a replacement UV map. For example after you have added distortions to the map.

          How to use
          - Create a VRay OSL Texture map.
          - Load in the downloaded OSL shader.
          – Set the transform values for Offset, Tiling and Rotation.
          – If you want to generate a replacement UV map for adding distortions, you can use a VRaySamplerInfoTex map set to UVW coordinates. You can then mix it with a noise map for example. It will look cool, believe me!

          O = Offset
          T = Tile
          R = Rotate

          Click image for larger version

Name:	uvtransform_node.JPG
Views:	1
Size:	41.0 KB
ID:	862255

          Click image for larger version

Name:	uvtransform_ui.JPG
Views:	1
Size:	36.0 KB
ID:	862256
          Rens Heeren
          Generalist
          WEBSITE - IMDB - LINKEDIN - OSL SHADERS

          Comment


          • #35
            Originally posted by Rens View Post
            I'm guessing it's the difference in how strings get interpreted.
            For example in other programs, the OSL string gets interpreted as a text input, and color as a texture mappable input... which is then not callable with the texture command. It's all a bit confusing.
            Yes. In Maya it would be preferable to have texture maps be read in as color inputs, rather than as strings. This is the default behavior in OSL, and Vray's implementation differs in that it uses string inputs for textures. I believe this has to do with the way Max works. Consequently, stuff like in Ren's OSL code like this:

            Code:
            string n_out_tex = ""         [[ string description = "Texture to use for the outside material IOR." ]],     int use_n_out_tex = 0         [[ string widget = "checkBox",         string description = "Use the texture instead of the value for the outside IOR." ]],
            does not work well in Maya, and stuff in my shaders like this
            (which is a sloppy work-around until we are able to have mappable color inputs)
            Code:
             
             color getTextureDif(string texture_name, color no_texture_default_color) {     int channels = -1;     if (gettextureinfo(texture_name, "channels", channels))     {         return texture(texture_name, u, v);     }       return no_texture_default_color; } 
            color MainColor = getTextureDif(Diffuse_color, color(0.5,0.2,0.2));
            does not work well in Max.

            Really, the best solution I think is to simply have color inputs be mappable.

            It would also be great to have floats be able to be sliders (for example with a OSL "slider" widget). I think this is also a Max/Maya thing. In Max a float is displayed as a number, and in Maya it has a slider. But for Maya with OSL we get numbers for the floats when what we would normally have is a slider.

            Finally, a difference between OSL in Max v. Maya is that Max can have a dropdown menu with choices (like Blinn, Phong, Ward, GGX in the VrayMtl BRDF type), whereas Maya cannot.
            Last edited by sharktacos; 31-05-2016, 08:41 PM.

            Comment


            • #36
              Originally posted by sharktacos View Post
              Yes. In Maya it would be preferable to have texture maps be read in as color inputs, rather than as strings. This is the default behavior in OSL, and Vray's implementation differs in that it uses string inputs for textures. I believe this has to do with the way Max works.
              (...)
              Really, the best solution I think is to simply have color inputs be mappable.
              Ooh now that would be great. I'm not sure how that could be implemented though. Interesting!
              Yes, in max mappable texture inputs and colour swatches are two completely different objects. Color is more of a dead end with no real connection behind it except for the UI swatch. It just supplies the RGB value and you can't connect to it with another node.
              Texture is just an empty placeholder with a map connection slot, no colour swatch to set colour when nothing's connected.

              Now in OSL most of the implementations that I've seen use color to get map data, and sort of ignore texture, except for VRay. Ignoring that is weird because then you can't get to the UVs or alpha channel at all. Unless I'm not getting how it's supposed to be set up.

              What does the string input in maya look like?

              Nice shaders BTW sharktacos!
              Rens Heeren
              Generalist
              WEBSITE - IMDB - LINKEDIN - OSL SHADERS

              Comment


              • #37
                Originally posted by Dave_Wortley View Post
                @Vlado, is there any way of creating a scripted interface so we can use maxscript to control properties of an OSL map that are generate from the OSL file? The camera map one for instance is a brilliant map but to build it into some camera mapping tools we have I'd need to be able to set the width/height via maxscript. Any thoughts?
                One of our interns is working on MaxScript support right now.

                Best regards,
                Vlado
                I only act like I know everything, Rogers.

                Comment


                • #38
                  Originally posted by Rens View Post
                  What does the string input in maya look like?
                  In Maya we just have a color input on a shader that can either stay a color, or can be mapped to a texture. In OSL for Maya that could be

                  string Diffuse_color = "",
                  ...
                  color DiffuseColor = texture (Diffuse_color, u, v, "missingcolor"
                  , color(1,0,0));

                  except that the "missingcolor" widget has not been implemented, so all the color swatches that are mappable strings all turn black. I think if we could specify a default value for the color to be for a string (as it is in the above code), then it would be fine to keep it as a string in both Max & Maya.

                  Comment


                  • #39
                    Nice Shaders !

                    Would be so nice if someone would make them work in Maya.

                    Thanks & Greets

                    Rico

                    Comment


                    • #40
                      I'll have a look. : )
                      Rens Heeren
                      Generalist
                      WEBSITE - IMDB - LINKEDIN - OSL SHADERS

                      Comment


                      • #41
                        fantastic shaders man!
                        Mohammadreza Mohseni

                        Website | Instagram | E-Mail | Art Station | Behance | Twitter | Facebook

                        Comment


                        • #42
                          Originally posted by Dave_Wortley View Post
                          @Vlado, is there any way of creating a scripted interface so we can use maxscript to control properties of an OSL map that are generate from the OSL file? The camera map one for instance is a brilliant map but to build it into some camera mapping tools we have I'd need to be able to set the width/height via maxscript. Any thoughts?

                          Great stuff Rens! Carry on!
                          Actually, VRayOSLTex and VRayOSLMtl are already MaxScript-able. Here is a small MaxScript excerpt that demonstrates how to control the VRayOSLTex map, including getting and setting the properties of the shader. This example uses the CamMapScale shader posted by Rens:

                          Code:
                          -- Find the first VRayOSLTex map
                          map=(getClassInstances VRayOSLTex)[1]
                          [COLOR=#0000FF]Map #1:VRayOSLTex[/COLOR]
                          
                          -- You can inspect the interfaces that are supported by the OSL map
                          showInterfaces map
                          [COLOR=#0000FF]  Interface: IMtlRender_Compability_MtlBase
                             Properties:
                             Methods:
                             Actions:
                            Interface: TweakAccessor
                             Properties:
                              .groupCount : integer : Read
                              .isShaderLoaded : boolean : Read
                             Methods:
                              <fpvalue>getTweak <fpvalue>tweak inGroup:<fpvalue>
                                 inGroup default value: 1
                              <void>setTweak <fpvalue>tweak <fpvalue>value inGroup:<fpvalue>
                                 inGroup default value: 1
                              <integer>tweakCount inGroup:<fpvalue>
                                 inGroup default value: 1
                              <void>load <TSTR>filePath
                              <void>reload()
                              <void>reset()
                              <void>clear()
                              <boolean>export <TSTR>filePath compress:<boolean>
                                 compress default value: true
                             Actions:
                          OK[/COLOR]
                          
                          -- The TweakAccessor interface is the interesting part here, since it provides
                          -- a couple of methods for reading/setting shader parameters, i.e., setTweak and getTweak.
                          -- It also gives you the ability to load a shader, reload the currently loaded one,
                          -- reset its parameters to their default values (that come from the shader file itself)
                          -- or unload an already loaded file.
                          
                          -- Let's load the camera map shader
                          map.load "X:\osl\camMapScale_tex_v001.osl"
                          [COLOR=#0000FF]OK[/COLOR]
                          
                          -- ...and query its second parameter, i.e., "render_width" (parameter indices start from 1)
                          map.getTweak 2
                          [COLOR=#0000FF]1920[/COLOR]
                          
                          -- you can also address parameters by their name
                          map.getTweak "input_tex"
                          [COLOR=#0000FF]undefined[/COLOR] -- hm, there is nothing attached to input_tex
                          
                          -- attach the first found VRayColor to our OSL shader (assuming that you already have a VRayColor instance in the scene)
                          map.setTweak "input_tex" (getClassInstances VRayColor)[1]
                          [COLOR=#0000FF]OK[/COLOR]
                          
                          -- make "image_width" equal to "render_width"
                          map.setTweak "image_width" (map.getTweak "render_width")
                          [COLOR=#0000FF]OK[/COLOR]
                          
                          -- find out the number of shader parameters
                          map.tweakCount()
                          [COLOR=#0000FF]7[/COLOR]
                          
                          -- let's reset the properties to their default values
                          map.reset()
                          [COLOR=#0000FF]OK[/COLOR]
                          
                          -- The OSL map also exposes the properties shown in the "Generall" rollout
                          showProperties map
                          [COLOR=#0000FF]  .shader_file : filename
                            .color_output : integer
                            .color_output_value : string
                            .alpha_output : integer
                            .alpha_output_value : string
                            .max_ray_depth : integer
                            .show_preview : boolean
                            .clamp_shader_result : boolean
                            .clamping_limit : float
                            .wrap_texture_coordinates : boolean
                            .use_quick_shader : boolean
                            .shader_sourcecode : string
                            .message_log : string
                            .groupCount : integer
                            .isShaderLoaded : boolean
                            .UVGen
                          false[/COLOR]
                          
                          -- you can change the shader via "shader_file" property too
                          map.shader_file="X:\osl\checker.osl"
                          [COLOR=#0000FF]"X:\osl\checker.osl"[/COLOR]
                          
                          -- turn off the preview
                          map.show_preview=off
                          [COLOR=#0000FF]false[/COLOR]
                          
                          --
                          Hope this helps in your MaxScript adventures!

                          Comment


                          • #43
                            Ivan, maybe you should put that on the docs page...

                            Best regards,
                            Vlado
                            I only act like I know everything, Rogers.

                            Comment


                            • #44
                              Hi, This OLS thing is a dream come true! OSL has really opend up some amazing things.

                              Question about "The Reflector". Is this to simulate, for example a polished concrete floor and how facing angles are shiny and grazing angles are blurry? ~ If so, I have been wandering how to do that for so long. materials have an IOR and also a fresnel that may be sharp on facing angles and blurry on grazing angles. For all this time Vray didnt do that for us? so odd. I thought that parameter was very important for physically based rendering. Anyway, I'm a small fish and very appreciative of the amazing resources that can be found here. I must say I dont really understand how to use this OSL. Is someone able to make some examples of how and why to use it?

                              Comment


                              • #45
                                Originally posted by stevejjd View Post
                                Question about "The Reflector". Is this to simulate, for example a polished concrete floor and how facing angles are shiny and grazing angles are blurry? ~ If so, I have been wandering how to do that for so long. materials have an IOR and also a fresnel that may be sharp on facing angles and blurry on grazing angles. For all this time Vray didnt do that for us? so odd. I thought that parameter was very important for physically based rendering.
                                You mean when it gets more shiny on grazing angles? An easy way to do that is to create a Falloff map, and adjust the colours for front and side facing value, then plug that into the glossiness slot of a VRayMtl.
                                You can feed that same Falloff map into the glossiness of the reflector OSL map.
                                For this effect, the IOR doesn't change, it's the glossiness/roughness. But very easy to simulate with a falloff map. And no, you have to tell the VrayMtl that as the reflector is a texture map meant to be plugged into the reflection amount of a material (it doesn't control glossiness, it just tells a VRayMtl for example how much and what colour to reflect).

                                The 'rough Fresnel' hack I've added basically makes sure that the reflection doesn't get too strong on grazing angles, this is different from how scattered or rough the reflection is. It's the strength it adjusts, not the blurriness.

                                Hopes that makes sense.

                                Originally posted by stevejjd View Post
                                Is someone able to make some examples of how and why to use it?
                                After uploading some more OSL shaders I'll add some practical examples for each map to make it a bit clearer what they can be used for.
                                Last edited by Rens; 01-06-2016, 08:44 PM.
                                Rens Heeren
                                Generalist
                                WEBSITE - IMDB - LINKEDIN - OSL SHADERS

                                Comment

                                Working...
                                X