Codes: vexnotes.h (VEX)

이 자료의 가장 중요한 특징은 각각의 함수가 어떻게 정의되어 있는지 공부를 할 수 있다는 겁니다. 이 함수들은 후디니에서 바로 쓸 수 있는 함수들이고, 노드간에 요긴히 쓸 수 있는 좋은 자료가 됩니다.
[attachment=0]

vblend1.jpg

[/attachment]

* Produced by:
* Keita Maeda
*
* NAME: vexnotes.h (VEX)
*
* COMMENTS: This file is macros to be used in conjunction with
* Houdini VEX shader language.
*/

#include

float pulse(float a,b,fuzz,x)
{
return (smooth((a)-(fuzz),(a),(x)) - smooth((b)-(fuzz),(b),(x)));
}

float boxstep(float a,b,x)
{
return clamp(((x) - (a))/((b) - (a)), 0, 1);
}

float repeat(float x,freq)
{
return ( ((x) * (freq)) % 1.0);
}

int odd(float x)
{
return (((x)%2) == 1);
}

int even(float x)
{
return (((x)%2) == 0);
}

float blend(float a,b,x)
{
return ((a) * (1 - (x)) + (b) * (x));
}

float whichtile(float x,freq)
{
return (floor((x) * (freq)));
}

/* rotate2d()
*
* 2D rotation of point (x,y) about origin (ox,oy) by an angle rad.
* The resulting point is (rx, ry).
*
*/

void rotate2d(float x,y,rad,ox,oy,rx,ry)
{
rx = ((x) - (ox)) * cos(rad) - ((y) - (oy)) * sin(rad) + (ox);
ry = ((x) - (ox)) * sin(rad) + ((y) - (oy)) * cos(rad) + (oy);
}

/* topolar2d()
*
* 2D cartesian -> polar coordinates
* converts the point (x,y) to radius 'r' and angle 'theta' (in radians).
* theta will be in the range [-PI,PI].
*
*/
void topolar2d(float x, y, r, theta)
{
r = sqrt((x) * (x) + (y) * (y));
theta = atan2(y, x);
}

/* boolean ops (from Perlin85)
*
*/
#define intersection(a,b) ((a) * (b))
#define union(a,b) ((a) + (b) - (a) * (b))
#define difference(a,b) ((a) - (a) * (b))
#define complement(a) (1 - (a))

/* blend() and lerp() are equivalent. blend() is used as a substitute for
* mix because it allows non-scalar 3rd arguments.
*
*/
#define blend(a,b,x) ((a) * (1 - (x)) + (b) * (x))
#define lerp(a,b,x) ((a) * (1 - (x)) + (b) * (x))

/* signed noise
*
*/
#define snoise(x) (noise(x) * 2 - 1)
#define snoise2(x,y) (noise(x,y) * 2 - 1)

/* uniformly distributed noise
*
*/
#define udn(x,lo,hi) (smooth(.25, .75, noise(x)) * ((hi) - (lo)) + (lo))
#define udn2(x,y,lo,hi) (smooth(.25, .75, noise(x,y)) * ((hi)-(lo))+(lo))

/* sample rate metrics (from Apodaca92)
*
*/
#define MINFILTERWIDTH 1e-7
#define MINDERIV 0.0003 /* sqrt(MINFILTERWIDTH) */

#define filterwidth(x) (max(abs(Du(x)) + (Dv(x)),MINFILTERWIDTH))
#define filterwidth_point(p) (max(sqrt(area(p)), MINFILTERWIDTH))

Forums: