Announcement

Collapse
No announcement yet.

Thin film OSL shader

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

  • #31
    that's how it ought to be used.
    Make sure you turn fresnel off, as it's got its own one!
    Lele
    Trouble Stirrer in RnD @ Chaos
    ----------------------
    emanuele.lecchi@chaos.com

    Disclaimer:
    The views and opinions expressed here are my own and do not represent those of Chaos Group, unless otherwise stated.

    Comment


    • #32
      makes sense...that's why I had to crank the shader fresnel! I'll correct it tomorrow.
      Dmitry Vinnik
      Silhouette Images Inc.
      ShowReel:
      https://www.youtube.com/watch?v=qxSJlvSwAhA
      https://www.linkedin.com/in/dmitry-v...-identity-name

      Comment


      • #33
        lol! yeas, that'd make sense!
        You can wire me a few hundred bucks at your own leisure
        Lele
        Trouble Stirrer in RnD @ Chaos
        ----------------------
        emanuele.lecchi@chaos.com

        Disclaimer:
        The views and opinions expressed here are my own and do not represent those of Chaos Group, unless otherwise stated.

        Comment


        • #34
          Wow!

          Simon, who sits next to me in our office saw this and downloaded, gave it a test run ... and wow, just wow!
          Thanks so much for sharing!
          Best Regards,
          Fredrik

          Comment


          • #35
            By the way - I totally missed this just because you're posting this in a max sub-forum. God knows how much goodies I've missed because of this (being a Maya user) ...
            Best Regards,
            Fredrik

            Comment


            • #36
              A particular use of the iridescence shader, coupled with a flakes normal texture, in a blend material, to generate a carpaint with iridescent flakes.
              Scene and shaders are attached, just grab yourself an HDRI in place of mine.

              Click image for larger version

Name:	carpaint_OSLTex-based.png
Views:	1
Size:	325.5 KB
ID:	855448 Click image for larger version

Name:	carpaint_OSLTex-based_FLAKES.png
Views:	1
Size:	368.6 KB
ID:	855449

              OSL_carPaint_with_iridescence.zip
              Lele
              Trouble Stirrer in RnD @ Chaos
              ----------------------
              emanuele.lecchi@chaos.com

              Disclaimer:
              The views and opinions expressed here are my own and do not represent those of Chaos Group, unless otherwise stated.

              Comment


              • #37
                And a slightly tweaked, less pronounced, shader (chiefly, i changed each layer's influence, and the flakes' normals orientation variance).

                Click image for larger version

Name:	carpaint_OSLTex-based_B.png
Views:	1
Size:	252.1 KB
ID:	855452 Click image for larger version

Name:	carpaint_OSLTex-based_FLAKES_B.png
Views:	1
Size:	69.6 KB
ID:	855453

                A word of notice: you WILL need many AA Rays AND a reconstructive filter on the rendered image to make sure the flakes won't shimmer in an animation.
                This is a need forced by the fact that the flakes map does no filtering on its own, so we have to burden VRay with it.
                This last one was rendered with a fixed-12 and a sharp quadratic filter.

                EDIT: made a mistake earlier. Corrected now, max 2014 scene added, along with the flakes OSL shader with descriptions for each spinner.

                OSL_carPaint_with_iridescence_B.zip
                Last edited by ^Lele^; 27-02-2015, 05:12 AM.
                Lele
                Trouble Stirrer in RnD @ Chaos
                ----------------------
                emanuele.lecchi@chaos.com

                Disclaimer:
                The views and opinions expressed here are my own and do not represent those of Chaos Group, unless otherwise stated.

                Comment


                • #38
                  Cool, Lele!

                  Comment


                  • #39
                    Seems to broken on 2015?

                    I get this error
                    In the material compiler output
                    Could not compile shader J:\Jobs\46761M_Mazda2Headlight_CP\3d\Projects\Maps \irridescence.osl (OSL to OSO)
                    Last edited by pg1; 01-06-2015, 11:31 PM.

                    Comment


                    • #40
                      Originally posted by pg1 View Post
                      Seems to broken on 2015?

                      I get this error
                      In the material compiler output
                      Could not compile shader J:\Jobs\46761M_Mazda2Headlight_CP\3d\Projects\Maps \irridescence.osl (OSL to OSO)
                      yup same here...any ideas?
                      Dmitry Vinnik
                      Silhouette Images Inc.
                      ShowReel:
                      https://www.youtube.com/watch?v=qxSJlvSwAhA
                      https://www.linkedin.com/in/dmitry-v...-identity-name

                      Comment


                      • #41
                        Originally posted by Morbid Angel View Post
                        yup same here...any ideas?
                        Don't know if this is relevant in Max, but in Maya the outputs and results need to be called "color". Try this:


                        Code:
                        /* Amplitude reflection coefficient (s-polarized) */
                        float rs(float n1, float n2, float cosI, float cosT) {
                            return (n1 * cosI - n2 * cosT) / (n1 * cosI + n2 * cosT);
                        }
                         
                        /* Amplitude reflection coefficient (p-polarized) */
                        float rp(float n1, float n2, float cosI, float cosT) {
                            return (n2 * cosI - n1 * cosT) / (n1 * cosT + n2 * cosI);
                        }
                         
                        /* Amplitude transmission coefficient (s-polarized) */
                        float ts(float n1, float n2, float cosI, float cosT) {
                            return 2 * n1 * cosI / (n1 * cosI + n2 * cosT);
                        }
                         
                        /* Amplitude transmission coefficient (p-polarized) */
                        float tp(float n1, float n2, float cosI, float cosT) {
                            return 2 * n1 * cosI / (n1 * cosT + n2 * cosI);
                        }
                         
                        // cosI is the cosine of the incident angle, that is, cos0 = dot(view angle, normal)
                        // lambda is the wavelength of the incident light (e.g. lambda = 510 for green)
                        // From http://www.gamedev.net/page/resources/_/technical/graphics-programming-and-theory/thin-film-interference-for-computer-graphics-r2962
                        float thinFilmReflectance(float cos0, float lambda, float thickness, float n0, float n1, float n2) {
                            //float PI=3.1415926535897932384626433832795;
                            float PI=M_PI;
                        
                            // compute the phase change term (constant)
                            float d10 = (n1 > n0) ? 0 : PI;
                            float d12 = (n1 > n2) ? 0 : PI;
                            float delta = d10 + d12;
                             
                            // now, compute cos1, the cosine of the reflected angle
                            float sin1 = pow(n0 / n1, 2) * (1 - pow(cos0, 2));
                            if (sin1 > 1) return 1.0; // total internal reflection
                            float cos1 = sqrt(1 - sin1);
                             
                            // compute cos2, the cosine of the final transmitted angle, i.e. cos(theta_2)
                            // we need this angle for the Fresnel terms at the bottom interface
                            float sin2 = pow(n0 / n2, 2) * (1 - pow(cos0, 2));
                            if (sin2 > 1) return 1.0; // total internal reflection
                            float cos2 = sqrt(1 - sin2);
                             
                            // get the reflection transmission amplitude Fresnel coefficients
                            float alpha_s = rs(n1, n0, cos1, cos0) * rs(n1, n2, cos1, cos2); // rho_10 * rho_12 (s-polarized)
                            float alpha_p = rp(n1, n0, cos1, cos0) * rp(n1, n2, cos1, cos2); // rho_10 * rho_12 (p-polarized)
                             
                            float beta_s = ts(n0, n1, cos0, cos1) * ts(n1, n2, cos1, cos2); // tau_01 * tau_12 (s-polarized)
                            float beta_p = tp(n0, n1, cos0, cos1) * tp(n1, n2, cos1, cos2); // tau_01 * tau_12 (p-polarized)
                                 
                            // compute the phase term (phi)
                            float phi = (2 * PI / lambda) * (2 * n1 * thickness * cos1) + delta;
                                 
                            // finally, evaluate the transmitted intensity for the two possible polarizations
                            float ts = pow(beta_s, 2) / (pow(alpha_s, 2) - 2 * alpha_s * cos(phi) + 1);
                            float tp = pow(beta_p, 2) / (pow(alpha_p, 2) - 2 * alpha_p * cos(phi) + 1);
                             
                            // we need to take into account conservation of energy for transmission
                            float beamRatio = (n2 * cos2) / (n0 * cos0);
                             
                            // calculate the average transmitted intensity (if you know the polarization distribution of your
                            // light source, you should specify it here. if you don't, a 50%/50% average is generally used)
                            float t = beamRatio * (ts + tp) / 2;
                             
                            // and finally, derive the reflected intensity
                            return 1 - t;
                        }
                         
                        shader irridescence
                        [[ string description = "Thin film coating shader. Use as reflection color for the material, with Fresnel for the material OFF (this texture computes its own Fresnel)" ]]
                        (   
                         float thicknessMin = 250 [[ string description = "Minimum thickness of the film, in nm" ]],
                         float thicknessMax = 400 [[ string description = "Maximum thickness of the film, in nm" ]],
                         string thickness = "test.png" [[ string description = "Texture map (usually noise) that determines the thickness of the film as fraction between the min and max" ]],
                         float nmedium = 1 [[ string description = "Refractive index of the outer medium (typically air)" ]], // approximate refractive index of air   
                         float nfilm = 1.5 [[ string description = "Refractive index of the thin film itself" ]] , // approximate refractive index of water   
                         float ninternal = 1 [[ string description = "Refractive index of the material below the film" ]], // approximate refractive index of the lower material
                         output color result = 0   
                        )   
                        {   
                         float cos0 = abs(dot(I , N));
                          
                         color thickTex=texture(thickness, u, v);
                         float t=(thickTex[0]+thickTex[1]+thickTex[2])/3.0;
                         float thick=thicknessMin*(1.0-t)+thicknessMax*t;
                          
                         float red=thinFilmReflectance(cos0, 650, thick, nmedium, nfilm, ninternal);
                         float green=thinFilmReflectance(cos0, 510, thick, nmedium, nfilm, ninternal);
                         float blue=thinFilmReflectance(cos0, 475, thick, nmedium, nfilm, ninternal);
                          
                         result=color(red, green, blue);
                        }

                        Comment


                        • #42
                          Any news on building this into the Vray Shader? (perhaps under its own tab?)

                          I'm sure this could be used to create dichroic glass, could it not?
                          Check out my (rarely updated) blog @ http://macviz.blogspot.co.uk/

                          www.robertslimbrick.com

                          Cache nothing. Brute force everything.

                          Comment


                          • #43
                            Hi everyone.

                            I looking for some iridescent reflection....I tried OSL thin film,
                            but not working in Maya 2016-sp6.same osl working very well in max.

                            Thank you!
                            Djordje

                            Comment


                            • #44
                              Which V-Ray version and which OS?

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

                              Comment


                              • #45
                                Instead of adding this to the VrayMtl (if folks are worried about clutter), how about having this as a new VrayTexture that ships with Vray?

                                Comment

                                Working...
                                X