Archived

This topic is now archived and is closed to further replies.

setting the alpha value in a texture

This topic is 5236 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

My two ideas: 1) Set the render target to the texture, then render some stuff using D3DPT_POINTLIST or whatever it is with the fvf containing a diffuse color. Question: will this set the alpha value in the texture or not? 2) Lock the texture and set the data manually. I looked up in the msdn and the pitch part in the data thing is confusing. If I can''t do #1 could someone explain this for me? Thanks!

Share this post


Link to post
Share on other sites
I would go with #2 if it's done during loading time. Locking a texture, however, is very slow so you should make use of the graphics card and render to it whenever you can. In your case, though, I think you will be wanting to set the alpha value in the pixel through locking the texture.


Something like this:



D3DLOCKED_RECT rect;
ZeroMemory(&rect, sizeof(rect));
pTexture->LockRect(0, &rect, NULL, 0);
BYTE *pData = (BYTE*)rect.pBits;

int index = (y*rect.Pitch)+(x*4);
pData[index++] = (BYTE)(pixel.b*255);
pData[index++] = (BYTE)(pixel.g*255);
pData[index++] = (BYTE)(pixel.r*255);
pData[index++] = (BYTE)(pixel.a*255);
pTexture->Unlock();


[edited by - Chaucer on August 14, 2003 1:40:48 AM]

Share this post


Link to post
Share on other sites
Sorry to bump this thread, but now I can''t get them the base texture and alpha map to blend together . I''ve come close but it still doesn''t set actual alpha values, just makes the color what it would be. I don''t know how to really explain it. Can you show me what you set for your texture states? The ones on the site don''t work at all...


// stage 0 coloring : get color from texture0*diffuse

lpDev->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_MODULATE);
lpDev->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
lpDev->SetTextureStageState(0, D3DTSS_COLORARG2, D3DTA_DIFFUSE);

// stage 0 alpha : nada

lpDev->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);
lpDev->SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_CURRENT);

// stage 1 coloring : nada

lpDev->SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_SELECTARG1);
lpDev->SetTextureStageState(1, D3DTSS_COLORARG1, D3DTA_DIFFUSE);

// stage 1 alpha : get alpha from texture1

lpDev->SetTextureStageState(1, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);
lpDev->SetTextureStageState(1, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);

Share this post


Link to post
Share on other sites
here''s what i use:


m_pd3dDevice->SetTextureStageState(0,D3DTSS_COLOROP, D3DTOP_ADD);
m_pd3dDevice->SetTextureStageState(0,D3DTSS_COLORARG1, D3DTA_TEXTURE);
m_pd3dDevice->SetTextureStageState(0,D3DTSS_COLORARG2, D3DTA_DIFFUSE);
m_pd3dDevice->SetTextureStageState(0,D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);
m_pd3dDevice->SetTextureStageState(0,D3DTSS_ALPHAARG1, D3DTA_TEXTURE);

m_pd3dDevice->SetTextureStageState(1,D3DTSS_COLOROP, D3DTOP_SELECTARG1);
m_pd3dDevice->SetTextureStageState(1,D3DTSS_COLORARG1, D3DTA_CURRENT);
m_pd3dDevice->SetTextureStageState(1,D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);
m_pd3dDevice->SetTextureStageState(1,D3DTSS_ALPHAARG1, D3DTA_TEXTURE);

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Although chaucer is correct in locking the texture and accessing the contents directly remember that the code he has applies to 32 bit color (BGRA) with 8 bits for each color. For other color formats be sure to convert the color information appropriately. Also always check to see if a lock on a resource is successful (checking for a resource lock is more important than checking for your usual dx api calls IMHO due to funky things users try to do with the resources.) Trying to write data to an invalid resource location will give you a nice surprise
Also always use the pitch provided as the texture mem location may have a longer width than the actual width of the texture due to aligning.

As for your your prob of state settings for the alpha the states you have listed appear to be correct, for one thing try to write random data to the alpha chan of your tex and see if that helps.
I don''t have the dx sdk with me atm but have a good look at your lpd3ddevice settings to ensure that alpha is enabled.

Share this post


Link to post
Share on other sites
Ok, now something is seriously strange. Not even those settings get my textures to blend properly. In fact, they don''t even blend at all . I had to change your D3DTOP_ADD to D3DTOP_MODULATE since I don''t have a vertex color. Could that be the problem?

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
you need to set srccolorop and set destcolorop so that you can blend the texture from the resulting computed alpha with the backbuffer for version <8 and for dx9 i think they are done through samplers

Share this post


Link to post
Share on other sites
Ooooh shoot, I think you are right. You don't need to set them to do the multitexturing but I sure need them when I do my next pass for the other textures. Thanks!

[edited by - Raloth on August 14, 2003 12:42:59 AM]

Share this post


Link to post
Share on other sites