Skip to main content
gamedev.net
🔒 Locked

Texture blending...

Started by krad7 0 replies 700+ views
Original Post
krad7
krad7
Ok, i have been trying to blend 2 textures for my terrain.. as my terrain is created randomly (random height maps), i assign the alpha in the vertices. (also i have geforce 2, yea kinda sucky card, anyways it only supports 2 textures for multitexturing per pass). Also i want to preserve my defualt lighting. The way i tried to blend my textures was:
// light initialization

//Turn on lighting

D3DLIGHT9 d3dLight;

	//Initialize the light structure.

	ZeroMemory(&d3dLight, sizeof(D3DLIGHT9));

	d3dLight.Type = D3DLIGHT_DIRECTIONAL;
	
	d3dLight.Diffuse.r = 1.0f;
	d3dLight.Diffuse.g = 1.0f;
	d3dLight.Diffuse.b = 1.0f;
	
	d3dLight.Ambient.r = 0.0f;
	d3dLight.Ambient.g = 0.0f;
	d3dLight.Ambient.b = 0.0f;
	
	d3dLight.Specular.r = 0.0f;
	d3dLight.Specular.g	= 0.0f;
	d3dLight.Specular.b	= 0.0f;

	d3dLight.Direction = D3DXVECTOR3(-1.0, -1.0, 0.0);
	//Assign the point light to our device in poisition (index) 0

	if(FAILED(g_Device9->SetLight(0, &d3dLight)))
	{
		return false;
	}

	//Enable our point light in position (index) 0

	if(FAILED(g_Device9->LightEnable(0, TRUE)))
	{
	
		return E_FAIL;
	}
if(FAILED(g_Device9->SetRenderState(D3DRS_LIGHTING, TRUE)))
{
return E_FAIL;
}

	//Set ambient light level

if(FAILED(g_Device9->SetRenderState(D3DRS_AMBIENT, D3DCOLOR_XRGB(60, 60, 60))))	
{		
return E_FAIL;
}

#define TERRAIN_PATCH_FVF_VERTEX(D3DFVF_XYZ|D3DFVF_NORMAL|D3DFVF_DIFFUSE|D3DFVF_TEX1)
//Define a custom vertex for our terrain

typedef	struct TERRAIN_CUSTOMVERTEX
{
FLOAT x, y, z;
FLOAT nx, ny, nz;		// Lighting Normal

D3DCOLOR diffuseColor;		// diffuse color

FLOAT tu, tv;			// Texture coordinates

}TerrainVertex;

// Rendering function....

g_Device9->SetRenderState(D3DRS_ALPHABLENDENABLE, true);	
g_Device9->SetRenderState(D3DRS_SRCBLEND,D3DBLEND_SRCALPHA);
g_Device9->SetRenderState(D3DRS_DESTBLEND,D3DBLEND_INVSRCALPHA);

g_Device9->SetTexture(0, m_pTexture);//1st/base texture

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

g_Device9->SetTexture(1, m_pTexture1); //2nd texture

g_Device9->SetTextureStageState(1,D3DTSS_TEXCOORDINDEX,0);
g_Device9->SetTextureStageStat(1,D3DTSS_COLORARG1,D3DTA_CURRENT);
g_Device9->SetTextureStageStat(1,D3DTSS_COLORARG2,D3DTA_TEXTURE);
g_Device9->SetTextureStageState(1,D3DTSS_COLOROP,D3DTOP_BLENDCURRENTALPHA);

g_Device9->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0,0, NUM_PATCH_VERTICES, 0, NUM_PATCH_POLYS);
so now, the output is all weird, the tiles where my 2nd texture (i.e. m_pTexture1) should appear, is all black and i dont see my texture at all, i only see my base texture. Also using BLENDDIFFUSEALPHA would just ruin all my lighting ( i dont want to create a shodow map either). Hod do i fix my problem and blend the 2 textures? any suggestions would be greatly appreciated.. thanks
Slow and steady wins the race.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.