0
点赞
收藏
分享

微信扫一扫

webgpu初体验新版shader语言WGSL


​​threejs交流群511163089​​

目前webGPU好像还没正式登场,但是迫不及待的体验了一下现在的测试版本

vertex: `
const pos : array<vec2<f32>, 3> = array<vec2<f32>, 3>(
vec2<f32>(0.0, 0.5),
vec2<f32>(-0.5, -0.5),
vec2<f32>(0.5, -0.5));

[[builtin(position)]] var<out> Position : vec4<f32>;
[[builtin(vertex_index)]] var<in> VertexIndex : i32;

[[stage(vertex)]]
fn main() -> void {
Position = vec4<f32>(pos[VertexIndex], 0.0, 1.0);
return;
}
`,
fragment: `
[[location(0)]] var<out> outColor : vec4<f32>;

[[stage(fragment)]]
fn main() -> void {
outColor = vec4<f32>(1.0, 0.0, 0.0, 1.0);
return;
}
`,

变量都是显式指定类型了,看看vertex部分里,第一个const变量pos指定为array类型 array包含3个元素 每个都是vec2,vec2的xy都是float32。

然后内置变量前面写个builtin字段标识一下var<out> Position:vec4<f32> 对应webgl1.0的gl_position。

location字段和webgl里的location看起来是一样的用法

main函数里头就把待输出的变量填充好就可以了

你学废了吗?。?

举报

相关推荐

0 条评论