Announcement

Collapse
No announcement yet.

Wavelength dependent subsurface scattering OSL material

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

  • Wavelength dependent subsurface scattering OSL material

    The following OSL material emulates the skin shader made by Tony Reynolds which employs layered subsurface scattering modulated by red, green, and blue wavelengths. You can get the OSL code for the material here.

    I'd love to get feedback from folks trying this material out. Feel free to post your comments here!

    I'd also be interested to hear what folks like Vlado (who know tons more about physics than I do) think of the the shader's approach, which seems to me to address a lot of concerns that users encountered with other subsurface shader approaches.

    Here's some info on the material:

    Wavelength dependent subsurface scattering

    A mean free path describes the distance a photon travels through a particular material before it gets scattered or absorbed. The mean free path is a wavelength dependent value. If we simplify our visible spectrum to three colors (red, green and blue), the mean free path will take a different value for each one of these colors.

    Each wavelength of light penetrates the skin to a different depth. If we simplify our visible spectrum to three colors (red, green and blue) the mean free path (the distance a photon travels through a particular material before it gets scattered or absorbed) will take a different value for each one of these colors. For human skin red goes the deepest, then green, and blue is quite shallow.

    Based on this, the shader separates the main color texture (the Subsurface Color) into its red, green and blue components, and pipes these into three subsurface shaders, which are then combined together using weighted averages (the standard behavior for OSL closures).

    The depth of each these three subsurface shaders (i.e the mean free path) is then driven by the corresponding red, green, and blue channel of the "RGB Scatter Depth" color. In other words, the RGB Scatter Depth is not actually a color per se, but rather represents the scattering coefficients in the volume for the red, green and blue wavelengths. So setting the red channel of the Wavelength RGB Depth color to 1.0 means the depth of the red wavelength is at 100% while setting it to 0.7 means it is 70%, and so on for all three RGB channels.


    One added benefit of this approach is that it virtually eliminates the "green error" that can appear on thin parts of an SSS2 material when the scattering amount it set to large values since it linearly blends multiple subsurface shaders together, rather than the more complex interaction of the subsurface and scatter colors in the SSS2 material, which, while more physically correct, can be unintuitive for artists to work with



    Specular and single scatter reflections


    Additionally, the shader has a Lambertian diffuse term to simulate single scattering, which can be thought of as a diffused reflection. This would therefore be grey since skin is a dielectric material.


    The shader does not have any specular or reflection, and is intended to be combined with the reflection properties of a VrayMtl using an additive blendMtl. I like to use two GGX speculars with differing glossiness values to get the popular two-lobe specular for skin.



    Art and science


    While this approach emulates a physically accurate model of subsurface scattering, the shader is primarily designed to be artist friendly. One drawback of layered skin shaders like the VraySkinMtl is that a user needs to mix different, often unintuitive, colors together to arrive at the desired skin color. As autodesk says of their layered Misss* shader, "Each layer had it's distinct color, which made it difficult to aim for a given "final" color, and changing the balance between the layers threw the color off."

    In contrast, with this shader the user simply inputs a single texture map of the skin into the Subsurface Color and that's what you get. Likewise, the user sets the color for the Wavelength RGB Depth that they want to see in the bleed (keeping in mind that this also affects the scatter depth) and you get that too.WYSIWYG.


    One additional note: I optimistically included a subdiv parameter in theshader to make it forward compatible for when this is added into future code for the vray_subsurface osl closure.
    Last edited by sharktacos; 28-08-2016, 06:20 PM.

  • #2
    I'm testing it, my first impressions are : ca you make it Directionnal, like in the Alsurface shader from anderslanglands http://www.anderslanglands.com/alshaders/index.html so that we had less SSS blending like between the lips etc. ?

    From what I see, it's a bit slow to render compare to the SSS2 but it's rendering ^^ .

    So we don't have control over the RGB and depth of each color ?

    Would need an opacity map aslo to make it more viable with character related stuff.

    Also, is it possible to add a slut for texture in the Subsurface amount? So we can have more control over the zone of the face where we want more or less sss ?

    Overall I like the look of the shader, gonna post some render comparaison to the sss2 ( I'm not even bothering to compare it to the skin shader .. )

    EDIT : I can't use a texture in the Subsurface color, something is borken, the texture is like tiled super small or something... it's not working, any idea why it's not working in max ?
    Last edited by Bigguns; 18-05-2016, 09:52 AM.

    Comment


    • #3
      It has the same problem as the sss2 , way too much bounce bleeding sss if you want, let's say between the lips.. we get a red line.. probably because the light is boucing too much inside the shader and then it creates a redish line between closes surface, like lips, eye eyelids fold, etc. wich is not accurate compare to real skin.. is there a way to tell to the shader to do less bounces in closes surface proximity.. or just less bounce in general? I don't know what would be the best.. I know the sss in direcitonnal mode get rid of these...
      Last edited by Bigguns; 18-05-2016, 03:20 PM.

      Comment


      • #4
        Very interesting sss shader you did here, look's a b it better then the sss2 in the SSS perspective, look's a bit more accurate. It's really slow though but look a bit better ,wich I like I hope you can make the diffuse slot work on 3dsmax so I can do further test

        Comment


        • #5
          Originally posted by Bigguns View Post
          I'm testing it, my first impressions are : ca you make it Directionnal, like in the Alsurface shader from anderslanglands http://www.anderslanglands.com/alshaders/index.html so that we had less SSS blending like between the lips etc. ?
          The shader uses the vray_subsurface closure, and I don't think there is a way to make that directional. Maybe Vlado can comment on that.

          From what I see, it's a bit slow to render compare to the SSS2 but it's rendering ^^ .
          It combines three sss2 materials, so it makes sense that it would be slower. Again, perhaps Vlado might have some ideas of how it could be made faster.

          BTW, I noted that you said you are using 32bit EXR textures. Are you using mipmaps of those? Or Vray's tileEXR utility? That helps a tone with slow renders!

          So we don't have control over the RGB and depth of each color ?
          You do. The depth is controlled by the red, green, and blue channels of the RGB_Scatter_Depth. This also impacts the color.

          Would need an opacity map aslo to make it more viable with character related stuff.
          That's certainly doable. Can I ask what you would use it for?

          Also, is it possible to add a slut for texture in the Subsurface amount? So we can have more control over the zone of the face where we want more or less sss ?
          It's possible, but may be confusing to the user. It's not really a color value, and more percentage of the depth for the red, green, and blue wavelengths. Are you thinking of having different depth amounts for the channels? Maybe I could make a multiplier for that which could take a texture map. That would keep the RGB_Scatter_Depth as a color (essentially a vector), but allow you to control the overall depth with a map.

          Overall I like the look of the shader, gonna post some render comparaison to the sss2 ( I'm not even bothering to compare it to the skin shader .. )
          That would be awesome

          EDIT : I can't use a texture in the Subsurface color, something is borken, the texture is like tiled super small or something... it's not working, any idea why it's not working in max ?
          It's a Max thing I think. I posted a version that should work with Max over here.
          Last edited by sharktacos; 18-05-2016, 04:00 PM.

          Comment


          • #6
            Originally posted by sharktacos View Post
            The shader uses the vray_subsurface closure, and I don't think there is a way to make that directional. Maybe Vlado can comment on that.

            Vlado is supposed to be working on an Alsurface shader equivalent so we will have soon I hope that directionnal shader



            It combines three sss2 materials, so it makes sense that it would be slower. Again, perhaps Vlado might have some ideas of how it could be made faster.

            BTW, I noted that you said you are using 32bit EXR textures. Are you using mipmaps of those? Or Vray's tileEXR utility? That helps a tone with slow renders!
            No never tried! since normally I don't use EXR.. but jpg for the diffuse etc ( except displacement ) so I don't even know how to use it .. you have a tutorial for it somewhere?



            You do. The depth is controlled by the red, green, and blue channels of the RGB_Scatter_Depth. This also impacts the color.
            Ho like in one of the Mr skin mtl they made ^^ but in my max interface I don't see these control.. I join an image to show the interface I have in max.


            That's certainly doable. Can I ask what you would use it for?
            For eyes opacity and other stuff



            It's possible, but may be confusing to the user. It's not really a color value, and more percentage of the depth for the red, green, and blue wavelengths. Are you thinking of having different depth amounts for the channels? Maybe I could make a multiplier for that which could take a texture map. That would keep the RGB_Scatter_Depth as a color (essentially a vector), but allow you to control the overall depth with a map.
            Yes that would be cool



            That would be awesome



            It's a Max thing I think. I posted a version that should work with Max over here.

            Here's an image of the interface it shows in max

            Click image for larger version

Name:	OSL_TEST_001.jpg
Views:	1
Size:	491.1 KB
ID:	862080

            Comment


            • #7
              Regarding mipmaps, if you are using 8-bit files mostly, you will want to use maketx. I have a tutorial for it here, but note that it is written for Maya.

              Comment


              • #8
                Originally posted by Bigguns View Post
                Ho like in one of the Mr skin mtl they made ^^ but in my max interface I don't see these control.. I join an image to show the interface I have in max.
                In the image I see a color swatch by the RGB_Scatter_Depth. Just change the color, and the red, green, and blue depth will be whatever you set the RGB channels to. If you set the red channel to 1 then the red depth will be 100%. If you set the green channel to 0.5 then the green depth will be 50% and so on.

                Comment


                • #9
                  ok but in max, we don't have acces to the RGB channels of a flat color. We need a slot ,like for the diffuse, so I can put a color there and modify it with the 3 channels .. would be better for max to have, like Mental ray did, a button called R: with a value associated to it that you can tweak, then a G and Blue etc.

                  Comment


                  • #10
                    Originally posted by Bigguns View Post
                    ok but in max, we don't have acces to the RGB channels of a flat color. We need a slot ,like for the diffuse, so I can put a color there and modify it with the 3 channels .. would be better for max to have, like Mental ray did, a button called R: with a value associated to it that you can tweak, then a G and Blue etc.
                    Can't you just click the color swatch and have the Color Selector open? The Color Selector in Max has an RGB section in it. In your pic the Diffuse Color and the RGB Scatter Depth both have color swatches so they should work the same.
                    Last edited by sharktacos; 20-05-2016, 06:43 AM.

                    Comment


                    • #11
                      Ha ok you mean just that.. I though I would need to use the output in map map where I can control with a curve editor the RGB independantly.

                      Comment


                      • #12
                        Ive been tinkering around with the parameters, simplifying things. I think I'll remove the diffuse and bump and just focus on SSS. Folks can always add a diffuse to it with a blendMtl, and OSL tends to have problems with bump maps anyway. Here are the current parameters:

                        • Depth Scale (float): Global control for the depth of the subsurface scattering
                        • Overall Brightness (float) : Controls the brightness of the colors
                        • Subsurface Color (color): The main color of the material. This is where your color texture goes
                        • Subsurface amount (float): Controls the amount of shallow scatter, as opposed to deep scatter
                        • RGB Scatter Depth (color): Controls the percentage of scattering for the red, green, and blue wavelengths, which also affects the scatter color
                        • Texture Gamma (float): Gamma corrects textures and colors
                        Last edited by sharktacos; 20-05-2016, 09:46 PM.

                        Comment


                        • #13
                          Here's a question about speed: The material essentially adds 3 sss2 material together, making it 3x slower than a single sss2. It does this to avoid the issues that come up with a single sss2 (as I described in the 1st post). Is there a way to speed that up? I did find one way. Since the material is intended for skin, where the deep color tends to red (because of blood), I split it into 2 sss materials, red and green+blue.

                          Code:
                          closure color SkinRed = vray_subsurface (
                                 IOR, PhaseFunction,
                                 SubsurfaceR * RGB_Depth[0] * Depth_Scale,
                                 SubsurfaceR,
                                 "subdivs", Subdivs);
                               
                              closure color SkinGB = vray_subsurface (
                                 IOR, PhaseFunction,
                                 (SubsurfaceG * RGB_Depth[1]) +
                                 (SubsurfaceB * RGB_Depth[2]) *
                                 Depth_Scale,
                                 SubsurfaceG + SubsurfaceB,
                                 "subdivs", Subdivs);
                            
                               Ci = SkinRed + SkinGB;
                          That makes it only 2x slower than a sss2, rather than 3x slower. My question is whether there is a way to make it even faster, without losing the functionality of the material which works because it is doing a simple add of the sss2 materials, taking one that has a high depth value (the red sss) and adding to another with a lower depth value (the green&blue sss). In contrast, the sss2 does not simply add the subsurface color (shallow) with the scatter color (deep), but is doing more complex math to combine them that, while physically correct, results in colors coming out the other end that are artistically unintuitive (not WYSIWYG) which is what I am trying to get around.

                          My understanding is that the VraySkinMtl is also essentially adding different sss materials together too, multiplying them with a color for each layer. So why is that not 3x slower than the sss2? Maybe there is something there that I could implement here?

                          Comment


                          • #14
                            That skin shader is quite better then the sss2 (especially, the more sss it has, the better we see the difference compared to the sss2 ) ,thank's for that man if you want to see some render, do you have skype? I have some confidential stuff for now that I don't want to post on the net unitl it's finished, but I can show you

                            Comment


                            • #15
                              Originally posted by Bigguns View Post
                              That skin shader is quite better then the sss2 (especially, the more sss it has, the better we see the difference compared to the sss2 ) ,thank's for that man if you want to see some render, do you have skype? I have some confidential stuff for now that I don't want to post on the net unitl it's finished, but I can show you
                              Sure, love to see it. PM me and we can figure it out.

                              Comment

                              Working...
                              X