共用方式為


Effect Class (Microsoft.DirectX.Direct3D)

How Do I...?

  • Using an Effect

Used to set and query effects and choose techniques.

Definition

Visual Basic NotInheritable Public Class Effect
    Inherits BaseEffect
C# public sealed class Effect : BaseEffect
C++ public ref class Effect sealed : BaseEffect
JScript public final class Effect extends BaseEffect

Members Table

The following table lists the members exposed by the object.

Events

Event Description
Disposing Occurs when the Dispose method is called or when the Effect object is finalized and collected by the garbage collector of the .NET common language runtime.
Lost Occurs when an object is lost, normally just before a device is reset.
Reset Occurs after the Effect.OnResetDevice method is called or after the Device is reset.

Methods

Method Description
ApplyParameterBlock Assigns a state value to each effect parameter in a parameter block.
Begin Begins the application of an effect technique.
BeginParameterBlock Captures parameter effect state changes.
BeginPass Applies the state settings for the specified pass of a technique.
Clone Creates a clone of an effect.
CommitChanges Propagates the state change that occurs inside of an active pass to the device before rendering.
DeleteParameterBlock Deletes an effect parameter block.
Disassemble Disassembles an effect.
Dispose Immediately releases the unmanaged resources used by the Effect object.
Effect Initializes a new instance of the Effect class.
End Ends the application of the current effect technique.
EndParameterBlock Stops the capturing of effect parameter state changes.
EndPass Signals the end of an effect pass.
Equals Returns a value that indicates whether the current instance is equal to a specified object.
Finalize Allows the BaseEffect object to free resources before it is destroyed by the garbage collector. Inherited from BaseEffect.
FindNextValidTechnique Searches for the next valid technique, starting at the technique after the one specified.
static (Shared in Visual Basic) FromFile Creates an effect from an ASCII or binary effect description.
static (Shared in Visual Basic) FromStream Creates an effect from an ASCII or binary effect description.
static (Shared in Visual Basic) FromString Creates an effect from an ASCII or binary effect description in a string.
GetAnnotation Retrieves an annotation. Inherited from BaseEffect.
GetFunction Retrieves a function. Inherited from BaseEffect.
GetFunctionDescription Retrieves a function description. Inherited from BaseEffect.
GetHashCode Returns the hash code for the current instance.
GetObjectByValue This member supports the infrastructure for Microsoft DirectX 9.0 for Managed Code and is not intended to be used directly from your code.
GetParameter Retrieves a top-level parameter or a structure member parameter. Inherited from BaseEffect.
GetParameterBySemantic Retrieves the handle of a top-level parameter or structure member parameter by looking up its semantic. Inherited from BaseEffect.
GetParameterDescription Retrieves a parameter or annotation description. Inherited from BaseEffect.
GetParameterElement Retrieves the EffectHandle of an array element parameter. Inherited from BaseEffect.
GetPass Retrieves the EffectHandle of a pass. Inherited from BaseEffect.
GetPassDescription Retrieves a pass description. Inherited from BaseEffect.
GetTechnique Retrieves the EffectHandle of a technique. Inherited from BaseEffect.
GetTechniqueDescription Retrieves a technique description. Inherited from BaseEffect.
GetValue Retrieves the value of an arbitrary parameter or annotation, including simple types, structures, arrays, strings, shaders, and textures. Inherited from BaseEffect.
GetValueBoolean Retrieves a Boolean value. Inherited from BaseEffect.
GetValueBooleanArray Retrieves an array of Boolean values. Inherited from BaseEffect.
GetValueColor Retrieves a ColorValue structure. Inherited from BaseEffect.
GetValueColorArray Retrieves an array of ColorValue structures. Inherited from BaseEffect.
GetValueFloat Retrieves a floating-point value. Inherited from BaseEffect.
GetValueFloatArray Retrieves an array of floating-point values. Inherited from BaseEffect.
GetValueInteger Retrieves an integer. Inherited from BaseEffect.
GetValueIntegerArray Retrieves an array of integers. Inherited from BaseEffect.
GetValueMatrix Retrieves a nontransposed matrix. Inherited from BaseEffect.
GetValueMatrixArray Retrieves an array of nontransposed matrices. Inherited from BaseEffect.
GetValueMatrixTranspose Retrieves a transposed matrix. Inherited from BaseEffect.
GetValueMatrixTransposeArray Retrieves an array of transposed matrices. Inherited from BaseEffect.
GetValuePixelShader Retrieves a pixel shader. Inherited from BaseEffect.
GetValueString Retrieves a string. Inherited from BaseEffect.
GetValueTexture Retrieves a texture. Inherited from BaseEffect.
GetValueVector Retrieves a vector. Inherited from BaseEffect.
GetValueVectorArray Retrieves an array of vectors. Inherited from BaseEffect.
GetValueVertexShader Retrieves a vertex shader. Inherited from BaseEffect.
IsParameterUsed Determines whether a parameter is used by a technique.
IsTechniqueValid Validates a technique.
OnLostDevice Releases all references to video memory resources and deletes all state blocks.
OnResetDevice Should be called after a device is reset and before any other methods are called, if Device.IsUsingEventHandlers is set to false.
static (Shared in Visual Basic) op_Equality Compares the current instance of a class to another instance to determine whether they are the same.
static (Shared in Visual Basic) op_Equality Compares the current instance of a class to another instance to determine whether they are the same. Inherited from BaseEffect.
static (Shared in Visual Basic) op_Inequality Compares the current instance of a class to another instance to determine whether they are different.
static (Shared in Visual Basic) op_Inequality Compares the current instance of a class to another instance to determine whether they are different. Inherited from BaseEffect.
raise_Disposing Raises the Microsoft.DirectX.Direct3D.Effect.Disposing event when called from within a derived class.
raise_Lost Raises an Effect.Lost event when called from within a derived class.
raise_Reset Raises an Effect.Reset event when called from within a derived class.
SetArrayRange Sets the range of an array to pass to the device.
SetRawValue Sets a contiguous range of shader constants with a memory copy.
SetValue Sets the value of an arbitrary parameter or annotation, including simple types, structures, arrays, strings, shaders, and textures. Inherited from BaseEffect.
SetValueTranspose Sets a transposed matrix. Inherited from BaseEffect.
UpdateUnmanagedPointer Updates the unmanaged pointer for this BaseEffect object. This method supports the Microsoft .NET Framework infrastructure and is not intended to be used directly in your code. Inherited from BaseEffect.
UpdateUnmanagedPointer Updates the unmanaged pointer for this Effect object. This method supports the Framework infrastructure and is not intended to be used directly in your code.
ValidateTechnique Validates a technique.

Properties

Property Description
Description Retrieves an effect description. Inherited from BaseEffect.
Device Retrieves the device associated with an effect.
Disposed Gets a value that indicates whether the object is disposed.
Pool Retrieves an effect pool object that represents the pool of shared parameters.
StateManager Retrieves or sets the EffectStateManager object for this effect.
Technique Retreives and sets the active technique.
UnmanagedComPointer Returns the unmanaged Component Object Model (COM) ID3DXBaseEffect interface pointer. Inherited from BaseEffect.
UnmanagedComPointer Returns the unmanaged COM ID3DXEffect interface pointer.

Inheritance Hierarchy

ObjectLeave Site

MarshalByRefObjectLeave Site

BaseEffect

Effect

Remarks

An effect object can contain multiple techniques to render the same effect.

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.

  1. Create or obtain access to a high-level shader language (HLSL) file (.fx).
  2. Load the HLSL file using Effect.FromFile.
  3. Set Effect.Technique with the effect's technique.
  4. Use Effect.Begin to obtain the number of passes for the effect.
  5. 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.
  6. 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();

    .
    .
    .
}

Class Information

Namespace Microsoft.DirectX.Direct3D
Assembly Microsoft.DirectX.Direct3DX (microsoft.directx.direct3dx.dll)
Strong Name Microsoft.DirectX.Direct3DX,  Version=1.0.900.0,  Culture=neutral,  PublicKeyToken=d3231b57b74a1492