i could use some help :)
i'm using a simple shader to animate a heavy metal chain shaking about.
the following is the attached code:

shader_type spatial;

uniform float amp = 0.0;
uniform float sharpness = 0.4;

void vertex() {
	VERTEX.y -= (max(0.0, amp - abs(VERTEX.x) * sharpness));
}

pictured is the result of amp at 0.0 and sharpness at 0.4

pictured here is the result of amp at 4.0 and sharpness at 0.4

i'd like the effect smoothed out, because as it stands, the effect is linear based on the value of VERTEX. you can see how that causes the center link to look pretty jagged, and the effect is a little boring. the chain should also be able to bulge out in the opposite direction as well. with the current math, it doesn't seem to want to do that convincingly at all.

an unrelated request: if you know a good cheap math tutor, hit me up.
another unrelated request: if you want to do this kind of math with me often (possibly paid) you should also hit me up.

  • xyz replied to this.
    packrat changed the title to rattling chain shader assistance .

    packrat Show chain's local coordinate system.

      xyz
      i'm assuming this gimbal says enough.

      • xyz replied to this.

        packrat The mesh itself is rotated by 45 degs? Wouldn't it be easier if the length of the chain was going along one of the major axes?

          • Edited

          packrat

          shader_type spatial;
          uniform float range = 4.0;
          uniform float bulge = 1.0;
          uniform float side_swing = 0.0;
          
          void vertex() {
          	float distFromCenter = length(VERTEX.xy);
          	float xmin = -range;
          	float xmax = range;
          	float xnorm = clamp((distFromCenter - xmin) / (xmax - xmin), 0.0, 1.0);
          	VERTEX -= (xnorm - xnorm * xnorm) * normalize(vec3(-1.0, 1.0, side_swing)) * bulge;
          }

          range needs to be adjusted so that it exactly spans the whole length of the chain.

          Compact version:

          shader_type spatial;
          uniform float range = 4.0;
          uniform float bulge = 1.0;
          uniform float side_swing = 0.0;
          void vertex() {
          	float xnorm = clamp((length(VERTEX.xy) + range) / 2.0 / range, 0.0, 1.0);
          	VERTEX -= (xnorm - xnorm * xnorm) * normalize(vec3(-1.0, 1.0, side_swing)) * bulge;
          }

          xyz yeah..i'll study this when i've slept more. some dude was driving circles around the block with the waaahm waaahm waaaahm waaaahm alarm of their car going off. the freshman this year are brutal.

          thanks :)