23 ms·
Computer Graphics from Scratch (2017)
- ggambetta 8y agoAuthor here. What a surprise to open HN and see this on the front page :) Happy to answer any questions.
- andrewshadura 8y agoThank you very much for this. I'm glad there still are people writing books like this one. When I was a teenager, I found a book by L. Ammeraal which was awesome reading. It taught how to build a simple 3D graphics renderer with hidden edges removal and other interesting features. Unfortunately, back then I was a Pascal fan, so it took me some significant effort to translate bits of the code from the book from C Later, I found another book, can't remember the author, which described even more things, like z-buffering and so on. Very interesting and very useful.
- ggambetta 8y agoMaybe it was "Computer Graphics: Principles and Practice", most commonly known as "the Foley Van-Dam"?
- Bekwnn 8y agohttp://www.opengl-tutorial.org/ http://www.opengl-tutorial.org/ is a pretty fantastic resource of learning this stuff. Don't worry too much about opengl vs direct x vs vulkan. There are underlying principles that apply broadly to both. Alternatively if you want a book that goes more in depth, but still allows you to take your first steps, opengl programming guide 8th+ edition is good. Expect it to require some patience no matter what route you take. Graphics programming is finnicky.
- KZeillmann 8y agoThanks for writing this! I've been interested in computer graphics for a while and too many tutorial dive straight into the details without explaining key concepts. I'm eager to get started reading.
- blondin 8y agothank you so much for writing this. this is one of my favorites on computer graphics. i love the simple and to the point approach. similar are the github.com/ssloy repos. so, are you going to release a print version? (i am one of the few who still love them) do you plan on adding more chapters after rasterization?
- ggambetta 8y agoThanks for your kind words :) No definite plan for a print version, but it could be fun, if nothing else to have a copy on my own shelf! There's a few sections I need to complete first, though. I do have plans to add a few more chapters covering more advanced topics, but again, nothing definite.
- furcyd 8y agoI am preparing to teach a computer graphics course for the first time and have been reading up on WebGL, etc. It looks like this will be a nice intro to the lower level aspects of graphics. Thank you! By the way, Eck's book at: http://math.hws.edu/graphicsbook/ http://math.hws.edu/graphicsbook/ is REALLY helpful for learning WebGL.
- Buttons840 8y agoThanks for mentioning it. Do you think that book is a good source to learn "traditional" OpenGL?
- Jasper_ 8y agoTraditional OpenGL is not useful except as a history lesson. It will give you bad practices when you then try and use a newer API (not even counting DX12/Vulkan; the bad practices will stick with you even if you try to just use DX11/modern OpenGL). WebGL is a pared down version of GLES, which is still not perfect, but a big step in the right direction. I wish there was a better cross-platform intermediate graphics API; Vulkan has a lot of challenges. Metal is very close but it's Apple-specific. Dawn/WebGPU/wgpu seems to be a nice fit in the middle, but it's still in development.
- fermentation 8y agoSo would that book be a good way to get into graphics programming? I see that it uses OpenGL 1.1
- heleninboodler 8y agoJust a heads up, it looks like your script that renders the math bits is failing to load intermittently, making the equations very difficult to read sometimes. But: this looks really cool. I'm sending it to my brother who is a newbie programmer and wants to know about graphics.
- heleninboodler 8y agoNot sure if this is related to errors loading resources, but all the "Source code and live demo" links go to pages that seem to render the demo in javascript but don't show any code. Maybe the reader is intended to view source to see it?
- ggambetta 8y agoThanks for letting me know, I'll take a look. IIRC the script is hosted externally, maybe I should host a copy. You're correct about the source code. Perhaps I should make it easier to see or download.
- fuball63 8y agoI've been following your Fast Paced Multiplayer articles[1] as I write my first networked game; it is really helpful, thanks! [1] http://www.gabrielgambetta.com/client-server-game-architecture.html http://www.gabrielgambetta.com/client-server-game-architectu...
- ggambetta 8y agoThanks for your kind words, I'm glad you found it helpful :)
- Animats 8y agoYou're at Improbable. Tell us more about how you deal with scaling and dynamic region boundaries. How do you keep message traffic from bottlenecking the system? Can you really get a thousand avatars in a big room and not have the system choke? What would it take to port Second Life / Open Simulator to Spatial OS? There are a ton of computer graphics intro books. Not so much on big-world architecture.
- ggambetta 8y agoMaybe I'll write a book about Improbable some day - but more likely about the mythical origin story :) That said, at two different times I managed teams that made demos, tutorials and documentation, most recently https://twitter.com/gabrielgambetta/status/921358763117961216 https://twitter.com/gabrielgambetta/status/92135876311796121..., but there's people much more qualified than I am to write technical stuff about SpatialOS nowadays. Region boundaries are a fascinating topic, see this for example: https://improbable.io/games/blog/distributed-physics-without-server-boundaries https://improbable.io/games/blog/distributed-physics-without... But as Woody Harrelson would say, "let's keep it about Computer Graphics, people..." ;)
- justin66 8y agoI'd like to see the book Animats mentioned as well. Perhaps you should encourage one of your colleagues to write it.
- nofunsir 8y agoSmall typo in 9th paragraph of the Introduction. Look forward to reading it
- ggambetta 8y agoHmmm, can't find it. Mind telling me what it is?
- alanpetrel 8y ago"While their sets of features have considerable overlap, they aren’t identical, so this book covers their specific strenghts" - it should be "strengths".
- ggambetta 8y agoUgh, thanks. Will fix.
- jamiek88 8y agoNot the guy who mentioned it but: >.....so this book covers their specific strenghts: Reversed h and t in strengths.
- User23 8y agoNo questions, but I'd like to thank you for a well written article that takes me back to when I was writing bzone style wireframe games as a kid.
- ggambetta 8y agoGlad to hear you've found it interesting :)
- pseudosudoer 8y agoLike many other programmers, I originally picked up programming because I wanted to write games. I spent time on my own in high school messing around with rudimentary 2D libraries in C++. That feeling of awe and accomplishment that was captured the first time an image successfully moves across the screen was what got me hooked. After starting college I soon learned of the trials and tribulations of software engineers in the gaming industry. I changed my degree to Computer Engineering, took the embedded track, and recaptured that sense of awe by staring into the abyss of an Oscilloscope. Albeit, I did still take several graphics courses as electives (simply because I loved the subject).
- BurningCycles 8y agoFor me it was my big brother passing his Commodore 64 down to me as he got himself an Amiga. First it was just playing games, then doing some stuff in the built-in basic, and then following an assembly language course in a monthly magazine. By the time I managed to display eight sprites on the upper part of the screen, trigger a raster interrupt, move the same sprites to the lower part of the screen and thus have it appear as sixteen sprites on screen, I was hooked. It was like being able to wield magic.
- ggambetta 8y agoSimilar story here, but on a ZX Spectrum :)
- Flow 8y agoMy thing was sprite-multiplexers. In theory it's very simple. You sort the sprites by y-position, then use raster interrupts to reprogram the sprite registers for "(spriteN++ & 7)". The hardest part is sorting. It takes quite some time to sort data on a 6502. I "invented" my own sorting routine for this, but I later learned that most coders used bubblesort since most of the time sprites move just a little so it's mostly sorted already. My routine used half the stack. I took ypos >> 2 and used that as an index to the bottom half of the stack. If the position was occupied I used the next pos etc. To collect I simply used a PLA(pop) instruction. There were holes of course, so you had to check for empty slots. That routine took about the same time every frame. 32 sprites was not very hard to do, sorting-wise.
- code_duck 8y agoThis is primitive, but not quite from scratch - that makes me think of TempleOS. This is more like, computer graphics without libraries.
- ggambetta 8y agoFair enough. It's definitely "from scratch" compared with most graphics courses which start at the OpenGL level, but as with whether a language is "low level", it's somewhat subjective.
- fuball63 8y agoGraphics was one of the hardest courses when I was in school for game development. We started with raytracing, did rasterization from scratch, then worked with DirectX and OpenGL. I formed lifelong friendships struggling through toon shading, bump mapping, and particles with HLSL shaders.
- dancodes 8y agoI found it surprisingly hard to get access to the primitives mentioned in the intro, on a modern pc. How does one draw a pixel on a specific coordinate in a modern OS?
- gameswithgo 8y agothe best/easiest way is still use opengl/directx/etc but draw your texture in software, and then draw the texture full screen. This is the approach I used to teach software rendering in gameswithgo.org we make a putpixel function as in the old days, and use it to build up a texture, which we draw each frame. The texture becomes what used to be the framebuffer.
- Asooka 8y agoCopying the entire framebuffer over the PCI bus makes me sad, though it's obviously way faster than when you could memory-map the framebuffer. These days you can't map texture objects in memory because texture storage on GPUs is its own black magic and textures are not stored as simple linear framebuffers. It would be fun to restrict yourself to a well-documented architecture, e.g. give everyone a cheap intel-based notebook and write out commands directly for the graphics chip. I guess while fun that would teach more about doing low-level hardware access than graphics themselves. And while on the topic of changing hardware forcing us to change our algorithms, I wonder if teaching scanline rendering is even worth it these days. Every CPU supports SIMD and a SIMD-optimised software rasteriser is a very different beast than the classic scanline triangle rasterisers of old. Probably the fastest software rasteriser for modern CPUs is OpenSWR [0], written by Intel mostly to keep themselves relevant in the data visualisation space until GPUs eat HPCs (GPUs still can't help you when your dataset is measured in hundreds of gigabytes of graphics data), but it scales perfectly fine down to desktop CPUs. The code for it is in the Mesa tree [1]. I wish I could explain exactly how it works, but it's a pretty big beast and I haven't had the time to read and understand all of it. Intel gave a presentation on it at the HPC developers conference back in 2015 [2] [0] http://openswr.org/index.html http://openswr.org/index.html [1] https://cgit.freedesktop.org/mesa/mesa/tree/src/gallium/drivers/swr/rasterizer/core https://cgit.freedesktop.org/mesa/mesa/tree/src/gallium/driv... [2] https://youtu.be/gpYd18E3TWc?t=1531 https://youtu.be/gpYd18E3TWc?t=1531
- frenchie14 8y agoAnyone know how this guide compares to tinyrenderer? https://github.com/ssloy/tinyrenderer/wiki/Lesson-0:-getting-started https://github.com/ssloy/tinyrenderer/wiki/Lesson-0:-getting...
- person_of_color 8y agoAny dummies guide to shaders?
- formalsystem 8y agohttps://thebookofshaders.com/ https://thebookofshaders.com/
- akdas 8y agoThis is awesome! One thing I really appreciate is building up the mathematical concepts. For example, instead of providing a ray-sphere intersection formula, the tutorial talks about representing a ray and a sphere, and how the two representations must match at intersection points. When I was asked to teach a workshop on computer graphics, I wanted to make the concepts accessible to those who were either rusty, or hadn't even encountered the necessary math. Given a limited amount of teaching time, I introduced only the most relevant math, but did so from first principles. Hopefully my treatment can be useful to others: https://avik-das.github.io/build-your-own-raytracer https://avik-das.github.io/build-your-own-raytracer
- ssdsa 8y agoYes, it is very rewarding to program your own graphics routines or your own simple implementation of a raytracer and then see the correctly rendered scene on screen for the first time. I did this on my Amiga a lot time ago (1995), and then re-created the feeling using ShaderToy: https://www.shadertoy.com/view/lds3z8 https://www.shadertoy.com/view/lds3z8 It's so cool: A scene that took 10 minutes to render in 1995 - nowadays you can see that scene through a moving camera raytraced in real time in your browser!
- philshem 8y agoThe capitalization of Scratch in the title made me first guess that they were using the educational programming language Scratch.
- ggambetta 8y agoThis is the capitalisation the OP used; the one I use myself is lowercase. Perhaps a mod (paging dang?) could fix this?
- hatsunearu 8y agoThis ought to be super helpful for my toy rasterizer project written in Rust. If anyone is interested, I'll post the link (it's crappy) I suggest everyone to try implementing a rasterizer in a new language; it goes over a lot of language fundamentals and a lot of reasonably efficient memory manipulation (if you try to, at least) is required, which forces you to be intimate with the lang. Great Rust practice for me, at least.