Live data from Hacker News

Scratchapixel: Computer Graphics Programming from Scratch

scratchapixel.com

61–70 of 73 posts

Re: Scratchapixel: Computer Graphics Programming from Scratch

#61
These are the other graphics related tutorials I have found.

Ray Tracing in a Weekend Series. Most the way through the first book and I plan on continuing it. [1][2][3]

Tiny Renderer - How OpenGL Works. A software renderer in 500 lines of code. Wiki has a full tutorial. [4]

The Book of Shaders. A step by step introduction into fragment shaders. [5]

[1] https://www.amazon.com/_/dp/B01B5AODD8

[2] https://www.amazon.com/_/dp/B01CO7PQ8C

[3] https://www.amazon.com/_/dp/B01DN58P8C

[4] https://github.com/ssloy/tinyrenderer/wiki

[5] https://thebookofshaders.com/

Re: Scratchapixel: Computer Graphics Programming from Scratch

#62

Earlier quoted context omitted.

http://portal.aauj.edu/portal_resources/downloads/programmin...

Seems to be the same author, but an earlier book?

This is a PDF of the 1st edition of another book by the same author. There is a 2nd edition, which is an excellent but outdated text covering 2D game programming.

Re: Scratchapixel: Computer Graphics Programming from Scratch

#63
post #59

Earlier quoted context omitted.

Fixed point is a good approach for line drawing but doing a sqrt for circles with integer arithmetics does not work really that well even if you don't know how to convert floats to ints fast (like author of the article you linked :)).

This one shows the branchy and branchless variations of bresenham being nearly equal in speed, within 5% on the older 32 bit CPU, with the branchy old school way being 1% faster on a more recent 64 bit CPU. Both are significantly faster than the naive floating point version. That is in line with my experience that floating point can still be quite slow on the CPU; the advantage from using fixed point isn't necessaril…

Did you forget to add a link to your post or something? I repeat this for the final time: floating point can be quite slow but flow control is much slower. Also, fixed point square root is very slow compared to the FP one.

If you have a "brancheless bresenham" then go for it, I've never heard of such a thing so I'd be curious to see that link. But from the description it sounds like a contradiction to the Bresenham's idea.

Re: Scratchapixel: Computer Graphics Programming from Scratch

#64
post #59

Earlier quoted context omitted.

This one shows the branchy and branchless variations of bresenham being nearly equal in speed, within 5% on the older 32 bit CPU, with the branchy old school way being 1% faster on a more recent 64 bit CPU. Both are significantly faster than the naive floating point version. That is in line with my experience that floating point can still be quite slow on the CPU; the advantage from using fixed point isn't necessaril…

Did you forget to add a link to your post or something? I repeat this for the final time: floating point can be quite slow but flow control is much slower. Also, fixed point square root is very slow compared to the FP one. If you have a "brancheless bresenham" then go for it, I've never heard of such a thing so I'd be curious to see that link. But from the description it sounds like a contradiction to the Bresenham's…

See userbinator's link for a little performance comparison of the naive floating point code vs. bresenham vs. fixed point.

Re: Scratchapixel: Computer Graphics Programming from Scratch

#65
post #64

Earlier quoted context omitted.

Did you forget to add a link to your post or something? I repeat this for the final time: floating point can be quite slow but flow control is much slower. Also, fixed point square root is very slow compared to the FP one. If you have a "brancheless bresenham" then go for it, I've never heard of such a thing so I'd be curious to see that link. But from the description it sounds like a contradiction to the Bresenham's…

See userbinator's link for a little performance comparison of the naive floating point code vs. bresenham vs. fixed point.

There are many problems with that link. First of all - there is no "branchless bresenham" in it. Second - the author, while noticing that float to int conversion in his compiler is slow, decided not to do anything about it instead of doing a simple google search to find how to do it fast enough. Third - he is using 8087 FP instructions, which had been deprecated since late 90s. Fourth - he is essentially measuring function call (look what's happening in his inner loop). And fifth - he is not measuring other Bresenham's algorithms. I'd love to see how he does ellipses with fixed point.

Re: Scratchapixel: Computer Graphics Programming from Scratch

#66
post #13

Maybe I missed it, but I didn't see any discussion of the Bresenham family of algorithms. I realize this is always done for you nowadays, but if you're really teaching pixels from scratch, it seems like drawing lines and circles from raw pixels needs to be covered.

Sadly if you're actually implementing Bresenham's algorithm today you're doing something very wrong (or don't care about performance). Drawing lines and shapes is all a matter of pumping the desired geometry and shaders into your GPU today and letting it take care of the rasterization--running Bresenham's algorithm on your CPU will be many orders of magnitude slower.

No argument. That's why I said I realized this was always done for you today. But somebody had to build and program that GPU, and for those of us who care about such details, it would be nice to learn how rasterization works in a GPU. I had assumed that GPUs were still using Bresenham-like DDAs, but I learned from the above discussion that fixed-point non-branching algorithms may have become more common.

Re: Scratchapixel: Computer Graphics Programming from Scratch

#67

Earlier quoted context omitted.

Ignoring matrix transformations is easy, as long as the eye point is at the origin. Then yes, the algebra is almost trivial: projection is just divide-by-z. But the moment you move the camera, or stretch and turn objects, or worry about clipping, you need the full machinery that matrices provide. They're not that mysterious. I wish they were taught in high school, because they would motivate kids to learn graphics an…

> I wish they were taught in high school, because they would motivate kids to learn graphics and programming. Learned Linear Algebra (matrix calculations and some analytical geometry) + Calculus in eleventh grade, around 1995. I think it was the standard curriculum in all Eastern Europe and the countries from the ex Soviet Union.

I learned some degree of linear algebra sometime during high school (in optional math classes that a lot of my schoolmates never reached), but mostly as a set of rote-learned operations without a connection to anything useful. As a consequence, I ended up re-learning a lot of it in university, and then catching up on it again on my own while learning about 3D graphics. (American, in high school during early 00's)

Re: Scratchapixel: Computer Graphics Programming from Scratch

#68

Earlier quoted context omitted.

We learned basic vector arithmetic back in highschool doing our own gamedev stuff, and it's pretty straightforward. The use of matrices as "mapping" one space to another likewise so. Any approach that ignores the relevant parts of linear algebra, though, is probably going to collapse under its own weight as things get more complicated--experiencing that collapse may be interesting from a learning perspective, but I s…

This. You went to the right high school. Matrices and vectors are just a subset of linear algebra, and can definitely be taught to teenagers. When I teach graphics to 3rd-year college undergraduates, I tell them "this is what all that point-and-vector stuff you learnt in high school was really meant for". They've usually forgotten it all, but it comes back to them quickly, and the matrix stuff on top of that isn't ve…

What would be the "gain" of leaving out linear algebra and other mathematical concepts? Agreed, computers can do graphics using basic arithmetic, so can we humans. We get the stuff done without advanced concepts. I still disagree with the "[linear algebra and stuff being] useless for graphics" part. You may not require that knowledge to implement graphics-related stuff, but if you are seeking to develop methods in that field or reason about them in a way other people will understand, you naturally end up using the language of linear algebra. You could do without it, but it would be hard for others to follow you. It might be some other kind of language, but I'd say LA is pretty darn succinct.

Re: Scratchapixel: Computer Graphics Programming from Scratch

#69

Earlier quoted context omitted.

> I wish they were taught in high school, because they would motivate kids to learn graphics and programming. Learned Linear Algebra (matrix calculations and some analytical geometry) + Calculus in eleventh grade, around 1995. I think it was the standard curriculum in all Eastern Europe and the countries from the ex Soviet Union.

I learned some degree of linear algebra sometime during high school (in optional math classes that a lot of my schoolmates never reached), but mostly as a set of rote-learned operations without a connection to anything useful. As a consequence, I ended up re-learning a lot of it in university, and then catching up on it again on my own while learning about 3D graphics. (American, in high school during early 00's)

The math courses from my first university year where 90% a redo of the math from my last two years of high school. The difference was that in university they emphasized the theory over exercises, basically forced us to learn 1 - 2 hours demonstrations of some theorem.

Re: Scratchapixel: Computer Graphics Programming from Scratch

#70
post #18

Earlier quoted context omitted.

What you are wanting is this book: "Tricks of the 3D Game Programming Gurus" by Andre LaMothe. The book teaches you how to write a 3D software rasterizer from first principles. The first part of the book is nothing but a well written linear algebra primer. The book then assumes you have nothing but a C++ compiler and a pointer to the frame buffer like you might get using SDL. Unfortunately the book appears to be out…

Thanks for the recommendation, I'll see if I can find a copy somewhere. But I think the 12-yo-me wouldn't have bought a book and certainly wouldn't have appreciated one that starts with a linear algebra primer (no matter how well written). Really, what I would've needed back then would've been a relatively short tutorial somewhere online, preferrably one that doesn't require me to start with linear algebra. Just the…

I just had the Asphyxia Demotutorials (look them up on one of those oldskool textfiles websites, maybe it's exactly what you are referring to? except of course the bits were they also learn you Turbo Pascal and ASM :p) But the arithmetic, goniometry (trigonometry?) and geometry were the hard parts, which I learned in school, but were still tricky (because I liked learning, not memorizing formulas).

Linear algebra was the new and easy part. You don't need matrix inversions, eigenvectors or triangular decompositions or any of the complex Linear Algebra stuff. It's just vector math. And you probably already know arrays. It's merely a notational convenience when you recognize that you're doing the exact same operations on three x,y,z-variables all the time.

When I saw it first as a teenager I was like "hey that's clever, lots less to write!" (when working out formulas on pen and paper, not having to write everything thrice, yay!).

Post reply on HN