Helper shaders

Here are the helper shaders currently implemented in the layering package:

The 'adapter' shader mila_adapter

Mixing other shaders with layering shader is not currently recommended, since it will not use shared light lists, and be able to use LPE multi-pass control, among many things. It may be of some use in the future. All shaders participating in the layering shade tree (i.e. any shader plugged into mila_layer or mila_mix) must be able to participate properly in internal layering communications for passing component weights and other data.

mila_adapter
declare shader 
    color
    "mila_adapter" (
        color   "input",
        array struct "passes" {
            string "path",
            color  "output",
            boolean "comp"
        }
    )
    version 1
    apply texture
end declare

Though not recommended, to use this shader, plug in some other non-layering shader into it's inputs. It will (as well as possible) turn the shader into something that works with the layering shader system.

A couple of rules must be followed:

Glossy helper shader mila_get_roughness

The mia material uses glossiness as an input parameter. This small helper shader simply inverts glossiness to make roughness used by mila_glossy_* shaders.

mila_get_roughness
declare shader scalar "mila_get_roughness" (
        scalar "glossiness" 
    )
    apply texture
    version 1
end declare
glossiness
is the glossiness ranging from 0 being mirror-like to 1 being diffuse like, inverted from roughness.

Bump helper shader mila_get_normal

Many older mental ray bump mapping shaders simply modify the normal - the mila_layer and mila_mix shaders require the modified normal as a vector input.

This small helper shader simply calls some shader (generally such a bump shader), and then returns the modified normal.

mila_get_normal
 declare shader vector "mila_get_normal" (
         shader "shader" 
     )
     apply texture
     version 1
 end declare
shader
is the shader which perturbs the normal.

To use this shader with the 3ds max DCC application, use the shader max_Bump (supplied with 3ds max) into which the actual texture shaders (e.g. max_Bitmap) are plugged.

Example:

    max_Bitmap  =>  max_Bump.Map  =>  mila_get_normal.shader => mila_layer.components[x].bump

Car paint helper shader mila_flakes_adapter

mila_flakes_adapter
declare shader 
   struct {
       vector "normal",
       color  "color"
   }
   "mila_flakes_adapter" (
        color  "tint",
        shader "flakeshader"
    )
    apply texture
    version 1
end declare

This shader exists solely to interface with the mi_flakes_bump shader from the paint library. That shader has a very special behavior where it takes a color, modifies it, and returns the color and modifies the normal in a single operation.

This helper shader takes the given color and calls the flakeshader (which must be an instance of mi_flakes_bump and returns the modified color and the normal as separate outputs, to be connected to the appropriate inputs of the layering shaders.

Car paint helper shader mila_bump_flakes

>

This shader assists in car paint component combinations to simulate flakes effecting both a normal change and a visibility factor.

See the car paint examples here for a use case.

declare shader
    struct {
        vector "normal",
        scalar "visibility"
    }
    "mila_bump_flakes" (
        scalar  "weight"       default 1.0,
        scalar  "density"      default 0.5,
        scalar  "perturbation" default 0.8,
        scalar  "scale"        default 0.2,
        integer "type"         default 0,    
        integer "cell_style"   default 0,    #: enum "edgy:circular"
        scalar  "circle_size"  default 0.5
    )
    apply texture
    version 4
end declare
weight
is the incoming weight which is multiplied by other calculated factors to eventually determine outgoing visibility shader which perturbs the normal.
density
used to affect visibility, increasing or decreasing as if it affects the absorption of light by a painted layer containing flakes. In a sense, models how much flake is seen over the underlying layers.
perturbation
is general amount of normal change caused by the flakes. Less perturbation is less normal change, flatter flakes.
scale
is scale of the size of the flakes.
type
is the type of the noise creating the flakescale of the size of the flakes: 3 variants on two types of noise, distortion and cellular: "distortion1:distortion2:distortion3:cellular1:cellular2:cellular3".
cell_style
is the cell shape when using cellular noise, either edgy (0) or circular (1).
circle_size
is the size of the circle if use circular cell style.

Base Hair helper shader mila_shift_normal

This shader shifts normals for the separate components of the base hair: Primary Reflection (R), Transmission (TT), Secondary Reflection (TRT), Secondary Reflection Glint Right and Left lobes(TRT Glint R/L).

declare shader 
    vector "mila_shift_normal" (
        integer "mode"          default 0, #: enum "hair_R:hair_TT:hair_TRT:hair_TRT_glint_R:hair_TRT_glint_L"
        scalar  "u_offset"      default 0.0,
        scalar  "v_offset"      default 1.0
    )
    version 1
    apply texture
end declare

Base Hair helper shader mila_hair_base_normal

This shader shifts normals at the most base level to change from ribbon to cylindrical hair shaped geometry. In mental ray, hair is modeled as ribbons facing the camera / eye. This is a method to emulate cylindrical geometry by changing the normal. Not necessary if using fully modeled geometry for hair tubes.

declare shader 
    vector "mila_hair_base_normal" (
    )
    version 1
    apply texture
end declare

Base Hair helper shader mila_color_sqrt

This shader takes square root of color, useful for hair color absorption, of half distance.

declare shader 
    color "mila_color_sqrt" (
        color "color"
    )
    version 1
    apply texture
end declare

Base Hair helper shader mila_hair_color

This shader creates hair tint color from base and tip colors.

declare shader 
    color "mila_hair_color" (
        color "base_color"    default 0.3 0.3 0.2 1,
        scalar "base_noise"   default 0,
        color "tip_color"     default 0.6 0.6 0.4 1,
        scalar "tip_noise"    default 0        
    )
    version 1
    apply texture
end declare
base_color
is the color at the base of the hair.
base_noise
not implemented noise factor for base color. In order to vary per hair.
tip_color
is the color at the tip of the hair.
tip_noise
not implemented noise factor for tip color. In order to vary per hair.

Base Hair helper shader mila_hair_scalar

This shader creates hair tint scalar from base and tip scalars.

declare shader 
    scalar "mila_hair_scalar" (
        scalar "base_scalar"  default 0.,
        scalar "base_noise"   default 0,
        scalar "tip_scalar"   default 1,
        scalar "tip_noise"    default 0        
    )
    version 1
    apply texture
end declare
base_scalar
is the scalar at the base of the hair.
base_noise
not implemented noise factor for base scalar. In order to vary per hair.
tip_scalar
is the scalar at the tip of the hair.
tip_noise
not implemented noise factor for tip scalar. In order to vary per hair.

Base Hair helper shader mila_scalar_to_vector

This shader makes a vector from a scalar, repeating the scalar value to x, y, z channels of vector.

declare shader 
    vector "mila_scalar_to_vector" (
        scalar "scale"
    )
    version 1
    apply texture
end declare
scale
is the scalar that is repeated for all three dimensions of the vector.

A physical light shader matched for mila materials mila_light

This shader serves in place of physical light, as it also adds functionality for texture mapping, as well as splitting color and intensity for typical light integrations.

declare shader
	color "mila_light" (
		color		"color",
		scalar		"intensity",
		scalar		"cone",	
		scalar		"threshold",# accuracy threshold for optimization
		scalar		"cos_exp"   # cosine exponent (disc&rectangle)
	)
	version 1
	apply light
end declare
color
is the color of the light.
intensity
multiplies by the color of the light.
cone
is the inner solid cond for the spotlight, when used as a spotlight shader.
threshold
is the accuracy threshold for optimization when the light contributes insignificantly to the final rendered image.
cos_exp
is the cosine exponent for the disc, rectangle and object area lights. As the cosine is set by the face of the area light geometry compared to the direction from the light. This arguement can enhance that curve from directly facing (factor 1.0) to glancing faces (factor close to 0).