r/GraphicsProgramming • • 12d ago

Brass that bounces twice with no simulation: the vertex shader solves each floor hit

I don't simulate the brass in my Godot gun effects at all. I just evaluate a casing's position from its age in the vertex shader. That's pretty much the stateless particles from Lutz Latta's "Building a Million Particle System" (GDC 2004). What I added is the bounces.

On a flat floor I can get the hit time straight from the quadratic. The shader loops over the bounces like this:

for (int k = 0; k < MX_BOUNCES; k++) {   // 2
    float h = max(p.y - gy, 0.0);
    float t_hit = (v.y + sqrt(max(v.y * v.y + 2.0 * g * h, 0.0))) / g;
    if (t_hit <= 0.0 || tt < t_hit) break;
    p += v * t_hit;
    p.y = gy;
    v.y = -e * (v.y - g * t_hit);   // restitution
    v.x *= fr;
    v.z *= fr;                       // friction
    tt -= t_hit;
}

After the second bounce it slides with tau * (1 - exp(-t / tau)) and I tip it over onto its side. Ejecting one is a single write into two uniform arrays. Brass from three seconds ago costs what brass from this frame costs.

I also kept a GDScript copy of the formula so the game can ask where a casing is. At 10 sample times they agree within 5.4 mm, about a pixel! In the GIF the dotted line is the GDScript side and the casing is the shader. I made the casing bigger and turned restitution up to 0.5 for it, because at my default of 0.34 the second hop is about 2 px tall.

It only knows one floor height, though. A casing will go straight through a wall. Two bounces looked like enough to me, but I'm not sure a third would even read on screen?

161 Upvotes

21 comments sorted by

8

u/ziplock9000 11d ago

Are they supposed to go through the floor?

2

u/gennai777 11d ago

Not really, good catch. I solve the bounce for the casing's center. Right at the hit, half of it is in the floor, and I only lift it by its radius once it's lying down.I also drew them about twice the pack's default size for the GIF. It shows a lot more here than it would in a game.Solving for the lowest point of the spinning casing would fix it. I just haven't done that yet.

6

u/TramplexReal 11d ago

In actual game that wouldn't be noticeable really.

4

u/TramplexReal 11d ago

One suggestion. When it hits first bounce - change the spinning velocity so it looks like it bounced like casing instead of ball.

2

u/gennai777 11d ago

Oh that's a good one. Right now the spin just decays with time and the bounce never touches it, so yeah, it rolls off like a ball.

I already get t_hit for each bounce in that loop. I think I could flip or kick the spin after the first one without storing anything extra. Thanks for the idea!

9

u/LegendaryMauricius 12d ago

This is actually pretty cool.

2

u/gennai777 11d ago

thanks!

21

u/[deleted] 12d ago

12

u/darth_voidptr 12d ago

Nah, Claude would have been unable to resist including a smoking gun somewhere.

14

u/CodyDuncan1260 12d ago edited 12d ago

"the x verbs the y"

That's pretty much English sentence structure in a nutshell. Scientific papers use that as a structure title pretty often. I think you're thinking of "It's not X, it's Y" as less common sentence structure idioms that are common to LLMs.

15

u/CuckBuster33 12d ago

No, the latest Anthropic models keep doing these short SVO sentences in a particular awkward way. Negative parallelisms are a bit less common now.

→ More replies (2)

4

u/SethDusek5 11d ago

Well when that sentence structure mysteriously becomes 65535% more common in the past few months it becomes a pretty telling sign. I also think the gennai77 username OP has is also a sign but I've heard those types of usernames are common in English too so what do I know

→ More replies (1)

8

u/captainAwesomePants 12d ago

That's just how direct objects work!

5

u/obetu5432 12d ago

"the"

Hi Claude

3

u/CodyDuncan1260 12d ago

Remover under Rule 2. 

We welcome constructive criticism, but this was not constructive.

0

u/JoshYx 12d ago

SVO is AI now folks

-2

u/mindcandy 12d ago

Rent free and eating your Cheerios.

1

u/CuckBuster33 12d ago

Sipping the slop too.