White Paper. Texture Arrays Terrain Rendering. February 2007 WP _v01

Similar documents
SDK White Paper. Vertex Lighting Achieving fast lighting results

SDK White Paper. Matrix Palette Skinning An Example

Technical Report. Anisotropic Lighting using HLSL

User Guide. Vertex Texture Fetch Water

Technical Report. Mesh Instancing

SDK White Paper. Occlusion Query Checking for Hidden Pixels

Sparkling Effect. February 2007 WP _v01

SDK White Paper. HLSL Blood Shader Gravity Maps

White Paper. Denoising. February 2007 WP _v01

Soft Particles. Tristan Lorach

White Paper. Soft Shadows. February 2007 WP _v01

Skinned Instancing. Bryan Dudash

Order Independent Transparency with Dual Depth Peeling. Louis Bavoil, Kevin Myers

Technical Report. GLSL Pseudo-Instancing

Multi-View Soft Shadows. Louis Bavoil

White Paper. Solid Wireframe. February 2007 WP _v01

User Guide. GPGPU Disease

White Paper. Perlin Fire. February 2007 WP _v01

User Guide. TexturePerformancePBO Demo

Technical Brief. NVIDIA Quadro FX Rotated Grid Full-Scene Antialiasing (RG FSAA)

Android PerfHUD ES quick start guide

Technical Brief. LinkBoost Technology Faster Clocks Out-of-the-Box. May 2006 TB _v01

Technical Brief. NVIDIA and Microsoft Windows Vista Getting the Most Out Of Microsoft Windows Vista

GPU LIBRARY ADVISOR. DA _v8.0 September Application Note

Technical Report. SLI Best Practices

Application Note. NVIDIA Business Platform System Builder Certification Guide. September 2005 DA _v01

Horizon-Based Ambient Occlusion using Compute Shaders. Louis Bavoil

NVIDIA nforce 790i SLI Chipsets

User Guide. GLExpert NVIDIA Performance Toolkit

GLExpert NVIDIA Performance Toolkit

NVIDIA SDK. NVMeshMender Code Sample User Guide

Constant-Memory Order-Independent Transparency Techniques

SDK White Paper. Soft Shadows

User Guide. DU _v01f January 2004

Cg Toolkit. Cg 2.1 October 2008 Release Notes

Cg Toolkit. Cg 1.4 rc 1 Release Notes

Technical Report. SLI Best Practices

Enthusiast System Architecture Certification Feature Requirements

Cg Toolkit. Cg 2.1 beta August 2008 Release Notes

NVWMI VERSION 2.24 STANDALONE PACKAGE

Cg Toolkit. Cg 1.2 Release Notes

CUDA Particles. Simon Green

SDK White Paper. Video Filtering on the GPU. Eric Young NVIDIA Corporation 2701 San Tomas Expressway Santa Clara, CA 95050

Deinterleaved Texturing for Cache-Efficient Interleaved Sampling. Louis Bavoil

High Quality DXT Compression using OpenCL for CUDA. Ignacio Castaño

SDK White Paper. Improve Batching Using Texture Atlases

GRID SOFTWARE FOR RED HAT ENTERPRISE LINUX WITH KVM VERSION /370.28

Cg Toolkit. Cg 2.0 January 2008 Release Notes

Cg Toolkit. Cg 2.0 May 2008 Release Notes

Technical Brief. AGP 8X Evolving the Graphics Interface

User Guide. Melody 1.2 Normal Map Creation & Multiple LOD Generation

Cg Toolkit. Cg 2.2 April 2009 Release Notes

Optical Flow Estimation with CUDA. Mikhail Smirnov

Technical Report. Non-Power-of-Two Mipmap Creation

CUDA/OpenGL Fluid Simulation. Nolan Goodnight

Cg Toolkit. Cg 1.3 Release Notes. December 2004

Tuning CUDA Applications for Fermi. Version 1.2

NVWMI VERSION 2.18 STANDALONE PACKAGE

GRID SOFTWARE FOR MICROSOFT WINDOWS SERVER VERSION /370.12

Histogram calculation in CUDA. Victor Podlozhnyuk

Technical Brief. FirstPacket Technology Improved System Performance. May 2006 TB _v01

NVIDIA CAPTURE SDK 6.1 (WINDOWS)

QUADRO SYNC II FIRMWARE VERSION 2.02

Cg Toolkit. Cg 2.2 February 2010 Release Notes

Intel Core 4 DX11 Extensions Getting Kick Ass Visual Quality out of the Latest Intel GPUs

NSIGHT ECLIPSE PLUGINS INSTALLATION GUIDE

NVIDIA CAPTURE SDK 6.0 (WINDOWS)

How to Work on Next Gen Effects Now: Bridging DX10 and DX9. Guennadi Riguer ATI Technologies

Rendering Grass with Instancing in DirectX* 10

Histogram calculation in OpenCL. Victor Podlozhnyuk

NVIDIA CAPTURE SDK 7.1 (WINDOWS)

TUNING CUDA APPLICATIONS FOR MAXWELL

Rain. Sarah Tariq

Analyze and Optimize Windows* Game Applications Using Intel INDE Graphics Performance Analyzers (GPA)

RMA PROCESS. vr384 October RMA Process

TUNING CUDA APPLICATIONS FOR MAXWELL

GRID VIRTUAL GPU FOR HUAWEI UVP Version ,

Technical Brief. NVIDIA Storage Technology Confidently Store Your Digital Assets

CUDA TOOLKIT 3.2 READINESS FOR CUDA APPLICATIONS

Per-Pixel Lighting and Bump Mapping with the NVIDIA Shading Rasterizer

Hardware Displacement Mapping

User Guide. NVIDIA Quadro FX 4700 X2 BY PNY Technologies Part No. VCQFX4700X2-PCIE-PB

Semantic and Annotation Remapping in FX Composer

Chapter IV Fragment Processing and Output Merging. 3D Graphics for Game Programming

The Application Stage. The Game Loop, Resource Management and Renderer Design

CS 354R: Computer Game Technology

NVIDIA CUDA C GETTING STARTED GUIDE FOR MAC OS X

Cg Toolkit. Cg 1.2 User s Manual Addendum

DX10, Batching, and Performance Considerations. Bryan Dudash NVIDIA Developer Technology

VIRTUAL GPU LICENSE SERVER VERSION

PASCAL COMPATIBILITY GUIDE FOR CUDA APPLICATIONS

VIRTUAL GPU MANAGEMENT PACK FOR VMWARE VREALIZE OPERATIONS

CUDA-GDB: The NVIDIA CUDA Debugger

CUDA Particles. Simon Green

MAXWELL COMPATIBILITY GUIDE FOR CUDA APPLICATIONS

Getting Started. NVIDIA CUDA C Installation and Verification on Mac OS X

MOSAIC CONTROL DISPLAYS

Dominic Filion, Senior Engineer Blizzard Entertainment. Rob McNaughton, Lead Technical Artist Blizzard Entertainment

Getting Started. NVIDIA CUDA Development Tools 2.2 Installation and Verification on Mac OS X. May 2009 DU _v01

KEPLER COMPATIBILITY GUIDE FOR CUDA APPLICATIONS

Transcription:

Texture Arrays Terrain Rendering February 2007 WP-03015-001_v01

Document Change History Version Date Responsible Reason for Change _v01 BD, TS Initial release Go to sdkfeedback@nvidia.com to provide feedback on Texture Arrays. ii WP-03015-001_v01

Texture Arrays Abstract The appearance of terrain varies widely. When drawing large expansive terrain, artists require many different textures. There are different ways to solve this, including splitting the mesh into many pieces with different bound textures per draw call. DirectX10 introduces the concept of texture arrays allowing an array of textures to be bound to a shader as a single piece of state, dynamically indexed within the shader. This allows a palette of textures to be applied to a terrain mesh, which means we are able to draw the entire terrain section in a single draw call. The equivalent in DirectX9 would require multiple draw calls which would reduce efficiency. Alternatively, texture atlases are commonly used. However, atlases require careful handling and impose restrictions on art content, so are not ideal (see references). Bryan Dudash NVIDIA Corporation WP-03015-001_v01 1

Figure 1. Terrain Mesh Rendered with Four Blended Textures all Read from a Texture Array Motivation The motivation for the texture arrays technique is performance. In general, reducing state changes and draw calls reduces the overhead on the CPU, which provides more processing power to the application. CPU overhead is a common bottleneck in modern 3D applications. This technique allows a developer to reduce overhead while maintaining robustness and unique textures for rendered polygons. A secondary motivation, compared with texture atlases, is to simplify a game s art pipeline. Use of an atlas requires changes to the model s texture coordinates to reflect a texture s position within the atlas. This complicates the art pipeline. Also, packing textures into adjacent space in an atlas leads to blending artifacts if handled naively, and makes it difficult to support tiled textures. These issues all go away when using texture arrays. 2 WP-03015-001_v01

Texture Arrays, Terrain Rendering How It Works The way the sample makes use of texture arrays is quite simple. Each vertex of the terrain mesh includes three texture coordinate vectors. Each of these coordinates is a 4-component vector. This is in contrast to the standard 2-component UV. The third component contains the array index into the texture array and the fourth component contains an alpha blend value. Then at runtime, in the shader, we index into the texture array to pull out the appropriate texture and use the alpha blend value to blend together multiple layers. Note: The sample does not provide a way to export or author multiple texture coordinates into your vertex data. It is assumed that developers will have an established tools pipeline and are able to implement that functionality themselves. The three sets of coordinates give us support for blending of two base textures per vertex as well as a decal texture to be overlaid on top of the blend result. The equation for this is: blendedcolor = color1 * color1alpha + color2 * color2alpha; if(decalalpha > 0) finalcolor = decalcolor * decalalpha + blendedcolor * (1-decalAlpha); else finalcolor = blendedcolor; The shader code calculating a finalcolor is: // Load the color values (3rd component is the slice of the aray from which to sample) // We multiply by the last component of the texcoord, which is set by the application to be the blend weight float4 albedo0 = g_txtextures.sample(g_samaniso,input.tex0.xyz)*input.tex0.w; float4 albedo1 = g_txtextures.sample(g_samaniso,input.tex1.xyz)*input.tex1.w; float4 bumps0 = g_txnormals.sample(g_samaniso,input.tex0.xyz)*input.tex0.w; float4 bumps1 = g_txnormals.sample(g_samaniso,input.tex1.xyz)*input.tex1.w; // combine using sampled alphas float3 finalalbedo = (albedo0.xyz * albedo0.w) + (albedo1.xyz * albedo1.w); float3 finalbumps = bumps0.xyz + bumps1.xyz; // third texture is the decal, but is optional if(input.tex2.w > 0) { float4 decal = g_txtextures.sample(g_samaniso,input.tex2.xyz); float4 decalbumps = g_txtextures.sample(g_samaniso,input.tex2.xyz); float decalalpha = input.tex2.w * decal.w; finalalbedo = finalalbedo*(1-decalalpha) + decal.xyz*decalalpha; WP-03015-001_v01 3

finalbumps = normalize(finalbumps*(1-decalalpha) + decalbumps*decalalpha); } Texture Arrays We use a conditional since, in the general case, the decal texture will not be used. Also, the decal might not even be needed depending on the application. Also, notice that we multiply each diffuse color by its alpha value. This allows the artists to have per-texel control over the coverage of a terrain texture. If the artist wants to control the blending using the alpha value of the texture, they can. The DirectX10 API for creating a texture array is similar to the one for creating a regular texture. The difference is in the D3D10_TEXTURE2D_DESC structure where the ArraySize element is set to the size of the array. Refer to the code block below for an example of creating a texture array. D3D10_TEXTURE2D_DESC desc; desc.format = DXGI_FORMAT_R8G8B8A8_UNORM; desc.width = iwidth; desc.height = iheight; desc.miplevels = imiplevels; desc.usage = D3D10_USAGE_DEFAULT; desc.bindflags = D3D10_BIND_SHADER_RESOURCE; desc.cpuaccessflags = 0; desc.arraysize = inumtextures; pd3ddevice->createtexture2d( &desc, NULL, pptex2d); Texture Ping Pong In the sample code, the function MultiTextureTerrain::loadTextureArray() shows how to create a texture array and fill it with data from an array of DDS files. An issue will arise with texture coordinates that is worth mentioning. If a mesh uses three base textures let s say in a progressive blend from texture 0 thru 2 (see Figure 2) then in order to get proper interpolation of the texture coordinated between vertices you will need to swap the texture coordinate that the shader texture is using as the texture changes. The system doesn t understand which texture will be read with each texcoord, For this example, your textures are red brick, green grass and white snow. Your mesh transitions from those in that order as shown in Figure 2. You need to be careful that all meshes in the contiguous area of green assign the green texture to be read from texcoord 1. This may seem obvious here, but if you adopt a strategy of always putting the texture transitioning from in texcoord 0 and the texture transitioning to into texcoord 1, then you will get improper blending at the transition areas. 4 WP-03015-001_v01

Texture Arrays, Terrain Rendering Figure 2. Example of Texture Ping Pong Implementation Details This project is extremely simple. The source code is divided into two cpp files and an fx file: TextureArrayTerrain.cpp: This is the standard sample DX10 setup code and UI code. It simply creates a MultiTextureTerrain object and calls into it. MultiTextureTerrain.cpp: This file contains all the code to create and render a terrain mesh. It loads the mesh file, and all relevant textures, and setups render state. TextureArrayTerrain.fx contains the D3DX effect. Running the Sample The arrow keys move the camera around in a FPS-style control scheme. The mouse rotates the camera view. Esc exits. WP-03015-001_v01 5

Performance The GPU load of this technique will be on par with separate draw calls for the sample rendering. The performance difference here is in the fact that there are less state changes and only a single draw call to render the whole terrain mesh. Also note that we draw the terrain in two passes. The first pass is a Z only pass that should run at blazing speeds. This engages the Z cull hardware of modern graphics processor allowing the hardware to efficiently cull out occluded surfaces. Integration Using this technique in your game engine requires that your export tool path include multiple texture coords for each terrain vertex, as well as moving to a float4 texcoord system. The tool should also support inserting the relevant index into a texture array to allow selection of the proper texture. In addition, similar to the process the sample uses, your codebase will need to load all textures for the terrain palette and insert them into a texture array object. This object can then be used instead of separate textures. References NVIDIA SDK9.5 Texture Atlases Sample Whitepaper Improving Batching using Texture Atlases, Mattias Wloka. 6 WP-03015-001_v01

Notice ALL NVIDIA DESIGN SPECIFICATIONS, REFERENCE BOARDS, FILES, DRAWINGS, DIAGNOSTICS, LISTS, AND OTHER DOCUMENTS (TOGETHER AND SEPARATELY, MATERIALS ) ARE BEING PROVIDED AS IS. NVIDIA MAKES NO WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO THE MATERIALS, AND EXPRESSLY DISCLAIMS ALL IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE. Information furnished is believed to be accurate and reliable. However, NVIDIA Corporation assumes no responsibility for the consequences of use of such information or for any infringement of patents or other rights of third parties that may result from its use. No license is granted by implication or otherwise under any patent or patent rights of NVIDIA Corporation. Specifications mentioned in this publication are subject to change without notice. This publication supersedes and replaces all information previously supplied. NVIDIA Corporation products are not authorized for use as critical components in life support devices or systems without express written approval of NVIDIA Corporation. Trademarks NVIDIA and the NVIDIA logo are trademarks or registered trademarks of NVIDIA Corporation in the United States and other countries. Other company and product names may be trademarks of the respective companies with which they are associated. Copyright 2007 NVIDIA Corporation. All rights reserved. NVIDIA Corporation 2701 San Tomas Expressway Santa Clara, CA 95050 www.nvidia.com