![]() |
![]() |
![]() |
Effect Class |
Language: |
Used to set and query effects and choose techniques.
Visual Basic .NET NotInheritable Public Class Effect
Inherits BaseEffectC# public sealed class Effect : BaseEffect Managed C++ public __gc __sealed class Effect : public BaseEffect JScript .NET public class Effect extends BaseEffect
An effect object can contain multiple techniques to render the same effect.
Using an Effect
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.
- Create or obtain access to a high-level shader language (HLSL) file (.fx).
- Load the HLSL file using Effect.FromFile.
- Set Effect.Technique with the effect's technique.
- Use Effect.Begin to obtain the number of passes for the effect.
- Create a loop to iterate through all of the effect's passes. Rendering an effect occurs within a loop between calls to Effect.BeginPass and Effect.EndPass. The loop itself is nested between calls to Effect.Begin and Effect.End.
- Render each pass within the loop with calls to Effect.BeginPass, Device.DrawPrimitives, and Effect.EndPass.
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(); . . . }
Namespace Microsoft.DirectX.Direct3D Assembly Microsoft.DirectX.Direct3DX (microsoft.directx.direct3dx.dll) Strong Name Microsoft.DirectX.Direct3DX, Version=1.0.2902.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
Feedback? Please provide us with your comments on this topic.
For more help, visit the DirectX Developer Center