Skip to main content
GameDev.net gamedev.net
🔒 Locked

Multiple bitmaps/textures using the same alpha

Started by Roof Top Pew Wee Oct 10, 2002 at 2:57 PM 1 replies 550+ views
Original Post
Roof Top Pew Wee
Roof Top Pew Wee
I''m just starting my first terrain editor in DX8 (had one in DX7). I''ve come across the issue of one terrain converting into another, and for some types, it is acceptable to simply blend one into the other. This technique is going to be my default one for having a terrain next to another, so I''m wondering, how do I make it so that I can have a set of alpah channels for the blending that I can use for every texture. That way, I could use the same grass bitmap regardless of whether it is completely surrounded by grass, or if it has dirt all thew ay around it. All I''d have to do is select the appropriate alpha. My idea was to make a black bitmap (which is my invisible color in the color key), and have an alpha key on that, but I''m not familiar with using multiple textures. Is this the rout to go? Thanks for any input --Vic--
NotTaxes
NotTaxes
Ah hahahahahaha.

I was in exactly the same place as you a few months back. You can lock the texture and assign the alpha values directly to memory from your alpha-map. That's a mission and it's really slow. The second method is to use texture blending during the render, but that requires that the hardware supports multiple texture operations in a single pass.

What you do is render your terrain with the 'base' texture (e.g. mud) with the following renderstates


d3ddevice.SetTextureStageState 0, D3DTSS_COLOROP, D3DTOP_MODULATE
d3ddevice.SetTextureStageState 0, D3DTSS_COLORARG1, D3DTA_TEXTURE
d3ddevice.SetTextureStageState 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE
d3ddevice.SetTextureStageState 0, D3DTSS_ALPHAOP, D3DTOP_MODULATE
d3ddevice.SetTextureStageState 0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE
d3ddevice.SetTextureStageState 0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE

d3ddevice.SetTextureStageState 1, D3DTSS_COLOROP, D3DTOP_DISABLE


Then you render your overlying texture (e.g. Grass) in Stage 0 and the alpha map in Stage 1, with your render state like this:


d3ddevice.SetTextureStageState 0, D3DTSS_COLOROP, D3DTOP_MODULATE
d3ddevice.SetTextureStageState 0, D3DTSS_COLORARG1, D3DTA_TEXTURE
d3ddevice.SetTextureStageState 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE
d3ddevice.SetTextureStageState 0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1
d3ddevice.SetTextureStageState 0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE
d3ddevice.SetTextureStageState 0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE

d3ddevice.SetTextureStageState 1, D3DTSS_COLOROP, D3DTOP_MODULATE


Works like a charm.

I got a lot of information from the other people here, but it was all more about how to structure your transformations rather than how to actually get it working with re-useable alpha-maps. Curious to see if there're any other ways of doing this.

[edited by - Nottaxes on October 10, 2002 4:31:54 PM]
'Doing the impossible is kind of fun' - Walt Disney
Roof Top Pew Wee
Roof Top Pew Wee
So you''re saying to set my textures as follows:

(*lpD3DDevice)->SetTexture( 0, grassTexture);

(*lpD3DDevice)->SetTexture( 1, textureWithAlphaToUse);

Then set up the TextureStageStates as you have set, then simply draw it, eh?

I''ll give it a try. If I''ve got it wrong, please do tell me.

--Vic--

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.