well apparently I can't use Desmos as a legitimate graphics library for my resume so let's talk
about gaming nowadays it seems like anyone can regurgitate Unity assets until they make
the next Baldi's Basics and high level game engines such as Unity and Unreal have really
made game development something that anyone can get into top indie games in the past few
years have used even simpler engines GameMaker Studio produced Undertale RPG Maker produced
Omori Pygame produced
If you stretch the definition even Discord has been used for game development though
only for very simple text-based games of course but game development to its full extent requires
a lot of complicated engineering from animation to mechanics lighting and sound or as they
say in the game development industry *screams* but perhaps what is taken the most for granted
from our game enginers is the ability to render in 3D
obviously computer screens and other devices aren't actually 3D they're 2D surfaces however
anything in 3D can be represented by a model which contains a series of vertices and indices
a vertice represents a coordinate in 3D space x y z while an indice gives each vertex and
index so that we don't draw duplicate vertices we may also want to specify a mesh topology
which tells our renderer how we want to connect our vertices using these indices for example
connecting every 3 vertices with a triangle however we should note that the vertices we
now have from the model are all only relative to the model they may tell us that the model
is a cube or a character but that's it tells us and it's not enough for us to create a
3D rendering
what you're going to have to do is to transform your local model through several spaces namely
the world space, the view space, and then the clip space the world space is probably
the easiest to understand if you've ever played Roblox or lived in a 3-dimensional universe
before it represents the position, size, and orientation of your object in the world and
it's achieved by simply moving, scaling, and rotating your object as you want to see it
in the world view space just represents the perspective of the camera if you want the
camera to move in a certain direction you would move everything else in the opposite
direction if you wanted the camera to rotate up or down then you would move everything
a certain way using some trigonometric equations the clip space is where everything comes together
taking your 3D coordinates and projecting them as 2D coordinates on a rectangular plane
in front of your camera you can imagine there being this box that contains all the objects
that you're rendering that flattens into a rectangle that you can then put onto a screen
however if you just use a rectangular prism as your box to provide a clip space what you're
going to get is not going to look like real life that's because in real life there are
things called perspectives and so you to use a perspective projection also known as lying
but with geometry in real life when things are farther away they appear to be smaller
but a GPU has no concept of this so what we have to do to mimic the concept is to make
it so that our box that holds the clip space gets smaller as it approaches the rectangular
plane this way when an object on that part of the clip space gets projected it appears
to be bigger when it gets closer and when it's farther away it appears to be smaller
once it shrinks down to the size of our rectangular plane you can see that the result looks much
more natural and once you take these 2D vertexes and convert them into whatever the pixels
are on your screen you end up having your 3D render running on your 2D screen everything
I've talked about up to now is run by a script sent to the GPU called the vertex shader what
this is is it's basically a script that runs for every single vertice we have loaded from
the model transforms it through teh spaces and finally loads it as a 2D coordinate on
your screen space and from there the output of your vertex shader becomes the input of
the fragment shader and by fragment shader I mean pixel shader and by pixel I mean fragment
they're interchangeable what this shader does is it takes in other data that may be included
with the model such as texture and texture coordinates to determine which part of the
texture goes to which vertex and runs for every single fragment that's been produced
by the vertex shader thus giving us colour it should be noted that this fragment shader
is also sent to the GPU and just like that you've got a very rudimentary 3D renderer
of course my explanation drastically simplifies this process and if you want to optimise your
renderer or create more advanced renders you'd have to go through many more steps including
additional shaders I mean I haven't even mentioned lighting and that goes much more into simulating
how light optics works lucky for us there's many well-established graphics libraries that
abstracts much of this process for us OpenGL has been a standard for cross-platform graphics
rendering and its process is fairly simple to learn DirectX offers a bit more than just
the graphics rendering capabilities and it's a bit more advanced but it's proprietary to
Microsoft so only available on Windows and Xbox which can be a turn-off for a certain
crowd of people though DirectX has many versions each one improving in performance and complexity
Vulkan also exists I guess and that's all I really know about it though it's also cross-platform
and said to offer higher performance and lower level nonetheless we now have the tools to
render 3D graphics on a 2D screen and knowing what we known now we could hypothetically
run 3D renderings on 2D graphics tools of course there are limitations to this for example
you can't 3D graphics on Discord that's a text messaging app that would be ridiculous
well kind of I mean I'm kind of cheating cause I'm not using Discord as the game engine that
would be much more complicated instead I'm using OpenGL but rather than sending outputted
fragment shader data into pixels on a window for example I'm sending the pixels through
a websocket to Discord API a websocket is just a communications protocol that's pretty
much real-time so very useful for video games the emoji reactions on the top message get
sent through this websocket to our OpenGL which then manipulates the view space which
is as you remember the camera once we have moved everything as we have inputted the fragment
data creates the pixels and those are sent back through the websocket to Discord where
we can then render the next 20 frames as an animated file now we're using animated frames
rather than say updating an image every frame or having ASCII art because Discord has rate
limiting like any other sensible app and so it's a lot less noticeable to have a 20 frame
input lag than outputting at 1 frames per second or getting banned for API abuse nonetheless
a pointless animated file on a messaging app is still a 2D surface so if anything it still
demonstrates the functionality of a 3D renderer though you may have noticed that tehre are
limitations to my renderer as I used a pretty basic implementation and thus it can only
play very basic games such as floating cubes or Cyberpunk