Alpha in Mesh .x

Started by
11 comments, last by Buckeye 13 years, 5 months ago
I have a texture (.png) where the background is transparent (channel alpha):


In a 3d Studio MAX 2010:


and active after the Opacity:


I export to the format .x (with Plugin Panda),but when I load my game on the level, take a look:



Why?

Thanks


http://mateusvitali.wordpress.com/
Advertisement
Did you setup alpha blending in your code?
Yes,
	m_pDevice->SetRenderState( D3DRS_ALPHABLENDENABLE, true );	m_pDevice->SetRenderState( D3DRS_SRCBLEND , D3DBLEND_SRCALPHA );	m_pDevice->SetRenderState( D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA) ;
http://mateusvitali.wordpress.com/
".png" image in your post doesnt contain alpha channel so i have edited it
and exported it to dds so you can try to see if it works now?
If is this somewhat related to your previous thread then you would need to enable alpha blending in your shader:
technique tAlpha{    pass p0    {        VertexShader = compile vs_3_0 VS();        PixelShader  = compile ps_3_0 PS();        AlphaBlendEnable = true;        SrcBlend         = SrcAlpha;        DestBlend        = InvSrcAlpha;    }}

instead your code.
Quote:Original post by belfegor
".png" image in your post doesnt contain alpha channel so i have edited it
and exported it to dds so you can try to see if it works now?


Thank you and sorry for the work :)
But still the same problem :(


Quote:Original post by belfegor
If is this somewhat related to your previous thread then you would need to enable alpha blending in your shader:
technique tAlpha{    pass p0    {        VertexShader = compile vs_3_0 VS();        PixelShader  = compile ps_3_0 PS();        AlphaBlendEnable = true;        SrcBlend         = SrcAlpha;        DestBlend        = InvSrcAlpha;    }}

instead your code.

Thanks friend :D
but I'm not using shaders in this case

thanks
http://mateusvitali.wordpress.com/
Please post your whole render function.
class XMesh{public:	XMesh();	~XMesh();	void Release();	bool LoadMesh(IDirect3DDevice9 *pDevice, char *szFolder, char *szFileName, const bool bComputeNormals);	void RenderMesh(IDirect3DDevice9 *pDevice);		void changePosition(D3DXVECTOR3 positionVector);		void setPosition(D3DXVECTOR3 positionVector);	void setRotation(D3DXVECTOR3 rotationVector);	void setScale(D3DXVECTOR3 scaleVector);		LPD3DXMESH              getMesh();			// Return the Mesh	DWORD					getnMaterials();	// Return the array of nMaterials	D3DXVECTOR3				m_Min, m_Max;		// Bounding box	std::vector<LPDIRECT3DTEXTURE9>  GetTextures()  { return mTextures; }	std::vector<D3DMATERIAL9>		 GetMaterials() { return mMaterials; }private:	ID3DXMesh			   *m_pMesh;			// array of textures  	DWORD					m_nMaterials;		// number of materails in mesh 	std::vector<LPDIRECT3DTEXTURE9> mTextures;	std::vector<D3DMATERIAL9>		mMaterials;		D3DXMATRIX				transMatrix;		// the translation matrix	D3DXMATRIX				rotationMatrix;		// the rotation matrix	D3DXMATRIX				scaleMatrix;		// the scale matrix	D3DXVECTOR3				scale;				// the models scale	D3DXVECTOR3				position;			// the models position	D3DXVECTOR3				rotation;			// the models rotation};


#include "XMesh.h"//// Constructor of XMesh//XMesh::XMesh(){	m_pMesh = NULL;	m_nMaterials = 0x0;	m_Min.x = m_Min.y = m_Min.z = m_Max.x = m_Max.y = m_Max.z = 0.0f;}//// Destructor of XMesh//XMesh::~XMesh(){	Release();}//// Release of XMesh//void XMesh::Release(){		//Release the Mesh	if (m_pMesh != NULL)	{		m_pMesh->Release();		m_pMesh = NULL;	}	for(size_t i = 0; i < mTextures.size(); i++)	{		SAFE_RELEASE(mTextures);	}	//Release the Materials	m_nMaterials = 0;	mTextures.clear();	mMaterials.clear();	}//// Load the Mesh//bool XMesh::LoadMesh(IDirect3DDevice9 *pDevice, char *szFolder, char *szFileName, const bool bComputeNormals){	Release();	scale = D3DXVECTOR3(1.0f, 1.0f , 1.0f); //set our scale variable to 1	position = D3DXVECTOR3(0.0f, 0.0f , 0.0f); //set the position to 0,0,0	rotation = D3DXVECTOR3(0.0f, 0.0f , 0.0f); //set the rotation, to nothing.	ID3DXBuffer *pBuffer;	char szLocalization[1024];	if (szFolder)		strcpy(szLocalization, szFolder);	else		szLocalization[0] = '\0';	strcat(szLocalization, szFileName);	// Load the mesh	if(FAILED(D3DXLoadMeshFromX(szLocalization,				// Localization of the Mesh								D3DXMESH_SYSTEMMEM,	// where the data will be allocated in memory								pDevice,			// pointer to the device								NULL,				// buffer for adjacency (do not need it)								&pBuffer,			// buffer where to store the texture information, ...								NULL,				// buffer for efects (do not need it)								&m_nMaterials,		// total of different materials								&m_pMesh)))			// pointer to an object of mesh where our mesh is stored	{		MessageBox(NULL, "Mesh not found!", "Erro", MB_OK);		return false;	}	// takes a pointer array of materials	D3DXMATERIAL *mtrls = (D3DXMATERIAL*)pBuffer->GetBufferPointer();	// set materials and textures for mesh  	for(int t=0; t<(int)m_nMaterials; t++)	{		mMaterials.push_back(mtrls[t].MatD3D);		// if the current material has a texture ...		if(mtrls[t].pTextureFilename != NULL && strlen(mtrls[t].pTextureFilename) > 0)		{			IDirect3DTexture9 * newTexture = NULL;				if (szFolder)				strcpy(szLocalization, szFolder);			else				szLocalization[0] = '\0';			strcat(szLocalization, mtrls[t].pTextureFilename);				// carrega a textura...			if(FAILED(D3DXCreateTextureFromFile(pDevice, 												szLocalization, 												&newTexture)))			{				MessageBox(NULL, "Textura not found!", mtrls[t].pTextureFilename, MB_OK);			}			mTextures.push_back(newTexture);		}		else 		{			mTextures.push_back(NULL);					}	}	// Clears the buffer material	pBuffer->Release();	// If you want recomputes the normal ...	if (bComputeNormals)		D3DXComputeNormals(m_pMesh, NULL);		return true;	BYTE* pVertices=NULL;	m_pMesh->LockVertexBuffer(D3DLOCK_READONLY, (LPVOID*)&pVertices);		D3DXComputeBoundingBox((D3DXVECTOR3*)pVertices, m_pMesh->GetNumVertices(), D3DXGetFVFVertexSize(m_pMesh->GetFVF()), &m_Min, &m_Max);	m_pMesh->UnlockVertexBuffer();}void XMesh::RenderMesh(IDirect3DDevice9 *pDevice){	pDevice->SetRenderState( D3DRS_ALPHABLENDENABLE, true );	pDevice->SetRenderState( D3DRS_SRCBLEND , D3DBLEND_SRCALPHA );	pDevice->SetRenderState( D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);	//set the scale matrix	D3DXMatrixScaling(&scaleMatrix, scale.x,scale.y,scale.z);	// store the position information into the translation matrix	D3DXMatrixTranslation(&transMatrix, position.x, position.y, position.z);	// set the rotation matrix	D3DXMatrixRotationYawPitchRoll(&rotationMatrix,rotation.x,rotation.y,rotation.z);	// Multiply the translation matrix by the rotation matrix, store the result in the translation matrix	D3DXMatrixMultiply(&transMatrix, &rotationMatrix, &transMatrix);	// Multiply the translation matrix by the scale matrix,  store the result in the translation matrix	D3DXMatrixMultiply(&transMatrix, &scaleMatrix, &transMatrix);		// Position the object for rendering based on the position, rotation and scaleing.	pDevice->SetTransform(D3DTS_WORLD, &transMatrix);	for(int t=0; t<(int)m_nMaterials; t++)	{		pDevice->SetMaterial( &mMaterials[t] );		// sets the texture of that part of meshairplane		if( mTextures[t] )		{			pDevice->SetTexture( 0, mTextures[t] );		}		// Render this part of the Mesh			m_pMesh->DrawSubset(t);	}	// Now that we draw the mesh, we can reset the texture	// So that the texture of the mesh is not applied to other things	// Accidentally	pDevice->SetTexture(0, NULL);}////   Note: sets the position of the model//void XMesh::setPosition(D3DXVECTOR3 positionVector){	position = positionVector;}////   Note: adds the changeVector to the position, adjusting the position relitive to its current position//void XMesh::changePosition(D3DXVECTOR3 changeVector){	position = position + changeVector;}////   Note: sets the rotation of the model//void XMesh::setRotation(D3DXVECTOR3 rotationVector){	rotation = rotationVector;}////   Note: sets the scale of the model//void XMesh::setScale(D3DXVECTOR3 scaleVector){	scale = scaleVector;}////   Note: Return the current Mesh.//LPD3DXMESH XMesh::getMesh(){ 	return m_pMesh; }////   Note: Return the Materials//DWORD XMesh::getnMaterials(){	return m_nMaterials;}
http://mateusvitali.wordpress.com/
You need to enable alpha testing.
Quote:Original post by cgrant
You need to enable alpha testing.


The problems continue :(

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


EDIT:
It worked after I enabled the following options:
	m_pDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_CCW);	m_pDevice->SetRenderState(D3DRS_ZENABLE, D3DZB_TRUE);	m_pDevice->SetRenderState(D3DRS_AMBIENT, m_dwLightAmbient);	m_pDevice->SetSamplerState(0, D3DSAMP_MIPFILTER, D3DTEXF_LINEAR);	m_pDevice->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);	m_pDevice->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);	m_pDevice->SetRenderState( D3DRS_ALPHABLENDENABLE, true);	m_pDevice->SetRenderState( D3DRS_ALPHATESTENABLE, true);	m_pDevice->SetRenderState( D3DRS_SRCBLEND , D3DBLEND_SRCALPHA );	m_pDevice->SetRenderState( D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);



Can someone explain me why?

Thanks

EDIT EDIT:
The tree trunk is fading behind the leaves?! Why? (Was to appear among the leaves of the tree)
http://mateusvitali.wordpress.com/

This topic is closed to new replies.

Advertisement