From: Tim R. <ti...@us...> - 2004-08-09 08:44:17
|
Update of /cvsroot/csdopenglnet/csdOpenGL/Cg In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18915 Modified Files: demo2.cs Log Message: Noise functions implemnted Index: demo2.cs =================================================================== RCS file: /cvsroot/csdopenglnet/csdOpenGL/Cg/demo2.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** demo2.cs 9 Aug 2004 05:14:49 -0000 1.1 --- demo2.cs 9 Aug 2004 08:44:09 -0000 1.2 *************** *** 22,25 **** --- 22,32 ---- protected double[] PhaseOffsetTable = new double[REPEAT_INTERVAL]; + protected const int TextureRes = 512; + protected IntPtr Context; + protected IntPtr Program; + protected IntPtr KdParam; + protected IntPtr ModelViewProjParam; + protected IntPtr TestColorParam; + public Demo2() { Debug.Indent(); *************** *** 144,151 **** Debug.Unindent(); ! return (Lattice1D[MaskedIndex(x)]); } ! protected double LatticeVal( int x, int y ) { Debug.Indent(); Debug.WriteLine( "Entering LatticeVal(int,int)" ); --- 151,158 ---- Debug.Unindent(); ! return MaskedIndex(x); } ! protected int LatticeVal( int x, int y ) { Debug.Indent(); Debug.WriteLine( "Entering LatticeVal(int,int)" ); *************** *** 157,164 **** Debug.Unindent(); ! return Lattice2D[Index,0]; } ! protected double LatticeVal( int x, int y, int z ) { Debug.Indent(); Debug.WriteLine( "Entering LatticeVal(int,int,int)" ); --- 164,171 ---- Debug.Unindent(); ! return Index; } ! protected int LatticeVal( int x, int y, int z ) { Debug.Indent(); Debug.WriteLine( "Entering LatticeVal(int,int,int)" ); *************** *** 171,175 **** Debug.Unindent(); ! return Lattice2D[Index,0]; } --- 178,182 ---- Debug.Unindent(); ! return Index; } *************** *** 214,218 **** double Ret; double InvUParam, InvVParam; ! double G00, G10, G01, G11; double F00, F10, F01, F11; --- 221,225 ---- double Ret; double InvUParam, InvVParam; ! int G00, G10, G01, G11; double F00, F10, F01, F11; *************** *** 238,248 **** G11 = LatticeVal( U1, V1 ); ! Debug.WriteLine( "Exiting Demo2.cgNoise(double,double) *" ); Debug.Unindent(); } public static void Main( string[] args) { Debug.Listeners.Add( new TextWriterTraceListener( Console.Out ) ); --- 245,392 ---- G11 = LatticeVal( U1, V1 ); + F00 = UParam * Lattice2D[G00,0] + VParam * Lattice2D[G00,1]; + F10 = (UParam - 1.0) * Lattice2D[G10,0] + VParam * Lattice2D[G10,1]; + F01 = UParam * Lattice2D[G01,0] + (VParam - 1.0) * Lattice2D[G01,1]; + F11 = (UParam - 1.0) * Lattice2D[G11,0] + (VParam - 1.0) * Lattice2D[G11,1]; ! Ret = InvUParam * ( InvVParam * F00 + VParam * F01 ) + UParam * ( InvVParam * F10 + VParam * F11 ); ! Ret = 0.5 * ( Ret + 1.0 ); ! Debug.WriteLine( "Exiting Demo2.cgNoise(double,double) *" ); Debug.Unindent(); + return Ret; } + protected double cgNoise( double u, double v, double w ) { + Debug.Indent(); + Debug.WriteLine( "Entering Demo2.cgNoise(double,double,double)" ); + + double Ret; + double InvUParam, InvVParam, InvWParam; + int G000, G100, G010, G110, G001, G101, G011, G111; + double F000, F100, F010, F110; + double F001, F101, F011, F111; + + int U0 = (int)System.Math.Floor(u); + int U1 = U0 + 1; + double UParam = u - (double)U0; + + int V0 = (int)System.Math.Floor(v); + int V1 = V0 + 1; + double VParam = v - (double)V0; + + int W0 = (int)System.Math.Floor(w); + int W1 = W0 + 1; + double WParam = v - (double)W0; + + Initialize(); + + UParam = WeightSmooth( UParam ); + VParam = WeightSmooth( VParam ); + WParam = WeightSmooth( WParam ); + + InvUParam = 1.0 - UParam; + InvVParam = 1.0 - VParam; + InvWParam = 1.0 - WParam; + + G000 = LatticeVal( U0, V0, W0 ); + G100 = LatticeVal( U1, V0, W0 ); + G010 = LatticeVal( U0, V1, W0 ); + G110 = LatticeVal( U1, V1, W0 ); + G001 = LatticeVal( U0, V0, W1 ); + G101 = LatticeVal( U1, V0, W1 ); + G011 = LatticeVal( U0, V1, W1 ); + G111 = LatticeVal( U1, V1, W1 ); + + F000 = UParam * Lattice3D[G000,0] * Lattice3D[G000,1] * WParam * Lattice3D[G000,2]; + F100 = InvUParam * Lattice3D[G100,0] + VParam * Lattice3D[G100,1] * WParam * Lattice3D[G000,2]; + F010 = UParam * Lattice3D[G010,0] + InvVParam * Lattice3D[G010,1] * WParam * Lattice3D[G000,2]; + F110 = InvUParam * Lattice3D[G110,0] + InvVParam * Lattice3D[G110,1] * WParam * Lattice3D[G000,2]; + F001 = UParam * Lattice3D[G001,0] + VParam * Lattice3D[G001,1] * WParam * Lattice3D[G001,2]; + F101 = InvUParam * Lattice3D[G101,0] + VParam * Lattice3D[G101,1] * WParam * Lattice3D[G001,2]; + F011 = UParam * Lattice3D[G001,0] + InvVParam + Lattice3D[G011,1] * WParam * Lattice3D[G001,2]; + F111 = InvUParam * Lattice3D[G111,0] + InvVParam * Lattice3D[G111,1] * WParam * Lattice3D[G001,2]; + + Ret = InvWParam * ( InvUParam * ( InvVParam * F000 + VParam * F010 ) + UParam * (InvVParam * F100 + VParam * F110 ) ) + WParam * ( InvUParam * ( InvVParam * F001 + VParam * F011 ) + UParam * ( InvVParam * F101 + VParam * F111 ) ); + + Debug.WriteLine( "Exiting Demo2.cgNoise(double,double,double) *" ); + Debug.Unindent(); + + return Ret; + } + + protected double cgFbm( double t, int octaves, double lambda, double omega ) { + Debug.Indent(); + Debug.WriteLine( "Entering Demo2.cgFbm(double,int,double,double)" ); + + double Amp = 1.0; + double TotalAmp = 0.0; + double Freq = 1.0; + double Ret = 0.0; + + for( int i=0; i<octaves; ++i ) { + Ret += Amp * cgNoise( Freq * t + PhaseOffsetTable[i] ); + TotalAmp += Amp; + Amp *= lambda; + Freq *= omega; + } + + Ret /= TotalAmp; + + Debug.WriteLine( "Exiting Demo2.cgFbm(doubl,int,double,double) *" ); + Debug.Unindent(); + + return Ret; + } + + protected double cgFbm( double u, double v, int octaves, double lambda, double omega ) { + Debug.Indent(); + Debug.WriteLine( "Entering Demo2.cgFbm(double,double,int,double,double)" ); + + double Amp = 1.0; + double Freq = 1.0; + double TotalAmp = 0.0; + double Ret = 0.0; + + for ( int i=0; i<octaves; i++ ) { + Ret += Amp * cgNoise( Freq * u + PhaseOffsetTable[i], Freq * v + PhaseOffsetTable[i+1] ); + TotalAmp += Amp; + Amp *= lambda; + Freq *= omega; + } + + Ret /= TotalAmp; + + Debug.WriteLine( "Exiting Demo2.cgFbm(double,double,int,double,double) *" ); + Debug.Unindent(); + + return Ret; + } + + protected double cgFbm( double u, double v, double w, int octaves, double lambda, double omega ) { + Debug.Indent(); + Debug.WriteLine( "Entering Demo2.cgFbm(double,double,double,int,double,double)" ); + + double Amp = 1.0; + double Freq = 1.0; + double TotalAmp = 0.0; + double Ret = 0.0; + + for ( int i=0; i<octaves; i++ ) { + Ret += Amp * cgNoise( Freq * u + PhaseOffsetTable[i], Freq * v + PhaseOffsetTable[ i+1 ], Freq * w + PhaseOffsetTable[i+2] ); + TotalAmp += Amp; + Amp *= lambda; + Freq *= omega; + } + + Ret /= TotalAmp; + + Debug.WriteLine( "Exiting Demo2.cgFbm(double,double,double,int,double,double) *" ); + Debug.Unindent(); + + return Ret; + } + public static void Main( string[] args) { Debug.Listeners.Add( new TextWriterTraceListener( Console.Out ) ); |