Vibrating a guitar string in Blender

Ogg at the art galleryI have a YouTube channel where I make lots of short gag vids about Ogg. He’s a caveman muppet character who’s been thawed out of the ice and is now trying to figure out our modern world.

His performances are shot as live-action puppetry against a green screen, and I use Blender to create many of the backgrounds, props, 2D animation elements, and sometimes even his arms and legs. I’m now working on a script that will need Ogg to play the guitar and sing.

Making a muppet play the guitar is hard to do as a live shot – especially for a one-man production company with a crappy puppeteer – so once again I was developing a way to fake what I needed in Blender. I was happy with the pluck effect I created (shown here), but the production rapidly got too complicated for the joke, so I ended up abandoning the guitar sequence altogether.

Guitar string vibrating

 

Sadly, this means we won’t be seeing Ogg play the guitar any time soon, but since I’d already worked out the pluck effect, I thought I should at least share my technique with other Blender folks, in case anybody else might want to achieve something similar.

This technique works equally well in both Cycles and Evee, and relies entirely on material settings (plus one simple scale transform) to work its magic. No particles. No duplicated geometry. And no motion blur. So it adds almost nothing to the scene complexity and renders fairly quickly.

The idea is driven by a simple PLUCK value, which ranges from 0 when the string is not in motion, to 1.0 when the string is at maximum vibration. So this lets you animate the string as often as you like, at whatever time, and you can completely control both the attack and decay of the string animation – all by simply animating the pluck curve.

To my eye, a vibrating guitar string looks like multiple parallel strings shimmering beside one another within the overall vibration volume. You should be able to see right through that volume (between the phantom strings) and the whole effect should fade away at the edges too.

The pluck value I mentioned is implemented as a value node in the guitar string material, labeled “Pluck 0-1.” To define the overall vibration volume, I first cut and pasted this pluck value as a driver (not shown) to scale the string’s width across the fretboard, which will create the wider space needed for this material effect.

Node tree for the effect, along with a preview of the wave function mask that creates the illusion of multiple strings.

This pluck value feeds into a Multiply/Add node for tweaking, and then into the scale socket on a sinusoidal wave node. This wave will be used to wrap multiple fake cylinder highlights across the surface of the widened string geometry, as a bump map. By doing it this way, the effect still uses whatever color and shininess settings are already in your material. (Although if you’ve also got a bump map on your strings, you’ll have to combine that with the bumps generated here, but I’ll leave that as an exercise for the artist.)

Fading the edge of the volume

Edge fade mask

At the same time, the tricky vector math at the bottom of the node network extracts a mask that highlights the middle of the widened string and fades to black at the edges. (I tried using a simple fresnel node, but this setup works better at oblique camera angles.)

The inverse of the fake cylinder wave node is used to make the string volume transparent between the fake strings, so we can see the fretboard behind it, and then it’s also combined with the edge fade effect and used to soften the edges of the vibrating volume.

Note 1: This edge fade effect might be even more convincing if the mask is inverted so that the fake strings are clearest at the extremes of the volume, where the string would be moving most slowly, and most faded in the middle where they’d be moving at top speed, but I haven’t tested that variation.

Note 2: This implementation vibrates the entire string uniformly, but we all know that it should be stationary at the two ends (the bridge and either the nut or the fret at which the left hand is fingering). I think this could be handled by attenuating the Pluck value down to 0 at the min and max Z length of the string, but I didn’t need that for this video, so I didn’t try it.

The only other little trick in here is that bit where the Pluck value is dumped straight into the phase of the Wave node. This creates the little bit of ‘crawling’ you can see on the multiple strings, which to my eye, sells the whole effect.

Anyway, that’s the method that I found. If you know any other quick-render solutions for creating a vibrating string effect, I’d love to hear about it. And if you want to see more of Ogg’s vids, on subjects ranging from dinner parties, to real estate, to caveman bedtime stories, you can check out the index of over 400 topics he’s covered to date.

Cable Wrangler for the DM6000AR multimeter

About the author

Jefferson Smith is a Canadian fantasy author, as well as the founder, chief editor and resident proctologist of ImmerseOrDie. With a PhD in Computer Science and Creativity Systems compounded by a life spent exploring most art forms for fun and profit, he is underqualified in just about everything. That's why he writes.