Connecting scene properties to materials
Many of FX Composer's scene properties can be hooked up to
material properties, enabling effect files to gain information
about the currently rendered scene.
Automatically connected values
At the simplest level, it's possible to access various scene values by
applying semantics to variables in the file. For example:
-
float3 Pos : CAMERAPOSITION
This declares a float3 which always contains the current camera position
in world space. Another example would be:
-
float2 Size : VIEWPORTPIXELSIZE
This declares a float2 which contains the size in pixels of the current
render target.
Manually connected values
It's possible to connect values manually using the properties panel,
assuming they have been declared correctly. For example, the
following declaration creates a float property which contains a light
umbra value:
-
float umbra : LIGHTUMBRA
<
string object = "spotlight";
>
The annotation informs FX Composer that this value can be connected to a
light. When the effect is first loaded FX Composer should
automatically connect it to the first light, but the connection can also
be changed in the properties panel. Simply click on the 'umbra'
parameter, and this will bring up a 'connection' dialog which can be
used to choose the light to connect.
To discover semantics such as LIGHTUMBRA, look in the online help under
"Annotations & Semantics", or select the object in question and bring up
the properties dialog for it. Clicking the parameter name should
show the full declaration in the connection box, along with the semantic
required to access it. The scene's global properties are also
available by right clicking an empty area of the scene and choosing
'properties'.
A more complex parameter might be:
-
float3 LightPosView: POSITION
<
string space="view";
>
This declares a position variable which is required to be in 'view'
space. When a light is connected to this parameter, FX Composer
knows that it needs to supply the value in view space. It does
this by running a small virtual machine to do the transform, each time
the light position changes. You can see this code by
clicking on the connection dialog for the LightPosView parameter.
All connections are saved in the FX Composer project files, so that the
scene is correct when reloaded.
|