# [DX9] Alphamaps, MipMaps, Selection

This topic is 3025 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hello everybody! Im working on an implementation of a modelfile from a game. Its actually for learning purpose. Now im facing 3 problems. I dont know if these are simple problems or if its a harder one, but ill post'em here: 1. http://www.imagr.eu/up/4aeea600602bc_agyria.JPG As you can see it has a problem when i go away from the texture. If i go away very far it gets a picture with only green and blue squares. I think its a problem with the Mipmaps but i dont know what exactly! 2. Alphamaps: I have 4 layers of textures. every layer has its own 64 x 64 alphatexture. The first layer hast full opacity on every vertex but the next 3 layers have different alphavalues on the vertices. Now im trying to get the blending with the following rendering:
dev->SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);
dev->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);
dev->SetTexture(0, m_alphaMaps);
dev->SetTextureStageState(1, D3DTSS_ALPHAARG1, D3DTA_CURRENT);
dev->SetTextureStageState(1, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);
dev->SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_SELECTARG1);
dev->SetTextureStageState(1, D3DTSS_COLORARG1, D3DTA_TEXTURE);
m_3dMgr->SetTexture(m_textures, 1);
dev->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);
dev->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
dev->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);

Now actually the textures dont have the alpha-value of the alphamap-texture but either 0 or 255. 3. Selection I need to get the selectionpoint in my terrain of the mouse. I actually calculate the point on zNear and on zFar but now i got stuck and dont know what to do next to get the selectionpoint. I cant intersect it with a mesh because the terrain isnt rendered as a mesh but vertex-per-vertex. It would be really cool if someone has a lill hint bout that! Greetings Plerion

##### Share on other sites
Hi Plerion,

1. Possibly your samplers need to be changed, for terrain you often need to use an anisotropic filter

2. I'm not sure but this might help

3. You could either create a mesh and fill the VB and IB with your terrain values and do an intersection like that. Otherwise you would have to go though every triangle in your terrain and check for intersection (I would advice the first of these two solutions)

Hope that was of some help

##### Share on other sites
1. If you think it's MIP maps, try disabling them. I didn't understand from the image what the problem was.

2. I'd strongly suggest moving to pixel shaders. You can use pixel shaders 2.0 together with the fixed function vertex pipeline, virtually all cards support them, and they're a lot easier to understand and program than texture stages. They also support up to 16 textures and you'll be able to do all your blending in a single pass.

3. I don't understand what you mean by "vertex-per-vertex". There are various ways to pick. Terrain is typically a grid or grid-like hierarchy, and you should be able to trace a ray over it a lot more efficiently than checking all triangles.

##### Share on other sites
Hello!

Thx for your tipps, thats how it looks actually:
http://www.imagr.eu/up/4af71880ba2b7_p2.JPG

You can see, that blending works now (pretty) good. The problem remaining are these blue and green stripes all over the terrain. If i disable mipmapping the stripes disappear but the terrain looks overdetailed.

For the second point:
I would actually love to user vertex shaders but i have no plan how to use that. I have up to 4 textures where the first texture should be fully opaque and the other textures all have an external 64 x 64 alphamap containing only alphavalues for the texture. Could you maybe give me a sample how shading is done?

3. I think i figured out how to transform my terrain into a mesh and so intersecting it :)

Greetings
Cromon