• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
gchris6810

Object appears partly transparent when rotated

23 posts in this topic

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

0

Share this post


Link to post
Share on other sites

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.

0

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.

0

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?

0

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.

0

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.

0

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

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
1

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.
0

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)

0

Share this post


Link to post
Share on other sites

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)
0

Share this post


Link to post
Share on other sites

A larger image smile.png

 

By4gzzd.png?1

 

And this is how it should look:

 

TEqVqy8.png

Edited by gchris6810
0

Share this post


Link to post
Share on other sites

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

0

Share this post


Link to post
Share on other sites

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

0

Share this post


Link to post
Share on other sites

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.

0

Share this post


Link to post
Share on other sites

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.

0

Share this post


Link to post
Share on other sites

need move views of it, side view please.

 

my first throught was it goes pass the near plane.

0

Share this post


Link to post
Share on other sites

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
0

Share this post


Link to post
Share on other sites


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.

0

Share this post


Link to post
Share on other sites


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

 

You still haven't posted your projection matrix, along with the code that generates your projection matrix (as Spiro said, the thing that you posted was probably not your projection matrix, or if it was, then there's something seriously wrong with it and it's probably where it all goes wrong). Posting the view matrix too might be a good idea.

0

Share this post


Link to post
Share on other sites

Okay, now i'm sure it has something to do with the depth. When I rotate the object before I  do the first render pass 90 degrees the render appears completely 2D with all the triangles drawn on top of each other! It seems the closer to 90 degrees it is drawn the more of a 2D view you seem to get. I hope this helps.

 

Could someone please tell me what I have to do to solve this as it has been bugging me for a while now. As for the matrices you asked for, the matrix I posted previously is the only one I am using which is the models transform matrix (The bottom right element should be a 1 rather than a 0). 

Edited by gchris6810
0

Share this post


Link to post
Share on other sites

Okay, now i'm sure it has something to do with the depth. When I rotate the object before I  do the first render pass 90 degrees the render appears completely 2D with all the triangles drawn on top of each other! It seems the closer to 90 degrees it is drawn the more of a 2D view you seem to get. I hope this helps.

 

Could someone please tell me what I have to do to solve this as it has been bugging me for a while now. As for the matrices you asked for, the matrix I posted previously is the only one I am using which is the models transform matrix (The bottom right element should be a 1 rather than a 0). 

 

So this is your model transform matrix then?

 

  0.035, 0, 0, 0,

  0, 0, 0.045, 0,

  0, 0, 0.045, 0,

  0, 0, 0, 1

 

If so, then that is probably the problem, because that matrix is doing some sort of weird skew that would flatten the model completely along one axis. I'd expect something more like:

 

  0.035, 0, 0, 0,

  0, 0.045, 0, 0,

  0, 0, 0.045, 0,

  0, 0, 0, 1

0

Share this post


Link to post
Share on other sites

No sorry my matrix is the second one you posted.

 

 0.035, 0, 0, 0,

 0, 0.045, 0, 0,

 0, 0, 0.045, 0,

 0, 0, 0, 1

0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0