Friday, February 28, 2014

Wednesday, October 30, 2013

For-Loops

Setting up a for-loop with ShaderFX:


In this video we use an array node to provide 3 float2's for sampling the texture. You can of course also calculate some kind of UV offset based on the 'operator i'.

To use the 'operator i' inside your for-loop 'calculation', you select the 'String' node you used for the 'Operator'.

Set the 'Value Type' to 'Shader / Integer'.
This will change the 'As Value' output of the 'String' node to an integer you can now use in the rest of your node network inside the loop.



Tuesday, October 15, 2013

Nyra

Paul Tosca's beautiful Nyra model in Maya's DX11 viewport:


Tuesday, October 8, 2013

Working with UV sets

Working with UV sets in Maya and ShaderFX can be a bit confusing.
Here is how it works.

On the Texture Map node, or UV set node, there are two options:
1. UV set index
2. UV Set Name

You use one or the other.
If you don't rename your UV sets in Maya, the default names of your UV sets will be:

0: map1
1: uvSet
2: uvSet1
3: uvSet2 ... etc

When you choose to use the UV set index on the ShaderFX nodes, it will attempt to find a UV set by those names. So when you specify index 2, it will try to find a UV set with the name: uvSet1.

Not very obvious, but the default naming of UV sets in Maya is weird (why is 0 called "map1" and then the rest called "uvSet..." is not clear to me).

If, however, you give your UV sets a custom name, then you must specify its exact name on the Texture Map or UV Set node in ShaderFX.

For example, had we called our second UV set "LightMapUVs" then we must enter that exact name in the "UV Set Name" on the ShaderFX node.



Friday, October 4, 2013

Transparency

Using Transparency from textures or float values in ShaderFX is pretty easy, but you need to know to enable one or two settings on the Base Material node for it to work.

You connect your transparency value to the opacity socket on the Surface Shader (top).
Then enable the Opacity checkbox on the Base Material node.

You likely also want to disable the "Depth Write" checkbox so that transparent object do not block the rendering of objects behind them.

By default objects render double sided in the Maya view, if you do not want this, disable the "Double Sided" checkbox on the Shape node of the object.


You should get reasonable results, but keep in mind that Maya's viewport is not a game engine and so sometimes sorting is not perfect. There are some improvements you can get by switching to "Depth Peeling" transparency algorithm. This can be found in the Viewport 2.0 settings dialog.

Unfortunately in Maya LT this crashes, but I believe this will be fixed in SP 1.

Even with Depth Peeling things are not always sorting great. Hopefully we can improve this in the future.

Tuesday, October 1, 2013

V-Rex Maya 2014, Viewport 2.0 - DX11

This was too impressive not to post.
YOSUKE ISHIKAWA does such amazing real-time work:


Saturday, September 28, 2013

Empty group sockets

Sometimes when working with groups you end up with a few empty sockets inside the group and there is no button to remove these empty sockets (we may eventually add one).



But there is a way to get rid of them.

Empty sockets are removed during saving/Loading (saving and then loading the group or the scene).
So when you reload the group/scene the empty sockets will be gone, if the following conditions are met:

1. The label of the socket is empty (so it displays "any" as its label in the view)
2. There are no used sockets below it.
3. It is not the only empty socket (we always keep one empty socket)

Number 1 and 2 are are probably not that obvious, but the reason for it was if the user is in the middle of creating groups and saves a scene and goes home for the day, you don't want to loose your work and have to redo labeling or organizing your sockets.

In order to ensure a socket gets removed, you have to use the "Move Socket Up" button on any used sockets below it. (Which can also be a bit tedious to use at times, but it is what we have right now)

Here is the corrected group for which the unused sockets will get removed after save/load.
(Except for 1 'any' socket since we always keep one for users to add new connections)




Thursday, September 19, 2013

Sampling one texture with different settings

Some times you may want to sample a single texture with different settings, such as different UVs.

You can of course place down multiple "Texture Map" nodes and point them all to the same texture.
Then connect different UVs into each.

This works ok, but becomes a problem when you want to expose the texture path to the Attribute Editor as a parameter for artists to set when the node graph is closed. You really want  the artist to only have to supply the path to the texture once. 

When using Texture Map nodes, each would need to be visible to the AE in order for the path to be set. It would be strange for the artist to have to set the same texture in the shader multiple times. We can resolve this by constructing the sampling with your own set of nodes instead of using the Texture Map node.

To see these nodes, you should switch to "Advanced Mode" in the right-click menu.

You can look inside the Texture Map node for reference.

Here is an image with some explanation of how you can set this up:


The above example assumes you are using a regular 2D texture.
If you want to use a Cube texture, then you must also add a "Texture Type" node, set it to Cube and input it into each of the four nodes in the picture.

Tuesday, September 10, 2013

Working with Lights

A new video describing how you can work with lights inside Maya LT and ShaderFX


Friday, September 6, 2013

Valve DOTA2 hero in Maya LT using ShaderFX

I recreated Valve's DOTA2 hero shader using Maya LT and ShaderFX.
Download the DOTA2 ShaderFX graph here (v1.1)


I tried to stay true to the original shader code as much as possible.
To do that, I used a Custom Code node inside ShaderFX to paste Valve's original CGFX code into.

Then I decided to remove any CGFX specific semantics from the Shader.
By doing that, you can freely switch between OpenGL and DirectX11 with the same Maya LT scene and ShaderFX graph.

The only function I had to replace was a few calls to Tex2D().
I made those Tex2D calls "inputs" into the Custom Code node function and used the ShaderFX "Texture Map" node instead, which will automatically switch correctly between OpenGL and DX11.

It was about a day work to switch the code from the CGFX file over to a ShaderFX graph.
I had never seen the shader code before, so it took some time figuring out how it worked, but of course I had the benefit of knowing ShaderFX very well.

Another change I made was to add support for real-time shadows and point/spot/direction lights.
This was very easy, because I could re-use the "Light Contribution" group node in ShaderFX, which does all the magic for us.

I maintained the 1-light support for the shader.
Adding more lights would be easy, just bump up the "number of lights" property in the shader.
But the way I have structure the shader code in the custom code node, adding extra lights would mean we are not a very efficient shader anymore because every texture sample and calculation would be re-done inside the light loop.

For example, sampling the normal map texture would happen for every light!
Pretty waste full, but it can be fixed fairly easily if somebody wants to add extra lights.

It can be resolved by splitting the light dependent calculations and the rest of the calculations from the Custom Code node into two Custom Code nodes. Then use the "Inside Loop" and "After Loop" inputs on the "Socket Combiner" node. But my goal was to just reproduce as close as possible the original shader, so I did not do that work.

I love the graphics of Valve's DOTA2, it is a fantastic game. And seeing the models like this in Maya LT is quite rewarding. :)

Friday, August 30, 2013

ShaderFX custom code example

Here is an example of using the "Custom Code" node provided in ShaderFX to create a snow-layer effect.

We measure the angle between the vertex normal and the world UP (or "snow direction" if you wish) and blend in the white color on top of the rock texture.

We have a second custom code node that modifies the vertex position to give the snow some thickness.
Download Custom Code Snow ShaderFX graph


Example shaders in Maya LT

ShaderFX is a real-time shader editor build into Maya LT.
Below are some examples.

Matcap shader:
Download Matcap ShaderFX graph



Animated shader:
Download Animated Fire ShaderFX graph



Anisotropic and latlong reflections:
Download Anisotropic ShaderFX graph


ShaderFX is very customizable.
Most nodes are what I call "Group Nodes". Similar to e.g. compound nodes in XSI. For example you can go inside the Surface shader itself and poke around:



Blurring reflection maps based on procedural checker pattern:
Download Blurry Reflections ShaderFX graph



Blending normal maps with various options to blend:
Download Blending Normal Maps ShaderFX graph



Animated Surface Mask (Opacity Mask):
Download Surface Mask ShaderFX graph



An example of DirectX 11 tessellation and displacement:
Download Tessellation and Displacement ShaderFX graph


Mixing with vertex colors:
Download Vertex Colors ShaderFX graph


Wrinkle Map (sorry don't have a great face model/rig laying around):

The attribute on the locator drives the value in the shader.
In ShaderFX "Values nodes" (such as floats, colors, textures) have an option called "Input from Maya". When you enable this option, the value is exposed as a regular Maya Attribute in the dependency graph and can be connected to your rig:
Download Wrinkle Map ShaderFX graph


Translucency (Thickness map controls the density, in this case, a vein map):
Download Translucency ShaderFX graph