Fixed scenery

This commit is contained in:
numzero 2025-03-29 00:53:47 +03:00
parent 9a9a88360a
commit ae6b1f6b0d
2 changed files with 20 additions and 29 deletions

View File

@ -1,8 +1,10 @@
use crate::anim::{self, SphereParams};
use crate::trace::{self, Tracer, TracerData};
use crate::Sphere;
use glam::{mat3, uvec2, vec3, UVec2, Vec3};
use std::f32::consts::PI;
#[derive(Debug, Clone, Copy)]
struct CamLoc {
eye: Vec3,
forward: Vec3,
@ -43,34 +45,28 @@ impl Renderer {
}
pub struct SceneParams {
pub spheres: Vec<SphereParams>,
pub camera: SphereParams,
pub target: SphereParams,
spheres: Vec<Sphere>,
camera: CamLoc,
}
impl SceneParams {
pub fn new(n_spheres: u32) -> Self {
let mut rng = rand_pcg::Pcg32::new(42, 0);
let spheres: Vec<_> = {
let distr = anim::distr();
(0..n_spheres).map(|_| distr(&mut rng)).collect()
const R: f32 = 100.;
let sphere = Sphere {
center: vec3(0., 0., -R),
radius: R,
emit_color: vec3(0., 0., 0.),
reflect_color: Vec3::splat(0.3),
glossiness: 0.,
};
let camera = {
let mut p = anim::distr()(&mut rng);
p.amplitudes *= 2.0;
p.frequencies *= 0.1;
p
let spheres = vec![sphere];
let camera = CamLoc {
eye: vec3(-1., -1., 1.),
forward: vec3(1., 1., 0.).normalize(),
right: vec3(1., -1., 0.).normalize(),
};
let target = {
let mut p = spheres[0];
p.phases -= 2. * PI * CAMERA_LAG * p.frequencies;
p
};
Self {
spheres,
camera,
target,
}
Self { spheres, camera }
}
}
@ -100,14 +96,9 @@ impl Renderer {
time: f32,
seed: u32,
) {
let target = scene.target.to_sphere(time).center;
let eye = scene.camera.to_sphere(time).center;
let right = scene.camera.deriv(time);
let forward = target - eye;
let viewport = make_viewport(size.x, size.y);
let location = convert_location(CamLoc { eye, forward, right });
let spheres: Vec<_> = scene.spheres.iter().map(|p| p.to_sphere(time)).collect();
let data = TracerData::new(&device, &self.tracer, &spheres);
let location = convert_location(scene.camera);
let data = TracerData::new(&device, &self.tracer, &scene.spheres);
self.tracer.render(
&mut render_pass.0,
&data,

View File

@ -106,7 +106,7 @@ fn trace_fragment(in: Varying) -> vec3f {
var env: vec3f; // in kilonits
const ILLUMINANCE_LUX = 1e5;
const ANGULAR_DIAMETER_DEG = 0.5; // Sun: 0.5°
const ANGULAR_DIAMETER_DEG = 20.0; // Sun: 0.5°
const PI = 3.141592653589793;