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

Tutorial Effects - Funcion Printing

English | Italian | Mandarin | Japanese

TOC: Of Effects and Shaders
Back: Mr. Wiggle
Next: Vertex Data


Hay variadas posibilidades para alterar la posición de los vértices por medio de funciones matemáticas.

Para los siguientes ejemplos usaremos Grid (EX9.Geometry) como input. Ajusta la resolución cerca de 50x50.

f(x, y) = z

Crear una nueva coordenada z por medio de x e y.
Si usamos el ejemplo the MrWiggle example podemos escribir:

float2 Frequency = 10;
float2 Phase = 0;
float2 Amplitude = 0.01;
 
vs2ps VS(
    float4 PosO  : POSITION,
    float4 TexCd : TEXCOORD0)
{
    //declara la estructura de salida
    vs2ps Out;
 
    //calcula dos ondas
    float2 wave = sin(PosO.xy * Frequency + Phase) * Amplitude;
 
    //ajusta la coordenada z
    PosO.z = wave.x + wave.y;
 
    //transforma la posición
    Out.Pos = mul(PosO, tWVP);
 
    //transforma las coordenadas de textura
    Out.TexCd = mul(TexCd, tTex);
 
    return Out;
}

El patch así :

function patch

f(u, v) = xyz

Otro modo común es calcular una posición completamente nueva a partir de las coordenadas xy de la grilla. Suele llamarse superficie paramétrica aquella cuyos parámetros de entrada xy son llamados uv.

Por ejemplo un cono:

x = v*cos(u)
y = v*sin(u)
z = v

puede ser escrito como función:

float3 Cone(float2 uv)
{
    float u = uv.x;
    float v = uv.y;
 
    float3 newPos;
    newPos.x = v * cos(u);
    newPos.y = v * sin(u);
    newPos.z = v;
 
    return newPos;
}

Podría ser útil escalar u por dos Pi para obtener un ciclo completo en el rango 0 .. 1, así como tener un desplazamiento general y de escala para los parámetros de entrada.. El vertex shader quedaría algo así:

#define twopi 6.28318531
 
float2 Scale = 1;
float2 Offset = 0;
 
float3 Cone(float2 uv)
{
 
     uv *= Scale;
     uv += Offset;
 
    float u = uv.x * twopi;
    float v = uv.y;
 
    float3 newPos;
    newPos.x = v * cos(u);
    newPos.y = v * sin(u);
    newPos.z = v;
 
    return newPos;
}
 
vs2ps VS(
    float4 PosO  : POSITION,
    float4 TexCd : TEXCOORD0)
{
    //declara la estructura de salida
    vs2ps Out;
 
    //ajusta la nueva posición
    PosO.xyz = Cone(PosO.xy);
 
    //transforma la posición
    Out.Pos = mul(PosO, tWVP);
 
    //transforma las coordenadas de textura
    Out.TexCd = mul(TexCd, tTex);
 
    return Out;
}

Y el patch:

cone patch

Next: Vertex Data
Back: Mr. Wiggle
TOC: Of Effects and Shaders

anonymous user login

Shoutbox

~13h ago

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

~14h ago

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

~3d ago

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

~6d 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/

~7d ago

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

~13d ago

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

~13d ago

domj: If you happen to be in Prague, come join us at the Schema workshop on Thursday 25.4. :) https://www.facebook.com/events/395516526614988/?ti=ls

~25d ago

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