Jump to content

Transparent Gradient Material


Stalker
 Share

Recommended Posts

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.

Link to comment
Share on other sites

@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. 

Link to comment
Share on other sites

@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.

 

post-17157-0-09552100-1451433256.png

 

@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 :).

Link to comment
Share on other sites

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.  :D

 

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!

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.

Guest
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.

Loading...
 Share

  • Recently Browsing   0 members

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