Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


Object appears partly transparent when rotated


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
23 replies to this topic

#1 gchris6810   Members   -  Reputation: 207

Like
0Likes
Like

Posted 17 November 2013 - 09:42 AM

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



Sponsor:

#2 N.I.B.   Members   -  Reputation: 1195

Like
0Likes
Like

Posted 17 November 2013 - 10:36 AM

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.



#3 gchris6810   Members   -  Reputation: 207

Like
0Likes
Like

Posted 17 November 2013 - 10:44 AM

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.



#4 gchris6810   Members   -  Reputation: 207

Like
0Likes
Like

Posted 17 November 2013 - 11:15 AM

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?



#5 N.I.B.   Members   -  Reputation: 1195

Like
0Likes
Like

Posted 17 November 2013 - 11:26 AM

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.



#6 Tom KQT   Members   -  Reputation: 1612

Like
0Likes
Like

Posted 17 November 2013 - 11:53 AM

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.



#7 gchris6810   Members   -  Reputation: 207

Like
0Likes
Like

Posted 17 November 2013 - 12:08 PM

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 );
		}
	}


#8 L. Spiro   Crossbones+   -  Reputation: 14033

Like
1Likes
Like

Posted 17 November 2013 - 03:54 PM

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
It is amazing how often people try to be unique, and yet they are always trying to make others be like them. - L. Spiro 2011
I spent most of my life learning the courage it takes to go out and get what I want. Now that I have it, I am not sure exactly what it is that I want. - L. Spiro 2013
I went to my local Subway once to find some guy yelling at the staff. When someone finally came to take my order and asked, “May I help you?”, I replied, “Yeah, I’ll have one asshole to go.”
L. Spiro Engine: http://lspiroengine.com
L. Spiro Engine Forums: http://lspiroengine.com/forums

#9 Tom KQT   Members   -  Reputation: 1612

Like
0Likes
Like

Posted 18 November 2013 - 01:41 AM

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.


#10 C0lumbo   Crossbones+   -  Reputation: 2422

Like
0Likes
Like

Posted 18 November 2013 - 02:22 AM

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)



#11 gchris6810   Members   -  Reputation: 207

Like
0Likes
Like

Posted 18 November 2013 - 10:21 AM

The values in my model view projection matrix are as follows:

 

  0.035, 0, 0, 0,

  0, 0, 0.045, 0,

  0, 0, 0.045, 0,

  0, 0, 0, 0

 

The code I use to get the matrix is just a simple scale operation so the model fits within the screen:

mMVP.Identity( );  // Sets the matrix to identity
mMVP.Scale( 0.035f, 0.045f, 0.045f );  // Scales the matrix. Scale(xScale, yScale, zScale)


#12 gchris6810   Members   -  Reputation: 207

Like
0Likes
Like

Posted 18 November 2013 - 10:26 AM

A larger image smile.png

 

By4gzzd.png?1

 

And this is how it should look:

 

TEqVqy8.png


Edited by gchris6810, 18 November 2013 - 10:29 AM.


#13 Migi0027 =A=   Crossbones+   -  Reputation: 1993

Like
0Likes
Like

Posted 18 November 2013 - 01:05 PM

Please try the Assimp view, it's a great tool, maybe this doesn't apply to the way you load your model, but I usually need to triangulate my imported models.

 

Hope this might prove useful.

-MIGI0027


Hi! Cuboid Zone
The Rule: Be polite, be professional, but have a plan to steal all their shaders!


#14 L. Spiro   Crossbones+   -  Reputation: 14033

Like
0Likes
Like

Posted 18 November 2013 - 01:58 PM

The values in my model view projection matrix are as follows:
 
  0.035, 0, 0, 0,
  0, 0, 0.045, 0,
  0, 0, 0.045, 0,
  0, 0, 0, 0
 
The code I use to get the matrix is just a simple scale operation so the model fits within the screen:

mMVP.Identity( );  // Sets the matrix to identity
mMVP.Scale( 0.035f, 0.045f, 0.045f );  // Scales the matrix. Scale(xScale, yScale, zScale)

I highly doubt that is the model/view/projection matrix. It is at best part of a model matrix. You would have ended up with:
[0.035, 0.000, 0.000, 0.000]
[0.000, 0.045, 0.000, 0.000]
[0.000, 0.000, 0.045, 0.000]
[0.000, 0.000, 0.000, 1.000]

Please post accurate information.


L. Spiro


It is amazing how often people try to be unique, and yet they are always trying to make others be like them. - L. Spiro 2011
I spent most of my life learning the courage it takes to go out and get what I want. Now that I have it, I am not sure exactly what it is that I want. - L. Spiro 2013
I went to my local Subway once to find some guy yelling at the staff. When someone finally came to take my order and asked, “May I help you?”, I replied, “Yeah, I’ll have one asshole to go.”
L. Spiro Engine: http://lspiroengine.com
L. Spiro Engine Forums: http://lspiroengine.com/forums

#15 JacobM   Members   -  Reputation: 160

Like
0Likes
Like

Posted 18 November 2013 - 07:39 PM

I was actually having the same issue. Thought it had something to do with the importer I wrote, but some models showed up correctly while others didn't. A temporary fix is just to invert the polygons in your 3D program. I suspect the problem has something to do with the objects normals.



#16 Rld_   Members   -  Reputation: 1498

Like
0Likes
Like

Posted 19 November 2013 - 03:56 AM

Try to narrow down your problem space. I am assuming you did all the above mentioned potential solutions and I have to agree with L. sprio that I also think it's related to the vertexbuffer or how you use it. (or indirectly your vertices).

 

Try exporting a simple cube the same way you export the other model, this way you can easily debug your way through the buffers (and perhaps also check the model file if eveything is right) and see if all the data is right.

 

At first sight, I'd have to say it looks kind of like a triangulation error. Make sure your model is fully triangulated by either the exporter or yourself (through the modeling package). 

 

Nonetheless I would still suggest trying a simpler model and see if all the data is initially correct.



#17 ankhd   Members   -  Reputation: 1325

Like
0Likes
Like

Posted 21 November 2013 - 06:57 AM

need move views of it, side view please.

 

my first throught was it goes pass the near plane.



#18 gchris6810   Members   -  Reputation: 207

Like
0Likes
Like

Posted 23 November 2013 - 04:06 AM

I've just found something which may be of some use. When I enable triangle clipping based on depth large parts of the model go missing seemingly by a certain plain of depth. Also, when I completely remove the rasterizer state the wrong triangles are clipped as they are the triangles visible to the camera but the parts of the model you can see appear perfectly.

 

Do you have any ideas of how I could solve this in DirectX 11 that extend on the ideas above?

 

EDIT: A basic cube renders fine with no missing triangles


Edited by gchris6810, 23 November 2013 - 05:20 AM.


#19 N.I.B.   Members   -  Reputation: 1195

Like
0Likes
Like

Posted 23 November 2013 - 07:07 AM


When I enable triangle clipping based on depth large parts of the model go missing seemingly by a certain plain of depth

Not sure what you mean by that. Depth clipping is enabled by default, you must have changed something else in the rasterizer state.

 


when I completely remove the rasterizer state

There's no way to remove the rasterizer state. You mean set it to NULL? In that case, you'll get the default rasterizer values(scroll to the remarks section).

 

Have you tried loading it in AssimpView? Please try it to at least make sure your model is exported correctly.



#20 gchris6810   Members   -  Reputation: 207

Like
0Likes
Like

Posted 23 November 2013 - 07:13 AM

In Assimp view no textured model exported by Blender seems to work.






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS