Fixes for WESL on Windows (#18373)
# Objective WESL was broken on windows. ## Solution - Upgrade to `wesl_rs` 1.2. - Fix path handling on windows. - Improve example for khronos demo this week.
This commit is contained in:
parent
4b457cc2ce
commit
35bf9753e8
@ -1,4 +1,4 @@
|
|||||||
import super::shaders::util::make_polka_dots;
|
import super::util::make_polka_dots;
|
||||||
|
|
||||||
struct VertexOutput {
|
struct VertexOutput {
|
||||||
@builtin(position) position: vec4<f32>,
|
@builtin(position) position: vec4<f32>,
|
||||||
|
@ -1,29 +1,44 @@
|
|||||||
fn make_polka_dots(pos: vec2<f32>, time: f32) -> vec4<f32> {
|
fn make_polka_dots(pos: vec2<f32>, time: f32) -> vec4<f32> {
|
||||||
// Create repeating circles
|
|
||||||
let scaled_pos = pos * 6.0;
|
let scaled_pos = pos * 6.0;
|
||||||
let cell = vec2<f32>(fract(scaled_pos.x), fract(scaled_pos.y));
|
let cell = vec2<f32>(fract(scaled_pos.x), fract(scaled_pos.y));
|
||||||
let dist_from_center = distance(cell, vec2<f32>(0.5));
|
var dist_from_center = distance(cell, vec2<f32>(0.5));
|
||||||
|
|
||||||
// Make dots alternate between pink and purple
|
|
||||||
let is_even = (floor(scaled_pos.x) + floor(scaled_pos.y)) % 2.0;
|
let is_even = (floor(scaled_pos.x) + floor(scaled_pos.y)) % 2.0;
|
||||||
|
|
||||||
var dot_color = vec3<f32>(0.0);
|
var dot_color = vec3<f32>(0.0);
|
||||||
|
var is_dot = 0.0;
|
||||||
|
|
||||||
@if(!PARTY_MODE) {
|
@if(!PARTY_MODE) {
|
||||||
let color1 = vec3<f32>(1.0, 0.4, 0.8); // pink
|
let color1 = vec3<f32>(1.0, 0.4, 0.8); // pink
|
||||||
let color2 = vec3<f32>(0.6, 0.2, 1.0); // purple
|
let color2 = vec3<f32>(0.6, 0.2, 1.0); // purple
|
||||||
dot_color = mix(color1, color2, is_even);
|
dot_color = mix(color1, color2, is_even);
|
||||||
}
|
is_dot = step(dist_from_center, 0.3);
|
||||||
// Animate the colors in party mode
|
} @else {
|
||||||
@if(PARTY_MODE) {
|
let grid_x = floor(scaled_pos.x);
|
||||||
let color1 = vec3<f32>(1.0, 0.2, 0.2); // red
|
let grid_y = floor(scaled_pos.y);
|
||||||
let color2 = vec3<f32>(0.2, 0.2, 1.0); // blue
|
let wave_speed = 3.0;
|
||||||
let oscillation = (sin(time * 10.0) + 1.0) * 0.5;
|
let wave_phase = time * wave_speed;
|
||||||
let animated_color1 = mix(color1, color2, oscillation);
|
|
||||||
let animated_color2 = mix(color2, color1, oscillation);
|
let diagonal_pos = (grid_x + grid_y) * 0.5;
|
||||||
|
let wave_value = sin(diagonal_pos + wave_phase);
|
||||||
|
|
||||||
|
let wave_normalized = (wave_value + 1.0) * 0.5;
|
||||||
|
|
||||||
|
let color1 = vec3<f32>(1.0, 0.3, 0.7);
|
||||||
|
let color2 = vec3<f32>(0.5, 0.1, 1.0);
|
||||||
|
let intense_color1 = vec3<f32>(1.0, 0.1, 0.9);
|
||||||
|
let intense_color2 = vec3<f32>(0.8, 0.0, 1.0);
|
||||||
|
|
||||||
|
let animated_color1 = mix(color1, intense_color1, wave_normalized);
|
||||||
|
let animated_color2 = mix(color2, intense_color2, wave_normalized);
|
||||||
|
|
||||||
dot_color = mix(animated_color1, animated_color2, is_even);
|
dot_color = mix(animated_color1, animated_color2, is_even);
|
||||||
|
|
||||||
|
let size_mod = 0.15 * wave_value;
|
||||||
|
dist_from_center = dist_from_center * (1.0 - size_mod);
|
||||||
|
// Animate whether something is a dot by position but also time
|
||||||
|
is_dot = step(dist_from_center, 0.3 + wave_normalized * 0.2);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Draw the dot
|
|
||||||
let is_dot = step(dist_from_center, 0.3);
|
|
||||||
return vec4<f32>(dot_color * is_dot, is_dot);
|
return vec4<f32>(dot_color * is_dot, is_dot);
|
||||||
}
|
}
|
@ -113,7 +113,7 @@ tracing = { version = "0.1", default-features = false, features = ["std"] }
|
|||||||
indexmap = { version = "2" }
|
indexmap = { version = "2" }
|
||||||
fixedbitset = { version = "0.5" }
|
fixedbitset = { version = "0.5" }
|
||||||
bitflags = "2"
|
bitflags = "2"
|
||||||
wesl = { version = "0.1.0", optional = true }
|
wesl = { version = "0.1.2", optional = true }
|
||||||
|
|
||||||
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
|
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
|
||||||
# Omit the `glsl` feature in non-WebAssembly by default.
|
# Omit the `glsl` feature in non-WebAssembly by default.
|
||||||
|
@ -164,23 +164,34 @@ impl Shader {
|
|||||||
match import_path {
|
match import_path {
|
||||||
ShaderImport::AssetPath(asset_path) => {
|
ShaderImport::AssetPath(asset_path) => {
|
||||||
let asset_path = std::path::PathBuf::from(&asset_path);
|
let asset_path = std::path::PathBuf::from(&asset_path);
|
||||||
// Resolve and normalize the path
|
|
||||||
let asset_path = asset_path.canonicalize().unwrap_or(asset_path);
|
// Get the base path and canonicalize it to match the format of the asset path
|
||||||
// Strip the asset root
|
|
||||||
let mut base_path = bevy_asset::io::file::FileAssetReader::get_base_path();
|
let mut base_path = bevy_asset::io::file::FileAssetReader::get_base_path();
|
||||||
// TODO: integrate better with the asset system rather than hard coding this
|
|
||||||
base_path.push("assets");
|
base_path.push("assets");
|
||||||
let asset_path = asset_path
|
let base_path = base_path.canonicalize().unwrap_or(base_path);
|
||||||
.strip_prefix(&base_path)
|
|
||||||
.unwrap_or_else(|_| &asset_path);
|
// Try to make the path relative to the base path
|
||||||
// Wesl paths are provided as absolute relative to the asset root
|
let relative_path = match asset_path.canonicalize() {
|
||||||
let asset_path = std::path::Path::new("/").join(asset_path);
|
Ok(canonical_asset_path) => {
|
||||||
// And with a striped file name
|
match canonical_asset_path.strip_prefix(&base_path) {
|
||||||
let asset_path = asset_path.with_extension("");
|
Ok(rel_path) => rel_path.to_path_buf(),
|
||||||
let asset_path = asset_path.to_str().unwrap_or_else(|| {
|
Err(_) => canonical_asset_path,
|
||||||
panic!("Failed to convert path to string: {:?}", asset_path)
|
}
|
||||||
});
|
}
|
||||||
let import_path = ShaderImport::AssetPath(asset_path.to_string());
|
Err(_) => asset_path,
|
||||||
|
};
|
||||||
|
|
||||||
|
// Create the shader import path - always starting with "/"
|
||||||
|
let shader_path = std::path::Path::new("/").join(&relative_path);
|
||||||
|
|
||||||
|
// Convert to a string with forward slashes and without extension
|
||||||
|
let import_path_str = shader_path
|
||||||
|
.with_extension("")
|
||||||
|
.to_string_lossy()
|
||||||
|
.replace('\\', "/");
|
||||||
|
|
||||||
|
let import_path = ShaderImport::AssetPath(import_path_str.to_string());
|
||||||
|
|
||||||
Shader {
|
Shader {
|
||||||
path,
|
path,
|
||||||
imports,
|
imports,
|
||||||
|
@ -70,16 +70,20 @@ fn setup(
|
|||||||
|
|
||||||
fn update(
|
fn update(
|
||||||
time: Res<Time>,
|
time: Res<Time>,
|
||||||
mut query: Query<&MeshMaterial3d<CustomMaterial>>,
|
mut query: Query<(&MeshMaterial3d<CustomMaterial>, &mut Transform)>,
|
||||||
mut materials: ResMut<Assets<CustomMaterial>>,
|
mut materials: ResMut<Assets<CustomMaterial>>,
|
||||||
keys: Res<ButtonInput<KeyCode>>,
|
keys: Res<ButtonInput<KeyCode>>,
|
||||||
) {
|
) {
|
||||||
for material in query.iter_mut() {
|
for (material, mut transform) in query.iter_mut() {
|
||||||
let material = materials.get_mut(material).unwrap();
|
let material = materials.get_mut(material).unwrap();
|
||||||
material.time = time.elapsed_secs();
|
material.time = time.elapsed_secs();
|
||||||
if keys.just_pressed(KeyCode::Space) {
|
if keys.just_pressed(KeyCode::Space) {
|
||||||
material.party_mode = !material.party_mode;
|
material.party_mode = !material.party_mode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if material.party_mode {
|
||||||
|
transform.rotate(Quat::from_rotation_y(0.005));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user