Effect.FromFile(Device,String,Include,String,ShaderFlags,EffectPool) Method (Microsoft.DirectX.Direct3D)
How Do I...?
- Using an Effect
Creates an effect from an ASCII or binary effect description.
Definition
Visual Basic Public Shared Function FromFile( _
ByVal device As Device, _
ByVal sourceDataFile As String, _
ByVal includeFile As Include, _
ByVal skipConstants As String, _
ByVal flags As ShaderFlags, _
ByVal pool As EffectPool _
) As EffectC# public static Effect FromFile(
Device device,
string sourceDataFile,
Include includeFile,
string skipConstants,
ShaderFlags flags,
EffectPool pool
);C++ public:
static Effect^ FromFile(
Device^ device,
String^ sourceDataFile,
Include^ includeFile,
String^ skipConstants,
ShaderFlags flags,
EffectPool^ pool
);JScript public static function FromFile(
device : Device,
sourceDataFile : String,
includeFile : Include,
skipConstants : String,
flags : ShaderFlags,
pool : EffectPool
) : Effect;
Parameters
device Microsoft.DirectX.Direct3D.Device
The Device that creates the effect.sourceDataFile System.String
A String object that indicates the file name.includeFile Microsoft.DirectX.Direct3D.Include
Optional Include object to use for handling #include directives. If this value is null, #include directives are either honored when compiling from a file, or cause an error when compiled from a resource or memory.skipConstants System.String
A string of effect parameters that will be ignored by the effect system. The string must be NULL terminated and needs to contain the name of each application-managed constant separated by a semicolon.flags Microsoft.DirectX.Direct3D.ShaderFlags
One or more compile options identified by the ShaderFlags enumeration.pool Microsoft.DirectX.Direct3D.EffectPool
An EffectPool object to use for shared parameters. If this value is null, no parameters are shared.
Return Value
Microsoft.DirectX.Direct3D.Effect
An Effect that contains the compiled effect.
Remarks
Exceptions
The method call is invalid. For example, a method's parameter might contain an invalid value.
The data is invalid.
Microsoft Direct3D could not allocate sufficient memory to complete the call.
How Do I...?
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(); . . . }
See Also