13.12.2012 Views

ShaderX Shader Programming Tips & Tricks With DirectX 9

ShaderX Shader Programming Tips & Tricks With DirectX 9

ShaderX Shader Programming Tips & Tricks With DirectX 9

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

}<br />

// get the 10,10,10 portion of the position<br />

float3 cpos = input.position;<br />

// decode our 2 bits (0-3)<br />

float two bits = floor(input.enc2Bit.w / 64.0);<br />

// factor in the extra bits and convert back into the 0-1 range<br />

cpos.z = (cpos.z + two bits) * 0.25;<br />

// transform by the inverse compression matrix<br />

float4 pos = mul( float4(cpos,1), InvCompressionTransform );<br />

Displacement Compression<br />

My previous article covered the use of vertex shaders to render displacement<br />

maps. This capability can be extended to a very powerful technique that Tom<br />

Forsyth has termed “displacement compression.” It’s a complete family of techniques<br />

that includes patch rendering, displacement mapping, and subdivision surfaces<br />

that any vertex shader-capable hardware can do and is a powerful form of<br />

geometry compression.<br />

Usually tessellation levels are decided by the CPU, as we currently have no<br />

programmable tessellation hardware, but there are a few fixed-function hardware<br />

tessellation systems that you may be able to use. This is the technique’s major<br />

limitation — to a limited degree, we can remove triangles (by sending the vertices<br />

to be clipped), but we cannot add triangles.<br />

By using the vertex shaders as a function evaluator with the vertex stream<br />

bringing in the function parameters, we can render many geometrical surfaces.<br />

For the surfaces we use here, this consists of a barycentric surface function with<br />

an additional displacement scalar, but other surfaces’ parameterizations are<br />

possible.<br />

There are two components that are needed for displacement compression.<br />

� Displacement mapping: A method of retrieving a scalar displacement along<br />

the surface normal. <strong>With</strong>out it, your displacement compression becomes<br />

standard surface patch evaluation.<br />

� Surface basis: Every displacement compression shader requires a basis system<br />

that defines the base surface before displacement. The simplest is just<br />

planar, although it could be as complex as a subdivision surface.<br />

Displacement Mapping<br />

Section I — Geometry Manipulation <strong>Tricks</strong><br />

Using Vertex <strong>Shader</strong>s for Geometry Compression<br />

There are at least four ways to get the displacement value into the vertex shader.<br />

The more advanced methods require explicit hardware support and are not covered<br />

here. Refer to presentations from Mike Doggett and Tom Forsyth for details<br />

[2]. Also, Tom Forsyth’s article covers actual generation of displacement data in<br />

detail [1].<br />

The technique presented here works on any vertex shader hardware by<br />

treating the displacement map as a 1D vertex stream. It’s a generalization of the<br />

technique that I presented in Direct3D <strong><strong>Shader</strong>X</strong>, which had an implied planar basis<br />

that with a few minor modification works for any surface basis.<br />

7

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!