3 ms·
This is my understanding of shaders: Drawing a line on the CPU: a function looping through each pixel between point A and B and draw one pixel at a time sequen
by Kiro 3y ago
This is my understanding of shaders:
Drawing a line on the CPU: a function looping through each pixel between point A and B and draw one pixel at a time sequentially. Runs once with exactly as many steps as there are pixels in the line.
Drawing a line on the GPU: a function checking if the pixel is on the line or not and draw if it's a match. Runs on all pixels on the screen at the same time, even ones that are far from the line.
Is this correct?
- NZGumboot 3y agoNot exactly. First, a GPU can't run a pixel shader against EVERY pixel simultaneously. A typical screen might have about two million pixels, while GPUs max out at a few thousand concurrent 'threads of execution' i.e. it effectively draws in chunks of a few thousand pixels at a time. Second, the GPU doesn't need to run pixel shaders against a whole screen, it's capable of running shaders against any arbitrary shape you like using triangles. So the efficient way to draw a line is to send the GPU two triangles that match the line geometry that you want, and then only run the pixel shader on the pixels that the triangles overlap. Much more efficient.