~ubuntu-branches/ubuntu/gutsy/blender/gutsy-security

« back to all changes in this revision

Viewing changes to source/blender/blenlib/intern/noise.c

  • Committer: Bazaar Package Importer
  • Author(s): Florian Ernst
  • Date: 2005-11-06 12:40:03 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20051106124003-3pgs7tcg5rox96xg
Tags: 2.37a-1.1
* Non-maintainer upload.
* Split out parts of 01_SConstruct_debian.dpatch again: root_build_dir
  really needs to get adjusted before the clean target runs - closes: #333958,
  see #288882 for reference

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
2
 *
3
 
 * $Id: noise.c,v 1.6 2004/04/04 01:36:16 hos Exp $
 
3
 * $Id: noise.c,v 1.9 2005/03/30 05:05:05 zuster Exp $
4
4
 *
5
5
 * ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
6
6
 *
32
32
 *
33
33
 */
34
34
 
 
35
#ifdef _WIN32    
 
36
#pragma warning (disable : 4244) // "conversion from double to float"
 
37
#pragma warning (disable : 4305) // "truncation from const double to float" 
 
38
#endif
 
39
 
35
40
#include <math.h>
36
41
#include "BLI_blenlib.h"
37
42
 
39
44
#include <config.h>
40
45
#endif
41
46
 
42
 
#ifdef _WIN32
43
 
#pragma warning (once : 4244) // "conversion from double to float"
44
 
#pragma warning (once : 4305) // "truncation from const double to float"
45
 
#endif
46
 
 
47
47
/* local */
48
48
float noise3_perlin(float vec[3]);
49
49
float turbulence_perlin(float *point, float lofreq, float hifreq);
210
210
#define lerp(t, a, b) ((a)+(t)*((b)-(a)))
211
211
#define npfade(t) ((t)*(t)*(t)*((t)*((t)*6-15)+10))
212
212
 
213
 
float grad(int hash, float x, float y, float z)
 
213
static float grad(int hash, float x, float y, float z)
214
214
{
215
215
        int h = hash & 15;                     // CONVERT LO 4 BITS OF HASH CODE
216
216
        float u = h<8 ? x : y,                 // INTO 12 GRADIENT DIRECTIONS.
219
219
}
220
220
 
221
221
/* instead of adding another permutation array, just use hash table defined above */
222
 
float newPerlin(float x, float y, float z)
 
222
static float newPerlin(float x, float y, float z)
223
223
{
224
224
        int A, AA, AB, B, BA, BB;
225
225
        float u=floor(x), v=floor(y), w=floor(z);
243
243
}
244
244
 
245
245
/* for use with BLI_gNoise()/BLI_gTurbulence(), returns unsigned improved perlin noise */
246
 
float newPerlinU(float x, float y, float z)
 
246
static float newPerlinU(float x, float y, float z)
247
247
{
248
248
        return (0.5+0.5*newPerlin(x, y, z));
249
249
}
254
254
/**************************/
255
255
 
256
256
/* Was BLI_hnoise(), removed noisesize, so other functions can call it without scaling. */
257
 
float orgBlenderNoise(float x, float y, float z)
 
257
static float orgBlenderNoise(float x, float y, float z)
258
258
{
259
259
        register float cn1, cn2, cn3, cn4, cn5, cn6, i, *h;
260
260
        float ox, oy, oz, jx, jy, jz;
324
324
}
325
325
 
326
326
/* as orgBlenderNoise(), returning signed noise */
327
 
float orgBlenderNoiseS(float x, float y, float z)
 
327
static float orgBlenderNoiseS(float x, float y, float z)
328
328
{
329
329
        return (2.0*orgBlenderNoise(x, y, z)-1.0);
330
330
}
532
532
}
533
533
 
534
534
/* for use with BLI_gNoise/gTurbulence, returns signed noise */
535
 
float orgPerlinNoise(float x, float y, float z)
 
535
static float orgPerlinNoise(float x, float y, float z)
536
536
{
537
537
        float v[3];
538
538
 
543
543
}
544
544
 
545
545
/* for use with BLI_gNoise/gTurbulence, returns unsigned noise */
546
 
float orgPerlinNoiseU(float x, float y, float z)
 
546
static float orgPerlinNoiseU(float x, float y, float z)
547
547
{
548
548
        float v[3];
549
549
 
585
585
/* Camberra omitted, didn't seem useful */
586
586
 
587
587
/* distance squared */
588
 
float dist_Squared(float x, float y, float z, float e) { return (x*x + y*y + z*z); }
 
588
static float dist_Squared(float x, float y, float z, float e) { return (x*x + y*y + z*z); }
589
589
/* real distance */
590
 
float dist_Real(float x, float y, float z, float e) { return sqrt(x*x + y*y + z*z); }
 
590
static float dist_Real(float x, float y, float z, float e) { return sqrt(x*x + y*y + z*z); }
591
591
/* manhattan/taxicab/cityblock distance */
592
 
float dist_Manhattan(float x, float y, float z, float e) { return (fabs(x) + fabs(y) + fabs(z)); }
 
592
static float dist_Manhattan(float x, float y, float z, float e) { return (fabs(x) + fabs(y) + fabs(z)); }
593
593
/* Chebychev */
594
 
float dist_Chebychev(float x, float y, float z, float e)
 
594
static float dist_Chebychev(float x, float y, float z, float e)
595
595
{
596
596
        float t;
597
597
        x = fabs(x);
602
602
}
603
603
 
604
604
/* minkovsky preset exponent 0.5 */
605
 
float dist_MinkovskyH(float x, float y, float z, float e)
 
605
static float dist_MinkovskyH(float x, float y, float z, float e)
606
606
{
607
607
        float d = sqrt(fabs(x)) + sqrt(fabs(y)) + sqrt(fabs(z));
608
608
        return (d*d);
609
609
}
610
610
 
611
611
/* minkovsky preset exponent 4 */
612
 
float dist_Minkovsky4(float x, float y, float z, float e)
 
612
static float dist_Minkovsky4(float x, float y, float z, float e)
613
613
{
614
614
        x *= x;
615
615
        y *= y;
618
618
}
619
619
 
620
620
/* Minkovsky, general case, slow, maybe too slow to be useful */
621
 
float dist_Minkovsky(float x, float y, float z, float e)
 
621
static float dist_Minkovsky(float x, float y, float z, float e)
622
622
{
623
623
 return pow(pow(fabs(x), e) + pow(fabs(y), e) + pow(fabs(z), e), 1.0/e);
624
624
}
696
696
}
697
697
 
698
698
/* returns different feature points for use in BLI_gNoise() */
699
 
float voronoi_F1(float x, float y, float z)
 
699
static float voronoi_F1(float x, float y, float z)
700
700
{
701
701
        float da[4], pa[12];
702
702
        voronoi(x, y, z, da, pa, 1, 0);
703
703
        return da[0];
704
704
}
705
705
 
706
 
float voronoi_F2(float x, float y, float z)
 
706
static float voronoi_F2(float x, float y, float z)
707
707
{
708
708
        float da[4], pa[12];
709
709
        voronoi(x, y, z, da, pa, 1, 0);
710
710
        return da[1];
711
711
}
712
712
 
713
 
float voronoi_F3(float x, float y, float z)
 
713
static float voronoi_F3(float x, float y, float z)
714
714
{
715
715
        float da[4], pa[12];
716
716
        voronoi(x, y, z, da, pa, 1, 0);
717
717
        return da[2];
718
718
}
719
719
 
720
 
float voronoi_F4(float x, float y, float z)
 
720
static float voronoi_F4(float x, float y, float z)
721
721
{
722
722
        float da[4], pa[12];
723
723
        voronoi(x, y, z, da, pa, 1, 0);
724
724
        return da[3];
725
725
}
726
726
 
727
 
float voronoi_F1F2(float x, float y, float z)
 
727
static float voronoi_F1F2(float x, float y, float z)
728
728
{
729
729
        float da[4], pa[12];
730
730
        voronoi(x, y, z, da, pa, 1, 0);
732
732
}
733
733
 
734
734
/* Crackle type pattern, just a scale/clamp of F2-F1 */
735
 
float voronoi_Cr(float x, float y, float z)
 
735
static float voronoi_Cr(float x, float y, float z)
736
736
{
737
737
        float t = 10*voronoi_F1F2(x, y, z);
738
738
        if (t>1.f) return 1.f;
742
742
 
743
743
/* Signed version of all 6 of the above, just 2x-1, not really correct though (range is potentially (0, sqrt(6)).
744
744
   Used in the musgrave functions */
745
 
float voronoi_F1S(float x, float y, float z)
 
745
static float voronoi_F1S(float x, float y, float z)
746
746
{
747
747
        float da[4], pa[12];
748
748
        voronoi(x, y, z, da, pa, 1, 0);
749
749
        return (2.0*da[0]-1.0);
750
750
}
751
751
 
752
 
float voronoi_F2S(float x, float y, float z)
 
752
static float voronoi_F2S(float x, float y, float z)
753
753
{
754
754
        float da[4], pa[12];
755
755
        voronoi(x, y, z, da, pa, 1, 0);
756
756
        return (2.0*da[1]-1.0);
757
757
}
758
758
 
759
 
float voronoi_F3S(float x, float y, float z)
 
759
static float voronoi_F3S(float x, float y, float z)
760
760
{
761
761
        float da[4], pa[12];
762
762
        voronoi(x, y, z, da, pa, 1, 0);
763
763
        return (2.0*da[2]-1.0);
764
764
}
765
765
 
766
 
float voronoi_F4S(float x, float y, float z)
 
766
static float voronoi_F4S(float x, float y, float z)
767
767
{
768
768
        float da[4], pa[12];
769
769
        voronoi(x, y, z, da, pa, 1, 0);
770
770
        return (2.0*da[3]-1.0);
771
771
}
772
772
 
773
 
float voronoi_F1F2S(float x, float y, float z)
 
773
static float voronoi_F1F2S(float x, float y, float z)
774
774
{
775
775
        float da[4], pa[12];
776
776
        voronoi(x, y, z, da, pa, 1, 0);
778
778
}
779
779
 
780
780
/* Crackle type pattern, just a scale/clamp of F2-F1 */
781
 
float voronoi_CrS(float x, float y, float z)
 
781
static float voronoi_CrS(float x, float y, float z)
782
782
{
783
783
        float t = 10*voronoi_F1F2(x, y, z);
784
784
        if (t>1.f) return 1.f;
795
795
/*************/
796
796
 
797
797
/* returns unsigned cellnoise */
798
 
float cellNoiseU(float x, float y, float z)
 
798
static float cellNoiseU(float x, float y, float z)
799
799
{
800
800
  int xi = (int)(floor(x));
801
801
  int yi = (int)(floor(y));