# Multipass Texturing

## Recommended Posts

I created a terrain engine using Multipass Texturing to blend multiple textures. For every texture a trianglelist is created with different alphablending values. The problem is drawing the entire terrain for every texture takes a lot of time, and the engine is running pretty slow at the moment because instead of just drawing one trianglelist it has to draw 6 for each frame. Now I'm not sure of any solutions for this problem. I myself thought of the possibility of blending all maps together at the start and then render this one, since the map is static and the blending values are not changing during gameplay. Quinnie, Edit: Maybe not needed but for the record i'm using DirectX 9.0 for the terrain engine. [Edited by - Quinnie on March 27, 2006 10:58:19 AM]

##### Share on other sites
Sounds like a good idea to me. Offline work is better then doing stuff at runtime, (unless resolution is an issue). Other options would be to use shaders and put your blend weights there, or store the alpha in the textures themselves, and then just alpha blend. Either way, six passes over your geometry seems excessively wasteful.

##### Share on other sites
why do you use Multipass Multitexturing? you could use singlepass multitexturing(without shaders).

regards,
m4gnus

##### Share on other sites
Quote:
 Original post by INVERSEDSounds like a good idea to me. Offline work is better then doing stuff at runtime, (unless resolution is an issue). Other options would be to use shaders and put your blend weights there, or store the alpha in the textures themselves, and then just alpha blend. Either way, six passes over your geometry seems excessively wasteful.

The idea is that in a height map I can set for each tile what the alhpa value is... So at some tiles I render the texture with half transparency and in some with a quarter etc... is that possible using shaders?

And Six passes indeed are wastefull....

Quote:
 Original post by m4gnuswhy do you use Multipass Multitexturing? you could use singlepass multitexturing(without shaders).regards,m4gnus

Ummm... I need to set for each texture on each tile the alpha value, and it happens often that on a tile there is a half transparent texture and for the other half an other texture.... as far as i know this is not possible using only one pass...

Edit: Maybe not needed but for the record i'm using DirectX 9.0 for the terrain engine.

##### Share on other sites
Have a look into multitexturing
On todays hardware you can draw something like 8-16 textures onto one triangle in ONE pass.. Each with their own alpha values I should assume.. And multitexturing goes back to the Riva TNT days, so anyone should be able to handle it.

Otherwise, generate a large texture beforehand but this may not be the best solution..

##### Share on other sites
Ok Thnx... I will do some research...

Also I stumbled into this article http://www.gamedev.net/reference/articles/article2238.asp and I was wondering if this is what I need...

##### Share on other sites
Terrain texturing a subject near and dear to my heart:

http://www.grinninglizard.com/lilith/

If you are comfortable with the hardware requirements for shaders, I strongly recommend shaders combined with multitexturing. I haven't used the DirectX API for multitexturing, but assuming it's roughly comparable to OpenGL then setting up the API for just the right blend and color combinations is difficult and frustrating to experiment with.

On the other hand, it's very easy to write a fragment shader that combines the textures just the way you want, and adds special visual effects on the way. For example: perhaps you want specular reflection just on the snow layer. Or add a little random height noise so the terrain doesn't look to regular. Or experiment with texture splatting. Straightforward with shaders, time consuming with the fixed function API.

lee

##### Share on other sites
I have to admit I'm not quite familiar with DirectX shaders, though some of the advantages you name seem quite handy :P So for now I will work myself through an article about multitexturing in one pass... than later on I'll inform myself a bit about shaders....

Thanks for the info...

##### Share on other sites
Using single pass multi texturing, guided by this tutorial "http://www.two-kings.de/tutorials/dxgraphics/dxgraphics12.html" I already ran into problem:

This codes seems to assume that the texture for the entire trianglestrip has the same opacity... and if I understand correct, that would not allow me to create parts in the terrain where some textures are more transperant tehn others. Also this seems to assume...

g_App.GetDevice()->SetTexture(0,pBaseMap); //set base texture (NEW)
g_App.GetDevice()->SetTexture(1,pDarkMap); //set dark map (NEW)
g_App.GetDevice()->DrawPrimitive(D3DPT_TRIANGLESTRIP,0,2);

I'm quite lost at the moment... and maybe I'm totaly wrong about everything :P Or maybe it's alreay too late to be programming :P

Anyway here some code snippits of how I orginally implemented my tecture blending maybe totally unusefull:

Drawing the Lists:
// Pass 1 :: Set The StreamSource For The VertexBufferg_pd3dDevice->SetStreamSource( 0, g_pVertexBufferBlendOne, 0, sizeof(CUSTOMVERTEX) );// Pass 1 :: Set The Texturing Modeg_pd3dDevice->SetTexture( 0 , g_pTerrainTexture[0]);// Pass 1 :: And Render The Terrain TriangleStripg_pd3dDevice->DrawPrimitive( D3DPT_TRIANGLELIST, 0, HeightMapY * HeightMapX * 2);// Pass 2 :: Set The StreamSource For The VertexBufferg_pd3dDevice->SetStreamSource( 0, g_pVertexBufferBlendTwo, 0, sizeof(CUSTOMVERTEX) );// Pass 2 :: Set The Texturing Modeg_pd3dDevice->SetTexture( 0 , g_pTerrainTexture[1]);// Pass 2 :: And Render The Terrain TriangleStripg_pd3dDevice->DrawPrimitive( D3DPT_TRIANGLELIST, 0, HeightMapY * HeightMapX * 2);

Setting the alpha blending using the difuse colors:
// First Triangle		:: Alpha Bledning SettingsMapVertices[(x*120)+(y*1) + 0].DiffuseColor = D3DCOLOR_ARGB(*TexturePointerOne, 255, 255, 255);MapVertices[(x*120)+(y*1) + 1].DiffuseColor = D3DCOLOR_ARGB(*TexturePointerTwo, 255, 255, 255);MapVertices[(x*120)+(y*1) + 2].DiffuseColor = D3DCOLOR_ARGB(*TexturePointerThree, 255, 255, 255);// Second Triangle		:: Alpha Blending SettingsMapVertices[(x*120)+(y*1) + 3].DiffuseColor = D3DCOLOR_ARGB(*TexturePointerTwo, 255, 255, 255);MapVertices[(x*120)+(y*1) + 4].DiffuseColor = D3DCOLOR_ARGB(*TexturePointerFour, 255, 255, 255);MapVertices[(x*120)+(y*1) + 5].DiffuseColor = D3DCOLOR_ARGB(*TexturePointerThree, 255, 255, 255);

##### Share on other sites
I mentioned this earlier, but why not store the alpha in the texture. If you're using a TGA say, you can store your alpha values there, and then, viola, different alphas for each layer. Of course, I still reconmend compressing as many of those textures down as possible, any textures that are repeated with the same frequency can just be merged together. Sure you CAN do 8 - 16 texture reads in one pass, but that doesn't mean you should. In my engine, I have the option of rendering multipass, or rendering multi-texturing, and on some vid cards the advantages of multi-texturing was neglegible (I still use it of course), but that is to say reading from a bunch of texture isn't always fast.

##### Share on other sites
Ummm.... now I'm not sure if I understand you correct but setting the alpha value inside a TGA file would mean the texture has the same alpha value everytime it is used. I would like to be able to set that myself, so i will use the texture once with half transperancy and then somewhereelse again without any transparency etc...

Regarding my last post... It was already late and i wasn't quite clear :P so you can ignore it mainly :P

##### Share on other sites
I was under the impression that you where always blending certain passes at the same opacity every time. So, for instance, if you're using an image editor like photoshop; if the base color is always full opacity, put that on a layer with full opacity. If the grass layer is always at 50% opacity, put that on a layer with 50% opacity, etc. Unless I am misunderstanding you, are applying one opacity to a whole layer, or are you applying different oppacities to different points in the mesh? If so the easiest thing would be to use shaders, I imagine that you could alternatively use multi texturing, but you would end up having to use a bunch of masks and that sounds like it would get messy quickly.

##### Share on other sites
To clearify myself: If for instance I have a grass texture then maybe on the first heightmap field it should be 50% opacity. On another field it could be 25% or 67% etc.

##### Share on other sites
Let me see if I've got this straight. Are the different heightmap fields being rendered one on top of the other, or three different fields rendering next to each other (more like tiles)? One option is to have three different grass textures with different opacities, which may seem wasteful, but in order to use the same texture and multi-texture with the three different fields, you would need three different alpha masks (if I remember correctly). The other option, again, is to use shaders, and store the various alpha values for the various textures in texture coordinates, or vertex streams.

## Create an account

Register a new account

• ## Partner Spotlight

• ### Forum Statistics

• Total Topics
627680
• Total Posts
2978610

• 13
• 12
• 10
• 12
• 22