Jump to content
  • Advertisement
Sign in to follow this  
Swatter555

Combining two textures

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

To be clear, I am not talking about alpha blending. I need to combine two textures together, I believe using the lock method. I cant seem to find the correct terms to google, so I will give it a try here. Now, I am trying to combine several textures together to form my 2d map tile. There could be so many potential "layers" that locking the texture and copying the next texture on top seems to be the best way. I am using an open source 3D engine (irrlicht) that doesnt like it when you directly uncover the directx pointers, but locking textures isnt a problem though. All of the textures I use are colorkeyed, so I need to preserve that. How can I properly perform those actions? If anyone knows of any links to a article that directly covers this, I would appreciate it.

Share this post


Link to post
Share on other sites
Advertisement
I'm not really sure about what you're tryna do but check out function D3DXLoadSurfaceFromSurface. Here's what i found in i-net few months ago don't remember the link to the example so i'll post only the part of it (actually function that probably does what you need ):


void loadSubTexture( void )
{
LPDIRECT3DTEXTURE9 pSubTexture = NULL;
LPDIRECT3DSURFACE9 pDestSurface = NULL;
LPDIRECT3DSURFACE9 pSrcSurface = NULL;

D3DXCreateTextureFromFile( g_pd3dDevice, "tex64.bmp", &pSubTexture );

g_pTexture->GetSurfaceLevel( 0, &pDestSurface );
pSubTexture->GetSurfaceLevel( 0, &pSrcSurface );

RECT srcRect[] = { 0, 0, 64, 64 };
RECT destRect[] = { 32, 32, 96, 96 };

D3DXLoadSurfaceFromSurface( pDestSurface, NULL, destRect,
pSrcSurface, NULL, srcRect,
D3DX_DEFAULT, 0);

pSrcSurface->Release();
pDestSurface->Release();
pSubTexture->Release();
}



Not sure was that what you need :-P


Or there's a better way... use shaders.

Share this post


Link to post
Share on other sites
I'm afraid you're going to have to be more specific. I can think of at least a dozen realistic ways to 'combine' two textures. I understand that you want a method that takes two IDirect3DTexture9 objects and returns another, but exactly what operation do you intend to perform?

Admiral

Share this post


Link to post
Share on other sites
Exactly what I am doing is combining a base texture (say a grass tile) with another (say a trees tile). The final result will be the base grass texture plus the trees texture. I might need 5 - 10 textures combined into one ultimately, so I can simply draw one texture for one tile each frame. I dont really know how to be more specific than that, please elaborate on exactly what info you need.


Share this post


Link to post
Share on other sites
From your description it seems that you do want alpha blending (or at least testing). If I understand correctly, you have a base texture, on which you want to overlay another texture, defined with alpha (for example, trees with a transparent background).

You can do this by rendering to a render target, and performing your operation using the texture stages, a pixel shader, or multiple passes with alpha. You can then use the render target as your texture.

Share this post


Link to post
Share on other sites
Thank you for the reply. I am aware of alpha blending and other ways to perform such actions, but as I said that is not something I want to do. I am performing many, many calculations determining what will go onto each tile. Also, I dont want to perform up to 20 x 16 x (up to 15+) blending operations each frame. Each tile could have up to 15 layers.

To me the simplest option is to combine the textures once during initilization by locking the texture and copying one texture onto the other, that is the root of my inquiry.

My question is how do I properly copy one texture onto another using the lock operation while still maintaining the colorkey value on the textures. If you tell me that performing 4800 blending operations per frame wont hurt performance, then that might be something I would consider.

Share this post


Link to post
Share on other sites
I did it that way:

Got 3 textures, for example: grass, sand, cement.
Got another texture (painted in photoshop) where red channel - ammount of grass, green - ammount of sand, blue - cement. I only needed 3 textures but if you want more then just add with this principle.

My pixel shader for that:


float4 PS_RELIEF_LQ( VS_OUT_RELIEF IN ) : COLOR
{

// diffuse textures
float4 Diff0 = tex2D( sampTex0, IN.tex0 );
float4 Diff1 = tex2D( sampTex1, IN.tex1 );
float4 Diff2 = tex2D( sampTex2, IN.tex2 );

// Mix texture
float4 Mix = tex2D( sampTexMM, IN.tex3 );
// Shadowmap texture
float4 SM = tex2D( sampTexSM1, IN.tex3 );

// Combining diffuse textures using mix texture
float4 Col = ( Diff0 * Mix.r ) + ( Diff1 * Mix.g ) + ( Diff2 * Mix.b );
Col = Col * SM;

return Col;

}

Share this post


Link to post
Share on other sites
Quote:
Original post by Swatter555
Thank you for the reply. I am aware of alpha blending and other ways to perform such actions, but as I said that is not something I want to do. I am performing many, many calculations determining what will go onto each tile. Also, I dont want to perform up to 20 x 16 x (up to 15+) blending operations each frame.

You misunderstand. What I suggested is doing this once, into render targets, then reusing the render targets during the frames. Your response suggests to me that you don't understand render targets. I'd suggest that you read about them.

Share this post


Link to post
Share on other sites
Quote:
Original post by ET3D
Quote:
Original post by Swatter555
Thank you for the reply. I am aware of alpha blending and other ways to perform such actions, but as I said that is not something I want to do. I am performing many, many calculations determining what will go onto each tile. Also, I dont want to perform up to 20 x 16 x (up to 15+) blending operations each frame.

You misunderstand. What I suggested is doing this once, into render targets, then reusing the render targets during the frames. Your response suggests to me that you don't understand render targets. I'd suggest that you read about them.


I once again thank you for the reply.

Render targets return a IDirect3DSurface9 pointer, which is easy enough to understand and that would certainly make sense, but as I said I am using the irrlicht open source engine which I would doubt would allow such operations without modification. It is possible to uncover the directx device directly, but that is discouraged from what I understand. That is reason that I was asking for solutions that allowed manipulation of the textures using the lock method, which is a functionality allowed by the engine.

Also, as I read the thread even closer it seems like I simply cannot state exactly what I was looking for. To be as exact as I can, I was searching for a way to combine 2 textures, using the lock/unlock methods that would allow me to copy the needed pixels from a source texture to a target texture. Irrlicht will either use the alpha value of a texture for transparency, or it will accept a color key when the texture is loaded. I am loading the textures intially with color keying, and I am very confused how this will affect copying pixels from the source to the target.

I hope I have clarified what I am asking for, I am not sure how else to ask it. Thanks for the help and interest.

I edited the message for clarity, which I am lacking to a large degree in this thread.

[Edited by - Swatter555 on March 25, 2007 10:04:05 AM]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!