Fix torus normals (#3549)
# Objective Fixes #3547 ## Solution Normal calc adapted from https://web.cs.ucdavis.edu/~amenta/s12/findnorm.pdf ## Before <img width="1392" alt="before" src="https://user-images.githubusercontent.com/200550/148125212-fb1c083e-3c57-4330-a656-df34513c36ab.png"> ## After <img width="1392" alt="after" src="https://user-images.githubusercontent.com/200550/148125223-174dc956-37df-4ac2-8983-b18e1e2a9a7d.png"> I'm assuming that the greyness and the self-shadowing artifacts are... normal for the new renderer.
This commit is contained in:
parent
b9c623e4f3
commit
24b21ea35e
@ -37,7 +37,6 @@ impl From<Torus> for Mesh {
|
||||
|
||||
for segment in 0..=torus.subdivisions_segments {
|
||||
let theta = segment_stride * segment as f32;
|
||||
let segment_pos = Vec3::new(theta.cos(), 0.0, theta.sin() * torus.radius);
|
||||
|
||||
for side in 0..=torus.subdivisions_sides {
|
||||
let phi = side_stride * side as f32;
|
||||
@ -46,7 +45,14 @@ impl From<Torus> for Mesh {
|
||||
let z = theta.sin() * (torus.radius + torus.ring_radius * phi.cos());
|
||||
let y = torus.ring_radius * phi.sin();
|
||||
|
||||
let normal = segment_pos.cross(Vec3::Y).normalize();
|
||||
let tan_ring = Vec3::new(
|
||||
theta.cos() * phi.sin() * -1.0,
|
||||
theta.sin() * phi.sin() * -1.0,
|
||||
phi.cos(),
|
||||
);
|
||||
let tan = Vec3::new(theta.sin() * -1.0, theta.cos(), 0.0);
|
||||
|
||||
let normal = tan.cross(tan_ring).normalize();
|
||||
|
||||
positions.push([x, y, z]);
|
||||
normals.push(normal.into());
|
||||
|
||||
Loading…
Reference in New Issue
Block a user