i found the following example on https://www.w3.org/TR/WGSL/#for-statement
for(var i: i32 = 0; i < 4; i++) {
if a == 0 {
continue;
}
a = a + 2;
}
but my code doesn't work
// shader.wgsl
struct MarchOutput {
steps: i32;
depth: f32;
minimum_distance: f32;
hit: bool;
};
fn march(
point: vec3<f32>, direction: vec3<f32>,
max_steps: i32, max_shading_distance: f32, min_hit_distance: f32
) -> MarchOutput {
var out = MarchOutput ( 0, 0.0, max_shading_distance, false );
for (out.steps=0; out.depth < max_shading_distance && out.steps < max_steps; out.steps++) {
var current_position: vec3<f32> = point + direction * depth;
var current_distance: f32 = SDF(current_position);
if (abs(current_distance) < min_hit_distance) {
out.hit = true;
break;
}
out.minimum_distance = min(out.minimum_distance, current_distance);
out.depth += current_distance;
}
return out;
}
error:
Shader 'shader' parsing error: expected operation ('='), found '+'
┌─ wgsl:95:88
95 │ for (out.steps=0; out.depth < max_shading_distance && out.steps < max_steps; out.steps++) {
expected operation ('='), found '+'
what am i doing wrong here ?
the latest released version does not has the increment and decrement operators or the
+=
(and other similar operators). However, the naga master branch has the commits merged so in future releases these operators will work. For now usei=i+1