Skip to content

Commit

Permalink
Reduce filter size
Browse files Browse the repository at this point in the history
  • Loading branch information
KYovchevski committed Apr 29, 2024
1 parent 1290d51 commit c6e6d98
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 10 deletions.
6 changes: 3 additions & 3 deletions src/ispc/downsample_ispc.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#[allow(non_camel_case_types,dead_code,non_upper_case_globals,non_snake_case,improper_ctypes)]
pub mod downsample_ispc {
/* automatically generated by rust-bindgen 0.69.4 */
/* automatically generated by rust-bindgen 0.69.2 */

#[repr(C)]
#[derive(Debug, Copy, Clone)]
Expand Down Expand Up @@ -75,12 +75,12 @@ extern "C" {
}
pub const NormalMapFormat_R8g8b8: NormalMapFormat = 0;
pub const NormalMapFormat_R8g8TangentSpaceReconstructedZ: NormalMapFormat = 1;
pub type NormalMapFormat = ::std::os::raw::c_uint;
pub type NormalMapFormat = ::std::os::raw::c_int;
pub const PixelFormat_Rgba8Unorm: PixelFormat = 0;
pub const PixelFormat_Rgb8Unorm: PixelFormat = 1;
pub const PixelFormat_Rgba8Snorm: PixelFormat = 2;
pub const PixelFormat_Rgb8Snorm: PixelFormat = 3;
pub type PixelFormat = ::std::os::raw::c_uint;
pub type PixelFormat = ::std::os::raw::c_int;
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct SourceImage {
Expand Down
Binary file modified src/ispc/downsample_ispcx86_64-pc-windows-msvc.lib
Binary file not shown.
13 changes: 6 additions & 7 deletions src/ispc/kernels/downsampling.ispc
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ inline float<3> sample_normal(const uniform uint8* varying pixel_ptr, uniform No
}
}

// print("%\n", length(normal));

return normal;
}

Expand Down Expand Up @@ -204,19 +202,20 @@ export void resample_with_cached_weights_4(const uniform SourceImage * uniform s
/// scratch_space must be at least src_height * dst->width pixels big
export void downsample_normal_map(const uniform SourceImage * uniform src, uniform DownsampledImage * uniform dst, uniform NormalMapFormat normal_map_format) {
float<2> ratio = { (float)src->width / (float)dst->width, (float)src->height / (float)dst->height };
int<2> floored = { floor(ratio.x), floor(ratio.y) };
foreach_tiled(y = 0 ... dst->height, x = 0 ... dst->width) {

float<2> pixel_center = { (float)x + 0.5f, (float)y + 0.5f };

uint<2> start = { 0, 0 };
uint<2> end = { 0, 0 };
float pixel_weight = 0.0;

{
start.x = max((int)x * ratio.x - floored.x, 0);
start.y = max((int)y * ratio.y - floored.y, 0);
start.x = max((int)floor(x * ratio.x - floor(ratio.x / 2.0f) + 0.5f), 0);
start.y = max((int)floor(y * ratio.y - floor(ratio.y / 2.0f) + 0.5f), 0);

end.x = min((int)x * ratio.x + floored.x, src->width);
end.y = min((int)y * ratio.y + floored.y, src->height);
end.x = min((int)floor(x * ratio.x + ceil(ratio.x / 2.0f) + 0.5f) + 1, src->width);
end.y = min((int)floor(y * ratio.y + ceil(ratio.y / 2.0f) + 0.5f) + 1, src->height);

pixel_weight = (float)((end.x - start.x) * (end.y - start.y));
}
Expand Down

0 comments on commit c6e6d98

Please sign in to comment.