wgs​​l for 循环语法

wgsl for loop syntax

我在 https://www.w3.org/TR/WGSL/#for-statement

上找到了以下示例
for(var i: i32 = 0; i < 4; i++) {
  if a == 0 {
    continue;
  }
  a = a + 2;
}

但我的代码不起作用

// 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;
}

错误:

着色器'shader' 解析错误:预期操作('='),找到'+'

┌─ wgsl:95:88

95 │ for (out.steps=0; out.depth < max_shading_distance && out.steps < max_steps; out.steps++) {

expected operation ('='), found '+'

我做错了什么?

最新发布的版本没有递增和递减运算符或 +=(以及其他类似运算符)。然而,naga master 分支合并了提交,因此在未来的版本中这些操作符将起作用。 现在使用 i=i+1