c++ - Rendering 3D Models With Textures That Have Alpha In OpenGL -
so im trying figure out best way render 3d model in opengl when of textures applied have alpha channels.
when have depth buffer enabled, , start drawing triangles in 3d model, if draws triangle in front of triangle in model, not render triangle when gets it. problem when front triangle has alpha transparency, , should able seen through triangle behind it, triangle behind still not rendered.
disabling depth buffer eliminates problem, creates obvious issue if triangle opaque, still render triangles behind on top if rendered after.
for example, trying render pine tree cones stacked on top of each other have transparent base. following picture shows problem arises when depth buffer enabled:
you can see how can still see outline of transparent triangles.
the next picture shows looks when depth buffer disabled.
here can see how of triangles on of tree being rendered in front of rest of tree.
any ideas how address issue, , render pine tree properly?
p.s. using shaders render everything.
if you're not using partial transparency (everything either 0 or 255), can glenable(gl_alpha_test) , should you. problem if render top cone first, deposits whole quad z-buffer (even transparent parts), lower branches underneath z-rejected when time drawn. enabling alpha testing doesn't write pixels z buffer if fail alpha test (set glalphafunc).
if want use partial transparency, you'll need sort order of rendering objects front, or bottom top in case.
you'll need leave z-buffer enabled well.
[edit] whoops realized functions don't believe work when you're using shaders. in shader case want use discard function in fragment shader if alpha value close zero.
if(color.a < 0.01) { discard; } else { outcolor = color; }
Comments
Post a Comment