Announcement

Collapse
No announcement yet.

skin shader a la Alsurface pleaseeee

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

  • #61
    ok I'll try right after lunch and I'll let you know

    Comment


    • #62
      No it don't work, in fact that wholeOSL shader don't work in max.. it render black here.. I often have inconsistency rpoblem with osl shader in max.. sometimes it render balc, sometimes it work.. any idea on that Vlado ?I'm I missing something on how to use them?

      Comment


      • #63
        But, if I load a texture in that carbon OSL shader with a VrayMultiSubTex , it works... but the same tricks dont work in your skin shader.. any idea ? Ho and BTW I made you some suggestions in your post ehre : http://forums.chaosgroup.com/showthr...242#post693242

        Comment


        • #64
          Max crashed... then I reboot it and now the texture work in the OSL carbon shader.. but is blownout and look wierd.. but without the need to put the VrayMultiSubTex ... it's reaqlly behaving weirdly in max honestly..

          Comment


          • #65
            sharktacos , maybe you can take the diffuse portion of the fabrick OSL that one work. ?

            Comment


            • #66
              Okay, I think I know what's going on. In Maya the color slot and the texture slot are the same. In Max they are different. I have a routine in the OSL that checks if there is a texture or color being used, which works in Maya, but would need to be coded slightly differently in Max since the inputs are different.

              So to make it simple I just made an input for the texture (like in the fabric shader). Note that it may default to black now since OSL in Vray does not allow you to define default colors. But if you attach a texture map it should work. I changed the bump map too so you can input a map there as well.

              I also added a depth scale color that you can use to map the overall depth. Note that (as with all texture inputs) it will default to black, so make sure to set it to white or the sss will not show.

              I also added a gamma input for linear lighting. It defaults to 2.2 which means the textures and colors will get a degamma. If you want them linear (like for exr) then set it to 1.0.

              Code:
              /*
               *
               * Wavelenghth dependant subsurface scattering OSL shader by Derek Flood (c)2016
               * based on a shader tree by Tony Reynolds
               * from http://docs.sharktacos.com/misc.php?action=help&hid=66
               *
               */
              
              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 getTextureBump(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;
              }
              
              
              
              normal getBumpedBump(color centerColor, color uColor, color vColor, float inverseBumpAmount)
              {
                  vector worldTangent = normalize(dPdu);
                  vector worldBitangent = normalize(dPdv);
                  vector worldNormal = normalize(N);
               
                  vector average = vector(0.3333333);
                  float center = dot (average, vector(centerColor));
                  float ddu = center - dot(average, vector(uColor));
                  float ddv = center - dot(average, vector(vColor));
               
                  return normalize(ddu * worldTangent + ddv * worldBitangent + inverseBumpAmount * worldNormal);
              }
              
              normal getBumpedNormal(color compressedNormalSample, float Bump_amount)
              {
                  vector worldTangent = normalize(dPdu);
                  vector worldBitangent = normalize(dPdv);
                  vector worldNormal = normalize(N);
              
                  color normalSample = 2.0 * compressedNormalSample - 1.0;
                  normalSample *= color(Bump_amount, Bump_amount, 1.0);
              
                  return normalize(normalSample[0] * worldTangent + normalSample[1] * worldBitangent + normalSample[2] * worldNormal);
              }
              
              
              
              
              surface DFskinMtl
                  [[ string description = "Wavelenghth dependant subsurface scattering material" ]]
              (
                  //float Depth_Scale = 1,
                  string Depth_Scale = "depth.png",
                  float Overall_Color_Mult = 1,
                  //string Opacity = "opacity.png",
                  color Diffuse_Color = color(0.6,0.6,0.6),
                  float Diffuse_Amount = 0.8,
                  string Subsurface_Color = "color.png",
                  color RGB_Scatter_Depth = color(1,0.4,0.1),
                  float Subsurface_Amount = 1,
                  float ior = 1.38,
                  float Phase_Function = 0.8,
                  int Subdivs = 8,
                  float Texture_Gamma = 2.2, 
                  
                  /* Bump section */
                  string Bump_Map = "normal.png",
                  float Bump_amount = 1.0,
                  int Normal_Mapping = 0
                      [[ string widget = "checkBox" ]],
              
                  output color result = 1
              )
              
              
              
              {
              
                 /* Define Bump */
                  normal bumped_normal = N;
                
                  if ( Normal_Mapping == 1 )
                  {
                  //color compressedNormalSample = getTextureBump(Bump_Map, color(0.5,0.5,1));
                  color compressedNormalSample = texture (Bump_Map, u, v, "missingcolor", color(0.5,0.5,1));
              
                      bumped_normal = getBumpedNormal(compressedNormalSample, Bump_amount);
                  }
                  else
                  {
                      float delta = 0.004;
                      color center = texture(Bump_Map, u, v);
                      color uColor = texture(Bump_Map, u + delta, v);
                      color vColor = texture(Bump_Map, u, v + delta);
                      float Bump_amount = Bump_amount * 10;
                      bumped_normal = getBumpedBump(center, uColor, vColor, 1.0 / Bump_amount);
                  }
              
                  
                  
                  /* declare variables and read texture map */
                  color Red = color(1,0,0);
                  color Green = color(0,1,0);
                  color Blue = color(0,0,1);
                  color RGB_Depth = RGB_Scatter_Depth;
                  RGB_Depth[0] = clamp(RGB_Scatter_Depth[0],0.001,1);
                  RGB_Depth[1] = clamp(RGB_Scatter_Depth[1],0.001,1);
                  RGB_Depth[2] = clamp(RGB_Scatter_Depth[2],0.001,1);
                  
                  //color Map = getTextureDif(Subsurface_Color, color(0.85,0.75,0.65));
                  color Map = texture (Subsurface_Color, u, v, "missingcolor", color(0.85,0.75,0.65));
                  color DepthScale = texture (Depth_Scale, u, v, "missingcolor", color(1,1,1));
                  
                  Map = pow(Map, Texture_Gamma);
                  color SubsurfaceColor = Map * Subsurface_Amount * Overall_Color_Mult;
                  
                  color DifCol = pow(Diffuse_Color,Texture_Gamma);  // color for lambertian diffuse (single scatter)
                  
                  
                     
                  /* Closures */
                  closure color diffuse_component =  Overall_Color_Mult * Diffuse_Amount * DifCol * diffuse(bumped_normal);
                  
                  closure color SkinR = vray_subsurface (
                     ior, Phase_Function,
                     SubsurfaceColor * Red * RGB_Depth[0] * DepthScale,
                     SubsurfaceColor * Red,
                     "subdivs", Subdivs);
                     
                  closure color SkinG = vray_subsurface (
                     ior, Phase_Function,
                     SubsurfaceColor * Green * RGB_Depth[1] * DepthScale,
                     SubsurfaceColor * Green,
                     "subdivs", Subdivs);
              
                  closure color SkinB = vray_subsurface (
                     ior, Phase_Function,
                     SubsurfaceColor * Blue * RGB_Depth[2] * DepthScale,
                     SubsurfaceColor * Blue,
                     "subdivs", Subdivs);
                  
              
                   Ci = SkinR + SkinG + SkinB;
                   Ci += diffuse_component;
                   
              }
              Last edited by sharktacos; 18-05-2016, 03:58 PM.

              Comment


              • #67
                Hi ,

                Thank's for the quick reply! I still don't work, some procedural ( and not all ) work like the smoke,etc but the checker don't work etc and when I put a bitmap it don't work.. and don't work in the depth too so it feel's like it has no sss now.
                Can you install max demo and Vray demo? would be better for you for testing it out and find the problem I guess.

                Also, we would need a prepass rate or the object ID ( by the way, is it in a raytrace mode or in a prepass mode this shader ? )

                The opacity is like for the doing the alpha in the eyes and some other stuff

                Also I think the interface is not the same as in Maya.. I will post you an image in your thread of your shader.

                Thank's for your time!

                Comment


                • #68
                  Also, we would need a prepass rate or the object ID ( by the way, is it in a raytrace mode or in a prepass mode this shader ? )
                  It's raytrace mode only. Maybe that's why it's slower if you are comparing it to prepass.

                  The opacity is like for the doing the alpha in the eyes and some other stuff
                  Does the SSS2 in Max have opacity?

                  I still don't work, some procedural ( and not all ) work like the smoke,etc but the checker don't work etc and when I put a bitmap it don't work.. and don't work in the depth too so it feel's like it has no sss now.
                  Can you install max demo and Vray demo? would be better for you for testing it out and find the problem I guess.
                  I'll try. In the meantime, can you let me know if this shader works with maps? It's a Cook-Torrance shader made by the folks at Chaos that should work with Max.

                  Code:
                  float getTextureFloat(string texture_name, float no_texture_default_value, float value_scale, float value_center_offset)
                  {
                      int channels = -1;
                      if (gettextureinfo(texture_name, "channels", channels))
                      {
                          color texture_sample = texture(texture_name, u, v);
                          float sample_value = dot(vector(texture_sample), vector(0.3333333));
                          float result = value_scale * sample_value + value_center_offset;
                          return result;
                      }
                      
                      return no_texture_default_value;
                  }
                  
                  color getTextureColor(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 = fabs(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;
                  }
                  
                  normal getBumpNormal(string normal_map_texture, float bump_amount)
                  {
                      int channels = -1;
                      if (gettextureinfo(normal_map_texture, "channels", channels))
                      {
                          color texture_sample = texture(normal_map_texture, u, v);
                          texture_sample *= 2.0;
                          texture_sample -= 1.0;
                          texture_sample[0] *= bump_amount;
                          texture_sample[1] *= bump_amount;
                          return normalize(normal("shader", texture_sample[0], texture_sample[1], texture_sample[2]));
                      }
                      
                      return N;
                  }
                  
                  surface cook_torrance_material
                  (
                      /* Diffuse section */
                      color diffuse_color = 0.75,
                      string diffuse_color_texture = "diffuse_color_texture.bmp",
                      float roughness = 0.0,
                      string roughness_texture = "roughness_texture.bmp",
                      
                      /* Reflection section */
                      color reflection_color = 0.16,
                      string reflection_color_texture = "reflection_color_texture.bmp",
                      float reflection_glossiness = 0.7,
                      string reflection_glossiness_texture = "reflection_glossiness_texture.bmp",
                      int lock_highlight_glossiness = 1
                          [[    string widget = "checkBox"    ]],
                      float highlight_glossiness = 0.7,
                      string highlight_glossiness_texture = "highlight_glossiness_texture.bmp",
                      int fresnel_reflections = 0
                          [[    string widget = "checkBox"    ]],
                      float fresnel_ior = 3.0,
                      int subdivs = 8,
                      
                      /* BRDF section */
                      float anisotropy = 0.0,
                      string anisotropy_texture = "anisotropy_texture.bmp",
                      float aniso_rotation = 0.0,
                      string aniso_rotation_texture = "aniso_rotation_texture.bmp",
                      float soften_edge = 0.0,
                      
                      /* Options section */
                      int trace_reflections = 0
                          [[    string widget = "checkBox"    ]],
                      
                      /* Maps section */
                      float bump_amount = 0.0,
                      string bump_texture = "bump_texture.bmp",
                      color opacity_color = 1.0,
                      string opacity_color_texture = "opacity_color_texture.bmp"
                  )
                  {
                      normal bumped_normal = N;
                      if (bump_amount > 0.0)
                      {
                          bumped_normal = getBumpNormal(bump_texture, bump_amount);
                      }
                      
                      color diffuse_color_result = getTextureColor(diffuse_color_texture, diffuse_color);
                      float roughness_result = getTextureFloat(roughness_texture, roughness, 1.0, 0.0);
                          
                      color reflection_color_result = getTextureColor(reflection_color_texture, reflection_color);
                      if (fresnel_reflections)
                      {
                          reflection_color_result *= fresnelReflectionFactor(bumped_normal, fresnel_ior);
                      }
                      
                      if (trace_reflections) 
                      {
                          diffuse_color_result *= (1.0 - reflection_color_result);
                      }
                      
                      Ci = diffuse_color_result * orennayar(bumped_normal, roughness_result);
                      
                      float reflection_glossiness_result = getTextureFloat(reflection_glossiness_texture, reflection_glossiness, 1.0, 0.0);
                      float highlight_glossiness_result = reflection_glossiness_result;
                      if (!lock_highlight_glossiness)
                      {
                          highlight_glossiness_result = getTextureFloat(highlight_glossiness_texture, highlight_glossiness, 1.0, 0.0);
                      }
                      
                      float anisotropy_result = getTextureFloat(anisotropy_texture, anisotropy, 1.0, 0.0);
                      anisotropy_result = clamp(anisotropy_result, 0.0, 0.99);
                      float aniso_rotation_result = getTextureFloat(aniso_rotation_texture, aniso_rotation, 360.0, -180.0);
                      
                      Ci +=  reflection_color_result * vray_cooktorrance(bumped_normal, highlight_glossiness_result,
                          "anisotropy", anisotropy_result,
                          "aniso_rotation", aniso_rotation_result,
                          "reflection_glossiness", reflection_glossiness_result,
                          "soften_edge", soften_edge,
                          "subdivs", subdivs,
                          "trace_reflections", trace_reflections);
                      
                      color opacity_result = getTextureColor(opacity_color_texture, opacity_color);
                      if (luminance(opacity_result) < 0.99)
                      {
                          Ci *= opacity_result;
                          Ci += (1.0 - opacity_result) * transparent();
                      }
                  }

                  Comment


                  • #69
                    yes sss2 has opacity in max and the skin shader also.
                    so if its raytrace we need a raytrace sss id like in the sss2 to be able to make it blend with other objects in the sss calculation.

                    ok ill test soon if that shader work i guess it is sincr chaosgroup did it

                    Comment


                    • #70
                      taht cook torrence diffuse map don't work in my max 2014 .. I plug a png there and it don't shows...

                      Comment


                      • #71
                        I think the OSL shader in max is broken... I'm trying to plug a texture in the fabrick.osl and it don't work either... Vlado, can I skaype with you and show you the problem ?

                        Comment


                        • #72
                          Originally posted by Bigguns View Post
                          I think the OSL shader in max is broken... I'm trying to plug a texture in the fabrick.osl and it don't work either... Vlado, can I skaype with you and show you the problem ?

                          Here's a really simple one you can try:

                          Code:
                          surface
                          Lambert
                              
                          (
                              string diffuse_texture = "diffuse.png",
                              float diffuse_weight = 0.5,
                              
                          )
                          {
                              color diffuseColor = texture(diffuse_texture, u, v);
                              
                              Ci = diffuse_weight * diffuseColor * diffuse(N) ;
                          }

                          Comment


                          • #73
                            Note that you need to save the shader in a file with the same name, i.e. the Lambert shader above needs to be saved as Lambert.osl; I'm not sure if we found a work-around for that.

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

                            Comment


                            • #74
                              Originally posted by Bigguns View Post
                              if its raytrace we need a raytrace sss id like in the sss2 to be able to make it blend with other objects in the sss calculation.
                              I don't know if the OSL vray_subsurface can do that. Vlado?

                              Comment


                              • #75
                                I treid vlado and that lambert shader don't load in my OSLvraymtl. It say's synthax error could not compile ..etc can you check his skin shader and see why ther eis no way to plug a map in it? I always have problem with theOSL shaders in general and pluggin a map ..

                                Comment

                                Working...
                                X