TXAA 3.0 Utility LibraryΒΆ

Before initializing TXAA 3.0 utility library, it is necessary to initialize the factory interface first.

Initialize TXAA 3.0 Utility Library

// DX11
ID3D11Device*                            device;                  // Direct3D11 device.
nv::txaa::dx11::UtilityFactoryPtr        utilityFactory;          // TXAA 3.0 utility factory interface.
nv::txaa::dx11::UtilityFactoryParameters params;
memset(&params, 0, sizeof(params));
params.device = device;
if (nv::txaa::Status::OK != GFSDK_TXAA_DX11_CreateUtilityFactory(utilityFactory, params))
    return false;

// GL
nv::txaa::gl::UtilityFactoryPtr          utilityFactory;          // TXAA 3.0 utility factory interface.
nv::txaa::gl::UtilityFactoryParameters   params;
memset(&params, 0, sizeof(params));
if (nv::txaa::Status::OK != GFSDK_TXAA_GL_CreateUtilityFactory(utilityFactory, params, nv::txaa::gl::INTERFACE_VERSION))
    return false;

There are four independent interfaces available in TXAA 3.0 utility library, each of which performs different task. Developer can use them directly in their games so that less effort is needed in the integration. Only one specific example of creating those interfaces is shown below since all are done in a similar manner.

Create a Specific Interface

// DX11
nv::txaa::dx11::TargetCopierPtr         targetCopier;              // Interface for target copier.
if (nv::txaa::Status::OK != utilityFactory->CreateTargetCopier(targetCopier))
    return false;

// GL
nv::txaa::gl::TargetCopierPtr           targetCopier;              // Interface for target copier.
if (nv::txaa::Status::OK != utilityFactory->CreateTargetCopier(targetCopier))
    return false;

Copy a Texture

// DX11
ID3D11Device*                           device;                    // Direct3D11 device.
nv::txaa::dx11::TargetCopierPtr         targetCopier;              // Interface for target copier.
ID3D11RenderTargetView*                 destRTV;                   // Render target view of destination texture.
ID3D11ShaderResourceView*               srcSRV;                    // Shader resource view of source texture.
targetCopier->CopyTarget( device, destRTV, srcSRV );

// GL
nv::txaa::gl::TargetCopierPtr           targetCopier;              // Interface for target copier.
GLuint                                  destFboId;                 // FBO id.
GLuint                                  sourceId,                  // Id of the source texture
GLint                                   imageWidth;                // Width of the texture
GLint                                   imageHeight;               // Height of the texture
targetCopier->CopyTarget(destFboId, sourceId, imageWidth, imageHeight);

If there is no motion vector generation in game engine, one can always use the following interface to generate motion vector buffer for TXAA 3.0. However it will only consider camera movement since local matrix transformation is not taken into account in it, it is suggested that game engine should generate its own motion vector buffer for each frame to achieve best AA quality, instead of using this interface, which is treated as a fallback method.

Generate Motion Vector via Depth Reconstruction

// DX11
ID3D11Device*                            device;                    // Direct3D11 device.
nv::txaa::dx11::MotionVectorGeneratorPtr motionVectorGenerator;     // Interface of motion vector generator.
float*                                   viewProj;                  // Multiplication of View and Projection matrix for current frame.
float*                                   viewProjPrev;              // Mulitplication of View and Projection matrix for previous frame.
int                                      sampleCount;               // Number of samples in each pixel.
ID3D11RenderTargetView*                  mvRTV;                     // Render target view of motion vector.
ID3D11ShaderResourceView*                depthSRV;                  // Shader resource view of depth texture.
nv::txaa::MotionVectorParameters motionVectorParam;
motionVectorParam.vpCurrent = (const gfsdk_F32 *)viewProj;
motionVectorParam.vpPrior = (const gfsdk_F32 *)viewProjPrev;
motionVectorParam.sampleCount = sampleCount;
motionVectorGenerator->GenerateMotionVector( device , mvRTV , depthSRV , motionVectorParam );

// GL
nv::txaa::gl::MotionVectorGeneratorPtr   motionVectorGenerator;      // Interface of motion vector generator.
float*                                   viewProj;                   // Multiplication of View and Projection matrix for current frame.
float*                                   viewProjPrev;               // Mulitplication of View and Projection matrix for previous frame.
int                                      sampleCount;                // Number of samples in each pixel.
GLuint                                   mv;                         // FBO id.
GLuint                                   depth;                      // Depth texture id.
nv::txaa::MotionVectorParameters motionVectorParam;
motionVectorParam.vpCurrent = (const gfsdk_F32 *)viewProj;
motionVectorParam.vpPrior = (const gfsdk_F32 *)viewProjPrev;
motionVectorParam.sampleCount = sampleCount;
motionVectorGenerator->GenerateMotionVector( deviceContext , mv , depth , motionVectorParam );

Edge detection algorithm can be used to mark those pixels on geometry edges, texture marking edges can be used as control texture in TXAA 3.0 library. Two different edge detection methods are provided in TXAA 3.0 utility library. Following is the demonstration on their usage:

Edge Detection based on Edge Gradiant

// DX11
ID3D11Device*                           device;                    // Direct3D11 device.
nv::txaa::dx11::GradientEdgeDetectorPtr gradientEdgeDetector;      // Interface for edge detector.
ID3D11RenderTargetView*                 destRTV;                   // Render target view of destination texture.
ID3D11ShaderResourceView*               texLinearDepthResolvedSRV; // SRV of the texture holding linear depth information.
gradientEdgeDetector->DetectEdges(device, destRTV, texLinearDepthResolvedSRV , nv::txaa::DefaultEdgeDetectParameters);

// GL
nv::txaa::gl::GradientEdgeDetectorPtr   gradientEdgeDetector;      // Interface for edge detector.
GLuint                                  texEdgesFboId;             // FBO ID.
GLuint                                  texLinearDepthResolved;    // Id of the texture holding linear depth information.
gradientEdgeDetector->DetectEdges(texEdgesFboId, texLinearDepthResolved, nv::txaa::DefaultEdgeDetectParameters);

Edge Detection based on Second Order Derivatives

// DX11
ID3D11Device*                           device;                    // Direct3D11 device.
nv::txaa::dx11::GradientEdgeDetectorPtr secondOrderEdgeDetector;   // Interface for edge detector.
ID3D11RenderTargetView*                 destRTV;                   // Render target view of destination texture.
ID3D11ShaderResourceView*               texLinearDepthResolvedSRV; // SRV of the texture holding linear depth information.
ID3D11RenderTargetView*                 derivativeRTV;             // Render target view of scene derivative texture.
ID3D11ShaderResourceView*               derivativeSRV;             // Shader resource view of scene derivative texture.
secondOrderEdgeDetector->ComputeDerivatives(device, derivativeRTV, texLinearDepthResolvedSRV);
secondOrderEdgeDetector->DetectEdges(device, destRTV, derivativeSRV, nv::txaa::DefaultEdgeDetectParameters);

// GL
nv::txaa::gl::GradientEdgeDetectorPtr   secondOrderEdgeDetector;   // Interface for edge detector.
GLuint                                  texEdgesFboId;             // Id of the texture bound in FBO.
GLuint                                  texLinearDepthResolved;    // Id of the texture holding linear depth information.
GLuint                                  texDerivativeFBOId;        // FBO id which holds the derivative texture.
GLuint                                  texDerivative;             // Id of the derivative texture.
secondOrderEdgeDetector->ComputeDerivatives(texDerivativeFBOId, texLinearDepthResolved);
secondOrderEdgeDetector->DetectEdges(texEdgesFboId, texDerivatives, nv::txaa::DefaultEdgeDetectParameters);

Release Utility Library

// DX11
nv::txaa::dx11::TargetCopierPtr            targetCopier;            // Interface for target copier.
nv::txaa::dx11::GradientEdgeDetectorPtr    gradientEdgeDetector;    // Interface for edge detector.
nv::txaa::dx11::SecondOrderEdgeDetectorPtr secondOrderEdgeDetector; // Interface for edge detector.
nv::txaa::dx11::MotionVectorGeneratorPtr   motionVectorGenerator;   // Interface for motion vector generator .
motionVectorGenerator.reset();
secondOrderEdgeDetector.reset();
gradientEdgeDetector.reset();
targetCopier.reset();
GFSDK_TXAA_DX11_ReleaseContext(&m_txaaContext);

// GL
nv::txaa::gl::TargetCopierPtr              targetCopier;            // Interface for target copier.
nv::txaa::gl::GradientEdgeDetectorPtr      gradientEdgeDetector;    // Interface for edge detector.
nv::txaa::gl::SecondOrderEdgeDetectorPtr   secondOrderEdgeDetector; // Interface for edge detector.
nv::txaa::gl::MotionVectorGeneratorPtr     motionVectorGenerator;   // Interface for motion vector generator.
motionVectorGenerator.reset();
secondOrderEdgeDetector.reset();
gradientEdgeDetector.reset();
targetCopier.reset();
GFSDK_TXAA_DX11_ReleaseContext(&m_txaaContext);