3D transform effect

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

This effect applies the matrix (Mt) 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 ]*Mt

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 enumerationTypeDescription

InterpolationMode

D2D1_3DTRANSFORM_PROP_INTERPOLATION_MODE

D2D1_3DTRANSFORM_INTERPOLATION_MODE

D2D1_3DTRANSFORM_INTERPOLATION_MODE_LINEAR

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

BorderMode

D2D1_3DTRANSFORM_PROP_BORDER_MODE

D2D1_BORDER_MODE

D2D1_BORDER_MODE_SOFT

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

TransformMatrix

D2D1_3DTRANSFORM_PROP_TRANSFORM_MATRIX

D2D1_MATRIX_4X4_F

Matrix4x4F(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1)

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

Where:

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.

 

Interpolation modes

EnumerationDescription
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

NameDescription
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.

FunctionDescriptionMatrix
Matrix4x4F::Scale(X, Y, Z)Generates a transform matrix that scales the projection plane in the X, Y, and/or Z direction.Scale3D matrix
Matrix4x4F::SkewX(X)Generates a transform matrix that skews the projection plane in the X direction.Skew matrix
Matrix4x4F::SkewY(Y)Generates a transform matrix that skews the projection plane in the Y direction.Skew matrix
Matrix4x4F::Translation(X, Y, Z)Generates a transform matrix that translates the projection plane in the X, Y, or Z direction.Translate matrix
Matrix4x4F::RotationX(X)Generates a transform matrix that rotates the projection plane about the X axis.Rotate X matrix
Matrix4x4F::RotationY(Y)Generates a transform matrix that rotates the projection plane about the Y axis.Rotate Y matrix
Matrix4x4F::RotationZ(Z)Generates a transform matrix that rotates the projection plane about the Z axis.Rotate Z matrix
Matrix4x4F::PerspectiveProjection(D)A perspective transformation with a depth value of D.Perspective matrix
Matrix4x4F::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.

Requirements

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]
Headerd2d1effects.h
Libraryd2d1.lib, dxguid.lib

 

Related topics

ID2D1Effect

 

 

Community Additions

ADD
Show:
© 2014 Microsoft