Texcoord projection/mapping

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?

texpro_help.v4p (11.6 kB)

hi diki!

couldn’t make it for dx layers.

but i have a shader based solution: (3.2 kB)

hey gregsn,
thank you! i will take some time to understand it completely, though :)

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.

  1. get the position into the pixelshader
    Out.TexCd= Out.Pos;

you cannot access Pos:POSITION directly from the pixelshader. that’s why a second field is used here. (google X4502)

  1. 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)

  1. apply a custom 2d transformation
    In.TexCd = mul(In.TexCd, tTex);

  2. 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.

greg (3.3 kB)

very cool. do you mind if i pop that projection -> texture space conversion into ShaderSnippets ?

you explanation is excellent, btw. only this{CODE(ln=>0)}In.TexCd = In.TexCd / In.TexCd.w;^is what will take my time; i’m still not clear on the concept of homogenous coordinates.