[SOLVED] Weird Texture transparency problem

Started by
8 comments, last by Chetanhl 13 years, 6 months ago
Am upgrading my old texture loader code to include features like batching , multitextures,etc. But when i got it working i found a weird texture transparency problem which you can see in following screenshots -

image1

image2

I can see things behind the terrain surface as if texture is transparent.
I haven't loaded any transparent texture or used alpha blending or anything like that. Am loading a single texture from bmp file for whole terrain, treid other formats like jpg,tga,etc too.
I am implementing this in D3D9 Fixed funtion pipeline for now.

Here are my sampler & renderstates -

	chd3d->pd3dDevice->SetSamplerState(0,D3DSAMP_MINFILTER,D3DTEXF_LINEAR);	chd3d->pd3dDevice->SetSamplerState(0,D3DSAMP_MAGFILTER,D3DTEXF_LINEAR);	chd3d->pd3dDevice->SetSamplerState(0,D3DSAMP_MIPFILTER,D3DTEXF_LINEAR);	chd3d->pd3dDevice->SetRenderState(D3DRS_LIGHTING,false);	chd3d->pd3dDevice->SetRenderState(D3DRS_ZENABLE,true);	chd3d->pd3dDevice->SetRenderState(D3DRS_ALPHABLENDENABLE,false);	chd3d->pd3dDevice->SetTexture(0,texture->getTexture());	chd3d->pd3dDevice->SetTextureStageState(0,D3DTSS_COLORARG1,D3DTA_TEXTURE);	chd3d->pd3dDevice->SetTextureStageState(0,D3DTSS_COLOROP,D3DTOP_SELECTARG1);	chd3d->pd3dDevice->SetTextureStageState(0,D3DTSS_TEXCOORDINDEX,0);	chd3d->pd3dDevice->SetTextureStageState(1,D3DTSS_COLOROP,D3DTOP_DISABLE);        //disabling second texture till i fix this problem


Can anyone please tell me why these textures are being rendered in this weird manner ?

[Edited by - Chetanhl on September 28, 2010 3:36:12 PM]

My Game Development Blog : chetanjags.wordpress.com

Advertisement
Looks like a z-buffer problem to me. What format is your depth-stencil buffer, and what are your near and far clip planes set to (Near clip should be as far as possible, and definitely not 0)?
Quote:Original post by Evil Steve
Looks like a z-buffer problem to me. What format is your depth-stencil buffer, and what are your near and far clip planes set to (Near clip should be as far as possible, and definitely not 0)?


Thanks for quick reply.

I have treid these two Depth Stencil Formats -
D3DFMT_D24S8
D3DFMT_D24X8

I also tried few near and far clip plane values. But Currently -

Near Plane - 1.0f
Far Plane - 5000.0f

D3DXMatrixPerspectiveFovLH(&proj,D3DX_PI/2.0f, ((float)chd3d->getWidth()/(float)chd3d->getHeight()),
1.0f, 5000.0f);


Forgot to mention earlier, if it matters dimension of terrain is 2048x2048 units.

My Game Development Blog : chetanjags.wordpress.com

Is it possible that you're disabling the Z-buffer? I see you're changing the D3DRS_ZENABLE render state - you shouldn't need to touch that at all normally.
No am not disabling Z-buffer at all.
I inserted that line explicitly just while trying to make it work.

My Game Development Blog : chetanjags.wordpress.com

Are you certain that your terrain is seamless? Are you applying some sort of LOD to the mesh that could cause nearer portions to be drawn with different vertices than adjacent but more distant triangles?

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.

You don't forget how to play when you grow old; you grow old when you forget how to play.

Is the camera underneath the terrain? If it is then it won't look right unless you reverse D3DRS_CULLMODE (or turn it off).

You could also double check that D3DRS_ZWRITEENABLE is set, but it should be on by default.
Quote:Original post by Adam_42
Is the camera underneath the terrain? If it is then it won't look right unless you reverse D3DRS_CULLMODE (or turn it off).

You could also double check that D3DRS_ZWRITEENABLE is set, but it should be on by default.


Am not disabling Z-Buffer or ZWriteEnable at any point.

Camera is also above the terrain. I have implemented flexible camera class i can change it to FPS, 3rd Person, FreeLook etc and result is same as far as weird textures are concerned.

I am just trying to do following 3 things for now -

1)Load Height Map and make terrain
- Tried both my new subgrid code and a single grid for whole terrain
- Rendering terain as indexed trianglestrip
2) Load its texture
3) Render the terrain with texture

Am loading texture using this function if it helps -
D3DXCreateTextureFromFile()

But dunno what's wrong this time. I actually recoded the whole terrain class (using single grid for terrain approach) even then this problem persists.

I checked wireframe mode all tringles are being rendered without any probs.

My Game Development Blog : chetanjags.wordpress.com

Quote:Original post by Buckeye
Are you certain that your terrain is seamless? Are you applying some sort of LOD to the mesh that could cause nearer portions to be drawn with different vertices than adjacent but more distant triangles?


No am not performing any LOD for now infact the whole point of this recoding terrain loader was to include those things (subgrids,lod etc) and take it to shaders. But am stuck at first step only. -__-

For now I am just trying to achive 3 basic things mentioned in above post.

My Game Development Blog : chetanjags.wordpress.com

Finally it worked.
Problem was in a statement deep inside camera class where i was setting viewport using some improper settings.
my bad :(


Thanks again for helping.

My Game Development Blog : chetanjags.wordpress.com

This topic is closed to new replies.

Advertisement