Jump to content
  • Advertisement
Sign in to follow this  
dbryant2710

depth testing

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

I have a particle system that renders explosions and other particle effects against the black clear color background. The problem im having is with depth testing. I render a textured quad right before i render the particles. Since it is opaque i turn on depth testing and depth writing, render the quad, turn of depth writing and render the particles. My camera looks down the -z axis. when the quad is in front of the particles(positive z), the quad disappears and the particles are seen however if the quad is behind the particles(negative z), the particles cannot be seen at all. any help will be appreciated.

Share this post


Link to post
Share on other sites
Advertisement
It sounds like your program is behaving as expected. The textured quad *should* obscure all things behind it and *should* obscure the particles provided that it is large enough.

I'm guessing that your textured quad has alpha and that you expect the particles to show up behind the clear parts of the quad? It doesn't work like that. The z-writes will be even across the entire quad. The solution in that case: You need to aways render alphaed things starting with the objects in the back and working your way towards the camera.

Share this post


Link to post
Share on other sites
Thanks for the reply.

The textured quad is completely opaque and was drawn using no blending or alpha testing. I might not have phrased my problem correctly. I understand that z writes will be uniform regardless of the alpha value. the camera has a position on the positive z-axis and faces the negative z-axis. When the quad is closer to the camera then the particles, it is supposed to obscure the particles. however instead it disappears and the particles are visible. when the quad is drawn farther away from the camera then the particles the particles should obscure the quad and the colors should be additively blended. however instead both the particles and the quad are completely invisible.

Share this post


Link to post
Share on other sites
yes in fact i do create my own camera matrix.
i will post all relevant code.

CVector3 View(0,0,1);
CVector3 Up(0,1,0);
CVector3 Right;
Right.Cross(View,Up);
Right.SetLength(1);
CVector3 Position(0,0,10);

SetupCameraMatrix(View,Up,Right,Position);

glEnable(GL_DEPH_TEST);
glDepthMask(true);
//Draw quad at (0,0,-3)

glDepthMask(false);
//draw particles at (0,0,0)

if anymore code is needed i will put it up

Share this post


Link to post
Share on other sites
Could we see SetupCameraMatrix code aswell please?
I think maybe
Right.Cross(View,Up);
should be
Right.Cross(Up,View);
IIRC in a right handed coordinate system you cross x by y to get z, y by z to get x and z by x to get y. View is z, and Up is y so it should be Up by View.
Maybe this or something like it is causing you to get some kind of funky viewing fustrum where your z coordinates are reversed, effectively reversing the way your z-buffer works.

Share this post


Link to post
Share on other sites
the setupcameramatrix function:



newMatrix[0] = right.x;
newMatrix[1] = right.y;
newMatrix[2] = right.z;

newMatrix[4] = up.x;
newMatrix[5] = up.y;
newMatrix[6] = up.z;

newMatrix[8] = view.x;
newMatrix[9] = view.y;
newMatrix[10] = view.z;

newMatrix[12] = pos.x;
newMatrix[13] = pos.y;
newMatrix[14] = pos.z;

newMatrix[3] = newMatrix[7] = newMatrix[11] = 0;
newMatrix[15] = 1;


glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glMultMatrixf(newMatrix);

I will change that order of the up and cross product to see if that solves the problem.

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!