Fix out of bounds texture lookup and tweak noise function.
This commit is contained in:
parent
9c5233e057
commit
2f0ee09084
@ -60,9 +60,9 @@ impl NoiseTexture {
|
|||||||
|
|
||||||
impl Texture for NoiseTexture {
|
impl Texture for NoiseTexture {
|
||||||
fn value(&self, _u: f32, _v: f32, p: Vec3) -> Vec3 {
|
fn value(&self, _u: f32, _v: f32, p: Vec3) -> Vec3 {
|
||||||
//Vec3::new(1., 1., 1.) * turb(self.scale * p, 7)
|
Vec3::new(1., 1., 1.) * turb(self.scale * p, 7)
|
||||||
//Vec3::new(1., 1., 1.) * 0.5 * (1. + turb(self.scale * p, 7))
|
//Vec3::new(1., 1., 1.) * 0.5 * (1. + turb(self.scale * p, 7))
|
||||||
Vec3::new(1., 1., 1.) * 0.5 * (1. + (self.scale * p.x + 5. * turb(p, 7)).sin())
|
//Vec3::new(1., 1., 1.) * 0.5 * (1. + (self.scale * p.x + 5. * turb(p, 7)).sin())
|
||||||
//Vec3::new(1., 1., 1.) * 0.5 * (1. + GENERATOR.noise(self.scale * p))
|
//Vec3::new(1., 1., 1.) * 0.5 * (1. + GENERATOR.noise(self.scale * p))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -87,8 +87,20 @@ impl ImageTexture {
|
|||||||
impl Texture for ImageTexture {
|
impl Texture for ImageTexture {
|
||||||
fn value(&self, u: f32, v: f32, _p: Vec3) -> Vec3 {
|
fn value(&self, u: f32, v: f32, _p: Vec3) -> Vec3 {
|
||||||
// Wrap texcoords by default.
|
// Wrap texcoords by default.
|
||||||
let x = (u % 1. * self.width) as u32;
|
let x = (u % 1. * (self.width - 1.)) as u32;
|
||||||
let y = ((1. - v % 1.) * self.height) as u32;
|
let y = ((1. - v % 1.) * (self.height - 1.)) as u32;
|
||||||
|
if x >= self.width as u32 {
|
||||||
|
panic!(format!(
|
||||||
|
"u {} v {} x {} y {} w {} h {}",
|
||||||
|
u, v, x, y, self.width, self.height
|
||||||
|
));
|
||||||
|
}
|
||||||
|
if y >= self.height as u32 {
|
||||||
|
panic!(format!(
|
||||||
|
"u {} v {} x {} y {} w {} h {}",
|
||||||
|
u, v, x, y, self.width, self.height
|
||||||
|
));
|
||||||
|
}
|
||||||
let p = self.img.get_pixel(x, y);
|
let p = self.img.get_pixel(x, y);
|
||||||
let rgb = Vec3::new(p[0] as f32 / 255., p[1] as f32 / 255., p[2] as f32 / 255.);
|
let rgb = Vec3::new(p[0] as f32 / 255., p[1] as f32 / 255., p[2] as f32 / 255.);
|
||||||
rgb
|
rgb
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user