Scaling model with vertex shader - for non-uniform scaling animation

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Santiago
:warning: Old Version Published before Godot 3 was released.

Hi everyone!

I’m trying to achieve non-uniform scaling via vertex shader, I need this for squash and stretching for my characters, and currently, simply animating bones or the spatial itself gives errors or is not supported at all in the import process.

So I’ve been playing with ne graph shader and got this to work pretty much as I want it graph shader setup

The thing is that I want to use the curved world effect shader by user 1000h in the godot developers forum, this is the thread in question: this is the thread in question

… but I haven’t been able to put those effects together, because I can’t replicate the vertex shader scaling in code (that xform multiply with vector and matrix is the part I can’t replicate in code), and I can’t do the curved world effect in the graph shader, and I want to use both effects on some of my models.

Basically I want the game level and characters in it to have the curved effect, but for now I’m unable to do it.

So, if anyone have any idea on how can I do this I would really appreciate it.

Thank you in advance!!
And sorry for my english :smiley:

:bust_in_silhouette: Reply From: mollusca

Scaling in the vertex shader:

uniform vec3 scale = vec3(1.0);
VERTEX = MODELVIEW_MATRIX * (SRC_VERTEX * scale);

OMG! Thank you very much!!!
I’v never thought of that. I was looking through the docs to find something but completely oversaw that SRC_VERTEX.

Thank you again!!! :smiley:
You are a hero!!!

Santiago | 2017-05-31 10:55

This answer is no longer working or valid for newer version of Godot. Posting with Version 3.4.4.

sjharb | 2022-04-12 13:41

:bust_in_silhouette: Reply From: sjharb

Scale

uniform vec2 scale_vertex = vec2(2.0, 2.0); // x and y scale

void vertex() {
    VERTEX *= scale_vertex;
}

Scale over time

uniform vec2 play_grow_scale = vec2(2.0, 2.0);
uniform float play_grow_speed = 1.5;
void vertex() {
    VERTEX *= play_grow_scale * sin(TIME * play_grow_speed);
}