Start fixes for the gasket example
CI / cargo fmt (push) Successful in 25s
CI / cargo test (push) Successful in 13m26s
CI / cargo test (GPU) (push) Successful in 12m50s

The image is inverted for reasons I don't entirely understand yet
This commit is contained in:
2026-07-04 12:23:57 -04:00
parent d79ff7be21
commit 6a7ce14137
2 changed files with 35 additions and 18 deletions
+10 -5
View File
@@ -5,8 +5,8 @@ use enkou_shaders::camera::entry::main_image_render;
use enkou_shaders::chaos_game::entry::main_chaos_game;
use enkou_shaders::transform::Transform;
use enkou_shaders::variation::Variation;
use glam::{Affine2, UVec2, Vec2, Vec4, uvec2, vec2};
use image::{Rgba, Rgba32FImage};
use glam::{Affine2, UVec2, Vec2, Vec2Swizzles, Vec4, uvec2, vec2};
use image::{Rgba, RgbaImage};
use std::mem;
use std::process::Command;
use tempfile::NamedTempFile;
@@ -65,7 +65,7 @@ pub fn main() -> Result<()> {
let palette = &[Vec4::ONE; 2];
let mut output_points_pixel = Vec::new();
output_points_pixel.resize(ITERATIONS as usize, Vec4::ZERO);
output_points_pixel.resize(IMAGE_DIMENSION.xy().element_product() as usize, Vec4::ZERO);
main_image_render(
&camera,
@@ -74,11 +74,16 @@ pub fn main() -> Result<()> {
&mut output_points_pixel,
);
let mut image = Rgba32FImage::new(IMAGE_DIMENSION.x, IMAGE_DIMENSION.y);
for x in 0..image.dimensions().0 {
let mut image = RgbaImage::new(IMAGE_DIMENSION.x, IMAGE_DIMENSION.y);
for y in 0..image.dimensions().1 {
for x in 0..image.dimensions().0 {
let pixel_index = y * IMAGE_DIMENSION.x + x;
let pixel = output_points_pixel[pixel_index as usize];
let pixel = pixel.to_array().map(|channel| {
let channel = if channel.is_nan() { 0.0 } else { channel };
let channel = channel * u8::MAX as f32;
channel as u8
});
image.put_pixel(x, y, Rgba(pixel.into()));
}
}
+24 -12
View File
@@ -3,7 +3,7 @@
//! Map points from the IFS coordinate system to pixel coordinates. This is a lossy transformation.
use bytemuck::{Pod, Zeroable};
use glam::{Affine2, IVec2, UVec2, Vec2, Vec4, Vec4Swizzles, vec2};
use libm::{floorf, powf};
use libm::{floorf, log10f, powf};
/// Blending modes for mapping IFS color values (which are on a scale `[0, 1]`)
/// to RGBA colors.
@@ -102,7 +102,11 @@ impl Camera {
/// Map a point from IFS coordinates to a pixel index and RGBA value; if the IFS coordinate
/// is outside the viewable range, return [`None`].
pub fn transform_point_to_image(&self, point: Vec4, palette: &[Vec4]) -> Option<(usize, Vec4)> {
pub fn transform_point_to_image_hist(
&self,
point: Vec4,
palette: &[Vec4],
) -> Option<(usize, Vec4)> {
let pixel_coordinates = self.transform_point(point.xy());
if pixel_coordinates.x < 0
|| pixel_coordinates.y < 0
@@ -112,20 +116,29 @@ impl Camera {
return None;
}
let to_pixel_index = self.dimensions.with_y(0);
let to_pixel_index = self.dimensions.with_y(1);
let pixel_index = pixel_coordinates.as_uvec2().dot(to_pixel_index) as usize;
let rgba = self.blend_mode.ifs_to_rgb(point.w, palette);
Some((pixel_index, rgba))
}
/// Map an accumulated RGBA value to the final pixel color value
pub fn transform_image_hist_to_rgba(&self, pixel: Vec4) -> Vec4 {
if pixel.w <= 0.0 {
Vec4::ZERO
} else {
// TODO: Fix the bootleg gamma adjustment
(pixel * log10f(pixel.w) / (pixel.w * self.image_gamma)).clamp(Vec4::ZERO, Vec4::ONE)
}
}
}
#[allow(missing_docs)]
pub mod entry {
use crate::camera::Camera;
use glam::Vec4;
use libm::log10f;
use spirv_std::spirv;
/// Render an output image from a list of IFS coordinates.
@@ -144,17 +157,16 @@ pub mod entry {
#[spirv(storage_buffer, descriptor_set = 1, binding = 0)] image: &mut [Vec4],
) {
for coordinate_index in 0..coordinates_ifs.len() {
camera
.transform_point_to_image(coordinates_ifs[coordinate_index], palette)
.map(|(pixel_index, rgba)| image[pixel_index] += rgba);
if let Some((pixel_index, rgba)) =
camera.transform_point_to_image_hist(coordinates_ifs[coordinate_index], palette)
{
image[pixel_index] += rgba;
}
}
for pixel_index in 0..image.len() {
// TODO: Fix the bootleg gamma adjustment
let pixel_unscaled = image[pixel_index];
let pixel =
pixel_unscaled * log10f(pixel_unscaled.w) / (pixel_unscaled.w * camera.image_gamma);
image[pixel_index] = pixel;
let rgba = camera.transform_image_hist_to_rgba(image[pixel_index]);
image[pixel_index] = rgba;
}
}
}