Each HLSL function can be converted into a shader fragment with the addition of a fragment declaration.
fragmentKeyword FragmentName = compile_fragment shaderProfile FunctionName();
where:
| fragmentKeyword | Required keyword. Either pixelfragment or vertexfragment. |
| FragmentName | An ASCII text string that specifies the compiled fragment name. |
| compile_fragment | Required keyword. |
| shaderProfile | The shader model to compile against. Any valid vertex shader profile (see D3DXGetVertexShaderProfile) or pixel shader profile (see D3DXGetPixelShaderProfile). |
| FunctionName() | The shader function name, followed by parentheses. |
Shared fragment parameters are marked by adding an 'r_' prefix to their semantic. Here is an example of a vertex shader fragment declaration from the FragmentLinker Sample:
void AmbientDiffuse( float3 vPosWorld: r_PosWorld,
float3 vNormalWorld: r_NormalWorld,
out float4 vColor: COLOR0 )
{
// Compute the light vector
float3 vLight = normalize( g_vLightPosition - vPosWorld );
// Compute the ambient and diffuse components of illumination
vColor = g_vLightColor * g_vMaterialAmbient;
vColor += g_vLightColor * g_vMaterialDiffuse * saturate( dot( vLight, vNormalWorld ) );
}
vertexfragment AmbientDiffuseFragment = compile_fragment vs_1_1 AmbientDiffuse();
In this example, the r_PosWorld and r_NormalWorld semantics identify that these two parameters are shared parameters among other fragments.