noise: warnings--
This commit is contained in:
parent
992a8b2568
commit
b1b088eab6
@ -1,8 +1,6 @@
|
|||||||
use crate::lib8::interpolate::*;
|
use crate::lib8::interpolate::*;
|
||||||
|
|
||||||
use num::PrimInt;
|
const NOISE_CUBE: [u8; 257] = [
|
||||||
|
|
||||||
const noise_cube: [u8; 257] = [
|
|
||||||
151, 160, 137, 91, 90, 15, 131, 13, 201, 95, 96, 53, 194, 233, 7, 225,
|
151, 160, 137, 91, 90, 15, 131, 13, 201, 95, 96, 53, 194, 233, 7, 225,
|
||||||
140, 36, 103, 30, 69, 142, 8, 99, 37, 240, 21, 10, 23, 190, 6, 148,
|
140, 36, 103, 30, 69, 142, 8, 99, 37, 240, 21, 10, 23, 190, 6, 148,
|
||||||
247, 120, 234, 75, 0, 26, 197, 62, 94, 252, 219, 203, 117, 35, 11, 32,
|
247, 120, 234, 75, 0, 26, 197, 62, 94, 252, 219, 203, 117, 35, 11, 32,
|
||||||
@ -21,39 +19,39 @@ const noise_cube: [u8; 257] = [
|
|||||||
222, 114, 67, 29, 24, 72, 243, 141, 128, 195, 78, 66, 215, 61, 156, 180,
|
222, 114, 67, 29, 24, 72, 243, 141, 128, 195, 78, 66, 215, 61, 156, 180,
|
||||||
151];
|
151];
|
||||||
|
|
||||||
const fn P(x: u8) -> u8 {
|
const fn get_cube(x: u8) -> u8 {
|
||||||
noise_cube[x as usize]
|
NOISE_CUBE[x as usize]
|
||||||
}
|
}
|
||||||
|
|
||||||
fn inoise8_raw(x: u16, y: u16) -> i8 {
|
fn inoise8_raw(x_src: u16, y_src: u16) -> i8 {
|
||||||
let X: u8 = x.wrapping_shr(8) as u8;
|
let x = x_src.wrapping_shr(8) as u8;
|
||||||
let Y: u8 = y.wrapping_shr(8) as u8;
|
let y = y_src.wrapping_shr(8) as u8;
|
||||||
|
|
||||||
let A: u8 = P(X) + Y;
|
let a = get_cube(x) + y;
|
||||||
let AA: u8 = P(A);
|
let aa = get_cube(a);
|
||||||
let AB: u8 = P(A+1);
|
let ab = get_cube(a+1);
|
||||||
let B: u8 = P(X+1) + Y;
|
let b = get_cube(x+1) + y;
|
||||||
let BA: u8 = P(B);
|
let ba = get_cube(b);
|
||||||
let BB: u8 = P(B+1);
|
let bb = get_cube(b+1);
|
||||||
|
|
||||||
let mut u: u8 = x as u8;
|
let mut u = x_src as u8;
|
||||||
let mut v: u8 = y as u8;
|
let mut v = y_src as u8;
|
||||||
|
|
||||||
let xx: i8 = ((x as u8).wrapping_shr(1) & 0x7f) as i8;
|
let xx = ((x_src as u8).wrapping_shr(1) & 0x7f) as i8;
|
||||||
let yy: i8 = ((y as u8).wrapping_shr(1) & 0x7f) as i8;
|
let yy = ((y_src as u8).wrapping_shr(1) & 0x7f) as i8;
|
||||||
let N: i8 = 0x80u8 as i8;
|
let n = 0x80u8 as i8;
|
||||||
|
|
||||||
u = ease8InOutQuad(u);
|
u = ease8InOutQuad(u);
|
||||||
v = ease8InOutQuad(v);
|
v = ease8InOutQuad(v);
|
||||||
|
|
||||||
let X1: i8 = lerp7by8(grad8(P(AA), xx, yy), grad8(P(BA), xx.wrapping_sub(N), yy), u);
|
let x1 = lerp7by8(grad8(get_cube(aa), xx, yy), grad8(get_cube(ba), xx.wrapping_sub(n), yy), u);
|
||||||
let X2: i8 = lerp7by8(grad8(P(AB), xx, yy.wrapping_sub(N)), grad8(P(BB), xx.wrapping_sub(N), yy.wrapping_sub(N)), u);
|
let x2 = lerp7by8(grad8(get_cube(ab), xx, yy.wrapping_sub(n)), grad8(get_cube(bb), xx.wrapping_sub(n), yy.wrapping_sub(n)), u);
|
||||||
|
|
||||||
return lerp7by8(X1, X2, v);
|
return lerp7by8(x1, x2, v);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn inoise8(x: i16, y: i16) -> u8 {
|
pub fn inoise8(x: i16, y: i16) -> u8 {
|
||||||
let mut n: i8 = inoise8_raw(x as u16, y as u16);
|
let mut n = inoise8_raw(x as u16, y as u16);
|
||||||
n = n.wrapping_add(64);
|
n = n.wrapping_add(64);
|
||||||
return (n as u8).saturating_add(n as u8);
|
return (n as u8).saturating_add(n as u8);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user