Jump to content
  • Advertisement
Sign in to follow this  
parmar

OpenGL How to perform depth test in pixel shader

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

Hi Guys, I wanted to know how we can perform depth test in pixel shader for knowledge purpose.I am using openGL ES 2.0 and GLSL 1.0.I have tried to search on google also but i didnt get any much info on this topic.Please give me some link or if any document is there. Regards, Parmar.

Share this post


Link to post
Share on other sites
Advertisement
Doing depth testing yourself would require reading what is already in the depth buffer and reading the depth buffer is not possible from a pixel shader.

Share this post


Link to post
Share on other sites
Thanks V-man for your reply.As usual you replied for my question.

I think i could not formed the proper sentence.
How i will get the depth value of a pixel in
fragment shader.And can we write our own implementation
for depth test in vertex shader.
Regards,
Parmar.

Share this post


Link to post
Share on other sites
Quote:
Original post by Nanoha
Don't think you can, pixels don't get to the pixel shader if they fail the depth test.


Wrong. If you output your own depth value, the depth test happens after the pixel shader stage. Read about gl_FragDepth.

Quote:
Original post by parmar
How i will get the depth value of a pixel in
fragment shader.And can we write our own implementation
for depth test in vertex shader.


You could do render to a depth texture in pass 1, then in the next pass, read that texture and do your own depth testing. Normally, you do this in a pixel shader.

Share this post


Link to post
Share on other sites

Thanks V-man,

@V-man Is any document or sample is there for this concept.
so I can go through it.I am a regular reader of this
community but i didnt get much info on this concept.


@Nanoha thanks for your reply.

Share this post


Link to post
Share on other sites
There is this extension
examples are on that page
http://www.opengl.org/wiki/GL_EXT_framebuffer_object

There is the GL 3.0 version
http://www.opengl.org/wiki/Framebuffer_Objects

Share this post


Link to post
Share on other sites

I have a one doubt about depth test.
After vertex sahder traingle will rasterize,and it will get color and
depth value of per fragemnt.So why we dont have the depth test there only.
Even some fargment is occuleded we are accesing the per fragemnt color
and texture fetch in pixel shader.Can any one suggest.

Parmar.

Share this post


Link to post
Share on other sites
Search for early Z pass, pre z pass, etc. you generally turn off color writes, and only write depth, so you dont bother with textures in an early z pass, so there is no color value being written.

Share this post


Link to post
Share on other sites
Couldn't this depth test (the rendered to texture thing) used to draw decals on surfaces?

simply:
if(fabs(frag_depth-texture_depth(x,y))> tolerance )
discard fragment

No need of clipping, just draw it

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!