Questions tagged [wgsl]

WGSL is the shading language specifically designed for WebGPU. Use this tag for questions about shaders syntax, bugs, usage in WebGPU and implementation details in comparison to other shader languages such as GLSL and HLSL.

37 questions
1
vote
1 answer

shadertoy's GLSL and Rust Bevy WGSL incoherence

I'm trying to get into Shaders and decided to init a project using Rust and Bevy, the objective is to reproduce a raymarching shader just to confirm that the environment is ok, i was able to reproduce the "fragCoord" by using: var fragCoord:…
Joel Lima
  • 21
  • 5
0
votes
0 answers

How to convert global_invocation_id to clip space coordinates? (To convert depth buffer to world space position)

I am writing a compute shader that runs some function for every pixel in a framebuffer. To simplify this question, I'm using a workgroup size of 1. @compute @workgroup_size(1, 1) fn main(@builtin(global_invocation_id) gid: vec3u) { ...…
Lukas Kalbertodt
  • 79,749
  • 26
  • 255
  • 305
0
votes
1 answer

WGSL: Multiplying a vec4f by a mat4f identity matrix produces different results

I am trying out WebGPU for the first time and have come across a problem. Normally in other rendering frameworks I would multiply a vec4 my a matrix of all 1s and the output would be the same. Here is what I expect with this code: @vertex fn…
Jove
  • 105
  • 4
0
votes
1 answer

Cannot load WebGPU code: WGSL reader error

I'm following this WebGPU tutorial, and I copied the below shader code (shader.wgsl, full file is here): // vertex shader struct Output { @builtin(position) Position : vec4; // <-- error in this line @location(0) vColor :…
Hoff
  • 38,776
  • 17
  • 74
  • 99
0
votes
0 answers

When working with compute shader in WGSL, how to loop till the length of the binded buffer?

On a compute shader, I want to use runtime buffer array length for the loop. However shading languages don't allow conditions that can be resolved only in runtime. //runtime sized buffer @group(0) @binding(0) var v_indices:…
0
votes
1 answer

WGSL throws parsing error on seemingly correct code

I have a storage texture which I (try to) write to in a compute shader. Then in the fragment shader I am trying to read from that storage texture using textureLoad, but I am getting this error and I have no clue what I'm doing wrong: Caused by: …
LordRobin
  • 76
  • 5
0
votes
0 answers

Web GPU Call Stack Limit - Have to Expand function manually

Using the newest chrome 113 and the web gpu function, after updating drivers, testing on different computers, I have determined that this is the error, and I cannot understand why wgsl would fail here. Speculation: there's some call stack limit im…
Ben Hagel
  • 441
  • 4
  • 9
  • 22
0
votes
1 answer

Draw a rectangle using WebGPU

I'm new to WebGPU and the 3D rendering world. What I am trying to do is to draw a rectangle in Typescript and wgsl. I understand that a mesh is a set of vertices. A mesh of 3 vertices draws a triangle. Doesn't a mesh of 4 vertices draws a…
0
votes
1 answer

WebGPU. How to draw the Triangle Strip with different color for each Triangle?

The first triangle must be RED, the second triangle must be GREEN. But both are GREEN ((( How to set different colors for each sub-triangle in 'triangle-strip' primitive topology ? My final goal is: Creating new triangles with new colors at mouse…
Teamur
  • 67
  • 1
  • 4
0
votes
1 answer

How to write to a uniform buffer using mapAsync with WebGPU

I have a uniform buffer that is created like this: const temp = new Float32Array([0, 0, 0, 0, 0, 0, 0, 0]); const positionBuffer = device.createBuffer({ size: temp.byteLength, usage: GPUBufferUsage.UNIFORM | GPUBufferUsage.COPY_SRC, …
luek baja
  • 1,475
  • 8
  • 20
0
votes
1 answer

WebGPU: Vertex range requires a larger buffer than the bound buffer size

I am simply trying to send an array of vertex positions to the vertex shader. Here is a snippet of my JS code: const vertices = new Float32Array([0, 0.5, 0, 1, -0.5, -0.5, 0, 2, 0.5, -0.5, 0, 1]); const vertexBuffer = device.createBuffer({ //…
luek baja
  • 1,475
  • 8
  • 20
0
votes
1 answer

WGSL: Fixing an error in my mental model of how @builtin(position) works

I am a hobbyist programmer trying to learn graphics programming using WebGPU and JavaScript. I have a question about how @builtin(position) works, as it doesn't do-so how I would expect. My current mental model of the rendering pipeline is the naive…
user2628206
  • 241
  • 2
  • 11
0
votes
1 answer

WGpu z-coordinate ignored

I am using wgpu crate in rust to render triangles in layers. The problem is that the z coordinate of the vertices seems to be ignored. The shader returns the z coordinate in the output position, and there is no further transformation applied to it.…
Redirectk
  • 160
  • 9
0
votes
0 answers

How to implement per voxel lighting on GPU

I tried to do it like this: Raytrace the scene into 2 textures, one for the position of the hit rounded to a specific resolution and a normal for each pixel do lighting calculation and put information into the voxelbuffer for each pixel in the…
BrunoWallner
  • 417
  • 3
  • 10
0
votes
0 answers

Memory synchronization issues on shader that needs to read and write to a storage-buffer

I am working on a Voxel raytracer and I want to implement per-voxel lighting. I tried to do it like this: Raytrace the scene into 2 textures, one for the position of the hit rounded to a specific resolution and a normal voxelize all the positions…
BrunoWallner
  • 417
  • 3
  • 10