From 789be6324a5d33af0ffd6a74a635a77c36088dcb Mon Sep 17 00:00:00 2001 From: Christian Legnitto Date: Sat, 16 Aug 2025 17:40:24 -0700 Subject: [PATCH] Run cargo fmt --- shaders/rust/base/textoverlay/src/lib.rs | 11 ++- shaders/rust/base/uioverlay/src/lib.rs | 11 ++- shaders/rust/bloom/colorpass/src/lib.rs | 8 +- shaders/rust/bloom/gaussblur/src/lib.rs | 46 ++++++---- shaders/rust/bloom/phongpass/src/lib.rs | 12 +-- shaders/rust/bloom/skybox/src/lib.rs | 11 ++- shaders/rust/computecloth/cloth/src/lib.rs | 86 +++++++++++++----- shaders/rust/computecloth/sphere/src/lib.rs | 13 +-- .../rust/computecullandlod/cull/src/lib.rs | 52 ++++++----- .../computecullandlod/indirectdraw/src/lib.rs | 14 +-- .../rust/computeheadless/headless/src/lib.rs | 6 +- shaders/rust/computenbody/particle/src/lib.rs | 43 +++++---- .../particle_calculate/src/lib.rs | 51 ++++++----- .../particle_integrate/src/lib.rs | 41 +++++---- .../rust/computeshader/edgedetect/src/lib.rs | 39 ++++++--- shaders/rust/computeshader/emboss/src/lib.rs | 33 ++++--- shaders/rust/computeshader/sharpen/src/lib.rs | 35 +++++--- shaders/rust/computeshader/texture/src/lib.rs | 11 ++- .../rust/conditionalrender/model/src/lib.rs | 8 +- .../conservativeraster/fullscreen/src/lib.rs | 14 +-- .../conservativeraster/triangle/src/lib.rs | 7 +- .../triangleoverlay/src/lib.rs | 6 +- shaders/rust/debugutils/colorpass/src/lib.rs | 11 ++- .../rust/debugutils/postprocess/src/lib.rs | 39 +++++---- shaders/rust/debugutils/toon/src/lib.rs | 29 ++++--- shaders/rust/deferred/mrt/src/lib.rs | 26 +++--- .../deferredmultisampling/deferred/src/lib.rs | 52 +++++++---- .../rust/deferredmultisampling/mrt/src/lib.rs | 29 ++++--- .../rust/deferredshadows/deferred/src/lib.rs | 40 ++++++--- shaders/rust/deferredshadows/mrt/src/lib.rs | 26 +++--- .../rust/deferredshadows/shadow/src/lib.rs | 8 +- shaders/rust/descriptorbuffer/cube/src/lib.rs | 14 ++- shaders/rust/descriptorindexing/src/lib.rs | 13 ++- shaders/rust/descriptorsets/cube/src/lib.rs | 16 +++- shaders/rust/displacement/base/src/lib.rs | 19 ++-- .../rust/displacement/displacement/src/lib.rs | 34 +++++--- .../rust/distancefieldfonts/bitmap/src/lib.rs | 11 ++- .../rust/distancefieldfonts/sdf/src/lib.rs | 17 ++-- .../rust/dynamicrendering/texture/src/lib.rs | 27 ++++-- .../rust/dynamicuniformbuffer/base/src/lib.rs | 12 +-- shaders/rust/gears/src/lib.rs | 18 ++-- shaders/rust/geometryshader/base/src/lib.rs | 12 +-- shaders/rust/geometryshader/mesh/src/lib.rs | 9 +- .../geometryshader/normaldebug/src/lib.rs | 17 ++-- shaders/rust/gltfloading/mesh/src/lib.rs | 26 ++++-- .../rust/gltfscenerendering/scene/src/lib.rs | 33 +++++-- .../rust/gltfskinning/skinnedmodel/src/lib.rs | 36 +++++--- .../graphicspipelinelibrary/shared/src/lib.rs | 11 ++- .../graphicspipelinelibrary/uber/src/lib.rs | 22 +++-- shaders/rust/hdr/bloom/src/lib.rs | 15 ++-- shaders/rust/hdr/composition/src/lib.rs | 10 +-- shaders/rust/hdr/gbuffer/src/lib.rs | 30 ++++--- shaders/rust/imgui/scene/src/lib.rs | 10 ++- shaders/rust/imgui/ui/src/lib.rs | 12 ++- shaders/rust/indirectdraw/ground/src/lib.rs | 8 +- .../rust/indirectdraw/indirectdraw/src/lib.rs | 36 ++++---- .../rust/indirectdraw/skysphere/src/lib.rs | 10 ++- .../rust/inlineuniformblocks/pbr/src/lib.rs | 11 ++- .../attachmentread/src/lib.rs | 19 ++-- .../attachmentwrite/src/lib.rs | 13 +-- shaders/rust/instancing/instancing/src/lib.rs | 76 ++++++++-------- shaders/rust/instancing/planet/src/lib.rs | 19 ++-- shaders/rust/instancing/starfield/src/lib.rs | 16 +--- shaders/rust/meshshader/meshshader/src/lib.rs | 7 +- shaders/rust/multisampling/mesh/src/lib.rs | 16 ++-- shaders/rust/multithreading/phong/src/lib.rs | 19 ++-- .../rust/multithreading/starsphere/src/lib.rs | 17 ++-- shaders/rust/multiview/multiview/src/lib.rs | 12 ++- shaders/rust/multiview/viewdisplay/src/lib.rs | 18 ++-- .../negativeviewportheight/quad/src/lib.rs | 9 +- shaders/rust/occlusionquery/mesh/src/lib.rs | 19 ++-- .../rust/occlusionquery/occluder/src/lib.rs | 12 +-- shaders/rust/occlusionquery/simple/src/lib.rs | 12 +-- .../rust/parallaxmapping/parallax/src/lib.rs | 65 +++++++++----- .../rust/particlesystem/normalmap/src/lib.rs | 54 +++++++----- .../rust/particlesystem/particle/src/lib.rs | 46 ++++++---- shaders/rust/pbrbasic/pbr/src/lib.rs | 20 ++++- shaders/rust/pbribl/filtercube/src/lib.rs | 2 +- shaders/rust/pbribl/genbrdflut/src/lib.rs | 30 +++---- shaders/rust/pbribl/irradiancecube/src/lib.rs | 18 ++-- shaders/rust/pbribl/pbribl/src/lib.rs | 80 +++++++++-------- .../rust/pbribl/prefilterenvmap/src/lib.rs | 27 +++--- shaders/rust/pbribl/skybox/src/lib.rs | 26 +++--- shaders/rust/pipelines/phong/src/lib.rs | 18 ++-- shaders/rust/pipelines/toon/src/lib.rs | 38 +++++--- shaders/rust/pipelines/wireframe/src/lib.rs | 12 +-- .../rust/pipelinestatistics/scene/src/lib.rs | 27 +++--- shaders/rust/pushconstants/src/lib.rs | 12 +-- shaders/rust/pushdescriptors/cube/src/lib.rs | 16 +++- shaders/rust/radialblur/colorpass/src/lib.rs | 7 +- shaders/rust/radialblur/phongpass/src/lib.rs | 28 +++--- shaders/rust/radialblur/radialblur/src/lib.rs | 20 ++--- shaders/rust/rayquery/scene/src/lib.rs | 19 ++-- shaders/rust/raytracingbasic/src/lib.rs | 21 +++-- .../rust/renderheadless/triangle/src/lib.rs | 12 +-- shaders/rust/screenshot/mesh/src/lib.rs | 13 +-- shaders/rust/shaderobjects/phong/src/lib.rs | 16 ++-- .../rust/shadowmapping/offscreen/src/lib.rs | 6 +- shaders/rust/shadowmapping/quad/src/lib.rs | 7 +- shaders/rust/shadowmapping/scene/src/lib.rs | 32 ++++--- .../debugshadowmap/src/lib.rs | 14 +-- .../shadowmappingcascade/depthpass/src/lib.rs | 5 +- .../shadowmappingcascade/scene/src/lib.rs | 26 +++++- .../cubemapdisplay/src/lib.rs | 42 +++++---- .../shadowmappingomni/offscreen/src/lib.rs | 15 ++-- .../rust/shadowmappingomni/scene/src/lib.rs | 27 +++--- .../specializationconstants/uber/src/lib.rs | 30 +++++-- .../rust/sphericalenvmapping/sem/src/lib.rs | 22 +++-- shaders/rust/ssao/blur/src/lib.rs | 6 +- shaders/rust/ssao/composition/src/lib.rs | 12 +-- shaders/rust/ssao/fullscreen/src/lib.rs | 7 +- shaders/rust/ssao/gbuffer/src/lib.rs | 18 ++-- shaders/rust/ssao/ssao/src/lib.rs | 43 +++++---- shaders/rust/stencilbuffer/outline/src/lib.rs | 10 +-- shaders/rust/stencilbuffer/toon/src/lib.rs | 21 ++--- shaders/rust/subpasses/composition/src/lib.rs | 24 ++--- shaders/rust/subpasses/gbuffer/src/lib.rs | 24 ++--- shaders/rust/subpasses/transparent/src/lib.rs | 24 ++--- .../terraintessellation/skysphere/src/lib.rs | 2 +- .../terraintessellation/terrain/src/lib.rs | 31 +++++-- shaders/rust/tessellation/base/src/lib.rs | 13 +-- .../rust/tessellation/passthrough/src/lib.rs | 28 +++--- .../rust/tessellation/pntriangles/src/lib.rs | 87 ++++++++++--------- shaders/rust/textoverlay/mesh/src/lib.rs | 19 +++- shaders/rust/textoverlay/text/src/lib.rs | 11 ++- shaders/rust/texture/src/lib.rs | 17 ++-- shaders/rust/texture3d/src/lib.rs | 28 +++--- .../rust/texturearray/instancing/src/lib.rs | 13 ++- .../rust/texturecubemap/reflect/src/lib.rs | 23 ++--- shaders/rust/texturecubemap/skybox/src/lib.rs | 9 +- .../texturecubemaparray/reflect/src/lib.rs | 30 ++++--- .../texturecubemaparray/skybox/src/lib.rs | 9 +- .../rust/texturemipmapgen/texture/src/lib.rs | 8 +- shaders/rust/triangle/src/lib.rs | 15 ++-- .../rust/vertexattributes/scene/src/lib.rs | 44 +++++++--- .../rust/viewportarray/multiview/src/lib.rs | 21 +++-- shaders/rust/viewportarray/scene/src/lib.rs | 9 +- shaders/rust/vulkanscene/logo/src/lib.rs | 8 +- shaders/rust/vulkanscene/mesh/src/lib.rs | 12 ++- shaders/rust/vulkanscene/skybox/src/lib.rs | 8 +- 140 files changed, 1869 insertions(+), 1209 deletions(-) diff --git a/shaders/rust/base/textoverlay/src/lib.rs b/shaders/rust/base/textoverlay/src/lib.rs index c290d0e7d..34a2d15c5 100644 --- a/shaders/rust/base/textoverlay/src/lib.rs +++ b/shaders/rust/base/textoverlay/src/lib.rs @@ -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)] @@ -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, + #[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 -} \ No newline at end of file +} diff --git a/shaders/rust/base/uioverlay/src/lib.rs b/shaders/rust/base/uioverlay/src/lib.rs index 1543ae176..6409bf104 100644 --- a/shaders/rust/base/uioverlay/src/lib.rs +++ b/shaders/rust/base/uioverlay/src/lib.rs @@ -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)] @@ -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, + #[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; -} \ No newline at end of file +} diff --git a/shaders/rust/bloom/colorpass/src/lib.rs b/shaders/rust/bloom/colorpass/src/lib.rs index cb17a2975..7f36049ec 100644 --- a/shaders/rust/bloom/colorpass/src/lib.rs +++ b/shaders/rust/bloom/colorpass/src/lib.rs @@ -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); -} \ No newline at end of file +} diff --git a/shaders/rust/bloom/gaussblur/src/lib.rs b/shaders/rust/bloom/gaussblur/src/lib.rs index f52e9ff78..836ef4937 100644 --- a/shaders/rust/bloom/gaussblur/src/lib.rs +++ b/shaders/rust/bloom/gaussblur/src/lib.rs @@ -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)] @@ -13,7 +13,6 @@ pub struct UBO { pub blur_strength: f32, } - #[spirv(vertex)] pub fn main_vs( #[spirv(vertex_index)] vertex_index: i32, @@ -21,16 +20,15 @@ pub fn main_vs( 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, + #[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, @@ -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); -} \ No newline at end of file +} diff --git a/shaders/rust/bloom/phongpass/src/lib.rs b/shaders/rust/bloom/phongpass/src/lib.rs index 2cfda7f03..99f2e4f92 100644 --- a/shaders/rust/bloom/phongpass/src/lib.rs +++ b/shaders/rust/bloom/phongpass/src/lib.rs @@ -2,8 +2,8 @@ use spirv_std::{ glam::{Mat3, Mat4, Vec2, Vec3, Vec4}, - spirv, num_traits::Float, + spirv, }; #[repr(C)] @@ -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; } @@ -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, ); -} \ No newline at end of file +} diff --git a/shaders/rust/bloom/skybox/src/lib.rs b/shaders/rust/bloom/skybox/src/lib.rs index 4b7cb6f50..0ff98a344 100644 --- a/shaders/rust/bloom/skybox/src/lib.rs +++ b/shaders/rust/bloom/skybox/src/lib.rs @@ -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)] @@ -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, + #[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); -} \ No newline at end of file +} diff --git a/shaders/rust/computecloth/cloth/src/lib.rs b/shaders/rust/computecloth/cloth/src/lib.rs index a84ae9c74..22443d95a 100644 --- a/shaders/rust/computecloth/cloth/src/lib.rs +++ b/shaders/rust/computecloth/cloth/src/lib.rs @@ -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)] @@ -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 { @@ -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 { @@ -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; } @@ -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, ); -} \ No newline at end of file +} diff --git a/shaders/rust/computecloth/sphere/src/lib.rs b/shaders/rust/computecloth/sphere/src/lib.rs index 72ff7adc3..d40079c84 100644 --- a/shaders/rust/computecloth/sphere/src/lib.rs +++ b/shaders/rust/computecloth/sphere/src/lib.rs @@ -1,8 +1,8 @@ #![no_std] -use spirv_std::spirv; use spirv_std::glam::{Mat4, Vec3, Vec4, Vec4Swizzles}; use spirv_std::num_traits::Float; +use spirv_std::spirv; #[repr(C)] #[derive(Copy, Clone)] @@ -33,12 +33,7 @@ pub fn main_vs( } #[spirv(fragment)] -pub fn main_fs( - in_normal: Vec3, - in_view_vec: Vec3, - in_light_vec: Vec3, - out_frag_color: &mut Vec4, -) { +pub fn main_fs(in_normal: Vec3, in_view_vec: Vec3, in_light_vec: Vec3, out_frag_color: &mut Vec4) { let color = Vec3::splat(0.5); let n = in_normal.normalize(); let l = in_light_vec.normalize(); @@ -50,6 +45,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, ); -} \ No newline at end of file +} diff --git a/shaders/rust/computecullandlod/cull/src/lib.rs b/shaders/rust/computecullandlod/cull/src/lib.rs index 9e5c939ae..c52e01b10 100644 --- a/shaders/rust/computecullandlod/cull/src/lib.rs +++ b/shaders/rust/computecullandlod/cull/src/lib.rs @@ -1,8 +1,8 @@ #![no_std] -use spirv_std::spirv; -use spirv_std::glam::{UVec3, Vec3, Vec4, Mat4, Vec4Swizzles}; use spirv_std::arch::atomic_i_add; +use spirv_std::glam::{Mat4, UVec3, Vec3, Vec4, Vec4Swizzles}; +use spirv_std::spirv; #[repr(C)] #[derive(Copy, Clone)] @@ -59,37 +59,48 @@ fn frustum_check(pos: Vec4, radius: f32, frustum_planes: &[Vec4; 6]) -> bool { pub fn main_cs( #[spirv(global_invocation_id)] global_id: UVec3, #[spirv(storage_buffer, descriptor_set = 0, binding = 0)] instances: &[InstanceData], - #[spirv(storage_buffer, descriptor_set = 0, binding = 1)] indirect_draws: &mut [IndexedIndirectCommand], + #[spirv(storage_buffer, descriptor_set = 0, binding = 1)] + indirect_draws: &mut [IndexedIndirectCommand], #[spirv(uniform, descriptor_set = 0, binding = 2)] ubo: &UBO, #[spirv(storage_buffer, descriptor_set = 0, binding = 3)] ubo_out: &mut UBOOut, #[spirv(storage_buffer, descriptor_set = 0, binding = 4)] lods: &[LOD], #[spirv(spec_constant(id = 0, default = 5))] max_lod_level: u32, ) { let idx = global_id.x as usize; - + // Bounds check - important! if idx >= instances.len() || idx >= indirect_draws.len() { return; } - - let pos = Vec4::new(instances[idx].pos[0], instances[idx].pos[1], instances[idx].pos[2], 1.0); - + + let pos = Vec4::new( + instances[idx].pos[0], + instances[idx].pos[1], + instances[idx].pos[2], + 1.0, + ); + // Check if object is within current viewing frustum if frustum_check(pos, 1.0, &ubo.frustum_planes) { indirect_draws[idx].instance_count = 1; - + // Increase number of indirect draw counts unsafe { - atomic_i_add::( - &mut ubo_out.draw_count, - 1 - ); + atomic_i_add::< + i32, + { spirv_std::memory::Scope::Device as u32 }, + { spirv_std::memory::Semantics::NONE.bits() }, + >(&mut ubo_out.draw_count, 1); } - + // Select appropriate LOD level based on distance to camera let mut lod_level = max_lod_level; let camera_pos_vec3 = ubo.camera_pos.xyz(); - let instance_pos = Vec3::new(instances[idx].pos[0], instances[idx].pos[1], instances[idx].pos[2]); + let instance_pos = Vec3::new( + instances[idx].pos[0], + instances[idx].pos[1], + instances[idx].pos[2], + ); let dist = instance_pos.distance(camera_pos_vec3); for i in 0..max_lod_level { if dist < lods[i as usize].distance { @@ -99,15 +110,16 @@ pub fn main_cs( } indirect_draws[idx].first_index = lods[lod_level as usize].first_index; indirect_draws[idx].index_count = lods[lod_level as usize].index_count; - + // Update stats unsafe { - atomic_i_add::( - &mut ubo_out.lod_count[lod_level as usize], - 1 - ); + atomic_i_add::< + i32, + { spirv_std::memory::Scope::Device as u32 }, + { spirv_std::memory::Semantics::NONE.bits() }, + >(&mut ubo_out.lod_count[lod_level as usize], 1); } } else { indirect_draws[idx].instance_count = 0; } -} \ No newline at end of file +} diff --git a/shaders/rust/computecullandlod/indirectdraw/src/lib.rs b/shaders/rust/computecullandlod/indirectdraw/src/lib.rs index f245610af..49b0a58e5 100644 --- a/shaders/rust/computecullandlod/indirectdraw/src/lib.rs +++ b/shaders/rust/computecullandlod/indirectdraw/src/lib.rs @@ -1,7 +1,7 @@ #![no_std] +use spirv_std::glam::{Mat4, Vec3, Vec4, Vec4Swizzles}; use spirv_std::spirv; -use spirv_std::glam::{Vec3, Vec4, Mat4, Vec4Swizzles}; #[repr(C)] #[derive(Copy, Clone)] @@ -27,16 +27,16 @@ pub fn main_vs( ) { *out_color = in_color; *out_normal = in_normal; - + let pos = Vec4::new( (in_pos.x * instance_scale) + instance_pos.x, (in_pos.y * instance_scale) + instance_pos.y, (in_pos.z * instance_scale) + instance_pos.z, - 1.0 + 1.0, ); - + *out_position = ubo.projection * ubo.modelview * pos; - + let l_pos = Vec4::new(0.0, 10.0, 50.0, 1.0); *out_light_vec = l_pos.xyz() - pos.xyz(); *out_view_vec = -pos.xyz(); @@ -58,6 +58,6 @@ pub fn main_fs( (ambient.x + diffuse.x) * in_color.x, (ambient.y + diffuse.y) * in_color.y, (ambient.z + diffuse.z) * in_color.z, - 1.0 + 1.0, ); -} \ No newline at end of file +} diff --git a/shaders/rust/computeheadless/headless/src/lib.rs b/shaders/rust/computeheadless/headless/src/lib.rs index 8fac1088a..0aee1b2f9 100644 --- a/shaders/rust/computeheadless/headless/src/lib.rs +++ b/shaders/rust/computeheadless/headless/src/lib.rs @@ -1,7 +1,7 @@ #![cfg_attr(target_arch = "spirv", no_std)] #![allow(clippy::missing_safety_doc)] -use spirv_std::{spirv, glam::UVec3}; +use spirv_std::{glam::UVec3, spirv}; fn fibonacci(n: u32) -> u32 { if n <= 1 { @@ -27,6 +27,6 @@ pub fn main_cs( if index >= buffer_elements { return; } - + values[index as usize] = fibonacci(values[index as usize]); -} \ No newline at end of file +} diff --git a/shaders/rust/computenbody/particle/src/lib.rs b/shaders/rust/computenbody/particle/src/lib.rs index 54e44a2a1..0fe125fd3 100644 --- a/shaders/rust/computenbody/particle/src/lib.rs +++ b/shaders/rust/computenbody/particle/src/lib.rs @@ -1,10 +1,10 @@ #![cfg_attr(target_arch = "spirv", no_std)] +use spirv_std::image::SampledImage; use spirv_std::{ glam::{vec2, vec4, Mat4, Vec2, Vec4, Vec4Swizzles}, spirv, Image, }; -use spirv_std::image::SampledImage; #[repr(C)] #[derive(Copy, Clone)] @@ -16,44 +16,55 @@ pub struct UBO { #[spirv(vertex)] pub fn main_vs( - in_pos: Vec4, // particle position + mass - in_vel: Vec4, // particle velocity + gradient pos + in_pos: Vec4, // particle position + mass + in_vel: Vec4, // particle velocity + gradient pos #[spirv(uniform, descriptor_set = 0, binding = 2)] ubo: &UBO, #[spirv(position)] out_position: &mut Vec4, #[spirv(point_size)] out_point_size: &mut f32, out_gradient_pos: &mut f32, ) { - // Point size influenced by mass (stored in inPos.w) let sprite_size = 0.005 * in_pos.w; - + // Transform to eye space let eye_pos = ubo.modelview * vec4(in_pos.x, in_pos.y, in_pos.z, 1.0); - + // Calculate point size in screen space - let projected_corner = ubo.projection * vec4(0.5 * sprite_size, 0.5 * sprite_size, eye_pos.z, eye_pos.w); + let projected_corner = + ubo.projection * vec4(0.5 * sprite_size, 0.5 * sprite_size, eye_pos.z, eye_pos.w); *out_point_size = (ubo.screendim.x * projected_corner.x / projected_corner.w).clamp(1.0, 128.0); - + // Final position *out_position = ubo.projection * eye_pos; - + // Pass gradient position for coloring *out_gradient_pos = in_vel.w; } #[spirv(fragment)] pub fn main_fs( - #[spirv(descriptor_set = 0, binding = 0)] sampler_color_map: &SampledImage, - #[spirv(descriptor_set = 0, binding = 1)] sampler_gradient_ramp: &SampledImage, + #[spirv(descriptor_set = 0, binding = 0)] sampler_color_map: &SampledImage< + Image!(2D, type=f32, sampled), + >, + #[spirv(descriptor_set = 0, binding = 1)] sampler_gradient_ramp: &SampledImage< + Image!(2D, type=f32, sampled), + >, #[spirv(point_coord)] point_coord: Vec2, in_gradient_pos: f32, out_frag_color: &mut Vec4, ) { // Sample gradient color based on particle's gradient position - let color = sampler_gradient_ramp.sample(vec2(in_gradient_pos, 0.0)).xyz(); - + let color = sampler_gradient_ramp + .sample(vec2(in_gradient_pos, 0.0)) + .xyz(); + // Sample particle texture and modulate with gradient color let particle_color = sampler_color_map.sample(point_coord).xyz(); - - *out_frag_color = vec4(particle_color.x * color.x, particle_color.y * color.y, particle_color.z * color.z, 1.0); -} \ No newline at end of file + + *out_frag_color = vec4( + particle_color.x * color.x, + particle_color.y * color.y, + particle_color.z * color.z, + 1.0, + ); +} diff --git a/shaders/rust/computenbody/particle_calculate/src/lib.rs b/shaders/rust/computenbody/particle_calculate/src/lib.rs index d493d449d..0c44ba46e 100644 --- a/shaders/rust/computenbody/particle_calculate/src/lib.rs +++ b/shaders/rust/computenbody/particle_calculate/src/lib.rs @@ -1,17 +1,17 @@ #![cfg_attr(target_arch = "spirv", no_std)] use spirv_std::{ - glam::{vec3, vec4, Vec4, Vec4Swizzles}, - spirv, arch::workgroup_memory_barrier_with_group_sync, + glam::{vec3, vec4, Vec4, Vec4Swizzles}, num_traits::Float, + spirv, }; #[repr(C)] #[derive(Copy, Clone)] pub struct Particle { - pub pos: [f32; 4], // xyz = position, w = mass - pub vel: [f32; 4], // xyz = velocity, w = gradient texture position + pub pos: [f32; 4], // xyz = position, w = mass + pub vel: [f32; 4], // xyz = velocity, w = gradient texture position } #[repr(C)] @@ -36,15 +36,25 @@ pub fn main_cs( ) { let index = global_id.x as usize; let local_index = local_id.x as usize; - + if index >= ubo.particle_count as usize { return; } - - let position = vec4(particles[index].pos[0], particles[index].pos[1], particles[index].pos[2], particles[index].pos[3]); - let mut velocity = vec4(particles[index].vel[0], particles[index].vel[1], particles[index].vel[2], particles[index].vel[3]); + + let position = vec4( + particles[index].pos[0], + particles[index].pos[1], + particles[index].pos[2], + particles[index].pos[3], + ); + let mut velocity = vec4( + particles[index].vel[0], + particles[index].vel[1], + particles[index].vel[2], + particles[index].vel[3], + ); let mut acceleration = vec3(0.0, 0.0, 0.0); - + // Process particles in chunks of SHARED_DATA_SIZE let mut i = 0u32; while i < ubo.particle_count { @@ -55,46 +65,47 @@ pub fn main_cs( particles[particle_idx].pos[0], particles[particle_idx].pos[1], particles[particle_idx].pos[2], - particles[particle_idx].pos[3] + particles[particle_idx].pos[3], ); } else { shared_data[local_index] = vec4(0.0, 0.0, 0.0, 0.0); } - + // Ensure all threads have loaded their data unsafe { workgroup_memory_barrier_with_group_sync(); } - + // Calculate forces from particles in shared memory - for j in 0..256 { // gl_WorkGroupSize.x = 256 + for j in 0..256 { + // gl_WorkGroupSize.x = 256 let other = shared_data[j]; let len = other.xyz() - position.xyz(); let distance_sq = len.dot(len) + ubo.soften; acceleration += ubo.gravity * len * other.w / distance_sq.powf(ubo.power * 0.5); } - + // Synchronize before next iteration unsafe { workgroup_memory_barrier_with_group_sync(); } - + i += SHARED_DATA_SIZE as u32; } - + // Update velocity with acceleration velocity = vec4( velocity.x + acceleration.x * ubo.delta_t, velocity.y + acceleration.y * ubo.delta_t, velocity.z + acceleration.z * ubo.delta_t, - velocity.w + velocity.w, ); - + // Update gradient texture position for visual effects velocity.w += 0.1 * ubo.delta_t; if velocity.w > 1.0 { velocity.w -= 1.0; } - + particles[index].vel = [velocity.x, velocity.y, velocity.z, velocity.w]; -} \ No newline at end of file +} diff --git a/shaders/rust/computenbody/particle_integrate/src/lib.rs b/shaders/rust/computenbody/particle_integrate/src/lib.rs index 7152fdcec..fa3d0da0e 100644 --- a/shaders/rust/computenbody/particle_integrate/src/lib.rs +++ b/shaders/rust/computenbody/particle_integrate/src/lib.rs @@ -8,8 +8,8 @@ use spirv_std::{ #[repr(C)] #[derive(Copy, Clone)] pub struct Particle { - pub pos: [f32; 4], // xyz = position, w = mass - pub vel: [f32; 4], // xyz = velocity, w = gradient texture position + pub pos: [f32; 4], // xyz = position, w = mass + pub vel: [f32; 4], // xyz = velocity, w = gradient texture position } #[repr(C)] @@ -26,21 +26,32 @@ pub fn main_cs( #[spirv(uniform, descriptor_set = 0, binding = 1)] ubo: &UBO, ) { let index = global_id.x as usize; - + if index >= ubo.particle_count as usize { return; } - - let mut position = vec4(particles[index].pos[0], particles[index].pos[1], particles[index].pos[2], particles[index].pos[3]); - let velocity = vec4(particles[index].vel[0], particles[index].vel[1], particles[index].vel[2], particles[index].vel[3]); - - // Euler integration: position += velocity * deltaTime - position = position + vec4( - velocity.x * ubo.delta_t, - velocity.y * ubo.delta_t, - velocity.z * ubo.delta_t, - 0.0 + + let mut position = vec4( + particles[index].pos[0], + particles[index].pos[1], + particles[index].pos[2], + particles[index].pos[3], + ); + let velocity = vec4( + particles[index].vel[0], + particles[index].vel[1], + particles[index].vel[2], + particles[index].vel[3], ); - + + // Euler integration: position += velocity * deltaTime + position = position + + vec4( + velocity.x * ubo.delta_t, + velocity.y * ubo.delta_t, + velocity.z * ubo.delta_t, + 0.0, + ); + particles[index].pos = [position.x, position.y, position.z, position.w]; -} \ No newline at end of file +} diff --git a/shaders/rust/computeshader/edgedetect/src/lib.rs b/shaders/rust/computeshader/edgedetect/src/lib.rs index 43ef8db1b..a4b695c00 100644 --- a/shaders/rust/computeshader/edgedetect/src/lib.rs +++ b/shaders/rust/computeshader/edgedetect/src/lib.rs @@ -1,7 +1,10 @@ #![cfg_attr(target_arch = "spirv", no_std)] #![allow(clippy::missing_safety_doc)] -use spirv_std::{spirv, glam::{vec4, IVec2, UVec3, Vec4, Vec3Swizzles}, Image}; +use spirv_std::{ + glam::{vec4, IVec2, UVec3, Vec3Swizzles, Vec4}, + spirv, Image, +}; fn conv(kernel: &[f32; 9], data: &[f32; 9], denom: f32, offset: f32) -> f32 { let mut res = 0.0; @@ -14,13 +17,21 @@ fn conv(kernel: &[f32; 9], data: &[f32; 9], denom: f32, offset: f32) -> f32 { #[spirv(compute(threads(16, 16)))] pub fn main_cs( #[spirv(global_invocation_id)] global_id: UVec3, - #[spirv(descriptor_set = 0, binding = 0)] input_image: &Image!(2D, format=rgba8, sampled=false), - #[spirv(descriptor_set = 0, binding = 1)] result_image: &Image!(2D, format=rgba8, sampled=false), + #[spirv(descriptor_set = 0, binding = 0)] input_image: &Image!( + 2D, + format = rgba8, + sampled = false + ), + #[spirv(descriptor_set = 0, binding = 1)] result_image: &Image!( + 2D, + format = rgba8, + sampled = false + ), ) { // Fetch neighbouring texels let mut avg = [0.0; 9]; let mut n = 0; - + for i in -1..=1 { for j in -1..=1 { let coord = IVec2::new((global_id.x as i32) + i, (global_id.y as i32) + j); @@ -29,18 +40,24 @@ pub fn main_cs( n += 1; } } - + // Edge detection kernel let kernel = [ - -1.0/8.0, -1.0/8.0, -1.0/8.0, - -1.0/8.0, 1.0, -1.0/8.0, - -1.0/8.0, -1.0/8.0, -1.0/8.0, + -1.0 / 8.0, + -1.0 / 8.0, + -1.0 / 8.0, + -1.0 / 8.0, + 1.0, + -1.0 / 8.0, + -1.0 / 8.0, + -1.0 / 8.0, + -1.0 / 8.0, ]; - + let gray = conv(&kernel, &avg, 0.1, 0.0); let res = vec4(gray, gray, gray, 1.0); - + unsafe { result_image.write(IVec2::new(global_id.x as i32, global_id.y as i32), res); } -} \ No newline at end of file +} diff --git a/shaders/rust/computeshader/emboss/src/lib.rs b/shaders/rust/computeshader/emboss/src/lib.rs index 3a522b53c..c33d4f78f 100644 --- a/shaders/rust/computeshader/emboss/src/lib.rs +++ b/shaders/rust/computeshader/emboss/src/lib.rs @@ -1,7 +1,10 @@ #![cfg_attr(target_arch = "spirv", no_std)] #![allow(clippy::missing_safety_doc)] -use spirv_std::{spirv, glam::{vec4, IVec2, UVec3, Vec4}, Image}; +use spirv_std::{ + glam::{vec4, IVec2, UVec3, Vec4}, + spirv, Image, +}; fn conv(kernel: &[f32; 9], data: &[f32; 9], denom: f32, offset: f32) -> f32 { let mut res = 0.0; @@ -14,13 +17,21 @@ fn conv(kernel: &[f32; 9], data: &[f32; 9], denom: f32, offset: f32) -> f32 { #[spirv(compute(threads(16, 16)))] pub fn main_cs( #[spirv(global_invocation_id)] global_id: UVec3, - #[spirv(descriptor_set = 0, binding = 0)] input_image: &Image!(2D, format=rgba8, sampled=false), - #[spirv(descriptor_set = 0, binding = 1)] result_image: &Image!(2D, format=rgba8, sampled=false), + #[spirv(descriptor_set = 0, binding = 0)] input_image: &Image!( + 2D, + format = rgba8, + sampled = false + ), + #[spirv(descriptor_set = 0, binding = 1)] result_image: &Image!( + 2D, + format = rgba8, + sampled = false + ), ) { // Fetch neighbouring texels let mut avg = [0.0; 9]; let mut n = 0; - + for i in -1..=1 { for j in -1..=1 { let coord = IVec2::new((global_id.x as i32) + i, (global_id.y as i32) + j); @@ -29,18 +40,14 @@ pub fn main_cs( n += 1; } } - + // Emboss kernel - let kernel = [ - -1.0, 0.0, 0.0, - 0.0, -1.0, 0.0, - 0.0, 0.0, 2.0, - ]; - + let kernel = [-1.0, 0.0, 0.0, 0.0, -1.0, 0.0, 0.0, 0.0, 2.0]; + let gray = conv(&kernel, &avg, 1.0, 0.50); let res = vec4(gray, gray, gray, 1.0); - + unsafe { result_image.write(IVec2::new(global_id.x as i32, global_id.y as i32), res); } -} \ No newline at end of file +} diff --git a/shaders/rust/computeshader/sharpen/src/lib.rs b/shaders/rust/computeshader/sharpen/src/lib.rs index 4675d082a..e735ef221 100644 --- a/shaders/rust/computeshader/sharpen/src/lib.rs +++ b/shaders/rust/computeshader/sharpen/src/lib.rs @@ -1,7 +1,10 @@ #![cfg_attr(target_arch = "spirv", no_std)] #![allow(clippy::missing_safety_doc)] -use spirv_std::{spirv, glam::{vec4, IVec2, UVec3, Vec4}, Image}; +use spirv_std::{ + glam::{vec4, IVec2, UVec3, Vec4}, + spirv, Image, +}; fn conv(kernel: &[f32; 9], data: &[f32; 9], denom: f32, offset: f32) -> f32 { let mut res = 0.0; @@ -14,15 +17,23 @@ fn conv(kernel: &[f32; 9], data: &[f32; 9], denom: f32, offset: f32) -> f32 { #[spirv(compute(threads(16, 16)))] pub fn main_cs( #[spirv(global_invocation_id)] global_id: UVec3, - #[spirv(descriptor_set = 0, binding = 0)] input_image: &Image!(2D, format=rgba8, sampled=false), - #[spirv(descriptor_set = 0, binding = 1)] result_image: &Image!(2D, format=rgba8, sampled=false), + #[spirv(descriptor_set = 0, binding = 0)] input_image: &Image!( + 2D, + format = rgba8, + sampled = false + ), + #[spirv(descriptor_set = 0, binding = 1)] result_image: &Image!( + 2D, + format = rgba8, + sampled = false + ), ) { // Fetch neighbouring texels let mut r = [0.0; 9]; let mut g = [0.0; 9]; let mut b = [0.0; 9]; let mut n = 0; - + for i in -1..=1 { for j in -1..=1 { let coord = IVec2::new((global_id.x as i32) + i, (global_id.y as i32) + j); @@ -33,22 +44,18 @@ pub fn main_cs( n += 1; } } - + // Sharpen kernel - let kernel = [ - -1.0, -1.0, -1.0, - -1.0, 9.0, -1.0, - -1.0, -1.0, -1.0, - ]; - + let kernel = [-1.0, -1.0, -1.0, -1.0, 9.0, -1.0, -1.0, -1.0, -1.0]; + let res = vec4( conv(&kernel, &r, 1.0, 0.0), conv(&kernel, &g, 1.0, 0.0), conv(&kernel, &b, 1.0, 0.0), - 1.0 + 1.0, ); - + unsafe { result_image.write(IVec2::new(global_id.x as i32, global_id.y as i32), res); } -} \ No newline at end of file +} diff --git a/shaders/rust/computeshader/texture/src/lib.rs b/shaders/rust/computeshader/texture/src/lib.rs index b7e7dbf4d..d4795508a 100644 --- a/shaders/rust/computeshader/texture/src/lib.rs +++ b/shaders/rust/computeshader/texture/src/lib.rs @@ -1,8 +1,11 @@ #![cfg_attr(target_arch = "spirv", no_std)] #![allow(clippy::missing_safety_doc)] -use spirv_std::{spirv, glam::{vec4, Mat4, Vec2, Vec3, Vec4}, Image}; use spirv_std::image::SampledImage; +use spirv_std::{ + glam::{vec4, Mat4, Vec2, Vec3, Vec4}, + spirv, Image, +}; #[repr(C)] #[derive(Copy, Clone)] @@ -26,8 +29,10 @@ pub fn main_vs( #[spirv(fragment)] pub fn main_fs( in_uv: Vec2, - #[spirv(descriptor_set = 0, binding = 1)] sampler_color: &SampledImage, + #[spirv(descriptor_set = 0, binding = 1)] sampler_color: &SampledImage< + Image!(2D, type=f32, sampled), + >, out_frag_color: &mut Vec4, ) { *out_frag_color = sampler_color.sample(in_uv); -} \ No newline at end of file +} diff --git a/shaders/rust/conditionalrender/model/src/lib.rs b/shaders/rust/conditionalrender/model/src/lib.rs index 0145a3b66..d6746bc5d 100644 --- a/shaders/rust/conditionalrender/model/src/lib.rs +++ b/shaders/rust/conditionalrender/model/src/lib.rs @@ -1,7 +1,11 @@ #![cfg_attr(target_arch = "spirv", no_std)] #![allow(clippy::missing_safety_doc)] -use spirv_std::{spirv, glam::{vec3, vec4, Mat3, Mat4, Vec3, Vec4}, num_traits::Float}; +use spirv_std::{ + glam::{vec3, vec4, Mat3, Mat4, Vec3, Vec4}, + num_traits::Float, + spirv, +}; #[repr(C)] #[derive(Copy, Clone)] @@ -68,4 +72,4 @@ pub fn main_fs( let specular = r.dot(v).max(0.0).powf(16.0) * vec3(0.75, 0.75, 0.75); let final_color = (ambient + diffuse) * in_color + specular; *out_frag_color = vec4(final_color.x, final_color.y, final_color.z, 1.0); -} \ No newline at end of file +} diff --git a/shaders/rust/conservativeraster/fullscreen/src/lib.rs b/shaders/rust/conservativeraster/fullscreen/src/lib.rs index c7618c649..52ccd8346 100644 --- a/shaders/rust/conservativeraster/fullscreen/src/lib.rs +++ b/shaders/rust/conservativeraster/fullscreen/src/lib.rs @@ -10,16 +10,8 @@ pub fn main_vs( #[spirv(position)] out_position: &mut Vec4, out_uv: &mut Vec2, ) { - *out_uv = Vec2::new( - ((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, - ); + *out_uv = Vec2::new(((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)] @@ -30,4 +22,4 @@ pub fn main_fs( out_frag_color: &mut Vec4, ) { *out_frag_color = sampler_color.sample(*sampler, in_uv); -} \ No newline at end of file +} diff --git a/shaders/rust/conservativeraster/triangle/src/lib.rs b/shaders/rust/conservativeraster/triangle/src/lib.rs index 0a7e2adf2..f77a91226 100644 --- a/shaders/rust/conservativeraster/triangle/src/lib.rs +++ b/shaders/rust/conservativeraster/triangle/src/lib.rs @@ -23,9 +23,6 @@ pub fn main_vs( } #[spirv(fragment)] -pub fn main_fs( - in_color: Vec3, - out_frag_color: &mut Vec4, -) { +pub fn main_fs(in_color: Vec3, out_frag_color: &mut Vec4) { *out_frag_color = Vec4::new(in_color.x, in_color.y, in_color.z, 1.0); -} \ No newline at end of file +} diff --git a/shaders/rust/conservativeraster/triangleoverlay/src/lib.rs b/shaders/rust/conservativeraster/triangleoverlay/src/lib.rs index 7e16020aa..5c51464a2 100644 --- a/shaders/rust/conservativeraster/triangleoverlay/src/lib.rs +++ b/shaders/rust/conservativeraster/triangleoverlay/src/lib.rs @@ -4,8 +4,6 @@ use spirv_std::glam::Vec4; use spirv_std::spirv; #[spirv(fragment)] -pub fn main_fs( - out_frag_color: &mut Vec4, -) { +pub fn main_fs(out_frag_color: &mut Vec4) { *out_frag_color = Vec4::new(1.0, 1.0, 1.0, 1.0); -} \ No newline at end of file +} diff --git a/shaders/rust/debugutils/colorpass/src/lib.rs b/shaders/rust/debugutils/colorpass/src/lib.rs index 9139db2fe..59c8c1454 100644 --- a/shaders/rust/debugutils/colorpass/src/lib.rs +++ b/shaders/rust/debugutils/colorpass/src/lib.rs @@ -1,7 +1,10 @@ #![cfg_attr(target_arch = "spirv", no_std)] #![allow(clippy::missing_safety_doc)] -use spirv_std::{spirv, glam::{vec4, Mat4, Vec2, Vec3, Vec4}}; +use spirv_std::{ + glam::{vec4, Mat4, Vec2, Vec3, Vec4}, + spirv, +}; #[repr(C)] #[derive(Copy, Clone)] @@ -10,7 +13,6 @@ pub struct Ubo { pub model: Mat4, } - #[spirv(vertex)] pub fn main_vs( in_pos: Vec4, @@ -26,9 +28,6 @@ pub fn main_vs( } #[spirv(fragment)] -pub fn main_fs( - in_color: Vec3, - out_frag_color: &mut Vec4, -) { +pub fn main_fs(in_color: Vec3, out_frag_color: &mut Vec4) { *out_frag_color = vec4(in_color.x, in_color.y, in_color.z, 1.0); } diff --git a/shaders/rust/debugutils/postprocess/src/lib.rs b/shaders/rust/debugutils/postprocess/src/lib.rs index 463e1b24c..e4d7f474d 100644 --- a/shaders/rust/debugutils/postprocess/src/lib.rs +++ b/shaders/rust/debugutils/postprocess/src/lib.rs @@ -1,7 +1,11 @@ #![cfg_attr(target_arch = "spirv", no_std)] #![allow(clippy::missing_safety_doc)] -use spirv_std::{spirv, glam::{vec2, vec4, Vec2, Vec4}, Image, image::SampledImage}; +use spirv_std::{ + glam::{vec2, vec4, Vec2, Vec4}, + image::SampledImage, + spirv, Image, +}; #[spirv(vertex)] pub fn main_vs( @@ -9,22 +13,16 @@ pub fn main_vs( #[spirv(position)] out_position: &mut Vec4, out_uv: &mut Vec2, ) { - *out_uv = vec2( - ((vert_idx << 1) & 2) as f32, - (vert_idx & 2) as f32, - ); - *out_position = vec4( - out_uv.x * 2.0 - 1.0, - out_uv.y * 2.0 - 1.0, - 0.0, - 1.0, - ); + *out_uv = vec2(((vert_idx << 1) & 2) as f32, (vert_idx & 2) as f32); + *out_position = vec4(out_uv.x * 2.0 - 1.0, out_uv.y * 2.0 - 1.0, 0.0, 1.0); } #[spirv(fragment)] pub fn main_fs( in_uv: Vec2, - #[spirv(descriptor_set = 0, binding = 1)] sampler_color: &SampledImage, + #[spirv(descriptor_set = 0, binding = 1)] sampler_color: &SampledImage< + Image!(2D, type=f32, sampled), + >, out_frag_color: &mut Vec4, ) { // Single pass gauss blur @@ -50,9 +48,16 @@ pub fn main_fs( let col7: Vec4 = sampler_color.sample(tc7); let col8: Vec4 = sampler_color.sample(tc8); - let sum = (1.0 * col0 + 2.0 * col1 + 1.0 * col2 + - 2.0 * col3 + 4.0 * col4 + 2.0 * col5 + - 1.0 * col6 + 2.0 * col7 + 1.0 * col8) / 16.0; - + let sum = (1.0 * col0 + + 2.0 * col1 + + 1.0 * col2 + + 2.0 * col3 + + 4.0 * col4 + + 2.0 * col5 + + 1.0 * col6 + + 2.0 * col7 + + 1.0 * col8) + / 16.0; + *out_frag_color = vec4(sum.x, sum.y, sum.z, 1.0); -} \ No newline at end of file +} diff --git a/shaders/rust/debugutils/toon/src/lib.rs b/shaders/rust/debugutils/toon/src/lib.rs index a94791987..99af89973 100644 --- a/shaders/rust/debugutils/toon/src/lib.rs +++ b/shaders/rust/debugutils/toon/src/lib.rs @@ -1,7 +1,11 @@ #![cfg_attr(target_arch = "spirv", no_std)] #![allow(clippy::missing_safety_doc)] -use spirv_std::{spirv, glam::{vec3, vec4, Mat3, Mat4, Vec2, Vec3, Vec4}, num_traits::Float}; +use spirv_std::{ + glam::{vec3, vec4, Mat3, Mat4, Vec2, Vec3, Vec4}, + num_traits::Float, + spirv, +}; #[repr(C)] #[derive(Copy, Clone)] @@ -28,10 +32,11 @@ pub fn main_vs( *out_color = in_color; *out_uv = in_uv; *out_position = ubo.projection * ubo.model * vec4(in_pos.x, in_pos.y, in_pos.z, 1.0); - + let pos = ubo.model * vec4(in_pos.x, in_pos.y, in_pos.z, 1.0); *out_normal = Mat3::from_mat4(ubo.model) * in_normal; - let l_pos = Mat3::from_mat4(ubo.model) * vec3(ubo.light_pos.x, ubo.light_pos.y, ubo.light_pos.z); + let l_pos = + Mat3::from_mat4(ubo.model) * vec3(ubo.light_pos.x, ubo.light_pos.y, ubo.light_pos.z); *out_light_vec = l_pos - vec3(pos.x, pos.y, pos.z); *out_view_vec = -vec3(pos.x, pos.y, pos.z); } @@ -49,7 +54,7 @@ pub fn main_fs( // Desaturate color let gray = vec3(0.2126, 0.7152, 0.0722).dot(in_color); let color = in_color.lerp(vec3(gray, gray, gray), 0.65); - + // High ambient colors because mesh materials are pretty dark let ambient = color * 1.0; let n = in_normal.normalize(); @@ -58,11 +63,13 @@ pub fn main_fs( let r = (-l).reflect(n); let diffuse = n.dot(l).max(0.0) * color; let specular = r.dot(v).max(0.0).powf(16.0) * vec3(0.75, 0.75, 0.75); - *out_frag_color = vec4(ambient.x + diffuse.x * 1.75 + specular.x, - ambient.y + diffuse.y * 1.75 + specular.y, - ambient.z + diffuse.z * 1.75 + specular.z, - 1.0); - + *out_frag_color = vec4( + ambient.x + diffuse.x * 1.75 + specular.x, + ambient.y + diffuse.y * 1.75 + specular.y, + ambient.z + diffuse.z * 1.75 + specular.z, + 1.0, + ); + let intensity = n.dot(l); let mut shade = 1.0; if intensity < 0.5 { @@ -77,8 +84,8 @@ pub fn main_fs( if intensity < 0.1 { shade = 0.25; } - + out_frag_color.x = in_color.x * 3.0 * shade; out_frag_color.y = in_color.y * 3.0 * shade; out_frag_color.z = in_color.z * 3.0 * shade; -} \ No newline at end of file +} diff --git a/shaders/rust/deferred/mrt/src/lib.rs b/shaders/rust/deferred/mrt/src/lib.rs index 35cc20adc..269c57ad6 100644 --- a/shaders/rust/deferred/mrt/src/lib.rs +++ b/shaders/rust/deferred/mrt/src/lib.rs @@ -1,9 +1,9 @@ #![no_std] use spirv_std::glam::{vec4, Mat3, Mat4, Vec2, Vec3, Vec4, Vec4Swizzles}; +use spirv_std::image::SampledImage; use spirv_std::spirv; use spirv_std::Image; -use spirv_std::image::SampledImage; #[repr(C)] #[derive(Copy, Clone)] @@ -31,18 +31,18 @@ pub fn main_vs( out_tangent: &mut Vec3, ) { let tmp_pos = in_pos + ubo.instance_pos[instance_index as usize]; - + *out_position = ubo.projection * ubo.view * ubo.model * tmp_pos; - + *out_uv = in_uv; - + // Vertex position in world space *out_world_pos = (ubo.model * tmp_pos).xyz(); - + // Normal - just normalize, don't transform *out_normal = in_normal.normalize(); *out_tangent = in_tangent.normalize(); - + // Currently just vertex color *out_color = in_color; } @@ -54,14 +54,18 @@ pub fn main_fs( _in_color: Vec3, in_world_pos: Vec3, in_tangent: Vec3, - #[spirv(descriptor_set = 0, binding = 1)] sampler_color: &SampledImage, - #[spirv(descriptor_set = 0, binding = 2)] sampler_normal: &SampledImage, + #[spirv(descriptor_set = 0, binding = 1)] sampler_color: &SampledImage< + Image!(2D, type=f32, sampled), + >, + #[spirv(descriptor_set = 0, binding = 2)] sampler_normal: &SampledImage< + Image!(2D, type=f32, sampled), + >, out_position: &mut Vec4, out_normal: &mut Vec4, out_albedo: &mut Vec4, ) { *out_position = vec4(in_world_pos.x, in_world_pos.y, in_world_pos.z, 1.0); - + // Calculate normal in tangent space let n = in_normal.normalize(); let t = in_tangent.normalize(); @@ -70,6 +74,6 @@ pub fn main_fs( let sampled_normal = sampler_normal.sample(in_uv).xyz() * 2.0 - 1.0; let tnorm = tbn * sampled_normal.normalize(); *out_normal = vec4(tnorm.x, tnorm.y, tnorm.z, 1.0); - + *out_albedo = sampler_color.sample(in_uv); -} \ No newline at end of file +} diff --git a/shaders/rust/deferredmultisampling/deferred/src/lib.rs b/shaders/rust/deferredmultisampling/deferred/src/lib.rs index 7398a12d9..544162247 100644 --- a/shaders/rust/deferredmultisampling/deferred/src/lib.rs +++ b/shaders/rust/deferredmultisampling/deferred/src/lib.rs @@ -1,7 +1,7 @@ #![no_std] use spirv_std::glam::{ivec2, vec2, vec4, IVec2, UVec2, Vec2, Vec3, Vec4, Vec4Swizzles}; -use spirv_std::image::{ImageWithMethods, sample_with}; +use spirv_std::image::{sample_with, ImageWithMethods}; use spirv_std::{num_traits::Float, spirv, Image}; #[repr(C, align(16))] @@ -14,9 +14,9 @@ pub struct Light { #[repr(C, align(16))] #[derive(Copy, Clone)] pub struct UBO { - pub lights: [Light; 6], // 6 * 32 = 192 bytes - pub view_pos: Vec4, // 16 bytes, total = 208 bytes - pub _padding1: Vec4, // 16 bytes padding to align next member to 224 + pub lights: [Light; 6], // 6 * 32 = 192 bytes + pub view_pos: Vec4, // 16 bytes, total = 208 bytes + pub _padding1: Vec4, // 16 bytes padding to align next member to 224 pub debug_display_target: Vec4, // Use Vec4 with debug_display_target in x component } @@ -33,7 +33,11 @@ pub fn main_vs( const NUM_LIGHTS: usize = 6; -fn resolve(tex: &Image!(2D, format=rgba8, sampled, multisampled), uv: IVec2, num_samples: u32) -> Vec4 { +fn resolve( + tex: &Image!(2D, format = rgba8, sampled, multisampled), + uv: IVec2, + num_samples: u32, +) -> Vec4 { let mut result = Vec4::ZERO; for i in 0..num_samples { let val: Vec4 = tex.fetch_with(uv, sample_with::sample_index(i as i32)); @@ -54,7 +58,7 @@ fn calculate_lighting(pos: Vec3, normal: Vec3, albedo: Vec4, ubo: &UBO) -> Vec3 // Viewer to fragment let v = (ubo.view_pos.xyz() - pos).normalize(); - + // Light to fragment let l = l.normalize(); @@ -79,16 +83,34 @@ fn calculate_lighting(pos: Vec3, normal: Vec3, albedo: Vec4, ubo: &UBO) -> Vec3 #[spirv(fragment)] pub fn main_fs( in_uv: Vec2, - #[spirv(descriptor_set = 0, binding = 1)] sampler_position: &Image!(2D, format=rgba16f, sampled, multisampled), - #[spirv(descriptor_set = 0, binding = 2)] sampler_normal: &Image!(2D, format=rgba16f, sampled, multisampled), - #[spirv(descriptor_set = 0, binding = 3)] sampler_albedo: &Image!(2D, format=rgba8, sampled, multisampled), + #[spirv(descriptor_set = 0, binding = 1)] sampler_position: &Image!( + 2D, + format = rgba16f, + sampled, + multisampled + ), + #[spirv(descriptor_set = 0, binding = 2)] sampler_normal: &Image!( + 2D, + format = rgba16f, + sampled, + multisampled + ), + #[spirv(descriptor_set = 0, binding = 3)] sampler_albedo: &Image!( + 2D, + format = rgba8, + sampled, + multisampled + ), #[spirv(uniform, descriptor_set = 0, binding = 4)] ubo: &UBO, #[spirv(spec_constant(id = 0, default = 8))] num_samples: u32, out_frag_color: &mut Vec4, ) { let att_dim: UVec2 = sampler_position.query_size(); - let uv = ivec2((in_uv.x * att_dim.x as f32) as i32, (in_uv.y * att_dim.y as f32) as i32); - + let uv = ivec2( + (in_uv.x * att_dim.x as f32) as i32, + (in_uv.y * att_dim.y as f32) as i32, + ); + // Debug display if ubo.debug_display_target.x as i32 > 0 { let val: Vec4 = match ubo.debug_display_target.x as i32 { @@ -98,7 +120,7 @@ pub fn main_fs( 4 => { let alb: Vec4 = sampler_albedo.fetch_with(uv, sample_with::sample_index(0)); vec4(alb.w, alb.w, alb.w, 1.0) - }, + } _ => Vec4::ZERO, }; *out_frag_color = vec4(val.x, val.y, val.z, 1.0); @@ -110,7 +132,7 @@ pub fn main_fs( // Ambient part let alb = resolve(sampler_albedo, uv, num_samples); let mut frag_color = Vec3::ZERO; - + // Calculate lighting for every MSAA sample for i in 0..num_samples { let pos: Vec4 = sampler_position.fetch_with(uv, sample_with::sample_index(i as i32)); @@ -120,6 +142,6 @@ pub fn main_fs( } frag_color = (alb.xyz() * AMBIENT) + frag_color / (num_samples as f32); - + *out_frag_color = vec4(frag_color.x, frag_color.y, frag_color.z, 1.0); -} \ No newline at end of file +} diff --git a/shaders/rust/deferredmultisampling/mrt/src/lib.rs b/shaders/rust/deferredmultisampling/mrt/src/lib.rs index c876d6104..50d2d1e89 100644 --- a/shaders/rust/deferredmultisampling/mrt/src/lib.rs +++ b/shaders/rust/deferredmultisampling/mrt/src/lib.rs @@ -1,9 +1,9 @@ #![no_std] use spirv_std::glam::{vec4, Mat3, Mat4, Vec2, Vec3, Vec4, Vec4Swizzles}; +use spirv_std::image::SampledImage; use spirv_std::spirv; use spirv_std::Image; -use spirv_std::image::SampledImage; #[repr(C)] #[derive(Copy, Clone)] @@ -30,20 +30,21 @@ pub fn main_vs( out_world_pos: &mut Vec3, out_tangent: &mut Vec3, ) { - let tmp_pos = vec4(in_pos.x, in_pos.y, in_pos.z, 1.0) + ubo.instance_pos[instance_index as usize]; - + let tmp_pos = + vec4(in_pos.x, in_pos.y, in_pos.z, 1.0) + ubo.instance_pos[instance_index as usize]; + *out_position = ubo.projection * ubo.view * ubo.model * tmp_pos; - + *out_uv = in_uv; - + // Vertex position in world space *out_world_pos = (ubo.model * tmp_pos).xyz(); - + // Normal in world space let m_normal = Mat3::from_mat4(ubo.model).inverse().transpose(); *out_normal = (m_normal * in_normal.normalize()).normalize(); *out_tangent = (m_normal * in_tangent.normalize()).normalize(); - + // Currently just vertex color *out_color = in_color; } @@ -55,14 +56,18 @@ pub fn main_fs( _in_color: Vec3, in_world_pos: Vec3, in_tangent: Vec3, - #[spirv(descriptor_set = 0, binding = 1)] sampler_color: &SampledImage, - #[spirv(descriptor_set = 0, binding = 2)] sampler_normal_map: &SampledImage, + #[spirv(descriptor_set = 0, binding = 1)] sampler_color: &SampledImage< + Image!(2D, type=f32, sampled), + >, + #[spirv(descriptor_set = 0, binding = 2)] sampler_normal_map: &SampledImage< + Image!(2D, type=f32, sampled), + >, out_position: &mut Vec4, out_normal: &mut Vec4, out_albedo: &mut Vec4, ) { *out_position = vec4(in_world_pos.x, in_world_pos.y, in_world_pos.z, 1.0); - + // Calculate normal in tangent space let n = in_normal.normalize(); let t = in_tangent.normalize(); @@ -71,6 +76,6 @@ pub fn main_fs( let sampled_normal = sampler_normal_map.sample(in_uv).xyz() * 2.0 - Vec3::splat(1.0); let tnorm = tbn * sampled_normal.normalize(); *out_normal = vec4(tnorm.x, tnorm.y, tnorm.z, 1.0); - + *out_albedo = sampler_color.sample(in_uv); -} \ No newline at end of file +} diff --git a/shaders/rust/deferredshadows/deferred/src/lib.rs b/shaders/rust/deferredshadows/deferred/src/lib.rs index 9e239a5a9..56a5fb7c3 100644 --- a/shaders/rust/deferredshadows/deferred/src/lib.rs +++ b/shaders/rust/deferredshadows/deferred/src/lib.rs @@ -2,9 +2,9 @@ use spirv_std::{ glam::{Mat4, Vec2, Vec3, Vec4, Vec4Swizzles}, - spirv, Image, image::SampledImage, num_traits::Float, + spirv, Image, }; const LIGHT_COUNT: usize = 3; @@ -42,7 +42,11 @@ fn texture_proj( let shadow_coord_xy = shadow_coord.xy() * 0.5 + 0.5; if shadow_coord.z > -1.0 && shadow_coord.z < 1.0 { - let sample_coord = Vec3::new(shadow_coord_xy.x + offset.x, shadow_coord_xy.y + offset.y, layer); + let sample_coord = Vec3::new( + shadow_coord_xy.x + offset.x, + shadow_coord_xy.y + offset.y, + layer, + ); let dist = shadow_map.sample(sample_coord).x; if shadow_coord.w > 0.0 && dist < shadow_coord.z { shadow = SHADOW_FACTOR; @@ -86,7 +90,8 @@ fn shadow( ) -> Vec3 { let mut result = frag_color; for i in 0..LIGHT_COUNT { - let shadow_clip = ubo.lights[i].view_matrix * Vec4::new(frag_pos.x, frag_pos.y, frag_pos.z, 1.0); + let shadow_clip = + ubo.lights[i].view_matrix * Vec4::new(frag_pos.x, frag_pos.y, frag_pos.z, 1.0); let shadow_factor = if USE_PCF { filter_pcf(shadow_map, shadow_clip, i as f32) @@ -105,10 +110,7 @@ pub fn main_vs( #[spirv(position)] out_position: &mut Vec4, out_uv: &mut Vec2, ) { - let uv = Vec2::new( - ((vertex_index << 1) & 2) as f32, - (vertex_index & 2) as f32, - ); + let uv = Vec2::new(((vertex_index << 1) & 2) as f32, (vertex_index & 2) as f32); *out_uv = uv; *out_position = Vec4::new(uv.x * 2.0 - 1.0, uv.y * 2.0 - 1.0, 0.0, 1.0); } @@ -116,11 +118,19 @@ pub fn main_vs( #[spirv(fragment)] pub fn main_fs( in_uv: Vec2, - #[spirv(descriptor_set = 0, binding = 1)] position_sampler: &SampledImage, - #[spirv(descriptor_set = 0, binding = 2)] normal_sampler: &SampledImage, - #[spirv(descriptor_set = 0, binding = 3)] albedo_sampler: &SampledImage, + #[spirv(descriptor_set = 0, binding = 1)] position_sampler: &SampledImage< + Image!(2D, type=f32, sampled), + >, + #[spirv(descriptor_set = 0, binding = 2)] normal_sampler: &SampledImage< + Image!(2D, type=f32, sampled), + >, + #[spirv(descriptor_set = 0, binding = 3)] albedo_sampler: &SampledImage< + Image!(2D, type=f32, sampled), + >, #[spirv(uniform, descriptor_set = 0, binding = 4)] ubo: &UBO, - #[spirv(descriptor_set = 0, binding = 5)] shadow_map: &SampledImage, + #[spirv(descriptor_set = 0, binding = 5)] shadow_map: &SampledImage< + Image!(2D, type=f32, sampled, arrayed), + >, out_frag_color: &mut Vec4, ) { // Get G-Buffer values @@ -179,7 +189,11 @@ pub fn main_fs( let ndot_r = r.dot(v).max(0.0); let spec = Vec3::splat(ndot_r.powf(16.0) * albedo.w * 2.5); - frag_color += (diff + spec) * spot_effect * height_attenuation * ubo.lights[i].color.xyz() * albedo.xyz(); + frag_color += (diff + spec) + * spot_effect + * height_attenuation + * ubo.lights[i].color.xyz() + * albedo.xyz(); } // Shadow calculations in a separate pass @@ -197,4 +211,4 @@ fn smoothstep(edge0: f32, edge1: f32, x: f32) -> f32 { fn reflect(i: Vec3, n: Vec3) -> Vec3 { i - 2.0 * n.dot(i) * n -} \ No newline at end of file +} diff --git a/shaders/rust/deferredshadows/mrt/src/lib.rs b/shaders/rust/deferredshadows/mrt/src/lib.rs index 9ed604b81..8cb4fa808 100644 --- a/shaders/rust/deferredshadows/mrt/src/lib.rs +++ b/shaders/rust/deferredshadows/mrt/src/lib.rs @@ -2,8 +2,8 @@ use spirv_std::{ glam::{Mat4, Vec2, Vec3, Vec4, Vec4Swizzles}, - spirv, Image, image::SampledImage, + spirv, Image, }; #[repr(C)] @@ -32,18 +32,18 @@ pub fn main_vs( out_tangent: &mut Vec3, ) { let tmp_pos = in_pos + ubo.instance_pos[instance_index as usize]; - + *out_position = ubo.projection * ubo.view * ubo.model * tmp_pos; - + *out_uv = in_uv; - + // Vertex position in world space *out_world_pos = (ubo.model * tmp_pos).xyz(); - + // Normal in world space *out_normal = in_normal.normalize(); *out_tangent = in_tangent.normalize(); - + // Currently just vertex color *out_color = in_color; } @@ -55,14 +55,18 @@ pub fn main_fs( _in_color: Vec3, in_world_pos: Vec3, in_tangent: Vec3, - #[spirv(descriptor_set = 0, binding = 1)] sampler_color: &SampledImage, - #[spirv(descriptor_set = 0, binding = 2)] sampler_normal_map: &SampledImage, + #[spirv(descriptor_set = 0, binding = 1)] sampler_color: &SampledImage< + Image!(2D, type=f32, sampled), + >, + #[spirv(descriptor_set = 0, binding = 2)] sampler_normal_map: &SampledImage< + Image!(2D, type=f32, sampled), + >, out_position: &mut Vec4, out_normal: &mut Vec4, out_albedo: &mut Vec4, ) { *out_position = Vec4::new(in_world_pos.x, in_world_pos.y, in_world_pos.z, 1.0); - + // Calculate normal in tangent space let n = in_normal.normalize(); let t = in_tangent.normalize(); @@ -71,6 +75,6 @@ pub fn main_fs( // TBN matrix multiplication - transforms from tangent space to world space let tnorm = t * tnorm.x + b * tnorm.y + n * tnorm.z; *out_normal = Vec4::new(tnorm.x, tnorm.y, tnorm.z, 1.0); - + *out_albedo = sampler_color.sample(in_uv); -} \ No newline at end of file +} diff --git a/shaders/rust/deferredshadows/shadow/src/lib.rs b/shaders/rust/deferredshadows/shadow/src/lib.rs index 29e64b0e7..d474ff225 100644 --- a/shaders/rust/deferredshadows/shadow/src/lib.rs +++ b/shaders/rust/deferredshadows/shadow/src/lib.rs @@ -37,14 +37,14 @@ pub fn main_gs( ) { let instance_index = in_instance_index[0]; let instanced_pos = ubo.instance_pos[instance_index as usize]; - + for i in 0..3 { let tmp_pos = in_position[i] + instanced_pos; *out_position = ubo.mvp[invocation_id as usize] * tmp_pos; *out_layer = invocation_id; - + unsafe { spirv_std::arch::emit_vertex() }; } - + unsafe { spirv_std::arch::end_primitive() }; -} \ No newline at end of file +} diff --git a/shaders/rust/descriptorbuffer/cube/src/lib.rs b/shaders/rust/descriptorbuffer/cube/src/lib.rs index cab8959df..7a9dd0b93 100644 --- a/shaders/rust/descriptorbuffer/cube/src/lib.rs +++ b/shaders/rust/descriptorbuffer/cube/src/lib.rs @@ -1,8 +1,11 @@ #![cfg_attr(target_arch = "spirv", no_std)] #![allow(clippy::missing_safety_doc)] -use spirv_std::{spirv, glam::{vec4, Mat4, Vec2, Vec3, Vec4}, Image}; use spirv_std::image::SampledImage; +use spirv_std::{ + glam::{vec4, Mat4, Vec2, Vec3, Vec4}, + spirv, Image, +}; #[repr(C)] #[derive(Copy, Clone)] @@ -33,7 +36,8 @@ pub fn main_vs( *out_normal = in_normal; *out_color = in_color; *out_uv = in_uv; - *out_position = camera.projection * camera.view * model.matrix * vec4(in_pos.x, in_pos.y, in_pos.z, 1.0); + *out_position = + camera.projection * camera.view * model.matrix * vec4(in_pos.x, in_pos.y, in_pos.z, 1.0); } #[spirv(fragment)] @@ -41,9 +45,11 @@ pub fn main_fs( _in_normal: Vec3, in_color: Vec3, in_uv: Vec2, - #[spirv(descriptor_set = 2, binding = 0)] sampler_color_map: &SampledImage, + #[spirv(descriptor_set = 2, binding = 0)] sampler_color_map: &SampledImage< + Image!(2D, type=f32, sampled), + >, out_frag_color: &mut Vec4, ) { let texture_color = sampler_color_map.sample(in_uv); *out_frag_color = texture_color * vec4(in_color.x, in_color.y, in_color.z, 1.0); -} \ No newline at end of file +} diff --git a/shaders/rust/descriptorindexing/src/lib.rs b/shaders/rust/descriptorindexing/src/lib.rs index 53806cdea..530378c77 100644 --- a/shaders/rust/descriptorindexing/src/lib.rs +++ b/shaders/rust/descriptorindexing/src/lib.rs @@ -1,8 +1,11 @@ #![no_std] -use spirv_std::spirv; -use spirv_std::{glam::{vec4, Mat4, Vec2, Vec3, Vec4}, Image, RuntimeArray}; use spirv_std::image::SampledImage; +use spirv_std::spirv; +use spirv_std::{ + glam::{vec4, Mat4, Vec2, Vec3, Vec4}, + Image, RuntimeArray, +}; #[repr(C)] pub struct Matrices { @@ -32,11 +35,13 @@ pub fn main_vs( pub fn main_fs( in_uv: Vec2, #[spirv(flat)] in_tex_index: i32, - #[spirv(descriptor_set = 0, binding = 1)] textures: &RuntimeArray>, + #[spirv(descriptor_set = 0, binding = 1)] textures: &RuntimeArray< + SampledImage, + >, out_frag_color: &mut Vec4, ) { unsafe { let texture = textures.index(in_tex_index as usize); *out_frag_color = texture.sample(in_uv); } -} \ No newline at end of file +} diff --git a/shaders/rust/descriptorsets/cube/src/lib.rs b/shaders/rust/descriptorsets/cube/src/lib.rs index 4994ee1d1..cc8defb9a 100644 --- a/shaders/rust/descriptorsets/cube/src/lib.rs +++ b/shaders/rust/descriptorsets/cube/src/lib.rs @@ -1,8 +1,11 @@ #![cfg_attr(target_arch = "spirv", no_std)] #![allow(clippy::missing_safety_doc)] -use spirv_std::{spirv, glam::{vec4, Mat4, Vec2, Vec3, Vec4}, Image}; use spirv_std::image::SampledImage; +use spirv_std::{ + glam::{vec4, Mat4, Vec2, Vec3, Vec4}, + spirv, Image, +}; #[repr(C)] #[derive(Copy, Clone)] @@ -27,7 +30,10 @@ pub fn main_vs( *out_normal = in_normal; *out_color = in_color; *out_uv = in_uv; - *out_position = ubo_matrices.projection * ubo_matrices.view * ubo_matrices.model * vec4(in_pos.x, in_pos.y, in_pos.z, 1.0); + *out_position = ubo_matrices.projection + * ubo_matrices.view + * ubo_matrices.model + * vec4(in_pos.x, in_pos.y, in_pos.z, 1.0); } #[spirv(fragment)] @@ -35,9 +41,11 @@ pub fn main_fs( in_normal: Vec3, in_color: Vec3, in_uv: Vec2, - #[spirv(descriptor_set = 0, binding = 1)] color_sampler: &SampledImage, + #[spirv(descriptor_set = 0, binding = 1)] color_sampler: &SampledImage< + Image!(2D, type=f32, sampled), + >, out_frag_color: &mut Vec4, ) { let texture_color = color_sampler.sample(in_uv); *out_frag_color = texture_color * vec4(in_color.x, in_color.y, in_color.z, 1.0); -} \ No newline at end of file +} diff --git a/shaders/rust/displacement/base/src/lib.rs b/shaders/rust/displacement/base/src/lib.rs index 3bcbb9583..1629db61b 100644 --- a/shaders/rust/displacement/base/src/lib.rs +++ b/shaders/rust/displacement/base/src/lib.rs @@ -1,7 +1,10 @@ #![cfg_attr(target_arch = "spirv", no_std)] #![allow(clippy::missing_safety_doc)] -use spirv_std::{spirv, glam::{vec4, Vec2, Vec3, Vec4}}; +use spirv_std::{ + glam::{vec4, Vec2, Vec3, Vec4}, + spirv, +}; #[spirv(vertex)] pub fn main_vs( @@ -23,19 +26,21 @@ pub fn main_fs( in_uv: Vec2, in_eye_pos: Vec3, in_light_vec: Vec3, - #[spirv(descriptor_set = 0, binding = 1)] color_map: &spirv_std::image::SampledImage, + #[spirv(descriptor_set = 0, binding = 1)] color_map: &spirv_std::image::SampledImage< + spirv_std::Image!(2D, type=f32, sampled), + >, out_frag_color: &mut Vec4, ) { let _n = in_normal.normalize(); let _l = Vec3::new(1.0, 1.0, 1.0).normalize(); - + let color = color_map.sample(in_uv); - + let _eye = (-in_eye_pos).normalize(); let _reflected = (-in_light_vec).reflect(in_normal).normalize(); - + let i_ambient = vec4(0.0, 0.0, 0.0, 1.0); let i_diffuse = vec4(1.0, 1.0, 1.0, 1.0) * in_normal.dot(in_light_vec).max(0.0); - + *out_frag_color = (i_ambient + i_diffuse) * vec4(color.x, color.y, color.z, 1.0); -} \ No newline at end of file +} diff --git a/shaders/rust/displacement/displacement/src/lib.rs b/shaders/rust/displacement/displacement/src/lib.rs index 63376bfbf..77db8dc1f 100644 --- a/shaders/rust/displacement/displacement/src/lib.rs +++ b/shaders/rust/displacement/displacement/src/lib.rs @@ -1,7 +1,10 @@ #![cfg_attr(target_arch = "spirv", no_std)] #![allow(clippy::missing_safety_doc)] -use spirv_std::{spirv, glam::{vec4, Mat4, Vec2, Vec3, Vec4}}; +use spirv_std::{ + glam::{vec4, Mat4, Vec2, Vec3, Vec4}, + spirv, +}; #[repr(C)] #[derive(Copy, Clone)] @@ -33,7 +36,7 @@ pub fn main_tcs( tess_level_outer[1] = ubo.tess_level; tess_level_outer[2] = ubo.tess_level; } - + out_position[invocation_id as usize] = in_position[invocation_id as usize]; out_normal[invocation_id as usize] = in_normal[invocation_id as usize]; out_uv[invocation_id as usize] = in_uv[invocation_id as usize]; @@ -46,23 +49,34 @@ pub fn main_tes( in_normal: [Vec3; 3], in_uv: [Vec2; 3], #[spirv(uniform, descriptor_set = 0, binding = 0)] ubo: &Ubo, - #[spirv(descriptor_set = 0, binding = 1)] displacement_map: &spirv_std::image::SampledImage, + #[spirv(descriptor_set = 0, binding = 1)] displacement_map: &spirv_std::image::SampledImage< + spirv_std::Image!(2D, type=f32, sampled), + >, #[spirv(position)] out_position: &mut Vec4, out_normal: &mut Vec3, out_uv: &mut Vec2, out_eye_pos: &mut Vec3, out_light_vec: &mut Vec3, ) { - let pos = tess_coord.x * in_position[0] + tess_coord.y * in_position[1] + tess_coord.z * in_position[2]; + let pos = tess_coord.x * in_position[0] + + tess_coord.y * in_position[1] + + tess_coord.z * in_position[2]; *out_uv = tess_coord.x * in_uv[0] + tess_coord.y * in_uv[1] + tess_coord.z * in_uv[2]; - *out_normal = tess_coord.x * in_normal[0] + tess_coord.y * in_normal[1] + tess_coord.z * in_normal[2]; - + *out_normal = + tess_coord.x * in_normal[0] + tess_coord.y * in_normal[1] + tess_coord.z * in_normal[2]; + let displacement = displacement_map.sample_by_lod(*out_uv, 0.0).w.max(0.0) * ubo.tess_strength; let normal_normalized = out_normal.normalize(); - let displaced_pos = pos + vec4(normal_normalized.x, normal_normalized.y, normal_normalized.z, 0.0) * displacement; - + let displaced_pos = pos + + vec4( + normal_normalized.x, + normal_normalized.y, + normal_normalized.z, + 0.0, + ) * displacement; + *out_eye_pos = displaced_pos.truncate(); *out_light_vec = (ubo.light_pos.truncate() - *out_eye_pos).normalize(); - + *out_position = ubo.projection * ubo.modelview * displaced_pos; -} \ No newline at end of file +} diff --git a/shaders/rust/distancefieldfonts/bitmap/src/lib.rs b/shaders/rust/distancefieldfonts/bitmap/src/lib.rs index 322a3f1ff..91116a7c2 100644 --- a/shaders/rust/distancefieldfonts/bitmap/src/lib.rs +++ b/shaders/rust/distancefieldfonts/bitmap/src/lib.rs @@ -1,8 +1,11 @@ #![cfg_attr(target_arch = "spirv", no_std)] #![allow(clippy::missing_safety_doc)] -use spirv_std::{spirv, glam::{vec4, Mat4, Vec2, Vec3, Vec4}, Image}; use spirv_std::image::SampledImage; +use spirv_std::{ + glam::{vec4, Mat4, Vec2, Vec3, Vec4}, + spirv, Image, +}; #[repr(C)] #[derive(Copy, Clone)] @@ -26,9 +29,11 @@ pub fn main_vs( #[spirv(fragment)] pub fn main_fs( in_uv: Vec2, - #[spirv(descriptor_set = 0, binding = 1)] sampler_color: &SampledImage, + #[spirv(descriptor_set = 0, binding = 1)] sampler_color: &SampledImage< + Image!(2D, type=f32, sampled), + >, out_frag_color: &mut Vec4, ) { let alpha = sampler_color.sample(in_uv).w; *out_frag_color = vec4(alpha, alpha, alpha, alpha); -} \ No newline at end of file +} diff --git a/shaders/rust/distancefieldfonts/sdf/src/lib.rs b/shaders/rust/distancefieldfonts/sdf/src/lib.rs index 18572e252..95b7b01b4 100644 --- a/shaders/rust/distancefieldfonts/sdf/src/lib.rs +++ b/shaders/rust/distancefieldfonts/sdf/src/lib.rs @@ -1,9 +1,12 @@ #![cfg_attr(target_arch = "spirv", no_std)] #![allow(clippy::missing_safety_doc)] -use spirv_std::{spirv, glam::{vec3, vec4, Mat4, Vec2, Vec3, Vec4}, Image}; -use spirv_std::image::SampledImage; use spirv_std::arch::Derivative; +use spirv_std::image::SampledImage; +use spirv_std::{ + glam::{vec3, vec4, Mat4, Vec2, Vec3, Vec4}, + spirv, Image, +}; #[repr(C)] #[derive(Copy, Clone)] @@ -36,19 +39,21 @@ fn smooth_step(edge0: f32, edge1: f32, x: f32) -> f32 { pub fn main_fs( in_uv: Vec2, #[spirv(uniform, descriptor_set = 0, binding = 0)] ubo: &Ubo, - #[spirv(descriptor_set = 0, binding = 1)] sampler_color: &SampledImage, + #[spirv(descriptor_set = 0, binding = 1)] sampler_color: &SampledImage< + Image!(2D, type=f32, sampled), + >, out_frag_color: &mut Vec4, ) { let distance = sampler_color.sample(in_uv).w; let smooth_width = distance.fwidth(); let mut alpha = smooth_step(0.5 - smooth_width, 0.5 + smooth_width, distance); let mut rgb = vec3(alpha, alpha, alpha); - + if ubo.outline > 0.0 { let w = 1.0 - ubo.outline_width; alpha = smooth_step(w - smooth_width, w + smooth_width, distance); rgb += rgb.lerp(ubo.outline_color.truncate(), alpha); } - + *out_frag_color = vec4(rgb.x, rgb.y, rgb.z, alpha); -} \ No newline at end of file +} diff --git a/shaders/rust/dynamicrendering/texture/src/lib.rs b/shaders/rust/dynamicrendering/texture/src/lib.rs index d556afc1f..5aea1592c 100644 --- a/shaders/rust/dynamicrendering/texture/src/lib.rs +++ b/shaders/rust/dynamicrendering/texture/src/lib.rs @@ -1,8 +1,12 @@ #![cfg_attr(target_arch = "spirv", no_std)] #![allow(clippy::missing_safety_doc)] -use spirv_std::{spirv, glam::{mat3, vec3, vec4, Mat4, Vec2, Vec3, Vec4}, Image, num_traits::Float}; use spirv_std::image::SampledImage; +use spirv_std::{ + glam::{mat3, vec3, vec4, Mat4, Vec2, Vec3, Vec4}, + num_traits::Float, + spirv, Image, +}; #[repr(C)] #[derive(Copy, Clone)] @@ -25,9 +29,9 @@ pub fn main_vs( out_light_vec: &mut Vec3, ) { *out_uv = in_uv; - + *out_position = ubo.projection * ubo.model * vec4(in_pos.x, in_pos.y, in_pos.z, 1.0); - + let pos = ubo.model * vec4(in_pos.x, in_pos.y, in_pos.z, 1.0); let inverse_transpose_model = ubo.model.inverse().transpose(); let normal_mat3 = mat3( @@ -53,17 +57,24 @@ pub fn main_fs( in_normal: Vec3, in_view_vec: Vec3, in_light_vec: Vec3, - #[spirv(descriptor_set = 1, binding = 0)] sampler_color: &SampledImage, + #[spirv(descriptor_set = 1, binding = 0)] sampler_color: &SampledImage< + Image!(2D, type=f32, sampled), + >, out_frag_color: &mut Vec4, ) { let color = sampler_color.sample(in_uv); - + let n = in_normal.normalize(); let l = in_light_vec.normalize(); let v = in_view_vec.normalize(); let r = (-l).reflect(n); let diffuse = n.dot(l).max(0.0) * vec3(1.0, 1.0, 1.0); let specular = r.dot(v).max(0.0).powf(16.0) * color.w; - - *out_frag_color = vec4(diffuse.x * color.x + specular, diffuse.y * color.y + specular, diffuse.z * color.z + specular, 1.0); -} \ No newline at end of file + + *out_frag_color = vec4( + diffuse.x * color.x + specular, + diffuse.y * color.y + specular, + diffuse.z * color.z + specular, + 1.0, + ); +} diff --git a/shaders/rust/dynamicuniformbuffer/base/src/lib.rs b/shaders/rust/dynamicuniformbuffer/base/src/lib.rs index 1b9d89833..aaa49876b 100644 --- a/shaders/rust/dynamicuniformbuffer/base/src/lib.rs +++ b/shaders/rust/dynamicuniformbuffer/base/src/lib.rs @@ -1,7 +1,10 @@ #![cfg_attr(target_arch = "spirv", no_std)] #![allow(clippy::missing_safety_doc)] -use spirv_std::{spirv, glam::{vec4, Mat4, Vec3, Vec4}}; +use spirv_std::{ + glam::{vec4, Mat4, Vec3, Vec4}, + spirv, +}; #[repr(C)] #[derive(Copy, Clone)] @@ -31,9 +34,6 @@ pub fn main_vs( } #[spirv(fragment)] -pub fn main_fs( - in_color: Vec3, - out_frag_color: &mut Vec4, -) { +pub fn main_fs(in_color: Vec3, out_frag_color: &mut Vec4) { *out_frag_color = vec4(in_color.x, in_color.y, in_color.z, 1.0); -} \ No newline at end of file +} diff --git a/shaders/rust/gears/src/lib.rs b/shaders/rust/gears/src/lib.rs index 52429d067..dd59d5d58 100644 --- a/shaders/rust/gears/src/lib.rs +++ b/shaders/rust/gears/src/lib.rs @@ -1,8 +1,11 @@ #![cfg_attr(target_arch = "spirv", no_std)] #![allow(clippy::missing_safety_doc)] -use spirv_std::{spirv, glam::{vec4, Mat3, Mat4, Vec3, Vec4}}; use spirv_std::num_traits::Float; +use spirv_std::{ + glam::{vec4, Mat3, Mat4, Vec3, Vec4}, + spirv, +}; #[repr(C)] #[derive(Copy, Clone)] @@ -29,14 +32,14 @@ pub fn main_vs( let model = ubo.model[instance_index as usize]; *out_normal = (Mat3::from_mat4(model) * in_normal).normalize(); *out_color = in_color; - + let model_view = ubo.view * model; let pos = model_view * in_pos; *out_eye_pos = pos.truncate(); - + let light_pos = model_view * vec4(ubo.lightpos.x, ubo.lightpos.y, ubo.lightpos.z, 1.0); *out_light_vec = (light_pos.truncate() - *out_eye_pos).normalize(); - + *out_position = ubo.projection * pos; } @@ -50,11 +53,12 @@ pub fn main_fs( ) { let eye = (-in_eye_pos).normalize(); let reflected = (-in_light_vec).reflect(in_normal).normalize(); - + let i_ambient = vec4(0.2, 0.2, 0.2, 1.0); let i_diffuse = vec4(0.5, 0.5, 0.5, 0.5) * in_normal.dot(in_light_vec).max(0.0); let specular = 0.25; let i_specular = vec4(0.5, 0.5, 0.5, 1.0) * reflected.dot(eye).max(0.0).powf(0.8) * specular; - - *out_frag_color = (i_ambient + i_diffuse) * vec4(in_color.x, in_color.y, in_color.z, 1.0) + i_specular; + + *out_frag_color = + (i_ambient + i_diffuse) * vec4(in_color.x, in_color.y, in_color.z, 1.0) + i_specular; } diff --git a/shaders/rust/geometryshader/base/src/lib.rs b/shaders/rust/geometryshader/base/src/lib.rs index 4a3a00185..e9e285662 100644 --- a/shaders/rust/geometryshader/base/src/lib.rs +++ b/shaders/rust/geometryshader/base/src/lib.rs @@ -1,7 +1,10 @@ #![cfg_attr(target_arch = "spirv", no_std)] #![allow(clippy::missing_safety_doc)] -use spirv_std::{spirv, glam::{Vec3, Vec4}}; +use spirv_std::{ + glam::{Vec3, Vec4}, + spirv, +}; #[spirv(vertex)] pub fn main_vs( @@ -15,9 +18,6 @@ pub fn main_vs( } #[spirv(fragment)] -pub fn main_fs( - in_color: Vec3, - out_frag_color: &mut Vec4, -) { +pub fn main_fs(in_color: Vec3, out_frag_color: &mut Vec4) { *out_frag_color = Vec4::new(in_color.x, in_color.y, in_color.z, 1.0); -} \ No newline at end of file +} diff --git a/shaders/rust/geometryshader/mesh/src/lib.rs b/shaders/rust/geometryshader/mesh/src/lib.rs index 8f885f5d5..646cc9380 100644 --- a/shaders/rust/geometryshader/mesh/src/lib.rs +++ b/shaders/rust/geometryshader/mesh/src/lib.rs @@ -1,8 +1,11 @@ #![cfg_attr(target_arch = "spirv", no_std)] #![allow(clippy::missing_safety_doc)] -use spirv_std::{spirv, glam::{Mat4, Vec3, Vec4}}; use spirv_std::num_traits::Float; +use spirv_std::{ + glam::{Mat4, Vec3, Vec4}, + spirv, +}; #[repr(C)] #[derive(Copy, Clone)] @@ -54,6 +57,6 @@ pub fn main_fs( ((ambient + diffuse) * in_color + specular).x, ((ambient + diffuse) * in_color + specular).y, ((ambient + diffuse) * in_color + specular).z, - 1.0 + 1.0, ); -} \ No newline at end of file +} diff --git a/shaders/rust/geometryshader/normaldebug/src/lib.rs b/shaders/rust/geometryshader/normaldebug/src/lib.rs index 28ba3ffb6..fa16ca145 100644 --- a/shaders/rust/geometryshader/normaldebug/src/lib.rs +++ b/shaders/rust/geometryshader/normaldebug/src/lib.rs @@ -1,7 +1,10 @@ #![cfg_attr(target_arch = "spirv", no_std)] #![allow(clippy::missing_safety_doc)] -use spirv_std::{spirv, glam::{Mat4, Vec3, Vec4}}; +use spirv_std::{ + glam::{Mat4, Vec3, Vec4}, + spirv, +}; #[repr(C)] #[derive(Copy, Clone)] @@ -30,7 +33,7 @@ pub fn main_gs( out_color: &mut Vec3, ) { let normal_length = 0.02; - + for i in 0..3 { let pos = in_position[i].truncate(); let normal = in_normal[i]; @@ -42,7 +45,8 @@ pub fn main_gs( } let end_pos = pos + normal * normal_length; - *out_position = ubo.projection * (ubo.model * Vec4::new(end_pos.x, end_pos.y, end_pos.z, 1.0)); + *out_position = + ubo.projection * (ubo.model * Vec4::new(end_pos.x, end_pos.y, end_pos.z, 1.0)); *out_color = Vec3::new(0.0, 0.0, 1.0); unsafe { spirv_std::arch::emit_vertex(); @@ -55,9 +59,6 @@ pub fn main_gs( } #[spirv(fragment)] -pub fn main_fs( - in_color: Vec3, - out_frag_color: &mut Vec4, -) { +pub fn main_fs(in_color: Vec3, out_frag_color: &mut Vec4) { *out_frag_color = Vec4::new(in_color.x, in_color.y, in_color.z, 1.0); -} \ No newline at end of file +} diff --git a/shaders/rust/gltfloading/mesh/src/lib.rs b/shaders/rust/gltfloading/mesh/src/lib.rs index ca9a69551..0fe73d534 100644 --- a/shaders/rust/gltfloading/mesh/src/lib.rs +++ b/shaders/rust/gltfloading/mesh/src/lib.rs @@ -1,8 +1,12 @@ #![cfg_attr(target_arch = "spirv", no_std)] #![allow(clippy::missing_safety_doc)] -use spirv_std::{spirv, glam::{mat3, vec3, vec4, Mat4, Vec2, Vec3, Vec4}, Image, num_traits::Float}; use spirv_std::image::SampledImage; +use spirv_std::{ + glam::{mat3, vec3, vec4, Mat4, Vec2, Vec3, Vec4}, + num_traits::Float, + spirv, Image, +}; #[repr(C)] #[derive(Copy, Clone)] @@ -37,8 +41,11 @@ pub fn main_vs( *out_normal = in_normal; *out_color = in_color; *out_uv = in_uv; - *out_position = ubo_scene.projection * ubo_scene.view * push_consts.model * vec4(in_pos.x, in_pos.y, in_pos.z, 1.0); - + *out_position = ubo_scene.projection + * ubo_scene.view + * push_consts.model + * vec4(in_pos.x, in_pos.y, in_pos.z, 1.0); + let pos = ubo_scene.view * push_consts.model * vec4(in_pos.x, in_pos.y, in_pos.z, 1.0); let view_mat3 = mat3( ubo_scene.view.x_axis.truncate(), @@ -57,7 +64,9 @@ pub fn main_fs( in_uv: Vec2, in_view_vec: Vec3, in_light_vec: Vec3, - #[spirv(descriptor_set = 1, binding = 0)] sampler_color_map: &SampledImage, + #[spirv(descriptor_set = 1, binding = 0)] sampler_color_map: &SampledImage< + Image!(2D, type=f32, sampled), + >, out_frag_color: &mut Vec4, ) { let color = sampler_color_map.sample(in_uv) * vec4(in_color.x, in_color.y, in_color.z, 1.0); @@ -68,5 +77,10 @@ pub fn main_fs( let r = l.reflect(n); let diffuse = n.dot(l).max(0.15) * in_color; let specular = v.dot(r).max(0.0).powf(16.0) * vec3(0.75, 0.75, 0.75); - *out_frag_color = vec4(diffuse.x * color.x + specular.x, diffuse.y * color.y + specular.y, diffuse.z * color.z + specular.z, 1.0); -} \ No newline at end of file + *out_frag_color = vec4( + diffuse.x * color.x + specular.x, + diffuse.y * color.y + specular.y, + diffuse.z * color.z + specular.z, + 1.0, + ); +} diff --git a/shaders/rust/gltfscenerendering/scene/src/lib.rs b/shaders/rust/gltfscenerendering/scene/src/lib.rs index cebaffb27..7916515fc 100644 --- a/shaders/rust/gltfscenerendering/scene/src/lib.rs +++ b/shaders/rust/gltfscenerendering/scene/src/lib.rs @@ -1,8 +1,12 @@ #![cfg_attr(target_arch = "spirv", no_std)] #![allow(clippy::missing_safety_doc)] -use spirv_std::{spirv, glam::{mat3, vec3, vec4, Mat3, Mat4, Vec2, Vec3, Vec4}, Image, num_traits::Float}; use spirv_std::image::SampledImage; +use spirv_std::{ + glam::{mat3, vec3, vec4, Mat3, Mat4, Vec2, Vec3, Vec4}, + num_traits::Float, + spirv, Image, +}; #[repr(C)] #[derive(Copy, Clone)] @@ -40,8 +44,11 @@ pub fn main_vs( *out_color = in_color; *out_uv = in_uv; *out_tangent = in_tangent; - *out_position = ubo_scene.projection * ubo_scene.view * push_consts.model * vec4(in_pos.x, in_pos.y, in_pos.z, 1.0); - + *out_position = ubo_scene.projection + * ubo_scene.view + * push_consts.model + * vec4(in_pos.x, in_pos.y, in_pos.z, 1.0); + let model_mat3 = mat3( push_consts.model.x_axis.truncate(), push_consts.model.y_axis.truncate(), @@ -61,8 +68,12 @@ pub fn main_fs( in_view_vec: Vec3, in_light_vec: Vec3, in_tangent: Vec4, - #[spirv(descriptor_set = 1, binding = 0)] sampler_color_map: &SampledImage, - #[spirv(descriptor_set = 1, binding = 1)] sampler_normal_map: &SampledImage, + #[spirv(descriptor_set = 1, binding = 0)] sampler_color_map: &SampledImage< + Image!(2D, type=f32, sampled), + >, + #[spirv(descriptor_set = 1, binding = 1)] sampler_normal_map: &SampledImage< + Image!(2D, type=f32, sampled), + >, #[spirv(spec_constant(id = 0, default = 0))] alpha_mask: u32, #[spirv(spec_constant(id = 1, default = 0))] alpha_mask_cutoff_bits: u32, out_frag_color: &mut Vec4, @@ -71,7 +82,7 @@ pub fn main_fs( let alpha_mask_enabled = alpha_mask != 0; let alpha_mask_cutoff = f32::from_bits(alpha_mask_cutoff_bits); - + if alpha_mask_enabled { if color.w < alpha_mask_cutoff { #[cfg(target_arch = "spirv")] @@ -90,12 +101,16 @@ pub fn main_fs( let l = in_light_vec.normalize(); let v = in_view_vec.normalize(); let r = (-l).reflect(n); - let diffuse = vec3(n.dot(l).max(AMBIENT), n.dot(l).max(AMBIENT), n.dot(l).max(AMBIENT)); + let diffuse = vec3( + n.dot(l).max(AMBIENT), + n.dot(l).max(AMBIENT), + n.dot(l).max(AMBIENT), + ); let specular = r.dot(v).max(0.0).powf(32.0); *out_frag_color = vec4( diffuse.x * color.x + specular, diffuse.y * color.y + specular, diffuse.z * color.z + specular, - color.w + color.w, ); -} \ No newline at end of file +} diff --git a/shaders/rust/gltfskinning/skinnedmodel/src/lib.rs b/shaders/rust/gltfskinning/skinnedmodel/src/lib.rs index 70c8c51ca..412583bd5 100644 --- a/shaders/rust/gltfskinning/skinnedmodel/src/lib.rs +++ b/shaders/rust/gltfskinning/skinnedmodel/src/lib.rs @@ -1,8 +1,12 @@ #![cfg_attr(target_arch = "spirv", no_std)] #![allow(clippy::missing_safety_doc)] -use spirv_std::{spirv, glam::{mat3, vec3, vec4, Mat4, Vec2, Vec3, Vec4}, Image, num_traits::Float}; use spirv_std::image::SampledImage; +use spirv_std::{ + glam::{mat3, vec3, vec4, Mat4, Vec2, Vec3, Vec4}, + num_traits::Float, + spirv, Image, +}; #[repr(C)] #[derive(Copy, Clone)] @@ -41,14 +45,17 @@ pub fn main_vs( *out_uv = in_uv; // Calculate skinned matrix from weights and joint indices of the current vertex - let skin_mat = - in_joint_weights.x * joint_matrices[in_joint_indices.x as usize] + - in_joint_weights.y * joint_matrices[in_joint_indices.y as usize] + - in_joint_weights.z * joint_matrices[in_joint_indices.z as usize] + - in_joint_weights.w * joint_matrices[in_joint_indices.w as usize]; + let skin_mat = in_joint_weights.x * joint_matrices[in_joint_indices.x as usize] + + in_joint_weights.y * joint_matrices[in_joint_indices.y as usize] + + in_joint_weights.z * joint_matrices[in_joint_indices.z as usize] + + in_joint_weights.w * joint_matrices[in_joint_indices.w as usize]; + + *out_position = ubo_scene.projection + * ubo_scene.view + * push_consts.model + * skin_mat + * vec4(in_pos.x, in_pos.y, in_pos.z, 1.0); - *out_position = ubo_scene.projection * ubo_scene.view * push_consts.model * skin_mat * vec4(in_pos.x, in_pos.y, in_pos.z, 1.0); - // Transform normal with model and skin matrices (matching slang version) let model_mat3 = mat3( push_consts.model.x_axis.truncate(), @@ -80,7 +87,9 @@ pub fn main_fs( in_uv: Vec2, in_view_vec: Vec3, in_light_vec: Vec3, - #[spirv(descriptor_set = 2, binding = 0)] sampler_color_map: &SampledImage, + #[spirv(descriptor_set = 2, binding = 0)] sampler_color_map: &SampledImage< + Image!(2D, type=f32, sampled), + >, out_frag_color: &mut Vec4, ) { let color = sampler_color_map.sample(in_uv) * vec4(in_color.x, in_color.y, in_color.z, 1.0); @@ -91,5 +100,10 @@ pub fn main_fs( let r = (-l).reflect(n); let diffuse = n.dot(l).max(0.5) * in_color; let specular = v.dot(r).max(0.0).powf(16.0) * vec3(0.75, 0.75, 0.75); - *out_frag_color = vec4(diffuse.x * color.x + specular.x, diffuse.y * color.y + specular.y, diffuse.z * color.z + specular.z, 1.0); -} \ No newline at end of file + *out_frag_color = vec4( + diffuse.x * color.x + specular.x, + diffuse.y * color.y + specular.y, + diffuse.z * color.z + specular.z, + 1.0, + ); +} diff --git a/shaders/rust/graphicspipelinelibrary/shared/src/lib.rs b/shaders/rust/graphicspipelinelibrary/shared/src/lib.rs index f01bb33a9..24de98cd0 100644 --- a/shaders/rust/graphicspipelinelibrary/shared/src/lib.rs +++ b/shaders/rust/graphicspipelinelibrary/shared/src/lib.rs @@ -1,7 +1,10 @@ #![cfg_attr(target_arch = "spirv", no_std)] #![allow(clippy::missing_safety_doc)] -use spirv_std::{spirv, glam::{mat3, vec4, Mat4, Vec3, Vec4}}; +use spirv_std::{ + glam::{mat3, vec4, Mat4, Vec3, Vec4}, + spirv, +}; #[repr(C)] #[derive(Copy, Clone)] @@ -29,7 +32,7 @@ pub fn main_vs( let pos = vec4(in_pos.x, in_pos.y, in_pos.z, 1.0); *out_position = ubo.projection * ubo.model * pos; - + let world_pos = ubo.model * pos; let model_mat3 = mat3( ubo.model.x_axis.truncate(), @@ -40,7 +43,7 @@ pub fn main_vs( let l_pos = ubo.light_pos.truncate(); *out_light_vec = l_pos - world_pos.truncate(); *out_view_vec = -world_pos.truncate(); - + // Flat shading normal is not interpolated *out_flat_normal = *out_normal; -} \ No newline at end of file +} diff --git a/shaders/rust/graphicspipelinelibrary/uber/src/lib.rs b/shaders/rust/graphicspipelinelibrary/uber/src/lib.rs index e9691e540..4371e5c69 100644 --- a/shaders/rust/graphicspipelinelibrary/uber/src/lib.rs +++ b/shaders/rust/graphicspipelinelibrary/uber/src/lib.rs @@ -1,7 +1,11 @@ #![cfg_attr(target_arch = "spirv", no_std)] #![allow(clippy::missing_safety_doc)] -use spirv_std::{spirv, glam::{vec3, vec4, Vec3, Vec4}, num_traits::Float}; +use spirv_std::{ + glam::{vec3, vec4, Vec3, Vec4}, + num_traits::Float, + spirv, +}; #[spirv(fragment)] pub fn main_fs( @@ -14,7 +18,8 @@ pub fn main_fs( out_frag_color: &mut Vec4, ) { let mut color = match lighting_model { - 0 => { // Phong + 0 => { + // Phong let ambient = in_color * vec3(0.25, 0.25, 0.25); let n = in_normal.normalize(); let l = in_light_vec.normalize(); @@ -24,7 +29,8 @@ pub fn main_fs( let specular = r.dot(v).max(0.0).powf(32.0) * vec3(0.75, 0.75, 0.75); ambient + diffuse * 1.75 + specular } - 1 => { // Toon + 1 => { + // Toon let n = in_normal.normalize(); let l = in_light_vec.normalize(); let intensity = n.dot(l); @@ -40,10 +46,12 @@ pub fn main_fs( in_color * 0.2 } } - 2 => { // No shading + 2 => { + // No shading in_color } - 3 => { // Greyscale + 3 => { + // Greyscale let grey = in_color.x * 0.299 + in_color.y * 0.587 + in_color.z * 0.114; vec3(grey, grey, grey) } @@ -52,6 +60,6 @@ pub fn main_fs( // Scene is dark, brighten up a bit color *= 1.25; - + *out_frag_color = vec4(color.x, color.y, color.z, 1.0); -} \ No newline at end of file +} diff --git a/shaders/rust/hdr/bloom/src/lib.rs b/shaders/rust/hdr/bloom/src/lib.rs index 897f28499..33c0c13e4 100644 --- a/shaders/rust/hdr/bloom/src/lib.rs +++ b/shaders/rust/hdr/bloom/src/lib.rs @@ -1,9 +1,8 @@ #![cfg_attr(target_arch = "spirv", no_std)] use spirv_std::{ - glam::{Vec2, Vec4, UVec2}, - spirv, - Image, Sampler, + glam::{UVec2, Vec2, Vec4}, + spirv, Image, Sampler, }; #[spirv(vertex)] @@ -12,10 +11,7 @@ pub fn main_vs( #[spirv(position)] out_position: &mut Vec4, out_uv: &mut Vec2, ) { - let uv = Vec2::new( - ((vertex_index << 1) & 2) as f32, - (vertex_index & 2) as f32, - ); + let uv = Vec2::new(((vertex_index << 1) & 2) as f32, (vertex_index & 2) as f32); *out_uv = uv; *out_position = Vec4::new(uv.x * 2.0 - 1.0, uv.y * 2.0 - 1.0, 0.0, 1.0); } @@ -69,7 +65,8 @@ pub fn main_fs( ar = ts.y as f32 / ts.x as f32; } - let p = Vec2::new(in_uv.y, in_uv.x) - Vec2::new(0.0, (WEIGHTS.len() as f32 / 2.0) * ar * BLUR_SCALE); + let p = Vec2::new(in_uv.y, in_uv.x) + - Vec2::new(0.0, (WEIGHTS.len() as f32 / 2.0) * ar * BLUR_SCALE); let mut color = Vec4::ZERO; for i in 0..WEIGHTS.len() { @@ -79,4 +76,4 @@ pub fn main_fs( } *out_color = color; -} \ No newline at end of file +} diff --git a/shaders/rust/hdr/composition/src/lib.rs b/shaders/rust/hdr/composition/src/lib.rs index 08d39d6fa..d82fdef4c 100644 --- a/shaders/rust/hdr/composition/src/lib.rs +++ b/shaders/rust/hdr/composition/src/lib.rs @@ -2,8 +2,7 @@ use spirv_std::{ glam::{Vec2, Vec4}, - spirv, - Image, Sampler, + spirv, Image, Sampler, }; #[spirv(vertex)] @@ -12,10 +11,7 @@ pub fn main_vs( #[spirv(position)] out_position: &mut Vec4, out_uv: &mut Vec2, ) { - let uv = Vec2::new( - ((vertex_index << 1) & 2) as f32, - (vertex_index & 2) as f32, - ); + let uv = Vec2::new(((vertex_index << 1) & 2) as f32, (vertex_index & 2) as f32); *out_uv = uv; *out_position = Vec4::new(uv.x * 2.0 - 1.0, uv.y * 2.0 - 1.0, 0.0, 1.0); } @@ -30,4 +26,4 @@ pub fn main_fs( out_color: &mut Vec4, ) { *out_color = image_color0.sample(*sampler_color0, in_uv); -} \ No newline at end of file +} diff --git a/shaders/rust/hdr/gbuffer/src/lib.rs b/shaders/rust/hdr/gbuffer/src/lib.rs index a7f803017..a64408ea0 100644 --- a/shaders/rust/hdr/gbuffer/src/lib.rs +++ b/shaders/rust/hdr/gbuffer/src/lib.rs @@ -2,9 +2,8 @@ use spirv_std::{ glam::{Mat3, Mat4, Vec3, Vec4}, - spirv, num_traits::Float, - Image, Sampler, + spirv, Image, Sampler, }; #[repr(C)] @@ -32,20 +31,24 @@ pub fn main_vs( *out_uvw = in_pos; match type_id as i32 { - 0 => { // Skybox + 0 => { + // Skybox let pos = Mat3::from_mat4(ubo.modelview) * in_pos; *out_pos = pos; *out_position = ubo.projection * Vec4::new(pos.x, pos.y, pos.z, 1.0); } - 1 => { // Object + 1 => { + // Object let pos = ubo.modelview * Vec4::new(in_pos.x, in_pos.y, in_pos.z, 1.0); *out_pos = Vec3::new(pos.x, pos.y, pos.z); - *out_position = ubo.projection * ubo.modelview * Vec4::new(in_pos.x, in_pos.y, in_pos.z, 1.0); + *out_position = + ubo.projection * ubo.modelview * Vec4::new(in_pos.x, in_pos.y, in_pos.z, 1.0); } _ => { let pos = ubo.modelview * Vec4::new(in_pos.x, in_pos.y, in_pos.z, 1.0); *out_pos = Vec3::new(pos.x, pos.y, pos.z); - *out_position = ubo.projection * ubo.modelview * Vec4::new(in_pos.x, in_pos.y, in_pos.z, 1.0); + *out_position = + ubo.projection * ubo.modelview * Vec4::new(in_pos.x, in_pos.y, in_pos.z, 1.0); } } @@ -73,11 +76,13 @@ pub fn main_fs( out_color1: &mut Vec4, ) { let color = match type_id as i32 { - 0 => { // Skybox + 0 => { + // Skybox let normal = in_uvw.normalize(); image_env_map.sample(*sampler_env_map, normal) } - 1 => { // Reflect + 1 => { + // Reflect let w_view_vec = Mat3::from_mat4(ubo.inverse_modelview) * in_view_vec.normalize(); let normal = in_normal.normalize(); let w_normal = Mat3::from_mat4(ubo.inverse_modelview) * normal; @@ -113,16 +118,17 @@ pub fn main_fs( env_color.x * n_dot_l * (K + spec * (1.0 - K)), env_color.y * n_dot_l * (K + spec * (1.0 - K)), env_color.z * n_dot_l * (K + spec * (1.0 - K)), - 1.0 + 1.0, ) } - 2 => { // Refract + 2 => { + // Refract let w_view_vec = Mat3::from_mat4(ubo.inverse_modelview) * in_view_vec.normalize(); let w_normal = Mat3::from_mat4(ubo.inverse_modelview) * in_normal; let refract_vec = -w_view_vec.refract(w_normal, 1.0 / 1.6); image_env_map.sample(*sampler_env_map, refract_vec) } - _ => Vec4::new(1.0, 0.0, 1.0, 1.0) + _ => Vec4::new(1.0, 0.0, 1.0, 1.0), }; // Color with manual exposure into attachment 0 @@ -145,4 +151,4 @@ pub fn main_fs( out_color1.z = 0.0; } out_color1.w = 1.0; -} \ No newline at end of file +} diff --git a/shaders/rust/imgui/scene/src/lib.rs b/shaders/rust/imgui/scene/src/lib.rs index 3bc42bc96..4aafcc7b4 100644 --- a/shaders/rust/imgui/scene/src/lib.rs +++ b/shaders/rust/imgui/scene/src/lib.rs @@ -1,7 +1,11 @@ #![cfg_attr(target_arch = "spirv", no_std)] #![allow(clippy::missing_safety_doc)] -use spirv_std::{spirv, glam::{vec3, vec4, Mat3, Mat4, Vec3, Vec4, Vec4Swizzles}, num_traits::Float}; +use spirv_std::{ + glam::{vec3, vec4, Mat3, Mat4, Vec3, Vec4, Vec4Swizzles}, + num_traits::Float, + spirv, +}; #[repr(C)] #[derive(Copy, Clone)] @@ -25,7 +29,7 @@ pub fn main_vs( ) { *out_color = in_color; *out_position = ubo.projection * ubo.model * vec4(in_pos.x, in_pos.y, in_pos.z, 1.0); - + let pos = ubo.model * vec4(in_pos.x, in_pos.y, in_pos.z, 1.0); *out_normal = Mat3::from_mat4(ubo.model) * in_normal; let l_pos = Mat3::from_mat4(ubo.model) * ubo.light_pos.xyz(); @@ -49,4 +53,4 @@ pub fn main_fs( let specular = r.dot(v).max(0.0).powf(16.0) * vec3(0.75, 0.75, 0.75); let color = diffuse * in_color + specular; *out_frag_color = vec4(color.x, color.y, color.z, 1.0); -} \ No newline at end of file +} diff --git a/shaders/rust/imgui/ui/src/lib.rs b/shaders/rust/imgui/ui/src/lib.rs index 25f762b6f..4fb3c52ce 100644 --- a/shaders/rust/imgui/ui/src/lib.rs +++ b/shaders/rust/imgui/ui/src/lib.rs @@ -1,7 +1,11 @@ #![cfg_attr(target_arch = "spirv", no_std)] #![allow(clippy::missing_safety_doc)] -use spirv_std::{spirv, glam::{vec4, Vec2, Vec4}, Image, image::SampledImage}; +use spirv_std::{ + glam::{vec4, Vec2, Vec4}, + image::SampledImage, + spirv, Image, +}; #[repr(C)] #[derive(Copy, Clone)] @@ -30,8 +34,10 @@ pub fn main_vs( pub fn main_fs( in_uv: Vec2, in_color: Vec4, - #[spirv(descriptor_set = 0, binding = 0)] font_sampler: &SampledImage, + #[spirv(descriptor_set = 0, binding = 0)] font_sampler: &SampledImage< + Image!(2D, type=f32, sampled), + >, out_color: &mut Vec4, ) { *out_color = in_color * font_sampler.sample(in_uv); -} \ No newline at end of file +} diff --git a/shaders/rust/indirectdraw/ground/src/lib.rs b/shaders/rust/indirectdraw/ground/src/lib.rs index 23b7cc933..4f16c95ce 100644 --- a/shaders/rust/indirectdraw/ground/src/lib.rs +++ b/shaders/rust/indirectdraw/ground/src/lib.rs @@ -1,7 +1,7 @@ #![cfg_attr(target_arch = "spirv", no_std)] +use spirv_std::glam::{Mat4, Vec2, Vec3, Vec4}; use spirv_std::spirv; -use spirv_std::glam::{Vec2, Vec3, Vec4, Mat4}; #[repr(C)] pub struct UBO { @@ -26,8 +26,10 @@ pub fn main_vs( #[spirv(fragment)] pub fn main_fs( in_uv: Vec2, - #[spirv(descriptor_set = 0, binding = 2)] sampler_color: &spirv_std::image::SampledImage, + #[spirv(descriptor_set = 0, binding = 2)] sampler_color: &spirv_std::image::SampledImage< + spirv_std::image::Image2d, + >, out_color: &mut Vec4, ) { *out_color = sampler_color.sample(in_uv); -} \ No newline at end of file +} diff --git a/shaders/rust/indirectdraw/indirectdraw/src/lib.rs b/shaders/rust/indirectdraw/indirectdraw/src/lib.rs index 80325eb28..4af69f40e 100644 --- a/shaders/rust/indirectdraw/indirectdraw/src/lib.rs +++ b/shaders/rust/indirectdraw/indirectdraw/src/lib.rs @@ -1,8 +1,8 @@ #![cfg_attr(target_arch = "spirv", no_std)] -use spirv_std::spirv; -use spirv_std::glam::{vec3, vec4, Vec2, Vec3, Vec4, Mat4}; +use spirv_std::glam::{vec3, vec4, Mat4, Vec2, Vec3, Vec4}; use spirv_std::num_traits::Float; +use spirv_std::spirv; #[repr(C)] pub struct UBO { @@ -34,45 +34,45 @@ pub fn main_vs( // rotate around x let s = instance_rot.x.sin(); let c = instance_rot.x.cos(); - + let mx = Mat4::from_cols( vec4(c, s, 0.0, 0.0), vec4(-s, c, 0.0, 0.0), vec4(0.0, 0.0, 1.0, 0.0), vec4(0.0, 0.0, 0.0, 1.0), ); - + // rotate around y let s = instance_rot.y.sin(); let c = instance_rot.y.cos(); - + let my = Mat4::from_cols( vec4(c, 0.0, s, 0.0), vec4(0.0, 1.0, 0.0, 0.0), vec4(-s, 0.0, c, 0.0), vec4(0.0, 0.0, 0.0, 1.0), ); - + // rotate around z let s = instance_rot.z.sin(); let c = instance_rot.z.cos(); - + let mz = Mat4::from_cols( vec4(1.0, 0.0, 0.0, 0.0), vec4(0.0, c, s, 0.0), vec4(0.0, -s, c, 0.0), vec4(0.0, 0.0, 0.0, 1.0), ); - + let rot_mat = mz * my * mx; - + *out_normal = (rot_mat * vec4(in_normal.x, in_normal.y, in_normal.z, 0.0)).truncate(); - + let scaled_pos = in_pos * instance_scale + instance_pos; let pos = rot_mat * vec4(scaled_pos.x, scaled_pos.y, scaled_pos.z, 1.0); - + *out_position = ubo.projection * ubo.modelview * pos; - + let l_pos = vec4(0.0, -5.0, 0.0, 1.0); *out_light_vec = l_pos.truncate() - pos.truncate(); *out_view_vec = -pos.truncate(); @@ -85,20 +85,22 @@ pub fn main_fs( in_uv: Vec3, in_view_vec: Vec3, in_light_vec: Vec3, - #[spirv(descriptor_set = 0, binding = 1)] sampler_array: &spirv_std::image::SampledImage, + #[spirv(descriptor_set = 0, binding = 1)] sampler_array: &spirv_std::image::SampledImage< + spirv_std::image::Image2dArray, + >, out_color: &mut Vec4, ) { let color = sampler_array.sample(vec3(in_uv.x, in_uv.y, in_uv.z)); - + if color.w < 0.5 { spirv_std::arch::kill(); } - + let n = in_normal.normalize(); let l = in_light_vec.normalize(); let ambient = vec3(0.65, 0.65, 0.65); let diffuse = n.dot(l).max(0.0) * in_color; - + let final_color = (ambient + diffuse) * color.truncate(); *out_color = vec4(final_color.x, final_color.y, final_color.z, 1.0); -} \ No newline at end of file +} diff --git a/shaders/rust/indirectdraw/skysphere/src/lib.rs b/shaders/rust/indirectdraw/skysphere/src/lib.rs index 553b10fd8..5e8b13846 100644 --- a/shaders/rust/indirectdraw/skysphere/src/lib.rs +++ b/shaders/rust/indirectdraw/skysphere/src/lib.rs @@ -1,7 +1,7 @@ #![cfg_attr(target_arch = "spirv", no_std)] +use spirv_std::glam::{vec4, Mat3, Mat4, Vec2, Vec3, Vec4}; use spirv_std::spirv; -use spirv_std::glam::{vec4, Vec2, Vec3, Vec4, Mat3, Mat4}; #[repr(C)] pub struct UBO { @@ -27,12 +27,14 @@ pub fn main_vs( #[spirv(fragment)] pub fn main_fs( in_uv: Vec2, - #[spirv(descriptor_set = 0, binding = 2)] _sampler_color: &spirv_std::image::SampledImage, + #[spirv(descriptor_set = 0, binding = 2)] _sampler_color: &spirv_std::image::SampledImage< + spirv_std::image::Image2d, + >, out_color: &mut Vec4, ) { const GRADIENT_START: Vec4 = vec4(0.93, 0.9, 0.81, 1.0); const GRADIENT_END: Vec4 = vec4(0.35, 0.5, 1.0, 1.0); - + let mix_factor = ((0.5 - (in_uv.y + 0.05)).min(0.5) / 0.15) + 0.5; *out_color = GRADIENT_START.lerp(GRADIENT_END, mix_factor); -} \ No newline at end of file +} diff --git a/shaders/rust/inlineuniformblocks/pbr/src/lib.rs b/shaders/rust/inlineuniformblocks/pbr/src/lib.rs index 219da76e5..0f047e745 100644 --- a/shaders/rust/inlineuniformblocks/pbr/src/lib.rs +++ b/shaders/rust/inlineuniformblocks/pbr/src/lib.rs @@ -1,8 +1,12 @@ #![cfg_attr(target_arch = "spirv", no_std)] #![allow(clippy::missing_safety_doc)] -use spirv_std::{spirv, glam::{mat3, vec3, vec4, Mat4, Vec3, Vec4}, num_traits::Float}; use core::f32::consts::PI; +use spirv_std::{ + glam::{mat3, vec3, vec4, Mat4, Vec3, Vec4}, + num_traits::Float, + spirv, +}; #[repr(C)] #[derive(Copy, Clone)] @@ -48,7 +52,8 @@ pub fn main_vs( ubo.model.z_axis.truncate(), ); *out_normal = model_mat3 * in_normal; - *out_position = ubo.projection * ubo.view * vec4(out_world_pos.x, out_world_pos.y, out_world_pos.z, 1.0); + *out_position = + ubo.projection * ubo.view * vec4(out_world_pos.x, out_world_pos.y, out_world_pos.z, 1.0); } // Normal Distribution function -------------------------------------- @@ -133,4 +138,4 @@ pub fn main_fs( color = color.powf(0.4545); *out_color = vec4(color.x, color.y, color.z, 1.0); -} \ No newline at end of file +} diff --git a/shaders/rust/inputattachments/attachmentread/src/lib.rs b/shaders/rust/inputattachments/attachmentread/src/lib.rs index 16abe4c13..1ae48178c 100644 --- a/shaders/rust/inputattachments/attachmentread/src/lib.rs +++ b/shaders/rust/inputattachments/attachmentread/src/lib.rs @@ -1,7 +1,10 @@ #![cfg_attr(target_arch = "spirv", no_std)] #![allow(clippy::missing_safety_doc)] -use spirv_std::{spirv, glam::{vec4, Vec2, Vec3, Vec4}}; +use spirv_std::{ + glam::{vec4, Vec2, Vec3, Vec4}, + spirv, +}; #[repr(C)] #[derive(Copy, Clone)] @@ -12,10 +15,7 @@ pub struct Ubo { } #[spirv(vertex)] -pub fn main_vs( - #[spirv(vertex_index)] vert_idx: i32, - #[spirv(position)] out_position: &mut Vec4, -) { +pub fn main_vs(#[spirv(vertex_index)] vert_idx: i32, #[spirv(position)] out_position: &mut Vec4) { let x = ((vert_idx << 1) & 2) as f32; let y = (vert_idx & 2) as f32; *out_position = vec4(x * 2.0 - 1.0, y * 2.0 - 1.0, 0.0, 1.0); @@ -34,15 +34,16 @@ pub fn main_fs( out_color: &mut Vec4, ) { let coord = spirv_std::glam::IVec2::new(frag_coord.x as i32, frag_coord.y as i32); - + // Apply brightness and contrast filter to color input if ubo.attachment_index == 0 { // Read color from previous color input attachment let color = input_color.read_subpass(coord).truncate(); - let adjusted = brightness_contrast(color, ubo.brightness_contrast.x, ubo.brightness_contrast.y); + let adjusted = + brightness_contrast(color, ubo.brightness_contrast.x, ubo.brightness_contrast.y); *out_color = vec4(adjusted.x, adjusted.y, adjusted.z, 1.0); } - + // Visualize depth input range if ubo.attachment_index == 1 { // Read depth from previous depth input attachment @@ -50,4 +51,4 @@ pub fn main_fs( let normalized = (depth - ubo.range.x) * (1.0 / (ubo.range.y - ubo.range.x)); *out_color = vec4(normalized, normalized, normalized, 1.0); } -} \ No newline at end of file +} diff --git a/shaders/rust/inputattachments/attachmentwrite/src/lib.rs b/shaders/rust/inputattachments/attachmentwrite/src/lib.rs index 21a222e77..1dbe74802 100644 --- a/shaders/rust/inputattachments/attachmentwrite/src/lib.rs +++ b/shaders/rust/inputattachments/attachmentwrite/src/lib.rs @@ -1,7 +1,10 @@ #![cfg_attr(target_arch = "spirv", no_std)] #![allow(clippy::missing_safety_doc)] -use spirv_std::{spirv, glam::{vec3, vec4, Mat4, Vec3, Vec4}}; +use spirv_std::{ + glam::{vec3, vec4, Mat4, Vec3, Vec4}, + spirv, +}; #[repr(C)] #[derive(Copy, Clone)] @@ -53,13 +56,13 @@ pub fn main_fs( if intensity < 0.1 { shade = 0.25; } - + *out_color = vec4( in_color.x * 3.0 * shade, in_color.y * 3.0 * shade, in_color.z * 3.0 * shade, - 1.0 + 1.0, ); - + // Depth attachment does not need to be explicitly written -} \ No newline at end of file +} diff --git a/shaders/rust/instancing/instancing/src/lib.rs b/shaders/rust/instancing/instancing/src/lib.rs index 9d6e12aed..123391b4c 100644 --- a/shaders/rust/instancing/instancing/src/lib.rs +++ b/shaders/rust/instancing/instancing/src/lib.rs @@ -1,8 +1,8 @@ #![cfg_attr(target_arch = "spirv", no_std)] -use spirv_std::spirv; use spirv_std::glam::{vec3, vec4, Mat3, Mat4, Vec2, Vec3, Vec4}; use spirv_std::num_traits::Float; +use spirv_std::spirv; #[repr(C)] pub struct UBO { @@ -37,63 +37,54 @@ pub fn main_vs( // rotate around x let s = (instance_rot.x + ubo.loc_speed).sin(); let c = (instance_rot.x + ubo.loc_speed).cos(); - - let mx = Mat3::from_cols( - vec3(c, s, 0.0), - vec3(-s, c, 0.0), - vec3(0.0, 0.0, 1.0), - ); - + + let mx = Mat3::from_cols(vec3(c, s, 0.0), vec3(-s, c, 0.0), vec3(0.0, 0.0, 1.0)); + // rotate around y let s = (instance_rot.y + ubo.loc_speed).sin(); let c = (instance_rot.y + ubo.loc_speed).cos(); - - let my = Mat3::from_cols( - vec3(c, 0.0, s), - vec3(0.0, 1.0, 0.0), - vec3(-s, 0.0, c), - ); - + + let my = Mat3::from_cols(vec3(c, 0.0, s), vec3(0.0, 1.0, 0.0), vec3(-s, 0.0, c)); + // rotate around z let s = (instance_rot.z + ubo.loc_speed).sin(); let c = (instance_rot.z + ubo.loc_speed).cos(); - - let mz = Mat3::from_cols( - vec3(1.0, 0.0, 0.0), - vec3(0.0, c, s), - vec3(0.0, -s, c), - ); - + + let mz = Mat3::from_cols(vec3(1.0, 0.0, 0.0), vec3(0.0, c, s), vec3(0.0, -s, c)); + let rot_mat = mz * my * mx; - + // Global rotation matrix let s = (instance_rot.y + ubo.glob_speed).sin(); let c = (instance_rot.y + ubo.glob_speed).cos(); - + let g_rot_mat = Mat4::from_cols( vec4(c, 0.0, s, 0.0), vec4(0.0, 1.0, 0.0, 0.0), vec4(-s, 0.0, c, 0.0), vec4(0.0, 0.0, 0.0, 1.0), ); - + let loc_pos = rot_mat * in_pos; let pos = vec4( loc_pos.x * instance_scale + instance_pos.x, loc_pos.y * instance_scale + instance_pos.y, loc_pos.z * instance_scale + instance_pos.z, - 1.0 + 1.0, ); - + *out_position = ubo.projection * ubo.modelview * g_rot_mat * pos; - *out_normal = ubo.modelview.transform_vector3(g_rot_mat.transform_vector3(rot_mat.inverse() * in_normal)); - - let pos = ubo.modelview * vec4( - in_pos.x + instance_pos.x, - in_pos.y + instance_pos.y, - in_pos.z + instance_pos.z, - 1.0 - ); + *out_normal = ubo + .modelview + .transform_vector3(g_rot_mat.transform_vector3(rot_mat.inverse() * in_normal)); + + let pos = ubo.modelview + * vec4( + in_pos.x + instance_pos.x, + in_pos.y + instance_pos.y, + in_pos.z + instance_pos.z, + 1.0, + ); let l_pos = ubo.modelview.transform_vector3(ubo.light_pos.truncate()); *out_light_vec = l_pos - pos.truncate(); *out_view_vec = -pos.truncate(); @@ -111,26 +102,29 @@ pub fn main_fs( in_uv: Vec3, in_view_vec: Vec3, in_light_vec: Vec3, - #[spirv(descriptor_set = 0, binding = 1)] sampler_array: &spirv_std::image::SampledImage, + #[spirv(descriptor_set = 0, binding = 1)] sampler_array: &spirv_std::image::SampledImage< + spirv_std::image::Image2dArray, + >, out_color: &mut Vec4, ) { - let color = sampler_array.sample(vec3(in_uv.x, in_uv.y, in_uv.z)) * vec4(in_color.x, in_color.y, in_color.z, 1.0); + let color = sampler_array.sample(vec3(in_uv.x, in_uv.y, in_uv.z)) + * vec4(in_color.x, in_color.y, in_color.z, 1.0); let n = in_normal.normalize(); let l = in_light_vec.normalize(); let v = in_view_vec.normalize(); let r = reflect(-l, n); - + let diffuse = n.dot(l).max(0.1) * in_color; let specular = if n.dot(l) > 0.0 { r.dot(v).max(0.0).powf(16.0) * vec3(0.75, 0.75, 0.75) * color.x } else { Vec3::ZERO }; - + *out_color = vec4( diffuse.x * color.x + specular.x, diffuse.y * color.y + specular.y, diffuse.z * color.z + specular.z, - 1.0 + 1.0, ); -} \ No newline at end of file +} diff --git a/shaders/rust/instancing/planet/src/lib.rs b/shaders/rust/instancing/planet/src/lib.rs index b108cc391..7133693b6 100644 --- a/shaders/rust/instancing/planet/src/lib.rs +++ b/shaders/rust/instancing/planet/src/lib.rs @@ -1,8 +1,8 @@ #![cfg_attr(target_arch = "spirv", no_std)] -use spirv_std::spirv; use spirv_std::glam::{vec3, vec4, Mat4, Vec2, Vec3, Vec4}; use spirv_std::num_traits::Float; +use spirv_std::spirv; #[repr(C)] pub struct UBO { @@ -28,7 +28,7 @@ pub fn main_vs( *out_color = in_color; *out_uv = in_uv; *out_position = ubo.projection * ubo.modelview * vec4(in_pos.x, in_pos.y, in_pos.z, 1.0); - + let pos = ubo.modelview * vec4(in_pos.x, in_pos.y, in_pos.z, 1.0); *out_normal = ubo.modelview.transform_vector3(in_normal); let l_pos = ubo.modelview.transform_vector3(ubo.light_pos.truncate()); @@ -48,22 +48,25 @@ pub fn main_fs( in_uv: Vec2, in_view_vec: Vec3, in_light_vec: Vec3, - #[spirv(descriptor_set = 0, binding = 1)] sampler_color_map: &spirv_std::image::SampledImage, + #[spirv(descriptor_set = 0, binding = 1)] sampler_color_map: &spirv_std::image::SampledImage< + spirv_std::image::Image2d, + >, out_color: &mut Vec4, ) { - let color = sampler_color_map.sample(in_uv) * vec4(in_color.x, in_color.y, in_color.z, 1.0) * 1.5; + let color = + sampler_color_map.sample(in_uv) * vec4(in_color.x, in_color.y, in_color.z, 1.0) * 1.5; let n = in_normal.normalize(); let l = in_light_vec.normalize(); let v = in_view_vec.normalize(); let r = reflect(-l, n); - + let diffuse = n.dot(l).max(0.0) * in_color; let specular = r.dot(v).max(0.0).powf(4.0) * vec3(0.5, 0.5, 0.5) * color.x; - + *out_color = vec4( diffuse.x * color.x + specular.x, diffuse.y * color.y + specular.y, diffuse.z * color.z + specular.z, - 1.0 + 1.0, ); -} \ No newline at end of file +} diff --git a/shaders/rust/instancing/starfield/src/lib.rs b/shaders/rust/instancing/starfield/src/lib.rs index af41d81a8..c6eb968c4 100644 --- a/shaders/rust/instancing/starfield/src/lib.rs +++ b/shaders/rust/instancing/starfield/src/lib.rs @@ -1,8 +1,8 @@ #![cfg_attr(target_arch = "spirv", no_std)] -use spirv_std::spirv; use spirv_std::glam::{vec3, vec4, Vec3, Vec4}; use spirv_std::num_traits::Float; +use spirv_std::spirv; #[spirv(vertex)] pub fn main_vs( @@ -16,12 +16,7 @@ pub fn main_vs( (vertex_index & 2) as f32, (vertex_index & 2) as f32, ); - *out_position = vec4( - out_uvw.x * 2.0 - 1.0, - out_uvw.y * 2.0 - 1.0, - 0.0, - 1.0, - ); + *out_position = vec4(out_uvw.x * 2.0 - 1.0, out_uvw.y * 2.0 - 1.0, 0.0, 1.0); } const HASHSCALE3: Vec3 = Vec3::new(443.897, 441.423, 437.195); @@ -50,10 +45,7 @@ fn star_field(pos: Vec3) -> Vec3 { } #[spirv(fragment)] -pub fn main_fs( - in_uvw: Vec3, - out_color: &mut Vec4, -) { +pub fn main_fs(in_uvw: Vec3, out_color: &mut Vec4) { let color = star_field(in_uvw); *out_color = vec4(color.x, color.y, color.z, 1.0); -} \ No newline at end of file +} diff --git a/shaders/rust/meshshader/meshshader/src/lib.rs b/shaders/rust/meshshader/meshshader/src/lib.rs index 7af385f12..36879fd0f 100644 --- a/shaders/rust/meshshader/meshshader/src/lib.rs +++ b/shaders/rust/meshshader/meshshader/src/lib.rs @@ -64,9 +64,6 @@ pub fn main_mesh( } #[spirv(fragment)] -pub fn main_fs( - in_color: Vec3, - out_frag_color: &mut Vec4, -) { +pub fn main_fs(in_color: Vec3, out_frag_color: &mut Vec4) { *out_frag_color = vec4(in_color.x, in_color.y, in_color.z, 1.0); -} \ No newline at end of file +} diff --git a/shaders/rust/multisampling/mesh/src/lib.rs b/shaders/rust/multisampling/mesh/src/lib.rs index 9dcc895bd..a1b9a7190 100644 --- a/shaders/rust/multisampling/mesh/src/lib.rs +++ b/shaders/rust/multisampling/mesh/src/lib.rs @@ -1,8 +1,12 @@ #![cfg_attr(target_arch = "spirv", no_std)] #![allow(clippy::missing_safety_doc)] -use spirv_std::{spirv, glam::{mat3, vec3, vec4, Mat4, Vec2, Vec3, Vec4}, Image, num_traits::Float}; use spirv_std::image::SampledImage; +use spirv_std::{ + glam::{mat3, vec3, vec4, Mat4, Vec2, Vec3, Vec4}, + num_traits::Float, + spirv, Image, +}; #[repr(C)] #[derive(Copy, Clone)] @@ -50,7 +54,9 @@ pub fn main_fs( in_uv: Vec2, _in_view_vec: Vec3, in_light_vec: Vec3, - #[spirv(descriptor_set = 1, binding = 0)] color_sampler: &SampledImage, + #[spirv(descriptor_set = 1, binding = 0)] color_sampler: &SampledImage< + Image!(2D, type=f32, sampled), + >, out_frag_color: &mut Vec4, ) { let color = color_sampler.sample(in_uv) * vec4(in_color.x, in_color.y, in_color.z, 1.0); @@ -59,12 +65,12 @@ pub fn main_fs( let l = in_light_vec.normalize(); let v = _in_view_vec.normalize(); let r = (-l).reflect(n); - + let diffuse = n.dot(l).max(0.15) * in_color; - + let spec_power = r.dot(v).max(0.0); let specular = spec_power.powf(16.0) * vec3(0.75, 0.75, 0.75); let final_color = diffuse * color.truncate() + specular; *out_frag_color = vec4(final_color.x, final_color.y, final_color.z, 1.0); -} \ No newline at end of file +} diff --git a/shaders/rust/multithreading/phong/src/lib.rs b/shaders/rust/multithreading/phong/src/lib.rs index 7f58333bd..81b2c462c 100644 --- a/shaders/rust/multithreading/phong/src/lib.rs +++ b/shaders/rust/multithreading/phong/src/lib.rs @@ -1,7 +1,11 @@ #![cfg_attr(target_arch = "spirv", no_std)] #![allow(clippy::missing_safety_doc)] -use spirv_std::{spirv, glam::{mat3, vec3, vec4, Mat4, Vec3, Vec4}, num_traits::Float}; +use spirv_std::{ + glam::{mat3, vec3, vec4, Mat4, Vec3, Vec4}, + num_traits::Float, + spirv, +}; #[repr(C)] #[derive(Copy, Clone)] @@ -30,9 +34,9 @@ pub fn main_vs( } else { *out_color = in_color; } - + *out_position = push_consts.mvp * vec4(in_pos.x, in_pos.y, in_pos.z, 1.0); - + let pos = push_consts.mvp * vec4(in_pos.x, in_pos.y, in_pos.z, 1.0); let mvp_mat3 = mat3( push_consts.mvp.x_axis.truncate(), @@ -59,5 +63,10 @@ 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(0.75, 0.75, 0.75); - *out_frag_color = vec4(diffuse.x + specular.x, diffuse.y + specular.y, diffuse.z + specular.z, 1.0); -} \ No newline at end of file + *out_frag_color = vec4( + diffuse.x + specular.x, + diffuse.y + specular.y, + diffuse.z + specular.z, + 1.0, + ); +} diff --git a/shaders/rust/multithreading/starsphere/src/lib.rs b/shaders/rust/multithreading/starsphere/src/lib.rs index ddd5a3365..284e8ba87 100644 --- a/shaders/rust/multithreading/starsphere/src/lib.rs +++ b/shaders/rust/multithreading/starsphere/src/lib.rs @@ -1,7 +1,11 @@ #![cfg_attr(target_arch = "spirv", no_std)] #![allow(clippy::missing_safety_doc)] -use spirv_std::{spirv, glam::{vec3, vec4, Mat4, Vec3, Vec4}, num_traits::Float}; +use spirv_std::{ + glam::{vec3, vec4, Mat4, Vec3, Vec4}, + num_traits::Float, + spirv, +}; #[repr(C)] #[derive(Copy, Clone)] @@ -42,19 +46,16 @@ fn star_field(pos: Vec3) -> Vec3 { } #[spirv(fragment)] -pub fn main_fs( - in_uvw: Vec3, - out_frag_color: &mut Vec4, -) { +pub fn main_fs(in_uvw: Vec3, out_frag_color: &mut Vec4) { // Fake atmosphere at the bottom let atmosphere = vec3(0.1, 0.15, 0.4) * (in_uvw.y + 0.25); let atmosphere = vec3( atmosphere.x.clamp(0.0, 1.0), atmosphere.y.clamp(0.0, 1.0), - atmosphere.z.clamp(0.0, 1.0) + atmosphere.z.clamp(0.0, 1.0), ); let color = star_field(in_uvw) + atmosphere; - + *out_frag_color = vec4(color.x, color.y, color.z, 1.0); -} \ No newline at end of file +} diff --git a/shaders/rust/multiview/multiview/src/lib.rs b/shaders/rust/multiview/multiview/src/lib.rs index 4b402f73e..a7f1effe1 100644 --- a/shaders/rust/multiview/multiview/src/lib.rs +++ b/shaders/rust/multiview/multiview/src/lib.rs @@ -1,7 +1,11 @@ #![cfg_attr(target_arch = "spirv", no_std)] #![allow(clippy::missing_safety_doc)] -use spirv_std::{spirv, glam::{vec3, vec4, Mat3, Mat4, Vec3, Vec4}, num_traits::Float}; +use spirv_std::{ + glam::{vec3, vec4, Mat3, Mat4, Vec3, Vec4}, + num_traits::Float, + spirv, +}; #[repr(C)] #[derive(Copy, Clone)] @@ -29,7 +33,7 @@ pub fn main_vs( let pos = vec4(in_pos.x, in_pos.y, in_pos.z, 1.0); let world_pos = ubo.modelview[view_index as usize] * pos; - + let l_pos = ubo.modelview[view_index as usize] * ubo.light_pos; *out_light_vec = vec3(l_pos.x, l_pos.y, l_pos.z) - vec3(world_pos.x, world_pos.y, world_pos.z); *out_view_vec = -vec3(world_pos.x, world_pos.y, world_pos.z); @@ -56,6 +60,6 @@ pub fn main_fs( (ambient.x + diffuse.x) * in_color.x + specular.x, (ambient.y + diffuse.y) * in_color.y + specular.y, (ambient.z + diffuse.z) * in_color.z + specular.z, - 1.0 + 1.0, ); -} \ No newline at end of file +} diff --git a/shaders/rust/multiview/viewdisplay/src/lib.rs b/shaders/rust/multiview/viewdisplay/src/lib.rs index 5c02c76e0..bc8c7b799 100644 --- a/shaders/rust/multiview/viewdisplay/src/lib.rs +++ b/shaders/rust/multiview/viewdisplay/src/lib.rs @@ -1,7 +1,11 @@ #![cfg_attr(target_arch = "spirv", no_std)] #![allow(clippy::missing_safety_doc)] -use spirv_std::{spirv, glam::{vec2, vec3, vec4, Vec2, Vec4}, Image, image::SampledImage}; +use spirv_std::{ + glam::{vec2, vec3, vec4, Vec2, Vec4}, + image::SampledImage, + spirv, Image, +}; #[repr(C)] #[derive(Copy, Clone)] @@ -10,17 +14,13 @@ pub struct Ubo { pub distortion_alpha: f32, } - #[spirv(vertex)] pub fn main_vs( #[spirv(vertex_index)] vertex_index: i32, #[spirv(position)] out_position: &mut Vec4, out_uv: &mut Vec2, ) { - *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); let pos_xy = *out_uv * 2.0 - vec2(1.0, 1.0); *out_position = vec4(pos_xy.x, pos_xy.y, 0.0, 1.0); } @@ -28,7 +28,9 @@ pub fn main_vs( #[spirv(fragment)] pub fn main_fs( in_uv: Vec2, - #[spirv(descriptor_set = 0, binding = 1)] sampler_view: &SampledImage, + #[spirv(descriptor_set = 0, binding = 1)] sampler_view: &SampledImage< + Image!(2D, type=f32, sampled, arrayed), + >, #[spirv(uniform, descriptor_set = 0, binding = 0)] ubo: &Ubo, #[spirv(spec_constant(id = 0, default = 0))] view_layer: u32, out_color: &mut Vec4, @@ -46,4 +48,4 @@ pub fn main_fs( } else { vec4(0.0, 0.0, 0.0, 0.0) }; -} \ No newline at end of file +} diff --git a/shaders/rust/negativeviewportheight/quad/src/lib.rs b/shaders/rust/negativeviewportheight/quad/src/lib.rs index abf11e849..e1255d064 100644 --- a/shaders/rust/negativeviewportheight/quad/src/lib.rs +++ b/shaders/rust/negativeviewportheight/quad/src/lib.rs @@ -1,8 +1,11 @@ #![cfg_attr(target_arch = "spirv", no_std)] #![allow(clippy::missing_safety_doc)] -use spirv_std::{spirv, glam::{vec4, Vec2, Vec3, Vec4}, Image}; use spirv_std::image::SampledImage; +use spirv_std::{ + glam::{vec4, Vec2, Vec3, Vec4}, + spirv, Image, +}; #[spirv(vertex)] pub fn main_vs( @@ -18,7 +21,9 @@ pub fn main_vs( #[spirv(fragment)] pub fn main_fs( in_uv: Vec2, - #[spirv(descriptor_set = 0, binding = 0)] sampler_color: &SampledImage, + #[spirv(descriptor_set = 0, binding = 0)] sampler_color: &SampledImage< + Image!(2D, type=f32, sampled), + >, out_color: &mut Vec4, ) { *out_color = sampler_color.sample(in_uv); diff --git a/shaders/rust/occlusionquery/mesh/src/lib.rs b/shaders/rust/occlusionquery/mesh/src/lib.rs index 0e05be3a2..29e27f3eb 100644 --- a/shaders/rust/occlusionquery/mesh/src/lib.rs +++ b/shaders/rust/occlusionquery/mesh/src/lib.rs @@ -1,7 +1,11 @@ #![cfg_attr(target_arch = "spirv", no_std)] #![allow(clippy::missing_safety_doc)] -use spirv_std::{spirv, glam::{vec3, vec4, Mat3, Mat4, Vec3, Vec4}, num_traits::Float}; +use spirv_std::{ + glam::{vec3, vec4, Mat3, Mat4, Vec3, Vec4}, + num_traits::Float, + spirv, +}; #[repr(C)] #[derive(Copy, Clone)] @@ -30,9 +34,9 @@ pub fn main_vs( *out_normal = in_normal; *out_color = in_color * ubo.color.truncate(); *out_visible = ubo.visible; - + *out_position = ubo.projection * ubo.view * ubo.model * vec4(in_pos.x, in_pos.y, in_pos.z, 1.0); - + let pos = ubo.model * vec4(in_pos.x, in_pos.y, in_pos.z, 1.0); let model_mat3 = Mat3::from_cols( ubo.model.x_axis.truncate(), @@ -60,8 +64,13 @@ pub fn main_fs( let r = (-l).reflect(n); let diffuse = n.dot(l).max(0.25) * in_color; let specular = r.dot(v).max(0.0).powf(8.0) * vec3(0.75, 0.75, 0.75); - *out_frag_color = vec4(diffuse.x + specular.x, diffuse.y + specular.y, diffuse.z + specular.z, 1.0); + *out_frag_color = vec4( + diffuse.x + specular.x, + diffuse.y + specular.y, + diffuse.z + specular.z, + 1.0, + ); } else { *out_frag_color = vec4(0.1, 0.1, 0.1, 1.0); } -} \ No newline at end of file +} diff --git a/shaders/rust/occlusionquery/occluder/src/lib.rs b/shaders/rust/occlusionquery/occluder/src/lib.rs index ec79fe76e..a87e3e0bd 100644 --- a/shaders/rust/occlusionquery/occluder/src/lib.rs +++ b/shaders/rust/occlusionquery/occluder/src/lib.rs @@ -1,7 +1,10 @@ #![cfg_attr(target_arch = "spirv", no_std)] #![allow(clippy::missing_safety_doc)] -use spirv_std::{spirv, glam::{vec4, Mat4, Vec3, Vec4}}; +use spirv_std::{ + glam::{vec4, Mat4, Vec3, Vec4}, + spirv, +}; #[repr(C)] #[derive(Copy, Clone)] @@ -27,9 +30,6 @@ pub fn main_vs( } #[spirv(fragment)] -pub fn main_fs( - in_color: Vec3, - out_frag_color: &mut Vec4, -) { +pub fn main_fs(in_color: Vec3, out_frag_color: &mut Vec4) { *out_frag_color = vec4(in_color.x, in_color.y, in_color.z, 0.5); -} \ No newline at end of file +} diff --git a/shaders/rust/occlusionquery/simple/src/lib.rs b/shaders/rust/occlusionquery/simple/src/lib.rs index 620e2ffbb..ad330e54a 100644 --- a/shaders/rust/occlusionquery/simple/src/lib.rs +++ b/shaders/rust/occlusionquery/simple/src/lib.rs @@ -1,7 +1,10 @@ #![cfg_attr(target_arch = "spirv", no_std)] #![allow(clippy::missing_safety_doc)] -use spirv_std::{spirv, glam::{vec4, Mat4, Vec3, Vec4}}; +use spirv_std::{ + glam::{vec4, Mat4, Vec3, Vec4}, + spirv, +}; #[repr(C)] #[derive(Copy, Clone)] @@ -24,9 +27,6 @@ pub fn main_vs( } #[spirv(fragment)] -pub fn main_fs( - _in_color: Vec3, - out_frag_color: &mut Vec4, -) { +pub fn main_fs(_in_color: Vec3, out_frag_color: &mut Vec4) { *out_frag_color = vec4(1.0, 1.0, 1.0, 1.0); -} \ No newline at end of file +} diff --git a/shaders/rust/parallaxmapping/parallax/src/lib.rs b/shaders/rust/parallaxmapping/parallax/src/lib.rs index 50bbb47d7..e7386afc6 100644 --- a/shaders/rust/parallaxmapping/parallax/src/lib.rs +++ b/shaders/rust/parallaxmapping/parallax/src/lib.rs @@ -1,9 +1,9 @@ #![no_std] +use spirv_std::glam::{Mat3, Mat4, Vec2, Vec3, Vec3Swizzles, Vec4, Vec4Swizzles}; +use spirv_std::num_traits::Float; use spirv_std::spirv; -use spirv_std::glam::{Mat3, Mat4, Vec2, Vec3, Vec4, Vec4Swizzles, Vec3Swizzles}; use spirv_std::{Image, Sampler}; -use spirv_std::num_traits::Float; #[repr(C)] #[derive(Copy, Clone)] @@ -38,33 +38,46 @@ pub fn main_vs( out_tangent_view_pos: &mut Vec3, out_tangent_frag_pos: &mut Vec3, ) { - *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); let frag_pos = (ubo.model * Vec4::new(in_pos.x, in_pos.y, in_pos.z, 1.0)).xyz(); *out_uv = in_uv; - + let model_mat3 = Mat3::from_mat4(ubo.model); let n = (model_mat3 * in_normal).normalize(); let t = (model_mat3 * in_tangent.xyz()).normalize(); let b = n.cross(t).normalize(); let tbn = Mat3::from_cols(t, b, n).transpose(); - + *out_tangent_light_pos = tbn * ubo.light_pos.xyz(); *out_tangent_view_pos = tbn * ubo.camera_pos.xyz(); *out_tangent_frag_pos = tbn * frag_pos; } -fn parallax_mapping(uv: Vec2, view_dir: Vec3, normal_height_map: &Image!(2D, type=f32, sampled), sampler: &Sampler, ubo: &FragmentUBO) -> Vec2 { +fn parallax_mapping( + uv: Vec2, + view_dir: Vec3, + normal_height_map: &Image!(2D, type=f32, sampled), + sampler: &Sampler, + ubo: &FragmentUBO, +) -> Vec2 { let height = 1.0 - normal_height_map.sample_by_lod(*sampler, uv, 0.0).w; let p = view_dir.xy() * (height * (ubo.height_scale * 0.5) + ubo.parallax_bias) / view_dir.z; uv - p } -fn steep_parallax_mapping(uv: Vec2, view_dir: Vec3, normal_height_map: &Image!(2D, type=f32, sampled), sampler: &Sampler, ubo: &FragmentUBO) -> Vec2 { +fn steep_parallax_mapping( + uv: Vec2, + view_dir: Vec3, + normal_height_map: &Image!(2D, type=f32, sampled), + sampler: &Sampler, + ubo: &FragmentUBO, +) -> Vec2 { let layer_depth = 1.0 / ubo.num_layers; let mut curr_layer_depth = 0.0; let delta_uv = view_dir.xy() * ubo.height_scale / (view_dir.z * ubo.num_layers); let mut curr_uv = uv; - + for _ in 0..(ubo.num_layers as i32) { curr_layer_depth += layer_depth; curr_uv -= delta_uv; @@ -76,13 +89,19 @@ fn steep_parallax_mapping(uv: Vec2, view_dir: Vec3, normal_height_map: &Image!(2 curr_uv } -fn parallax_occlusion_mapping(uv: Vec2, view_dir: Vec3, normal_height_map: &Image!(2D, type=f32, sampled), sampler: &Sampler, ubo: &FragmentUBO) -> Vec2 { +fn parallax_occlusion_mapping( + uv: Vec2, + view_dir: Vec3, + normal_height_map: &Image!(2D, type=f32, sampled), + sampler: &Sampler, + ubo: &FragmentUBO, +) -> Vec2 { let layer_depth = 1.0 / ubo.num_layers; let mut curr_layer_depth = 0.0; let delta_uv = view_dir.xy() * ubo.height_scale / (view_dir.z * ubo.num_layers); let mut curr_uv = uv; let mut height = 1.0 - normal_height_map.sample_by_lod(*sampler, curr_uv, 0.0).w; - + for _ in 0..(ubo.num_layers as i32) { curr_layer_depth += layer_depth; curr_uv -= delta_uv; @@ -91,10 +110,12 @@ fn parallax_occlusion_mapping(uv: Vec2, view_dir: Vec3, normal_height_map: &Imag break; } } - + let prev_uv = curr_uv + delta_uv; let next_depth = height - curr_layer_depth; - let prev_depth = 1.0 - normal_height_map.sample_by_lod(*sampler, prev_uv, 0.0).w - curr_layer_depth + layer_depth; + let prev_depth = + 1.0 - normal_height_map.sample_by_lod(*sampler, prev_uv, 0.0).w - curr_layer_depth + + layer_depth; prev_uv.lerp(curr_uv, next_depth / (next_depth - prev_depth)) } @@ -113,7 +134,7 @@ pub fn main_fs( ) { let v = (in_tangent_view_pos - in_tangent_frag_pos).normalize(); let mut uv = in_uv; - + if ubo.mapping_mode == 0 { // Color only *out_color = color_map.sample(*color_sampler, in_uv); @@ -124,29 +145,31 @@ pub fn main_fs( 4 => uv = parallax_occlusion_mapping(in_uv, v, normal_height_map, normal_sampler, ubo), _ => {} } - + // Perform sampling before (potentially) discarding - let normal_height_map_lod = normal_height_map.sample_by_lod(*normal_sampler, uv, 0.0).xyz(); + let normal_height_map_lod = normal_height_map + .sample_by_lod(*normal_sampler, uv, 0.0) + .xyz(); let color = color_map.sample(*color_sampler, uv).xyz(); - + // Discard fragments at texture border if uv.x < 0.0 || uv.x > 1.0 || uv.y < 0.0 || uv.y > 1.0 { spirv_std::arch::kill(); } - + let n = (normal_height_map_lod * 2.0 - 1.0).normalize(); let l = (in_tangent_light_pos - in_tangent_frag_pos).normalize(); let h = (l + v).normalize(); - + let ambient = 0.2 * color; let diffuse = l.dot(n).max(0.0) * color; let specular = Vec3::splat(0.15) * n.dot(h).max(0.0).powf(32.0); - + *out_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, ); } -} \ No newline at end of file +} diff --git a/shaders/rust/particlesystem/normalmap/src/lib.rs b/shaders/rust/particlesystem/normalmap/src/lib.rs index 601b230ac..2fdd5a943 100644 --- a/shaders/rust/particlesystem/normalmap/src/lib.rs +++ b/shaders/rust/particlesystem/normalmap/src/lib.rs @@ -1,7 +1,11 @@ #![cfg_attr(target_arch = "spirv", no_std)] #![allow(clippy::missing_safety_doc)] -use spirv_std::{spirv, glam::{mat3, vec3, vec4, Mat4, Vec2, Vec3, Vec4}, num_traits::Float}; +use spirv_std::{ + glam::{mat3, vec3, vec4, Mat4, Vec2, Vec3, Vec4}, + num_traits::Float, + spirv, +}; #[repr(C)] #[derive(Copy, Clone)] @@ -28,9 +32,9 @@ pub fn main_vs( ) { let vertex_position = (ubo.model * vec4(in_pos.x, in_pos.y, in_pos.z, 1.0)).truncate(); *out_light_dir = (ubo.light_pos.truncate() - vertex_position).normalize(); - + let bi_tangent = in_normal.cross(in_tangent.truncate()); - + // Setup (t)angent-(b)inormal-(n)ormal matrix for converting // object coordinates into tangent space let normal_mat3 = mat3( @@ -41,26 +45,26 @@ pub fn main_vs( let tbn_matrix = mat3( normal_mat3 * in_tangent.truncate(), normal_mat3 * bi_tangent, - normal_mat3 * in_normal + normal_mat3 * in_normal, ); - + *out_light_vec = tbn_matrix.transpose() * (ubo.light_pos.truncate() - vertex_position); - + let light_dist = ubo.light_pos.truncate() - in_pos; *out_light_vec_b = vec3( in_tangent.truncate().dot(light_dist), bi_tangent.dot(light_dist), - in_normal.dot(light_dist) + in_normal.dot(light_dist), ); - + *out_view_vec = vec3( in_tangent.truncate().dot(in_pos), bi_tangent.dot(in_pos), - in_normal.dot(in_pos) + in_normal.dot(in_pos), ); - + *out_uv = in_uv; - + *out_position = ubo.projection * ubo.model * vec4(in_pos.x, in_pos.y, in_pos.z, 1.0); } @@ -73,30 +77,36 @@ pub fn main_fs( in_light_vec_b: Vec3, _in_light_dir: Vec3, in_view_vec: Vec3, - #[spirv(descriptor_set = 0, binding = 1)] s_color_map: &spirv_std::image::SampledImage, - #[spirv(descriptor_set = 0, binding = 2)] s_normal_height_map: &spirv_std::image::SampledImage, + #[spirv(descriptor_set = 0, binding = 1)] s_color_map: &spirv_std::image::SampledImage< + spirv_std::Image!(2D, type=f32, sampled), + >, + #[spirv(descriptor_set = 0, binding = 2)] s_normal_height_map: &spirv_std::image::SampledImage< + spirv_std::Image!(2D, type=f32, sampled), + >, out_frag_color: &mut Vec4, ) { let specular_color = vec3(0.85, 0.5, 0.0); - + let inv_radius = 1.0 / LIGHT_RADIUS; let ambient = 0.25; - + let rgb = s_color_map.sample(in_uv).truncate(); let normal = ((s_normal_height_map.sample(in_uv).truncate() - 0.5) * 2.0).normalize(); - + let dist_sqr = in_light_vec_b.dot(in_light_vec_b); let l_vec = in_light_vec_b * (1.0 / dist_sqr.sqrt()); - - let atten = (1.0 - inv_radius * dist_sqr.sqrt()).clamp(0.0, 1.0).max(ambient); + + let atten = (1.0 - inv_radius * dist_sqr.sqrt()) + .clamp(0.0, 1.0) + .max(ambient); let diffuse = l_vec.dot(normal).clamp(0.0, 1.0); - + let light = (-in_light_vec).normalize(); let view = in_view_vec.normalize(); let reflect_dir = (-light).reflect(normal); - + let specular = view.dot(reflect_dir).max(0.0).powf(4.0); - + let final_color = (rgb * atten + (diffuse * rgb + 0.5 * specular * specular_color)) * atten; *out_frag_color = vec4(final_color.x, final_color.y, final_color.z, 1.0); -} \ No newline at end of file +} diff --git a/shaders/rust/particlesystem/particle/src/lib.rs b/shaders/rust/particlesystem/particle/src/lib.rs index 9a2f6f440..d83bac63f 100644 --- a/shaders/rust/particlesystem/particle/src/lib.rs +++ b/shaders/rust/particlesystem/particle/src/lib.rs @@ -1,7 +1,11 @@ #![cfg_attr(target_arch = "spirv", no_std)] #![allow(clippy::missing_safety_doc)] -use spirv_std::{spirv, glam::{vec4, Mat4, Vec2, Vec4}, num_traits::Float}; +use spirv_std::{ + glam::{vec4, Mat4, Vec2, Vec4}, + num_traits::Float, + spirv, +}; #[repr(C)] #[derive(Copy, Clone)] @@ -32,15 +36,16 @@ pub fn main_vs( *out_alpha = in_alpha; *out_type = in_type; *out_rotation = in_rotation; - + *out_position = ubo.projection * ubo.modelview * vec4(in_pos.x, in_pos.y, in_pos.z, 1.0); - + // Base size of the point sprites let sprite_size = 8.0 * in_size; - + // Scale particle size depending on camera projection let eye_pos = ubo.modelview * vec4(in_pos.x, in_pos.y, in_pos.z, 1.0); - let projected_corner = ubo.projection * vec4(0.5 * sprite_size, 0.5 * sprite_size, eye_pos.z, eye_pos.w); + let projected_corner = + ubo.projection * vec4(0.5 * sprite_size, 0.5 * sprite_size, eye_pos.z, eye_pos.w); *out_point_size = ubo.viewport_dim.x * projected_corner.x / projected_corner.w; } @@ -51,21 +56,32 @@ pub fn main_fs( in_alpha: f32, #[spirv(flat)] in_type: i32, in_rotation: f32, - #[spirv(descriptor_set = 0, binding = 1)] sampler_smoke: &spirv_std::image::SampledImage, - #[spirv(descriptor_set = 0, binding = 2)] sampler_fire: &spirv_std::image::SampledImage, + #[spirv(descriptor_set = 0, binding = 1)] sampler_smoke: &spirv_std::image::SampledImage< + spirv_std::Image!(2D, type=f32, sampled), + >, + #[spirv(descriptor_set = 0, binding = 2)] sampler_fire: &spirv_std::image::SampledImage< + spirv_std::Image!(2D, type=f32, sampled), + >, out_frag_color: &mut Vec4, ) { - let alpha = if in_alpha <= 1.0 { in_alpha } else { 2.0 - in_alpha }; - + let alpha = if in_alpha <= 1.0 { + in_alpha + } else { + 2.0 - in_alpha + }; + // Rotate texture coordinates let rot_center = 0.5; let rot_cos = in_rotation.cos(); let rot_sin = in_rotation.sin(); let rot_uv = Vec2::new( - rot_cos * (point_coord.x - rot_center) + rot_sin * (point_coord.y - rot_center) + rot_center, - rot_cos * (point_coord.y - rot_center) - rot_sin * (point_coord.x - rot_center) + rot_center + rot_cos * (point_coord.x - rot_center) + + rot_sin * (point_coord.y - rot_center) + + rot_center, + rot_cos * (point_coord.y - rot_center) - rot_sin * (point_coord.x - rot_center) + + rot_center, ); - + let color = if in_type == 0 { // Flame let c = sampler_fire.sample(rot_uv); @@ -77,11 +93,11 @@ pub fn main_fs( out_frag_color.w = c.w * alpha; c }; - + *out_frag_color = vec4( color.x * in_color.x * alpha, color.y * in_color.y * alpha, color.z * in_color.z * alpha, - out_frag_color.w + out_frag_color.w, ); -} \ No newline at end of file +} diff --git a/shaders/rust/pbrbasic/pbr/src/lib.rs b/shaders/rust/pbrbasic/pbr/src/lib.rs index 14a748d16..0b0d3dc71 100644 --- a/shaders/rust/pbrbasic/pbr/src/lib.rs +++ b/shaders/rust/pbrbasic/pbr/src/lib.rs @@ -1,8 +1,12 @@ #![cfg_attr(target_arch = "spirv", no_std)] #![allow(clippy::missing_safety_doc)] -use spirv_std::{spirv, glam::{vec3, vec4, Mat3, Mat4, Vec3, Vec4, Vec4Swizzles}, num_traits::Float}; use core::f32::consts::PI; +use spirv_std::{ + glam::{vec3, vec4, Mat3, Mat4, Vec3, Vec4, Vec4Swizzles}, + num_traits::Float, + spirv, +}; #[repr(C)] #[derive(Copy, Clone)] @@ -49,7 +53,8 @@ pub fn main_vs( let loc_pos = (ubo.model * vec4(in_pos.x, in_pos.y, in_pos.z, 1.0)).xyz(); *out_world_pos = loc_pos + push_consts.obj_pos; *out_normal = Mat3::from_mat4(ubo.model) * in_normal; - *out_position = ubo.projection * ubo.view * vec4(out_world_pos.x, out_world_pos.y, out_world_pos.z, 1.0); + *out_position = + ubo.projection * ubo.view * vec4(out_world_pos.x, out_world_pos.y, out_world_pos.z, 1.0); } fn material_color(material: &FragmentPushConsts) -> Vec3 { @@ -80,7 +85,14 @@ fn f_schlick(cos_theta: f32, metallic: f32, material: &FragmentPushConsts) -> Ve } // Specular BRDF composition -fn brdf(l: Vec3, v: Vec3, n: Vec3, metallic: f32, roughness: f32, material: &FragmentPushConsts) -> Vec3 { +fn brdf( + l: Vec3, + v: Vec3, + n: Vec3, + metallic: f32, + roughness: f32, + material: &FragmentPushConsts, +) -> Vec3 { // Precalculate vectors and dot products let h = (v + l).normalize(); let dot_nv = n.dot(v).clamp(0.0, 1.0); @@ -139,4 +151,4 @@ pub fn main_fs( color = color.powf(0.4545); *out_color = vec4(color.x, color.y, color.z, 1.0); -} \ No newline at end of file +} diff --git a/shaders/rust/pbribl/filtercube/src/lib.rs b/shaders/rust/pbribl/filtercube/src/lib.rs index 94c004be3..c4448727f 100644 --- a/shaders/rust/pbribl/filtercube/src/lib.rs +++ b/shaders/rust/pbribl/filtercube/src/lib.rs @@ -19,4 +19,4 @@ pub fn main_vs( ) { *out_uvw = in_pos; *out_pos = push_consts.mvp * vec4(in_pos.x, in_pos.y, in_pos.z, 1.0); -} \ No newline at end of file +} diff --git a/shaders/rust/pbribl/genbrdflut/src/lib.rs b/shaders/rust/pbribl/genbrdflut/src/lib.rs index 9a507a6df..8ee702a43 100644 --- a/shaders/rust/pbribl/genbrdflut/src/lib.rs +++ b/shaders/rust/pbribl/genbrdflut/src/lib.rs @@ -1,7 +1,7 @@ #![cfg_attr(target_arch = "spirv", no_std)] use spirv_std::glam::{vec2, vec3, vec4, Vec2, Vec3, Vec4}; -use spirv_std::{spirv, num_traits::Float}; +use spirv_std::{num_traits::Float, spirv}; use core::f32::consts::PI; @@ -11,10 +11,7 @@ pub fn main_vs( #[spirv(position)] out_pos: &mut Vec4, out_uv: &mut Vec2, ) { - let uv = vec2( - ((vertex_index << 1) & 2) as f32, - (vertex_index & 2) as f32, - ); + let uv = vec2(((vertex_index << 1) & 2) as f32, (vertex_index & 2) as f32); *out_uv = uv; *out_pos = vec4(uv.x * 2.0 - 1.0, uv.y * 2.0 - 1.0, 0.0, 1.0); } @@ -48,9 +45,9 @@ fn importance_sample_ggx(xi: Vec2, roughness: f32, normal: Vec3) -> Vec3 { let phi = 2.0 * PI * xi.x + random(vec2(normal.x, normal.z)) * 0.1; let cos_theta = ((1.0 - xi.y) / (1.0 + (alpha * alpha - 1.0) * xi.y)).sqrt(); let sin_theta = (1.0 - cos_theta * cos_theta).sqrt(); - + let h = vec3(sin_theta * phi.cos(), sin_theta * phi.sin(), cos_theta); - + // Tangent space let up = if normal.z.abs() < 0.999 { vec3(0.0, 0.0, 1.0) @@ -59,7 +56,7 @@ fn importance_sample_ggx(xi: Vec2, roughness: f32, normal: Vec3) -> Vec3 { }; let tangent_x = up.cross(normal).normalize(); let tangent_y = normal.cross(tangent_x).normalize(); - + // Convert to world space (tangent_x * h.x + tangent_y * h.y + normal * h.z).normalize() } @@ -77,19 +74,19 @@ fn brdf(nov: f32, roughness: f32, num_samples: u32) -> Vec2 { // Normal always points along z-axis for the 2D lookup let n = vec3(0.0, 0.0, 1.0); let v = vec3((1.0 - nov * nov).sqrt(), 0.0, nov); - + let mut lut = Vec2::ZERO; - + for i in 0..num_samples { let xi = hammersley2d(i, num_samples); let h = importance_sample_ggx(xi, roughness, n); let l = 2.0 * v.dot(h) * h - v; - + let dot_nl = n.dot(l).max(0.0); let dot_nv = n.dot(v).max(0.0); let dot_vh = v.dot(h).max(0.0); let dot_nh = h.dot(n).max(0.0); - + if dot_nl > 0.0 { let g = g_schlicksmith_ggx(dot_nl, dot_nv, roughness); let g_vis = (g * dot_vh) / (dot_nh * dot_nv); @@ -98,17 +95,14 @@ fn brdf(nov: f32, roughness: f32, num_samples: u32) -> Vec2 { lut += vec2((1.0 - fc) * g_vis, fc * g_vis); } } - + lut / (num_samples as f32) } #[spirv(fragment)] -pub fn main_fs( - in_uv: Vec2, - out_color: &mut Vec4, -) { +pub fn main_fs(in_uv: Vec2, out_color: &mut Vec4) { // Default to 1024 samples as in the GLSL version const NUM_SAMPLES: u32 = 1024; let result = brdf(in_uv.x, in_uv.y, NUM_SAMPLES); *out_color = vec4(result.x, result.y, 0.0, 1.0); -} \ No newline at end of file +} diff --git a/shaders/rust/pbribl/irradiancecube/src/lib.rs b/shaders/rust/pbribl/irradiancecube/src/lib.rs index 438d38a70..fbb2e648d 100644 --- a/shaders/rust/pbribl/irradiancecube/src/lib.rs +++ b/shaders/rust/pbribl/irradiancecube/src/lib.rs @@ -1,8 +1,8 @@ #![cfg_attr(target_arch = "spirv", no_std)] use spirv_std::glam::{vec3, vec4, Mat4, Vec3, Vec4}; -use spirv_std::{spirv, num_traits::Float}; -use spirv_std::image::{SampledImage, Cubemap}; +use spirv_std::image::{Cubemap, SampledImage}; +use spirv_std::{num_traits::Float, spirv}; // Push constants with padding to match GLSL layout #[derive(Copy, Clone)] @@ -44,12 +44,12 @@ pub fn main_fs( let up = vec3(0.0, 1.0, 0.0); let mut right = up.cross(n).normalize(); let up = n.cross(right); - + const HALF_PI: f32 = PI * 0.5; - + let mut color = Vec3::ZERO; let mut sample_count = 0u32; - + let mut phi = 0.0; while phi < TAU { let mut theta = 0.0; @@ -58,16 +58,16 @@ pub fn main_fs( let sample_vector = theta.cos() * n + theta.sin() * temp_vec; color += sampler_env.sample(sample_vector).truncate() * theta.cos() * theta.sin(); sample_count += 1; - + theta += consts.delta_theta; } phi += consts.delta_phi; } - + *out_color = vec4( color.x * PI / (sample_count as f32), color.y * PI / (sample_count as f32), color.z * PI / (sample_count as f32), - 1.0 + 1.0, ); -} \ No newline at end of file +} diff --git a/shaders/rust/pbribl/pbribl/src/lib.rs b/shaders/rust/pbribl/pbribl/src/lib.rs index d3e0e267c..6fb4dc008 100644 --- a/shaders/rust/pbribl/pbribl/src/lib.rs +++ b/shaders/rust/pbribl/pbribl/src/lib.rs @@ -1,8 +1,8 @@ #![cfg_attr(target_arch = "spirv", no_std)] use spirv_std::glam::{vec2, vec3, vec4, Mat4, Vec2, Vec3, Vec4}; -use spirv_std::{spirv, num_traits::Float}; -use spirv_std::image::{SampledImage, Cubemap}; +use spirv_std::image::{Cubemap, SampledImage}; +use spirv_std::{num_traits::Float, spirv}; // UBO structure for camera matrices #[derive(Copy, Clone)] @@ -19,9 +19,9 @@ pub struct UBO { #[derive(Copy, Clone)] #[repr(C)] pub struct UBOParams { - lights: [Vec4; 4], // offset 0, size 64 - exposure: f32, // offset 64 - gamma: f32, // offset 68 + lights: [Vec4; 4], // offset 0, size 64 + exposure: f32, // offset 64 + gamma: f32, // offset 68 } // Push constants for object position @@ -68,7 +68,8 @@ pub fn main_vs( *out_world_pos = loc_pos + push_consts.obj_pos; *out_normal = ubo.model.transform_vector3(in_normal); *out_uv = Vec2::new(in_uv.x, 1.0 - in_uv.y); - *out_pos = ubo.projection * ubo.view * vec4(out_world_pos.x, out_world_pos.y, out_world_pos.z, 1.0); + *out_pos = + ubo.projection * ubo.view * vec4(out_world_pos.x, out_world_pos.y, out_world_pos.z, 1.0); } // Uncharted 2 tone mapping @@ -79,7 +80,7 @@ fn uncharted2_tonemap(x: Vec3) -> Vec3 { let d = 0.20; let e = 0.02; let f = 0.30; - + ((x * (a * x + c * b) + d * e) / (x * (a * x + b) + d * f)) - e / f } @@ -103,7 +104,8 @@ fn g_schlicksmith_ggx(dot_nl: f32, dot_nv: f32, roughness: f32) -> f32 { // Fresnel function (Schlick approximation) fn f_schlick(cos_theta: f32, f0: Vec3) -> Vec3 { let one_minus_cos = 1.0 - cos_theta; - let one_minus_cos_5 = one_minus_cos * one_minus_cos * one_minus_cos * one_minus_cos * one_minus_cos; + let one_minus_cos_5 = + one_minus_cos * one_minus_cos * one_minus_cos * one_minus_cos * one_minus_cos; f0 + (Vec3::splat(1.0) - f0) * one_minus_cos_5 } @@ -111,7 +113,8 @@ fn f_schlick(cos_theta: f32, f0: Vec3) -> Vec3 { fn f_schlick_r(cos_theta: f32, f0: Vec3, roughness: f32) -> Vec3 { let one_minus_roughness = Vec3::splat(1.0 - roughness); let one_minus_cos = 1.0 - cos_theta; - let one_minus_cos_5 = one_minus_cos * one_minus_cos * one_minus_cos * one_minus_cos * one_minus_cos; + let one_minus_cos_5 = + one_minus_cos * one_minus_cos * one_minus_cos * one_minus_cos * one_minus_cos; f0 + (one_minus_roughness.max(f0) - f0) * one_minus_cos_5 } @@ -125,10 +128,10 @@ fn prefiltered_reflection( let lod = roughness * MAX_REFLECTION_LOD; let lod_f = lod.floor(); let lod_c = lod.ceil(); - + let a = prefiltered_map.sample_by_lod(r, lod_f).truncate(); let b = prefiltered_map.sample_by_lod(r, lod_c).truncate(); - + a * (1.0 - (lod - lod_f)) + b * (lod - lod_f) } @@ -146,20 +149,20 @@ fn specular_contribution( let dot_nh = n.dot(h).clamp(0.0, 1.0); let dot_nv = n.dot(v).clamp(0.0, 1.0); let dot_nl = n.dot(l).clamp(0.0, 1.0); - + let mut color = Vec3::ZERO; - + if dot_nl > 0.0 { let d = d_ggx(dot_nh, roughness); let g = g_schlicksmith_ggx(dot_nl, dot_nv, roughness); let f = f_schlick(dot_nv, f0); - + let spec = (d * f * g) / (4.0 * dot_nl * dot_nv + 0.001); let kd = (Vec3::ONE - f) * (1.0 - metallic); - + color += (kd * albedo / PI + spec) * dot_nl; } - + color } @@ -172,63 +175,72 @@ pub fn main_fs( #[spirv(uniform, descriptor_set = 0, binding = 1)] ubo_params: &UBOParams, #[spirv(push_constant)] material: &PushConstsMaterial, #[spirv(descriptor_set = 0, binding = 2)] sampler_irradiance: &SampledImage, - #[spirv(descriptor_set = 0, binding = 3)] sampler_brdf_lut: &SampledImage, + #[spirv(descriptor_set = 0, binding = 3)] sampler_brdf_lut: &SampledImage< + spirv_std::image::Image2d, + >, #[spirv(descriptor_set = 0, binding = 4)] prefiltered_map: &SampledImage, out_color: &mut Vec4, ) { let n = in_normal.normalize(); let v = (ubo.cam_pos - in_world_pos).normalize(); let r = reflect(-v, n); - + let metallic = material.metallic; let roughness = material.roughness; let albedo = vec3(material.r, material.g, material.b); - + let mut f0 = Vec3::splat(0.04); f0 = f0 * (1.0 - metallic) + albedo * metallic; - + // Direct lighting contribution let mut lo = Vec3::ZERO; for i in 0..4 { let l = (ubo_params.lights[i].truncate() - in_world_pos).normalize(); lo += specular_contribution(l, v, n, f0, metallic, roughness, albedo); } - + // Sample BRDF LUT let n_dot_v = n.dot(v).max(0.0); - let brdf = sampler_brdf_lut.sample(vec2(n_dot_v, roughness)).truncate().truncate(); - + let brdf = sampler_brdf_lut + .sample(vec2(n_dot_v, roughness)) + .truncate() + .truncate(); + // Sample prefiltered reflection let reflection = prefiltered_reflection(r, roughness, prefiltered_map); - + // Sample irradiance let irradiance = sampler_irradiance.sample(n).truncate(); - + // Calculate diffuse let diffuse = irradiance * albedo; - + // Calculate Fresnel let f = f_schlick_r(n_dot_v, f0, roughness); - + // Specular reflectance let specular = reflection * (f * brdf.x + brdf.y); - + // Ambient part let mut kd = Vec3::ONE - f; kd *= 1.0 - metallic; let ambient = kd * diffuse + specular; - + // Final color let mut color = ambient + lo; - + // Tone mapping color = uncharted2_tonemap(color * ubo_params.exposure); let white_scale = Vec3::ONE / uncharted2_tonemap(Vec3::splat(11.2)); color = color * white_scale; - + // Gamma correction let inv_gamma = 1.0 / ubo_params.gamma; - color = vec3(color.x.powf(inv_gamma), color.y.powf(inv_gamma), color.z.powf(inv_gamma)); - + color = vec3( + color.x.powf(inv_gamma), + color.y.powf(inv_gamma), + color.z.powf(inv_gamma), + ); + *out_color = vec4(color.x, color.y, color.z, 1.0); -} \ No newline at end of file +} diff --git a/shaders/rust/pbribl/prefilterenvmap/src/lib.rs b/shaders/rust/pbribl/prefilterenvmap/src/lib.rs index 87b568dce..3253c040e 100644 --- a/shaders/rust/pbribl/prefilterenvmap/src/lib.rs +++ b/shaders/rust/pbribl/prefilterenvmap/src/lib.rs @@ -1,9 +1,8 @@ #![cfg_attr(target_arch = "spirv", no_std)] -use spirv_std::glam::{vec2, vec3, vec4, Mat4, Vec2, Vec3, Vec4, UVec2}; -use spirv_std::{spirv, num_traits::Float}; -use spirv_std::image::{SampledImage, Cubemap}; - +use spirv_std::glam::{vec2, vec3, vec4, Mat4, UVec2, Vec2, Vec3, Vec4}; +use spirv_std::image::{Cubemap, SampledImage}; +use spirv_std::{num_traits::Float, spirv}; // Push constants with padding to match GLSL layout #[derive(Copy, Clone)] @@ -62,9 +61,9 @@ fn importance_sample_ggx(xi: Vec2, roughness: f32, normal: Vec3) -> Vec3 { let phi = TAU * xi.x + random(vec2(normal.x, normal.z)) * 0.1; let cos_theta = ((1.0 - xi.y) / (1.0 + (alpha * alpha - 1.0) * xi.y)).sqrt(); let sin_theta = (1.0 - cos_theta * cos_theta).sqrt(); - + let h = vec3(sin_theta * phi.cos(), sin_theta * phi.sin(), cos_theta); - + // Tangent space let up = if normal.z.abs() < 0.999 { vec3(0.0, 0.0, 1.0) @@ -73,7 +72,7 @@ fn importance_sample_ggx(xi: Vec2, roughness: f32, normal: Vec3) -> Vec3 { }; let tangent_x = up.cross(normal).normalize(); let tangent_y = normal.cross(tangent_x).normalize(); - + // Convert to world space (tangent_x * h.x + tangent_y * h.y + normal * h.z).normalize() } @@ -97,22 +96,22 @@ fn prefilter_env_map( let v = r; let mut color = Vec3::ZERO; let mut total_weight = 0.0; - + // Get environment map dimensions // For cubemaps, query_size_lod returns a UVec2 with the dimensions of one face let env_map_size: UVec2 = sampler_env.query_size_lod(0); let env_map_dim = env_map_size.x as f32; - + for i in 0..num_samples { let xi = hammersley2d(i, num_samples); let h = importance_sample_ggx(xi, roughness, n); let l = 2.0 * v.dot(h) * h - v; let dot_nl = n.dot(l).clamp(0.0, 1.0); - + if dot_nl > 0.0 { let dot_nh = n.dot(h).clamp(0.0, 1.0); let dot_vh = v.dot(h).clamp(0.0, 1.0); - + // Probability Distribution Function let pdf = d_ggx(dot_nh, roughness) * dot_nh / (4.0 * dot_vh) + 0.0001; // Solid angle of current sample @@ -125,12 +124,12 @@ fn prefilter_env_map( } else { (0.5 * (omega_s / omega_p).log2() + 1.0).max(0.0) }; - + color += sampler_env.sample_by_lod(l, mip_level).truncate() * dot_nl; total_weight += dot_nl; } } - + color / total_weight } @@ -144,4 +143,4 @@ pub fn main_fs( let n = in_pos.normalize(); let result = prefilter_env_map(n, consts.roughness, consts.num_samples, sampler_env); *out_color = vec4(result.x, result.y, result.z, 1.0); -} \ No newline at end of file +} diff --git a/shaders/rust/pbribl/skybox/src/lib.rs b/shaders/rust/pbribl/skybox/src/lib.rs index 287b7f050..4327637bd 100644 --- a/shaders/rust/pbribl/skybox/src/lib.rs +++ b/shaders/rust/pbribl/skybox/src/lib.rs @@ -1,8 +1,8 @@ #![cfg_attr(target_arch = "spirv", no_std)] use spirv_std::glam::{vec3, vec4, Mat4, Vec2, Vec3, Vec4}; -use spirv_std::{spirv, num_traits::Float}; -use spirv_std::image::{SampledImage, Cubemap}; +use spirv_std::image::{Cubemap, SampledImage}; +use spirv_std::{num_traits::Float, spirv}; // UBO structure for skybox matrices #[derive(Copy, Clone)] @@ -16,9 +16,9 @@ pub struct UBO { #[derive(Copy, Clone)] #[repr(C)] pub struct UBOParams { - lights: [Vec4; 4], // offset 0, size 64 - exposure: f32, // offset 64 - gamma: f32, // offset 68 + lights: [Vec4; 4], // offset 0, size 64 + exposure: f32, // offset 64 + gamma: f32, // offset 68 } #[spirv(vertex)] @@ -42,7 +42,7 @@ fn uncharted2_tonemap(color: Vec3) -> Vec3 { let d = 0.20; let e = 0.02; let f = 0.30; - + ((color * (a * color + c * b) + d * e) / (color * (a * color + b) + d * f)) - e / f } @@ -54,15 +54,19 @@ pub fn main_fs( out_color: &mut Vec4, ) { let mut color = sampler_env.sample(in_uvw).truncate(); - + // Tone mapping color = uncharted2_tonemap(color * ubo_params.exposure); let white_scale = Vec3::ONE / uncharted2_tonemap(Vec3::splat(11.2)); color = color * white_scale; - + // Gamma correction let inv_gamma = 1.0 / ubo_params.gamma; - color = vec3(color.x.powf(inv_gamma), color.y.powf(inv_gamma), color.z.powf(inv_gamma)); - + color = vec3( + color.x.powf(inv_gamma), + color.y.powf(inv_gamma), + color.z.powf(inv_gamma), + ); + *out_color = vec4(color.x, color.y, color.z, 1.0); -} \ No newline at end of file +} diff --git a/shaders/rust/pipelines/phong/src/lib.rs b/shaders/rust/pipelines/phong/src/lib.rs index 813aaff81..472535bd1 100644 --- a/shaders/rust/pipelines/phong/src/lib.rs +++ b/shaders/rust/pipelines/phong/src/lib.rs @@ -1,8 +1,12 @@ #![cfg_attr(target_arch = "spirv", no_std)] #![allow(clippy::missing_safety_doc)] -use spirv_std::{spirv, glam::{mat3, vec3, vec4, Mat4, Vec3, Vec4}, Image, num_traits::Float}; use spirv_std::image::SampledImage; +use spirv_std::{ + glam::{mat3, vec3, vec4, Mat4, Vec3, Vec4}, + num_traits::Float, + spirv, Image, +}; #[repr(C)] #[derive(Copy, Clone)] @@ -27,7 +31,7 @@ pub fn main_vs( *out_normal = in_normal; *out_color = in_color; *out_position = ubo.projection * ubo.model * vec4(in_pos.x, in_pos.y, in_pos.z, 1.0); - + let pos = ubo.model * vec4(in_pos.x, in_pos.y, in_pos.z, 1.0); let model_mat3 = mat3( ubo.model.x_axis.truncate(), @@ -46,13 +50,15 @@ pub fn main_fs( in_color: Vec3, in_view_vec: Vec3, in_light_vec: Vec3, - #[spirv(descriptor_set = 0, binding = 1)] _color_sampler: &SampledImage, + #[spirv(descriptor_set = 0, binding = 1)] _color_sampler: &SampledImage< + Image!(2D, type=f32, sampled), + >, out_frag_color: &mut Vec4, ) { // Desaturate color let desaturated = vec3(0.2126, 0.7152, 0.0722).dot(in_color); let color = in_color.lerp(vec3(desaturated, desaturated, desaturated), 0.65); - + // High ambient colors because mesh materials are pretty dark let ambient = color * vec3(1.0, 1.0, 1.0); let n = in_normal.normalize(); @@ -61,7 +67,7 @@ pub fn main_fs( let r = (-l).reflect(n); let diffuse = n.dot(l).max(0.0) * color; let specular = r.dot(v).max(0.0).powf(32.0) * vec3(0.35, 0.35, 0.35); - + let final_color = ambient + diffuse * 1.75 + specular; *out_frag_color = vec4(final_color.x, final_color.y, final_color.z, 1.0); -} \ No newline at end of file +} diff --git a/shaders/rust/pipelines/toon/src/lib.rs b/shaders/rust/pipelines/toon/src/lib.rs index 818c832f7..b8ba02ead 100644 --- a/shaders/rust/pipelines/toon/src/lib.rs +++ b/shaders/rust/pipelines/toon/src/lib.rs @@ -1,8 +1,12 @@ #![cfg_attr(target_arch = "spirv", no_std)] #![allow(clippy::missing_safety_doc)] -use spirv_std::{spirv, glam::{mat3, vec3, vec4, Mat4, Vec3, Vec4}, Image, num_traits::Float}; use spirv_std::image::SampledImage; +use spirv_std::{ + glam::{mat3, vec3, vec4, Mat4, Vec3, Vec4}, + num_traits::Float, + spirv, Image, +}; #[repr(C)] #[derive(Copy, Clone)] @@ -27,7 +31,7 @@ pub fn main_vs( *out_normal = in_normal; *out_color = in_color; *out_position = ubo.projection * ubo.model * vec4(in_pos.x, in_pos.y, in_pos.z, 1.0); - + let pos = ubo.model * vec4(in_pos.x, in_pos.y, in_pos.z, 1.0); let model_mat3 = mat3( ubo.model.x_axis.truncate(), @@ -46,13 +50,15 @@ pub fn main_fs( in_color: Vec3, in_view_vec: Vec3, in_light_vec: Vec3, - #[spirv(descriptor_set = 0, binding = 1)] _color_sampler: &SampledImage, + #[spirv(descriptor_set = 0, binding = 1)] _color_sampler: &SampledImage< + Image!(2D, type=f32, sampled), + >, out_frag_color: &mut Vec4, ) { // Desaturate color let desaturated = vec3(0.2126, 0.7152, 0.0722).dot(in_color); let color = in_color.lerp(vec3(desaturated, desaturated, desaturated), 0.65); - + // High ambient colors because mesh materials are pretty dark let ambient = color * vec3(1.0, 1.0, 1.0); let n = in_normal.normalize(); @@ -61,17 +67,25 @@ pub fn main_fs( let r = (-l).reflect(n); let diffuse = n.dot(l).max(0.0) * color; let specular = r.dot(v).max(0.0).powf(16.0) * vec3(0.75, 0.75, 0.75); - + let mut result = ambient + diffuse * 1.75 + specular; - + // Toon shading effect let intensity = n.dot(l); let mut shade = 1.0; - if intensity < 0.5 { shade = 0.75; } - if intensity < 0.35 { shade = 0.6; } - if intensity < 0.25 { shade = 0.5; } - if intensity < 0.1 { shade = 0.25; } - + if intensity < 0.5 { + shade = 0.75; + } + if intensity < 0.35 { + shade = 0.6; + } + if intensity < 0.25 { + shade = 0.5; + } + if intensity < 0.1 { + shade = 0.25; + } + result = in_color * 3.0 * shade; *out_frag_color = vec4(result.x, result.y, result.z, 1.0); -} \ No newline at end of file +} diff --git a/shaders/rust/pipelines/wireframe/src/lib.rs b/shaders/rust/pipelines/wireframe/src/lib.rs index f2424c925..8075f4eb9 100644 --- a/shaders/rust/pipelines/wireframe/src/lib.rs +++ b/shaders/rust/pipelines/wireframe/src/lib.rs @@ -1,7 +1,10 @@ #![cfg_attr(target_arch = "spirv", no_std)] #![allow(clippy::missing_safety_doc)] -use spirv_std::{spirv, glam::{vec4, Mat4, Vec3, Vec4}}; +use spirv_std::{ + glam::{vec4, Mat4, Vec3, Vec4}, + spirv, +}; #[repr(C)] #[derive(Copy, Clone)] @@ -24,10 +27,7 @@ pub fn main_vs( } #[spirv(fragment)] -pub fn main_fs( - in_color: Vec3, - out_frag_color: &mut Vec4, -) { +pub fn main_fs(in_color: Vec3, out_frag_color: &mut Vec4) { let result = in_color * 1.5; *out_frag_color = vec4(result.x, result.y, result.z, 1.0); -} \ No newline at end of file +} diff --git a/shaders/rust/pipelinestatistics/scene/src/lib.rs b/shaders/rust/pipelinestatistics/scene/src/lib.rs index d30b3ac87..d425e7788 100644 --- a/shaders/rust/pipelinestatistics/scene/src/lib.rs +++ b/shaders/rust/pipelinestatistics/scene/src/lib.rs @@ -37,7 +37,7 @@ pub fn main_vs( let _loc_pos = (ubo.modelview * Vec4::from((in_pos, 1.0))).xyz(); let world_pos = (ubo.modelview * Vec4::from((in_pos + push_consts.obj_pos, 1.0))).xyz(); *out_position = ubo.projection * Vec4::from((world_pos, 1.0)); - + let pos = ubo.modelview * Vec4::from((world_pos, 1.0)); *out_normal = Mat3::from_mat4(ubo.modelview) * in_normal; *out_light_vec = ubo.light_pos.xyz() - pos.xyz(); @@ -89,18 +89,17 @@ pub fn main_tes( out_view_vec: &mut Vec3, out_light_vec: &mut Vec3, ) { - *out_position = tess_coord.x * in_position[2] + - tess_coord.y * in_position[1] + - tess_coord.z * in_position[0]; - *out_normal = tess_coord.x * in_normal[2] + - tess_coord.y * in_normal[1] + - tess_coord.z * in_normal[0]; - *out_view_vec = tess_coord.x * in_view_vec[2] + - tess_coord.y * in_view_vec[1] + - tess_coord.z * in_view_vec[0]; - *out_light_vec = tess_coord.x * in_light_vec[2] + - tess_coord.y * in_light_vec[1] + - tess_coord.z * in_light_vec[0]; + *out_position = tess_coord.x * in_position[2] + + tess_coord.y * in_position[1] + + tess_coord.z * in_position[0]; + *out_normal = + tess_coord.x * in_normal[2] + tess_coord.y * in_normal[1] + tess_coord.z * in_normal[0]; + *out_view_vec = tess_coord.x * in_view_vec[2] + + tess_coord.y * in_view_vec[1] + + tess_coord.z * in_view_vec[0]; + *out_light_vec = tess_coord.x * in_light_vec[2] + + tess_coord.y * in_light_vec[1] + + tess_coord.z * in_light_vec[0]; *out_color = in_color[0]; } @@ -119,4 +118,4 @@ pub fn main_fs( let diffuse = n.dot(l).max(0.0) * in_color; let specular = r.dot(v).max(0.0).powi(8) * Vec3::splat(0.75); *out_frag_color = Vec4::from((diffuse + specular, 0.5)); -} \ No newline at end of file +} diff --git a/shaders/rust/pushconstants/src/lib.rs b/shaders/rust/pushconstants/src/lib.rs index cb24b8b00..613a07f56 100644 --- a/shaders/rust/pushconstants/src/lib.rs +++ b/shaders/rust/pushconstants/src/lib.rs @@ -1,7 +1,10 @@ #![cfg_attr(target_arch = "spirv", no_std)] #![allow(clippy::missing_safety_doc)] -use spirv_std::{spirv, glam::{Mat4, Vec3, Vec4}}; +use spirv_std::{ + glam::{Mat4, Vec3, Vec4}, + spirv, +}; #[repr(C)] #[derive(Copy, Clone)] @@ -35,9 +38,6 @@ pub fn main_vs( } #[spirv(fragment)] -pub fn main_fs( - in_color: Vec3, - out_frag_color: &mut Vec4, -) { +pub fn main_fs(in_color: Vec3, out_frag_color: &mut Vec4) { *out_frag_color = Vec4::new(in_color.x, in_color.y, in_color.z, 1.0); -} \ No newline at end of file +} diff --git a/shaders/rust/pushdescriptors/cube/src/lib.rs b/shaders/rust/pushdescriptors/cube/src/lib.rs index b19859159..9709462e7 100644 --- a/shaders/rust/pushdescriptors/cube/src/lib.rs +++ b/shaders/rust/pushdescriptors/cube/src/lib.rs @@ -1,8 +1,11 @@ #![cfg_attr(target_arch = "spirv", no_std)] #![allow(clippy::missing_safety_doc)] -use spirv_std::{spirv, glam::{vec4, Mat4, Vec2, Vec3, Vec4}, Image}; use spirv_std::image::SampledImage; +use spirv_std::{ + glam::{vec4, Mat4, Vec2, Vec3, Vec4}, + spirv, Image, +}; #[repr(C)] #[derive(Copy, Clone)] @@ -33,7 +36,10 @@ pub fn main_vs( *out_normal = in_normal; *out_color = in_color; *out_uv = in_uv; - *out_position = ubo_camera.projection * ubo_camera.view * ubo_model.local * vec4(in_pos.x, in_pos.y, in_pos.z, 1.0); + *out_position = ubo_camera.projection + * ubo_camera.view + * ubo_model.local + * vec4(in_pos.x, in_pos.y, in_pos.z, 1.0); } #[spirv(fragment)] @@ -41,9 +47,11 @@ pub fn main_fs( _in_normal: Vec3, in_color: Vec3, in_uv: Vec2, - #[spirv(descriptor_set = 0, binding = 2)] sampler_color_map: &SampledImage, + #[spirv(descriptor_set = 0, binding = 2)] sampler_color_map: &SampledImage< + Image!(2D, type=f32, sampled), + >, out_frag_color: &mut Vec4, ) { let texture_color = sampler_color_map.sample(in_uv); *out_frag_color = texture_color * vec4(in_color.x, in_color.y, in_color.z, 1.0); -} \ No newline at end of file +} diff --git a/shaders/rust/radialblur/colorpass/src/lib.rs b/shaders/rust/radialblur/colorpass/src/lib.rs index af2883e5e..0b3b3e2bc 100644 --- a/shaders/rust/radialblur/colorpass/src/lib.rs +++ b/shaders/rust/radialblur/colorpass/src/lib.rs @@ -2,8 +2,7 @@ use spirv_std::{ glam::{Mat4, Vec2, Vec3, Vec4}, - spirv, - Image, Sampler, + spirv, Image, Sampler, }; #[repr(C)] @@ -17,7 +16,7 @@ pub struct UBO { #[spirv(vertex)] pub fn main_vs( in_pos: Vec3, - _in_uv: Vec2, // Location 1 - unused but needed to match GLSL layout + _in_uv: Vec2, // Location 1 - unused but needed to match GLSL layout in_color: Vec3, #[spirv(uniform, descriptor_set = 0, binding = 0)] ubo: &UBO, #[spirv(position)] out_position: &mut Vec4, @@ -50,4 +49,4 @@ pub fn main_fs( out_frag_color.z = in_color.z; // Note: GLSL version doesn't set alpha, leaving it undefined } -} \ No newline at end of file +} diff --git a/shaders/rust/radialblur/phongpass/src/lib.rs b/shaders/rust/radialblur/phongpass/src/lib.rs index f045cb7a7..5f375576e 100644 --- a/shaders/rust/radialblur/phongpass/src/lib.rs +++ b/shaders/rust/radialblur/phongpass/src/lib.rs @@ -2,9 +2,8 @@ use spirv_std::{ glam::{Mat4, Vec2, Vec3, Vec4}, - spirv, num_traits::Float, - Image, Sampler, + spirv, Image, Sampler, }; #[repr(C)] @@ -18,7 +17,7 @@ pub struct UBO { #[spirv(vertex)] pub fn main_vs( pos: Vec4, - _in_uv: Vec2, // Location 1 - unused but needed to match GLSL layout + _in_uv: Vec2, // Location 1 - unused but needed to match GLSL layout in_color: Vec3, in_normal: Vec3, #[spirv(uniform, descriptor_set = 0, binding = 0)] ubo: &UBO, @@ -33,12 +32,14 @@ pub fn main_vs( *out_color = in_color; *out_uv = Vec2::new(ubo.gradient_pos, 0.0); *out_position = ubo.projection * ubo.model * pos; - + let eye_pos = ubo.model * pos; *out_eye_pos = Vec3::new(eye_pos.x, eye_pos.y, eye_pos.z); - + let light_pos = Vec4::new(0.0, 0.0, -5.0, 1.0); - *out_light_vec = (Vec3::new(light_pos.x, light_pos.y, light_pos.z) - Vec3::new(pos.x, pos.y, pos.z)).normalize(); + *out_light_vec = (Vec3::new(light_pos.x, light_pos.y, light_pos.z) + - Vec3::new(pos.x, pos.y, pos.z)) + .normalize(); } #[spirv(fragment)] @@ -52,7 +53,7 @@ pub fn main_fs( #[spirv(descriptor_set = 0, binding = 1)] image_gradient_ramp: &Image!(2D, type=f32, sampled), out_frag_color: &mut Vec4, ) { - // No light calculations for glow color + // No light calculations for glow color // Use max. color channel value // to detect bright glow emitters if in_color.x >= 0.9 || in_color.y >= 0.9 || in_color.z >= 0.9 { @@ -64,13 +65,16 @@ pub fn main_fs( } else { let eye = (-in_eye_pos).normalize(); let reflected = (-in_light_vec).reflect(in_normal).normalize(); - + let ambient = Vec4::new(0.2, 0.2, 0.2, 1.0); let diffuse = Vec4::new(0.5, 0.5, 0.5, 0.5) * in_normal.dot(in_light_vec).max(0.0); let specular_strength = 0.25; - let specular = Vec4::new(0.5, 0.5, 0.5, 1.0) * reflected.dot(eye).max(0.0).powf(4.0) * specular_strength; - - let result = (ambient + diffuse) * Vec4::new(in_color.x, in_color.y, in_color.z, 1.0) + specular; + let specular = Vec4::new(0.5, 0.5, 0.5, 1.0) + * reflected.dot(eye).max(0.0).powf(4.0) + * specular_strength; + + let result = + (ambient + diffuse) * Vec4::new(in_color.x, in_color.y, in_color.z, 1.0) + specular; *out_frag_color = result; } -} \ No newline at end of file +} diff --git a/shaders/rust/radialblur/radialblur/src/lib.rs b/shaders/rust/radialblur/radialblur/src/lib.rs index 2fa1046ee..dbcaab227 100644 --- a/shaders/rust/radialblur/radialblur/src/lib.rs +++ b/shaders/rust/radialblur/radialblur/src/lib.rs @@ -1,9 +1,8 @@ #![cfg_attr(target_arch = "spirv", no_std)] use spirv_std::{ - glam::{Vec2, Vec4, UVec2}, - spirv, - Image, Sampler, + glam::{UVec2, Vec2, Vec4}, + spirv, Image, Sampler, }; #[repr(C)] @@ -20,10 +19,7 @@ pub fn main_vs( #[spirv(position)] out_position: &mut Vec4, out_uv: &mut Vec2, ) { - let uv = Vec2::new( - ((vertex_index << 1) & 2) as f32, - (vertex_index & 2) as f32, - ); + let uv = Vec2::new(((vertex_index << 1) & 2) as f32, (vertex_index & 2) as f32); *out_uv = uv; *out_position = Vec4::new(uv.x * 2.0 - 1.0, uv.y * 2.0 - 1.0, 0.0, 1.0); } @@ -38,17 +34,17 @@ pub fn main_fs( ) { let tex_dim: UVec2 = image_color.query_size_lod(0); let radial_size = Vec2::new(1.0 / tex_dim.x as f32, 1.0 / tex_dim.y as f32); - + let mut uv = in_uv; let mut color = Vec4::ZERO; uv += radial_size * 0.5 - ubo.radial_origin; - + const SAMPLES: i32 = 32; - + for i in 0..SAMPLES { let scale = 1.0 - ubo.radial_blur_scale * (i as f32 / (SAMPLES - 1) as f32); color += image_color.sample(*sampler_color, uv * scale + ubo.radial_origin); } - + *out_frag_color = (color / SAMPLES as f32) * ubo.radial_blur_strength; -} \ No newline at end of file +} diff --git a/shaders/rust/rayquery/scene/src/lib.rs b/shaders/rust/rayquery/scene/src/lib.rs index c7ea32d8f..4eea9583b 100644 --- a/shaders/rust/rayquery/scene/src/lib.rs +++ b/shaders/rust/rayquery/scene/src/lib.rs @@ -2,8 +2,11 @@ #![allow(clippy::missing_safety_doc)] #![feature(asm_experimental_arch)] -use spirv_std::{spirv, glam::{vec4, Mat3, Mat4, Vec2, Vec3, Vec4}}; -use spirv_std::ray_tracing::{AccelerationStructure, RayFlags, RayQuery, CommittedIntersection}; +use spirv_std::ray_tracing::{AccelerationStructure, CommittedIntersection, RayFlags, RayQuery}; +use spirv_std::{ + glam::{vec4, Mat3, Mat4, Vec2, Vec3, Vec4}, + spirv, +}; #[repr(C)] #[derive(Copy, Clone)] @@ -57,9 +60,9 @@ pub fn main_fs( let n = in_normal.normalize(); let l = in_light_vec.normalize(); let diffuse = n.dot(l).max(AMBIENT) * in_color; - + *out_frag_color = vec4(diffuse.x, diffuse.y, diffuse.z, 1.0); - + unsafe { spirv_std::ray_query!(let mut ray_query); ray_query.initialize( @@ -69,15 +72,15 @@ pub fn main_fs( in_world_pos, 0.01, l, - 1000.0 + 1000.0, ); - + // Traverse the acceleration structure ray_query.proceed(); - + // If the intersection has hit a triangle, the fragment is shadowed if ray_query.get_committed_intersection_type() == CommittedIntersection::Triangle { *out_frag_color *= 0.1; } } -} \ No newline at end of file +} diff --git a/shaders/rust/raytracingbasic/src/lib.rs b/shaders/rust/raytracingbasic/src/lib.rs index 49dcf86d5..098f6192a 100644 --- a/shaders/rust/raytracingbasic/src/lib.rs +++ b/shaders/rust/raytracingbasic/src/lib.rs @@ -1,10 +1,13 @@ #![cfg_attr(target_arch = "spirv", no_std)] #![allow(clippy::missing_safety_doc)] -use spirv_std::{spirv, glam::{vec2, vec3, vec4, Mat4, Vec2, Vec3, IVec3}}; use spirv_std::glam::Vec4Swizzles; use spirv_std::ray_tracing::{AccelerationStructure, RayFlags}; use spirv_std::Image; +use spirv_std::{ + glam::{vec2, vec3, vec4, IVec3, Mat4, Vec2, Vec3}, + spirv, +}; #[repr(C)] #[derive(Copy, Clone)] @@ -29,7 +32,13 @@ pub fn main_rgen( let origin = cam.view_inverse * vec4(0.0, 0.0, 0.0, 1.0); let target = cam.proj_inverse * vec4(d.x, d.y, 1.0, 1.0); let normalized_target = target.xyz().normalize(); - let direction = cam.view_inverse * vec4(normalized_target.x, normalized_target.y, normalized_target.z, 0.0); + let direction = cam.view_inverse + * vec4( + normalized_target.x, + normalized_target.y, + normalized_target.z, + 0.0, + ); let tmin = 0.001; let tmax = 10000.0; @@ -54,7 +63,7 @@ pub fn main_rgen( unsafe { image.write( spirv_std::glam::IVec2::new(launch_id.x, launch_id.y), - vec4(hit_value.x, hit_value.y, hit_value.z, 0.0) + vec4(hit_value.x, hit_value.y, hit_value.z, 0.0), ); } } @@ -69,8 +78,6 @@ pub fn main_rchit( } #[spirv(miss)] -pub fn main_rmiss( - #[spirv(incoming_ray_payload)] hit_value: &mut Vec3, -) { +pub fn main_rmiss(#[spirv(incoming_ray_payload)] hit_value: &mut Vec3) { *hit_value = vec3(0.0, 0.0, 0.2); -} \ No newline at end of file +} diff --git a/shaders/rust/renderheadless/triangle/src/lib.rs b/shaders/rust/renderheadless/triangle/src/lib.rs index b0a96d4a5..a559a61f8 100644 --- a/shaders/rust/renderheadless/triangle/src/lib.rs +++ b/shaders/rust/renderheadless/triangle/src/lib.rs @@ -1,7 +1,10 @@ #![cfg_attr(target_arch = "spirv", no_std)] #![allow(clippy::missing_safety_doc)] -use spirv_std::{spirv, glam::{vec4, Mat4, Vec3, Vec4}}; +use spirv_std::{ + glam::{vec4, Mat4, Vec3, Vec4}, + spirv, +}; #[repr(C)] #[derive(Copy, Clone)] @@ -22,9 +25,6 @@ pub fn main_vs( } #[spirv(fragment)] -pub fn main_fs( - in_color: Vec3, - out_frag_color: &mut Vec4, -) { +pub fn main_fs(in_color: Vec3, out_frag_color: &mut Vec4) { *out_frag_color = vec4(in_color.x, in_color.y, in_color.z, 1.0); -} \ No newline at end of file +} diff --git a/shaders/rust/screenshot/mesh/src/lib.rs b/shaders/rust/screenshot/mesh/src/lib.rs index 6c42f701a..651886efd 100644 --- a/shaders/rust/screenshot/mesh/src/lib.rs +++ b/shaders/rust/screenshot/mesh/src/lib.rs @@ -1,8 +1,11 @@ #![cfg_attr(target_arch = "spirv", no_std)] #![allow(clippy::missing_safety_doc)] -use spirv_std::{spirv, glam::{vec3, vec4, Mat3, Mat4, Vec3, Vec4}}; use spirv_std::num_traits::Float; +use spirv_std::{ + glam::{vec3, vec4, Mat3, Mat4, Vec3, Vec4}, + spirv, +}; #[repr(C)] #[derive(Copy, Clone)] @@ -27,10 +30,10 @@ pub fn main_vs( *out_normal = in_normal; *out_color = in_color; *out_position = ubo.projection * ubo.view * ubo.model * in_pos; - + let pos = ubo.view * ubo.model * vec4(in_pos.x, in_pos.y, in_pos.z, 1.0); *out_normal = Mat3::from_mat4(ubo.model) * in_normal; - + let light_pos = vec3(1.0, -1.0, 1.0); *out_light_vec = light_pos - pos.truncate(); *out_view_vec = -pos.truncate(); @@ -48,11 +51,11 @@ pub fn main_fs( let l = in_light_vec.normalize(); let v = in_view_vec.normalize(); let r = (-l).reflect(n); - + let ambient = vec3(0.1, 0.1, 0.1); let diffuse = n.dot(l).max(0.0) * vec3(1.0, 1.0, 1.0); let specular = r.dot(v).max(0.0).powf(16.0) * vec3(0.75, 0.75, 0.75); - + let color = (ambient + diffuse) * in_color + specular; *out_frag_color = vec4(color.x, color.y, color.z, 1.0); } diff --git a/shaders/rust/shaderobjects/phong/src/lib.rs b/shaders/rust/shaderobjects/phong/src/lib.rs index 1fb0de8ea..05d7979f9 100644 --- a/shaders/rust/shaderobjects/phong/src/lib.rs +++ b/shaders/rust/shaderobjects/phong/src/lib.rs @@ -1,8 +1,12 @@ #![cfg_attr(target_arch = "spirv", no_std)] #![allow(clippy::missing_safety_doc)] -use spirv_std::{spirv, glam::{mat3, vec3, vec4, Mat4, Vec3, Vec4}, Image, num_traits::Float}; use spirv_std::image::SampledImage; +use spirv_std::{ + glam::{mat3, vec3, vec4, Mat4, Vec3, Vec4}, + num_traits::Float, + spirv, Image, +}; #[repr(C)] #[derive(Copy, Clone)] @@ -27,7 +31,7 @@ pub fn main_vs( *out_normal = in_normal; *out_color = in_color; *out_position = ubo.projection * ubo.model * vec4(in_pos.x, in_pos.y, in_pos.z, 1.0); - + let pos = ubo.model * vec4(in_pos.x, in_pos.y, in_pos.z, 1.0); let model_mat3 = mat3( ubo.model.x_axis.truncate(), @@ -46,13 +50,15 @@ pub fn main_fs( in_color: Vec3, in_view_vec: Vec3, in_light_vec: Vec3, - #[spirv(descriptor_set = 0, binding = 1)] _sampler_color_map: &SampledImage, + #[spirv(descriptor_set = 0, binding = 1)] _sampler_color_map: &SampledImage< + Image!(2D, type=f32, sampled), + >, out_frag_color: &mut Vec4, ) { // Desaturate color let gray = in_color.dot(vec3(0.2126, 0.7152, 0.0722)); let color = in_color.lerp(vec3(gray, gray, gray), 0.65); - + // High ambient colors because mesh materials are pretty dark let ambient = color * vec3(1.0, 1.0, 1.0); let n = in_normal.normalize(); @@ -63,4 +69,4 @@ pub fn main_fs( let specular = r.dot(v).max(0.0).powf(32.0) * vec3(0.35, 0.35, 0.35); let final_color = ambient + diffuse * 1.75 + specular; *out_frag_color = vec4(final_color.x, final_color.y, final_color.z, 1.0); -} \ No newline at end of file +} diff --git a/shaders/rust/shadowmapping/offscreen/src/lib.rs b/shaders/rust/shadowmapping/offscreen/src/lib.rs index ace50b284..f84c6d5f0 100644 --- a/shaders/rust/shadowmapping/offscreen/src/lib.rs +++ b/shaders/rust/shadowmapping/offscreen/src/lib.rs @@ -19,9 +19,7 @@ pub fn main_vs( } #[spirv(fragment)] -pub fn main_fs( - out_color: &mut Vec4, -) { +pub fn main_fs(out_color: &mut Vec4) { // Shadow pass only writes depth, color output is not used *out_color = Vec4::new(1.0, 0.0, 0.0, 1.0); -} \ No newline at end of file +} diff --git a/shaders/rust/shadowmapping/quad/src/lib.rs b/shaders/rust/shadowmapping/quad/src/lib.rs index 8b32f166e..13e5aa345 100644 --- a/shaders/rust/shadowmapping/quad/src/lib.rs +++ b/shaders/rust/shadowmapping/quad/src/lib.rs @@ -22,10 +22,7 @@ pub fn main_vs( #[spirv(position)] out_position: &mut Vec4, out_uv: &mut Vec2, ) { - let uv = vec2( - ((vert_index << 1) & 2) as f32, - (vert_index & 2) as f32, - ); + let uv = vec2(((vert_index << 1) & 2) as f32, (vert_index & 2) as f32); *out_uv = uv; *out_position = vec4(uv.x * 2.0 - 1.0, uv.y * 2.0 - 1.0, 0.0, 1.0); } @@ -47,4 +44,4 @@ pub fn main_fs( fn linearize_depth(depth: f32, z_near: f32, z_far: f32) -> f32 { let z = depth; (2.0 * z_near) / (z_far + z_near - z * (z_far - z_near)) -} \ No newline at end of file +} diff --git a/shaders/rust/shadowmapping/scene/src/lib.rs b/shaders/rust/shadowmapping/scene/src/lib.rs index a4db2275e..85d49a58f 100644 --- a/shaders/rust/shadowmapping/scene/src/lib.rs +++ b/shaders/rust/shadowmapping/scene/src/lib.rs @@ -41,7 +41,7 @@ pub fn main_vs( *out_normal = in_normal; *out_position = ubo.projection * ubo.view * ubo.model * Vec4::from((in_pos, 1.0)); - + let pos = ubo.model * Vec4::from((in_pos, 1.0)); *out_normal = Mat3::from_mat4(ubo.model) * in_normal; *out_light_vec = (ubo.light_pos.xyz() - in_pos).normalize(); @@ -63,12 +63,18 @@ pub fn main_fs( out_frag_color: &mut Vec4, ) { const AMBIENT: f32 = 0.1; - + let shadow_coord = in_shadow_coord / in_shadow_coord.w; let shadow = if enable_pcf == 1 { filter_pcf(shadow_coord, texture_shadow, sampler_shadow) } else { - texture_proj(shadow_coord, vec2(0.0, 0.0), texture_shadow, sampler_shadow, AMBIENT) + texture_proj( + shadow_coord, + vec2(0.0, 0.0), + texture_shadow, + sampler_shadow, + AMBIENT, + ) }; let n = in_normal.normalize(); @@ -82,15 +88,17 @@ pub fn main_fs( } fn texture_proj( - shadow_coord: Vec4, - off: Vec2, + shadow_coord: Vec4, + off: Vec2, texture_shadow: &Image!(2D, type=f32, sampled), sampler_shadow: &Sampler, - ambient: f32 + ambient: f32, ) -> f32 { let mut shadow = 1.0; if shadow_coord.z > -1.0 && shadow_coord.z < 1.0 { - let dist = texture_shadow.sample(*sampler_shadow, shadow_coord.xy() + off).x; + let dist = texture_shadow + .sample(*sampler_shadow, shadow_coord.xy() + off) + .x; if shadow_coord.w > 0.0 && dist < shadow_coord.z { shadow = ambient; } @@ -104,7 +112,7 @@ fn filter_pcf( sampler_shadow: &Sampler, ) -> f32 { const AMBIENT: f32 = 0.1; - + // Since we can't query texture size in Rust GPU, we'll use a fixed scale let scale = 1.5; let texel_size = 1.0 / 2048.0; // Assuming 2048x2048 shadow map @@ -114,18 +122,18 @@ fn filter_pcf( let mut shadow_factor = 0.0; let mut count = 0; let range = 1; - + for x in -range..=range { for y in -range..=range { shadow_factor += texture_proj( - sc, + sc, vec2(dx * x as f32, dy * y as f32), texture_shadow, sampler_shadow, - AMBIENT + AMBIENT, ); count += 1; } } shadow_factor / count as f32 -} \ No newline at end of file +} diff --git a/shaders/rust/shadowmappingcascade/debugshadowmap/src/lib.rs b/shaders/rust/shadowmappingcascade/debugshadowmap/src/lib.rs index c8dda8b7a..f4ef2439a 100644 --- a/shaders/rust/shadowmappingcascade/debugshadowmap/src/lib.rs +++ b/shaders/rust/shadowmappingcascade/debugshadowmap/src/lib.rs @@ -19,10 +19,7 @@ pub fn main_vs( out_uv: &mut Vec2, #[spirv(flat)] out_cascade_index: &mut u32, ) { - let uv = Vec2::new( - ((vertex_index << 1) & 2) as f32, - (vertex_index & 2) as f32, - ); + let uv = Vec2::new(((vertex_index << 1) & 2) as f32, (vertex_index & 2) as f32); *out_uv = uv; *out_cascade_index = push_consts.cascade_index; *out_position = Vec4::new(uv.x * 2.0 - 1.0, uv.y * 2.0 - 1.0, 0.0, 1.0); @@ -36,6 +33,11 @@ pub fn main_fs( #[spirv(descriptor_set = 0, binding = 1)] sampler: &Sampler, out_frag_color: &mut Vec4, ) { - let depth = shadow_map.sample(*sampler, Vec3::new(in_uv.x, in_uv.y, in_cascade_index as f32)).x; + let depth = shadow_map + .sample( + *sampler, + Vec3::new(in_uv.x, in_uv.y, in_cascade_index as f32), + ) + .x; *out_frag_color = Vec4::new(depth, depth, depth, 1.0); -} \ No newline at end of file +} diff --git a/shaders/rust/shadowmappingcascade/depthpass/src/lib.rs b/shaders/rust/shadowmappingcascade/depthpass/src/lib.rs index a115262d9..d9e0b6e81 100644 --- a/shaders/rust/shadowmappingcascade/depthpass/src/lib.rs +++ b/shaders/rust/shadowmappingcascade/depthpass/src/lib.rs @@ -30,7 +30,8 @@ pub fn main_vs( ) { *out_uv = in_uv; let pos = in_pos + push_consts.position.xyz(); - *out_position = ubo.cascade_view_proj_mat[push_consts.cascade_index as usize] * Vec4::from((pos, 1.0)); + *out_position = + ubo.cascade_view_proj_mat[push_consts.cascade_index as usize] * Vec4::from((pos, 1.0)); } #[spirv(fragment)] @@ -43,4 +44,4 @@ pub fn main_fs( if alpha < 0.5 { spirv_std::arch::kill(); } -} \ No newline at end of file +} diff --git a/shaders/rust/shadowmappingcascade/scene/src/lib.rs b/shaders/rust/shadowmappingcascade/scene/src/lib.rs index b24378ff6..8283d8cba 100644 --- a/shaders/rust/shadowmappingcascade/scene/src/lib.rs +++ b/shaders/rust/shadowmappingcascade/scene/src/lib.rs @@ -75,7 +75,14 @@ fn texture_proj( if shadow_coord.z > -1.0 && shadow_coord.z < 1.0 { let dist = shadow_map - .sample(*sampler, vec3(shadow_coord.x + offset.x, shadow_coord.y + offset.y, cascade_index as f32)) + .sample( + *sampler, + vec3( + shadow_coord.x + offset.x, + shadow_coord.y + offset.y, + cascade_index as f32, + ), + ) .x; if shadow_coord.w > 0.0 && dist < shadow_coord.z - bias { shadow = AMBIENT; @@ -164,9 +171,20 @@ pub fn main_fs( let shadow_coord = (bias_mat * cascade_matrix) * vec4(in_pos.x, in_pos.y, in_pos.z, 1.0); let shadow = if enable_pcf == 1 { - filter_pcf(shadow_coord / shadow_coord.w, cascade_index, shadow_map, shadow_sampler) + filter_pcf( + shadow_coord / shadow_coord.w, + cascade_index, + shadow_map, + shadow_sampler, + ) } else { - texture_proj(shadow_coord / shadow_coord.w, vec2(0.0, 0.0), cascade_index, shadow_map, shadow_sampler) + texture_proj( + shadow_coord / shadow_coord.w, + vec2(0.0, 0.0), + cascade_index, + shadow_map, + shadow_sampler, + ) }; // Directional light @@ -189,4 +207,4 @@ pub fn main_fs( } *out_frag_color = vec4(frag_color.x, frag_color.y, frag_color.z, color.w); -} \ No newline at end of file +} diff --git a/shaders/rust/shadowmappingomni/cubemapdisplay/src/lib.rs b/shaders/rust/shadowmappingomni/cubemapdisplay/src/lib.rs index d62317e24..ea38ee945 100644 --- a/shaders/rust/shadowmappingomni/cubemapdisplay/src/lib.rs +++ b/shaders/rust/shadowmappingomni/cubemapdisplay/src/lib.rs @@ -1,8 +1,8 @@ #![no_std] -use spirv_std::spirv; -use spirv_std::glam::{Vec2, Vec3, Vec4, Mat4, Vec4Swizzles}; +use spirv_std::glam::{Mat4, Vec2, Vec3, Vec4, Vec4Swizzles}; use spirv_std::num_traits::Float; +use spirv_std::spirv; #[repr(C)] #[derive(Copy, Clone)] @@ -19,10 +19,7 @@ pub fn main_vs( #[spirv(position)] out_position: &mut Vec4, out_uv: &mut Vec2, ) { - let uv = Vec2::new( - ((vertex_index << 1) & 2) as f32, - (vertex_index & 2) as f32, - ); + let uv = Vec2::new(((vertex_index << 1) & 2) as f32, (vertex_index & 2) as f32); *out_uv = uv; *out_position = Vec4::new(uv.x * 2.0 - 1.0, uv.y * 2.0 - 1.0, 0.0, 1.0); } @@ -35,49 +32,56 @@ pub fn main_fs( out_frag_color: &mut Vec4, ) { *out_frag_color = Vec4::new(0.05, 0.05, 0.05, 1.0); - + let mut sample_pos = Vec3::ZERO; - + // Crude statement to visualize different cube map faces based on UV coordinates let x = (in_uv.x / 0.25).floor() as i32; let y = (in_uv.y / (1.0 / 3.0)).floor() as i32; - + if y == 1 { - let mut uv = Vec2::new(in_uv.x * 4.0, (in_uv.y - 1.0/3.0) * 3.0); + let mut uv = Vec2::new(in_uv.x * 4.0, (in_uv.y - 1.0 / 3.0) * 3.0); uv = 2.0 * Vec2::new(uv.x - (x as f32) * 1.0, uv.y) - Vec2::ONE; match x { - 0 => { // NEGATIVE_X + 0 => { + // NEGATIVE_X sample_pos = Vec3::new(-1.0, uv.y, uv.x); } - 1 => { // POSITIVE_Z + 1 => { + // POSITIVE_Z sample_pos = Vec3::new(uv.x, uv.y, 1.0); } - 2 => { // POSITIVE_X + 2 => { + // POSITIVE_X sample_pos = Vec3::new(1.0, uv.y, -uv.x); } - 3 => { // NEGATIVE_Z + 3 => { + // NEGATIVE_Z sample_pos = Vec3::new(-uv.x, uv.y, -1.0); } _ => {} } } else { if x == 1 { - let uv = 2.0 * Vec2::new((in_uv.x - 0.25) * 4.0, (in_uv.y - (y as f32) / 3.0) * 3.0) - Vec2::ONE; + let uv = 2.0 * Vec2::new((in_uv.x - 0.25) * 4.0, (in_uv.y - (y as f32) / 3.0) * 3.0) + - Vec2::ONE; match y { - 0 => { // NEGATIVE_Y + 0 => { + // NEGATIVE_Y sample_pos = Vec3::new(uv.x, -1.0, uv.y); } - 2 => { // POSITIVE_Y + 2 => { + // POSITIVE_Y sample_pos = Vec3::new(uv.x, 1.0, -uv.y); } _ => {} } } } - + if sample_pos.x != 0.0 && sample_pos.y != 0.0 { let sampled: Vec4 = shadow_cube_map.sample_by_lod(*sampler, sample_pos, 0.0); let dist = sampled.xyz().length() * 0.005; *out_frag_color = Vec4::new(dist, dist, dist, 1.0); } -} \ No newline at end of file +} diff --git a/shaders/rust/shadowmappingomni/offscreen/src/lib.rs b/shaders/rust/shadowmappingomni/offscreen/src/lib.rs index 863639cf2..e5c5684a3 100644 --- a/shaders/rust/shadowmappingomni/offscreen/src/lib.rs +++ b/shaders/rust/shadowmappingomni/offscreen/src/lib.rs @@ -1,7 +1,7 @@ #![no_std] +use spirv_std::glam::{Mat4, Vec3, Vec4, Vec4Swizzles}; use spirv_std::spirv; -use spirv_std::glam::{Vec3, Vec4, Mat4, Vec4Swizzles}; #[repr(C)] #[derive(Copy, Clone)] @@ -28,18 +28,17 @@ pub fn main_vs( out_pos: &mut Vec4, out_light_pos: &mut Vec3, ) { - *out_position = ubo.projection * push_consts.view * ubo.model * Vec4::new(in_pos.x, in_pos.y, in_pos.z, 1.0); + *out_position = ubo.projection + * push_consts.view + * ubo.model + * Vec4::new(in_pos.x, in_pos.y, in_pos.z, 1.0); *out_pos = Vec4::new(in_pos.x, in_pos.y, in_pos.z, 1.0); *out_light_pos = ubo.light_pos.xyz(); } #[spirv(fragment)] -pub fn main_fs( - in_pos: Vec4, - in_light_pos: Vec3, - out_frag_color: &mut f32, -) { +pub fn main_fs(in_pos: Vec4, in_light_pos: Vec3, out_frag_color: &mut f32) { // Store distance to light as 32 bit float value let light_vec = in_pos.xyz() - in_light_pos; *out_frag_color = light_vec.length(); -} \ No newline at end of file +} diff --git a/shaders/rust/shadowmappingomni/scene/src/lib.rs b/shaders/rust/shadowmappingomni/scene/src/lib.rs index 5f4db68e5..acaddc228 100644 --- a/shaders/rust/shadowmappingomni/scene/src/lib.rs +++ b/shaders/rust/shadowmappingomni/scene/src/lib.rs @@ -1,7 +1,7 @@ #![no_std] +use spirv_std::glam::{Mat4, Vec3, Vec4, Vec4Swizzles}; use spirv_std::spirv; -use spirv_std::glam::{Vec3, Vec4, Mat4, Vec4Swizzles}; #[repr(C)] #[derive(Copy, Clone)] @@ -29,12 +29,13 @@ pub fn main_vs( ) { *out_color = in_color; *out_normal = in_normal; - - *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); *out_eye_pos = (ubo.model * Vec4::new(in_pos.x, in_pos.y, in_pos.z, 1.0)).xyz(); *out_light_vec = (ubo.light_pos.xyz() - in_pos).normalize(); *out_world_pos = in_pos; - + *out_light_pos = ubo.light_pos.xyz(); } @@ -52,22 +53,26 @@ pub fn main_fs( ) { const EPSILON: f32 = 0.15; const SHADOW_OPACITY: f32 = 0.5; - + // Lighting let i_ambient = Vec4::new(0.05, 0.05, 0.05, 1.0); let i_diffuse = Vec4::ONE * in_normal.dot(in_light_vec).max(0.0); - + *out_frag_color = i_ambient + i_diffuse * Vec4::new(in_color.x, in_color.y, in_color.z, 1.0); - + // Shadow let light_vec = in_world_pos - in_light_pos; let sampled_dist: Vec4 = shadow_cube_map.sample_by_lod(*sampler, light_vec, 0.0); let dist = light_vec.length(); - + // Check if fragment is in shadow - let shadow = if dist <= sampled_dist.x + EPSILON { 1.0 } else { SHADOW_OPACITY }; - + let shadow = if dist <= sampled_dist.x + EPSILON { + 1.0 + } else { + SHADOW_OPACITY + }; + out_frag_color.x *= shadow; out_frag_color.y *= shadow; out_frag_color.z *= shadow; -} \ No newline at end of file +} diff --git a/shaders/rust/specializationconstants/uber/src/lib.rs b/shaders/rust/specializationconstants/uber/src/lib.rs index b9ff8a230..9269dd330 100644 --- a/shaders/rust/specializationconstants/uber/src/lib.rs +++ b/shaders/rust/specializationconstants/uber/src/lib.rs @@ -1,8 +1,12 @@ #![cfg_attr(target_arch = "spirv", no_std)] #![allow(clippy::missing_safety_doc)] -use spirv_std::{spirv, glam::{mat3, vec3, vec4, Mat4, Vec2, Vec3, Vec4}, Image, num_traits::Float}; use spirv_std::image::SampledImage; +use spirv_std::{ + glam::{mat3, vec3, vec4, Mat4, Vec2, Vec3, Vec4}, + num_traits::Float, + spirv, Image, +}; #[repr(C)] #[derive(Copy, Clone)] @@ -30,7 +34,7 @@ pub fn main_vs( *out_color = in_color; *out_uv = in_uv; *out_position = ubo.projection * ubo.model * vec4(in_pos.x, in_pos.y, in_pos.z, 1.0); - + let pos = ubo.model * vec4(in_pos.x, in_pos.y, in_pos.z, 1.0); let model_mat3 = mat3( ubo.model.x_axis.truncate(), @@ -50,8 +54,12 @@ pub fn main_fs( in_uv: Vec2, in_view_vec: Vec3, in_light_vec: Vec3, - #[spirv(descriptor_set = 0, binding = 1)] colormap_sampler: &SampledImage, - #[spirv(descriptor_set = 0, binding = 2)] _discard_sampler: &SampledImage, + #[spirv(descriptor_set = 0, binding = 1)] colormap_sampler: &SampledImage< + Image!(2D, type=f32, sampled), + >, + #[spirv(descriptor_set = 0, binding = 2)] _discard_sampler: &SampledImage< + Image!(2D, type=f32, sampled), + >, #[spirv(spec_constant(id = 0))] lighting_model: u32, #[spirv(spec_constant(id = 1))] toon_desaturation_bits: u32, out_frag_color: &mut Vec4, @@ -66,7 +74,12 @@ 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(32.0) * vec3(0.75, 0.75, 0.75); - *out_frag_color = vec4((ambient + diffuse * 1.75 + specular).x, (ambient + diffuse * 1.75 + specular).y, (ambient + diffuse * 1.75 + specular).z, 1.0); + *out_frag_color = vec4( + (ambient + diffuse * 1.75 + specular).x, + (ambient + diffuse * 1.75 + specular).y, + (ambient + diffuse * 1.75 + specular).z, + 1.0, + ); } 1 => { // Toon @@ -87,7 +100,10 @@ pub fn main_fs( // Desaturate a bit - convert u32 bits to f32 let toon_desaturation = f32::from_bits(toon_desaturation_bits); let desaturated = vec3(0.2126, 0.7152, 0.0722).dot(color); - let final_color = color.lerp(vec3(desaturated, desaturated, desaturated), toon_desaturation); + let final_color = color.lerp( + vec3(desaturated, desaturated, desaturated), + toon_desaturation, + ); *out_frag_color = vec4(final_color.x, final_color.y, final_color.z, 1.0); } 2 => { @@ -109,4 +125,4 @@ pub fn main_fs( *out_frag_color = vec4(1.0, 0.0, 1.0, 1.0); // Magenta for debugging } } -} \ No newline at end of file +} diff --git a/shaders/rust/sphericalenvmapping/sem/src/lib.rs b/shaders/rust/sphericalenvmapping/sem/src/lib.rs index 2f648c5b2..68434f9db 100644 --- a/shaders/rust/sphericalenvmapping/sem/src/lib.rs +++ b/shaders/rust/sphericalenvmapping/sem/src/lib.rs @@ -1,8 +1,12 @@ #![cfg_attr(target_arch = "spirv", no_std)] #![allow(clippy::missing_safety_doc)] -use spirv_std::{spirv, glam::{vec3, vec4, Mat3, Mat4, Vec3, Vec4, Vec3Swizzles}, Image, num_traits::Float}; use spirv_std::image::SampledImage; +use spirv_std::{ + glam::{vec3, vec4, Mat3, Mat4, Vec3, Vec3Swizzles, Vec4}, + num_traits::Float, + spirv, Image, +}; #[repr(C)] #[derive(Copy, Clone)] @@ -30,14 +34,14 @@ pub fn main_vs( let model_view = ubo.view * ubo.model; *out_eye_pos = (model_view * in_pos).truncate().normalize(); *out_tex_index = ubo.tex_index; - + let normal_mat3 = Mat3::from_cols( ubo.normal.x_axis.truncate(), ubo.normal.y_axis.truncate(), ubo.normal.z_axis.truncate(), ); *out_normal = (normal_mat3 * in_normal).normalize(); - + let r = out_eye_pos.reflect(*out_normal); let _m = 2.0 * (r.x.powi(2) + r.y.powi(2) + (r.z + 1.0).powi(2)).sqrt(); *out_position = ubo.projection * model_view * in_pos; @@ -49,21 +53,23 @@ pub fn main_fs( in_eye_pos: Vec3, in_normal: Vec3, #[spirv(flat)] in_tex_index: i32, - #[spirv(descriptor_set = 0, binding = 1)] mat_cap: &SampledImage, + #[spirv(descriptor_set = 0, binding = 1)] mat_cap: &SampledImage< + Image!(2D, type=f32, sampled, arrayed), + >, out_frag_color: &mut Vec4, ) { let r = in_eye_pos.reflect(in_normal); let r2 = vec3(r.x, r.y, r.z + 1.0); let m = 2.0 * r2.length(); let v_n = r.xy() / m + 0.5; - + let tex_coord = vec3(v_n.x, v_n.y, in_tex_index as f32); let sampled_color = mat_cap.sample(tex_coord); - + *out_frag_color = vec4( sampled_color.x * (in_color.x * 2.0).clamp(0.0, 1.0), sampled_color.y * (in_color.x * 2.0).clamp(0.0, 1.0), sampled_color.z * (in_color.x * 2.0).clamp(0.0, 1.0), - 1.0 + 1.0, ); -} \ No newline at end of file +} diff --git a/shaders/rust/ssao/blur/src/lib.rs b/shaders/rust/ssao/blur/src/lib.rs index 2d38858c3..18af0a1ef 100644 --- a/shaders/rust/ssao/blur/src/lib.rs +++ b/shaders/rust/ssao/blur/src/lib.rs @@ -22,7 +22,7 @@ pub fn main_fs( let mut n = 0; let texel_size = ubo.texel_size; let mut result = 0.0; - + for x in -BLUR_RANGE..=BLUR_RANGE { for y in -BLUR_RANGE..=BLUR_RANGE { let offset = vec2(x as f32, y as f32) * texel_size; @@ -30,6 +30,6 @@ pub fn main_fs( n += 1; } } - + *out_frag_color = result / n as f32; -} \ No newline at end of file +} diff --git a/shaders/rust/ssao/composition/src/lib.rs b/shaders/rust/ssao/composition/src/lib.rs index 20b0c7002..94eb26f9d 100644 --- a/shaders/rust/ssao/composition/src/lib.rs +++ b/shaders/rust/ssao/composition/src/lib.rs @@ -32,25 +32,25 @@ pub fn main_fs( let frag_pos = texture_position.sample(*sampler_position, in_uv).xyz(); let normal = (texture_normal.sample(*sampler_normal, in_uv).xyz() * 2.0 - 1.0).normalize(); let albedo = texture_albedo.sample(*sampler_albedo, in_uv); - + let ssao = if ubo_params.ssao_blur == 1 { texture_ssao_blur.sample(*sampler_ssao_blur, in_uv).x } else { texture_ssao.sample(*sampler_ssao, in_uv).x }; - + let light_pos = Vec3::ZERO; let l = (light_pos - frag_pos).normalize(); let n_dot_l = normal.dot(l).max(0.5); - + if ubo_params.ssao_only == 1 { *out_frag_color = vec4(ssao, ssao, ssao, 1.0); } else { let base_color = albedo.xyz() * n_dot_l; - + if ubo_params.ssao == 1 { let mut color = vec3(ssao, ssao, ssao); - + if ubo_params.ssao_only != 1 { color *= base_color; } @@ -59,4 +59,4 @@ pub fn main_fs( *out_frag_color = vec4(base_color.x, base_color.y, base_color.z, 1.0); } } -} \ No newline at end of file +} diff --git a/shaders/rust/ssao/fullscreen/src/lib.rs b/shaders/rust/ssao/fullscreen/src/lib.rs index b49721196..59a37b13a 100644 --- a/shaders/rust/ssao/fullscreen/src/lib.rs +++ b/shaders/rust/ssao/fullscreen/src/lib.rs @@ -9,10 +9,7 @@ pub fn main_vs( #[spirv(position)] out_position: &mut Vec4, out_uv: &mut Vec2, ) { - let uv = vec2( - ((vert_index << 1) & 2) as f32, - (vert_index & 2) as f32, - ); + let uv = vec2(((vert_index << 1) & 2) as f32, (vert_index & 2) as f32); *out_uv = uv; *out_position = vec4(uv.x * 2.0 - 1.0, uv.y * 2.0 - 1.0, 0.0, 1.0); -} \ No newline at end of file +} diff --git a/shaders/rust/ssao/gbuffer/src/lib.rs b/shaders/rust/ssao/gbuffer/src/lib.rs index 28a76b7ff..d27d2a6a0 100644 --- a/shaders/rust/ssao/gbuffer/src/lib.rs +++ b/shaders/rust/ssao/gbuffer/src/lib.rs @@ -29,14 +29,14 @@ pub fn main_vs( ) { *out_position = ubo.projection * ubo.view * ubo.model * in_pos; *out_uv = in_uv; - + // Vertex position in view space *out_pos = (ubo.view * ubo.model * in_pos).truncate(); - + // Normal in view space let normal_matrix = Mat3::from_mat4(ubo.view * ubo.model); *out_normal = normal_matrix * in_normal; - + *out_color = in_color; } @@ -57,11 +57,17 @@ pub fn main_fs( let depth = linear_depth(frag_coord.z, ubo.near_plane, ubo.far_plane); *out_position = vec4(in_pos.x, in_pos.y, in_pos.z, depth); let normalized_normal = in_normal.normalize() * 0.5 + 0.5; - *out_normal = vec4(normalized_normal.x, normalized_normal.y, normalized_normal.z, 1.0); - *out_albedo = texture_colormap.sample(*sampler_colormap, in_uv) * vec4(in_color.x, in_color.y, in_color.z, 1.0); + *out_normal = vec4( + normalized_normal.x, + normalized_normal.y, + normalized_normal.z, + 1.0, + ); + *out_albedo = texture_colormap.sample(*sampler_colormap, in_uv) + * vec4(in_color.x, in_color.y, in_color.z, 1.0); } fn linear_depth(depth: f32, near_plane: f32, far_plane: f32) -> f32 { let z = depth * 2.0 - 1.0; (2.0 * near_plane * far_plane) / (far_plane + near_plane - z * (far_plane - near_plane)) -} \ No newline at end of file +} diff --git a/shaders/rust/ssao/ssao/src/lib.rs b/shaders/rust/ssao/ssao/src/lib.rs index abda4382a..541cefdad 100644 --- a/shaders/rust/ssao/ssao/src/lib.rs +++ b/shaders/rust/ssao/ssao/src/lib.rs @@ -34,41 +34,50 @@ pub fn main_fs( out_frag_color: &mut f32, ) { // Get G-Buffer values - let frag_pos = texture_position_depth.sample(*sampler_position_depth, in_uv).xyz(); + let frag_pos = texture_position_depth + .sample(*sampler_position_depth, in_uv) + .xyz(); let normal = (texture_normal.sample(*sampler_normal, in_uv).xyz() * 2.0 - 1.0).normalize(); - + // Get a random vector using a noise lookup let noise_uv = ubo.noise_scale * in_uv; - let random_vec = texture_ssao_noise.sample(*sampler_ssao_noise, noise_uv).xyz() * 2.0 - 1.0; - + let random_vec = texture_ssao_noise + .sample(*sampler_ssao_noise, noise_uv) + .xyz() + * 2.0 + - 1.0; + // Create TBN matrix let tangent = (random_vec - normal * random_vec.dot(normal)).normalize(); let bitangent = tangent.cross(normal); let tbn = Mat3::from_cols(tangent, bitangent, normal); - + // Calculate occlusion value let mut occlusion = 0.0f32; let bias = 0.025f32; - + for i in 0..SSAO_KERNEL_SIZE { let sample_vec = ubo_ssao_kernel.samples[i].xyz(); let sample_pos = frag_pos + tbn * sample_vec * SSAO_RADIUS; - + // Project let mut offset = vec4(sample_pos.x, sample_pos.y, sample_pos.z, 1.0); offset = ubo.projection * offset; let offset_xyz = offset.xyz() / offset.w; - let offset_xy = vec2( - offset_xyz.x * 0.5 + 0.5, - offset_xyz.y * 0.5 + 0.5 - ); - - let sample_depth = -texture_position_depth.sample(*sampler_position_depth, offset_xy).w; - + let offset_xy = vec2(offset_xyz.x * 0.5 + 0.5, offset_xyz.y * 0.5 + 0.5); + + let sample_depth = -texture_position_depth + .sample(*sampler_position_depth, offset_xy) + .w; + let range_check = smoothstep(0.0, 1.0, SSAO_RADIUS / (frag_pos.z - sample_depth).abs()); - occlusion += if sample_depth >= sample_pos.z + bias { 1.0 } else { 0.0 } * range_check; + occlusion += if sample_depth >= sample_pos.z + bias { + 1.0 + } else { + 0.0 + } * range_check; } - + occlusion = 1.0 - (occlusion / SSAO_KERNEL_SIZE as f32); *out_frag_color = occlusion; } @@ -76,4 +85,4 @@ pub fn main_fs( fn smoothstep(edge0: f32, edge1: f32, x: f32) -> f32 { let t = ((x - edge0) / (edge1 - edge0)).clamp(0.0, 1.0); t * t * (3.0 - 2.0 * t) -} \ No newline at end of file +} diff --git a/shaders/rust/stencilbuffer/outline/src/lib.rs b/shaders/rust/stencilbuffer/outline/src/lib.rs index 1947c21a3..c4e6065f9 100644 --- a/shaders/rust/stencilbuffer/outline/src/lib.rs +++ b/shaders/rust/stencilbuffer/outline/src/lib.rs @@ -1,7 +1,7 @@ #![no_std] -use spirv_std::spirv; use spirv_std::glam::{Mat4, Vec3, Vec4}; +use spirv_std::spirv; #[repr(C)] #[derive(Copy, Clone)] @@ -25,14 +25,12 @@ pub fn main_vs( in_pos.x + in_normal.x * ubo.outline_width, in_pos.y + in_normal.y * ubo.outline_width, in_pos.z + in_normal.z * ubo.outline_width, - in_pos.w + in_pos.w, ); *out_position = ubo.projection * ubo.model * pos; } #[spirv(fragment)] -pub fn main_fs( - out_frag_color: &mut Vec4, -) { +pub fn main_fs(out_frag_color: &mut Vec4) { *out_frag_color = Vec4::new(1.0, 1.0, 1.0, 1.0); -} \ No newline at end of file +} diff --git a/shaders/rust/stencilbuffer/toon/src/lib.rs b/shaders/rust/stencilbuffer/toon/src/lib.rs index 319c661f1..2a9e16345 100644 --- a/shaders/rust/stencilbuffer/toon/src/lib.rs +++ b/shaders/rust/stencilbuffer/toon/src/lib.rs @@ -1,7 +1,7 @@ #![no_std] -use spirv_std::spirv; use spirv_std::glam::{Mat3, Mat4, Vec3, Vec4, Vec4Swizzles}; +use spirv_std::spirv; #[repr(C)] #[derive(Copy, Clone)] @@ -25,26 +25,21 @@ pub fn main_vs( ) { *out_color = Vec3::new(1.0, 0.0, 0.0); *out_position = ubo.projection * ubo.model * Vec4::new(in_pos.x, in_pos.y, in_pos.z, 1.0); - + let model_mat3 = Mat3::from_mat4(ubo.model); *out_normal = model_mat3 * in_normal; - + let pos = ubo.model * Vec4::new(in_pos.x, in_pos.y, in_pos.z, 1.0); let l_pos = model_mat3 * ubo.light_pos.xyz(); *out_light_vec = l_pos - pos.xyz(); } #[spirv(fragment)] -pub fn main_fs( - in_normal: Vec3, - in_color: Vec3, - in_light_vec: Vec3, - out_frag_color: &mut Vec4, -) { +pub fn main_fs(in_normal: Vec3, in_color: Vec3, in_light_vec: Vec3, out_frag_color: &mut Vec4) { let n = in_normal.normalize(); let l = in_light_vec.normalize(); let intensity = n.dot(l); - + let mut color = if intensity > 0.98 { in_color * 1.5 } else if intensity > 0.9 { @@ -56,10 +51,10 @@ pub fn main_fs( } else { in_color * 0.2 }; - + // Desaturate a bit let grayscale = Vec3::new(0.2126, 0.7152, 0.0722).dot(color); color = color.lerp(Vec3::splat(grayscale), 0.1); - + *out_frag_color = Vec4::new(color.x, color.y, color.z, 1.0); -} \ No newline at end of file +} diff --git a/shaders/rust/subpasses/composition/src/lib.rs b/shaders/rust/subpasses/composition/src/lib.rs index 1a048a092..81aa4a1ec 100644 --- a/shaders/rust/subpasses/composition/src/lib.rs +++ b/shaders/rust/subpasses/composition/src/lib.rs @@ -1,8 +1,11 @@ #![cfg_attr(target_arch = "spirv", no_std)] #![allow(clippy::missing_safety_doc)] -use spirv_std::{spirv, glam::{Vec2, Vec3, Vec4}}; use spirv_std::num_traits::Float; +use spirv_std::{ + glam::{Vec2, Vec3, Vec4}, + spirv, +}; #[repr(C)] #[derive(Copy, Clone)] @@ -20,10 +23,7 @@ pub fn main_vs( #[spirv(position)] out_position: &mut Vec4, out_uv: &mut Vec2, ) { - let uv = Vec2::new( - ((vertex_index << 1) & 2) as f32, - (vertex_index & 2) as f32 - ); + let uv = Vec2::new(((vertex_index << 1) & 2) as f32, (vertex_index & 2) as f32); *out_uv = uv; *out_position = Vec4::new(uv.x * 2.0 - 1.0, uv.y * 2.0 - 1.0, 0.0, 1.0); } @@ -42,25 +42,25 @@ pub fn main_fs( let frag_pos = input_position.read_subpass(coord).truncate(); let normal = input_normal.read_subpass(coord).truncate(); let albedo = input_albedo.read_subpass(coord); - + // Ambient part let mut frag_color = albedo.truncate() * AMBIENT; - + for i in 0..64 { let light = &lights[i]; let l = light.position.truncate() - frag_pos; let dist = l.length(); - + let l = l.normalize(); let atten = light.radius / (dist.powf(3.0) + 1.0); - + let n = normal.normalize(); let n_dot_l = n.dot(l).max(0.0); let color = Vec3::new(light.color[0], light.color[1], light.color[2]); let diff = color * albedo.truncate() * n_dot_l * atten; - + frag_color += diff; } - + *out_color = Vec4::new(frag_color.x, frag_color.y, frag_color.z, 1.0); -} \ No newline at end of file +} diff --git a/shaders/rust/subpasses/gbuffer/src/lib.rs b/shaders/rust/subpasses/gbuffer/src/lib.rs index bc2b707fb..a9cf07199 100644 --- a/shaders/rust/subpasses/gbuffer/src/lib.rs +++ b/shaders/rust/subpasses/gbuffer/src/lib.rs @@ -1,7 +1,10 @@ #![cfg_attr(target_arch = "spirv", no_std)] #![allow(clippy::missing_safety_doc)] -use spirv_std::{spirv, glam::{Mat3, Mat4, Vec3, Vec4}}; +use spirv_std::{ + glam::{Mat3, Mat4, Vec3, Vec4}, + spirv, +}; #[repr(C)] #[derive(Copy, Clone)] @@ -24,16 +27,16 @@ pub fn main_vs( _out_tangent: &mut Vec3, ) { *out_position = ubo.projection * ubo.view * ubo.model * in_pos; - + // Vertex position in world space let world_pos = (ubo.model * in_pos).truncate(); // GL to Vulkan coord space *out_world_pos = Vec3::new(world_pos.x, -world_pos.y, world_pos.z); - + // Normal in world space let m_normal = Mat3::from_mat4(ubo.model).transpose().inverse(); *out_normal = m_normal * in_normal.normalize(); - + // Currently just vertex color *out_color = in_color; } @@ -52,21 +55,22 @@ pub fn main_fs( out_albedo: &mut Vec4, ) { *out_position = Vec4::new(in_world_pos.x, in_world_pos.y, in_world_pos.z, 1.0); - + let mut n = in_normal.normalize(); n.y = -n.y; *out_normal = Vec4::new(n.x, n.y, n.z, 1.0); - + out_albedo.x = in_color.x; out_albedo.y = in_color.y; out_albedo.z = in_color.z; - + // Store linearized depth in alpha component let near_plane = f32::from_bits(near_plane_bits); let far_plane = f32::from_bits(far_plane_bits); let z = frag_coord.z * 2.0 - 1.0; - out_position.w = (2.0 * near_plane * far_plane) / (far_plane + near_plane - z * (far_plane - near_plane)); - + out_position.w = + (2.0 * near_plane * far_plane) / (far_plane + near_plane - z * (far_plane - near_plane)); + // Write color attachments to avoid undefined behaviour (validation error) *out_color = Vec4::ZERO; -} \ No newline at end of file +} diff --git a/shaders/rust/subpasses/transparent/src/lib.rs b/shaders/rust/subpasses/transparent/src/lib.rs index cbd614f29..b8962839b 100644 --- a/shaders/rust/subpasses/transparent/src/lib.rs +++ b/shaders/rust/subpasses/transparent/src/lib.rs @@ -1,7 +1,10 @@ #![cfg_attr(target_arch = "spirv", no_std)] #![allow(clippy::missing_safety_doc)] -use spirv_std::{spirv, glam::{Mat4, Vec2, Vec3, Vec4}, Sampler, Image}; +use spirv_std::{ + glam::{Mat4, Vec2, Vec3, Vec4}, + spirv, Image, Sampler, +}; #[repr(C)] #[derive(Copy, Clone)] @@ -11,7 +14,6 @@ pub struct Ubo { pub view: Mat4, } - #[spirv(vertex)] pub fn main_vs( in_pos: Vec4, @@ -25,8 +27,9 @@ pub fn main_vs( ) { *out_color = in_color; *out_uv = in_uv; - - *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)] @@ -44,20 +47,21 @@ pub fn main_fs( // Sample depth from deferred depth buffer and discard if obscured let coord = spirv_std::glam::IVec2::new(0, 0); // Subpass reads at current fragment location let depth = sampler_position_depth.read_subpass(coord).w; - + // Save the sampled texture color before discarding. // This is to avoid implicit derivatives in non-uniform control flow. let sampled_color: Vec4 = texture.sample(*sampler, in_uv); - + // Linearize depth let near_plane = f32::from_bits(near_plane_bits); let far_plane = f32::from_bits(far_plane_bits); let z = frag_coord.z * 2.0 - 1.0; - let linear_depth = (2.0 * near_plane * far_plane) / (far_plane + near_plane - z * (far_plane - near_plane)); - + let linear_depth = + (2.0 * near_plane * far_plane) / (far_plane + near_plane - z * (far_plane - near_plane)); + if depth != 0.0 && linear_depth > depth { spirv_std::arch::kill(); } - + *out_color = sampled_color; -} \ No newline at end of file +} diff --git a/shaders/rust/terraintessellation/skysphere/src/lib.rs b/shaders/rust/terraintessellation/skysphere/src/lib.rs index f824ad839..f495320ec 100644 --- a/shaders/rust/terraintessellation/skysphere/src/lib.rs +++ b/shaders/rust/terraintessellation/skysphere/src/lib.rs @@ -32,4 +32,4 @@ pub fn main_fs( ) { let color = sampler_color_map.sample(*sampler, in_uv); *out_frag_color = Vec4::from((color.xyz(), 1.0)); -} \ No newline at end of file +} diff --git a/shaders/rust/terraintessellation/terrain/src/lib.rs b/shaders/rust/terraintessellation/terrain/src/lib.rs index 777a4075b..c968bb236 100644 --- a/shaders/rust/terraintessellation/terrain/src/lib.rs +++ b/shaders/rust/terraintessellation/terrain/src/lib.rs @@ -47,7 +47,8 @@ fn screen_space_tess_factor(p0: Vec4, p1: Vec4, ubo: &UBO) -> f32 { let clip0_vp = clip0.xy() * ubo.viewport_dim; let clip1_vp = clip1.xy() * ubo.viewport_dim; - (clip0_vp.distance(clip1_vp) / ubo.tessellated_edge_size * ubo.tessellation_factor).clamp(1.0, 64.0) + (clip0_vp.distance(clip1_vp) / ubo.tessellated_edge_size * ubo.tessellation_factor) + .clamp(1.0, 64.0) } fn frustum_check( @@ -85,7 +86,13 @@ pub fn main_tcs( #[spirv(tess_level_outer)] tess_level_outer: &mut [f32; 4], ) { if invocation_id == 0 { - if !frustum_check(in_position[invocation_id as usize], in_uv[0], ubo, sampler_height, sampler) { + if !frustum_check( + in_position[invocation_id as usize], + in_uv[0], + ubo, + sampler_height, + sampler, + ) { tess_level_inner[0] = 0.0; tess_level_inner[1] = 0.0; tess_level_outer[0] = 0.0; @@ -145,9 +152,9 @@ pub fn main_tes( let pos1 = in_position[0].lerp(in_position[1], tess_coord.x); let pos2 = in_position[3].lerp(in_position[2], tess_coord.x); let mut pos = pos1.lerp(pos2, tess_coord.y); - + pos.y -= displacement_map.sample_by_lod(*sampler, *out_uv, 0.0).x * ubo.displacement_factor; - + *out_position = ubo.projection * ubo.modelview * pos; *out_view_vec = -pos.xyz(); @@ -172,14 +179,17 @@ fn sample_terrain_layer( ]; let mut color = Vec3::ZERO; - + let height = sampler_height.sample_by_lod(*sampler, uv, 0.0).x * 255.0; - + for i in 0..6 { let range = layers[i].y - layers[i].x; let weight = ((range - (height - layers[i].y).abs()) / range).max(0.0); let tex_coord = uv * 16.0; - color += weight * sampler_layers.sample(*sampler, vec3(tex_coord.x, tex_coord.y, i as f32)).xyz(); + color += weight + * sampler_layers + .sample(*sampler, vec3(tex_coord.x, tex_coord.y, i as f32)) + .xyz(); } color @@ -211,8 +221,11 @@ pub fn main_fs( let ambient = Vec3::splat(0.5); let diffuse = n.dot(l).max(0.0) * Vec3::ONE; - let color = Vec4::from(((ambient + diffuse) * sample_terrain_layer(in_uv, sampler_height, sampler_layers, sampler), 1.0)); + let color = Vec4::from(( + (ambient + diffuse) * sample_terrain_layer(in_uv, sampler_height, sampler_layers, sampler), + 1.0, + )); const FOG_COLOR: Vec4 = Vec4::new(0.47, 0.5, 0.67, 0.0); *out_frag_color = color.lerp(FOG_COLOR, fog(frag_coord.z / frag_coord.w)); -} \ No newline at end of file +} diff --git a/shaders/rust/tessellation/base/src/lib.rs b/shaders/rust/tessellation/base/src/lib.rs index f4cf08003..2de50c12a 100644 --- a/shaders/rust/tessellation/base/src/lib.rs +++ b/shaders/rust/tessellation/base/src/lib.rs @@ -1,7 +1,10 @@ #![cfg_attr(target_arch = "spirv", no_std)] #![allow(clippy::missing_safety_doc)] -use spirv_std::{spirv, glam::{Vec2, Vec3, Vec4}, Image, Sampler}; +use spirv_std::{ + glam::{Vec2, Vec3, Vec4}, + spirv, Image, Sampler, +}; #[spirv(vertex)] pub fn main_vs( @@ -27,14 +30,14 @@ pub fn main_fs( ) { let n = in_normal.normalize(); let l = Vec3::new(-4.0, -4.0, 0.0).normalize(); - + let color: Vec4 = color_texture.sample(*color_sampler, in_uv); - + let lighting = n.dot(l).max(0.0).clamp(0.2, 1.0); *out_frag_color = Vec4::new( lighting * color.x, lighting * color.y, lighting * color.z, - color.w + color.w, ); -} \ No newline at end of file +} diff --git a/shaders/rust/tessellation/passthrough/src/lib.rs b/shaders/rust/tessellation/passthrough/src/lib.rs index cd8573708..f13133475 100644 --- a/shaders/rust/tessellation/passthrough/src/lib.rs +++ b/shaders/rust/tessellation/passthrough/src/lib.rs @@ -1,7 +1,10 @@ #![cfg_attr(target_arch = "spirv", no_std)] #![allow(clippy::missing_safety_doc)] -use spirv_std::{spirv, glam::{Mat4, Vec2, Vec3, Vec4}}; +use spirv_std::{ + glam::{Mat4, Vec2, Vec3, Vec4}, + spirv, +}; #[repr(C)] #[derive(Copy, Clone)] @@ -47,17 +50,14 @@ pub fn main_tes( out_normal: &mut Vec3, out_uv: &mut Vec2, ) { - let pos = tess_coord.x * in_position[0] + - tess_coord.y * in_position[1] + - tess_coord.z * in_position[2]; - + let pos = tess_coord.x * in_position[0] + + tess_coord.y * in_position[1] + + tess_coord.z * in_position[2]; + *out_position = ubo.projection * ubo.model * pos; - - *out_normal = tess_coord.x * in_normal[0] + - tess_coord.y * in_normal[1] + - tess_coord.z * in_normal[2]; - - *out_uv = tess_coord.x * in_uv[0] + - tess_coord.y * in_uv[1] + - tess_coord.z * in_uv[2]; -} \ No newline at end of file + + *out_normal = + tess_coord.x * in_normal[0] + tess_coord.y * in_normal[1] + tess_coord.z * in_normal[2]; + + *out_uv = tess_coord.x * in_uv[0] + tess_coord.y * in_uv[1] + tess_coord.z * in_uv[2]; +} diff --git a/shaders/rust/tessellation/pntriangles/src/lib.rs b/shaders/rust/tessellation/pntriangles/src/lib.rs index 9d1534144..0dd60ca7e 100644 --- a/shaders/rust/tessellation/pntriangles/src/lib.rs +++ b/shaders/rust/tessellation/pntriangles/src/lib.rs @@ -1,7 +1,10 @@ #![cfg_attr(target_arch = "spirv", no_std)] #![allow(clippy::missing_safety_doc)] -use spirv_std::{spirv, glam::{Mat4, Vec2, Vec3, Vec4}}; +use spirv_std::{ + glam::{Mat4, Vec2, Vec3, Vec4}, + spirv, +}; #[repr(C)] #[derive(Copy, Clone)] @@ -52,12 +55,12 @@ pub fn main_tcs( #[spirv(tess_level_outer)] tess_level_outer: &mut [f32; 4], ) { let inv_id = invocation_id as usize; - + // Pass through vertex data out_position[inv_id] = in_position[inv_id]; out_normal[inv_id] = in_normal[inv_id]; out_uv[inv_id] = in_uv[inv_id]; - + // Extract component for current invocation // In GLSL, gl_InvocationID is used as a swizzle index (0=x, 1=y, 2=z) // to extract a single float from each vertex's position/normal @@ -97,7 +100,7 @@ pub fn main_tcs( 2 => in_normal[2].z, _ => 0.0, }; - + // Compute control points out_patch[inv_id].b210 = (2.0 * p0 + p1 - wij(0, 1, &in_position, &in_normal) * n0) / 3.0; out_patch[inv_id].b120 = (2.0 * p1 + p0 - wij(1, 0, &in_position, &in_normal) * n1) / 3.0; @@ -105,21 +108,22 @@ pub fn main_tcs( out_patch[inv_id].b012 = (2.0 * p2 + p1 - wij(2, 1, &in_position, &in_normal) * n2) / 3.0; out_patch[inv_id].b102 = (2.0 * p2 + p0 - wij(2, 0, &in_position, &in_normal) * n2) / 3.0; out_patch[inv_id].b201 = (2.0 * p0 + p2 - wij(0, 2, &in_position, &in_normal) * n0) / 3.0; - - let e = (out_patch[inv_id].b210 + - out_patch[inv_id].b120 + - out_patch[inv_id].b021 + - out_patch[inv_id].b012 + - out_patch[inv_id].b102 + - out_patch[inv_id].b201) / 6.0; + + let e = (out_patch[inv_id].b210 + + out_patch[inv_id].b120 + + out_patch[inv_id].b021 + + out_patch[inv_id].b012 + + out_patch[inv_id].b102 + + out_patch[inv_id].b201) + / 6.0; let v = (p0 + p1 + p2) / 3.0; out_patch[inv_id].b111 = e + (e - v) * 0.5; - + // Compute normal control points out_patch[inv_id].n110 = n0 + n1 - vij(0, 1, &in_position, &in_normal) * (p1 - p0); out_patch[inv_id].n011 = n1 + n2 - vij(1, 2, &in_position, &in_normal) * (p2 - p1); out_patch[inv_id].n101 = n2 + n0 - vij(2, 0, &in_position, &in_normal) * (p0 - p2); - + // Set tessellation levels tess_level_outer[inv_id] = ubo.tess_level; tess_level_inner[0] = ubo.tess_level; @@ -140,12 +144,12 @@ pub fn main_tes( let u = tess_coord.x; let v = tess_coord.y; let w = tess_coord.z; - + let uu = u * u; let vv = v * v; let ww = w * w; let uvw_cubed = Vec3::new(uu * u, vv * v, ww * w); - + // Extract control points as vec3s from the three patches let b210 = Vec3::new(in_patch[0].b210, in_patch[1].b210, in_patch[2].b210); let b120 = Vec3::new(in_patch[0].b120, in_patch[1].b120, in_patch[2].b120); @@ -154,45 +158,50 @@ pub fn main_tes( let b102 = Vec3::new(in_patch[0].b102, in_patch[1].b102, in_patch[2].b102); let b201 = Vec3::new(in_patch[0].b201, in_patch[1].b201, in_patch[2].b201); let b111 = Vec3::new(in_patch[0].b111, in_patch[1].b111, in_patch[2].b111); - + // Extract control normals let n110 = Vec3::new(in_patch[0].n110, in_patch[1].n110, in_patch[2].n110).normalize(); let n011 = Vec3::new(in_patch[0].n011, in_patch[1].n011, in_patch[2].n011).normalize(); let n101 = Vec3::new(in_patch[0].n101, in_patch[1].n101, in_patch[2].n101).normalize(); - + // Compute texcoords - note the order: w*tc0 + u*tc1 + v*tc2 *out_uv = w * in_uv[0] + u * in_uv[1] + v * in_uv[2]; - + // Compute normals // Barycentric normal let bar_normal = w * in_normal[0] + u * in_normal[1] + v * in_normal[2]; // PN normal - let pn_normal = in_normal[0] * ww + in_normal[1] * uu + in_normal[2] * vv + - n110 * w * u + n011 * u * v + n101 * w * v; + let pn_normal = in_normal[0] * ww + + in_normal[1] * uu + + in_normal[2] * vv + + n110 * w * u + + n011 * u * v + + n101 * w * v; *out_normal = (ubo.tess_alpha * pn_normal + (1.0 - ubo.tess_alpha) * bar_normal).normalize(); - + // Compute position // Barycentric position - let bar_pos = w * in_position[0].truncate() + - u * in_position[1].truncate() + - v * in_position[2].truncate(); - + let bar_pos = w * in_position[0].truncate() + + u * in_position[1].truncate() + + v * in_position[2].truncate(); + // Save some computations let uvw_squared3 = Vec3::new(uu * 3.0, vv * 3.0, ww * 3.0); - + // Compute PN position - let pn_pos = in_position[0].truncate() * uvw_cubed.z + - in_position[1].truncate() * uvw_cubed.x + - in_position[2].truncate() * uvw_cubed.y + - b210 * uvw_squared3.z * u + - b120 * uvw_squared3.x * w + - b201 * uvw_squared3.z * v + - b021 * uvw_squared3.x * v + - b102 * uvw_squared3.y * w + - b012 * uvw_squared3.y * u + - b111 * 6.0 * u * v * w; - + let pn_pos = in_position[0].truncate() * uvw_cubed.z + + in_position[1].truncate() * uvw_cubed.x + + in_position[2].truncate() * uvw_cubed.y + + b210 * uvw_squared3.z * u + + b120 * uvw_squared3.x * w + + b201 * uvw_squared3.z * v + + b021 * uvw_squared3.x * v + + b102 * uvw_squared3.y * w + + b012 * uvw_squared3.y * u + + b111 * 6.0 * u * v * w; + // Final position let final_pos = (1.0 - ubo.tess_alpha) * bar_pos + ubo.tess_alpha * pn_pos; - *out_position = ubo.projection * ubo.model * Vec4::new(final_pos.x, final_pos.y, final_pos.z, 1.0); -} \ No newline at end of file + *out_position = + ubo.projection * ubo.model * Vec4::new(final_pos.x, final_pos.y, final_pos.z, 1.0); +} diff --git a/shaders/rust/textoverlay/mesh/src/lib.rs b/shaders/rust/textoverlay/mesh/src/lib.rs index 51d2c1d32..6f32938e8 100644 --- a/shaders/rust/textoverlay/mesh/src/lib.rs +++ b/shaders/rust/textoverlay/mesh/src/lib.rs @@ -1,7 +1,11 @@ #![cfg_attr(target_arch = "spirv", no_std)] #![allow(clippy::missing_safety_doc)] -use spirv_std::{spirv, glam::{mat3, vec3, vec4, Mat4, Vec2, Vec3, Vec4}, num_traits::Float}; +use spirv_std::{ + glam::{mat3, vec3, vec4, Mat4, Vec2, Vec3, Vec4}, + num_traits::Float, + spirv, +}; #[repr(C)] #[derive(Copy, Clone)] @@ -26,10 +30,17 @@ pub fn main_vs( *out_normal = in_normal; *out_uv = in_uv; *out_position = ubo.projection * ubo.model * vec4(in_pos.x, in_pos.y, in_pos.z, 1.0); - + let pos = ubo.model * vec4(in_pos.x, in_pos.y, in_pos.z, 1.0); let normalized_normal = in_normal.normalize(); - *out_normal = (ubo.model.inverse().transpose() * vec4(normalized_normal.x, normalized_normal.y, normalized_normal.z, 0.0)).truncate(); + *out_normal = (ubo.model.inverse().transpose() + * vec4( + normalized_normal.x, + normalized_normal.y, + normalized_normal.z, + 0.0, + )) + .truncate(); let model_mat3 = mat3( ubo.model.x_axis.truncate(), ubo.model.y_axis.truncate(), @@ -56,4 +67,4 @@ pub fn main_fs( let specular = r.dot(v).max(0.0).powf(1.0); let color = vec3(0.25, 0.25, 0.25) * (diffuse + specular); *out_frag_color = vec4(color.x, color.y, color.z, 1.0); -} \ No newline at end of file +} diff --git a/shaders/rust/textoverlay/text/src/lib.rs b/shaders/rust/textoverlay/text/src/lib.rs index 1e79ffdcb..1cef222c5 100644 --- a/shaders/rust/textoverlay/text/src/lib.rs +++ b/shaders/rust/textoverlay/text/src/lib.rs @@ -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, +}; #[spirv(vertex)] pub fn main_vs( @@ -18,9 +21,11 @@ pub fn main_vs( #[spirv(fragment)] pub fn main_fs( in_uv: Vec2, - #[spirv(descriptor_set = 0, binding = 0)] sampler_font: &SampledImage, + #[spirv(descriptor_set = 0, binding = 0)] sampler_font: &SampledImage< + Image!(2D, type=f32, sampled), + >, out_frag_color: &mut Vec4, ) { let color = sampler_font.sample(in_uv).x; *out_frag_color = vec4(color, color, color, color); -} \ No newline at end of file +} diff --git a/shaders/rust/texture/src/lib.rs b/shaders/rust/texture/src/lib.rs index 7ca08fc7d..a7ff1feaf 100644 --- a/shaders/rust/texture/src/lib.rs +++ b/shaders/rust/texture/src/lib.rs @@ -1,8 +1,12 @@ #![cfg_attr(target_arch = "spirv", no_std)] #![allow(clippy::missing_safety_doc)] -use spirv_std::{spirv, glam::{mat3, vec3, vec4, Mat4, Vec2, Vec3, Vec4}, Image, num_traits::Float}; use spirv_std::image::SampledImage; +use spirv_std::{ + glam::{mat3, vec3, vec4, Mat4, Vec2, Vec3, Vec4}, + num_traits::Float, + spirv, Image, +}; #[repr(C)] #[derive(Copy, Clone)] @@ -29,7 +33,6 @@ pub fn main_vs( *out_uv = in_uv; *out_lod_bias = ubo.lod_bias; - *out_position = ubo.projection * ubo.model * vec4(in_pos.x, in_pos.y, in_pos.z, 1.0); let pos = ubo.model * vec4(in_pos.x, in_pos.y, in_pos.z, 1.0); @@ -38,7 +41,9 @@ pub fn main_vs( ubo.model.y_axis.truncate(), ubo.model.z_axis.truncate(), ); - *out_normal = (ubo.model.inverse().transpose() * vec4(in_normal.x, in_normal.y, in_normal.z, 0.0)).truncate(); + *out_normal = (ubo.model.inverse().transpose() + * vec4(in_normal.x, in_normal.y, in_normal.z, 0.0)) + .truncate(); let light_pos = vec3(0.0, 0.0, 0.0); let l_pos = model_mat3 * light_pos; *out_light_vec = l_pos - pos.truncate(); @@ -52,7 +57,9 @@ pub fn main_fs( in_normal: Vec3, in_view_vec: Vec3, in_light_vec: Vec3, - #[spirv(descriptor_set = 0, binding = 1)] color_sampler: &SampledImage, + #[spirv(descriptor_set = 0, binding = 1)] color_sampler: &SampledImage< + Image!(2D, type=f32, sampled), + >, out_frag_color: &mut Vec4, ) { let color = color_sampler.sample(in_uv); @@ -66,4 +73,4 @@ pub fn main_fs( let final_color = diffuse * color.truncate() + vec3(specular, specular, specular); *out_frag_color = vec4(final_color.x, final_color.y, final_color.z, 1.0); -} \ No newline at end of file +} diff --git a/shaders/rust/texture3d/src/lib.rs b/shaders/rust/texture3d/src/lib.rs index 6800d3590..65a0c2717 100644 --- a/shaders/rust/texture3d/src/lib.rs +++ b/shaders/rust/texture3d/src/lib.rs @@ -1,8 +1,8 @@ #![cfg_attr(target_arch = "spirv", no_std)] -use spirv_std::spirv; use spirv_std::glam::{vec3, vec4, Mat4, Vec2, Vec3, Vec4}; use spirv_std::num_traits::Float; +use spirv_std::spirv; #[repr(C)] pub struct UBO { @@ -26,22 +26,22 @@ pub fn main_vs( out_light_vec: &mut Vec3, ) { *out_uv = vec3(in_uv.x, in_uv.y, ubo.depth); - + let world_pos = (ubo.model * vec4(in_pos.x, in_pos.y, in_pos.z, 1.0)).truncate(); - + *out_position = ubo.projection * ubo.model * vec4(in_pos.x, in_pos.y, in_pos.z, 1.0); - + let pos = ubo.model * vec4(in_pos.x, in_pos.y, in_pos.z, 1.0); - + // Transform normal by inverse transpose of model matrix let normal_matrix = ubo.model.inverse().transpose(); *out_normal = normal_matrix.transform_vector3(in_normal); - + let light_pos = Vec3::ZERO; let l_pos = ubo.model.transform_vector3(light_pos); *out_light_vec = l_pos - pos.truncate(); *out_view_vec = ubo.view_pos.truncate() - pos.truncate(); - + // Note: out_lod_bias is not used in the GLSL shader, leaving uninitialized *out_lod_bias = 0.0; } @@ -58,23 +58,25 @@ pub fn main_fs( in_normal: Vec3, in_view_vec: Vec3, in_light_vec: Vec3, - #[spirv(descriptor_set = 0, binding = 1)] sampler_color: &spirv_std::image::SampledImage, + #[spirv(descriptor_set = 0, binding = 1)] sampler_color: &spirv_std::image::SampledImage< + spirv_std::image::Image3d, + >, out_color: &mut Vec4, ) { let color = sampler_color.sample(in_uv); - + let n = in_normal.normalize(); let l = in_light_vec.normalize(); let v = in_view_vec.normalize(); let r = reflect(-l, n); - + let diffuse = n.dot(l).max(0.0) * vec3(1.0, 1.0, 1.0); let specular = r.dot(v).max(0.0).powf(16.0) * color.x; - + *out_color = vec4( diffuse.x * color.x + specular, diffuse.y * color.x + specular, diffuse.z * color.x + specular, - 1.0 + 1.0, ); -} \ No newline at end of file +} diff --git a/shaders/rust/texturearray/instancing/src/lib.rs b/shaders/rust/texturearray/instancing/src/lib.rs index c3b03efb3..ddb139420 100644 --- a/shaders/rust/texturearray/instancing/src/lib.rs +++ b/shaders/rust/texturearray/instancing/src/lib.rs @@ -1,8 +1,11 @@ #![cfg_attr(target_arch = "spirv", no_std)] #![allow(clippy::missing_safety_doc)] -use spirv_std::{spirv, glam::{vec3, vec4, Mat4, Vec2, Vec3, Vec4}, Image}; use spirv_std::image::SampledImage; +use spirv_std::{ + glam::{vec3, vec4, Mat4, Vec2, Vec3, Vec4}, + spirv, Image, +}; // Each Instance needs to be exactly 80 bytes for proper alignment in arrays // NOTE: rust-gpu has issues with array padding in structs that are themselves in arrays, // so we use individual padding fields instead of _pad: [f32; 3] @@ -12,7 +15,7 @@ pub struct Instance { pub model: Mat4, // 64 bytes pub array_index: f32, // 4 bytes pub _pad0: f32, // 4 bytes padding - pub _pad1: f32, // 4 bytes padding + pub _pad1: f32, // 4 bytes padding pub _pad2: f32, // 4 bytes padding } @@ -42,8 +45,10 @@ pub fn main_vs( #[spirv(fragment)] pub fn main_fs( in_uv: Vec3, - #[spirv(descriptor_set = 0, binding = 1)] sampler_array: &SampledImage, + #[spirv(descriptor_set = 0, binding = 1)] sampler_array: &SampledImage< + Image!(2D, type=f32, sampled, arrayed), + >, out_frag_color: &mut Vec4, ) { *out_frag_color = sampler_array.sample(in_uv); -} \ No newline at end of file +} diff --git a/shaders/rust/texturecubemap/reflect/src/lib.rs b/shaders/rust/texturecubemap/reflect/src/lib.rs index 775ea15be..305e06cfa 100644 --- a/shaders/rust/texturecubemap/reflect/src/lib.rs +++ b/shaders/rust/texturecubemap/reflect/src/lib.rs @@ -1,8 +1,11 @@ #![no_std] -use spirv_std::spirv; -use spirv_std::{glam::{vec3, vec4, Mat3, Mat4, Vec3, Vec4}, image::{Cubemap, SampledImage}}; use spirv_std::num_traits::Float; +use spirv_std::spirv; +use spirv_std::{ + glam::{vec3, vec4, Mat3, Mat4, Vec3, Vec4}, + image::{Cubemap, SampledImage}, +}; #[repr(C)] pub struct UBO { @@ -25,10 +28,10 @@ pub fn main_vs( out_light_vec: &mut Vec3, ) { *out_pos = ubo.projection * ubo.model * vec4(in_pos.x, in_pos.y, in_pos.z, 1.0); - + *out_world_pos = (ubo.model * vec4(in_pos.x, in_pos.y, in_pos.z, 1.0)).truncate(); *out_normal = Mat3::from_mat4(ubo.model) * in_normal; - + let light_pos = vec3(0.0, -5.0, 5.0); *out_light_vec = light_pos - *out_world_pos; *out_view_vec = -*out_world_pos; @@ -46,22 +49,22 @@ pub fn main_fs( ) { let ci = in_pos.normalize(); let cr = ci.reflect(in_normal.normalize()); - + let mut cr_transformed = (ubo.inv_model * vec4(cr.x, cr.y, cr.z, 0.0)).truncate(); cr_transformed.x *= -1.0; cr_transformed.y *= -1.0; - + let color = sampler_color.sample_by_lod(cr_transformed, ubo.lod_bias); - + let n = in_normal.normalize(); let l = in_light_vec.normalize(); let v = in_view_vec.normalize(); let r = (-l).reflect(n); - + let ambient = vec3(0.5, 0.5, 0.5) * color.truncate(); let diffuse = n.dot(l).max(0.0) * vec3(1.0, 1.0, 1.0); let specular = r.dot(v).max(0.0).powf(16.0) * vec3(0.5, 0.5, 0.5); - + let final_color = ambient + diffuse * color.truncate() + specular; *out_frag_color = vec4(final_color.x, final_color.y, final_color.z, 1.0); -} \ No newline at end of file +} diff --git a/shaders/rust/texturecubemap/skybox/src/lib.rs b/shaders/rust/texturecubemap/skybox/src/lib.rs index c427ea587..f3528ee61 100644 --- a/shaders/rust/texturecubemap/skybox/src/lib.rs +++ b/shaders/rust/texturecubemap/skybox/src/lib.rs @@ -1,7 +1,10 @@ #![no_std] use spirv_std::spirv; -use spirv_std::{glam::{vec4, Mat3, Mat4, Vec3, Vec4}, image::{Cubemap, SampledImage}}; +use spirv_std::{ + glam::{vec4, Mat3, Mat4, Vec3, Vec4}, + image::{Cubemap, SampledImage}, +}; #[repr(C)] pub struct SkyboxUBO { @@ -20,7 +23,7 @@ pub fn main_vs( *out_uvw = in_pos; out_uvw.x *= -1.0; out_uvw.y *= -1.0; - + let view_mat = Mat4::from_mat3(Mat3::from_mat4(ubo.model)); *out_pos = ubo.projection * view_mat * vec4(in_pos.x, in_pos.y, in_pos.z, 1.0); } @@ -32,4 +35,4 @@ pub fn main_fs( out_frag_color: &mut Vec4, ) { *out_frag_color = sampler_cube_map.sample(in_uvw); -} \ No newline at end of file +} diff --git a/shaders/rust/texturecubemaparray/reflect/src/lib.rs b/shaders/rust/texturecubemaparray/reflect/src/lib.rs index d213cc71f..899442c95 100644 --- a/shaders/rust/texturecubemaparray/reflect/src/lib.rs +++ b/shaders/rust/texturecubemaparray/reflect/src/lib.rs @@ -1,8 +1,11 @@ #![no_std] -use spirv_std::spirv; -use spirv_std::{glam::{vec3, vec4, Mat3, Mat4, Vec3, Vec4}, Image, Sampler}; use spirv_std::num_traits::Float; +use spirv_std::spirv; +use spirv_std::{ + glam::{vec3, vec4, Mat3, Mat4, Vec3, Vec4}, + Image, Sampler, +}; #[repr(C)] pub struct UBO { @@ -26,10 +29,10 @@ pub fn main_vs( out_light_vec: &mut Vec3, ) { *out_pos = ubo.projection * ubo.model * vec4(in_pos.x, in_pos.y, in_pos.z, 1.0); - + *out_world_pos = (ubo.model * vec4(in_pos.x, in_pos.y, in_pos.z, 1.0)).truncate(); *out_normal = Mat3::from_mat4(ubo.model) * in_normal; - + let light_pos = vec3(0.0, -5.0, 5.0); *out_light_vec = light_pos - *out_world_pos; *out_view_vec = -*out_world_pos; @@ -48,23 +51,28 @@ pub fn main_fs( ) { let ci = in_pos.normalize(); let cr = ci.reflect(in_normal.normalize()); - + let mut cr_transformed = (ubo.inv_model * vec4(cr.x, cr.y, cr.z, 0.0)).truncate(); cr_transformed.y *= -1.0; cr_transformed.z *= -1.0; - - let coord = vec4(cr_transformed.x, cr_transformed.y, cr_transformed.z, ubo.cube_map_index as f32); + + let coord = vec4( + cr_transformed.x, + cr_transformed.y, + cr_transformed.z, + ubo.cube_map_index as f32, + ); let color = image.sample_by_lod(*sampler, coord, ubo.lod_bias); - + let n = in_normal.normalize(); let l = in_light_vec.normalize(); let v = in_view_vec.normalize(); let r = (-l).reflect(n); - + let ambient = vec3(0.5, 0.5, 0.5) * color.truncate(); let diffuse = n.dot(l).max(0.0) * vec3(1.0, 1.0, 1.0); let specular = r.dot(v).max(0.0).powf(16.0) * vec3(0.5, 0.5, 0.5); - + let final_color = ambient + diffuse * color.truncate() + specular; *out_frag_color = vec4(final_color.x, final_color.y, final_color.z, 1.0); -} \ No newline at end of file +} diff --git a/shaders/rust/texturecubemaparray/skybox/src/lib.rs b/shaders/rust/texturecubemaparray/skybox/src/lib.rs index 7f7e6f383..74dfbe850 100644 --- a/shaders/rust/texturecubemaparray/skybox/src/lib.rs +++ b/shaders/rust/texturecubemaparray/skybox/src/lib.rs @@ -1,7 +1,10 @@ #![no_std] use spirv_std::spirv; -use spirv_std::{glam::{vec4, Mat3, Mat4, Vec3, Vec4}, Image, Sampler}; +use spirv_std::{ + glam::{vec4, Mat3, Mat4, Vec3, Vec4}, + Image, Sampler, +}; #[repr(C)] pub struct UBO { @@ -23,7 +26,7 @@ pub fn main_vs( *out_uvw = in_pos; out_uvw.x *= -1.0; out_uvw.y *= -1.0; - + // Remove translation from view matrix let view_mat = Mat3::from_mat4(ubo.model); *out_pos = ubo.projection * Mat4::from_mat3(view_mat) * vec4(in_pos.x, in_pos.y, in_pos.z, 1.0); @@ -39,4 +42,4 @@ pub fn main_fs( ) { let coord = vec4(in_uvw.x, in_uvw.y, in_uvw.z, ubo.cube_map_index as f32); *out_frag_color = image.sample_by_lod(*sampler, coord, ubo.lod_bias); -} \ No newline at end of file +} diff --git a/shaders/rust/texturemipmapgen/texture/src/lib.rs b/shaders/rust/texturemipmapgen/texture/src/lib.rs index 2e0f85c77..76b89567f 100644 --- a/shaders/rust/texturemipmapgen/texture/src/lib.rs +++ b/shaders/rust/texturemipmapgen/texture/src/lib.rs @@ -1,7 +1,11 @@ #![cfg_attr(target_arch = "spirv", no_std)] #![allow(clippy::missing_safety_doc)] -use spirv_std::{spirv, glam::{vec2, vec3, vec4, Mat3, Mat4, Vec2, Vec3, Vec4, Vec4Swizzles}, Image, Sampler, num_traits::Float}; +use spirv_std::{ + glam::{vec2, vec3, vec4, Mat3, Mat4, Vec2, Vec3, Vec4, Vec4Swizzles}, + num_traits::Float, + spirv, Image, Sampler, +}; #[repr(C)] #[derive(Copy, Clone)] @@ -63,4 +67,4 @@ pub fn main_fs( let specular = r.dot(v).max(0.0).powf(16.0) * color.w; let final_color = diffuse * color.xyz() + vec3(specular, specular, specular); *out_frag_color = vec4(final_color.x, final_color.y, final_color.z, 1.0); -} \ No newline at end of file +} diff --git a/shaders/rust/triangle/src/lib.rs b/shaders/rust/triangle/src/lib.rs index 6263b015e..50ffe533a 100644 --- a/shaders/rust/triangle/src/lib.rs +++ b/shaders/rust/triangle/src/lib.rs @@ -1,7 +1,10 @@ #![cfg_attr(target_arch = "spirv", no_std)] #![allow(clippy::missing_safety_doc)] -use spirv_std::{spirv, glam::{Mat4, Vec3, Vec4}}; +use spirv_std::{ + glam::{Mat4, Vec3, Vec4}, + spirv, +}; #[repr(C)] #[derive(Copy, Clone)] @@ -20,13 +23,13 @@ pub fn main_vs( out_color: &mut Vec3, ) { *out_color = in_color; - *out_position = ubo.projection_matrix * ubo.view_matrix * ubo.model_matrix * Vec4::new(in_pos.x, in_pos.y, in_pos.z, 1.0); + *out_position = ubo.projection_matrix + * ubo.view_matrix + * ubo.model_matrix + * Vec4::new(in_pos.x, in_pos.y, in_pos.z, 1.0); } #[spirv(fragment)] -pub fn main_fs( - in_color: Vec3, - out_frag_color: &mut Vec4, -) { +pub fn main_fs(in_color: Vec3, out_frag_color: &mut Vec4) { *out_frag_color = Vec4::new(in_color.x, in_color.y, in_color.z, 1.0); } diff --git a/shaders/rust/vertexattributes/scene/src/lib.rs b/shaders/rust/vertexattributes/scene/src/lib.rs index 88edafc27..e4a7d036e 100644 --- a/shaders/rust/vertexattributes/scene/src/lib.rs +++ b/shaders/rust/vertexattributes/scene/src/lib.rs @@ -1,7 +1,12 @@ #![cfg_attr(target_arch = "spirv", no_std)] #![allow(clippy::missing_safety_doc)] -use spirv_std::{spirv, glam::{vec3, vec4, Mat3, Mat4, Vec2, Vec3, Vec4}, Image, image::SampledImage, num_traits::Float}; +use spirv_std::{ + glam::{vec3, vec4, Mat3, Mat4, Vec2, Vec3, Vec4}, + image::SampledImage, + num_traits::Float, + spirv, Image, +}; #[repr(C)] #[derive(Copy, Clone)] @@ -38,12 +43,23 @@ pub fn main_vs( *out_normal = in_normal; *out_uv = in_uv; *out_tangent = in_tangent; - *out_position = ubo_scene.projection * ubo_scene.view * push_consts.model * vec4(in_pos.x, in_pos.y, in_pos.z, 1.0); - + *out_position = ubo_scene.projection + * ubo_scene.view + * push_consts.model + * vec4(in_pos.x, in_pos.y, in_pos.z, 1.0); + *out_normal = Mat3::from_mat4(push_consts.model) * in_normal; let pos = push_consts.model * vec4(in_pos.x, in_pos.y, in_pos.z, 1.0); - *out_light_vec = vec3(ubo_scene.light_pos.x, ubo_scene.light_pos.y, ubo_scene.light_pos.z) - vec3(pos.x, pos.y, pos.z); - *out_view_vec = vec3(ubo_scene.view_pos.x, ubo_scene.view_pos.y, ubo_scene.view_pos.z) - vec3(pos.x, pos.y, pos.z); + *out_light_vec = vec3( + ubo_scene.light_pos.x, + ubo_scene.light_pos.y, + ubo_scene.light_pos.z, + ) - vec3(pos.x, pos.y, pos.z); + *out_view_vec = vec3( + ubo_scene.view_pos.x, + ubo_scene.view_pos.y, + ubo_scene.view_pos.z, + ) - vec3(pos.x, pos.y, pos.z); } #[spirv(fragment)] @@ -53,8 +69,12 @@ pub fn main_fs( in_view_vec: Vec3, in_light_vec: Vec3, in_tangent: Vec4, - #[spirv(descriptor_set = 1, binding = 0)] sampler_color_map: &SampledImage, - #[spirv(descriptor_set = 1, binding = 1)] sampler_normal_map: &SampledImage, + #[spirv(descriptor_set = 1, binding = 0)] sampler_color_map: &SampledImage< + Image!(2D, type=f32, sampled), + >, + #[spirv(descriptor_set = 1, binding = 1)] sampler_normal_map: &SampledImage< + Image!(2D, type=f32, sampled), + >, #[spirv(push_constant)] push_consts: &PushConstants, out_frag_color: &mut Vec4, ) { @@ -71,7 +91,9 @@ pub fn main_fs( let b = in_normal.cross(vec3(in_tangent.x, in_tangent.y, in_tangent.z)) * in_tangent.w; let tbn = Mat3::from_cols(t, b, n); let normal_sample: Vec4 = sampler_normal_map.sample(in_uv); - n = tbn * (vec3(normal_sample.x, normal_sample.y, normal_sample.z) * 2.0 - vec3(1.0, 1.0, 1.0)).normalize(); + n = tbn + * (vec3(normal_sample.x, normal_sample.y, normal_sample.z) * 2.0 - vec3(1.0, 1.0, 1.0)) + .normalize(); const AMBIENT: f32 = 0.1; let l = in_light_vec.normalize(); @@ -80,11 +102,11 @@ pub fn main_fs( let diffuse_factor = n.dot(l).max(AMBIENT); let diffuse = vec3(diffuse_factor, diffuse_factor, diffuse_factor); let specular = r.dot(v).max(0.0).powf(32.0); - + *out_frag_color = vec4( diffuse.x * color.x + specular, diffuse.y * color.y + specular, diffuse.z * color.z + specular, - color.w + color.w, ); -} \ No newline at end of file +} diff --git a/shaders/rust/viewportarray/multiview/src/lib.rs b/shaders/rust/viewportarray/multiview/src/lib.rs index fb9cdd980..407a64c0f 100644 --- a/shaders/rust/viewportarray/multiview/src/lib.rs +++ b/shaders/rust/viewportarray/multiview/src/lib.rs @@ -1,7 +1,10 @@ #![cfg_attr(target_arch = "spirv", no_std)] #![allow(clippy::missing_safety_doc)] -use spirv_std::{spirv, glam::{Mat3, Mat4, Vec3, Vec4}}; +use spirv_std::{ + glam::{Mat3, Mat4, Vec3, Vec4}, + spirv, +}; #[repr(C)] #[derive(Copy, Clone)] @@ -28,26 +31,26 @@ pub fn main_gs( #[spirv(primitive_id, flat)] out_primitive_id: &mut u32, ) { let inv_id = invocation_id as usize; - + for i in 0..3 { *out_normal = Mat3::from_mat4(ubo.modelview[inv_id]) * in_normal[i]; *out_color = in_color[i]; - + let pos = in_position[i]; let world_pos = ubo.modelview[inv_id] * pos; - + let l_pos = (ubo.modelview[inv_id] * ubo.light_pos).truncate(); *out_light_vec = l_pos - world_pos.truncate(); *out_view_vec = -world_pos.truncate(); - + *out_position = ubo.projection[inv_id] * world_pos; - + // Set the viewport index that the vertex will be emitted to *out_viewport_index = invocation_id; *out_primitive_id = primitive_id_in; - + unsafe { spirv_std::arch::emit_vertex() }; } - + unsafe { spirv_std::arch::end_primitive() }; -} \ No newline at end of file +} diff --git a/shaders/rust/viewportarray/scene/src/lib.rs b/shaders/rust/viewportarray/scene/src/lib.rs index b0d0102a9..3f5eb4f0b 100644 --- a/shaders/rust/viewportarray/scene/src/lib.rs +++ b/shaders/rust/viewportarray/scene/src/lib.rs @@ -1,8 +1,11 @@ #![cfg_attr(target_arch = "spirv", no_std)] #![allow(clippy::missing_safety_doc)] -use spirv_std::{spirv, glam::{Vec3, Vec4}}; use spirv_std::num_traits::Float; +use spirv_std::{ + glam::{Vec3, Vec4}, + spirv, +}; #[spirv(vertex)] pub fn main_vs( @@ -37,6 +40,6 @@ pub fn main_fs( ((ambient + diffuse) * in_color + specular).x, ((ambient + diffuse) * in_color + specular).y, ((ambient + diffuse) * in_color + specular).z, - 1.0 + 1.0, ); -} \ No newline at end of file +} diff --git a/shaders/rust/vulkanscene/logo/src/lib.rs b/shaders/rust/vulkanscene/logo/src/lib.rs index 9c86a3249..9ccb8bdb7 100644 --- a/shaders/rust/vulkanscene/logo/src/lib.rs +++ b/shaders/rust/vulkanscene/logo/src/lib.rs @@ -1,7 +1,11 @@ #![cfg_attr(target_arch = "spirv", no_std)] #![allow(clippy::missing_safety_doc)] -use spirv_std::{spirv, glam::{vec4, Mat3, Mat4, Vec2, Vec3, Vec4, Vec4Swizzles}, num_traits::Float}; +use spirv_std::{ + glam::{vec4, Mat3, Mat4, Vec2, Vec3, Vec4, Vec4Swizzles}, + num_traits::Float, + spirv, +}; #[repr(C)] #[derive(Copy, Clone)] @@ -56,4 +60,4 @@ pub fn main_fs( *out_frag_color = diff + spec; out_frag_color.w = 1.0; -} \ No newline at end of file +} diff --git a/shaders/rust/vulkanscene/mesh/src/lib.rs b/shaders/rust/vulkanscene/mesh/src/lib.rs index 3e084bf85..ec67b2738 100644 --- a/shaders/rust/vulkanscene/mesh/src/lib.rs +++ b/shaders/rust/vulkanscene/mesh/src/lib.rs @@ -1,7 +1,12 @@ #![cfg_attr(target_arch = "spirv", no_std)] #![allow(clippy::missing_safety_doc)] -use spirv_std::{spirv, glam::{vec4, Mat3, Mat4, Vec2, Vec3, Vec4, Vec4Swizzles}, Image, image::SampledImage, num_traits::Float}; +use spirv_std::{ + glam::{vec4, Mat3, Mat4, Vec2, Vec3, Vec4, Vec4Swizzles}, + image::SampledImage, + num_traits::Float, + spirv, Image, +}; #[repr(C)] #[derive(Copy, Clone)] @@ -69,7 +74,8 @@ pub fn main_fs( let shininess = 0.75; let i_specular = vec4(0.5, 0.5, 0.5, 1.0) * reflected.dot(eye).max(0.0).powf(2.0) * shininess; - *out_frag_color = (i_ambient + i_diffuse) * vec4(in_color.x, in_color.y, in_color.z, 1.0) + i_specular; + *out_frag_color = + (i_ambient + i_diffuse) * vec4(in_color.x, in_color.y, in_color.z, 1.0) + i_specular; // Some manual saturation if intensity > 0.95 { @@ -78,4 +84,4 @@ pub fn main_fs( if intensity < 0.15 { *out_frag_color = vec4(0.1, 0.1, 0.1, 0.1); } -} \ No newline at end of file +} diff --git a/shaders/rust/vulkanscene/skybox/src/lib.rs b/shaders/rust/vulkanscene/skybox/src/lib.rs index 9807b5023..73f88066a 100644 --- a/shaders/rust/vulkanscene/skybox/src/lib.rs +++ b/shaders/rust/vulkanscene/skybox/src/lib.rs @@ -1,7 +1,11 @@ #![cfg_attr(target_arch = "spirv", no_std)] #![allow(clippy::missing_safety_doc)] -use spirv_std::{spirv, glam::{vec4, Mat3, Mat4, Vec3, Vec4}, image::{SampledImage, Cubemap}}; +use spirv_std::{ + glam::{vec4, Mat3, Mat4, Vec3, Vec4}, + image::{Cubemap, SampledImage}, + spirv, +}; #[repr(C)] #[derive(Copy, Clone)] @@ -32,4 +36,4 @@ pub fn main_fs( out_frag_color: &mut Vec4, ) { *out_frag_color = sampler_cube_map.sample(in_uvw); -} \ No newline at end of file +}