fenomas Posted March 15, 2015 Share Posted March 15, 2015 Hi, two questions: 1. Which is the intended way to correctly render a texture with an alpha channel? The docs say to set "texture.hasAlpha", but this appears to render the texture opaquely while dropping pixels under some threshold. Am I supposed to be setting tex.opacityTexture=tex.diffuseTexture? (opacityTexture doesn't seem to be in any of the tutorials so it's hard to tell..) 2. When I set an opacityTexture on a mesh, it messes up other parts of my scene - for example, sprites get drawn on top of the mesh regardless of position (thusly). Is this avoidable? Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted March 15, 2015 Share Posted March 15, 2015 Hey 1. set your texture to mat.opacityTexture as well. In this case alpha blending is used instead of alpha testing2. The problem with opacity is that they have to be drawn after everything to ensure correct alpha blending. Quote Link to comment Share on other sites More sharing options...
Wingnut Posted March 15, 2015 Share Posted March 15, 2015 Hi. SOME info about Opacity Texture can be found in our "Unleash" document. The lack of mention of Opacity Texture in our basic Materials tutorial has been noted. Coming soon (maybe). Thanks for the tip, Fen. GameMonetize 1 Quote Link to comment Share on other sites More sharing options...
fenomas Posted March 16, 2015 Author Share Posted March 16, 2015 2. The problem with opacity is that they have to be drawn after everything to ensure correct alpha blending. Sure, but in this case they aren't. Are sprites drawn after transparencies? Quote Link to comment Share on other sites More sharing options...
fenomas Posted March 16, 2015 Author Share Posted March 16, 2015 Hmm, another oddity - if a sprite has alpha, it masks out other sprites rather than being composited.Thus: http://www.babylonjs-playground.com/#5RPNC#1 Is the lesson here that sprites occupy their own rendering layer, so if you want something that renders in with the rest of the scene you need to create a bunch of planes and manage your own u/v scales and offsets? Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted March 16, 2015 Share Posted March 16, 2015 For textures with alpha: they are drawn only in color buffer and not in depth buffer to not block blending. So because sprites are rendered after and because there is no depth buffer they cannot take care of their position. This is done by this instruction:https://github.com/BabylonJS/Babylon.js/blob/master/Babylon/Rendering/babylon.renderingGroup.ts#L74which in turn call this one:https://github.com/BabylonJS/Babylon.js/blob/master/Babylon/babylon.engine.ts#L1373 We should perhaps add a parameter to allow depth rendering for alpha objects. For sprites: because they are not designed to get alpha, they are not sorted. So alpha sprites may be rendered first and so block the depth buffer. 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.