Announcement

Collapse
No announcement yet.

An assortment of OSL shaders for your perusal

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

  • #76
    Originally posted by Rens View Post
    Are there any shaders that anyone would like to see?

    A procedural texture (or a few) that emulated the weave of various types of fabric would be useful. The clothTex is nice, but only matches a certain type of fabric weave.

    Comment


    • #77
      Originally posted by Rens View Post
      I had a chance to test the OSL maps in Maya, and other than a doubling of the inputs (one color, one texture) it appears to be working fine!
      True

      One thing that seemed to be missing was the string widget, as in an actual text field, this was a colour input in the UI.
      Yes, as far as I know that concept does not exist in Maya.


      remapValue allows you to adjust the input colour using a curve or gradient, yes? I'll write one where you can input one gradient ramp to drive another, because OSL does not allow for UI curves or keys.
      FWIW, in Maya I usually end up using the blendColors node. This does more what I'm after, and has a cleaner interface than the remapValue node.


      Other than to match it with existing BxDFs, not much.
      Yeah, I have that much of the DisneyBRDF working in OSL currently, but I'm not sure how useful it is. I'd be happy to share it if anyone is interested.

      Comment


      • #78
        Shark,

        What is "clothTex"?


        The clothTex is nice, but only matches a certain type of fabric weave.

        Comment


        • #79
          Originally posted by DaveKW;69723b1
          I'm not sure I follow the reason for the rough fresnel. Couldn't you just increase the ior and decrease the reflection amount, or is it a case of this does it in fewer clicks and/or it's more physically accurate?
          Yes, If you increase the IOR and decrease the reflection amount you'll get roughly the same, and yes it's less eyeballing with the shader and you can have varying roughness as well. Plus it calculates the front reflection colour for you.
          If you want to set up what I did in the shader yourself you can get a reflection map like Falloff set to Fresnel (or the reflector shader hehe) and place that into the second/white input of a Mix node. Place a VRayColor into the first/black input and set the colour to what you think the front reflection amount will be, roughly. So say RGB 0.04 for a plastic. Now have the glossiness input drive the mix amount. I tweaked the glossiness input a bit in my shader so it's not linear, but this is roughly the same setup. In the end it's just a colour blend and not a full per-sample calculation, but it seems to do the trick nicely so far. : )

          To explain it a bit more, basically what rough Frensel does is it evens out the reflection amount (the % of light reflected) so that is is less angle dependent. So in most shaders, if you set the IOR and enable Frensel reflections you will have stronger reflections near the grazing angles or side edges of the object, like as in the edges of the sphere example I posted. The front facing reflections will be much lower.
          Rough Fresnel evens this out, as when the surface is rougher, the angles get mixed and blended because of all the scratches and bumps on rough surfaces. Basically with a rougher surface you will look at a lot of front facing surfaces mixed into the side facing surfaces and the other way around, because of the micro-detail valleys and mountains (scratches). Summed up with a fully rough surface, this comes down to a close to uniform reflection amount for all angles that is close to the original front facing reflection amount, it gets evened out over all angles, side and front.

          In this shader this means I have blended the Fresnel falloff curve (front low, side high) with a single colour that is close to the Fresnel front (low) reflection amount. Or to put it in numbers, when your object reflection is 4% in the front and 100% at the sides, rough Fresnel will blend this to be say 5% in the front and 5% at the sides for a fully rough surface.


          Originally posted by Laserschwert View Post
          I don't know if this is possible, I wish there was a shader that makes single sided geometry appear to have actual thickness... kinda like a shader-based Shell modifier. It doesn't have to be so big as to change the object's silhouette, just a one-pixel edge that catches the light.
          That would be tricky. I had a quick look but you're pretty limited in OSL when it comes to looking up geometry. A shader similar to the VRayEdgesTex might be able to do that.


          Originally posted by Art48 View Post
          I remember one time I saw something floating around here which emulates building interios. Imagine you have a high-rise building with thousands of offices behind glass windows. Somewhere I found some sort of shader or sth which generates perspectively correct simplified interiors/rooms behind those glass panels. I can't find it at the moment, but do you know what I mean?
          Yes, I've added some features and hope to finish this version in the coming week. Here's the WIP if you're interested:
          http://www.rensheeren.com/osl/intmaptemp.zip

          And this is the thread you mentioned, I think:
          http://forums.chaosgroup.com/showthr...terior+mapping


          Originally posted by Ihno View Post


          And whats about a Curvature with 3 input Textures Flat,Concave,Convex?

          You should sell your shaders, or at least add a donate button to your Page.
          I'd be happy to pay a little for them
          Probably not doable in OSL but I'll have a look. I won't be selling these shaders, but I'll consider a donate button. : )
          I started on a blur shader, but it might be very slow, let's see!


          Originally posted by Moriah View Post
          Can you do a decent Color Correction node via OSL? Also +1 for blur node...
          Yes I've done a CC shader, I'll upload it sometime next week hopefully.


          Originally posted by Art48 View Post
          Actually I think I may want something even more important: Texture Bombing!
          Sounds interesting! Should be doable, yes.


          Originally posted by sharktacos View Post
          A procedural texture (or a few) that emulated the weave of various types of fabric would be useful. The clothTex is nice, but only matches a certain type of fabric weave.
          That's a tricky one but would be fun to figure out how to do that. : )

          If you want to share what you have on the Disney shader I'd be interested in having a look!
          Rens Heeren
          Generalist
          WEBSITE - IMDB - LINKEDIN - OSL SHADERS

          Comment


          • #80
            Originally posted by sharktacos View Post
            A procedural texture (or a few) that emulated the weave of various types of fabric would be useful. The clothTex is nice, but only matches a certain type of fabric weave.
            Could you link said clothTex?
            Software:
            Windows 7 Ultimate x64 SP1
            3ds Max 2016 SP4
            V-Ray Adv 3.60.04


            Hardware:
            Intel Core i7-4930K @ 3.40 GHz
            NVIDIA GeForce GTX 780 (4096MB RAM)
            64GB RAM


            DxDiag

            Comment


            • #81
              What is "clothTex"?
              Sorry that might be a Maya thing. Don't know Max. At any rate, Vray has a plugin for it, so it should work in Max too. Just load it under the vray texture plugins.

              Comment


              • #82
                Here's the DisneyBRDF (minus the BRDF part I guess). I may try to get this working in GLSL instead since you can do BRDFs there...

                This works in Maya. I think Max might freakout about the getTextureDif routine, if so you can just swap that out with a result texture call.

                Code:
                /* artist friendly metal */
                float n_min( float r )
                { return (1-r )/(1+ r ); }
                
                
                float n_max( float r )
                { return (1+ sqrt ( r ))/(1- sqrt ( r )); }
                
                float get_n ( float r , float g)
                { return n_min( r )*g + (1-g)*n_max( r ); }
                
                
                float get_k2 ( float r , float n)
                { 
                float nr = (n+1)*(n+1)*r-(n-1)*(n-1);
                return nr/(1-r );
                }
                
                float get_r ( float n, float k)
                { return ((n-1)*(n-1)+k*k )/(( n+1)*(n+1)+k*k);  }
                
                float get_g ( float n, float k)
                {
                float r = get_r (n,k);
                return (n_max( r)-n )/( n_max( r)-n_min( r ));
                }
                
                float AFMF ( float r , float g, float theta )
                {
                float _r = clamp(r ,0 ,0.99);
                
                float n = get_n (_r ,g);
                float k2 = get_k2 (_r ,n);
                float c = cos ( theta );
                float rs_num = n*n + k2 - 2*n*c + c*c;
                float rs_den = n*n + k2 + 2*n*c + c*c;
                float rs = rs_num/ rs_den ;
                float rp_num = (n*n + k2)*c*c - 2*n*c + 1;
                float rp_den = (n*n + k2)*c*c + 2*n*c + 1;
                float rp = rp_num/ rp_den ;
                
                return 0.5*( rs+rp );
                }
                
                
                
                //////
                
                
                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;
                }
                
                float fresnelReflectionFactor(normal bumped_normal, float ior)
                {
                    float c = abs(dot(I, bumped_normal));
                    float g = ior * ior - 1.0 + c * c;
                    if (g > 0.0) {
                        g = sqrt (g);
                        float A = (g - c) / (g + c);
                        float B = (c * (g + c) - 1.0) / (c * (g - c) + 1.0);
                        return 0.5 * A * A * (1.0 + B * B);
                    }
                 
                    return 1.0;
                }
                
                // Schlick simplified Fresnel function, non-metal/non-metal, no polarisation.
                float SchlickFresnel(normal bumped_normal, float ior)
                {
                    float c = abs(dot(-I, bumped_normal));
                    float g = (1 - ior) / (1 + ior);
                    g = g * g;
                    return g + (1 - g) * pow((1 - c), 5);
                    
                }
                
                
                
                surface
                DisneyBRDFMtl
                [[ string description = "Disney Principled BRDF Material" ]]
                (
                
                    string  Base_Color = "color.png",
                    
                        float  Metallic_Amount = 0
                    [[ string description = 
                        "the metallic-ness (0 = dielectric,  1 = metallic).  This is a linear blend between two
                        different models.  The metallic model has no diffuse component and also has a tinted incident
                        specular, equal to the base color."
                    ]],
                    
                    float  Specular_Amount = 0.5
                    [[ string description = 
                        "incident specular amount.  This is in lieu of an explicit index-of-refraction. 
                        normalizes ior 1.0-1.8"
                    ]],
                    
                    float  Specular_Tint = 0
                    [[ string description = 
                        "a concession for artistic control that tints incident specular towards the base color.
                        Grazing specular is still achromatic."
                    ]],
                    
                    float  Roughness = 0.5
                    [[ string description = 
                        "surface roughness, controls both diffuse and specular response. 
                           R = roughness^2 for diffuse & (0.5 + roughness/2)^2 for spec"
                    ]],
                    
                    float  Anisotropic = 0
                    [[ string description = 
                        "degree of anisotropy.  This controls the aspect ratio of the specular highlight.  
                        (0 = isotropic, 1 = maximally anisotropic)."
                    ]],
                    
                    float  Anisotropic_Rotation = 0.5,
                    
                    float  Sheen = 0
                    [[ string description = 
                        "an additional grazing component, primarily intended for cloth."
                    ]],
                    
                    float  Sheen_Tint = 0.5
                    [[ string description = 
                        "amount to tint sheen towards base color."
                    ]],
                    
                    float  Clearcoat = 0
                    [[ string description = 
                        "a second, special-purpose specular lobe. always isotropic and non-metallic.  
                          fixed ior=1.5. Fixed roughness=0.25. Fixed GGX gamma=2. normalizes amount 0-0.25." 
                    ]],
                    
                    float  Clearcoat_Gloss = 1  [[ string description = 
                        "controls clearcoat glossiness (0 = satin appearance, 1 = gloss appearance"
                    ]],
                    
                    string Opacity = "opacity.png",
                    int Reflection_Subdivs = 8,
                    float Texture_Gamma = 1,
                
                    output color result = 1
                )
                
                {
                    /* Define Bump */
                    normal bumped_normal = N;
                    
                    /* Diffuse */
                    color OpacityColor = getTextureDif(Opacity, color(1));
                    color BaseColor = getTextureDif(Base_Color, color(0.5));
                    BaseColor = pow(BaseColor, Texture_Gamma);
                
                    float Kd = 1;
                //is there an amount?
                
                   /* Specular */
                    float IOR_disable = 0;
                    float Tail = 2.0;
                    float RoughnessGGX = 0;
                    
                    /* Spec amount - remaps ior to normalized value */
                    float SpecAmount = clamp(Specular_Amount,0,1); //set min-max to 0-1
                    // remapping: b1 + (s-a1)*(b2-b1)/(a2-a1)
                    float IOR = 1 + SpecAmount*0.8; //in lieu of an explicit index-of-refraction. Normalizes ior 1.0-1.8
                    color Fresnel = SchlickFresnel(bumped_normal, IOR); //Fresnel_Amount
                    
                    /* Spec tint */
                    float SpecTintAmount = clamp(Specular_Tint,0,1); //set min-max to 0-1
                    color TintColor= mix(1,BaseColor,SpecTintAmount); //mix between baseColor and white based on Specular_Tint amount
                    color Tint = mix(TintColor,1,Fresnel); //mix between tintColor and white based on Fresnel
                    Fresnel *= Tint; //tints incident specular towards the base color. Grazing specular is still achromatic.
                    Fresnel *= Specular_Amount;
                    
                    /* Metallic */
                    color BaseMetal = pow(BaseColor,2.2);
                    color Edgetint = pow(BaseColor,0.2);
                
                    float thetaB = acos(dot(-I,N));
                    float RCH = AFMF(BaseMetal[0],Edgetint[0],thetaB);
                    float GCH = AFMF(BaseMetal[1],Edgetint[1],thetaB);
                    float BCH = AFMF(BaseMetal[2],Edgetint[2],thetaB);
                    
                    float MetallicAmount = clamp(Metallic_Amount,0,1); //set min-max to 0-1. 0 = dielectric,  1 = metallic
                    Kd = 1 - MetallicAmount; //The metallic model has no diffuse component
                    color Metallic = mix(BaseMetal,Edgetint,Fresnel); // Metallic has tinted incident specular, equal to the base color.
                //    color Metallic = color(RCH,GCH,BCH);
                    color SpecColor = mix(Fresnel,Metallic,MetallicAmount); // linear blend between dielectric & metallic
                
                    
                    /* Anisotropy */
                    float AniAmount = clamp(Anisotropic,0,1); //set min-max to 0-1
                    float AniRotation = clamp(Anisotropic_Rotation,0,1); //set min-max to 0-1
                    AniRotation *= 10; // not sure why this works...
                
                
                 
                    /* Define Sheen */
                    float SheenAmount = clamp(Sheen,0,1); //set min-max to 0-1
                    float SheenTintAmount = clamp(Sheen_Tint,0,1); //set min-max to 0-1
                    float facingRatio = 1 - abs(dot(I, bumped_normal));
                
                    SheenTintAmount *= 2; // intensify tint amount
                    color TintBoost = transformc("hsl", BaseColor);
                    TintBoost[2] = TintBoost[2] + 0.5; // make the tint a brighter version of the mainColor
                    TintBoost[2] = clamp(TintBoost[2],0,1);
                    TintBoost = transformc("hsl","rgb", TintBoost);
                      
                    color EdgeColor = color(0.25,0.25,0.25);
                    color TintEdge = EdgeColor * TintBoost;   //colorize sheen with the tint
                    EdgeColor = mix (EdgeColor, TintEdge, SheenTintAmount); //mix between tinted & untinted sheen based on tint value
                    EdgeColor = clamp (EdgeColor, 0, 1);
                    color SheenMix = EdgeColor * facingRatio * SheenAmount;
                    BaseColor += SheenMix;
                    
                    /*  Roughness */
                    float RoughnessAmount = clamp(Roughness,0,1); //set min-max to 0-1
                    float DifRoughness = pow(RoughnessAmount,2);
                    float SpecRoughness = RoughnessAmount; // paper uses pow((0.5 + RoughnessAmount/2),2) in BRDF
                    
                
                
                    /* diffuse  */
                    color BaseLess = BaseColor * 0.5; // reduce diffuse by 0.5 at grazing angles for smooth surfaces
                    color BaseMore = BaseColor * 2.5; // increase diffuse by up to 2.5 at grazing angles for rough surfaces.
                    color BaseEdge = mix(BaseLess,BaseMore,RoughnessAmount);
                     //BaseColor = mix(BaseColor,BaseEdge,Fresnel);
                
                
                    /* Clearcoat */
                    float ClearcoatAmount = clamp(Clearcoat,0,1); //set min-max to 0-1
                    float ClearcoatGloss = clamp(Clearcoat_Gloss,0,1); //set min-max to 0-1
                    ClearcoatAmount *= 0.25; //normalizes amount 0-0.25
                    float ClearIOR = 1.5; // fixed ior
                    
                    closure color difMain =  BaseColor * Kd *
                        diffuse(bumped_normal, "roughness", DifRoughness);
                        
                     
                     closure color spcMain = SpecColor *
                        microfacet_ggx (bumped_normal, SpecRoughness, IOR_disable,
                        "gtr_gamma", Tail,
                        "subdivs", Reflection_Subdivs,
                        "anisotropy", AniAmount,
                        "aniso_rotation", AniRotation
                        );
                        
                        
                    closure color spcClearcoat = ClearcoatAmount *
                        microfacet_ggx (bumped_normal, RoughnessGGX, ClearIOR,
                        "gtr_gamma", Tail,     
                        "reflection_glossiness", ClearcoatGloss,
                        "highlight_glossiness", ClearcoatGloss,
                        "subdivs", Reflection_Subdivs
                        );
                    
                    Ci = OpacityColor * difMain + spcMain + spcClearcoat + (1.0 - OpacityColor) * transparent();
                    //Ci = OpacityColor * difMain + (1.0 - OpacityColor) * transparent();
                    
                
                }

                Comment


                • #83
                  Originally posted by Rens View Post
                  That would be tricky. I had a quick look but you're pretty limited in OSL when it comes to looking up geometry. A shader similar to the VRayEdgesTex might be able to do that.
                  Maybe it might work somewhere along the lines of Photoshop's bevel layer style, wheras the bevel edge is just a color inset, with light angles defining where the light and dark edges appear.

                  Comment


                  • #84
                    Rens,

                    Luc was saying here that he was not able to connect an OSLmtl to a blendMtl or bumpMtl in Max. This works fine for me in Maya. Can you conform whether this is working in Max too?

                    Comment


                    • #85
                      Originally posted by sharktacos View Post
                      Rens,

                      Luc was saying here that he was not able to connect an OSLmtl to a blendMtl or bumpMtl in Max. This works fine for me in Maya. Can you conform whether this is working in Max too?
                      Hi, I did a quick test with the archGlass material, and that seems to work fine. I only had a look in the material editor preview though, but that should give the same result.
                      Rens Heeren
                      Generalist
                      WEBSITE - IMDB - LINKEDIN - OSL SHADERS

                      Comment


                      • #86
                        Another idea: convert object-space procedurals to world space procedurals.

                        Background:
                        I got asphalt with procedural potholes. Now I wanna have stripes of paint on top, as extra object, but not where the potholes are.
                        I can't just take the potholes mask and use it, since they are object space. I could now rework all procedurals to be in world space, but a node which converts or offsets or something the procedurals in a way they are at the same position on another object would be nice.
                        Software:
                        Windows 7 Ultimate x64 SP1
                        3ds Max 2016 SP4
                        V-Ray Adv 3.60.04


                        Hardware:
                        Intel Core i7-4930K @ 3.40 GHz
                        NVIDIA GeForce GTX 780 (4096MB RAM)
                        64GB RAM


                        DxDiag

                        Comment


                        • #87
                          Quick update: finished the blur shader! It's slow as expected, but it works nicely, even with most procedurals. I'll post that tomorrow and answer the replies here as well. : )
                          Rens Heeren
                          Generalist
                          WEBSITE - IMDB - LINKEDIN - OSL SHADERS

                          Comment


                          • #88
                            Originally posted by Rens View Post
                            Quick update: finished the blur shader! It's slow as expected, but it works nicely, even with most procedurals. I'll post that tomorrow and answer the replies here as well. : )
                            It would be interesting to know how it reacts with extreme values. You know for example the antialiasing has problems to get smooth transitions in super-high contrast areas (0 vs 10+). How does your blur shader handles this? In my head it could happen that there would still be a harsh line, with a soft glow around it, since the blur doesn't blur so much as to make that border disappear.
                            Software:
                            Windows 7 Ultimate x64 SP1
                            3ds Max 2016 SP4
                            V-Ray Adv 3.60.04


                            Hardware:
                            Intel Core i7-4930K @ 3.40 GHz
                            NVIDIA GeForce GTX 780 (4096MB RAM)
                            64GB RAM


                            DxDiag

                            Comment


                            • #89
                              Another one:

                              Erode/Dilate.

                              Background:
                              I got a noise map which is clamped already with a harsh transition/border. I want to erode that further by some amount to create kind of like an inset effect.
                              Software:
                              Windows 7 Ultimate x64 SP1
                              3ds Max 2016 SP4
                              V-Ray Adv 3.60.04


                              Hardware:
                              Intel Core i7-4930K @ 3.40 GHz
                              NVIDIA GeForce GTX 780 (4096MB RAM)
                              64GB RAM


                              DxDiag

                              Comment


                              • #90
                                The page isn't up yet, but here's the blur map already for those interested.
                                http://www.rensheeren.com/osl/slowBlur_tex_v001.osl
                                (right-click, save as)

                                Usage:
                                - Connect the texture you want to blur.
                                - Adjust the scale UP until you start to see blocks, pixels or lines in your blurred texture.
                                - Then adjust the scale down again to the limit where they just disappear.
                                - Then set the blur size (amount of blur).
                                - The falloff is an easy way to get some more blur in at the cost of it looking more blocky.
                                Falloff 1 is pure Gaussian blur, 0 is close to a box blur.

                                The reason for the scale factor is that the blur texture has no idea of the input pixel size, so it might over or under sample, so that's why you need to adjust the scale until you start to see blocks and lines (undersampling) in your render and then adjust down again until they disappear.
                                Rens Heeren
                                Generalist
                                WEBSITE - IMDB - LINKEDIN - OSL SHADERS

                                Comment

                                Working...
                                X