Texture coordinate generation

Started by
0 comments, last by DarkImp 18 years, 5 months ago
Hi, I think that I have some troubles understanding the texture coordinate generation feature of the fixed pipeline. My understanding of "generation" means that I have no texture coordinates and I "generate" some, using some kind of information such as the current vertex position. But if I understand the "generation" used in DirectX, it seems to be more some kind of texture transformation but generation, because it seems that you already have to have the texture coordinates. Am I wrong? What I want to achieve is: I have a terrain (underwater) on which I want to project the caustic texture from above. How can I achieve this without adding additional texture coordinates to the terrain mesh? Is it possible to achieve the same effect to any mesh (projecting the texture from above)? Best regards, Metron
----------------------------------------http://www.sidema.be----------------------------------------
Advertisement
Yeah. You can create texture co-ordinates in D3D quite easily. Never actually done (dynamic) projected textures, but I THINK this is how you'd go about it...

You need to set the texture co-ord index to one of the creation types, which are:

D3DTSS_TCI_CAMERASPACENORMAL
D3DTSS_TCI_CAMERASPACEPOSITION
D3DTSS_TCI_CAMERASPACEREFLECTIONVECTOR
D3DTSS_TCI_SPHEREMAP

So for your case you'd use the position (as your projected texture co-ordinates will be position based) by setting the following state before rendering:

d3dDevice->SetTextureStageState(0, D3DTSS_TEXCOORDINDEX, D3DTSS_TCI_CAMERASPACEPOSITION);

This will then assign texture co-ordinated bases on your camera position, but you don't want this (as you're unlikely to have your camera where you're projecting from), so you'll need to project the co-ordinates to your texture emitter using:

d3dDevice->SetTransform(D3DTS_TEXTURE0, &cameraToTexEmitterTrans );
d3dDevice->SetTextureStageState(0, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_COUNT2 );

The second line basically throws away the z-component of the co-ordinate as you don't need this after the projection.

Not a clue if that'll actually work, as I've never done it, and I'm sure there's probably an easier way to do it somehow, but I hope it'll provide a good starting point. I'd be interested to know the solution when you find it :)

This topic is closed to new replies.

Advertisement