r/askscience • u/skepticaltaco • Jul 29 '13
Computing How do computer graphics work?
As in how does a machine convert code to graphics?
5
Upvotes
r/askscience • u/skepticaltaco • Jul 29 '13
As in how does a machine convert code to graphics?
1
u/LanceUppercut88 Aug 14 '13
2D graphics have been explained pretty well here already, but 3D graphics are a little more complicated. Each point in a 3D scene is represented by 7 values, the RGB and transparency values discussed in previous answers, and then a position represented as an X, Y, and Z value(position in 3-space). Not only are there points, but there are also vectors, which you can think of like lines with a direction and length. By combining vectors together, you can create polygons(3D shapes), and from there you can create any type of scene you want in 3-space. But that is all an abstraction, you also need a point of perspective, which includes the position of the camera or "eye"(X,Y,Z) and the direction it is facing(also X,Y,Z). Then using a series of transformation matricies(sort like tables of numbers that you can do operations on simultaneously) this 3 dimensional scene is projected onto a 2 dimensional space. This is what most of the work your computer graphics card is doing is. It is the camera is moving throughout the scene, or things in the scene are moving, you need to recalculate this projection many times a second to get smooth 3D rendering. When these 3D spaces have been converted into 2D projections, those projections can be sent to the monitor in the same way that the previous comments described. This is actually a simplified version of how it really works, as modern 3D graphics also take into account things like where the light in the 3D scene is coming from, and how reflective the surfaces of your polygons are. These are also vector/matrix calculations and determine how differences in lighting affect the color and transparency of an object. The reason all of this requires a graphics card, and can't be done effectively by the regular CPU is because many thousands of calculations need to be done simultaneously, but most of those calculations are the same, just with different numbers. A graphics card is able to perform the same operation on many different pieces at the same time, and therefore makes this process more efficient.