Announcement

Collapse
No announcement yet.

OSL Mtl in V-Ray 1.5, how to use?

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

  • OSL Mtl in V-Ray 1.5, how to use?

    I updated my V-Ray for SketchUp yesterday, and saw in the release that it now supported OSL Material, but I couldn't find the map, any tips?

  • #2
    Hi henriqueb,

    OSL materials and textures can be loaded from a manually created vrmat containing TexOSL or MtlOSL plugins.
    Nikoleta Garkova | chaos.com

    Comment


    • #3
      Hi

      I would like to know how to use the OSL material, i Saw some time ago an Adán Martin vídeo explaining parallax occlusion in 3d max and it was very interesting and with great results.
      Thanks in advance
      Last edited by luisgamino2; 30-07-2021, 04:51 AM.

      Comment


      • #4
        Originally posted by nikoleta.garkova View Post
        Hi henriqueb,

        OSL materials and textures can be loaded from a manually created vrmat containing TexOSL or MtlOSL plugins.
        Hi Nikoleta, i tried this code and other, but it doesn't work for me

        Code:
         /*
        * CG-Lion Surface-Car-Paint 1.0 OSL shader written by Oded Erell (c)2020 CG-Lion Studio
        *
        * Description:
        * Outputs a car-paint material (surface shader) combining 3 layers:
        * Base: A blend of diffuse/metallic shading with a view-angle color mix
        * Metallic flakes: Distance blended procedural metallic flakes
        * Clear coat: Glossy clear coat layer with built-in procedural bump irregularity
        *
        * This shader was tested in the following renderers:
        * Cycles for Blender 2.83 (CPU)
        * Arnold 6 for Maya 2020 (CPU)
        * V-Ray Next for 3ds max 2020 (CPU)
        *
        * For user manual and more info visit:
        * https://cg-lion.com/2020/07/25/freebie-advanced-car-paint-osl-shader/
        */
        
        #include "stdosl.h"
        
        // Calculates simplified Fresnel reflection weight (Schlick's approximation)
        // * Needed because some systems dont support the microfacet closure's built in Fresnel
        float simple_fresnel(normal nrm, float ior)
        [[ string help = "Calculate Fresnel reflection weight (Schlick's approximation)" ]]
        {
        float r = pow( ( 1.0 - ior ) / ( 1.0 + ior ), 2.0 );
        return r + ( 1.0 - r ) * pow( 1.0 - fabs( dot( -I, nrm ) ), 5.0 );
        }
        
        // Main surface shader:
        surface cglSurfaceCarPaint
        [[ string help = "customizable car-paint material (surface shader)" ]]
        (
        float base_layer_weight = 1.0
        [[ string help = "The base layer overall mix weight",
        float min = 0.0, float max = 1.0]],
        color base_color_facing = color( 0.6, 0.03, 0.02 )
        [[ string help = "The base layer facing color" ]],
        color base_color_side = color( 0.07, 0.005, 0.02 )
        [[ string help = "The base layer side color" ]],
        float base_color_blend_curve = 1.5
        [[ string help = "The base layer color blend curve power (1 = linear)",
        float min = 0.001, float max = 5.0]],
        float base_metallic = 0.5
        [[ string help = "The metallic mix weight of the base layer",
        float min = 0.0, float max = 1.0]],
        float base_dielectric_ior = 1.5
        [[ string help = "Base layer dielectric ior (also serves as metallic grasing angle reflection blend)",
        float min = 1.0, float max = 2.0]],
        float base_layer_roughness = 0.25
        [[ string help = "The base layer metallic and specular roughness",
        float min = 0.0, float max = 0.5]],
        float metallic_flakes_weight = 1.0
        [[ string help = "Metallic flakes overall mix weight",
        float min = 0.0, float max = 1.0]],
        color metallic_flakes_color = color( 0.8, 0.2, 0.1 )
        [[ string help = "Metallic flakes color" ]],
        float metallic_flakes_density = 1.0
        [[ string help = "Metallic flakes pattern density",
        float min = 0.001, float max = 1000.0]],
        float metallic_flakes_size = 0.3
        [[ string help = "Metallic flakes individual size (independent of pattern density)",
        float min = 0.0, float max = 0.5]],
        float metallic_flakes_roughness = 0.2
        [[ string help = "Metallic flakes metallic roughness",
        float min = 0.0, float max = 1.0]],
        float metallic_flakes_direction_spread = 0.1
        [[ string help = "The amount at which the metallic flakes deviate from the original surface normal direction",
        float min = 0.0, float max = 5.0]],
        float metallic_flakes_distance_fade = 2.0
        [[ string help = "Distance at which the metallic flakes fade completely",
        float min = 0.0, float max = 1000.0]],
        float metallic_flakes_distance_full = 0.5
        [[ string help = "Distance at which the metallic flakes are fully visible",
        float min = 0.0, float max = 1000.0]],
        float clear_coat_weight = 1.0
        [[ string help = "Clear coat layer weight",
        float min = 0.0, float max = 1.0]],
        float clear_coat_ior = 1.6
        [[ string help = "The dielectric Refractive Index of clear coat layer",
        float min = 1.0, float max = 5.0]],
        float clear_coat_roughness = 0.001
        [[ string help = "Clear coat specular roughness",
        float min = 0.0, float max = 1.0]],
        float clear_coat_bump_strength = 0.1
        [[ string help = "Clear coat procedural bump strength",
        float min = 0.0, float max = 100.0]],
        float clear_coat_bump_density = 1.0
        [[ string help = "Clear coat procedural bump density",
        float min = 0.0001, float max = 10000.0]],
        int vray_compatible = 0
        [[ string help = "Sets internal parameters for compatibility with V-Ray (should be either 0 or 1)",
        int min = 0, int max = 1]],
        float system_scale_unit = 1.0
        [[ string help = "Meter based system units scale",
        float min = 0.001, float max = 1000.0]],
        output closure color surface_out = 0
        [[ string help = "Final surface output" ]]
        )
        {
        // Get shading position in object-space:
        point os_pos = transform("common", "object", P) * system_scale_unit;
        
        // Set roughness values:
        float base_roughness = base_layer_roughness * ( 1.0 - vray_compatible ) + pow( base_layer_roughness, 0.5 ) * vray_compatible;
        float flakes_roughness = metallic_flakes_roughness * ( 1.0 - vray_compatible ) + pow( metallic_flakes_roughness, 0.5 ) * vray_compatible;
        float coat_roughness = clear_coat_roughness * ( 1.0 - vray_compatible ) + pow( clear_coat_roughness, 0.5 ) * vray_compatible;
        
        // Base layer:
        // Calculate base layer Fresnel (Schlick) specular mix:
        float base_fr = simple_fresnel(N, base_dielectric_ior);
        // Calculate the linear facing ratio between 0 - 90 degrees (in randians):
        float facing_ratio = acos(fabs(dot(-I, N))) / M_PI_2;
        // Apply power curve to the calculated facing ratio:
        float facing_ratio_curved = pow(facing_ratio, base_color_blend_curve);
        // Mix the base layer color:
        color base_color_final = ((base_color_facing * (1 - facing_ratio_curved)) + (base_color_side * facing_ratio_curved));
        
        // Metallic flakes layer:
        // Apply internal factor to flakes pattern scale
        float flakes_scale = metallic_flakes_density * 1000;
        // Calculate camera dostance for shading point:
        float cam_dist = length( P - point("camera",0.0, 0.0, 0.0) ) * system_scale_unit;
        // Calculate flakes view distance fade:
        float flakes_distance_blend = 1.0 - clamp( cam_dist - metallic_flakes_distance_full, 0.0, 1.0) / ( metallic_flakes_distance_fade - metallic_flakes_distance_full );
        // Calculate metallic flakes final mix weight:
        float flakes_weight = metallic_flakes_weight * flakes_distance_blend;
        float flakes_mask = ( noise("usimplex", os_pos * flakes_scale) >= (1.0 - metallic_flakes_size) ) * flakes_weight;
        vector flakes_normal_source = ( noise( "cell", os_pos * flakes_scale ) * 2.0 ) - vector(1.0);
        normal flakes_normal = normalize( mix( N, flakes_normal_source, metallic_flakes_direction_spread ) );
        
        // Clear coat layer:
        // Clear normal bump multipy by internal factors (to keep input values convenient):
        float coat_bump_density = clear_coat_bump_density * 100.0;
        float coat_bump_strength = clear_coat_bump_strength * 0.075;
        // Caculate clear coat normals:
        vector coat_normal_source = noise( "perlin", os_pos * coat_bump_density );
        normal coat_normal = normalize( mix( N, coat_normal_source, coat_bump_strength ) );
        // Caculate clear coat Fresnel (Schlick):
        float coat_fr = simple_fresnel(coat_normal, clear_coat_ior);
        
        // Define Closures (BSDF's) and final shader output:
        closure color base_layer;
        closure color base_layer_dielectric = base_color_final * diffuse(N);
        closure color base_layer_metallic = base_color_final * microfacet ("ggx", N, base_roughness, 0.0, 0);
        base_layer = base_layer_dielectric * (1 - base_metallic) + base_layer_metallic * base_metallic;
        base_layer = base_layer * (1 - base_fr) + microfacet ("ggx", N, base_roughness, 0.0, 0) * base_fr;
        closure color metallic_flakes_layer;
        metallic_flakes_layer = metallic_flakes_color * microfacet ("ggx", flakes_normal, flakes_roughness, 0.0, 0);
        closure color base_Plus_flakes = ( base_layer * base_layer_weight ) * (1 - flakes_mask) + ( metallic_flakes_layer * metallic_flakes_weight ) * flakes_mask;
        closure color clear_coat_layer;
        clear_coat_layer = microfacet("ggx", coat_normal, coat_roughness, 0.0, 0);
        float clear_coat_final_weight = coat_fr * clear_coat_weight;
        surface_out = base_Plus_flakes * (1.0 - clear_coat_final_weight) + clear_coat_layer * clear_coat_final_weight;
        }
        I just changed the file extension to vrmat

        Comment


        • #5
          Does it works with vray gpu!!!???
          thanks in advance

          Comment


          • #6
            Hi luisgamino2 ,

            The OSL support is still in an experimental stage and as Nikoleta explained you need to import a .vrmat containing TexOSL or MtlOSL to see it appear in the asset editor.
            There is no way to create those in the Asset Editor directly.

            Here's an archive with two example vrmats: OSL.zip

            The workflow is:
            1. Import one of the vrmats in the Asset Editor using the Open button
            2. Load the OSL texture/material file in the OSL shader - UI for this is going to be generated
            3. Write the name (as a string) of the Output parameter that you want to use for shading
            A big limitation right now is that no user-defined OSL parameters will get populated in the UI.
            This means that you basically have to hard-code the values in the OSL shader itself.
            Supporting the user parameters is quite a challenging task but something we'll add support for in the future.

            Hope that clarifies things a bit,
            Konstantin

            Comment


            • #7
              Hi Konstantin
              don't worry i can understand that, it's not than important for me, i would prefer a better suport for vray gpu, for example two sided material the option multiply the front material diffuse doesnt work with vray gpu, and it gives more realism to the two sided material with cpu

              thanks in advance

              Comment


              • #8
                How about OSL? Don't we have news?

                Comment

                Working...
                X