r/GraphicsProgramming • • Oct 04 '20

Efficient methods to rasterize a scene of connected triangles

Assuming I wanted to rasterize a scene of triangles that are all connected that is similar to the image below, what would be an efficient way to do it on a GPU and a CPU? The triangles can be of any size. Names of any methods utilized or any advice is appreciated!

Thanks!

0 Upvotes

8 comments sorted by

3

u/ShillingAintEZ Oct 04 '20

What have you tried so far? Anything will work, including early 90s opengl.

1

u/rh12503 Oct 04 '20

I'm completely new to this topic. My initial idea was to iterate through each pixel and each triangle and see if they intersect, but I was sure there had to be a faster way. Looking up "triangle rasterization" just brought up tutorials on how to render individual triangles.

2

u/ShillingAintEZ Oct 04 '20

Is this homework? You will have to render individual triangles. Th easiest way would be to follow a beginner opengl tutorial.

1

u/leseiden Oct 04 '20

That will work but it scales really badly.

A simple approach for software is to find the top and bottom scanline of a triangle and follow the edges from top to bottom. This gives you a list of begin and and positions that you can fill in.

The details are tricky and there are lots of refinements but that's the basic idea.

Some gpus use a block/tile subdivision as it works well in parallel.

This is lower level than what most people work with because gpus and graphics apis hide the gory details.

If you really want to learn this stuff then old school textbooks like "computer graphics; principles and practice" are a good bet, but bear in mind that it will rarely be useful.

If you just want to draw things then learn opengl/dx/vulkan and treat rasterisation as a thing that happens.

5

u/Botondar Oct 04 '20

I don't really understand the question. Triangle rasterization is something that GPUs have been continuously optimizing ever since they first came into existence. Unless you're trying to render billions of triangles no GPU will have a problem with this. You don't even need to know the exact method since the rasterization happens in a fixed function stage that you don't have much control over.

So basically using any graphics API with a simple vertex and pixel shader should suffice.

5

u/NegativeEntr0py Oct 04 '20

GPUs are literally designed to do what you’re asking. And with only a handful of triangles any way you do it (OpenGL, DirectX, Vulkan) will be extremely efficient. Just simple graphics programming stuff, although I can admit getting the application running has a lot of boilerplate code.

3

u/HighRelevancy Oct 04 '20

What's the context of this question? Why are you asking it? What are you trying to achieve?