6 ms·
>Shaders technically don't even know their X and Y coordinates by default unless you specifically provide those im kind of a boomer regarding shaders but isnt
by webdevver 10mo ago
>Shaders technically don't even know their X and Y coordinates by default unless you specifically provide those
im kind of a boomer regarding shaders but isnt gl_FragCoord always available?
- LoganDark 10mo agoIs the article about OpenGL? I see a few mentions of OpenGL in a section about graphics APIs that also mentions at least Vulkan, which doesn't automatically provide fragment coordinates, and WebGPU, which also doesn't. Shaders by default have no concept of fragment coordinates; it's OpenGL the API that introduces them by default.
- mandarax8 10mo agoThe pixel position has to be known, how else are you rasterizing something?
- LoganDark 10mo agoThe view transform doesn't necessarily have to be known to the fragment shader, though. That's usually in the realm of the geometry shader, but even the geometry shader doesn't have to know how things correspond to screen coordinates, for example if your API of choice represents coordinates as floats from [0.5, 0.5) and all you feed it is vertex positions. (I experienced that with wgpu-rs) You can rasterize things perfectly fine with just vertex positions; in fact you can even hardcode vertex positions into the geometry shader and not have to input any coordinates at all.
- dahart 10mo agoRasterizing and shading are two separate stages. You don’t need to know pixel position when shading. You can wire up the pixel coordinates, if you want, and they are often nearby, but it’s not necessary. This gets even more clear when you do deferred shading - storing what you need in a G-buffer, and running the shaders later, long after all rasterization is complete.
- corysama 10mo agoTechnically, the (pixel) fragment shader stage happens after the rasterization stage.
- pjmlp 10mo agoNo, that is OpenGL specific and only if using GLSL, other shading languages expect such values as explicit parameters, for example in WGSL it is @builtin(position) that you are to bind to a specific variable. @builtin(position) fragCoord: vec4f