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.

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

Geometry Compression<br />

Dean Calver<br />

This article is a follow-up to an article I wrote in Direct3D <strong><strong>Shader</strong>X</strong>: Vertex and<br />

Pixel <strong>Shader</strong> <strong>Tips</strong> and <strong>Tricks</strong>. <strong>DirectX</strong> 9 has introduced new data types and added<br />

new capabilities to the vertex stream model. This, combined with more complex<br />

and faster vertex shaders, allows us to explore more advanced forms of vertex<br />

and geometry compression.<br />

What’s New in <strong>DirectX</strong> 9?<br />

Vertex <strong>Shader</strong>s<br />

In most cases I still use vertex shader version 1.1, as this is executed in hardware<br />

on the greatest number of machines. The new cards do benefit in the extra constant<br />

space available. This improves the amount of batching that can occur. Static<br />

branching also makes it easier to use different compression methods on different<br />

models. Vertex shader version 3.0 potentially offers a number of new capabilities,<br />

the most prominent being vertex texturing. This will offer a new range of compression<br />

methods but isn’t explored here due to current lack of hardware support.<br />

New Vertex Stream Declaration Format<br />

Limitations<br />

The vertex stream declaration system from <strong>DirectX</strong> 8 was completely overhauled<br />

to make it both easier to use and add new capabilities. From a compression point<br />

of view, the most interesting items are the new vertex data types and the extra<br />

control over where each element comes from in the stream (stream offset).<br />

When under <strong>DirectX</strong> 8 drivers (you can check via the D3DDEVCAPS2_STREAM-<br />

OFFSET cap bit), most new capabilities of the <strong>DirectX</strong> 9 vertex stream declarations<br />

can’t be used. Under <strong>DirectX</strong> 7 drivers, you must stick to FVF-style<br />

declarations. Also, if a declaration’s stream offsets produce overlapping vertex<br />

elements, then even on <strong>DirectX</strong> 9 drivers, the D3DDEVCAPS2_VERTEXELE-<br />

MENTSCANSHARESTREAMOFFSET cap bit must be set. Another limitation is<br />

that stream offsets must align on DWORD boundaries (4 bytes).<br />

3

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

Saved successfully!

Ooh no, something went wrong!