d3d11.Effect

Supports vertex- pixel- geometry- hull- and compute-shaders.

Methods

class Effect
Effect(str path, dict defines=None) → Effect
Parameters:
  • path – File path to the .fx-file.
  • definesPreprocessor defines that will be used when compiling the effect.

Creates a new Effect from a file.

featureLevel = device.getFeatureLevel()
macros = {"RED" : "float4(1.0, 0.0, 0.0, 1.0)", MYVALUE : "8",
    "FEATURE_LEVEL" : str(featureLevel)}
f = Effect("Effects/Boom.fx", macros)

In the above case text like float4 backgroundColor = RED; will become float4 backgroundColor = float4(1.0, 0.0, 0.0, 1.0); after defines are applied. You can also use certain preprocessor commands in the .fx-file:

//Include some shared stuff.
#include "Shared.fx"

#if FEATURE_LEVEL >= 0xa000
    //Use some Direct3D 10.0 feature.
#else
    //No support, use some fallback strategy. In this case just fail.
    #error "Device does not support Direct3D 10.0"
#endif
apply(technique, int passindex) → None
Parameters:
  • technique – Technique to apply. Can be a name or an index.
  • passindex – Techniques pass index.

Applies the given technique and pass. This updates all views, variables etc.

f = Effect(...)
techIndex = 0 #What technique is used.
for i in range(f.getPasses(techIndex)):
    #Iterate all passes.
    f.set(...)
    f.set(...)
    f.apply(techIndex, i)
    ... #Render things.
get(name) → object
Parameters:
  • name – Name (normal or semantic) of the variable.

Returns a value from the effect. Only supports “native” types (int, float, string) and does not support arrays with vector elements.

getPasses(int techniqueindex) → list

Returns all pass names from the given technique. If a pass has no name, None is used.

getTechniques() → list

Returns all techniques as a list. If a technique has no name, None is used.

#List all techniques and passes.
f = Effect(...)
for i, tech in enumerate(f.getTechniques()):
    print("Technique", tech)
    for passName in f.getPasses(i):
        print("    Pass", passName)
set(name, value) → None

Updates a value inside the Effect. Supported DirectPython objects are d3d11.View, d3d11.Buffer, d3d11.Vector and d3d11.Matrix. If the first character in name is : it is treated as a semantic name. Call apply() when you want to apply these changes to the device.

It is also possible to set other values, for example:

//Some .fx-file.
float singleValue;
float values[3]; //An array of floats.
float3 valueVector[2]; //An array of 3-component vectors.
float4x4 someMatrix : MYMATRIX; //Semantic name: MYMATRIX

//Our user defined data structure.
struct Point {
    float2 xy;
};

//Constant buffer, holds 100 Point-objects.
cbuffer pointBuffer {
    Point points[100];
}

Could be set like this:

f = Effect(...)
f.set("singleValue", 4.0)
f.set("values", [1.0, 5.0, 6.0])
f.set("valueVector", [(1.0, 2.0, 3.0), (7.0, 8.0, 9.0)])
f.set(":MYMATRIX", Matrix()) #Or 'f.set("someMatrix", Matrix())'.

#Data for a cbuffer
initdata = [(0, 0)] * 100
b = Buffer([("", 0, FORMAT_R32G32_FLOAT)], initdata, BIND_CONSTANT_BUFFER)
f.set("pointBuffer", b)
setRaw(name, value) → None

Writes data directly into a variable. value must support buffer protocol for reading. This is a relatively unsafe way to update data unless you know what you are doing.

Table Of Contents

Get DirectPython 11 at SourceForge.net. Fast, secure and Free Open Source software downloads