Jump to content

alpha channel on a texture


Recommended Posts

Hi there,


I have a question related to how the alpha is computed in default shader which use a texture.


What I am trying to achieve here is to display the length of an object in a dynamic texture.


if4e90.jpg   x2nuib.jpg

 without transparent background                   with transparent background 



The shader algorithms only render pixels as opaque or full transparent ( discarded with alpha test ) which create this aliased aspect.


In order to make everything looks smoother, I want to have pixel that have an alpha channel between 0 and 1. I understand that it's more expensive in term of performance.


I found two ways to enable pixel blending:

  * I can apply a global alpha to the whole material but that's not what I want

  * I can use an opacity texture. It works but I think it's a bit overkill.


Indeed as the alpha information are already in the diffuse texture, the information in the opacity texture are redundant in that case.


I am ok with this solution, but is there currently a better way to achieve this? I guess we could use a flag to trigger a special behavior of the shader, but it may not worth it if this usecase is no so common.








modifications merged here  https://github.com/BabylonJS/Babylon.js/pull/194



Link to comment
Share on other sites

Well if I am not mistaken, In this case, it will not produce the desired effect as the alpha computed with the opacity texture is a composition of the texture pixel 's luminosity ( based on rvb values ) and it's actual alpha.

#ifdef OPACITY	vec4 opacityMap = texture2D(opacitySampler, vOpacityUV);	opacityMap.rgb = opacityMap.rgb * vec3(0.3, 0.59, 0.11) * opacityMap.a;	alpha *= (opacityMap.x + opacityMap.y + opacityMap.z)* vOpacityInfos.y;#endif

As the non transparent pixels are black, the value is zero even if the alpha channel is 1.


Once again, it's fine by me to use two separate textures for this effect, but I think this case could be treated in a simpler way, and it may be a feature worth to discuss about.


thanks !

Link to comment
Share on other sites



So do you think It is worthy to add another behavior ?


A flag could trigger a behavior where the diffuse texture's alpha channel is implied in the alpha computation of the pixel.


If you think it could be usefull, I'll made a pull request



Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...