首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >用于循环语法的wgsl

用于循环语法的wgsl
EN

Stack Overflow用户
提问于 2022-03-27 07:31:06
回答 1查看 441关注 0票数 0

我在https://www.w3.org/TR/WGSL/#for-statement上找到了下面的例子

代码语言:javascript
复制
for(var i: i32 = 0; i < 4; i++) {
  if a == 0 {
    continue;
  }
  a = a + 2;
}

但我的代码不起作用

代码语言:javascript
复制
// 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;
}

错误:

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

┌─wgsl:95:88

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

代码语言:javascript
复制
expected operation ('='), found '+'

我在这里做错什么了?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-03-30 05:56:34

最新发布的版本没有增量和递减运算符或+= (和其他类似的运算符)。但是,naga主分支合并了提交,因此在将来发布时,这些操作员将工作。现在使用i=i+1

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71634442

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档