platane Posted May 9, 2014 Share Posted May 9, 2014 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. 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. Thanks UPDATE : modifications merged here https://github.com/BabylonJS/Babylon.js/pull/194 thanks! Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted May 9, 2014 Share Posted May 9, 2014 The way I can tell you is to use the opacity texture with the same file (in this case there is no overhead) Quote Link to comment Share on other sites More sharing options...
platane Posted May 9, 2014 Author Share Posted May 9, 2014 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;#endifAs 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 ! Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted May 9, 2014 Share Posted May 9, 2014 Oh yes you are absolutely right: I idid that to support both alpha and black and white opacity maps Crap! Sorry about that Quote Link to comment Share on other sites More sharing options...
platane Posted May 12, 2014 Author Share Posted May 12, 2014 Ok, 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 Thanks Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted May 12, 2014 Share Posted May 12, 2014 If we can have it without losing performance it is perfect Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.