How to compute vertex rotation ?

Hi guys,

I’m completely new to shader and was wondering if the following is possible. Let’s say I have a flat mesh which wireframe could looks like a grid. Is it possible to compute/apply a rotation for all vertices based on the angle with the vertice and the middle-bottom point ?

I’m pretty sure I’m using wrong vocabulary here - I attached a sketch which represent what I try to ask :wink: The point would be to simulate the mesh is moving/bending by changing the angle base on time. I’m not looking for a very accurate effect, just trying to figure out if something simple/naive like that could be achieve and how ? Could be an entry point in the shader word for me :slight_smile:

Thanks

3067207--230583--grid.jpeg

In the vertex shader you get the position of each vertex and you can modify it according to any rule you can code. Figure out the math and apply it in the vertex shader.

Hey there,

So you need to know a bit of vector maths for that one. Here are rotation functions for a shader:

inline float3x3 xRotation3dRadians(float rad) {
    float s = sin(rad);
    float c = cos(rad);
    return float3x3(
        1, 0, 0,
        0, c, s,
        0, -s, c);
}

inline float3x3 yRotation3dRadians(float rad) {
    float s = sin(rad);
    float c = cos(rad);
    return float3x3(
        c, 0, -s,
        0, 1, 0,
        s, 0, c);
}

inline float3x3 zRotation3dRadians(float rad) {
    float s = sin(rad);
    float c = cos(rad);
    return float3x3(
        c, s, 0,
        -s, c, 0,
        0, 0, 1);
}

You can use them like that:

// degree is the variable with the degrees you want to rotate your vertex
float3 rotatedVertex = mul(yRotation3dRadians(radians(degree)), v.vertex);

I hope that gives you a starting point :slight_smile:

Thanks a lot guys !