Jump to content
  • Advertisement

Archived

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

kapru

im desperate

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

Using texture stages how do i set it up so the color comes from stage 0 but the alpha comes from stage 1

Share this post


Link to post
Share on other sites
Advertisement
You could do something like this:

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

This will take the result from the color op in stage 0, (which by default is to modulate diffuse with texture) and use it with the alpha value from the texture in stage 1.

[edited by - Zook on January 23, 2004 7:47:53 AM]

Share this post


Link to post
Share on other sites
Thats exactly what im doing maybe im not setting the right render states

this is what im doing

HRESULT CFrameWorkApplication::RenderTerrainTexture()
{
HRESULT hr;

LPD3DXRENDERTOSURFACE rendertargetsurface;
IDirect3DSurface8 *newsurface;


D3DSURFACE_DESC desc;
terrRenderTarget->GetSurfaceLevel(0, &newsurface);
newsurface->GetDesc(&desc);


if(FAILED(hr = D3DXCreateRenderToSurface(d3ddevice, desc.Width, desc.Height,
D3DFMT_A8R8G8B8, FALSE, D3DFMT_UNKNOWN, &rendertargetsurface)))
{
return hr;
}


rendertargetsurface->BeginScene(newsurface, NULL);


d3ddevice->SetStreamSource(0, rendertargetVB, sizeof(rendertargetvertex));
d3ddevice->SetVertexShader(RENDERTARGET_VERTEX);
d3ddevice->Clear( 0L, NULL, D3DCLEAR_TARGET,D3DCOLOR_ARGB(255,0,0,0), 0.0f, 0L );\



d3ddevice->SetRenderState(D3DRS_ZWRITEENABLE,false);

d3ddevice->SetRenderState(D3DRS_LIGHTING,false);
d3ddevice->SetRenderState(D3DRS_FILLMODE, D3DFILL_SOLID );
d3ddevice->SetRenderState(D3DRS_SRCBLEND,D3DBLEND_SRCALPHA);
d3ddevice->SetRenderState(D3DRS_DESTBLEND,D3DBLEND_INVSRCALPHA);
d3ddevice->SetRenderState(D3DRS_ALPHABLENDENABLE,true);
d3ddevice->SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_SELECTARG1);
d3ddevice->SetTextureStageState(1, D3DTSS_COLORARG1, D3DTA_TEXTURE);

d3ddevice->SetTextureStageState(0, D3DTSS_COLOROP,D3DTOP_SELECTARG1);
d3ddevice->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_CURRENT);
d3ddevice->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);
d3ddevice->SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);




d3ddevice->SetTexture(1,terrTexture[0]);
d3ddevice->SetTexture(0,terrBlendMap[0]);
d3ddevice->DrawPrimitive(D3DPT_TRIANGLELIST,0,2);

d3ddevice->SetTexture(1,terrTexture[1]);
d3ddevice->SetTexture(0,terrBlendMap[1]);
d3ddevice->DrawPrimitive(D3DPT_TRIANGLELIST,0,2);

d3ddevice->SetTexture(1,terrTexture[2]);
d3ddevice->SetTexture(0,terrBlendMap[2]);
d3ddevice->DrawPrimitive(D3DPT_TRIANGLELIST,0,2);

d3ddevice->SetTexture(1,terrTexture[3]);
d3ddevice->SetTexture(0,terrBlendMap[3]);
d3ddevice->DrawPrimitive(D3DPT_TRIANGLELIST,0,2);

rendertargetsurface->EndScene();

//Release the rendertosurface

SAFE_RELEASE(rendertargetsurface);
SAFE_RELEASE(newsurface);

return S_OK;
}

Share this post


Link to post
Share on other sites
It looks like the states you are setting for stage 0 should be for stage 1 and vice versa.

Share this post


Link to post
Share on other sites
Do you have a texture and then alpha that your getting from a black and white texture? You may want to combine them into one TGA. That way you don't waste a texture blending stage and it's so much easier too.

www.opticuslabs.com/alphatexgen

~Wave

[edited by - Wavewash on January 23, 2004 1:01:37 PM]

Share this post


Link to post
Share on other sites
Add this..

d3ddevice->SetTextureStageState(1, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);
d3ddevice->SetTextureStageState(1, D3DTSS_ALPHAARG1, D3DTA_CURRENT);

You need that to transfer the alpha to the end of the texture cascade, otherwise the alpha will just get lost.

Share this post


Link to post
Share on other sites
For some reason there is no blending happening at all they just overrite each other even if im just plotting grass its either drawing all or nothing. So my guess if im missing something that im too stupid to see

if any one want the code for the engine i can email it its only 300k with the 4 textures it needs

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!