Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions shaders/rust/base/textoverlay/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
#![cfg_attr(target_arch = "spirv", no_std)]
#![allow(clippy::missing_safety_doc)]

use spirv_std::{spirv, glam::{vec4, Vec2, Vec4}, Image};
use spirv_std::image::SampledImage;
use spirv_std::{
glam::{vec4, Vec2, Vec4},
spirv, Image,
};

// Text overlay vertex shader - simple passthrough with position transformation
#[spirv(vertex)]
Expand All @@ -20,9 +23,11 @@ pub fn main_vs(
#[spirv(fragment)]
pub fn main_fs(
in_uv: Vec2,
#[spirv(descriptor_set = 0, binding = 0)] font_sampler: &SampledImage<Image!(2D, type=f32, sampled)>,
#[spirv(descriptor_set = 0, binding = 0)] font_sampler: &SampledImage<
Image!(2D, type=f32, sampled),
>,
out_frag_color: &mut Vec4,
) {
let color = font_sampler.sample(in_uv).x; // Sample red channel like GLSL .r
*out_frag_color = vec4(color, color, color, 1.0); // Convert to grayscale with full alpha
}
}
11 changes: 8 additions & 3 deletions shaders/rust/base/uioverlay/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
#![cfg_attr(target_arch = "spirv", no_std)]
#![allow(clippy::missing_safety_doc)]

use spirv_std::{spirv, glam::{vec4, Vec2, Vec4}, Image};
use spirv_std::image::SampledImage;
use spirv_std::{
glam::{vec4, Vec2, Vec4},
spirv, Image,
};

// Push constants structure for UI overlay
#[repr(C)]
Expand Down Expand Up @@ -38,9 +41,11 @@ pub fn main_vs(
pub fn main_fs(
in_uv: Vec2,
in_color: Vec4,
#[spirv(descriptor_set = 0, binding = 0)] font_sampler: &SampledImage<Image!(2D, type=f32, sampled)>,
#[spirv(descriptor_set = 0, binding = 0)] font_sampler: &SampledImage<
Image!(2D, type=f32, sampled),
>,
out_frag_color: &mut Vec4,
) {
let tex_color = font_sampler.sample(in_uv);
*out_frag_color = in_color * tex_color;
}
}
8 changes: 2 additions & 6 deletions shaders/rust/bloom/colorpass/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,6 @@ pub fn main_vs(
}

#[spirv(fragment)]
pub fn main_fs(
in_color: Vec3,
_in_uv: Vec2,
out_frag_color: &mut Vec4,
) {
pub fn main_fs(in_color: Vec3, _in_uv: Vec2, out_frag_color: &mut Vec4) {
*out_frag_color = Vec4::new(in_color.x, in_color.y, in_color.z, 1.0);
}
}
46 changes: 30 additions & 16 deletions shaders/rust/bloom/gaussblur/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#![cfg_attr(target_arch = "spirv", no_std)]

use spirv_std::image::SampledImage;
use spirv_std::{
glam::{vec2, UVec2, Vec2, Vec4},
spirv, Image,
};
use spirv_std::image::SampledImage;

#[repr(C)]
#[derive(Copy, Clone)]
Expand All @@ -13,24 +13,22 @@ pub struct UBO {
pub blur_strength: f32,
}


#[spirv(vertex)]
pub fn main_vs(
#[spirv(vertex_index)] vertex_index: i32,
#[spirv(position)] out_position: &mut Vec4,
out_uv: &mut Vec2,
) {
// Generate fullscreen triangle using vertex index
*out_uv = vec2(
((vertex_index << 1) & 2) as f32,
(vertex_index & 2) as f32
);
*out_uv = vec2(((vertex_index << 1) & 2) as f32, (vertex_index & 2) as f32);
*out_position = Vec4::new(out_uv.x * 2.0 - 1.0, out_uv.y * 2.0 - 1.0, 0.0, 1.0);
}

#[spirv(fragment)]
pub fn main_fs(
#[spirv(descriptor_set = 0, binding = 1)] sampler_color: &SampledImage<Image!(2D, type=f32, sampled)>,
#[spirv(descriptor_set = 0, binding = 1)] sampler_color: &SampledImage<
Image!(2D, type=f32, sampled),
>,
#[spirv(uniform, descriptor_set = 0, binding = 0)] ubo: &UBO,
#[spirv(spec_constant(id = 0, default = 0))] blur_direction: u32,
in_uv: Vec2,
Expand All @@ -42,24 +40,40 @@ pub fn main_fs(
// Get texture size for offset calculation (matches original GLSL)
let tex_size: UVec2 = sampler_color.query_size_lod(0);
let tex_offset = vec2(1.0 / tex_size.x as f32, 1.0 / tex_size.y as f32) * ubo.blur_scale;

// Sample current fragment
let mut result = sampler_color.sample(in_uv).truncate() * weight[0];

// Sample surrounding pixels for blur
for i in 1..5i32 {
let offset = i as f32;

if blur_direction == 1 {
// Horizontal blur
result += sampler_color.sample(in_uv + vec2(tex_offset.x * offset, 0.0)).truncate() * weight[i as usize] * ubo.blur_strength;
result += sampler_color.sample(in_uv - vec2(tex_offset.x * offset, 0.0)).truncate() * weight[i as usize] * ubo.blur_strength;
result += sampler_color
.sample(in_uv + vec2(tex_offset.x * offset, 0.0))
.truncate()
* weight[i as usize]
* ubo.blur_strength;
result += sampler_color
.sample(in_uv - vec2(tex_offset.x * offset, 0.0))
.truncate()
* weight[i as usize]
* ubo.blur_strength;
} else {
// Vertical blur
result += sampler_color.sample(in_uv + vec2(0.0, tex_offset.y * offset)).truncate() * weight[i as usize] * ubo.blur_strength;
result += sampler_color.sample(in_uv - vec2(0.0, tex_offset.y * offset)).truncate() * weight[i as usize] * ubo.blur_strength;
result += sampler_color
.sample(in_uv + vec2(0.0, tex_offset.y * offset))
.truncate()
* weight[i as usize]
* ubo.blur_strength;
result += sampler_color
.sample(in_uv - vec2(0.0, tex_offset.y * offset))
.truncate()
* weight[i as usize]
* ubo.blur_strength;
}
}

*out_frag_color = Vec4::new(result.x, result.y, result.z, 1.0);
}
}
12 changes: 6 additions & 6 deletions shaders/rust/bloom/phongpass/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

use spirv_std::{
glam::{Mat3, Mat4, Vec2, Vec3, Vec4},
spirv,
num_traits::Float,
spirv,
};

#[repr(C)]
Expand Down Expand Up @@ -51,8 +51,8 @@ pub fn main_fs(
out_frag_color: &mut Vec4,
) {
let mut ambient = Vec3::ZERO;
// Adjust light calculations for glow color

// Adjust light calculations for glow color
if in_color.x >= 0.9 || in_color.y >= 0.9 || in_color.z >= 0.9 {
ambient = in_color * 0.25;
}
Expand All @@ -63,11 +63,11 @@ pub fn main_fs(
let r = (-l).reflect(n);
let diffuse = n.dot(l).max(0.0) * in_color;
let specular = r.dot(v).max(0.0).powf(8.0) * Vec3::new(0.75, 0.75, 0.75);

*out_frag_color = Vec4::new(
ambient.x + diffuse.x + specular.x,
ambient.y + diffuse.y + specular.y,
ambient.z + diffuse.z + specular.z,
1.0
1.0,
);
}
}
11 changes: 7 additions & 4 deletions shaders/rust/bloom/skybox/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#![cfg_attr(target_arch = "spirv", no_std)]

use spirv_std::image::SampledImage;
use spirv_std::{
glam::{Mat4, Vec3, Vec4},
spirv, Image,
};
use spirv_std::image::SampledImage;

#[repr(C)]
#[derive(Copy, Clone)]
Expand All @@ -22,14 +22,17 @@ pub fn main_vs(
out_uvw: &mut Vec3,
) {
*out_uvw = in_pos;
*out_position = ubo.projection * ubo.view * ubo.model * Vec4::new(in_pos.x, in_pos.y, in_pos.z, 1.0);
*out_position =
ubo.projection * ubo.view * ubo.model * Vec4::new(in_pos.x, in_pos.y, in_pos.z, 1.0);
}

#[spirv(fragment)]
pub fn main_fs(
#[spirv(descriptor_set = 0, binding = 1)] sampler_cube_map: &SampledImage<Image!(cube, type=f32, sampled)>,
#[spirv(descriptor_set = 0, binding = 1)] sampler_cube_map: &SampledImage<
Image!(cube, type=f32, sampled),
>,
in_uvw: Vec3,
out_frag_color: &mut Vec4,
) {
*out_frag_color = sampler_cube_map.sample(in_uvw);
}
}
86 changes: 63 additions & 23 deletions shaders/rust/computecloth/cloth/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#![no_std]

use spirv_std::glam::{IVec2, Mat4, UVec3, Vec2, Vec3, Vec4, Vec4Swizzles};
use spirv_std::num_traits::Float;
use spirv_std::spirv;
use spirv_std::glam::{IVec2, UVec3, Vec2, Vec3, Vec4, Vec4Swizzles, Mat4};
use spirv_std::{Image, Sampler};
use spirv_std::num_traits::Float;

#[repr(C)]
#[derive(Copy, Clone)]
Expand Down Expand Up @@ -60,59 +60,99 @@ pub fn main_cs(
if index >= particle_count_x * particle_count_y {
return;
}

// Initial force from gravity
let mut force = ubo.gravity.xyz() * ubo.particle_mass;

let idx = index as usize;
let pos = particle_in[idx].pos.xyz();
let vel = particle_in[idx].vel.xyz();

// Spring forces from neighboring particles
// left
if id.x > 0 {
force += spring_force(particle_in[idx - 1].pos.xyz(), pos, ubo.rest_dist_h, ubo.spring_stiffness);
force += spring_force(
particle_in[idx - 1].pos.xyz(),
pos,
ubo.rest_dist_h,
ubo.spring_stiffness,
);
}
// right
if id.x < particle_count_x - 1 {
force += spring_force(particle_in[idx + 1].pos.xyz(), pos, ubo.rest_dist_h, ubo.spring_stiffness);
force += spring_force(
particle_in[idx + 1].pos.xyz(),
pos,
ubo.rest_dist_h,
ubo.spring_stiffness,
);
}
// upper
if id.y < particle_count_y - 1 {
force += spring_force(particle_in[idx + particle_count_x as usize].pos.xyz(), pos, ubo.rest_dist_v, ubo.spring_stiffness);
force += spring_force(
particle_in[idx + particle_count_x as usize].pos.xyz(),
pos,
ubo.rest_dist_v,
ubo.spring_stiffness,
);
}
// lower
if id.y > 0 {
force += spring_force(particle_in[idx - particle_count_x as usize].pos.xyz(), pos, ubo.rest_dist_v, ubo.spring_stiffness);
force += spring_force(
particle_in[idx - particle_count_x as usize].pos.xyz(),
pos,
ubo.rest_dist_v,
ubo.spring_stiffness,
);
}
// upper-left
if id.x > 0 && id.y < particle_count_y - 1 {
force += spring_force(particle_in[idx + particle_count_x as usize - 1].pos.xyz(), pos, ubo.rest_dist_d, ubo.spring_stiffness);
force += spring_force(
particle_in[idx + particle_count_x as usize - 1].pos.xyz(),
pos,
ubo.rest_dist_d,
ubo.spring_stiffness,
);
}
// lower-left
if id.x > 0 && id.y > 0 {
force += spring_force(particle_in[idx - particle_count_x as usize - 1].pos.xyz(), pos, ubo.rest_dist_d, ubo.spring_stiffness);
force += spring_force(
particle_in[idx - particle_count_x as usize - 1].pos.xyz(),
pos,
ubo.rest_dist_d,
ubo.spring_stiffness,
);
}
// upper-right
if id.x < particle_count_x - 1 && id.y < particle_count_y - 1 {
force += spring_force(particle_in[idx + particle_count_x as usize + 1].pos.xyz(), pos, ubo.rest_dist_d, ubo.spring_stiffness);
force += spring_force(
particle_in[idx + particle_count_x as usize + 1].pos.xyz(),
pos,
ubo.rest_dist_d,
ubo.spring_stiffness,
);
}
// lower-right
if id.x < particle_count_x - 1 && id.y > 0 {
force += spring_force(particle_in[idx - particle_count_x as usize + 1].pos.xyz(), pos, ubo.rest_dist_d, ubo.spring_stiffness);
force += spring_force(
particle_in[idx - particle_count_x as usize + 1].pos.xyz(),
pos,
ubo.rest_dist_d,
ubo.spring_stiffness,
);
}

// Damping
force += -ubo.damping * vel;

// Integrate
let f = force * (1.0 / ubo.particle_mass);
let new_pos = pos + vel * ubo.delta_t + 0.5 * f * ubo.delta_t * ubo.delta_t;
let new_vel = vel + f * ubo.delta_t;

particle_out[idx].pos = Vec4::new(new_pos.x, new_pos.y, new_pos.z, 1.0);
particle_out[idx].vel = Vec4::new(new_vel.x, new_vel.y, new_vel.z, 0.0);

// Sphere collision
let sphere_dist = new_pos - ubo.sphere_pos.xyz();
if sphere_dist.length() < ubo.sphere_radius + 0.01 {
Expand All @@ -122,11 +162,11 @@ pub fn main_cs(
// Cancel out velocity
particle_out[idx].vel = Vec4::ZERO;
}

// Calculate normals
if push_consts.calculate_normals == 1 {
let mut normal = Vec3::ZERO;

let stride = particle_count_x as usize;
if id.y > 0 {
if id.x > 0 {
Expand Down Expand Up @@ -156,13 +196,13 @@ pub fn main_cs(
normal += a.cross(b) + b.cross(c);
}
}

if normal.length() > 0.0 {
normal = normal.normalize();
}
particle_out[idx].normal = Vec4::new(normal.x, normal.y, normal.z, 0.0);
}

// Copy UV coordinates
particle_out[idx].uv = particle_in[idx].uv;
}
Expand Down Expand Up @@ -221,6 +261,6 @@ pub fn main_fs(
diffuse.x * color.x + specular.x,
diffuse.y * color.y + specular.y,
diffuse.z * color.z + specular.z,
1.0
1.0,
);
}
}
Loading
Loading