Sign in to follow this  
Derobrash

Multicoloured nightmare )

Recommended Posts

http://www.ireallydontcare.com/images/mushroommode.zip Now, it looks all very well and good, but its NOT MEANT TO BE LIKE THAT. Whats actually meant to be there, is a sand texture, here is the code:

	m_Device->SetTexture( 0, m_pSandTexture );	

    m_Device->SetTextureStageState( 0, D3DTSS_COLOROP,   D3DTOP_MODULATE );
    m_Device->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );
    m_Device->SetTextureStageState( 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE );
    m_Device->SetTextureStageState( 0, D3DTSS_ALPHAOP,   D3DTOP_DISABLE );

	D3DXMATRIX WorldMat;
	D3DXMatrixIdentity( &WorldMat );
	m_Device->SetTransform(D3DTS_WORLD, &WorldMat);
	
	m_Device->SetFVF(D3DFVF_TERRAINVERTEX);
	m_Device->SetStreamSource(0,m_pTerrainVB,0,sizeof(D3DTERRAINVERTEX));
	m_Device->SetIndices(m_pTerrainIB);

	for(int cellRow = 0 ; cellRow < CELLS_DIM ; ++cellRow)
	{
		for(int cellColumn = 0; cellColumn < CELLS_DIM ; ++cellColumn)
		{

			int cellNumber = cellColumn + ( cellRow * CELLS_DIM );
			HRESULT hr = m_Device->DrawIndexedPrimitive(D3DPT_TRIANGLELIST,VERTS_PER_CELL*cellNumber,0,VERTS_PER_CELL,0,FACES_PER_CELL);
		}
	}


	m_Device->SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_DISABLE);
	m_Device->SetFVF(NULL);
	m_Device->SetTexture(0, NULL);


If I change the attribute 'modulate' to using hte current argument only, I get my sand texture that I desired in the first place (and yes, I know there should be mipmapping, this is a small portion of what was my terrain rendering function, complete with water and vertex shaders :/. Anyway, my declarations and vertex filling function is below in part

#define D3DFVF_TERRAINVERTEX ( D3DFVF_XYZ | D3DFVF_DIFFUSE  | D3DFVF_NORMAL | D3DFVF_TEX1 )

typedef struct D3DTERRAINVERTEX
{
	D3DXVECTOR3 Position; //v0
	DWORD	dwColor;	  //v1 - Alpha Used for blending, high = grass, low = sand
	D3DXVECTOR3 Normal; //v2
	float tu1, tv1;	// grass texture //v3
//	float tu2, tv2; // sand texture //v4

}D3DTERRAINVERTEX;





int CurrentTexPointU = 0;
	int CurrentTexPointV = 0;



	for( int cellrow = 0; cellrow < CELLS_DIM; ++cellrow )
	{
		for( int cellcolumn = 0; cellcolumn < CELLS_DIM; ++cellcolumn )
		{ //cycle through the cells
			bool CellVisible = 0;
			for(int subrow = 0 ; subrow <= CELLWIDTH ; ++subrow)
			{

				for(int subcolumn = 0 ; subcolumn <= CELLWIDTH ; ++subcolumn)
				{
					int row = subrow + ( cellrow * CELLWIDTH );
					int column = subcolumn + ( cellcolumn * CELLWIDTH );

					float PosX = float(row - HEIGHTMAPSIZE/2)*SCALE;
					float PosZ = float(column - HEIGHTMAPSIZE/2)*SCALE;
					D3DTERRAINVERTEX v;

					v.Position = D3DXVECTOR3(PosX,HeightArray[row][column],PosZ);
					v.tu1 = (float)CurrentTexPointU;
					v.tv1 = (float)CurrentTexPointV;
//					v.tu2 = (float)CurrentTexPointU;
//					v.tv2 = (float)CurrentTexPointV;
					int Alpha = (int)(HeightArray[row][column]/(64/5.0f));
					Alpha *= 3;
					if(Alpha > 255)
						Alpha = 255;
					v.dwColor = D3DCOLOR_ARGB(Alpha , 255, 255, 255);

					CurrentTexPointU += 1;
					if(CurrentTexPointU > 1)
						CurrentTexPointU = 0;

					v.dwColor = 0xFFFFFFFF; //for now, as the other version aint working either, this will be good for now.
					*pBuffer++ = v;


Help, as this is very annoying, I will carry on working on it, but if anyone has any ideas....

Share this post


Link to post
Share on other sites
I'm not sure, but I think if you swap the normal and the colour around in the structure decleration, that might work. I remember you need to have them in a certain order, just cant find the bit in the SDK where it tells you the order.

Share this post


Link to post
Share on other sites
You are of course, perfectly correct, I sussed it last night after removing the normal and going 'ooh, it works' :/

Thanks though :)
www.ireallydontcare.com/blog <-- history of yesterdays coding hehe.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this