-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move all members but position to another struct named VertexExt.
- Loading branch information
Showing
8 changed files
with
64 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
// Copyright © 2022 | ||
// Copyright © 2022-2024 | ||
// Author: Antonio Caggiano <[email protected]> | ||
// SPDX-License-Identifier: MIT | ||
|
||
|
@@ -35,40 +35,40 @@ impl BvhTriangle { | |
|
||
/// Returns the interpolation of the vertices colors | ||
pub fn interpolate_colors(&self, hit_uv: &Vec2) -> Color { | ||
self.vertices[2].color * (1.0 - hit_uv.x - hit_uv.y) | ||
+ self.vertices[0].color * hit_uv.x | ||
+ self.vertices[1].color * hit_uv.y | ||
self.vertices[2].ext.color * (1.0 - hit_uv.x - hit_uv.y) | ||
+ self.vertices[0].ext.color * hit_uv.x | ||
+ self.vertices[1].ext.color * hit_uv.y | ||
} | ||
|
||
/// Returns the interpolation of the vertices uvs | ||
pub fn interpolate_uvs(&self, hit_uv: &Vec2) -> Vec2 { | ||
self.vertices[2].uv * (1.0 - hit_uv.x - hit_uv.y) | ||
+ self.vertices[0].uv * hit_uv.x | ||
+ self.vertices[1].uv * hit_uv.y | ||
self.vertices[2].ext.uv * (1.0 - hit_uv.x - hit_uv.y) | ||
+ self.vertices[0].ext.uv * hit_uv.x | ||
+ self.vertices[1].ext.uv * hit_uv.y | ||
} | ||
|
||
/// Returns the interpolation of the vertices normals | ||
pub fn interpolate_normals(&self, hit_uv: &Vec2) -> Vec3 { | ||
let n = self.vertices[2].normal * (1.0 - hit_uv.x - hit_uv.y) | ||
+ self.vertices[0].normal * hit_uv.x | ||
+ self.vertices[1].normal * hit_uv.y; | ||
let n = self.vertices[2].ext.normal * (1.0 - hit_uv.x - hit_uv.y) | ||
+ self.vertices[0].ext.normal * hit_uv.x | ||
+ self.vertices[1].ext.normal * hit_uv.y; | ||
n.get_normalized() | ||
} | ||
|
||
/// Returns the interpolation of the vertices tangents | ||
pub fn interpolate_tangents(&self, hit_uv: &Vec2) -> Vec3 { | ||
let mut t = self.vertices[2].tangent * (1.0 - hit_uv.x - hit_uv.y) | ||
+ self.vertices[0].tangent * hit_uv.x | ||
+ self.vertices[1].tangent * hit_uv.y; | ||
let mut t = self.vertices[2].ext.tangent * (1.0 - hit_uv.x - hit_uv.y) | ||
+ self.vertices[0].ext.tangent * hit_uv.x | ||
+ self.vertices[1].ext.tangent * hit_uv.y; | ||
t.normalize(); | ||
t | ||
} | ||
|
||
/// Returns the interpolation of the vertices bitangents | ||
pub fn interpolate_bitangents(&self, hit_uv: &Vec2) -> Vec3 { | ||
let mut b = self.vertices[2].bitangent * (1.0 - hit_uv.x - hit_uv.y) | ||
+ self.vertices[0].bitangent * hit_uv.x | ||
+ self.vertices[1].bitangent * hit_uv.y; | ||
let mut b = self.vertices[2].ext.bitangent * (1.0 - hit_uv.x - hit_uv.y) | ||
+ self.vertices[0].ext.bitangent * hit_uv.x | ||
+ self.vertices[1].ext.bitangent * hit_uv.y; | ||
b.normalize(); | ||
b | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,14 @@ | ||
// Copyright © 2022 | ||
// Copyright © 2022-2024 | ||
// Author: Antonio Caggiano <[email protected]> | ||
// SPDX-License-Identifier: MIT | ||
|
||
pub mod sphere; | ||
pub mod triangles; | ||
pub mod vertex; | ||
|
||
pub use sphere::*; | ||
pub use triangles::*; | ||
pub use vertex::*; | ||
|
||
#[derive(Debug, Clone)] | ||
pub enum Geometry { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,28 @@ | ||
// Copyright © 2022 | ||
// Copyright © 2022-2024 | ||
// Author: Antonio Caggiano <[email protected]> | ||
// SPDX-License-Identifier: MIT | ||
|
||
use super::*; | ||
use crate::*; | ||
|
||
#[repr(C)] | ||
#[derive(Debug, Copy, Clone, PartialEq)] | ||
#[derive(Debug, Default, Copy, Clone, PartialEq)] | ||
pub struct Vertex { | ||
pub pos: Point3, | ||
pub ext: VertexExt, | ||
} | ||
|
||
impl Vertex { | ||
pub fn new(x: f32, y: f32, z: f32) -> Self { | ||
Self { | ||
pos: Point3::new(x, y, z), | ||
ext: Default::default(), | ||
} | ||
} | ||
} | ||
|
||
#[repr(C)] | ||
#[derive(Debug, Copy, Clone, PartialEq)] | ||
pub struct VertexExt { | ||
pub uv: Vec2, | ||
pub color: Color, | ||
|
||
|
@@ -17,10 +31,9 @@ pub struct Vertex { | |
pub bitangent: Vec3, | ||
} | ||
|
||
impl Vertex { | ||
pub fn new(x: f32, y: f32, z: f32) -> Self { | ||
impl Default for VertexExt { | ||
fn default() -> Self { | ||
Self { | ||
pos: Point3::new(x, y, z), | ||
uv: Vec2::default(), | ||
color: Color::from(0xFFFFFFFF), | ||
normal: Vec3::new(0.0, 0.0, 1.0), | ||
|
@@ -29,9 +42,3 @@ impl Vertex { | |
} | ||
} | ||
} | ||
|
||
impl Default for Vertex { | ||
fn default() -> Self { | ||
Self::new(0.0, 0.0, 0.0) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
// Copyright © 2022 | ||
// Copyright © 2022-2024 | ||
// Author: Antonio Caggiano <[email protected]> | ||
// SPDX-License-Identifier: MIT | ||
|
||
|
@@ -22,7 +22,6 @@ pub mod sampler; | |
pub mod scene; | ||
pub mod texture; | ||
pub mod util; | ||
pub mod vertex; | ||
#[cfg(target_arch = "wasm32")] | ||
pub mod www; | ||
|
||
|
@@ -43,6 +42,5 @@ pub use sampler::*; | |
pub use scene::*; | ||
pub use texture::*; | ||
pub use util::*; | ||
pub use vertex::*; | ||
#[cfg(target_arch = "wasm32")] | ||
pub use www::*; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters