|
|
|
|
Using an Effect |
Language: |
This example demonstrates how to use an effect technique that was loaded from a file.
Add effects code to your rendering method, such as OnRender(), in-between calls to Device.BeginScene and Device.EndScene.
In the following C# code example, device is assumed to be the rendering Device.
[C#]
public void OnRender ()
{
.
.
.
// Load the effect from file.
Effect effect = Effect.FromFile(device, "shadercode.fx", null,
ShaderFlags.None, null);
// Set the technique.
effect.Technique = "ShaderTechnique";
// Note: Effect.Begin returns the number of
// passes required to render the effect.
int passes = effect.Begin(0);
// Loop through all of the effect's passes.
for (int i = 0; i < passes; i++)
{
// Set a shader constant
effect.SetValue("WorldMatrix", worldMatrix);
// Set state for the current effect pass.
effect.BeginPass(i);
// Render some primitives.
device.DrawPrimitives(PrimitiveType.TriangleList, 0, 1);
// End the effect pass
effect.EndPass();
}
// Must call Effect.End to signal the end of the technique.
effect.End();
.
.
.
}
Send comments about this topic to Microsoft. © Microsoft Corporation. All rights reserved.
Feedback? Please provide us with your comments on this topic.
For more help, visit the DirectX Developer Center