hs_velvet.mel

 

The hs_velvet.mel is a script that creates a velvet kind of layer.

To execute it, first source the script by typing in the script editor: source hs_velvet.mel

In order to make it work correctly, you need to select your shader (whatever shader type you want: blinn, phong, phongE, lambert, ...) and type in the script editor: hs_velvet.

note: The selected shader needs to be assigned to a surface or else you'll get an error message (and you'll just have to connect it manually to the surface)

The script creates 2 surfaceShader: the velvet (with xtras attributes to control it) and a top_velvet_layer (which is applied instead of your original shader)

If you have more than one shader, you'll have to re-execute the script for each shader, but the velvet shader will not be duplicated, the scripts will re-connect what's needed.

 

How it works?

- The velvet layer is in fact a surfaceShader which is on top of the shading network.
To control the velvet effect, you have some extras attributes added to the velvet sufaceShader.

* Color: is just the color of the surfaceShader. Modify it as you want.
* Orientation: Shows the dummy directional light's orientation (attribute readable only)
* Type: Enter a type value (1 to 6) of the velvet. In fact, the type is directly connected to a ramp. So modifying the type is the same as modifying a ramp's type (1 = linear, 2 = exponential up, 3 = exponential down, 4 = bump, 5 = smooth, and 6 = spike)
* Spread: Controls the spread of the velvet (0 = almost none, 1 = very large and soft (according the velvet's type you've selected)

Now you know how to control, let's see how you set the velvet in your scene.

During the script process, a directional light is created. Actually it's a dummy light (intensity 0 and color 0 0 0).
The shader just need its orientation (lightDirection) to force the velvet to be 'aligned' regarding the light's direction and the normalCamera.

So, select the directional light called backLight (the shape), and orient it to 'fit' with your keyLight. (you can orient-constrain the backLight to your keyLight) You'll see the orientation of the velvet changing.

The dummy light casts shadows. This is to prevent from having some velvet in a supposed to be in shadow area. This is done with the lightShadowFraction attribute. So each time you change the dummy light's orientation, update the shadows in IPR (if you use IPR).
Note: if you don't like this shadow feature, just connect the blendColor node called blend_materials into the top_velvet_layer (surfaceShader) or more simple, check off the cast shadow of the directional light.

Here you can see before and after applying the velvet script to a shader.

 

Limitations:

- If you select a shader not assigned to a surface, you'll get the following error message:
// Error: No renderable object is selected for assignement //
This is normal. Just select your surface and apply the top_velvet_layer surfaceShader to it.

- If you have bad results with the velvet, try to check off the cast shadow attribute of the dummy light.

download the script

 

hs_velvet.mel - (c) Emmanuel Campin - April 3rd 2001