» 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

~8d ago

joreg: Postponed: Next vvvv beginner course starting April 29: https://thenodeinstitute.org/courses/vvvv-beginner-class-summer-2024/

~1mth ago

~1mth ago

joreg: The Winter Season of vvvv workshops is now over but all recordings are still available for purchase: https://thenodeinstitute.org/ws23-vvvv-intermediates/

~1mth ago

schlonzo: Love the new drag and drop functionality for links in latest previews!

~2mth ago

joreg: Workshop on 29 02: Create Sequencers and Precise Clock Based Tools. Signup here: https://thenodeinstitute.org/courses/ws23-vvvv-08-create-sequencers-and-precise-clock-based-tools-in-vvvv-gamma/

~2mth ago

joreg: Workshop on 22 02: Unlocking Shader Artistry: A Journey through ‘The Book of Shaders’ with FUSE. Signup here: https://thenodeinstitute.org/courses/ws23-vvvv-12-book-of-shaders/