PageRenderTime 937ms CodeModel.GetById 745ms app.highlight 7ms RepoModel.GetById 184ms app.codeStats 0ms

/indra/newview/noise.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 85 lines | 41 code | 18 blank | 26 comment | 1 complexity | 65c0331cc013d5fa6aa527ca44dec811 MD5 | raw file
 1/** 
 2 * @file noise.cpp
 3 * @brief Perlin noise routines for procedural textures, etc
 4 *
 5 * $LicenseInfo:firstyear=2000&license=viewerlgpl$
 6 * Second Life Viewer Source Code
 7 * Copyright (C) 2010, Linden Research, Inc.
 8 * 
 9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation;
12 * version 2.1 of the License only.
13 * 
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17 * Lesser General Public License for more details.
18 * 
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
22 * 
23 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
24 * $/LicenseInfo$
25 */
26
27#include "llviewerprecompiledheaders.h"
28
29#include "noise.h"
30
31#include "llrand.h"
32
33
34// static
35#define B 0x100
36S32 p[B + B + 2];
37F32 g3[B + B + 2][3];
38F32 g2[B + B + 2][2];
39F32 g1[B + B + 2];
40S32 gNoiseStart = 1;
41
42
43F32 noise2(F32 *vec)
44{
45	U8 bx0, bx1, by0, by1;
46	U32 b00, b10, b01, b11;
47	F32 rx0, rx1, ry0, ry1, *q, sx, sy, a, b, u, v;
48	S32 i, j;
49
50	if (gNoiseStart) {
51		gNoiseStart = 0;
52		init();
53	}
54
55
56	fast_setup(*vec, bx0, bx1, rx0, rx1);
57	fast_setup(*(vec + 1), by0, by1, ry0, ry1);
58
59	i = *(p + bx0);
60	j = *(p + bx1);
61
62	b00 = *(p + i + by0);
63	b10 = *(p + j + by0);
64	b01 = *(p + i + by1);
65	b11 = *(p + j + by1);
66
67	sx = s_curve(rx0);
68	sy = s_curve(ry0);
69
70
71	q = *(g2 + b00);
72	u = fast_at2(rx0, ry0, q);
73	q = *(g2 + b10); 
74	v = fast_at2(rx1, ry0, q);
75	a = lerp_m(sx, u, v);
76
77	q = *(g2 + b01); 
78	u = fast_at2(rx0,ry1,q);
79	q = *(g2 + b11); 
80	v = fast_at2(rx1,ry1,q);
81	b = lerp_m(sx, u, v);
82
83	return lerp_m(sy, a, b);
84}
85