Using mental mill shaders in FX Composer 2 - NVIDIA · Note: In FX Composer, a .cgfx or an .hlsl...

4
Using mental mill shaders in FX Composer 2.5 | © 2010 mental images page 1 of 4 This document describes how to export shading networks, shaders and Phenomena from mental mill so that they can be imported and used in NVIDIA’s™ FX Composer. A basic knowledge of how to work with mental mill and FX Composer 2.5 is assumed. If you are not familiar with these tools, consult the FX Composer help files. Preparing your shader in mental mill Before you export a shader from mental mill to another application, you need to ensure that you have a light source available. If your Graph or Phe- nomenon contains nodes with reflections, such as the Component_reflection, you also have to create an environment shader instance for this. This section explains how to perform these tasks. Creating a light source Follow the steps to create a light source and add it to the shader that you want to export: 1. Go to the Toolbox and drag and drop a light shader of your choice on to the workspace. 2. Go to Render> Scene Settings and click Add light. The Select Light Shader dialog box opens. 3. From the list, select the light shader that you want to apply to the light source. 4. Click OK. The dialog box closes and the light shader is added to the Light List. About multiple light sources You can create multiple light instances from one shader. These instances share the input data such as color, falloff, etc. For each light source, you should instantiate light shaders on the workspace. When you add a light to your Light List, choose a different light shader for each light. Two lights should not use the same light shader. A shader graph in mental mill 1.1 Using mental mill shaders in FX Composer 2.5

Transcript of Using mental mill shaders in FX Composer 2 - NVIDIA · Note: In FX Composer, a .cgfx or an .hlsl...

Using mental mill shaders in FX Composer 2.5 | © 2010 mental images page 1 of 4

This document describes how to export shading networks, shaders and Phenomena from mental mill so that they can be imported and used in NVIDIA’s™ FX Composer.

A basic knowledge of how to work with mental mill and FX Composer 2.5 is assumed. If you are not familiar with these tools, consult the FX Composer help files.

Preparing your shader in mental mill

Before you export a shader from mental mill to another application, you need to ensure that you have a light source available. If your Graph or Phe-nomenon contains nodes with reflections, such as the Component_reflection, you also have to create an environment shader instance for this. This section explains how to perform these tasks.

Creating a light source

Follow the steps to create a light source and add it to the shader that you want to export:

1. Go to the Toolbox and drag and drop a light shader of your choice on to the workspace.

2. Go to Render> Scene Settings and click Add light. The Select Light Shader dialog box opens.

3. From the list, select the light shader that you want to apply to the light source.

4. Click OK. The dialog box closes and the light shader is added to the Light List.

About multiple light sources

You can create multiple light instances from one shader. These instances share the input data such as color, falloff, etc. For each light source, you should instantiate light shaders on the workspace. When you add a light to your Light List, choose a different light shader for each light. Two lights should not use the same light shader.

A shader graph in mental mill 1.1

Using mental mill™ shaders in FX Composer 2.5

Using mental mill shaders in FX Composer 2.5 | © 2010 mental images page 2 of 4

Creating an environment shader

To create en environment shader, follow the steps below:

1. Go to Render> Scene Settings, and open the Environment Shader menu.

2. Select an environment shader from the list.

Note: For more information, see How to set preview rendering preferences, in the Output Preview chapter of the Standard Edition User Guide. You can access the User Guide from the Help menu of mental mill.

Saving your shader to export

To export your shader, follow the steps below:

1. Go to File> Export. The Export options dialog box opens.

2. From the Export Format menu, select FX Composer (HLSL/CGFX).

3. Go to the File name field and click the Browse to button. The Save an FX Composer dialog box opens.

4. Browse to the file location on your file system where you want to save your exported shader file.

5. Click Save and then OK. Your shader is now ready to be exported to FX Composer.

For more information, see Exporting the shader in the Standard Edition User Guide. You can access the User Guide from the Help menu of mental mill.

Note: Before you export a shader, you should instantiate the number of lights that you want to use. The light shaders are baked into the exported code. For example, if you want your shader to support three light sources, make sure that you have three lights instantiated in the Scene Settings in mental mill.

Loading and using your exported shader in FX Composer 2.5

In FX Composer 2.5, it is possible for you to load shaders for a variety of target platforms such as CgFX or HLSL. Since these two renderers are very different, it is not possible to combine HLSL and CgFX shaders.

1 The first view uses a CgFX file to render with OpenGL.

2 The second view shows the HLSL version of the same shader.

3 The third view shows a shader used in the wrong context: An HLSL shader cannot be compiled for OpenGL usage, so the object is drawn as a red wireframe, thus indicating a failure.

1 2 3

Using mental mill shaders in FX Composer 2.5 | © 2010 mental images page 3 of 4

Note: In FX Composer, a .cgfx or an .hlsl file is called an Effect once it is loaded into the application.

To load a mental mill shader in FX Composer, follow the steps below:

1. Open FX Composer and check that the Assets pane is displayed. If the Assets pane is not open by default, go to the View menu and select Assets.

2. In the Assets pane, right-click Effects and select Add Effect From File.

3. Browse to the file you previously saved in mental mill and open it. The file displays under the Effects section of the Assets pane.

4. Drag and drop the effect from the Effects section on to the geometry that is displayed inside the Render window.

Creating a light source

In FX Composer light positions are automatically linked to your shader. You just need to add a corresponding light source.

To create a light source in FX Composer, follow the steps below.

1. Go to the Assets pane and right-click Lights.

2. Select a light type.

Alternatively, you can click one of the light sources in the Asset Creation toolbar.

Dragging the exported shader on to the geometry

Creating a light source

Using mental mill shaders in FX Composer 2.5 | © 2010 mental images page 4 of 4

Editing the shader code

One reason why FX Composer is widely used among shader developers is because of the built-in editor that allows you to develop a shader, compile it and see the resulting effect immediately. If you want to fine-tune your effect, you can apply changes to your exported shader. Follow the step below to edit a shader:

◼ Open the Assets panel and double-click the file you imported from men-tal mill. Alternatively, you can right-click the file and select Edit from the menu.

Important: To edit a shader, you need to have advanced shader writing knowledge. To learn more about shader writing, consult CG Toolkit Users Manual: A Developer’s Guide to Programming Graphics. This document is part of the CG Toolkit and can be downloaded from www.nvidia.com.

Known issue

When using HLSL FX|files, sometimes the lights do not display in the Properties panel. To solve this, you need to drag and drop them. Once you have finished editing your shader code, compile it by pressing Ctrl + F7. You can check any compilation errors inside the output area of the Task panel.

The shader editor in FX Composer 2.5

Teapot rendered with an HLSL shader that was created and exported using mental mill