Home Technical Talk

How to make a circular gradient for an arbitrary shape

polycounter lvl 6
Offline / Send Message
OverTheMoon polycounter lvl 6

Hi there! I'm trying to make a technical mask of sorts that requires precision and I'm genuinely not sure how to make it, at least not without a fair bit of pain. Observe this image:

What I want is to create a circular gradient, but instead of a circle, I want it to apply to an arbitrary shape. Imagine that we assume some kind of middle point, which is that yellow line, and then given that middle point, the gradient spreads to the edge in all cases, evenly and precisely. Is there a simple way of doing this?

The only way I can think of to do this is to create a strip of polygons with a gradient on it, and wrap it around in the shape of a ring, and pull points until I get exactly what I want, and then render THAT to texture. This will work, it just sucks, because I want this to be on a complex 3d model, which means I'll have to draw the shape, see that it works, apply it to a plane, trace over it with geo, render to texture, and…

…well okay maybe it's not THAT big a deal but if an easier way exists that'd be really lovely…

Replies

  • pior
    Options
    Offline / Send Message
    pior grand marshal polycounter

    Vertex color (either in a 3D software, or the equivalent as 2D vector) is pretty much exactly what you describe - by assigning pure white to the verts around the border, and pure black to the verts of the middle line :

  • supaclueless
    Options
    Offline / Send Message
    supaclueless polycounter lvl 12
    If you are able to use UV mapped textures, you could also try SDF's generated in Substance Designer (if you have that as well).
    I think you would get best results if you set Distance Node to "Manhatten Distance". It's not 100% perfect but this is extremely fast for iteration since the process is completely automated and you just adjust your distance spread.


  • Eric Chadwick
    Options
    Offline / Send Message
    fwiw Photoshop can do that kind of effect too, via the Inner Glow layer style.
  • OverTheMoon
    Options
    Offline / Send Message
    OverTheMoon polycounter lvl 6
    You guys are the best!

    pior - Thanks very much for the idea and for taking the time! That's kinda what I had in mind when I mentioned geometry, more or less. I'd rather not pursue that method because it's a bit labor intensive if I want this effect to be on a character, let's say, which has complex geo that I don't want to alter. SOOOO I'd have to make some arbitrary geo and then bake it to texture, blah blah blah.

    supaclueless - HEY that's a good idea! Thanks for the setup example that's really awesome.  That's pretty good but I think I need the center to be a much smaller shape or line that I can control. 

    Eric - thank you, that's another good idea, but same problem as above, I think.

    Honestly all things considered I think I might be forced to do something like what pior recommends .

    Oh by the way, if ya'll are curious, I'm using this as an alpha cuttof mask to do a ripping effect as a material stretches. it works great!
  • Alex_J
    Options
    Offline / Send Message
    Alex_J grand marshal polycounter
    This might be a dumb question but, is applying vertex colors and then baking that out as a mask not more work than just hand painting a mask in photoshop / texturing app?

    Seems like just hand paint and then spend five minutes with blur brush would give all the precision?
  • killnpc
    Options
    Offline / Send Message
    killnpc polycounter
    I think the prep work is reasonably lateral. The vert color technique would allow much more freedom, more irregularities. The other approaches will generate a uniform thickness.
    I would anticipate impurities from hand painted strokes to become more noticeable when clamping values, especially with something ornate in mind.
  • Eric Chadwick
    Options
    Offline / Send Message
    Shapeburst gradient is probably what you're looing for.

    https://plugins.qgis.org/planet/tag/gradient/
    And it looks like QGIS is free.
  • pior
    Options
    Offline / Send Message
    pior grand marshal polycounter
    BTW, even though many solutions have been proposed ... It's still not too late to show a practical example of what you are *actually* trying to do with this mask. Also we don't know if you are limited to a texture only, if you have access to edit the geo, and so on.
    This actually sounds a lot like one of the many tricks to add shading/depth to a realtime eyeball ...
  • Eric Chadwick
    Options
    Offline / Send Message
    They did say
    Oh by the way, if ya'll are curious, I'm using this as an alpha cuttof mask to do a ripping effect as a material stretches. it works great!

  • pior
    Options
    Offline / Send Message
    pior grand marshal polycounter
    Yeah, but that still only half of the story, there could be all kinds of limitations/unexpected cases still ... And furthermore, the fact that fabric has directionality and doesn't rip in random directions could also affect whether or not the effect looks convincing. And so on ...
  • OverTheMoon
    Options
    Offline / Send Message
    OverTheMoon polycounter lvl 6
    Hey hey! I think Eric might have nailed it. Never heard of Shapeburst Gradient. Thanks Eric! that's awesome... I'll give it a try. alltthouugghhh those branches might fight the effect.

    Yeah of course, I probably should have just posted an example of what I'm playing with. Here's an example of a rip effect I'm playing with, and the texture channels I'm using to animate it. Mostly I'd be looking for oval-like shapes... it probably wouldn't be deviating much... but of course when painted on a texture sheet, it won't be exactly an oval.





    First of all, I use the red channel but animate the cutoff. Then, I use the green channel to animate the break, then use the last two channels as frames for a quick bounce for the torn edge.

    Oh, almost forgot. Alex_J - it's a reasonable idea but I'm worried that I might need really precise gradients to make the rips feel natural - although I haven't done a ton of testing here. as killnpc said, I expect the artifacts from manual painting would cause weirdness.
  • Eric Chadwick
    Options
    Offline / Send Message
    What kind of fabric is it? Looks a bit like spandex or rubber in your test. If it more like cotton it might look great to overlay a weave pattern on the burst.

    I’d probably try the QGIS thing but ultimately go Pior’s route. Then just Gaussian blur it a bit.

  • poopipe
    Options
    Offline / Send Message
    poopipe grand marshal polycounter
    Something to consider with @supaclueless and @Eric Chadwick approaches are that you get a constant 'speed' towards the outer edge. 
    I've stepped through a similar distance field here as an example of how it might look when animated 



    Pior's approach will give you a constant 'time' to reach the edge (ie. speed will vary with distance) -  that could look more natural in terms of opening up a gap/tear as the centre line will split along it's full length at the beginning


    getting a normalised distance to the median line of a shape is basically impossible with a bitmap so making a mesh and vert coloring it is probably the simplest solution
  • OverTheMoon
    Options
    Offline / Send Message
    OverTheMoon polycounter lvl 6
    Hey! sorry for the delay.

    Eric - Skin, believe it or not. Cartoony skin though. Realism doesn't matter so much here.

    Great point, Poopipe. There's a statement I never thought I'd say. 

    I've been on other things while this marinates, but if I discover anything while implementing this finally I'll update...
Sign In or Register to comment.