glDepthMask question
What does glDepthMask do exactly ? How does it affect blended objects ? Does it remove the need to sort them ?
Thanks,
Nitzan
-------------------------
www.geocities.com/nitzanw
www.scorchedearth3d.net
-------------------------
straight from the MSDN....
glDepthMask
for those of use to lazy to click on the link....
Platform SDK: OpenGL
glDepthMask
The glDepthMask function enables or disables writing into the depth buffer.
void glDepthMask(
GLboolean flag
);
Parameters
flag
Specifies whether the depth buffer is enabled for writing. If flag is zero, depth-buffer writing is disabled. Otherwise, it is enabled. Initially, depth-buffer writing is enabled.
Remarks
The following function retrieves information related to glDepthMask:
glGet with argument GL_DEPTH_WRITEMASK
Error Codes
The following is the error code generated and its condition.
Error code Condition
GL_INVALID_OPERATION glDepthMask was called between a call to glBegin and the corresponding call to glEnd.
and no it does remove the need to sort blended objects.
peace.
To the vast majority of mankind, nothing is more agreeable than to escape the need for mental exertion... To most people, nothing is more troublesome than the effort of thinking.
glDepthMask
for those of use to lazy to click on the link....
Platform SDK: OpenGL
glDepthMask
The glDepthMask function enables or disables writing into the depth buffer.
void glDepthMask(
GLboolean flag
);
Parameters
flag
Specifies whether the depth buffer is enabled for writing. If flag is zero, depth-buffer writing is disabled. Otherwise, it is enabled. Initially, depth-buffer writing is enabled.
Remarks
The following function retrieves information related to glDepthMask:
glGet with argument GL_DEPTH_WRITEMASK
Error Codes
The following is the error code generated and its condition.
Error code Condition
GL_INVALID_OPERATION glDepthMask was called between a call to glBegin and the corresponding call to glEnd.
and no it does remove the need to sort blended objects.
peace.
To the vast majority of mankind, nothing is more agreeable than to escape the need for mental exertion... To most people, nothing is more troublesome than the effort of thinking.
To the vast majority of mankind, nothing is more agreeable than to escape the need for mental exertion... To most people, nothing is more troublesome than the effort of thinking.
Whats the difference between doing
glDepthMask(0);
draw some stuff
glDepthMask(1);
and
glDisable(GL_DEPTH_TEST);
draw some stuff
glEnable(GL_DEPTH_TEST);
I understand that glDepthMask controlls WRITING to the depth buffer, while GL_DEPTH_TEST controlls the depth COMPARISON testing. But how does that translate into actually drawing blended objects onto the screen ?
Nitzan
-------------------------
www.geocities.com/nitzanw
www.scorchedearth3d.net
-------------------------
glDepthMask(0);
draw some stuff
glDepthMask(1);
and
glDisable(GL_DEPTH_TEST);
draw some stuff
glEnable(GL_DEPTH_TEST);
I understand that glDepthMask controlls WRITING to the depth buffer, while GL_DEPTH_TEST controlls the depth COMPARISON testing. But how does that translate into actually drawing blended objects onto the screen ?
Nitzan
-------------------------
www.geocities.com/nitzanw
www.scorchedearth3d.net
-------------------------
First of all, you should not use glDepthMask(0) and glDepthMask(1), but rather you should use respectively glDepthMask(GL_FALSE) and glDepthMask(GL_TRUE).
With that said, glDepthMask(GL_FALSE) is a kind of "read-only" whereas glDisbale(GL_DEPTH_TEST) is a "forget completely the depth buffer".
If depth testing is enabled, the "stuff" will be drawn wherever they are "in front of" what''s already drawn in the screen (if the depth test function is something like GL_LESS or GL_LEQUAL).
But this "stuff" will not write the depth buffer.
Imagine you look at two walls.
The wall 1 is closer to the camera than the wall 2.
Now imagine the code for drawing is that :
In this case, wall 2 will be visible even though in reality it is "behind" the wall 1.
Why ? because the wall 1 was drawn with glDepthMask(GL_FALSE), thus there is no trace of it in the depth buffer.
With that said, glDepthMask(GL_FALSE) is a kind of "read-only" whereas glDisbale(GL_DEPTH_TEST) is a "forget completely the depth buffer".
quote:
glDepthMask(0);
draw some stuff
glDepthMask(1);
If depth testing is enabled, the "stuff" will be drawn wherever they are "in front of" what''s already drawn in the screen (if the depth test function is something like GL_LESS or GL_LEQUAL).
But this "stuff" will not write the depth buffer.
Imagine you look at two walls.
The wall 1 is closer to the camera than the wall 2.
Now imagine the code for drawing is that :
glEnable(GL_DEPTH_TEST);glDepthFunc(GL_LESS);glDepthMask(GL_FALSE);draw_wall_1(); // draw the closest wallglDepthMask(GL_TRUE);draw_wall_2(); // draw the farthest wall
In this case, wall 2 will be visible even though in reality it is "behind" the wall 1.
Why ? because the wall 1 was drawn with glDepthMask(GL_FALSE), thus there is no trace of it in the depth buffer.
the difference being that "glWriteMask(GL_FALSE)" with depth testing enable still allows the current vertex depth test against the current values in the depth buffer. if you disable depth testing than no testing is done, so all vertices get drawn.
To the vast majority of mankind, nothing is more agreeable than to escape the need for mental exertion... To most people, nothing is more troublesome than the effort of thinking.
To the vast majority of mankind, nothing is more agreeable than to escape the need for mental exertion... To most people, nothing is more troublesome than the effort of thinking.
To the vast majority of mankind, nothing is more agreeable than to escape the need for mental exertion... To most people, nothing is more troublesome than the effort of thinking.
Ok, so if I want to draw a bunch of blended particles as the trail of rocket, and I want them to blend beautifuly together and with the landscape, but I DONT want them to be drawn in front of a mountain when they should be behing, I should leave DEPTH_TEST enabled, yet set DepthMask to 0, just when I draw the particles ?
Nitzan
-------------------------
www.geocities.com/nitzanw
www.scorchedearth3d.net
-------------------------
Nitzan
-------------------------
www.geocities.com/nitzanw
www.scorchedearth3d.net
-------------------------
if you want to do blending than enable blending. with depth testing enabled, objects behind the mountain are going to get drawn anyway.
To the vast majority of mankind, nothing is more agreeable than to escape the need for mental exertion... To most people, nothing is more troublesome than the effort of thinking.
To the vast majority of mankind, nothing is more agreeable than to escape the need for mental exertion... To most people, nothing is more troublesome than the effort of thinking.
To the vast majority of mankind, nothing is more agreeable than to escape the need for mental exertion... To most people, nothing is more troublesome than the effort of thinking.
Whops, what I meant was, is there a way to do beautiful blending of the particles without sorting yet with depth test enabled using some sort of combination of glDepthMask and glDepthTest ?
Ok that still sounds confusing, what I want to do is...
1) draw landscape
2) draw blended particles, so they blend to each other correctly
no matter where the camera is. I also want them to get drawn behind an object (building, mountain, etc...) if they are behind it.
Nitzan
-------------------------
www.geocities.com/nitzanw
www.scorchedearth3d.net
-------------------------
Ok that still sounds confusing, what I want to do is...
1) draw landscape
2) draw blended particles, so they blend to each other correctly
no matter where the camera is. I also want them to get drawn behind an object (building, mountain, etc...) if they are behind it.
Nitzan
-------------------------
www.geocities.com/nitzanw
www.scorchedearth3d.net
-------------------------
Yes.
Use normal glEnable (GL_DEPTH_TEST) throughout.
Draw the landscape
Disable depth writing
Draw the particles
Enable depth writing
Helpful links:
How To Ask Questions The Smart Way | Google can help with your question | Search MSDN for help with standard C or Windows functions
Use normal glEnable (GL_DEPTH_TEST) throughout.
Draw the landscape
Disable depth writing
Draw the particles
Enable depth writing
Helpful links:
How To Ask Questions The Smart Way | Google can help with your question | Search MSDN for help with standard C or Windows functions
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement