Skip to content

Commit 74ddd75

Browse files
committed
Fixed compilation issue on Unity 2021
1 parent 38393b3 commit 74ddd75

File tree

2 files changed

+99
-100
lines changed

2 files changed

+99
-100
lines changed

Runtime/Noise/Hashx.cs

Lines changed: 98 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -94,26 +94,26 @@ public static partial class mathx
9494
// }
9595

9696

97-
private static readonly float4 primef = new(73856093, 19349663, 83492791, 16835253);
98-
private static readonly int4 prime = new(73856093, 19349663, 83492791, 16835253);
99-
100-
private static float hash01(this float value) => (value + primef.x) % primef.y / primef.y;
101-
private static float hash01(this float2 coord) => coord.dot(primef.xy) % primef.y / primef.y;
102-
private static float hash01(this float3 coord) => coord.dot(primef.xyz) % primef.y / primef.y;
103-
private static float hash01(this float4 coord) => coord.dot(primef) % primef.y / primef.y;
104-
private static float hash01(this int value) => (value + primef.x) % primef.y / primef.y;
105-
private static float hash01(this int2 coord) => coord.dot(prime.xy) % primef.y / primef.y;
106-
private static float hash01(this int3 coord) => coord.dot(prime.xyz) % primef.y / primef.y;
107-
private static float hash01(this int4 coord) => coord.dot(prime) % primef.y / primef.y;
108-
109-
public static float hashnp01(this float value) => value.hash01().m2n1();
110-
// public static float hashnp01(this f2 coord) => coord.hash01().m2n1();
111-
public static float hashnp01(this float3 coord) => coord.hash01().m2n1();
112-
public static float hashnp01(this float4 coord) => coord.hash01().m2n1();
113-
public static float hashnp01(this int value) => value.hash01().m2n1();
114-
public static float hashnp01(this int2 coord) => coord.hash01().m2n1();
115-
public static float hashnp01(this int3 coord) => coord.hash01().m2n1();
116-
public static float hashnp01(this int4 coord) => coord.hash01().m2n1();
97+
// private static readonly float4 primef = new(73856093, 19349663, 83492791, 16835253);
98+
// private static readonly int4 prime = new(73856093, 19349663, 83492791, 16835253);
99+
//
100+
// private static float hash01(this float value) => (value + primef.x) % primef.y / primef.y;
101+
// private static float hash01(this float2 coord) => coord.dot(primef.xy) % primef.y / primef.y;
102+
// private static float hash01(this float3 coord) => coord.dot(primef.xyz) % primef.y / primef.y;
103+
// private static float hash01(this float4 coord) => coord.dot(primef) % primef.y / primef.y;
104+
// private static float hash01(this int value) => (value + primef.x) % primef.y / primef.y;
105+
// private static float hash01(this int2 coord) => coord.dot(prime.xy) % primef.y / primef.y;
106+
// private static float hash01(this int3 coord) => coord.dot(prime.xyz) % primef.y / primef.y;
107+
// private static float hash01(this int4 coord) => coord.dot(prime) % primef.y / primef.y;
108+
//
109+
// public static float hashnp01(this float value) => value.hash01().m2n1();
110+
// // public static float hashnp01(this f2 coord) => coord.hash01().m2n1();
111+
// public static float hashnp01(this float3 coord) => coord.hash01().m2n1();
112+
// public static float hashnp01(this float4 coord) => coord.hash01().m2n1();
113+
// public static float hashnp01(this int value) => value.hash01().m2n1();
114+
// public static float hashnp01(this int2 coord) => coord.hash01().m2n1();
115+
// public static float hashnp01(this int3 coord) => coord.hash01().m2n1();
116+
// public static float hashnp01(this int4 coord) => coord.hash01().m2n1();
117117

118118
// public static float hashnp01(this f2 coord)
119119
// {
@@ -125,83 +125,83 @@ public static partial class mathx
125125
// hash = (hash << 13) ^ hash;
126126
// return (float)(hash & 0x7fffffff) / (float)0x7fffffff;
127127
// }
128-
129-
const float F1 = 0.3176f;
130-
const float F2 = 0.7393f;
131-
const float F3 = 0.2847f;
132-
private static float Hash(float3 coord)
133-
{
134-
float3 n = frac(coord * F1);
135-
n += dot(n, n.yxz + 19.19f) + F2;
136-
n = frac(n * F3);
137-
n += dot(n, n.yxz + 57.57f) + F1;
138-
return frac(n.cmul() * n.csum());
139-
}
140-
141-
public static float Hash(this float2 coord) {
142-
return coord.seedrand() * 2 -1;
143-
// float2 n = frac(coord * F1);
144-
// n += dot(n, n.yx + 19.19f) + F2;
145-
// n = frac(n * F3);
146-
// n += dot(n, n.yx + 57.57f) + F1;
147-
// return frac(n.cmul() * n.csum());
148-
}
149-
private static float Hash(float coord)
150-
{
151-
float n = frac(coord * F1);
152-
n += n * (n + 19.19f) + F2;
153-
n = frac(n * F3);
154-
n += n * (n + 57.57f) + F1;
155-
return frac(n * n);
156-
}
157-
158-
159-
public static float GradientNoise(float3 position)
160-
{
161-
int3 cell = (int3)math.floor(position);
162-
float3 frac = position - cell;
163-
164-
float3x4 corners = new float3x4(
165-
GenerateGradient(cell + int3(0, 0, 0)),
166-
GenerateGradient(cell + int3(1, 0, 0)),
167-
GenerateGradient(cell + int3(0, 1, 0)),
168-
GenerateGradient(cell + int3(1, 1, 0))
169-
);
170-
171-
float3x4 corners_z1 = new float3x4(
172-
GenerateGradient(cell + int3(0, 0, 1)),
173-
GenerateGradient(cell + int3(1, 0, 1)),
174-
GenerateGradient(cell + int3(0, 1, 1)),
175-
GenerateGradient(cell + int3(1, 1, 1))
176-
);
177-
178-
float3x4 blend_x = frac.z.lerp(corners, corners_z1);
179-
float3x2 blend_xy = frac.y.lerp(new float3x2(blend_x.c0, blend_x.c1), new float3x2(blend_x.c2, blend_x.c3));
180-
float3 blend_xyz = frac.x.lerp(blend_xy.c0, blend_xy.c1);
181-
182-
return blend_xyz.dot(0.25f);
183-
}
184-
185-
public static float3 GenerateGradient(int3 cell) => cell.hashnp01();
186-
187-
188-
public static float2 randdir(float2 p) => p.seedrand2() * 2 -1; // haha lol symetry on both axis
189-
190-
public static float unity_gradientNoise(float2 p)
191-
{
192-
float2 ip = floor(p);
193-
float2 fp = frac(p);
194-
float2 d0 = f2(dot(randdir(ip), fp), dot(randdir(ip + rightf2), fp - rightf2));
195-
float2 d1 = f2(dot(randdir(ip + upf2), fp - upf2), dot(randdir(ip + 1), fp - 1));
196-
fp = smooth5(fp);
197-
d1 = fp.y.lerp(d0, d1);
198-
return fp.x.lerp(d1.x, d1.y) + 0.5f;
199-
}
200-
201-
private const float F = 0.61803398875f; // golden ratio
202-
public static float hashx(this float2 p) => p.mult(F).frac().set(out p).add(p.cycle().add(37).dot(p)).set(out p).cmul().mult(p.csum()).frac();
203-
public static float hashx(this float3 p) => p.mult(F).frac().set(out p).add(p.cycle().add(37).dot(p)).set(out p).cmul().mult(p.csum()).frac();
204-
public static float hashx(this float4 p) => p.mult(F).frac().set(out p).add(p.cycle().add(37).dot(p)).set(out p).cmul().mult(p.csum()).frac();
205-
public static float hashx(this float p) => frac(p * F + 0.1f).add(p.sq().mult(34.53f)).set(out p).mult(p + 1).frac();
128+
//
129+
// const float F1 = 0.3176f;
130+
// const float F2 = 0.7393f;
131+
// const float F3 = 0.2847f;
132+
// private static float Hash(float3 coord)
133+
// {
134+
// float3 n = frac(coord * F1);
135+
// n += dot(n, n.yxz + 19.19f) + F2;
136+
// n = frac(n * F3);
137+
// n += dot(n, n.yxz + 57.57f) + F1;
138+
// return frac(n.cmul() * n.csum());
139+
// }
140+
//
141+
// public static float Hash(this float2 coord) {
142+
// return coord.seedrand() * 2 -1;
143+
// // float2 n = frac(coord * F1);
144+
// // n += dot(n, n.yx + 19.19f) + F2;
145+
// // n = frac(n * F3);
146+
// // n += dot(n, n.yx + 57.57f) + F1;
147+
// // return frac(n.cmul() * n.csum());
148+
// }
149+
// private static float Hash(float coord)
150+
// {
151+
// float n = frac(coord * F1);
152+
// n += n * (n + 19.19f) + F2;
153+
// n = frac(n * F3);
154+
// n += n * (n + 57.57f) + F1;
155+
// return frac(n * n);
156+
// }
157+
//
158+
//
159+
// public static float GradientNoise(float3 position)
160+
// {
161+
// int3 cell = (int3)math.floor(position);
162+
// float3 frac = position - cell;
163+
//
164+
// float3x4 corners = new float3x4(
165+
// GenerateGradient(cell + int3(0, 0, 0)),
166+
// GenerateGradient(cell + int3(1, 0, 0)),
167+
// GenerateGradient(cell + int3(0, 1, 0)),
168+
// GenerateGradient(cell + int3(1, 1, 0))
169+
// );
170+
//
171+
// float3x4 corners_z1 = new float3x4(
172+
// GenerateGradient(cell + int3(0, 0, 1)),
173+
// GenerateGradient(cell + int3(1, 0, 1)),
174+
// GenerateGradient(cell + int3(0, 1, 1)),
175+
// GenerateGradient(cell + int3(1, 1, 1))
176+
// );
177+
//
178+
// float3x4 blend_x = frac.z.lerp(corners, corners_z1);
179+
// float3x2 blend_xy = frac.y.lerp(new float3x2(blend_x.c0, blend_x.c1), new float3x2(blend_x.c2, blend_x.c3));
180+
// float3 blend_xyz = frac.x.lerp(blend_xy.c0, blend_xy.c1);
181+
//
182+
// return blend_xyz.dot(0.25f);
183+
// }
184+
//
185+
// public static float3 GenerateGradient(int3 cell) => cell.hashnp01();
186+
//
187+
//
188+
// public static float2 randdir(float2 p) => p.seedrand2() * 2 -1; // haha lol symetry on both axis
189+
//
190+
// public static float unity_gradientNoise(float2 p)
191+
// {
192+
// float2 ip = floor(p);
193+
// float2 fp = frac(p);
194+
// float2 d0 = f2(dot(randdir(ip), fp), dot(randdir(ip + rightf2), fp - rightf2));
195+
// float2 d1 = f2(dot(randdir(ip + upf2), fp - upf2), dot(randdir(ip + 1), fp - 1));
196+
// fp = smooth5(fp);
197+
// d1 = fp.y.lerp(d0, d1);
198+
// return fp.x.lerp(d1.x, d1.y) + 0.5f;
199+
// }
200+
//
201+
// private const float F = 0.61803398875f; // golden ratio
202+
// public static float hashx(this float2 p) => p.mult(F).frac().set(out p).add(p.cycle().add(37).dot(p)).set(out p).cmul().mult(p.csum()).frac();
203+
// public static float hashx(this float3 p) => p.mult(F).frac().set(out p).add(p.cycle().add(37).dot(p)).set(out p).cmul().mult(p.csum()).frac();
204+
// public static float hashx(this float4 p) => p.mult(F).frac().set(out p).add(p.cycle().add(37).dot(p)).set(out p).cmul().mult(p.csum()).frac();
205+
// public static float hashx(this float p) => frac(p * F + 0.1f).add(p.sq().mult(34.53f)).set(out p).mult(p + 1).frac();
206206
}
207207
}

Runtime/_Experimental/Jobify/FunctionPointers.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,9 @@
99

1010
namespace Unity.Mathematics
1111
{
12-
[BurstCompile]
1312
public static partial class FunctionPointers
1413
{
1514
// ** Very important to cache the function pointer for performance reasons
16-
public static readonly f1x3_f1 p_smax_exp = compile<f1x3_f1>(mathx.smax_exp);
15+
// public static readonly f1x3_f1 p_smax_exp = compile<f1x3_f1>(mathx.smax_exp);
1716
}
1817
}

0 commit comments

Comments
 (0)