Jump to content
  • Advertisement
Sign in to follow this  
plasmalasgun

Streaked out Textures

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

Hey everyone.... When rendering per subset of my mesh, some of the texture if displayed alright, however the rest of my polys display a streaked texture (parallel lines cover these polys) could everyone help me and give me a hand here? Appreciate it thanx noel some code
//////////////////////////////////////

void 3DManager::RenderModelSubset( tMesh* pMesh,
									   DWORD  dwModelSubsetID )
{
	D3DCAPS9 pCaps;
	m_d3dDevice->GetDeviceCaps(&pCaps);

	// Set the material and texture for this subset
	m_d3dDevice->SetMaterial( &pMesh->pMaterials[dwModelSubsetID] );
	m_d3dDevice->SetTexture( 0, pMesh->lpTextures[dwModelSubsetID] );
	m_d3dDevice->SetTextureStageState(0, (D3DTEXTURESTAGESTATETYPE)16/*D3DTSS__MAGFILTER*/, (D3DTEXTUREFILTERTYPE)3/*D3DTEXF_ANISOTROPIC*/); //check
	m_d3dDevice->SetTextureStageState(0, (D3DTEXTURESTAGESTATETYPE)17/*D3DTSS_MINFILTER*/, (D3DTEXTUREFILTERTYPE)3/*D3DTEXF_ANISOTROPIC*/);  //check
	m_d3dDevice->SetTextureStageState(0, (D3DTEXTURESTAGESTATETYPE)18/*D3DTSS_MIPFILTER*/, (D3DTEXTUREFILTERTYPE)3/*D3DTEXF_ANISOTROPIC*/);  //check
	m_d3dDevice->SetTextureStageState(0, (D3DTEXTURESTAGESTATETYPE)21/*D3DTSS_MAXANISOTROPY*/, pCaps.MaxAnisotropy); 
																		 
	pMesh->lpMesh->DrawSubset( dwModelSubsetID );

}
//////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////
HRESULT Renderer::SetLevelSubsets(tLevel* pLevel)
{


	DWORD dwNumFaces = pLevel->pMesh->lpMesh->GetNumFaces();



///////////////////////////////////////////////////////////////////////////
// Parse the Attribute buffer in order to assign the subsets information //
///////////////////////////////////////////////////////////////////////////

	// lock the attribute buffer
	DWORD *attribBuf;
	HRESULT hResult;


		DWORD dwNumVerts = dwNumFaces * 3;
		// allocate storage and generate adjacency data
		DWORD *pAdjacencyData = new DWORD[ dwNumVerts ];

		if (!pAdjacencyData)
			return E_OUTOFMEMORY;
		if (FAILED( hResult = pLevel->pMesh->lpMesh->GenerateAdjacency(0.0f,pAdjacencyData) ))
		{
			delete pAdjacencyData;
			return hResult;
		}

		// optimize the mesh with attribute sorting
		if (FAILED(hResult = pLevel->pMesh->lpMesh->OptimizeInplace(D3DXMESHOPT_VERTEXCACHE|D3DXMESHOPT_ATTRSORT,pAdjacencyData,NULL,NULL,NULL))	)
		{
			delete pAdjacencyData;
			return hResult;
		}



		// de-allocate adjacency data storage
		delete pAdjacencyData;


		pLevel->pMesh->lpMesh->GetAttributeTable( NULL, &pLevel->dwAttributesQty );
		pLevel->pAttributes = new D3DXATTRIBUTERANGE[ pLevel->dwAttributesQty ];
		pLevel->pMesh->lpMesh->GetAttributeTable (pLevel->pAttributes,  &pLevel->dwAttributesQty );



		////////////////////////////////////////////////////////////
		// Traverses each Subset's individual indexes by offseting
		// by the size of each subset the index buffer to access the
		// vertex positional information for creating a bounding box
		////////////////////////////////////////////////////////////
		LPDIRECT3DVERTEXBUFFER9 pVertexBuffer = 0;
		LPDIRECT3DINDEXBUFFER9  pIndexBuffer  = 0;

		tVertexReader*          pVertexReader;
		WORD*                   pIndexReader;
		tLevelSubset*           pLevelSubsetInfo;
		tTriangleIndexes        triangleIndexes;

		pLevel->pMesh->lpMesh->GetVertexBuffer(&pVertexBuffer);
		pLevel->pMesh->lpMesh->GetIndexBuffer(&pIndexBuffer);

		this->m_pDX3D->GetD3DDevice()->SetStreamSource( 0,pVertexBuffer, 0, sizeof(tVertexReader) );
		this->m_pDX3D->GetD3DDevice()->SetFVF( D3DFVF_XYZ );
		this->m_pDX3D->GetD3DDevice()->SetIndices(pIndexBuffer);

		for(DWORD dwAttributeIndex = 0;
		          dwAttributeIndex < pLevel->dwAttributesQty;
			      dwAttributeIndex ++                          )
		{
			//each attribute has its own aabb...
			// so we  reset the information
			float fxMin =  999999.99f;
			float fxMax = -999999.99f;
			float fzMin =  999999.99f;
			float fzMax = -999999.99f;

			pLevelSubsetInfo = new tLevelSubset;
			pLevelSubsetInfo->dwSubsetId = dwAttributeIndex;

			DWORD dwPlaceholder;
			dwPlaceholder = pLevel->pAttributes[dwAttributeIndex].AttribId;
			
			if (SUCCEEDED 
				(	pVertexBuffer->Lock( 
											(
												pLevel->pAttributes[dwAttributeIndex].VertexStart *
												(sizeof(float) * 3)
											),

											(
												pLevel->pAttributes[dwAttributeIndex].VertexCount *
												(sizeof(float) * 3)
											),

											(void **) &pVertexReader,

											D3DLOCK_READONLY
										)
				)
			)
			{
				if(SUCCEEDED
					( pIndexBuffer->Lock(
											(
												pLevel->pAttributes[dwAttributeIndex].FaceStart *
												(sizeof(WORD) * 3)
											),

											(
												pLevel->pAttributes[dwAttributeIndex].FaceCount *
												(sizeof(WORD) * 3)
											),

											(void **) &pIndexReader,

											D3DLOCK_READONLY
										)
					)
				)
				{
					for(unsigned int iCurrentVertex = 0;
									 iCurrentVertex < ((pLevel->pAttributes[dwAttributeIndex].FaceCount) * 3);
									 iCurrentVertex++  )
					{
						if(pVertexReader[pIndexReader[iCurrentVertex]].x < fxMin )
						{
							fxMin = pVertexReader[pIndexReader[iCurrentVertex]].x;
						}
						else if(pVertexReader[pIndexReader[iCurrentVertex]].x > fxMax )
						{
							fxMax = pVertexReader[pIndexReader[iCurrentVertex]].x;
						} 

						if( pVertexReader[pIndexReader[iCurrentVertex]].z < fzMin )
						{
							fzMin = pVertexReader[pIndexReader[iCurrentVertex]].z;
						}
						else if( pVertexReader[pIndexReader[iCurrentVertex]].z > fzMax )
						{
							fzMax = pVertexReader[pIndexReader[iCurrentVertex]].z;
						}

					}

				}

			}
			pVertexBuffer->Unlock();
			pLevelSubsetInfo->aabb.fMinX = fxMin;
			pLevelSubsetInfo->aabb.fMinZ = fzMin;
			pLevelSubsetInfo->aabb.fMaxX = fxMax;
			pLevelSubsetInfo->aabb.fMaxZ = fzMax;

			this->m_vecLevelSubsetInfo.push_back(pLevelSubsetInfo);
		}
	}
	
}

[Edited by - plasmalasgun on June 14, 2005 9:49:25 AM]

Share this post


Link to post
Share on other sites
Advertisement
You might find your post is more appreciated by people in the forums if you use the [ source ] ... [ /source ] tags [smile]

void 3DManager::RenderModelSubset( tMesh* pMesh,
DWORD dwModelSubsetID )
{
D3DCAPS9 pCaps;
m_d3dDevice->GetDeviceCaps(&pCaps);

// Set the material and texture for this subset
m_d3dDevice->SetMaterial( &pMesh->pMaterials[dwModelSubsetID] );
m_d3dDevice->SetTexture( 0, pMesh->lpTextures[dwModelSubsetID] );
m_d3dDevice->SetTextureStageState(0, (D3DTEXTURESTAGESTATETYPE)16/*D3DTSS__MAGFILTER*/, (D3DTEXTUREFILTERTYPE)3/*D3DTEXF_ANISOTROPIC*/); //check
m_d3dDevice->SetTextureStageState(0, (D3DTEXTURESTAGESTATETYPE)17/*D3DTSS_MINFILTER*/, (D3DTEXTUREFILTERTYPE)3/*D3DTEXF_ANISOTROPIC*/); //check
m_d3dDevice->SetTextureStageState(0, (D3DTEXTURESTAGESTATETYPE)18/*D3DTSS_MIPFILTER*/, (D3DTEXTUREFILTERTYPE)3/*D3DTEXF_ANISOTROPIC*/); //check
m_d3dDevice->SetTextureStageState(0, (D3DTEXTURESTAGESTATETYPE)21/*D3DTSS_MAXANISOTROPY*/, pCaps.MaxAnisotropy);

pMesh->lpMesh->DrawSubset( dwModelSubsetID );

}
//////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////
HRESULT Renderer::SetLevelSubsets(tLevel* pLevel)
{


DWORD dwNumFaces = pLevel->pMesh->lpMesh->GetNumFaces();



///////////////////////////////////////////////////////////////////////////
// Parse the Attribute buffer in order to assign the subsets information //
///////////////////////////////////////////////////////////////////////////

// lock the attribute buffer
DWORD *attribBuf;
HRESULT hResult;


DWORD dwNumVerts = dwNumFaces * 3;
// allocate storage and generate adjacency data
DWORD *pAdjacencyData = new DWORD[ dwNumVerts ];

if (!pAdjacencyData)
return E_OUTOFMEMORY;
if (FAILED( hResult = pLevel->pMesh->lpMesh->GenerateAdjacency(0.0f,pAdjacencyData) ))
{
delete pAdjacencyData;
return hResult;
}

// optimize the mesh with attribute sorting
if (FAILED(hResult = pLevel->pMesh->lpMesh->OptimizeInplace(D3DXMESHOPT_VERTEXCACHE|D3DXMESHOPT_ATTRSORT,pAdjacencyData,NULL,NULL,NULL)) )
{
delete pAdjacencyData;
return hResult;
}



// de-allocate adjacency data storage
delete pAdjacencyData;


pLevel->pMesh->lpMesh->GetAttributeTable( NULL, &pLevel->dwAttributesQty );
pLevel->pAttributes = new D3DXATTRIBUTERANGE[ pLevel->dwAttributesQty ];
pLevel->pMesh->lpMesh->GetAttributeTable (pLevel->pAttributes, &pLevel->dwAttributesQty );



////////////////////////////////////////////////////////////
// Traverses each Subset's individual indexes by offseting
// by the size of each subset the index buffer to access the
// vertex positional information for creating a bounding box
////////////////////////////////////////////////////////////
LPDIRECT3DVERTEXBUFFER9 pVertexBuffer = 0;
LPDIRECT3DINDEXBUFFER9 pIndexBuffer = 0;

tVertexReader* pVertexReader;
WORD* pIndexReader;
tLevelSubset* pLevelSubsetInfo;
tTriangleIndexes triangleIndexes;

pLevel->pMesh->lpMesh->GetVertexBuffer(&pVertexBuffer);
pLevel->pMesh->lpMesh->GetIndexBuffer(&pIndexBuffer);

this->m_pDX3D->GetD3DDevice()->SetStreamSource( 0,pVertexBuffer, 0, sizeof(tVertexReader) );
this->m_pDX3D->GetD3DDevice()->SetFVF( D3DFVF_XYZ );
this->m_pDX3D->GetD3DDevice()->SetIndices(pIndexBuffer);

for(DWORD dwAttributeIndex = 0;
dwAttributeIndex < pLevel->dwAttributesQty;
dwAttributeIndex ++ )
{
//each attribute has its own aabb...
// so we reset the information
float fxMin = 999999.99f;
float fxMax = -999999.99f;
float fzMin = 999999.99f;
float fzMax = -999999.99f;

pLevelSubsetInfo = new tLevelSubset;
pLevelSubsetInfo->dwSubsetId = dwAttributeIndex;

DWORD dwPlaceholder;
dwPlaceholder = pLevel->pAttributes[dwAttributeIndex].AttribId;

if (SUCCEEDED
( pVertexBuffer->Lock(
(
pLevel->pAttributes[dwAttributeIndex].VertexStart *
(sizeof(float) * 3)
),

(
pLevel->pAttributes[dwAttributeIndex].VertexCount *
(sizeof(float) * 3)
),

(void **) &pVertexReader,

D3DLOCK_READONLY
)
)
)
{
if(SUCCEEDED
( pIndexBuffer->Lock(
(
pLevel->pAttributes[dwAttributeIndex].FaceStart *
(sizeof(WORD) * 3)
),

(
pLevel->pAttributes[dwAttributeIndex].FaceCount *
(sizeof(WORD) * 3)
),

(void **) &pIndexReader,

D3DLOCK_READONLY
)
)
)
{
for(unsigned int iCurrentVertex = 0;
iCurrentVertex < ((pLevel->pAttributes[dwAttributeIndex].FaceCount) * 3);
iCurrentVertex++ )
{
if(pVertexReader[pIndexReader[iCurrentVertex]].x < fxMin )
{
fxMin = pVertexReader[pIndexReader[iCurrentVertex]].x;
}
else if(pVertexReader[pIndexReader[iCurrentVertex]].x > fxMax )
{
fxMax = pVertexReader[pIndexReader[iCurrentVertex]].x;
}

if( pVertexReader[pIndexReader[iCurrentVertex]].z < fzMin )
{
fzMin = pVertexReader[pIndexReader[iCurrentVertex]].z;
}
else if( pVertexReader[pIndexReader[iCurrentVertex]].z > fzMax )
{
fzMax = pVertexReader[pIndexReader[iCurrentVertex]].z;
}

}

}

}
pVertexBuffer->Unlock();
pLevelSubsetInfo->aabb.fMinX = fxMin;
pLevelSubsetInfo->aabb.fMinZ = fzMin;
pLevelSubsetInfo->aabb.fMaxX = fxMax;
pLevelSubsetInfo->aabb.fMaxZ = fzMax;

this->m_vecLevelSubsetInfo.push_back(pLevelSubsetInfo);
}
}

}


Basic questions:

1. Any chance of a screenshot to show us what you mean?
2. Have you verified that your texture coordinates are valid?
3. Verified that your texture is correct?
4. Run it against the debug runtime and watched for any warnings/errors?
5. Run it on the D3DDEVTYPE_REF to eliminate any driver/hardware issues?
6. Can you verify that your BBox code isn't screwing something up? if you disable that code does it render correctly?

One other thing, why have you gotten rid of the constants in your SetTextureStageState() calls? I understand it could just be for debugging, but it doesn't make for either good or readable code!

Sorry to sound a bit blunt, but there are a few obvious things that it's well worth learning to check when you get these errors. If you don't quite understand the steps I've mentioned above, post back here and I'll explain them to you..

hth
Jack

Share this post


Link to post
Share on other sites
1. Any chance of a screenshot to show us what you mean?


2. Have you verified that your texture coordinates are valid?
// havent changed the... how to check em?

3. Verified that your texture is correct?
// texture is correct, i viewed the file in the mesh viewer

4. Run it against the debug runtime and watched for any warnings/errors?
// no warnnings or errors

5. Run it on the D3DDEVTYPE_REF to eliminate any driver/hardware issues?
/// ?
6. Can you verify that your BBox code isn't screwing something up? if you disable that code does it render correctly?
// Ill do this as a last resort... my frustumn culling wont work with this code off (no geometry rendered...)

Share this post


Link to post
Share on other sites
FIXED...
We needed to state the set sampler's state
texture adress as WRAP in both the u and the v

///////////////////////////////////////////////////////////////////
void FSR_3DManager::RenderModelSubset( tMesh* pMesh,
DWORD dwModelSubsetID )
{
D3DCAPS9 pCaps;
m_d3dDevice->GetDeviceCaps(&pCaps);



m_d3dDevice->SetFVF( m_dwFVF );

m_d3dDevice->SetSamplerState(0, D3DSAMP_ADDRESSU, D3DTADDRESS_WRAP );
m_d3dDevice->SetSamplerState(0, D3DSAMP_ADDRESSV, D3DTADDRESS_WRAP );
m_d3dDevice->SetMaterial( &pMesh->pMaterials[dwModelSubsetID] );
m_d3dDevice->SetTexture( 0, pMesh->lpTextures[dwModelSubsetID] );

m_d3dDevice->SetTextureStageState(0, (D3DTEXTURESTAGESTATETYPE)16/*D3DTSS__MAGFILTER*/, (D3DTEXTUREFILTERTYPE)3/*D3DTEXF_ANISOTROPIC*/);
m_d3dDevice->SetTextureStageState(0, (D3DTEXTURESTAGESTATETYPE)17/*D3DTSS_MINFILTER*/, (D3DTEXTUREFILTERTYPE)3/*D3DTEXF_ANISOTROPIC*/);
m_d3dDevice->SetTextureStageState(0, (D3DTEXTURESTAGESTATETYPE)18/*D3DTSS_MIPFILTER*/, (D3DTEXTUREFILTERTYPE)3/*D3DTEXF_ANISOTROPIC*/);
m_d3dDevice->SetTextureStageState(0, (D3DTEXTURESTAGESTATETYPE)21/*D3DTSS_MAXANISOTROPY*/, pCaps.MaxAnisotropy);

pMesh->lpMesh->DrawSubset( dwModelSubsetID );

}
///////////////////////////////////////////////////////////////////

Share this post


Link to post
Share on other sites
Sign in to follow this  

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