Jump to content
  • Advertisement

Archived

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

kapru

Terrain texture blending

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

Im having some trouble getting my terrain textures to blend correctly. my basic method i have 4 base texures that can be used to texture the terrain. Each terrain patch has 4 blend map one for each different base texture. So basicaly to change the terrain texture all you do is modify the patches blend maps. I render the base textures onto a texture by just using a quad then i render the landscape using that newly created texture. It is running pritty fast but i cant get the blending right i want to select the color from texture stage 0 and the alpha value from stage 1 i did some research and found blooms'' paper here are the texture stages he uses
		// 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);
but this just makes texture all white what am i doing wrong??

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
Your stage 1 operation just overwrites the previous texture with the diffuse colour. Sounds like you just need the colour op from stage 0, and the alpha op from stage 1.

ie.


// 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 1 alpha : get alpha from texture1


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

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


Rory

Share this post


Link to post
Share on other sites
This is my function that renders the terrain texture the problem in the texture stages(i think)


HRESULT CFrameWorkApplication::RenderTerrainTexture()
{
HRESULT hr;

LPD3DXRENDERTOSURFACE rendertargetsurface;
IDirect3DSurface8 *newsurface;

// D3DXCreateTexture(d3ddevice,rendertargetsize,rendertargetsize, 1, D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &rendertargettexture);


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->SetRenderState(D3DRS_ALPHABLENDENABLE,true);
d3ddevice->SetRenderState(D3DRS_LIGHTING,FALSE);


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




//////////////////

// testing //

//////////////////

// d3ddevice->SetRenderState(D3DRS_BLENDOP, D3DBLENDOP_ADD);

d3ddevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
d3ddevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);


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

d3ddevice->SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_MODULATE);
d3ddevice->SetTextureStageState(1, D3DTSS_COLORARG1, D3DTA_TEXTURE);
d3ddevice->SetTextureStageState(1, D3DTSS_COLORARG2, D3DTA_DIFFUSE);
// stage 1 alpha : get alpha from texture1

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

  • 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!