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:
Rob Parrett 2022-01-04 21:30:46 +00:00
parent b9c623e4f3
commit 24b21ea35e

View File

@ -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());