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

Before
the image before the transform.
After
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);

m_d2dContext->BeginDraw();
m_d2dContext->DrawImage(D2D13DTransformEffect.Get());
m_d2dContext->EndDraw();

Effect properties

Display name and index enumeration Description
InterpolationMode
D2D1_3DTRANSFORM_PROP_INTERPOLATION_MODE
The interpolation mode the effect uses on the image. There are 5 scale modes that range in quality and speed.
Type is D2D1_3DTRANSFORM_INTERPOLATION_MODE.
Default value is D2D1_3DTRANSFORM_INTERPOLATION_MODE_LINEAR.
BorderMode
D2D1_3DTRANSFORM_PROP_BORDER_MODE
The mode used to calculate the border of the image, soft or hard. See Border modes for more info.
Type is D2D1_BORDER_MODE.
Default value is D2D1_BORDER_MODE_SOFT.
TransformMatrix
D2D1_3DTRANSFORM_PROP_TRANSFORM_MATRIX
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 MatrixWhere:
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

Enumeration Description
D2D1_3DTRANSFORM_INTERPOLATION_MODE_NEAREST_NEIGHBOR Samples the nearest single point and uses that. This mode uses less processing time, but outputs the lowest quality image.
D2D1_3DTRANSFORM_INTERPOLATION_MODE_LINEAR Uses 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_CUBIC Uses 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_LINEAR Uses 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_ANISOTROPIC Uses 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

Name Description
D2D1_BORDER_MODE_SOFT The effect pads the image with transparent black pixels as it interpolates, resulting in a soft edge.
D2D1_BORDER_MODE_HARD 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.

Function Description Matrix
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. Shows a skew matrix in the X direction.
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.

Requirements

Requirement Value
Minimum supported client Windows 8 and Platform Update for Windows 7 [desktop apps | Windows Store apps]
Minimum supported server Windows 8 and Platform Update for Windows 7 [desktop apps | Windows Store apps]
Header d2d1effects.h
Library d2d1.lib, dxguid.lib

ID2D1Effect