Vertex textures, standards and gaffer tape

· by Steve · Read in about 3 min · (589 Words)

I have a few things on my TODO right now, but one of them is vertex texture support in Eihort. Now, this isn’t actually that hard to implement, but I didn’t do it for Dagon because DirectX and GL take completely different approaches to the way they bind textures for use in the vertex shader. So it’s a design question rather than one of implementation - the differences between the vertex texture implementations pretty much mirrors the fundamental design differences between D3D and GL.

  • Direct3D approach - do it now, and screw the long-term, we’ll patch as we go. Kind of like design with blinkers on, but very useful when you want access to standardised versions of what’s hot right now. But it hurts you in the long run of course with interface breaking change. With vertex textures, this equates to having a bunch of separate vertex texture samplers which you bind textures to. This won’t survive beyond DirectX9 because the unified shader architecture in Dx10 will make it obsolete, requiring interface breaking change. This is exactly the same situation as Dx8.1 with it’s implementation of shaders which were far too closely tied with the way the GeForce3 did things, and which had to be heavily changed in Dx9.
  • GL approach - plan for the future, at the expense of short-term difficulties. In GL vertex shaders share texture bindings with the fragment pipeline. This is undoubtedly because they saw the writing on the wall and that this was a transitionary stage, the final solution would be a unified shader architecture, which incidentally GLSL can already leverage due it’s smart design, unlike Dx9. Because current tech doesn’t quite fit this model it’s a bit of an awkward squeeze right now, but it’s much more future proof. This mirrors pretty much all of GL’s design approach, such as the way Frame Buffer Object (FBO) works (the interface already supports much of the changes lauded in Dx10, even though no card supports it yet).

So in the short term you love D3D for it’s early access to scope-limited features, but curse it for its myopia in the long term. In the short term you’ll hate GL for the dodgy early drivers, vendor extension variations and missing standards implementations as manufacturers struggle to implement the ambitious standard on cards which aren’t up to it yet, in the long term you’ll love GL because it does it right, and clearly kept a firm weather eye out to the horizon. Horses for courses.

Anyway, in this case it’s up to us to paper over the cracks again. Basically I’ve exposed whether or not vertex texture units are shared with fragment samplers or not, and if they are, the vertex texture binding is an alias for the regular texture binding - the only difference being that it will trigger a technique fallback if the card doesn’t support vertex texture fetching. This should mean the structure is ready for a Dx10 plugin when it eventually happens. Whilst platforms where they are not shared exist, it will be possible to bind both vertex and regular textures separately if the rendersystem indicates it is possible. This is of course a transient position, but one which will last a fair while (Dx9 is not going away any time soon).

I’ve already documented what I’m going to do in the manual, and done most of the preparatory work. I’ll commit the implementation in a few days once I’ve had chance to do some proper testing, it’ll probably need a new demo.