Porting a shader

From Unify Community Wiki
Revision as of 20:17, 23 December 2008 by Tgraupmann (Talk | contribs)

Jump to: navigation, search



This document aims to provide some guidelines for porting shaders between FX composer, RenderMonkey, Mental Mill, ShaderFX, and Unity3d. Porting shaders is a manual process. But most of the work is just copy paste. And there are some slight semantic differences on each platform.

Shader Applications

There are several applications that facilitate shader development and prototyping:
  • ShaderFX - A max plugin capable of exporting to FX composer. Similar to Mental Mill to be used by artists.
  • Mental Mill - An artist shader development application bundled with FX Composer similar to ShaderFX, but in a free flavor.
  • Unity - Our target shader platform

Getting Shader Help

  • AMD - Developer forums

Shader Porting Practice

I found it helpful to first port the shader to FX composer. When comparing your ported shader it makes a good base to compare to. Before porting to Unity, I attempted a port to RenderMonkey first. That way I could identify all the correct semantics to use. And lastly I ported to Unity while checking the docs and chat for the Unity semantics.

RenderMonkey has a StreamMapping that controls the mapping of semantics into your vertex and shader programs. You likely need to double click the stream mapping outside of the pass and provide Normal, Tangent, and Binormal information. They should all map to index 0. And use names like rmTangent, rmBinormal, and rmNormal.

Note, when using the vertex and fragment programs, the Unity ShaderLab binding parameters are created for you. So you don't want to provide that redudant/wrong information in your shader.

Vertex and Fragment programs likely have you define input and output structures. It's recommended that you use your vertex program output structure also for the fragment program input. Or else bad things could happen.

Using FX Composer

When using FX Composer you must first create a project.

Occasionally the FX Composer default layout gets messed up. So you'll want to restore the FX composer layout with View->Layouts->Reset layout.

In the materials pane, right click and select Add Material From File. Select your FX file (exported from ShaderFX perhaps). Then create some geometry to test the material. Create->Teapot. Then Drag your material from the material window to the RenderWindow and drop it on the Teapot.

Double click a material and click the Editor tab in the top middle pane to see the code.

FX composer FX files have their UI elements and shaders code in the same file. They still use the "uniform" keyword to link the UI variables to the shader code.
Personal tools