Jump to content

  • Log In with Google      Sign In   
  • Create Account

Sprite with alpha Blending in 3D world


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
5 replies to this topic

#1 Papi93   Members   -  Reputation: 107

Like
0Likes
Like

Posted 14 August 2013 - 07:07 AM

Hi,
 

I'm working on a game in a 3D world with elements 2D only (Like Don't starve game) for Android and IOS.

Currently, I've managed "Sprite" without alpha blending, I've just put a condition in the pixel shader to test if pixel alpha channel is null:
 

if ( texture.a < 0.5 ) discard;

Everything working here. (On old devices like an HTC desire mobile, this condition "destroy" framerate but it's another problem :/)
But recently, I've tried to had another Sprite with AlphaBlending activated (The character in the video):

glCheck( glEnable(GL_BLEND) );
glCheck( glBlendFunc( GL_ONE, GL_ONE_MINUS_SRC_ALPHA ) );
glCheck( glDisable(GL_DEPTH_TEST) );

My sprite transparency is ok but it is now in front of everything in the scene. (Probably due to glDisable(GL_DEPTH_TEST)).

How can I handle depth with alpha blending activated?

Here is a video to show the problem:
 

T
hanks for your time!



Sponsor:

#2 FLeBlanc   Crossbones+   -  Reputation: 3117

Like
0Likes
Like

Posted 14 August 2013 - 08:28 AM

Alpha-blended objects should be sorted back-to-front and then rendered in order after any solid geometry that doesn't use alpha blending. 



#3 cozzie   Members   -  Reputation: 1762

Like
0Likes
Like

Posted 14 August 2013 - 11:04 AM

You have to do this yourself, where my advice would be to do this based on distance of the viewer, using a scaled radius per "object" (in this case sprite)

#4 Papi93   Members   -  Reputation: 107

Like
0Likes
Like

Posted 15 August 2013 - 03:49 PM

Thanks, I've tried to draw from back to front and it's better!

But I have another question now: If I use static batching I've got one draw call to draw all my scene and one draw call to draw the character, how can I handle alpha blending? 



#5 FLeBlanc   Crossbones+   -  Reputation: 3117

Like
0Likes
Like

Posted 15 August 2013 - 04:02 PM

Well, if your scene involves alpha-blending then you can't really do it like that, since all alpha-blended objects need to be drawn back to front. If the scene is solid geometry with no alpha blending, then you can batch it and draw, then draw the character using blending afterward.



#6 powly k   Members   -  Reputation: 653

Like
0Likes
Like

Posted 16 August 2013 - 01:14 PM

Just do more draw calls then, that really is the simplest and very probably most efficient solution. Keep all the fully opaque stuff in one batch, though. You could reorder your objects otherwise (read their coordinates and texture atlas IDs from an attribute buffer or a lookup texture or something). There are tricks to do actual order independent transparency too, but they need relatively new hardware and/or are very computationally demanding.






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS