Live data from Hacker News

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

makingsoftware.com

31–40 of 93 posts

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

#31
post #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 diffi…

I think their explanation is great. The shader is run on all the pixels within the quad and your shader code needs to figure out if the pixel is within the shape you want to draw or not. Compared to just drawing it pixel by pixel if you do it by pen or on the CPU.

For a red line between A and B:

CPU/pen: for each pixel between A and B: draw red

GPU/shader: for all pixels: draw red if it's on the intersection between A and B

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

#32
post #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.

For swiftUI+metal specifically: https://metal.graphics

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

#33
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…

> Vulkan is an open _standard_

That too kinda depends on where you draw the line, the spec text is freely available but all development happens behind closed doors under strict NDA. From an outsiders perspective it doesn't feel very open to get completely stonewalled by Khronos on the status of a feature that debuted in DirectX or CUDA well over a year ago, they won't even confirm whether it's on their roadmap.

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

#34
post #24

Earlier quoted context omitted.

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…

Fair enough! In my humble opinion those specific circumstances outlined are a bit overly-pedantic for the target audience of this article and for general practical purposes. The average Windows user can reasonably expect that they'll be able to write a Vulkan application without much fuss ( until you run into the driver bugs of course ;) ).

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

#35

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

There's also bonzomatic which the demo scene uses for shader live coding competitions:

https://github.com/Gargaj/Bonzomatic

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

#36
post #33
post #24

Earlier quoted context omitted.

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…

> Vulkan is an open _standard_ That too kinda depends on where you draw the line, the spec text is freely available but all development happens behind closed doors under strict NDA. From an outsiders perspective it doesn't feel very open to get completely stonewalled by Khronos on the status of a feature that debuted in DirectX or CUDA well over a year ago, they won't even confirm whether it's on their roadmap.

Sure, that's true and a pretty valid criticism of the system.

My definition of open is that Khronos doesn't restrict (as far as I know) what platforms Vulkan can be implemented on. The same cannot be said for DX12 or Metal.

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

#37

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…

At least Vulkan runs on Windows, that certainly makes it more cross-platform than DirectX. According to Google, some VNCs on Linux don’t support Vulkan, but I don’t think that’s a fair reason to suggest Vulkan doesn’t run on Linux in general, right? You’re right Vulkan isn’t part of the OS. Does that usually matter, if most people get Vulkan support through their driver?

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

#38
Programming in general is about converting something you understand into something a computer understands, and making sure the computer can execute it fast enough.

This is already hard enough as it is, but GPU programming (at least in its current state) is an order of magnitude worse in my experience. Tons of ways to get tripped up, endless trivial/arbitrary things you need to know or do, a seemingly bottomless pit of abstraction that contains countless bugs or performance pitfalls, hardware disparity, software/platform disparity, etc. Oh right, and a near complete lack of tooling for debugging. What little tooling there is only ever works on one GPU backend, or one OS, or one software stack.

I’m no means an expert but I feel our GPU programming “developer experience” standards are woefully out of touch and the community seems happy to keep it that way.

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

#39
post #31
post #28

Earlier quoted context omitted.

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 diffi…

I think their explanation is great. The shader is run on all the pixels within the quad and your shader code needs to figure out if the pixel is within the shape you want to draw or not. Compared to just drawing it pixel by pixel if you do it by pen or on the CPU. For a red line between A and B: CPU/pen: for each pixel between A and B: draw red GPU/shader: for all pixels: draw red if it's on the intersection between…

Figuring out if a pixel is within a shape, or is on the A-B intersection line, is part of the rasterizing step, not the shading. At least in the parent’s analogy. There are quite a few different ways to draw a red line between two points.

Also using CPU and GPU here isn’t correct. There is no difference in the way CPUs and GPUs draw things unless you choose different drawing algorithms.

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

#40

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…

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

Vulkan is not entirely cross-platform, but it's still way "more" cross-platform than DirectX by your own point of view.

DirectX: - Windows - Xbox

Vulkan: - Linux - Android - Windows - Nintendo Switch - Nintendo Switch 2

Metal: - MacOS - iOS

Post reply on HN