speed up gfx, colored lighting is out for now

This commit is contained in:
asrael 2026-02-05 02:42:58 -06:00
parent 3c3e961995
commit 01e6059dd1
17 changed files with 1055 additions and 250 deletions

View file

@ -1,14 +1,14 @@
use core::ops::{Add, Mul, Sub};
#[repr(C)]
#[derive(Debug, Copy, Clone)]
#[derive(Debug, Copy, Clone, Default)]
pub struct Vec2 {
pub x: f32,
pub y: f32,
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
#[derive(Debug, Copy, Clone, Default)]
pub struct Vec3 {
pub x: f32,
pub y: f32,
@ -16,7 +16,7 @@ pub struct Vec3 {
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
#[derive(Debug, Copy, Clone, Default)]
pub struct Vec4 {
pub x: f32,
pub y: f32,
@ -25,7 +25,7 @@ pub struct Vec4 {
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
#[derive(Debug, Copy, Clone, Default)]
pub struct Mat4 {
pub m: [f32; 16],
}
@ -39,31 +39,40 @@ pub type pxl8_vec4 = Vec4;
#[allow(non_camel_case_types)]
pub type pxl8_mat4 = Mat4;
pub const VEC3_ZERO: Vec3 = Vec3 { x: 0.0, y: 0.0, z: 0.0 };
pub const VEC3_Y: Vec3 = Vec3 { x: 0.0, y: 1.0, z: 0.0 };
impl Vec3 {
pub const ZERO: Vec3 = Vec3 { x: 0.0, y: 0.0, z: 0.0 };
pub const Y: Vec3 = Vec3 { x: 0.0, y: 1.0, z: 0.0 };
pub trait Vec3Ext {
fn new(x: f32, y: f32, z: f32) -> Self;
fn dot(self, rhs: Self) -> f32;
}
impl Vec3Ext for pxl8_vec3 {
fn new(x: f32, y: f32, z: f32) -> Self {
pub fn new(x: f32, y: f32, z: f32) -> Self {
Self { x, y, z }
}
fn dot(self, rhs: Self) -> f32 {
pub fn dot(self, rhs: Self) -> f32 {
self.x * rhs.x + self.y * rhs.y + self.z * rhs.z
}
}
impl Default for pxl8_vec3 {
fn default() -> Self {
VEC3_ZERO
pub fn cross(self, rhs: Self) -> Self {
Self {
x: self.y * rhs.z - self.z * rhs.y,
y: self.z * rhs.x - self.x * rhs.z,
z: self.x * rhs.y - self.y * rhs.x,
}
}
pub fn length(self) -> f32 {
libm::sqrtf(self.dot(self))
}
pub fn normalize(self) -> Self {
let len_sq = self.dot(self);
if len_sq < 1e-12 {
return Self::ZERO;
}
self * (1.0 / libm::sqrtf(len_sq))
}
}
impl Add for pxl8_vec3 {
impl Add for Vec3 {
type Output = Self;
fn add(self, rhs: Self) -> Self {
Self {
@ -74,7 +83,7 @@ impl Add for pxl8_vec3 {
}
}
impl Sub for pxl8_vec3 {
impl Sub for Vec3 {
type Output = Self;
fn sub(self, rhs: Self) -> Self {
Self {
@ -85,7 +94,7 @@ impl Sub for pxl8_vec3 {
}
}
impl Mul<f32> for pxl8_vec3 {
impl Mul<f32> for Vec3 {
type Output = Self;
fn mul(self, rhs: f32) -> Self {
Self {