Jump to content
  • Advertisement
Sign in to follow this  
Kincaid

OpenGL alter fragment (alpha) on depth fail

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

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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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)

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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...

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!