JACOB ROBINSONOpen.
← Blog ArchiveARTICLE 254 / 265

Blog Archive / JACOB ROBINSON

So, How Do Computer Graphics Work?

One of the open threads left in our article on the fast inverse square root algorithm was how exactly all those advanced 3D graphics worked. And while I don’t want to get too technical or mathematical, I do think it’s worth returning to this topic to get the 101 on computer graphics.

Basics of 3D Graphics

Your screen is made up of a bunch of really small light cells. The way in which these light cells differ depends on what exact screen you’re using, but they all have the same purpose: when your computer sends a message saying a certain cell should be a certain color, the cell changes to that color. There are millions of these cells, and they are sometimes changing hundreds of times a second.

Now, how this approach works when it comes to 2D graphics is pretty easy to understand. Right now, my Google doc is a white background with black text (I left my dark theme at home). The code Google made tells the browser to make it this color, the browser tells the OS it needs to be this color, and the OS tells the computer to change my monitor to that color. Once again, at a high-level, this isn’t anything too crazy.

But 3D is weird. Our monitors obviously cannot handle 3D – even VR headsets, which are made to look 3D, are mostly just relying on perspective tricks using the lenses. So why does it not feel like a 2D image when we play video games?

A few changes to the traditional formula are done here. The first is that we create a 3D Model – don’t think of this in the colloquial “3d model” term like a .obj or .dae file, but as in literally a mathematical map of 3D space. We use x,y,z coordinates to illustrate points and faces of entities within our new 3D world. But simply saying where these things would be if they were 3D doesn’t really do anything – if we tried to render it, it would still look like a plain 2D image.

This is where those “advanced mathematical equations” come into play.

Basically, we want to make our 2D scene as realistically 3D as possible. So, what better way to do this than to use real world equations? We can get information on how light reflects on objects, how our eyes perceive depth, or how physics works – and then we can apply it to the 3D Model in order to give us the illusion that it’s all happening in 3D space.

Primarily, there are four major categories in which we use to define realism in a 3D Model: camera transformation, shading, shadowing, and depth buffers. As is usually the case, the best way to explain this is through an example.

How to Make a 3D Model

Traditionally, there’s two ways of making a 3D model. If you’ve ever tried to do it before, it’s likely you were using software such as Blender or Unreal. These are 3D engines – they do all the advanced math for you on the backend, so all you have to do is press a couple of checkboxes, alter a few variables, and change things around in an already existing 3d space. But there’s also 3D APIs – these are programming languages that allow you interface directly with a GPU, a specialized part of a computer specifically created to handle this advanced mathematics. Blender and Unreal are actually built using these APIs, and even if you haven’t used them directly before you might be surprised to find they’re already installed onto your computer!

There are many of these 3D APIs available – OpenGL, WebGL, Vulkan, and DirectX are among the biggest. Fortunately for you, we’re going to keep it general and so you won’t need to learn one of these APIs or boot up Visual Studio in order to understand what we’re talking about.

The first thing you do in any 3D API is create a window. This is actually unrelated to the process of making our 3D Model, but is such a fundamental part of the process that it’s impossible to start with anything else.  This window basically just allows the OS a viewpoint into this 3D world you’re creating – much like how a browser window allows the OS to view a connection to the internet, etc.

In the next step, we create an entity (such as a cube) in our 3D Model by describing vertices (specific x/y/z points) and indices which define faces (the blocking that encloses points, thus making them a 3D object). As I’ve mentioned before this still doesn’t make the scene look 3D, but it helps our mathematical model understand where certain “blocking” points are that would require light reflection or depth perception.

After we create these vertices/indices, we ship them off to the GPU’s memory. As I’ve said, the GPU does the heavy lifting in the wide majority of 3D calculations, so we’re keeping the GPU informed of where things are in our 3D space so it can make speedy calculations when we tell it to place something like a light or a camera.

Speaking of light, our next step is the shader. A shader is arguably the most important piece of the computer graphics puzzle – at a very basic definition, it defines how texture changes on an object when light shines on it. But there’s a lot of ways we can define texture: color, roughness, shininess, transparency, and many more that are outside the scope of this article!

Typically, “shading” and “shadowing” are handled by the shader, whereas “camera transformation” and “depth buffering” are handled by the API. They are pretty easy to package together: shading and shadowing are based on light interactions (the way an object shines and the shadow it leaves behind) and transformation/buffering are based on camera interactions (if a camera is at point A, what do we see? How are objects layered on top of each other, and are certain ones easier to see than others?). So, that segues us very nicely into the final chapter of this article…

Adding Spice with Cameras and Lighting

Now, hold on a minute – we added the ability for our 3D Model to handle lighting, but we didn’t actually add any lights! Beyond that, how does our 3D Model know which way to face the scene if there’s no camera?

Fortunately, this is pretty easy to do in the API. Both consist of three components: a point in x/y/z space (its origin), a vector (the direction it’s facing) and a ray (how far it interacts with other objects in the x/y/z space). If you read our FISR article, this should all be sounding pretty familiar!

When it comes to the camera (also sometimes called the “viewpoint”), the complexity usually ends there. But for lighting – arguably the most important entity that sets up a believable 3D scene – there’s a few more things we can tweak. Like shading, this could be its own article – but I do want to mention one category in particular.

If we want to calculate light, there’s two ways we can do it: ambient lighting, and ray-traced lighting. Ambient lighting is the more basic calculation – it is usually just an equal spread of light, either around the entire origin (a “point” light) or in the direction of the vector (a “spot” light). However, ray-tracing – a relatively new invention – uses real-world light physics to determine how far any given ray of light would go, and how it would look, based on its journey from the origin. Engines like Blender and Unreal now have native support for ray-tracing, but it still requires a pretty beefy GPU to compute!

Anyway, that’s all for our Computer Graphics 101. We still have a lot we can cover – such as shading and lighting – so I can see this topic becoming a playlist on here. Let me know in the comments if there’s anything you’d like to see in particular!

[Image omitted]

Select text in the article to highlight it.

Your saved highlights

    Article contents

    Blog Archive · 265 articles

    1. 01 Five Takeaways from #100DaysofCode
    2. 02 Getting Past the Bump
    3. 03 How Important are Principles?
    4. 04 How to Avoid Writer’s Fatigue
    5. 05 The Dangers of Catastrophizing
    6. 06 State of the Union 2019
    7. 07 The Rise of the Personal Brand
    8. 08 Finding Adventure in 2019
    9. 09 5 Ways to Use Automation to Vastly Increase Your Efficiency
    10. 10 What you Should be Doing Instead of Networking
    11. 11 Creatives vs. Technicals: Which Should You Focus On?
    12. 12 The Difference between Quitting and Giving Up
    13. 13 3 Ways To Get Value Out Of Nature
    14. 14 What is the Purpose of Dreams?
    15. 15 How to develop intellectual success in future generations
    16. 16 What the Definition of Luck Really Is
    17. 17 Who Makes the Culture?
    18. 18 Sexual Frustration and Trying to Find Love in the Age of the Internet
    19. 19 The Lazy Man’s Guide to More Efficient Research
    20. 20 How One Joke Can Ruin Your Life
    21. 21 Why IQ is BS
    22. 22 Why it’s Impossible for the Illuminati to Exist
    23. 23 Some of my Favorite Blogs
    24. 24 The Most Important Indicator on Why a Company Succeeds
    25. 25 Returning to Tesla
    26. 26 Living in a Post-Truth World
    27. 27 The Function of Success
    28. 28 Lessons at 20
    29. 29 If the Recession Happened This Year…
    30. 30 Why People Don’t Read
    31. 31 Social Media and Truth
    32. 32 Making Things 1% Better
    33. 33 What the Book of Job Really Means
    34. 34 Life as a Game
    35. 35 The Function of Opportunity
    36. 36 Exponential Growth
    37. 37 The Machine Learning Revolution
    38. 38 Practical Thoughts on Blockchain
    39. 39 Why the Humanities Are Just as Important as STEM
    40. 40 Dow 30,000
    41. 41 The Shame Economy
    42. 42 You Can’t Do It All Alone
    43. 43 Favorites of 2019
    44. 44 State of the Union 2020
    45. 45 The Tolerance Paradox
    46. 46 Null
    47. 47 Social Game Theory
    48. 48 3 Tips for Developing a Positive Mindset
    49. 49 Why Social Gaming is So Popular
    50. 50 A Design Study on YourStack
    51. 51 Relationships, Careers, and Investments
    52. 52 The Fall of GAFA
    53. 53 Wartime CEO
    54. 54 Mass Shooting Cycles
    55. 55 But Who’s Right?
    56. 56 What Matters in the End
    57. 57 Is AR/VR too “weird”?
    58. 58 Convenience + Efficiency
    59. 59 Vicious Cycles
    60. 60 With Smart People
    61. 61 The Third Moat
    62. 62 The Secret to Success
    63. 63 The End of Education
    64. 64 The Ben Carson Effect
    65. 65 Biological Evolution, Cultural Evolution
    66. 66 Suicide and the Self
    67. 67 The Life Cycle of a Business
    68. 68 How to Get into Harvard
    69. 69 Managing Your Personal KPIs
    70. 70 Fog of War
    71. 71 Make-or-Break vs. Nice-to-Have
    72. 72 Identity and Political Groups
    73. 73 Nationalism’s Pros and Cons
    74. 74 How to Win an Election
    75. 75 Why You Shouldn’t Network
    76. 76 On Relative Morality
    77. 77 Death in the Age of the Internet
    78. 78 Audience of One
    79. 79 The Rise of Anxiety
    80. 80 Stop Getting Scared By AI
    81. 81 If You Build It, They Will Come
    82. 82 Building Knowledge Advantage
    83. 83 The Quest to be Kinder
    84. 84 Everything You Do Sucks
    85. 85 Niche Monopolies
    86. 86 Up Shit Creek
    87. 87 Emotional Equivalent Salary
    88. 88 Uncertainty Principle
    89. 89 Building a Startup with Anxiety
    90. 90 Punishment and Forgiveness
    91. 91 Favorites of 2020
    92. 92 State of the Union 2021
    93. 93 Random Factor Social Suicide
    94. 94 Old World Business, New World Business
    95. 95 The Customer Takes Care of Itself
    96. 96 How to Use Reddit as a Business
    97. 97 Genetic Obsolescence
    98. 98 A Social Capital Theory of Management
    99. 99 If I Could Do My Education Over Again
    100. 100 Aggregation and Decoupling
    101. 101 The Crazies, Part II
    102. 102 Art as Inspiration, Art as Education
    103. 103 Free to Play Models for SaaS Services
    104. 104 A Recap on my 2020 Politics Posts
    105. 105 Making Mistakes, Post-Internet
    106. 106 Taste is Not Tech
    107. 107 Immortality
    108. 108 Biases Against Consistency
    109. 109 The Mythical Self
    110. 110 Faulty Mental Models
    111. 111 Honor and Glory
    112. 112 Momentum, and the Value of Cold Showers
    113. 113 The Prestige Myth: Providing Structure to Structureless Forms
    114. 114 The Unluckiest Man Alive
    115. 115 Those Who Make, And Those Who Work
    116. 116 Post-Truth, Revisited
    117. 117 Conscience Questions, Unchristianized Edition
    118. 118 On Being You
    119. 119 Effective versus Efficient
    120. 120 The Experimental Method of Learning
    121. 121 A New Model for Teaching Humanities
    122. 122 A Dialogue on Mindset
    123. 123 I Am Not Your Friend
    124. 124 My 5 Tips Towards Reading Books
    125. 125 Buying Immortality
    126. 126 Do this, but…
    127. 127 Leverage and Wealth: A Simplification
    128. 128 Mind’s Eye and Creative Application
    129. 129 Intersection of Technology and Art
    130. 130 Blog Writing for Robots
    131. 131 10 Tips on Writing
    132. 132 The Cost of Staying Alive in America
    133. 133 Taste on the Margin
    134. 134 Top 10 Tools I Use in 2021
    135. 135 Income Generators 101
    136. 136 Strategies for David, Versus Goliath
    137. 137 Progress in the Long Term
    138. 138 The End of Journalism
    139. 139 Myths of People
    140. 140 Heroism
    141. 141 External Mentors
    142. 142 Favorites of 2021
    143. 143 State of the Union 2022
    144. 144 The End of Gender
    145. 145 The Work After Work
    146. 146 There Is No Metaverse
    147. 147 On Dealing With Chaos
    148. 148 Risk/Return Bets in Entrepreneurship
    149. 149 The Weird, Magical World of Modern Day Quora
    150. 150 On Business
    151. 151 What’s “Hivemind”?
    152. 152 Life as a War
    153. 153 On Culture
    154. 154 My Approach to Investing
    155. 155 Stop Caring About Your Reputation
    156. 156 On Humility
    157. 157 Is Relative Morality Helpful?
    158. 158 Achievement-Based Thinking
    159. 159 On Success
    160. 160 Moral Implications in Maximums and Minimums
    161. 161 Sentience and Suffering
    162. 162 On Improving
    163. 163 The Suicide Disease
    164. 164 Social Diversification
    165. 165 On Meaning
    166. 166 Convenience and Pareto Optimality
    167. 167 Mental Illness is Not a Permanent State
    168. 168 Biased Science
    169. 169 People as Means
    170. 170 Being Wise and Being Smart
    171. 171 The New Working Class
    172. 172 Fitness, Suffering, Self
    173. 173 Political Theory and Evolution
    174. 174 Explaining my Rating System
    175. 175 Why You Might Want A Trading Account Over An IRA
    176. 176 Why NFTs Don’t Work For Games
    177. 177 A Few Thoughts on MMOs
    178. 178 A Review of MyMind
    179. 179 Read, Think, Make, Share, Monetize
    180. 180 Is Science Perfect?
    181. 181 A Guide to Fiction Writing
    182. 182 The Productivity Tool World Tour 2022
    183. 183 My Daily Routine
    184. 184 The Curse of The Conqueror
    185. 185 Some Brief Notes on Programming
    186. 186 My Life Principles
    187. 187 Cyberpunk in 2022
    188. 188 What Decides Good Art?
    189. 189 Trends in Mass Murder Techniques
    190. 190 Changing to Fit the Times
    191. 191 Why Did Photographers Embrace NFTs, but Artists Didn’t?
    192. 192 Favorites of 2022
    193. 193 State of the Union 2023
    194. 194 New Blog Post Schedule
    195. 195 Was Lex Fridman’s “Reading List” Controversy Caused by Mass Psychosis?
    196. 196 Is Notion “Too Good”?
    197. 197 Mastodon is Social Media PvP with Permadeath Enabled
    198. 198 Arc, Vivaldi, and the Next Generation of Browsers
    199. 199 Is the Four-Hour Workweek Actually Possible?
    200. 200 Do Not Obsess Over Your Customer. Obsess Over Your Community.
    201. 201 Why Big Entertainment Failed to Bring in Diversity
    202. 202 My All-Time Favorite Tools
    203. 203 Museums on the Computer
    204. 204 How to use AI to get you motivated to work
    205. 205 The Best Way to Focus: Do Nothing
    206. 206 Can Buddhism and Ego Intertwine?
    207. 207 How I Write My Blog Posts Now
    208. 208 Practice and Mysticism
    209. 209 Automate the Boring Stuff with ChatGPT
    210. 210 State of the Union 2024
    211. 211 The Secret to Great Products You Aren’t Doing
    212. 212 How to build a $5 billion dollar business in 5 minutes
    213. 213 How To Easily Automate Investments, Beat Big Tech, and more!
    214. 214 Can I Use AI To Solve The World’s Unsolvable Problems?
    215. 215 How A “Taste Matrix” Can Improve Your Art And Kill Writer’s Block
    216. 216 My Bizarre, Counterintuitive, and Lifechanging Approach to Work
    217. 217 Top 3 Recommended Browsers (They Aren’t What You Think)
    218. 218 How Hard Is It To Make Money On Steam?
    219. 219 What To Do If You’re Socially Anxious
    220. 220 My New New Way of Reading Books (I Abandoned AI)
    221. 221 References Are The Best Way To Learn Anything
    222. 222 How To Quit Planning Goals And Start Achieving Them
    223. 223 The Only Good Self-Help Book
    224. 224 Be Nice To Everyone. It Just Might Save Your Life.
    225. 225 I Learned An Ancient 3-Step Process And Became A Master Meditator
    226. 226 How Canva Became The Home of Everything
    227. 227 Has The Internet Made More People Mentally Ill?
    228. 228 The Biology Behind Why We Like Stories
    229. 229 This Tape Haunted An Entire Nation. But Was It Even Real?
    230. 230 We Are All Most Certainly Going To Make It
    231. 231 What Makes Good Taste?
    232. 232 In a World of Cancel Culture, Reputation Doesn’t Matter Anymore
    233. 233 Why You Hate Diversity In Media
    234. 234 I Used Readwise for 200 days. Here’s what happened.
    235. 235 Lessons on Bootstrapping Solo with Little Income
    236. 236 This Ancient Story Was Drowned In Lies. The Truth is Much More Interesting.
    237. 237 How To Get Actionable, Memorable Advice Out Of Anything You Read
    238. 238 You Are A Coward. And That’s Not So Bad, Really.
    239. 239 Time Travel is Real. Here’s How to Use It.
    240. 240 How I Got Into Old Games
    241. 241 Is Every Story Political?
    242. 242 Your Culture Decides Your Fate
    243. 243 In Defense of the Jumpscare
    244. 244 Final Fantasy XIV’s Story Is A Mess
    245. 245 Markov Chains and You!
    246. 246 I used Obsidian for 90 days. Here’s what happened.
    247. 247 Ideas That Can Kill You
    248. 248 Porting A 250k+ Item Database from Notion to Obsidian
    249. 249 Why the Fast Inverse Square Root Matters
    250. 250 A Deep Dive on Networking
    251. 251 A Deep Dive on Cybersecurity
    252. 252 Converting a $100k+ Trading Algorithm from Excel to Python
    253. 253 How To Make A (Super) Hard Drive From Scratch
    254. 254 So, How Do Computer Graphics Work?
    255. 255 The Quantum Physics Rabbit Hole, Part I
    256. 256 The Quantum Physics Rabbit Hole, Part II
    257. 257 The Story (and Meaning) of Humanity’s Greatest Achievement
    258. 258 Explaining Tonal Indicators
    259. 259 AI should have you thinking MORE, not less
    260. 260 Forbidden Knowledge: The Vela Incident
    261. 261 All success in life comes back to pain tolerance
    262. 262 The AI Revolution rewards the curious
    263. 263 Forbidden Knowledge: Marco Evaristti
    264. 264 Forbidden Knowledge: Casket Failure
    265. 265 Forbidden Knowledge: Coriander Theory

    Share

    Make it your own before sharing.

    Page link

    Send to

    EmailWhatsAppBlueskyFacebookX

    Facebook shares the link only; add your message there.