Your Ad Here

Setting Up a Fragment (Pixel) Shader

To set up a fragment shader on an object

1. Open a render tree (press 7) and connect an OGL Draw shader (Nodes > Realtime OpenGL > OGL Draw) to the realtime port of the object’s Material node.

 

2. Connect a Cg Program node (Nodes > Realtime Cg > Cg Program) to the OGL Draw node’s previous port.

 

3. Double-click the Cg Program node to open its property editor and start typing your code.

But first, let take a look at what’s in the property editor.

 

• The Build options allow you to do any one of the following:

- Disable the Cg Program.

- Compile the program without executing it.

- Compile and execute the program.

• You can see compilation results by activating the Debug messages option.

 

Compilation results are logged and available from the script editor’s log window.

• The Profile options let you choose the type of program you want to execute. This is where you specify which hardware you are targeting and whether it’s a vertex or a pixel (fragment) program.

 

If you are not specifically targeting nVidia hardware, you should choose the ARB types.

In the property editor shown above, the parameters were set as follows:

• A Cg Program was typed in the text box.

• The Build option was set to Compile and execute.

• The Debug messages were activated.

• The Profile was set to ARB Fragment Program.

You can see that the compilation succeeded in the script editor log window, where the following appeared:

'Program is compiled
'LAST LISTING--------
'---- PROGRAM BEGIN ----
'!!ARBfp1.0
'# ARB_fragment_program generated by NVIDIA Cg compiler
'# cgc version 1.2.0001, build date Feb 19 2004  10:44:56
'# command line args: -q -profile arbfp1 -entry main
'#vendor NVIDIA Corporation
'#version 1.0.02
'#profile arbfp1
'#program main
'#semantic main.TestColor_red
'#var float TestColor_red :  : c[0] : 1 : 1
'#var float4 color : $vin.COL0 : COL0 : 0 : 1
'#var float4 main : $vout.COLOR : COL : -1 : 1
'PARAM u0 = program.local[0];
'PARAM c0 = {0, 0, 0, 1};
'TEMP R0;
'MOV R0.x, u0.x;
'MOV R0.yzw, c0;
'MUL result.color, fragment.color.primary, R0;
'END
'# 3 instructions, 1 R-regs, 0 H-regs.
'# End of program

Setting Pixel Shader Parameters

Now that you have your program code written, you have to set the values for the uniform parameters. You can use the same techniques as the vertex shader parameters. These include:

• Softimage semantics, which are described [here].

• Custom parameter sets, which are described [here].

• The Cg Matrix, CgVector, Cg Color, or Cg Light tracker shaders, which are described [here].

Texture Map Relationships

You can also specify sampler2D and samplerCUBE as types for uniform parameters. These are mapped to the texture targets that are set for the current drawing pass. For example, if your program specifies the following uniform parameters...

...
uniform sampler2D      normalmap,
uniform samplerCUBE    normalizationmap,
uniform sampler2D      diffusemap
...

...you will need to use three texture nodes to reflect that sequence:

• One OGL Texture set in target 0 to map to the normalmap parameter.

• One OGL Cubic Texture set in target 1 to map to the normalizationmap parameter.

• One OGL Texture set in target 2 to map to the diffusemap parameter.



SOFTIMAGE|XSI v.6.01     

Return to Softimage XSI Index


Your Ad Here