1 | /**********************************************************************
|
---|
2 | *<
|
---|
3 | FILE: texutil.h
|
---|
4 |
|
---|
5 | DESCRIPTION:
|
---|
6 |
|
---|
7 | CREATED BY: Dan Silva
|
---|
8 |
|
---|
9 | HISTORY:
|
---|
10 |
|
---|
11 | *> Copyright (c) 1994, All Rights Reserved.
|
---|
12 | **********************************************************************/
|
---|
13 |
|
---|
14 |
|
---|
15 | #ifndef __TEXUTIL__H
|
---|
16 |
|
---|
17 | #define __TEXUTIL__H
|
---|
18 |
|
---|
19 | //
|
---|
20 | // Misc. noise functions from Texturing and Modeling A Procedural Approach
|
---|
21 | // Perlin, Musgrave...
|
---|
22 | //
|
---|
23 |
|
---|
24 | CoreExport float bias(float a, float b);
|
---|
25 | CoreExport float gain(float a, float b);
|
---|
26 | CoreExport float clamp(float x, float a, float b);
|
---|
27 |
|
---|
28 | CoreExport float boxstep(float a, float b, float x); // linear from (a,0) to (b,1)
|
---|
29 | CoreExport float smoothstep(float a, float b, float x); // Hermite cubic from (a,0) to (b,1)
|
---|
30 | CoreExport float mod(float x, float m); // returns x Mod m, handles negatives correctly
|
---|
31 | CoreExport int mod(int x, int m); // returns x Mod m, handles negatives correctly
|
---|
32 |
|
---|
33 | // This function makes a sort of straight segment S curve.
|
---|
34 | // sramp() is a for x < a-d and b for x > b+d.
|
---|
35 | // for a+d < x < b-d sramp(x) = x
|
---|
36 | // for a-d < x < a+d sramp makes a smooth transition (parabolic) from
|
---|
37 | // sramp' = 0 to sramp' = 1
|
---|
38 | // for b-d < x < b+d sramp makes a smooth transition (parabolic) from
|
---|
39 | // sramp' = 1 to sramp' = 0
|
---|
40 | CoreExport float sramp(float x,float a, float b, float d);
|
---|
41 |
|
---|
42 | // returns 0 if x<a, 1 if x>b otherwise x.
|
---|
43 | CoreExport float threshold(float x,float a, float b);
|
---|
44 |
|
---|
45 | CoreExport void setdebug(int i);
|
---|
46 | CoreExport float noise1(float arg);
|
---|
47 | CoreExport float noise2(Point2 p);
|
---|
48 | CoreExport float noise3(Point3 p);
|
---|
49 | CoreExport float noise4(Point3 p,float time);
|
---|
50 |
|
---|
51 | // This is 3DStudio's Noise function: its only slightly different from noise3:
|
---|
52 | // scaled up by factor of 1.65 and clamped to -1,+1.
|
---|
53 | CoreExport float noise3DS(Point3 p);
|
---|
54 |
|
---|
55 | CoreExport float turbulence(Point3& p, float freq);
|
---|
56 |
|
---|
57 | CoreExport int Perm(int v);
|
---|
58 |
|
---|
59 | #define MAX_OCTAVES 50
|
---|
60 | CoreExport float fBm1(float point, float H, float lacunarity, float octaves);
|
---|
61 | CoreExport float fBm1(Point2 point, float H, float lacunarity, float octaves);
|
---|
62 | CoreExport float fBm1(Point3 point, float H, float lacunarity, float octaves);
|
---|
63 |
|
---|
64 | CoreExport float spline(float x, int nknots, float *knot);
|
---|
65 |
|
---|
66 | CoreExport Color color_spline(float x, int nknots, Color *knot);
|
---|
67 |
|
---|
68 |
|
---|
69 | // faster version of floor
|
---|
70 | inline int FLOOR( float x) { return ((int)(x)-((x)<0.0f)); }
|
---|
71 |
|
---|
72 | inline float frac(float x) { return x - (float)FLOOR(x); }
|
---|
73 | inline float fmax(float x, float y) { return x>y?x:y; }
|
---|
74 | inline float fmin(float x, float y) { return x<y?x:y; }
|
---|
75 |
|
---|
76 | // Macro to map it into interval [0,1]
|
---|
77 | #define NOISE(p) ((1.0f+noise3DS(p))*.5f)
|
---|
78 |
|
---|
79 | // alpha-composite ctop on top of cbot, assuming pre-multiplied alpha
|
---|
80 | inline AColor AComp(AColor cbot, AColor ctop) {
|
---|
81 | float ia = 1.0f - ctop.a;
|
---|
82 | return (ctop + ia*cbot);
|
---|
83 | }
|
---|
84 |
|
---|
85 | #endif
|
---|