Live data from Hacker News

Shaders: How to draw high fidelity graphics with just x and y coordinates

makingsoftware.com

21–30 of 93 posts

Re: Shaders: How to draw high fidelity graphics with just x and y coordinates

#21

For anyone looking for some IDEs to tinker around with shaders: * shadertoy - in-browser, the most popular and easiest to get started with * Shadron - my personal preference due to ease of use and high capability, but a bit niche * SHADERed - the UX can take a bit of getting used to, but it gets the job done * KodeLife - heard of it, never tried it

Also on macOS (and iPadOS) it's super easy to get started with Metal shaders in Playgrounds.

Re: Shaders: How to draw high fidelity graphics with just x and y coordinates

#22

Earlier quoted context omitted.

Is 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.

The pixel position has to be known, how else are you rasterizing something?

The 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.

Re: Shaders: How to draw high fidelity graphics with just x and y coordinates

#23

For anyone looking for some IDEs to tinker around with shaders: * shadertoy - in-browser, the most popular and easiest to get started with * Shadron - my personal preference due to ease of use and high capability, but a bit niche * SHADERed - the UX can take a bit of getting used to, but it gets the job done * KodeLife - heard of it, never tried it

Had a look in Mint's software manager and found this (flatpak/aur/macports/windows): https://github.com/fralonra/wgshadertoy

Re: Shaders: How to draw high fidelity graphics with just x and y coordinates

#24

Nice article, though the diagram showing [OpenGL] [WebGL] [WebGPU] being built on Vulkan and then from Vulkan to D3D12 and Metal is wrong. WebGL and WebGPU go directly to D3D and Metal, they do not go through Vulkan first Also, Vulkan is labeled as Open Source. It is not open source. The are other mistakes in that area as well. It claims WebGPU is limited to Browsers. It is, not. WebGPU is available as both a C++ (Da…

To elaborate on this, Vulkan is an open _standard_ whose many implementations (user mode driver) may or may not be open source. Vulkan is just a header file, it's up to the various independent hardware vendors (IHVs) to implement it for their platform.

Also a small correction: Vulkan actually _does_ run Apple platforms (via Vulkan-to-Metal translation) using MoltenVK and the new KosmicKrisp driver, and it works quite well.

Re: Shaders: How to draw high fidelity graphics with just x and y coordinates

#25

Earlier quoted context omitted.

Is 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.

The pixel position has to be known, how else are you rasterizing something?

Rasterizing 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.

Re: Shaders: How to draw high fidelity graphics with just x and y coordinates

#26

For anyone looking for some IDEs to tinker around with shaders: * shadertoy - in-browser, the most popular and easiest to get started with * Shadron - my personal preference due to ease of use and high capability, but a bit niche * SHADERed - the UX can take a bit of getting used to, but it gets the job done * KodeLife - heard of it, never tried it

Cables[0] is pretty cool too. Kirell Benzi has released some impressive work using it [1].

[0]: https://cables.gl/

[1]: https://youtu.be/CltYdTVH7_A

Re: Shaders: How to draw high fidelity graphics with just x and y coordinates

#27

Earlier quoted context omitted.

Is 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.

The pixel position has to be known, how else are you rasterizing something?

Technically, the (pixel) fragment shader stage happens after the rasterization stage.

Re: Shaders: How to draw high fidelity graphics with just x and y coordinates

#28
post #16

That, I think, is the most unintuitive part about writing fragment shaders. The idea that you take a couple of coordinates and output a color. Compared to traditional drawing, as with a pen and paper, you have to think in reverse. For example if you want to draw a square with a pen, you put your pen where the square is, draw the outlines, than fill it up, with a shader, for each pixel, you look at where you are, calc…

I think what you’re describing is the difference between raster and vector graphics, and doesn’t reflect on shaders directly.

It always depends on your goals, of course. The goal of drawing with a pen is to draw outlines, but the goal behind rasterizing or ray tracing, and shading, is not to draw outlines, but often to render 3d scenes with physically based materials. Achieving that goal with a pen is extremely difficult and tedious and time consuming, which is why the way we render scenes doesn’t do that, it is closer to simulating bundles of light particles and approximating their statistical behavior.

Of course, painting is slighty closer to shading than pen drawing is.

Re: Shaders: How to draw high fidelity graphics with just x and y coordinates

#29

Nice article, though the diagram showing [OpenGL] [WebGL] [WebGPU] being built on Vulkan and then from Vulkan to D3D12 and Metal is wrong. WebGL and WebGPU go directly to D3D and Metal, they do not go through Vulkan first Also, Vulkan is labeled as Open Source. It is not open source. The are other mistakes in that area as well. It claims WebGPU is limited to Browsers. It is, not. WebGPU is available as both a C++ (Da…

The Vulkan specification is Open Source. Many Vulkan implementations are not.

Vulkan also isn't built on D3D at all, and only MoltenVK (an open-source implementation for Apple platforms) is built on Metal. (Edit: It appears Mesa also now has KosmicKrisp as a Vulkan translation layer for extremely recent (≤5 years) Mac devices.)

> WebGPU is available as both a C++ (Dawn) and a Rust (WGPU) library.

WebGPU is implemented by both a C++ library (Dawn) and Rust crate (wgpu-rs), but like Vulkan, is itself only a specification. Also I'd still hesitate to even call wgpu-rs an implementation of WebGPU, because it's only based on the WebGPU specification, not actually an exact conforming implementation like Dawn is.

> Vulkan is also not really cross-platform any more than DirectX .

Sure it is: DirectX makes assumptions that it's running on Windows, and uses Windows data structures in its APIs. Vulkan makes no such assumptions, and uses no platform-specific data structures, making it automatically more cross-platform.

Sure, users of DirectX can be cross-platform with the use of translation layers such as Wine or Proton, but the API itself can't be ported natively to other platforms without bringing the Windows baggage with it, while Vulkan can.

Additionally, Vulkan provides a lot more metadata that can be used to adapt to differing situations at runtime, for example the ability to query the graphics devices on the system and select which one to use. DirectX did not have this capability at first, but added it two years after Vulkan did.

Re: Shaders: How to draw high fidelity graphics with just x and y coordinates

#30
post #24

Nice article, though the diagram showing [OpenGL] [WebGL] [WebGPU] being built on Vulkan and then from Vulkan to D3D12 and Metal is wrong. WebGL and WebGPU go directly to D3D and Metal, they do not go through Vulkan first Also, Vulkan is labeled as Open Source. It is not open source. The are other mistakes in that area as well. It claims WebGPU is limited to Browsers. It is, not. WebGPU is available as both a C++ (Da…

To elaborate on this, Vulkan is an open _standard_ whose many implementations (user mode driver) may or may not be open source. Vulkan is just a header file, it's up to the various independent hardware vendors (IHVs) to implement it for their platform. Also a small correction: Vulkan actually _does_ run Apple platforms (via Vulkan-to-Metal translation) using MoltenVK and the new KosmicKrisp driver, and it works quite…

> Also a small correction: Vulkan actually _does_ run Apple platforms (via Vulkan-to-Metal translation) using MoltenVK and the new KosmicKrisp driver, and it works quite well.

I think, since they mentioned some enterprise deployments on Windows won't have Vulkan drivers preinstalled, that drivers merely being available is not enough for GP to count them as Vulkan "running". I think GP is only counting platforms (and circumstances) where you can reasonably expect Vulkan support to already be present.

Post reply on HN