Terrain texturing stages

Started by
10 comments, last by kapru 20 years, 3 months ago
I need some help with texture stages for my landscape heres how im doing it. the terrain has 4 textures eg grass sand rock and snow. Each 33x33 patch has its own 4 alpha only texture that are used to blend the 4 main textures together but i cant get them to blende together they are always solid colours. Heres how im rendering i have a texture that is used as a render target over the entire rendertarget i draw a 2d quad for each texture layer then i use that render target to texture the landscape. it works really well and pritty fast apart for there being no blending a bit of psudo code create blend maps set texture 0,grass set texture 1,grassblendmap drawquad repeat for the of three texutes set texture 0,rendertarget set texture 1,NULL draw landscape patch so hopefully now you understand how im doing it. Now what are the proper render states to draw texture 0 but with texture 1''s alpha channel? thanks for any help been stuck on this for awhile
Advertisement
quote:
Now what are the proper render states to draw texture 0 but with texture 1''s alpha channel?


SetRenderState(D3DRS_SRCBLEND,D3DBLEND_SRCALPHA);
SetRenderState(D3DRS_DESTBLEND,D3DBLEND_INVSRCALPHA);
SetRenderState(D3DRS_ALPHABLENDENABLE,TRUE);

SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_SELECTARG1);
SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);

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

SetTextureStageState(1, D3DTSS_TEXCOORDINDEX , 0);
That 1/2 works but there is no blending between the layers
I''m not sure what you mean by that.. Do you mean that each layer is completely overwriting the previous one? Or do you mean that you get blending, but its all or nothing for each layer? (eg, 100% grass,0% snow, or 0%grass, 100% snow, but no 30% grass, 70% snow).

Could be alpha-testing in that case. Add this..

SetRenderState(D3DRS_ALPHATESTENABLE,FALSE);
Yeah each layer is all or nothing adding that extra bit didnt help at all

ill post exactly 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_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->SetRenderState(D3DRS_ALPHATESTENABLE,FALSE); 	d3ddevice->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_SELECTARG1);	d3ddevice->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE);	d3ddevice->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);	d3ddevice->SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_SELECTARG1);	d3ddevice->SetTextureStageState(1, D3DTSS_COLORARG1, D3DTA_CURRENT);	d3ddevice->SetTextureStageState(1, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);	d3ddevice->SetTextureStageState(1, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);	d3ddevice->SetTextureStageState(1, D3DTSS_TEXCOORDINDEX , 0); 	d3ddevice->SetTexture(0,terrTexture[0]);	d3ddevice->SetTexture(1,terrBlendMap[0]);	d3ddevice->DrawPrimitive(D3DPT_TRIANGLELIST,0,2);	d3ddevice->SetTexture(0,terrTexture[1]);	d3ddevice->SetTexture(1,terrBlendMap[1]);	d3ddevice->DrawPrimitive(D3DPT_TRIANGLELIST,0,2);	d3ddevice->SetTexture(0,terrTexture[2]);	d3ddevice->SetTexture(1,terrBlendMap[2]);	d3ddevice->DrawPrimitive(D3DPT_TRIANGLELIST,0,2);	d3ddevice->SetTexture(0,terrTexture[3]);	d3ddevice->SetTexture(1,terrBlendMap[3]);	d3ddevice->DrawPrimitive(D3DPT_TRIANGLELIST,0,2);	rendertargetsurface->EndScene();	//Release the rendertosurface	SAFE_RELEASE(rendertargetsurface);    SAFE_RELEASE(newsurface);	return S_OK;}
I dont see any problem with that code.. Are you certain that the blend maps are using a texture format that has enough alpha bits? Its worth putting in a check after the texture is created to ensure that is the case.
the textures are 8 bit alpha only if ichange it to a8r8g8b8 it still does the same thing does any one want the source to have a look at
just a quick note

d3ddevice->SetTextureStageState(0, D3DTSS_ALPHAOP,D3DTOP_SELECTARG1);

there is no D3DTSS_ALPHAARG1 for it to refer to could this be a problem or does this make it refer to texture stage 1
bump
If you havent fixed this yet you could send me the code, as long as its not more than 100kb or so.

(treething @ yahoo DOT com)

quote:
there is no D3DTSS_ALPHAARG1 for it to refer to could this be a problem or does this make it refer to texture stage 1

Shouldnt be a problem since its overwritten in the next stage anyway.

This topic is closed to new replies.

Advertisement