alter fragment (alpha) on depth fail

Started by
2 comments, last by Kincaid 15 years, 4 months ago
Hello everyone I have a scene with labels (3d letters) floating above stuff. I want these names to be visible always, so glDepthFunc(GL_ALWAYS) solves that nicely. However, it would be cool to alpha blend parts of the label that are obscured by other objects (like in strategy games, when a settlers is behind a tree or something, you can still see him, but blended). shaders apart, is there a way to simply state if depthfail -> fragment.color.a = 0.5f; ?? (i dont believe shaders would do this anyway sinced a depthfail prohibits a fragment to be passed to the shader at all, but again, im not looking for an shader approach, hoping to solve this on a pixelbasis with standard opengl) Im thinking about the stencil buffer which lets you define an action on depthfail, but this is only with respect to stenciling, and im NOT gonna - stencil the scene - print blended version of letters in stencil - draw scene - draw letters normal where stencil = x/ blended where stencil = y too expensive.... Im guessing it cannot be done that simply since there is no glDepthOp or something that lets you acces and alter fragments (although they are available in the colorbuffer) thanx in advance
Advertisement
1. Shaders don't tell if you a fragment passed the test or not.
2. You should use shaders for everything anyway.
3. Yes, stencil buffer can be used for this.
- render your scene
- render the letters and where the depth test fails, set stencil to 1
- enable blending, render the letters where stencil=1

The expensive part is the blending. Whenever you have blending enable, performance drops according to the number of pixels to blend.
Sig: http://glhlib.sourceforge.net
an open source GLU replacement library. Much more modern than GLU.
float matrix[16], inverse_matrix[16];
glhLoadIdentityf2(matrix);
glhTranslatef2(matrix, 0.0, 0.0, 5.0);
glhRotateAboutXf2(matrix, angleInRadians);
glhScalef2(matrix, 1.0, 1.0, -1.0);
glhQuickInvertMatrixf2(matrix, inverse_matrix);
glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);
Thanx for the reply, however, it doesn't answer my question.
I know that I can employ the stencil, but I dont want to... (info is already there (zfail), doesn't need to be stenciled (in principle))
Im looking for the easiest way (shaderless) to alter the alphacomponent to 0.5f (or whatever) the moment a fragment fails the depth test...
I see this as the most direct/cheap way, but dont know if it is possible
(maybe something like the glStencilOp...idk...there you can say, GL_SOMETHING on depthfail, and I want to say framgament.color.A = x on depthfail)

(and yes, this info isnt even avilable in shader world)
Well, you could always reverse the direction of the z-test. This is normally something you do NOT want to do because it causes a hefty stall, but that is probably still cheaper than first rendering to stencil and then rendering again with stencil test.

Having inverted the direction, you are now interested not in fragments that fail, but fragments that pass. As it happens, these are the ones the hardware draws.

With the right parameters to glBlendFuncSeparate/glBlendEquationSeparate, this should work. Personally, I always found those functions unintuitive and hard to grasp, but it should be possible with a little trial and error.
Hmm they are unknown calls to my opengl version, and it still doesnt seem to be able to change the color of a fragment.
also, i dont believe this is the desired result, the 'most' back polygon will be allowed, but i need all 'in between'.
also, reversing de depthfunc (kinda the same idea) also simply reverses the question : howto change fragment color on depthpass...


thanx though
(ill google those functions anyways and see)



PS: anyone know how 'they' do it in the big games?? stenciling i guess then...

This topic is closed to new replies.

Advertisement