Stalker Posted December 28, 2015 Share Posted December 28, 2015 Hi! I'd like to create material with gradient and transparency effect as show on the image bellow (green, yellow and aqua color circles, everything else is irrelevant). After some searching I found gradient material, but it uses BABYLON.Color3 which doesn't support transparency. How can I achieve desired effect? Quote Link to comment Share on other sites More sharing options...
Convergence Posted December 28, 2015 Share Posted December 28, 2015 How about a material with a diffusecolor (or emissivecolor to get the glow effect) in combination with a black-white gradient texture in the opacity texture channel? Wingnut 1 Quote Link to comment Share on other sites More sharing options...
Wingnut Posted December 28, 2015 Share Posted December 28, 2015 I had to give that a try, just because it is such a cool idea. But I have run into SO many problems... because I'm not very smart. First, here is a good black and white gradient image... https://c1.staticflickr.com/1/169/409539495_70d220b646.jpg I temporarily mapped it onto the cylinder's diffuseTexture... http://playground.babylonjs.com/#27HFSC#1 But, it doesn't turn white at the top. Not sure why. Anyway, here we go with the attempt to use it as an opacityTexture, and use a green texture as the diffuseTexture... http://playground.babylonjs.com/#27HFSC#2 Pretty much a complete failure... but in the right hands, I bet this could work. Anyone feel like getting it working for Stalker and I? Thanks! Update: http://playground.babylonjs.com/#27HFSC#3 (getting closer) Update2: http://playground.babylonjs.com/#27HFSC#4 - Got rid of the end caps by using a Jerome tube. It still has a little "rim" showing at the top... not sure how to remove that. Stalker and RaananW 2 Quote Link to comment Share on other sites More sharing options...
Stalker Posted December 28, 2015 Author Share Posted December 28, 2015 @Convergence - I did not find opacity texture channel, it will certainly make thing easier (was searching for transparency and alpha, opacity synonym slipped my mind). @Wingnut - Awesome, like it already . I'm gonna use your code as a starting point. I also enabled backface culling on the material, but I don't know yet about about that top rim. Perhaps unwrapping a model and creating an UV image, but I'm positive there is an easier way. Wingnut 1 Quote Link to comment Share on other sites More sharing options...
Temechon Posted December 28, 2015 Share Posted December 28, 2015 Transparency is incoming. Documentation incoming tomorrow, but you can play with these parameters: topColorAlpha (float between 0 and 1)bottomColorAlpha (float between 0 and 1)smoothness (float between 0 and whatever) Stalker and Wingnut 2 Quote Link to comment Share on other sites More sharing options...
Stvsynrj Posted December 29, 2015 Share Posted December 29, 2015 Hi ! Another way to get something similar is to first create the gradient with alpha like this : Then, set it as a diffuse, emissive and opacity texture. http://www.babylonjs-playground.com/#LCGQ8#2 Hope this help pichou and Wingnut 2 Quote Link to comment Share on other sites More sharing options...
Stalker Posted December 29, 2015 Author Share Posted December 29, 2015 @Temechon, thanks a lot for the update. But I'm experiencing two problems.1. Alpha isn't working (but probably I'm doing something wrong): Code that I used: var material: BABYLON.GradientMaterial; material = new BABYLON.GradientMaterial("selection-material", this.scene); material.topColor = BABYLON.Color3.Red(); material.topColorAlpha = 0; material.bottomColor = BABYLON.Color3.Green(); material.bottomColorAlpha = 1; material.offset = 0; material.backFaceCulling = false; material.smoothness = 50.0; // var tube: BABYLON.Mesh; // tube = BABYLON.Mesh.CreateTube("selection", path, 1, 12, radiusFunc, 0, this.scene, false); var tube = BABYLON.Mesh.CreateCylinder("cy", 100, 1, 1, 12, 1, this.scene); tube.material = material; tube.isPickable = false;2. Don't really know how to explain, so I'll add an image. Colors transition isn't correct, it is only when mesh height is equal or greater than 100. Code is the same as the one above (alphas and smoothness properties were not set). Left is height 100, the right one is 20. @Stvsynrj, thanks! Your solution is quite similiar to the Wingnut's. I'd like to avoid additional images (and top edge) so I'll go with this option as a last resort . Quote Link to comment Share on other sites More sharing options...
Wingnut Posted December 30, 2015 Share Posted December 30, 2015 Hi guys! @stalker... I'm no expert in materials and textures, but I think that when Convergence said "opacity texture channel"... he was talking about the BabylonJS material.opacityTexture. In short, I just built a demo... using Convergence's idea. At least that's what I think I did. His comment caused me to put the gradient image in material.opacityTexture. Ok, sorry to interrupt the discussion of the new Gradient Material. Party on! GameMonetize 1 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.