OgreMax Scene Exporter for 3DS Max - Using Shader Programs

Using Shader Programs

Shader programs are used by OgreMax Passes. Before they can be used, however, the OgreMax environment needs to be configured:

1. Write the shader code files - These will be written in HLSL, GLSL, or CG. Here is a sample HLSL file named AmbientOneTexture_vs.hlsl: `
   void main
   (
   float4 position : POSITION,
   float2 uv : TEXCOORD0,
   out float4 outPosition : POSITION,
   out float2 outUv : TEXCOORD0,
   out float4 outColor : COLOR,
   uniform float4x4 worldViewProj,
   uniform float4 ambientColor
   )
   {
   outPosition = mul(worldViewProj, position);
   outUv = uv;
   outColor = ambientColor;
   }`
2. Write the Ogre shader program files - The Ogre programs are typically stored in .program files and define which shader code files are referenced, entry points, and default parameters. You should define as many default parameters as possible. This will reduce the amount of configuration you need to do once your OgreMax material references the program. Here is a sample program file named AmbientOneTexture_hlsl.program `
   vertex_program AmbientOneTexture_hlsl hlsl
   {
   source AmbientOneTexture_vs.hlsl
   entry_point main
   target vs_1_1
   default_params
   {
   param_named_auto worldViewProj worldviewproj_matrix
   param_named_auto ambientColor ambient_light_colour
   }
   }
   `
3. Configure the OgreMax Scene settings - In the OgreMax Scene Settings dialog, under the Ogre tab, add the directories containing your shader code files and Ogre program files to the list of resource locations.

4. Create an OgreMax material - Create an OgreMax material in the material editor, add a technique, then add a pass to the technique. In the pass you can select the programs to reference under one of the shader rollouts. Once a program is selected, its user interface controls will appear:

   If there are no shader programs to select, or no user interface controls appear, it's because:

   - There are mistakes in the shader or program files.
   - The shader programs aren't written for the current rendering system. For example, GLSL programs won't appear if a Direct3D rendering system is active. Change the current rendering system if necessary.
5. Modify shader parameters - Changes made to the shader parameters will be displayed in real time in the OgreMax Material Viewer.