我在 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'shader'解析错误:预期操作('='),发现'+'
┌─wgsl:95:88
95 │ for (out.steps=0;out.深度 < max_shading_distance && out.steps < max_steps; out.steps++) {
expected operation ('='), found '+'
我在这里做错了什么?
最新发布的版本没有递增和递减运算符或
+=
(以及其他类似运算符)。然而,naga master 分支已合并提交,因此在未来的版本中这些运算符将起作用。
现在使用i=i+1