texutil.h

Go to the documentation of this file.
00001 /**********************************************************************
00002  *<
00003     FILE: texutil.h
00004 
00005     DESCRIPTION:
00006 
00007     CREATED BY: Dan Silva
00008 
00009     HISTORY:
00010 
00011  *> Copyright (c) 1994, All Rights Reserved.
00012  **********************************************************************/
00013 #pragma once
00014 
00015 #include "coreexp.h"
00016 #include "point2.h"
00017 #include "point3.h"
00018 #include "acolor.h"
00019 
00020 //
00021 //  Misc. noise functions from Texturing and Modeling A Procedural Approach
00022 //  Perlin, Musgrave...
00023 //
00024 
00025 CoreExport float bias(float a, float b);
00026 CoreExport float gain(float a, float b);
00027 CoreExport float clamp(float x, float a, float b);
00028 
00029 CoreExport float boxstep(float a, float b, float x); // linear from (a,0) to (b,1)
00030 CoreExport float smoothstep(float a, float b, float x);  // Hermite cubic from (a,0) to (b,1)
00031 CoreExport float mod(float x, float m); // returns x Mod m, handles negatives correctly
00032 CoreExport int mod(int x, int m); // returns x Mod m, handles negatives correctly
00033 
00034 // This function makes a sort of straight segment S curve.
00035 // sramp() is a for x < a-d and b for x > b+d.
00036 // for a+d < x < b-d sramp(x) = x
00037 // for a-d < x < a+d sramp makes a smooth transition (parabolic) from
00038 //     sramp' = 0 to sramp' = 1
00039 // for b-d < x < b+d sramp makes a smooth transition (parabolic) from
00040 //     sramp' = 1 to sramp' = 0
00041 CoreExport float sramp(float x,float a, float b, float d);
00042 
00043 // returns 0 if x<a, 1 if x>b otherwise x.
00044 CoreExport float threshold(float x,float a, float b);
00045 
00046 CoreExport void  setdebug(int i);
00047 CoreExport float noise1(float arg);
00048 CoreExport float noise2(Point2 p);
00049 CoreExport float noise3(Point3 p);
00050 CoreExport float noise4(Point3 p,float time);
00051 
00052 // This is 3DStudio's Noise function: its only slightly different from noise3:
00053 //  scaled up by factor of 1.65 and clamped to -1,+1.
00054 CoreExport float noise3DS(Point3 p);
00055 
00056 CoreExport float turbulence(Point3& p, float freq);
00057 
00058 CoreExport int Perm(int v);
00059 
00060 #define MAX_OCTAVES 50
00061 CoreExport float fBm1(float  point, float H, float lacunarity, float octaves);
00062 CoreExport float fBm1(Point2 point, float H, float lacunarity, float octaves);
00063 CoreExport float fBm1(Point3 point, float H, float lacunarity, float octaves);
00064 
00065 CoreExport float spline(float x, int nknots, float *knot);
00066 
00067 CoreExport Color color_spline(float x, int nknots, Color *knot);
00068 
00069 
00070 // faster version of floor
00071 inline int FLOOR( float x) { return ((int)(x) - ((int)(x)>(x)? 1:0)); }
00072 
00073 inline float frac(float x) { return x - (float)FLOOR(x); }
00074 inline float fmax(float x, float y) { return x>y?x:y;   }
00075 inline float fmin(float x, float y) { return x<y?x:y;   }
00076 
00077 // Macro to map it into interval [0,1]
00078 #define NOISE(p) ((1.0f+noise3DS(p))*.5f)
00079 
00080 // alpha-composite ctop on top of cbot, assuming pre-multiplied alpha
00081 inline AColor AComp(AColor cbot, AColor ctop) {
00082     float ia = 1.0f - ctop.a;
00083     return (ctop + ia*cbot);
00084     }
00085 
00086 
00087 //-----------------------------------------------------------
00088 // Based on: A Cellular Basis Function
00089 //                   Steven Worley
00090 //
00091 // SIGGRAPH 1996 Conference Procedings
00092 //
00093 #define MAX_CELL_LEVELS 20
00094 
00095 CoreExport void CellFunction(Point3 v,int n,float *dist,int *celIDs=NULL,Point3 *grads=NULL,float gradSmooth=0.0f);
00096 CoreExport void FractalCellFunction(Point3 v,float iterations, float lacunarity,int n,float *dist,int *celIDs=NULL,Point3 *grads=NULL,float gradSmooth=0.0f);
00097 CoreExport float RandFromCellID(int id);
00098