3D transform effect

Use the 3D transform effect to apply an arbitrary 4x4 transform matrix to an image.

This effect applies the matrix (Mₜ) you provide to the corner vertices of the source image ([ x y z 1 ]) using this calculation:

[ xr yr zr 1 ]=[ x y z 1 ]*Mₜ

The CLSID for this effect is CLSID_D2D13DTransform.

Example image

The image before the transform.
The image after the transform.


ComPtr<ID2D1Effect> D2D13DTransformEffect;
m_d2dContext->CreateEffect(CLSID_D2D13DTransform, &D2D13DTransformEffect);

D2D13DTransformEffect->SetInput(0, bitmap);

// You can use the helper methods in D2D1::Matrix4x4F to create common matrix transformations.
D2D1_MATRIX_4X4_F matrix = 
	D2D1::Matrix4x4F::Translation(0.0f, -192.0f, 0.0f) *
	D2D1::Matrix4x4F::RotationY(30.0f) *
	D2D1::Matrix4x4F::Translation(0.0f, 192.0f, 0.0f);

D2D13DTransformEffect->SetValue(D2D1_3DTRANSFORM_PROP_TRANSFORM_MATRIX, matrix);


Effect properties

Display name and index enumerationDescription



The interpolation mode the effect uses on the image. There are 5 scale modes that range in quality and speed.





The mode used to calculate the border of the image, soft or hard. See Border modes for more info.


Default value is D2D1_BORDER_MODE_SOFT.



A 4x4 transform matrix applied to the projection plane. The following matrix calculation is used to map points from one 3D coordinate system to the transformed 2D coordinate system.

3D Depth Matrix


X, Y, Z = Input projection plane coordinates
Mx,y = Transform Matrix elements
X’, Y’, Z’ =Output projection plane coordinates

The individual matrix elements are not bounded and are unitless.

Type is D2D1_MATRIX_4X4_F.

Default value is Matrix4x4F(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1).


Interpolation modes

D2D1_3DTRANSFORM_INTERPOLATION_MODE_NEAREST_NEIGHBORSamples the nearest single point and uses that. This mode uses less processing time, but outputs the lowest quality image.
D2D1_3DTRANSFORM_INTERPOLATION_MODE_LINEARUses a four point sample and linear interpolation. This mode uses more processing time than the nearest neighbor mode, but outputs a higher quality image.
D2D1_3DTRANSFORM_INTERPOLATION_MODE_CUBICUses a 16 sample cubic kernel for interpolation. This mode uses the most processing time, but outputs a higher quality image.
D2D1_3DTRANSFORM_INTERPOLATION_MODE_MULTI_SAMPLE_LINEARUses 4 linear samples within a single pixel for good edge anti-aliasing. This mode is good for scaling down by small amounts on images with few pixels.
D2D1_3DTRANSFORM_INTERPOLATION_MODE_ANISOTROPICUses anisotropic filtering to sample a pattern according to the transformed shape of the bitmap.


Note  If you don't select a mode, the effect defaults to D2D1_3DTRANSFORM_INTERPOLATION_MODE_LINEAR.
Note  Anisotropic mode generates mipmaps when scaling, however, if you set the Cached property to true on the effects that are input to this effect, the mipmaps won't be generated every time for sufficiently small images.

Border modes


The effect pads the image with transparent black pixels as it interpolates, resulting in a soft edge.


The effect clamps the output to the size of the input image.


4x4 Transform Matrix Class

Direct2D provides a 4x4 matrix class to provide helper functions for transforming the image in 3 dimensions. See the Matrix4x4F topic for more info and a description of all the class members.

Matrix4x4F::Scale(X, Y, Z)Generates a transform matrix that scales the projection plane in the X, Y, and/or Z direction.Scale3D matrix
SkewX(X)Generates a transform matrix that skews the projection plane in the X direction.Skew matrix
SkewY(Y)Generates a transform matrix that skews the projection plane in the Y direction.Skew matrix
Translation(X, Y, Z)Generates a transform matrix that translates the projection plane in the X, Y, or Z direction.Translate matrix
RotationX(X)Generates a transform matrix that rotates the projection plane about the X axis.Rotate X matrix
RotationY(Y)Generates a transform matrix that rotates the projection plane about the Y axis.Rotate Y matrix
RotationZ(Z)Generates a transform matrix that rotates the projection plane about the Z axis.Rotate Z matrix
PerspectiveProjection(D)A perspective transformation with a depth value of D.Perspective matrix
RotationArbitraryAxis(X, Y, Z, degrees)Rotates the projection plane about the axis you specify.


Sample code

For an example of this effect, download the Direct2D 3D transform effect sample.


Minimum supported clientWindows 8 and Platform Update for Windows 7 [desktop apps | Windows Store apps]
Minimum supported serverWindows 8 and Platform Update for Windows 7 [desktop apps | Windows Store apps]
Libraryd2d1.lib, dxguid.lib


Related topics