Advertisement Jump to content
Sign in to follow this  
gchris6810

Object appears partly transparent when rotated

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

Hi,

 

I have managed to render a 3D model with Direct3D 11 but when it is rotated some of the triangles in the mesh go transparent as seen in the image below. I think this may have something to do with the depth buffer but i'm not sure how to fix it. At the moment my depth buffer is a D3D 11 Depth Stencil view. Notice the transparent triangles in the area the camera is directly facing.

 

8ovWGPr.png?1

Share this post


Link to post
Share on other sites
Advertisement

It's not necessarily a depth buffer issue. The image is too small, but it appears entire triangles are missing, so it might be backface culling problem.

Check the following:

- Make sure your model is correct - all triangles facing the same direction. Load it with an external program such as AssimpView to make sure no issues with the model.

- Check that backface culling is enabled, cull mode is CULL_BACK, FrontCounterClockwise is false, or set the rasterizer state to NULL.

- Check that your depth stencil state is correct. Basically - you should set it to NULL.

- Make sure to clear the depth buffer before calling the draw.

 

Just to be on the safe side, call RSSetState(NULL), OMSetDepthStencilState(NULL) and OMSetBlendState(NULL) before the draw.

Share this post


Link to post
Share on other sites

No sorry, I tried all of your potential solutions and none of them worked. Removing the depth stencil state just made the render even worse. The model comes from Blender where it renders fine so I don't think it is an issue with the model. Although I do agree with you that it may be a back face culling issue.

Share this post


Link to post
Share on other sites

I found out that when I try and import the model into Blender there is a similar problem with black missing triangles. Why would this be?

Share this post


Link to post
Share on other sites

Did you try AssimpView? sounds like something went wrong during export.

 


Removing the depth stencil state just made the render even worse.

Remove the state or the view? Setting the state to NULL is not removing the state, it's setting it to default values, which is exactly what you want for a simple renderer.

Share this post


Link to post
Share on other sites

Another possible source of problems - check the near Z and far Z values in your projection matrix. If they are too far from each other, you can have serious problems with depth buffer precision. People often tend to put large nubers there (near = 0.0001f, far = 100000.0f), thinking it would always cover the whole scene without having to care about it anymore.

Share this post


Link to post
Share on other sites

I just remembered I rendered a model using OpenGL ES and I had a similar sort of problem. Could it be to do with the function I am using to get the right rotation matrix? Here is the code:

        void Matrix4x4::Rotate( float angle, float x, float y, float z )
	{
		float sinAngle, cosAngle;
		float mag = sqrtf( x * x + y * y + z * z );

		sinAngle = sinf( angle * 3.14159 / 180.0f );
		cosAngle = cosf( angle * 3.14159 / 180.0f );
		if ( mag > 0.0f )
		{
			float xx, yy, zz, xy, yz, zx, xs, ys, zs;
			float oneMinusCos;
			Matrix4x4 rotMat;

			x /= mag;
			y /= mag;
			z /= mag;

			xx = x * x;
			yy = y * y;
			zz = z * z;
			xy = x * y;
			yz = y * z;
			zx = z * x;
			xs = x * sinAngle;
			ys = y * sinAngle;
			zs = z * sinAngle;
			oneMinusCos = 1.0f - cosAngle;

			rotMat.matrix[0].x = ( oneMinusCos * xx ) + cosAngle;
			rotMat.matrix[0].y = ( oneMinusCos * xy ) - zs;
			rotMat.matrix[0].z = ( oneMinusCos * zx ) + ys;
			rotMat.matrix[0].w = 0.0F;

			rotMat.matrix[1].x = ( oneMinusCos * xy ) + zs;
			rotMat.matrix[1].y = ( oneMinusCos * yy ) + cosAngle;
			rotMat.matrix[1].z = ( oneMinusCos * yz ) - xs;
			rotMat.matrix[1].w = 0.0F;

			rotMat.matrix[2].x = ( oneMinusCos * zx ) - ys;
			rotMat.matrix[2].y = ( oneMinusCos * yz ) + xs;
			rotMat.matrix[2].z = ( oneMinusCos * zz ) + cosAngle;
			rotMat.matrix[2].w = 0.0F;

			rotMat.matrix[3].x = 0.0F;
			rotMat.matrix[3].y = 0.0F;
			rotMat.matrix[3].z = 0.0F;
			rotMat.matrix[3].w = 1.0F;

			Multiply( rotMat );
		}
	}

Share this post


Link to post
Share on other sites

Could it be to do with the function I am using to get the right rotation matrix?

No, it could not. Rotation matrices are not triangle-selective.
Neither are depth-buffer issues.

The only possible issues are:
* Triangle winding.
* Misaligned (corrupted) index buffers (if using index buffers).
* Corrupted vertex buffers.
* Misuse of vertex buffers (telling Direct3D that it is a triangle strip when it is in fact a triangle list, etc.)

If it takes multiple render calls to draw the object then there is also:
* Mismatched materials or invalid materials (resulting in blackness) assigned to triangles. This seems least likely.



Each of these is quite easy to test one-by-one.
If culling is disabled and it persists, then it is not a winding issue.

Testing if it is related to materials is trivial—make your shader return a hard-coded color that gradates with depth (if the whole object is a single color you won’t be able to tell if anything is missing, obviously) and a hard-coded alpha value of 1.


I only mention these first because they are so trivial to test, but it is likely to be related directly to the vertex buffers themselves. Either the vertices themselves are corrupted or they are being misrepresented to Direct3D via a bad index buffer or wrong flags on the render call.


I found out that when I try and[sic] import the model into Blender there is a similar problem with black missing triangles. Why would this be?

Why not explain to what format you exported in the first place? Is this your custom exporter and importer? If so then this is not useful information. If it is being exported and re-imported from a file format such as .FBX, it means the exporter itself is corrupting the vertex data.

Either way, all signs point to the vertex buffer.
Use PIX and verify the data being sent to Direct3D.


L. Spiro

Share this post


Link to post
Share on other sites
Neither are depth-buffer issues.
 
My problem is that the screenshot is very small and it's hard to really see the problem (especially when I don't know how is the model supposed to look). Depth-buffer issues are not triangle-selective of course, but some triangles can be more affected by it if they are close to other triangles and there's a problem with depth-buffer precision.

Share this post


Link to post
Share on other sites

Why don't you post the code where you create the projection and view matrix? My guess is that the model is miles away from the camera, but the camera's field of view is tiny to compensate, and you're not getting much depth precision as a result (this is based on thinking it looks like there isn't much perspective in your scene, the projection looks almost orthographic)

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!