user3162134
user3162134

Reputation: 307

Composite a texture with alpha blended components

Todo :

What we need is for the texture to have full red (1,0,0) colour and alpha of 0.5, but this then gets much more complicated when we render multiple alpha blended polygons over each other.

Is there a way to achieve this ?
Maybe with a different screen blend mode ?
This needs to be done with the GPU whilst rendering to a texture.

Using OpenGLES 2.0.

Please suggest.
Thanks

Shaun

Upvotes: 2

Views: 130

Answers (1)

user3162134
user3162134

Reputation: 307

Our artist found this answer. While it may not be identical, it's very good.

Opengl Render To Texture With Partial Transparancy (Translucency) And Then Rendering That To The Screen

WE basically used option 2, render everything to the texture as normal, starting with a black clear texture, but when rendering this texture to the hud, modify the pixel shader to simply divide the colour by the alpha.

This works because say a colour (1, 0.5, 0.2) had been added to the texture at 25% alpha, then the texture colour would be (0.25, 0.125, 0.05) and 0.25 alpha. Dividing back by the 0.25 alpha gives the colour back (1, 0.5, 0.2) which is what we need.

So, only when using the created texture, add this line onto the end of your pixel shader

outcol.rgb /= outcol.a

We tested with multiple transparencies overlaid and could not tell the difference. The more opaque the colour is, the less of the original "black with zero alpha" is in it. It requires no changes to your rendering pipeline, except for when you actually use the created texture.

Shaun

Upvotes: 1

Related Questions