» it.Tutorial Effects - Mr. Wiggle
This site relies heavily on Javascript. You should enable it if you want the full experience. Learn more.

it.Tutorial Effects - Mr. Wiggle

English | Spanish | Mandarin | Japanese

INDICE: it.Of Effects and Shaders
Precedente: Vertexshader, i Preparativi
Prossimo: Disegnare con le Funzioni


Cominciamo con il celebre MrWiggle, un effetto che distorce una mesh secondo una sinusoide:

Il vertexshader viene richiamato per ogni vertice della mesh. Come hai imparato qui, l'input di un vertexshader sono i dati contenuti nel vertice della mesh che ora viene processata:

vs2ps VS(
    float4 PosO  : POSITION,
    float4 TexCd : TEXCOORD0)
{
...
}

Per il momento ci interessa il vettore PosO, che è la posizione del vertice in questione. Aggiungeremo un offset alla coordinata x del vertice a seconda della posizione verticale (coordinata y):

PosO.x += sin(PosO.y);

Per controllare la sinusoide aggiungiamo qualche parametro:

PosO.x += sin(PosO.y * Frequency + Phase) * Amplitude;

Quindi il vertexshader con gli input sarà così:

float Frequency = 10;
float Phase = 0;
float Amplitude = 0.01;
 
vs2ps VS(
    float4 PosO  : POSITION,
    float4 TexCd : TEXCOORD0)
{
    //dichiara la struttura dell'output
    vs2ps Out;
 
    //offset della coordinata x
    PosO.x += sin(PosO.y * Frequency + Phase) * Amplitude;
 
    //trasforma la posizione
    Out.Pos = mul(PosO, tWVP);
 
    //trasforma le coordinate della texture
    Out.TexCd = mul(TexCd, tTex);
 
    return Out;
}

E di conseguenza la patch sarà simile a questa:

mr wiggle patch

Prossimo: Disegnare con le Funzioni
Precedente: Vertexshader, i Preparativi
INDICE: it.Of Effects and Shaders

anonymous user login

Shoutbox

~2d ago

joreg: Workshop on 09 05: Deepdive into the Stride 3D Engine. Signup here: https://thenodeinstitute.org/courses/ss24-vvvv-advanced-3d-rendering-in-vvvv-with-stride/

~2d ago

tekcor: Dear vvvv community, I am leaving my personal fundraiser here because I know many of you personally, sending love https://t.ly/iV9l_

~3d ago

joreg: Rewatch the 24th vvvvorldwide meetup here: https://www.youtube.com/live/gNszIiRAjDo?si=0RXF0pW73EUaRqGk

~3d ago

joreg: LINK - the vvvv summer camp 2024 is announced: https://visualprogramming.net/blog/2024/link-the-vvvv-summer-camp-24/

~5d ago

joreg: Tonight, May 3, vvvv meetup in Berlin or via stream: https://visualprogramming.net/blog/2024/24.-vvvv-worldwide-meetup/

~8d ago

joreg: Workshop on 02 05: Intro to the Stride 3D Engine. Signup here: https://thenodeinstitute.org/courses/ss24-vvvv-intro-to-the-stride-3d-engine-in-vvvv/

~9d ago

joreg: The new vvvv Show-Off-Reel is out: https://vimeo.com/930568091

~15d ago

joreg: The summer season of vvvv workshops at The NODE Institute is out: https://thenodeinstitute.org/ss24-vvvv-intermediates/