Jump to content

circle/custom shaped ribbon "2D" with gradient


leechii
 Share

Recommended Posts

Hey guys - haven't found what I needed so far so I hope it's not a duplicate.

I'd like to create a custom shape in "2D" with a gradient.

This playground shows the shape I currently have https://www.babylonjs-playground.com/#E6IX1#122
instead of just having an emissiveColor I wanted to add a gradient.
I so far figured out that if I'd use multiple paths to create a sphere for example and omit the z-coordinate the lights would be applied.
 

What is the way to go if I want to have a gradient?

Link to comment
Share on other sites

Link to comment
Share on other sites

thanks already for your answers, I tried that quickly and it seems that I'm missing something.
https://www.babylonjs-playground.com/#E6IX1#127
as soon as I add the colors to the options, the mash disappears. I hope you can quickly help me again. 

What I figured out so far: If I add a second path and scale that to 0 (like in the example below) and therefore add the double amount of colors it works. 
I guess that's because only like that the vertex outer ring color differs to the inner ring color and therefore a gradient applied (correct me if I'm wrong)

But think I have to further specify what I actually want to achieve: 
I got now how I could do it with the lights applied: https://www.babylonjs-playground.com/#E6IX1#128

but I'd also like to know how I can apply such a gradient without the influence of the light / as if we had an emissiveGradient.

thanks again.

Link to comment
Share on other sites

If you pass a single path in the pathArray, the underlying process cut this path into two half sized paths and build the ribbon with these two paths : https://www.babylonjs-playground.com/#E6IX1#126

The color array must contain exactly the same number of color4 than the ribbon points. I suppose that, in this case, the number of color4 is different than the the number of points.

For no light, just apply a white emissive color and the vertex colors will simply be merged to it : https://www.babylonjs-playground.com/#E6IX1#130

 

Remember also that, if you set the ribbon as DOUBLESIDED, it has then twice more points, so twice more colors to set : https://www.babylonjs-playground.com/#E6IX1#131

Link to comment
Share on other sites

Hm 
I guess I'm more looking for something like that:

https://www.babylonjs-playground.com/#E6IX1#135

but with the API of this: 

https://www.babylonjs-playground.com/#E6IX1#137 
maybe this can be altered so it becomes something like the above (135) - sorry for being a noob - I'll get better soon :D

I guess I'm looking for something like we have in Photoshop for 2D images - different kind of gradients: radial, linear etc.
 

Link to comment
Share on other sites

remember also that the colors are updatable like the mesh geometry : https://www.babylonjs-playground.com/#E6IX1#138

(could be fixed for the last remaining points, but it's only as an example purpose)

can't stop playing : https://www.babylonjs-playground.com/#E6IX1#139

 

[EDIT] the gradient material is nice but works only along the Y axis

Link to comment
Share on other sites

a good to know we can also update the colors :)


 

Quote

the gradient material is nice but works only along the Yaxis:

how could we create one along the X axis? was just trying to figure that out in my mind but with the ribbons and multiple paths (scaled), I'll always only reach radial gradients.
I guess creating the right path might be a solution - instead of just scaling it down I could calc the middle and add the right vertex colors there - but I guess I'm wrong there too since - the color on the outer left part should be more intense and become less intense going to the right. If you have a good approach - I'd be very interested. 

Link to comment
Share on other sites

51 minutes ago, santarcade said:

I didn't know too about update-able vertex color and uvs.
Lovely discovery that should be added in the docs and tutorials maybe.

To achieve something similar, I did write a custom shader! :rolleyes:

Thank you!

do you still have that shader? :}

Link to comment
Share on other sites

Hey @leechii,

here it is a sample I used on a ribbon, creating a linear gradient via UVs: http://www.babylonjs-playground.com/#1YHPOU#7
It can take an input color or sample the passed texture (for that uncomment lines 67 and 68).

Applied to you shape it looks like this: http://www.babylonjs-playground.com/#1YHPOU#9

My goal was to make a fadeout near the head and tail of my shape, probably you will want to adapt the code to blend between two colors.

Best,
santarcade

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