i’m trying to achieve a ‘masking’-effect by putting a texture onto a mesh and changing the texture state / mapping so the texture appears static / billboarded regardless of the mesh position (see attached patch).
i got it working using TexCoords (EX9.Texturestate) and Drawfixed (EX9.Effect) , but it stops working when the texture is transformed in any way. i’ve also got no clue on how to implement this using any DX9-node, or which shader semantics need to be invoked to achieve the same effect.
is anyone on the projectionmatrix-crew in the know about this kind of thing?
the main idea is that each pixel that is rendered by the pixel shader only needs to know its position within the renderer to be able to map it in a simple way to a texture coordinate.
get the position into the pixelshader
you cannot access Pos:POSITION directly from the pixelshader. that’s why a second field is used here. (google X4502)
do the projection from homogenous space to projection space
In.TexCd = In.TexCd / In.TexCd.w;
do the same what the rasterizer also did, before calling the pixelshader: apply the perspective disortion, leaving temporary 4d work space behind, entering 2.5d space.
coordinates now range from (-1, -1) to (1, 1)
apply a custom 2d transformation
In.TexCd = mul(In.TexCd, tTex);
on the patch side we used a module to get from projection space (-1, -1)…(1, 1) to texture space (0, 1)…(1, 0). (left, bottom)…(right, top)
attached is another version that simplifies the patch (by doing more redundant stuff in the vertexshader), but also speeds up the pixelshader (which typically is called more often than the vertexshader) by moving a transformation into the vertexshader.