Orthographic projection causes artifacts

Started by
2 comments, last by renman29 9 years, 7 months ago

Hey guys,

I observe strange artifacts in my application when I switch from perspective projection

to orthographic projection.

Here's an image of the problem: https://dl.dropboxusercontent.com/u/56764397/projection_bug.png

It looks to me like some sort of z-fighting.

Now, I'm using depth peeling for transparency and the artifacts

disappear when rendering with another transparency technique,

so maybe the issue is how I read and write the depth textures.

It's pretty strange, though, because the projection matrix is not referenced in any fragment shaders.

Any ideas what I can do to isolate the problem?

Advertisement

Hmm. To my surprise the problem disappears when I choose a sufficiently large negative value for the near clipping plane.

So before I set (znear, zfar) = (0.1, 100.0) for both the perspective and the orthographic projection matrix and the error

occurs. When I choose (znear, zfar) = (-100.0, 100.0) for the orthographic matrix everything looks fine.

I have no idea why. Since setting znear = -100.0 essentially doubles the viewing volume I would guess the error

becomes even worse!

Could be gldepthfunc, try using GL_ALWAYS?

I noticed a similar thing when I was rotating a plane of width 1000 so that part of it would be cut off by the near plane. I noticed that if for example the plane was 1000 in size then the front and far clipping planes would need to accommodate the size(around 0,0,0) so -500 to +500 or something like that. I did like you and changed it to allow bigger objects with world matrix applied and now it works - mine is like so:

public void Use2DCamera()

{

Shader.Projection = Matrix.CreateOrthographicOffCenter(0.0f, device.Viewport.Width, device.Viewport.Height, 0.0f, -2000f, 2000.0f); //near and far need to be huge for 3d world rotations to work

Shader.View = Matrix.Identity;

}

This topic is closed to new replies.

Advertisement