Jump to content
  • Advertisement
Sign in to follow this  
c_olin

OpenGL Deferred shading and alpha testing

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

In my deferred shading implementation I have my gbuffer laid out like so:

buffer 1: rgb = diffuseColor, a = specular
buffer 2: rgb = normal, a = depth

I'm rendering a lot of trees and vegetation and I have been rendering them using GL_ALPHA_TEST and glAlphaFunc(GL_GREATER, 0.5f). This worked great for fixed-function rendering but now that I'm rendering to a gbuffer I have run into issues.

Since I'm storing other values in the alpha channel of the buffers they don't get drawn when the specular is less than 0.5 and the normal color does not get drawn when the depth is less than 0.5.

Is there a way to do alpha testing without OpenGL's GL_ALPHA_TEST. I tried disabling GL_ALPHA_TEST and not writing to the buffer if the alpha value is less than 0.5, but I just get blackness where there should be transparency.


if (color.a > alphaTest) {
gl_FragData[0].rgba = vec4(color.rgb, specular);
gl_FragData[1].rgba = vec4(normal.xyz, gl_FragCoord.z);
}


Any ideas on how to deal with this?

Thanks

Share this post


Link to post
Share on other sites
Advertisement
Ok I finally found what I was looking for. In order to not write a pixel in a fragment shader you use the discard keyword:



if (color.a > alphaTest) {
gl_FragData[0].rgba = vec4(color.rgb, specular);
gl_FragData[1].rgba = vec4(normal.xyz, gl_FragCoord.z);
} else {
discard;
}


I just didn't know what to search for.

Thanks

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!