#Foundations - Learning Graphics Programming with the Zig Programming language
1 messages Ā· Page 3 of 1
I like how I can just give a function a type T as an arg and then start calling functions on a variable of that T without having to define any kind of interfaces, just pure ducktyping 
it is just automatically inferred at compile time what the constraints of T are based on how I end up using it
I don't like C++ all that much, but it just gives me the most control
you get a lot with C++, it's pretty robust I kind of wish I was writing C++ sometimes, like when I realized I had no good ecs options
tons of stable libraries
all the editors and debuggers work
all the books and websites use C++ examples
lots of people on the server can offer advice, although I can get that on the zig server
despite all the problems though I just really like zig
I've never once had a single footgun or gotcha moment in nearly a year of using it
I started writing my own ECS, it's actually not all that hard (at least for the basics)
ended up switching to flecs just to save time, cause it was fully featured, but for some simple stuff it's not more than like 1 week of work
yeah I am going to basically write something of a game engine a little bit as I go along
not all at once
I'll try to keep in mind how I would use an ECS and try to build something similar as I go so I don't get into too much of a mess, and once it performs badly it'll be hopefully isolated behind an API and I can change how that part works without having to rewrite everything
writing my own pseudo ECS or making zig bindings for flecs are basically equal amounts of work and if it came down I'd rather just write the zig bindings for flecs though
It took me like around 2 minutes to build a brand new scene with a grid and a move around look at camera
just that little amount of code there
also I caved and did it camel case :<
now I need to figure out what an infinite plane should look like
I couldn't help but keep working on my camera
it now has smooth deceleration, I think decent mouse sensitivity and behaves really nicely, and adjustable speed
it's pretty nice now, fully time step and using integration
: )
I added coderabbit to my repo and it gave me a nice diagram of my scene
this isn't right, I'm just winging it instead of reading. I need sleep
idk what's supposed to happen but looks wrong
trying to just create arbitrary plane position and normal orientation
via the parameterized plane [n|d]
this is an infinite plane
but drawing it like that looked not great
it'll make more sense when it's right
I am going to put a little ball at an arbitrary 3D point and have it calculate the distance to the plane and which side it's on
and I'm also going to do an arbitrary plane reflection
so move and rotate a cube around and it will be reflected across the plane
the controls are wrong, it's possible to create a zero vector via cross product, I have to just reread the plane stuff
I need a little pointer thing to tell me which way a plane's facing
so I'm building a cylinder mesh and a cone mesh, and will combine them to create a little pointer object
not a cylinder yet, but it will be :O
not a cylinder yet, but looks kinda cool
also not a cylinder
i really enjoy watching this journey š
Those colors are supposed to be the normals?
If so, doesnāt look right to meāthe bases should have a single normal vector, not a gradient
Thereās no base
OH
Itās just open at the ends
Yeah that makes a lot of sense
https://www.khronos.org/opengl/wiki/Calculating_a_Surface_Normal
Also this is my goto for surface normals
Though Iāll also often actually manually assign normals
I have circles I could use, this is just the cylinder sides
I calculate surface normals via tangents which I get by subtracting points of a triangle
I take the cross product of the tangents as the surface normal
Looks like thatās what that also says
Sounds like what that page is doing, yeah
I go for that page because itās really easy to find it
So for that like one time every couple moths that I start a new rendering project I can just google it
I just sit next to a mountain of math books and use those:P
The point of this project is to build reusable code I can just give it three points and get all that for any future projects
Like all these shapes I can use in the future once I have built them
I am going to delete my cube now that I have my parallelepiped actually, itās way better
Cubes suck tbh
I tend to prototype stuff in minecraft, so doing shared code is a bit annoying sometimes
Especially considering I tend to have like 1% of my code even being able to be shared
How is your project going?
My game engine?
On pause
Currently trying to make an LLM model
I got my LLM model to something that could loosely be considered as learning
Aka before training it generates random tokens and after training it generates <finetune_right_pad_id> over and over 
Granted my dataset is also unrelated to my usage and I donāt think a suitable dataset exists 
(Multiuser conversations is what Iām trying to get working; LLama3.1 is somewhat ok at those but itās noticeably not meant for it)
Sounds expensive tokenwise
<|begin_of_text|>
<|start_chat_header_id|>User<end_chat_header_id>
Hello! How are you?<|eot_id|>
<|start_header_id|>instruction<end_header_id>
You are a chatbot, designed to respond to the user.<|eot_id|>
<|start_chat_header_id|>assistant<|end_chat_header_id|>
Iām using a prompt format derived from llamaās
Neat itās too close to what I do for work these days
Hm?
It would just feel like my job to do anything ai related

I work with azure ai studio and copilot all day now
Writing prompts and state machines for helpdesk support
I have plans to try to work around context length; my machine isnāt all that beefy and Iāve been running into the context length limitations of LLama3.1 8b a lot
that summary step is whatās running into context length limits
Itās also extremely incoherent with names
Which is
a huge problem for a discord chat bot
Basically
My thought is
what if I use up to 4 NNs to encode the context into a fixed size block of data
Neat project thatās way beyond my level of understanding. I got enough trying to learn geometry and graphics :P
I love jupyter notebooks only time I use python anymore
Step over doesnāt murder performance
Iām using HF Transformers for my AI stuff and Iām kinda doing it for a discord chat bot
So my options are either:
- use actual python scripts
- transpile python to java (pretty sure I need to write the transpiler myself)
I am absolutely not writing the discord portion of a discord bot in python, that sounds like a nightmare 
Yeah I agree
Iām currently just using the input/output streams to have java communicate with python and vice versa
which is, not a great solution but it does work
Like http2 or bare socket or tcp
Those would be the proper solutions, yes
Lol
I mean so far my program hasnāt crashed in the like
probably already hundreds of messages Iāve had it generate
Every time my program starts generating a message
If Iām playing a game when it happens
My game reduces to like 1fps 
You could spin up a small k8s or docker compose if you wanted something fancy
I think I need performance

The game also reduces the program to like 1 message per minute
Which is, another reason Iām trying to make my own model
Forgot weāre talking about gpus when I started thinking about services

I mean the game Iām referring to is an unreal engine game
And unreal engine is a large GPU hog
Also
Worth noting
With LLama, when you go over the context limit, the output is a lower quality and it takes far longer
Which is, not necessarily desired when Iām pretty sure Iām above the limit like 25% of the time 
Oh interesting hrmm
They do get slower
Yeah even the accuracy thing I noticed too in larger contexts
Transformers has a warning when over the length limit
Different models respond differently to the context limit according to said warning
What this means exactly? not sure
So far I have yet to go above⦠I believe I currently have the limit set as 4096
For some reason I made it so users can upload multiple files to my system at once
users can upload like 5GB of data as a prompt if they have discord nitro
Users can also upload PNGs, which seem to deadlock response generation
Do these models have raw embedding extraction options, like just the vectors, for storing contexts
Unsure what that means
Embedding models let you extract embeddings which are like huge multi dimensional arrays of data
But it would be a more compact format for maybe
Storing conversation context for example
Iām not storing conversations, actually
I donāt know about these small open source models
Based on what Iāve written (with, more than a small amount of assistance from code copilot on chat gptās interface)
Thereās no way to do that with huggingface models
The embedding layer is part of the forward method, as well as the entire rest of the generation process
Basically you store shit in binary form, itās a black box that we donāt really understand
That page does not like safari 
Itād be more reasonable for me to store tokenized data instead of embedding data tbh
Which actually I think would be ~40-75% compression ratio
But also Iām using json and I think json would freak out with that 
iphone safari or desktop safari?
On iPhone it loads the page
Then abruptly reloads
Then abruptly errors
Iāve already had a user happen to create a prompt that would get exponentially larger every time I loaded the program 
Json is funky with special characters
iphone safari
first coherent sentence my LLM has ever generated:
I have a problem
Iāve already shut it off because it was gonna take 5 hours and I kinda donāt want to wait 5 hours
you should get back to graphics programming
But I wanna innovate and doing that in GP is difficult due to how long GP has been around and been a focus of things-
to innovate in GP you have to get really specific
like that fog guy that works at unreal
he's got like a PHD in fog
More specifically I also wanna innovate for low to middle end devices
There has been, little to no focus on high end models for low end devices afaik
Oh hey that thing you said about storing the embeddings
thatās a viable idea for one of the things Iām thinking of
So
Considering I want this to be a high end model for low end devices
I kinda, donāt want to actually train everything into it
Iād rather have it deal a lot with what itās given as inputs, and be able to have it request extra additional inputs for a given topic to substitute the extra training data
I think itās time I mess with activation functions tbh
nice
this was a tough one
my brain can't comprehend the open bottom 
anyway, how's that mo-
oh
I see how that's more c-
no I don't-
do I
yeah I don't see how that's more complex than a cylinder
it's a smoll brain thing I guess
with a cylinder you rotate all vertices of a quad to assemble the cylinder
with this cone I walked the bottom triangle vertices around a circle
and each triangle's first bottom vertex starts at the previous triangle's bottom vertex
I think cylinder is much less complex
it's just one matrix per quad
I think I'm being hecked over by huggingface transformers works 
height = 1;
radius = 2;
for (double rad = 0; rad < rad_360; rad += rad_1) {
double x0 = cos(rad) * radius;
double z0 = sin(rad) * radius;
double x1 = cos(rad + rad_1) * radius;
double z1 = sin(rad + rad_1) * radius;
addTri(
x0, 0, z0,
x1, 0, z1,
0, height, 0
);
}```
I do, operate on a per triangle basis by default
so I am also biased by that fact, since a cylinder is 2 tris per face
you don't think that's more complex
than doing the same thing but with 2 triangles instead of 1?
I am not so good at math that I can just look at trig and visualize what it does unfortunately
that looks like one triangle per loop but, I have smoll brain
I literally wrote this out in discord, lol
sin combined with cos creates a circle
sine on one axis, cosine on the other
doesn't matter which is which, it'll create a circle
right
that's the only bit of trig you need to know for a cone
mhm
with a cylinder it'd be two triangles per loop
oh I see what you're saying
height = 1;
radius = 2;
for (double rad = 0; rad < rad_360; rad += rad_1) {
double x0 = cos(rad) * radius;
double z0 = sin(rad) * radius;
double x1 = cos(rad + rad_1) * radius;
double z1 = sin(rad + rad_1) * radius;
addTri(
x0, 0, z0,
x1, height, z1,
x1, height, x1
);
addTri(
x0, 0, z0,
x1, 0, z1,
x0, height, x0
);
}```good chance I have this wrong
cool
actually kinda curious how scuffed that cylinder algo I just wrote it
but I don't really wanna setup an entire renderer just to test it 
idk man it was hard for me, but you did it in 2 seconds in discord š
noice
obvious in retrospect that is correct
What's for lunch?<|eot_id|>
<|start_chat_header_id|>assistant<|end_chat_header_id|>
I'm not? <|eot_id|>
some more training later
What's for lunch?<|eot_id|>
<|start_chat_header_id|>assistant<|end_chat_header_id|>
I'm not have a good. <|eot_id|>
context; these are the best results I've gotten, and it's taken a long time to get to those
I feel like if I make a custom generate algorithm I could probably reach that point in a few dataset entries instead of like 12k dataset entries or whatever
of note; I also do not understand the generate function at all, for I have not yet interacted with it on a lower level than just calling it and debugging some crashes
"I'm not have a good" perfectly describes me rn

I still love how the first sentence my LLM ever generates was "I have a problem"
also
I don't understand this perfectly yet, obviously
but it seems to me like it's gonna be output count that drags down speed more than input count
so I think I should be able to give it a large input count and small output count for a semi-reasonable speed
or alternatively, I do weird things, which seems like the more fun option
something I could do
is cut my inputs into pieces
cache the embeddings for the inputs into a variable
then when those inputs are next seen, until an unrelated input is provided, I just use those same embeddings
and piece together the embeddings into a single nd array and go from there
I think
how many dimensions are the embeddings
What's for lunch?<|eot_id|>
<|start_chat_header_id|>assistant<|end_chat_header_id|>
What's a problem? <|eot_id|>
<|start_chat_header_id|>assistant<|end_chat_header_id|>
well that's a new output sentence
input_dim * 512
what for lunch is too complex of a prompt, ask it something simple, like how to draw a cone
that's not in my dataset at all
I don't even know if what's for lunch is anywhere in my dataset
but it seems probably based off the like 2 entries I looked at 
but yeah I want this thing to be as close to real time as possible
I'm gonna do my best to accelerate it in any way I can
more gpus
okay any programmatic way I can 
oh I should avoid training the model on full conversations actually
well they can run pretty capable models on small devices, it's the training where you need more hardware? idk
Well yeah, if you quantize the model it can run at a reasonable speed for short conversations
Problem is, thatās not several simultaneous long conversations
I have
I believe a [high end for home computers] computer, and even that isnāt really good enough for a high enough quality one
Granted Iām also severely limited in the fact that most prompt formats die if you decide to use a username instead of a role, since thatās sorta the best way to prompt-injection-proof naming, and thereās no models trained for that
unsloth 8B models are about the highest I can reasonably run for any kind of performance, and even thatās struggling in both performance and quality
Quantization also tends to slightly reduce output quality or change the output drastically from my messing around with LLama3.1 quants
I've been in saving my job mode for the last 2 and half weeks, so only have had a tiny bit of time to do any of this, otherwise be boring you with my book reading rn
I usually spend about 4 hours a day on weekdays and nearly all of the weekend working on my game engine when I'm not doing stuff with my family, but it's just a lot of working late nights and weekends right now trying to make unhappy customers happy again
I haven't fixed any of the plane rotation around an arbitrary axis and the normals are all wrong also but I am now pointing in the direction of the plane
ah I figured it out thanks to renderdoc, I just had to normalize my normals after the inverse transpose
now I just have to fix my rotation
yeah, always normalize to be be safe
Yup makes sense!
I think I will fix my weird rotation by always rotating around the axes of the plane instead of an invisible arbitrary axis
I will have to convert it to the axis angle though
Well
I have to read the math again
itās just [n|d]
I donāt know why planes are so hard for me
I am going to get it soon
The goal here is to just change the parametric plane values [n|d] and the. draw it based on the values of that four d vector
I am drawing a sub plane of the full plane , the center is the planeās closest point to origin
Then I will add a sphere and a cube and move them around and find their closest points to the plane and reflect them across the plane
I think I got it
cool
I fixed a bunch of stuff, I fixed the ridiculous grid scale, I fixed camera, grid and plane positioning, I made pointer look more like pointer, normals are all correct. I'm ready to make progress again
now that the grid scale is actually sane I think maybe the camera sensitivity seems too high again
all of these fixes, fix everything going forward, these are all fixes that impact everything going forward, the camera, the scale of things, the normals of things
these aren't one off fixes for this particular scene, so when I make a game eventually all this will make that game better
I added my sphere as an origin marker but it's got some tears in it and issues with normals at the top
the cone normals inverted also
a lot of work to get these normals right š
seems correct now though
just the sphere is horrid
that's a little better, now the holes
just bad geometry
Kind of a funny looking sphere
But yeah I don't think you want the triangles to align like that
I would generate it basically as if it were quads and then triangulate each one
It should be basically the same as an algorithm to generate a grid, except that you take the x and y position of each vertex and use them as lat/long instead
yeah
what's funny looking about it?
besides the holes
I made it before I had a projection
so couldn't see all the problems with it then
Yeah just the alignment of the triangles, the way the tip of one lines up to the edge of the other
yeah
that's inevitably going to cause gaps unles the mesh is flat
it's just bad geometry code
yeah that's all I was referring to
Ah spheres
Those are something I donāt dare touch

I favor using a shader to project a sphere out of a quad
Also for spheres
I recommend icospheres, personally
this is just a first iteration
I'll probably make a bunch of different ones eventually
icospheres are a pain, UV spheres are straightforward
I do not like UV spheres
They are straightforward, yes
But I want even point spacing
Then you will suffer for it
I am going to fix this sphere I guess
I don't want to spend forever on this right now I'm going to see if I can these holes plugged, I'll make a better sphere eventually
I am going to delete my cube, I have a parallelepied that's a million times better
fix it if you like, but cubes can be colored to have the faces represent the XYZ basis vectors too which is nice, it has a recognizable orientation
parallelepiped
alright
also appreciate your advice thank you!
I'm just kidding around too just do whatever you like
I like the vector thingy up there
thanks!
personally I just use bare lines as debug vectors but that's fancy
bare lines are cool, I was also thinking about dashed lines for some debug things
like when I have an AI and it does path finding
I was thinking like a dashed debug line to show where it's going
yeah
this works
it's got some rough edges, but works for now
I will make something better eventually
yikes
There's no escape š
this sphere will cut you
hrm lat long huh, I actually am using that
spherical coordinates
Yeah
You should just be able to have a double for loop that goes over incrementals of the polar and azimuthal angle
And makes points
And then the index scheme is the same as a grid
yeah the holes are gone but this is gross
They don't seem to be quite gone in the sense of being an actual manifold mesh they just appear to be gone
right
Whereas the UV sphere as I'm describing will only have singularities at the poles
And they'll be invisible anyways
It'll only be broken in the sense that the coordinate system doesn't lend itself to calculating a surface normal at the very top point
But actually you can anyways since we can do it analytically
I'm getting the normals by just shooting them out from the origin
not using the triangles at all
it looks right though
It is, I'm laughing at my own suffering from my non-spherical earth terrain system
your terrain is mind blowing, I think it is amazing and if I ever achieve anything half as good I would be pretty happy
I am not very fast but I am committed and I do the work. It works for me.
this is not a good sphere but it works for this scene I want to get back to reading so I'm going to do all the plane stuff
I bet one of my many books has a sphere in it
I am going to use a cube actually for the distance measuring
Spoiler'd in case you don't want it to be given away but the position part of the UV sphere is just
||```cpp
int stepsAzimuth = 32;
int stepsPolar = 16;
float r = 1.0f;
std::vectorglm::vec3 verts;
for (int i = 0; i < (stepsPolar+1); i++)
{
for (int j = 0; j < (stepsAzimuth+1); j++)
{
float az = 2pifloat(j)/stepsAzimuth;
float polar = pi * (1.0f - float(i)/stepsPolar);
glm::vec3 pos = r * glm::vec3(sin(polar)*cos(az), sin(polar)*sin(az), cos(polar));
verts.push_back(pos);
}
}
I will leave the index generation as a graph paper exercise
I was actually writing some code doing quads just now because I couldn't let it go :P
I haven't looked your spoiler yet let me see how far I get
I think my original solution I realized I need more triangles near the equator so I came up with something convoluted one late night
but it doesnt need to be
yeah
I like the quad idea
If you want to be clever you can skip some of the triangles at the top so that the ends come together nicely but personally I just allow a whole row of verts to collapse to a point at the poles and just call it good
at which point it's literally just a grid
yeah I'm writing a grid now using spherical coordinates
idk we'll see. I just reduce the grid to very few quads at first it should be somewhat spherical, and simple to debug any issues and then I can increase the grid size and it will look more sphere like
gn!
already looking better
let me try it with more points
holy fuck
looking great
that was so easy
that took me like 10 minutes lol
I always over think this shit
alright this is my solution, now I will check your spoiler https://github.com/btipling/foundations/blob/2a718120525013bd6661a5183418b2eed03f0876/src/foundations/object/object_sphere/ObjectSphere.zig#L47
ok mine is a bit different, my spherical coordinates do have the same trig though
I'm a bit more explicit in my quad/indices, I can't quite visualize the quad/triangles in your solution, though I can see the points as a sphere
no more sharp edges
it has the same number of triangles though for each band 
it's so pretty though
thanks for your help!
I am so glad I stick with that dumb thing I had before
here it is with a orthographic projection
alright time to add a cube
these normals are looking great man
I got these things rotating around their centers now too
I wonder if discord is unhappy how much I upload
so I can make a finger gun when I am thinking about my coordinate system
I like this scene so much I made it a banner on my githubs
Mine just places the points and then you just generate the indices to define the tris
Someone stayed up late hehe
Jeez someone's up early too lol
Yeah would be better to sleep more
For reflecting the cube across the plane, I am just going to draw triangles, i have only read about the reflection math for points so far. This scene is just about basic plane math
I will just iterate over the points in the cube, reflect three at a time and literally just draw triangles just for the demo. I hope to wrap it up today
Then work on a frustum plane extraction culling scene
Maybe I can get both done today
I can't remember off the top of my head what it entails in general
I think just reflecting all the points works
The only potential snag is that it may require reordering the indices to change the winding order
Or just flipping the cull face direction
Yes, I will find out. Hehe
point in plane closest to origin 
AI giving me PR reviews (I hadn't written tests or used this yet so no compile error heh)
I got closest point in plane for object working
just need to reflect that cube across the plane and am done with this scene 
I got the distances working too
it was actually so little code to do this https://github.com/btipling/foundations/pull/13/files :/
I want to theme my dear imgui tbh
probably won't do it right now I want to get back to reading I'm just tired of looking at it
feels so vanilla, everything else I put so much work into it
yeah that sounds cool even just to look at it to see how theming is done
I'm working on reflecting finally
I know these things aren't games but they're pretty fun to work on
feels great when you see the math work
You can theme it just be opening the demo window and tweaking the properties in the theme editor
And then export
oh
reflection!
#wip message
I do always come back to GP stuff though
looks great!
thats the green one demon was talking about š
back to working on my sphere
I'm going to have a reallly nice sphere
100% worth it
for my plane extraction I was thinking demoing a little voxel scene with my parallelopiped instances via stb_perlin
the failure to extract planes from my frustum was the reason I stopped working on blockens, this will be a pretty feel good scene once I get it working
Oh is this using index buffers?
huh I have never considered sharing a buffer for the two
oh maybe I'm lying
I'm sharing instance data and attribute data
not indices
sorry
Also
One of the problems with using a game engine instead of making your own and just hardcoding everything
Thereās a chance that your game just decides to corrupt 
:S
Godot crashes ~5 seconds after I open my project, and my fog volumes corrupted 
So this is actually probably my least favorite sphere meshing algo in terms of sphere aesthetic
I love it
although
this is all I've done with it
maybe uv mapping or lighting or other stuff is harder
I have no idea how to do any of that yet
I mean compared to what I had before, which was just broken, I like this for sure :P
I wrote my own trig for this one :O
same
UV maps are pain with that one and normals and tangents and binormals get a bit wonky at the top and bottom
UV spheres are the easiest spheres to make
They are also the easiest to UV map
Icospheres have an even point distribution (these are my favorite)
The one you did is also a bit too mathy for me, given the fact that I really donāt see any potential advantage to it
Lighting is a pretty universal algorithm
What works for one object works for all, until you get to shadow maps
Well
I would say stuff like specular and metalic and stuff but I actually donāt know anything about those
I can tell godot also uses this sphere geometry, due to the top of my bubble being a bit wonky; Iāll probably make an icosphere in blender at some point or smth ig
looks amazing
icospheres look really cool
I'll probably give that go at some point
2d equalizer š
2 cameras
plane extraction from frustum and culling:
Back to reading! I got about 5 books that each have a perspective chapter to get through now and then read the 3D math review chapters in the books like GEA and then I am out of the math kiddie pool and on to actual graphics programming topics instead of basic math and geometry
I think I might just drill down the opengl book and get through it after I get through these chapters, I'm kind of blocked less on math at this point and more on how to use OpenGL, like I don't know anything about attachments or separate frame buffers or much at all about opengl textures beyond the basics
if I get blocked on math somewhere along the way I'll switch back to the math books, probably on lighting, I don't know anything about lighting or shadow math
if it's just basic vectors stuff though I should be fine
I have culling now working with two different methods:
- getting the planes via the linear combination of the camera matrix columns and the the focal length and aspect ratio
- by extracting planes via the transpose of the full model to view perspective transform, including the look at and the x up coordinate space transform
they both work
I literally pieced the math together from three different math books
They all had a different piece of the puzzle
One book has a zup coordinate system, one has a yup and the other has a camera y down world y up coordinate system
None of them have an xup
One book is left handed the other are right w
Left handed is cursed idk who is using that unironically
None of them explain how handedness and up affect the plane extraction math
I am lol
It is good for me forcing me to learn more
I would really suggest using right handed though that's what like all of math and physics uses
but fair enough
Yeah these books just donāt bother to explain how the math is different
The 0 to 1 Z NDC also was a trip
I would have to derive the rotation matrices and stuff
maybe it doesn't affect the basic transforms that much
but it would really fuck with my head so I'd prefer not to think about it too much lol
all of my years of math education have been in RH coordinate systems so trying to do it in another is like trying to read a foreign language
I'm sure I could figure it out with some conditioning though
I think I kind of am stuck with my left handed x up
Like I am conditioned now by my normals and constantly having to map y up book math to x up
I Actually really like it
Y pointing into the screen is great
x and y are up and forward, z horizontal
I have Y into the screen too
I just have X to the right and Z up
Typical ENU (east, north, up) coordinates
it's mostly just contained to a single matrix concatenation, but the plane extraction was much harder because of my weird coordinate system
from the clip space
getting the planes that make up the surfaces of the clip space volume
into camera space
and then into world space
I see
yeah
so the easy way is to just take your camera matrix and do the linear combination thing
doesn't even involve the perspective matrix
like the left plane from the view frustum I extract via adding the second column of my camera matrix multiplied by the focal length and third columns of my camera matrix multiplied by the aspect ratio
the other way from clip space it's the addition of the inverse of my mvp transform's fourth column by its first
and then inversing the plane distance
I just didnt realize how much harder that would be because of coordinate system decisions
it's interesting how the planes are similar but not equal
also my sphere has too much geometry to instance spam it
I need like a sphere LOD
The projection chapter in https://www.mathfor3dgameprogramming.com/ is ancient
it uses glFrustum, uses a height/width aspect ratio where the plane of perspective height is the +/- aspect ratio, and mentions that some older GPUs don't do perspective correct interpolation
it also uses the -1 to 1 Z clip space
the math is still correct and interesting though
published in 2011
discusses a reflection perspective matrix also, so not that old I guess
perspective matrices are pretty complex and I understand now why they're so far into these books, people don't want to wait to get to 3D but in a math book you have to work through the math because if you're starting at 0 it's not going to be understood
the whole viewing in 3D is pretty complicated objects get moved to world space, then get moved into camera space via a reverse camera matrix, then projected into a view frustrum onto a projection plane into a clip space which is not 2D, you're still 3D, then you're in shaders, then you're in clipping and rasterization, and now you're working on pixels that get put into framebuffers
Not super interesting I'm sure, but I wrote this in my notes when trying to explain how a projection matrix works just from my understanding:
In a perspective matrix the x and y of a point have to be mapped into the x y coordinates of the projection plane, this is done by casting a ray from the camera through the point onto the projection plane. The aspect ratio and the focal length(the distance from the near plane to the projection plane) determine the shape of the projection plane and thus in the perspective matrix the first two entries in the diagonal achieve this transformation of x and y, in the case of older platforms a linear combination required more columns than just the diagonals for anx and y. This is probably because of the shape glFrustum took. In any case the z needs to be transformed into a reciprocal (1/z) by the projection matrix for the purpose of being interpolated into the clip space depth volume to then be transformed into a value in the depth buffer after division by w. The reciprocal is is also used for perspective correct interpolation of vertex attributes. The z value of the perspective requires the depth scale created by the near and far plane and thus the z value ends up being transformed by a linear combination of two components in the third row (in a column major matrix).
I didn't state that because the projection plane's x is twice the size of the aspect ratio it's multiplied by focal length and divided by the aspect ratio, and the y is just multiplied by the focal length, but I know that. The z projection math is harder to explain, but I think I got the high level of it.
probably the hardest to understand matrix so far
I like Cem Yukselās explanation a lot
It is intuitive in that perspective projection is divided into two steps: perspective transformation + orthographic projection
It was easier for me to internalize that way
I also used a combination of sources to tackle this topic
www.gamemath.com (chapter 10 has a section dedicated to viewing transform),
songhoās explanation,
Cem Yukselās explanation,
Bremdan Galeaās explanation
Introduction to Computer Graphics.
School of Computing, University of Utah.
Course website: https://graphics.cs.utah.edu/courses/cs4600/fall2020/
Perspective matrices have been used behind the scenes since the inception of 3D gaming, and the majority of vector libraries will have built-in helper functions to construct them for you. But what if you wanted to know the reasoning behind how these matrices are constructed.
I start off with a brief introduction of computer graphics and the k...
Also took some notes if you want to compare
i feel like directly learning a bit of the core math works well too
khan academy linear algebra stuff
so that you learn about things like vector spaces
Definitely
Also, I could not keep up with this thread coming in so late as I did
Iām watching you though beware š¦
Awesome stuff in the works, kudos!
understanding linear algebra is definitely a prerequisite for understanding perspective matrices, but it's not enough in my opinion
even understanding perspective geometry isn't enough, because that's not what the perspective matrices we use in our games do, it's not a simple perspective divide
the result of a perspective matrix in games and game engines doesn't simply project a 3D point in 2D, it is a homegenous 4x4 matrix that instead performs a transformation from 4D to 3D, the end result being a 3D point in clip space, not a 2D point, because the depth needs to be preserved for hidden surface removal and perspective correct interpolation of vertex attribute data
so you have to also understand graphics apis and the rendering pipeline, and on top of that you have understand how virtual cameras work and coordinate system transformations and NDC because the shape a perspective matrix takes will vary considerably based on these
an infinite reverse matrix takes into account floating point precision near the far plane, so there's even more
or you can just use the glm perspective function and be happy with what you see if that works for you
So reading through Essential Math I realized that I don't need to inverse my camera matrix, although that works, there's a more performant option which is to transpose the upper 3x3 of the camera matrix and then multiply the transform the translation from the camera by that and negate it
pub inline fn cameraInverse(m: matrix) matrix {
var r: matrix = .{
.columns = .{
.{
at(m, 0, 0),
at(m, 0, 1),
at(m, 0, 2),
0,
},
.{
at(m, 1, 0),
at(m, 1, 1),
at(m, 1, 2),
0,
},
.{
at(m, 2, 0),
at(m, 2, 1),
at(m, 2, 2),
0,
},
.{ 0, 0, 0, 0 },
},
};
var vPos: vector.vec4 = vector.negate(transformVector(r, m.columns[3]));
vPos[3] = 1;
r.columns[3] = vPos;
return r;
}
works
I think this is better than zmath's lookAt tbh https://github.com/zig-gamedev/zig-gamedev/blob/1c9461eab81a004bf0e3b3064da2487f57a07d77/libs/zmath/src/zmath.zig#L2264-L2273
I think Lengyel didn't even cover the camera matrix
this produces the exact same matrix as inverse did since the upper right 3x3 is orthonormal
yes, very handy I agree
more evidence that just one math book isn't enough, you have to read a bunch of them
I guess I should have figured this out on my own though, I know that the inverse of orthonormal matrices is the same as the transpose
but I didn't think about how the translation would be affected
I just learned that incidentally from group theory I think
@delicate delta last night
you were in my dreams
along with your foundation
i dont rember the details, but some maffematical stuff came up and involved vectors or normals of sorts, and then all of a sudden you were there, and all your pictures and clips were parts of a book you browsed through to show/explain to me what normals (or whatever it was exactly i dont rember) were
background was dark blue
and the pages of the book must have been A3 or so
š
lol
hey yeah you should be having Lyzantra lecture you on maths in your dreams, as Lyzantra is way beyond me
I am NOT a math person
still better than me
I just know how to make the most of the stuff I do know
Typically J17 ācuz thatās what MC used for a while
Though I flip between J8, J17, and J21
I knew you were still using java 8
I think like 90% of people writing java are still using 8. I made that up but I think its' true
whenever I use J17+, I regret not using J8, and whenever I use J8 I regret not using J17 
MC is the one place where I donāt have to deal with this conundrum
Most likely correct, yes
is java 8 peak java
Only reason I ever regret not using J8 is because itās what everyone has 
Basically; the java website only has J8
So if you want to use a newer version, you have to download a JDK from elsewhere
Yes, but that doesnāt install as a default java to run jars with
Yes, but that doesnāt install as a default java to run jars with
oh really? 
looks like because it went GPL?
The newer JDKs are faster due to JIT optimizations and easier to write code with due to newer syntax features and methods which exist to reduce boilerplate
I am asking the ai
idk seems like it's mostly that java 8 is just the version everyone has I guess
just as you said
According to reddit
Until Jdk9, the developers of java didnāt want people to redistribute the JDK, and this mindset changed with J9
this all gives me the impression that java is kind of at a deadend, time to switch to something modern like Mono or Perl 6
I mean
Code wise Javaās got more potential now than it ever did before
Also got more active development in the JDK than ever before
what's a new feature you're excited about in java
Theyāve been working on redoing native interface is the big thing theyāre working on
Project Panama
I have⦠mixed opinions on it
I donāt really keep track of whatās upcoming, nor am I sure if thatās a thing Iām able to do?
But the new syntax features are indeed quite nice
new zig nightly doesn't let me do this any more :(
not sure what to name these props now
config2 and scene2 wdyt
config_prop
config_
config_123
those are quite the variable names to reserve
they're not reserved
it's that I can't use them as props because they're imported
I can rename either one
oh game config like right now just screen settings
well they're both the same thing one is an instance of the other
so it's like having a function parameter called x setting an x prop on a struct inside the function
hrm
no that's allowed
src\foundations\app.zig:1:1: error: duplicate struct member name 'scenes'
scenes: *scenes,
const scenes = @import("scenes/scenes.zig");
I import this at the bottom
Chapter 10 of game math is like 120 some pages
it's gonna take a while :<
it's basically a summary of an entire book on rendering
it's a good intro because that's what's next
I just have to power through it
I've never read so much in my life as I have in the last few months tbh
you can tell when I started getting into graphics programming and zig
half way through chapter 10, with notes, covered the phong and other basic lighting models
I have finished Chapter 10!
Of game math (gamemath.com)
it is a massive chapter
I actually really enjoyed it
I learned so much, and because of how old this book is, I got a little bit nostalgia and I felt like I was really learning about how to build a game
like I didn't know anything about lighting at all before this chapter, never once read about phong or blinn or doom style volumetric lighting
the amount of detail it went into the render pipeline and graphics pipeline, even though it is a bit dated, was really cool and I learend a lot
a 150 pages that covered like all of rendering at a very high level and ended with some HSLS examples of how to do bitmapping and skinning and lighting
I also really liked that it kind of broke down how games are built, at least how the rendering is built
like what is done where and when
I am actually done with math books for a while. I am going to read three chapters of Game Engine Architecture and then just plow through my OpenGL book, Computer Graphics Programming in OpenGL with C++
3rd Edition, https://athena.ecs.csus.edu/~gordonvs/textC3E.html
because I'm actually like kinda more limited by lack of OpenGL knowledge than anything else before I get into advanced math I can't use because I don't know how to add attachments and whatever
I emailed the publisher for the files for that book, I will actually build all of the examples in my engine
Nice
Time to whip up some gameplay
It will require you to expand your GL knowledge pretty quickly
nice, that would be fun
yeah everything I read from here on out should lead to some cool rendering I hope, out of the kiddie pool now
Nice progress!
Most of the lighting stuff is decades old knowledge anyways, so it might be less outdated than you think
I have finished and implemented in-engine the first 8 chapters
And the viewing transform part of Chapter 10
I think the book is solid from an education point of view
Our curriculum's are similar š I'm also reading Game Engine Architecture on the side. Though for OpenGL I use LOGL. Once my current term ends in this curriculum, I'll pick up Real Time Rendering I think.
Nice, itāll take a bit before I get to real time rendering
I want to finish all the math books first
I am about halfway through most of them now
So probably at this rate maybe next year
idk
I want to read the books I bought they arenāt there to just look pretty
To this day
I still know nothing about phong and blinn
Iāve yet to really have a reason to read about those tbh
Itās trivial
Itās super basic
Itās cool how basic it is and how well it works
Solid mentality
You'll be a force of nature next year
Though a little overpowered math-wise
Me personally
Nah
I tend to forget math topics if I don't apply them frequently
Everyone is like that mostly I think
You donāt need lighting or because you use godot?
Your godot project looked really cool
Iāve always just sorta made my own shading model when I wanted to do lighting stuff outside godot
Physical accuracy isnāt really something I desire, I like my stuff being stylized
Makes sense
In my opinion
Realistic rendering is best for horror games, because it makes it a lot easier to get immersed in it
Beyond that, I donāt generally care much for realism in games, and generally see it being more performance intensive or more file size than itās worth
I like cool lighting, like a cyberpunk scene in which all the neon and digital lights refract and reflect all over and every other thing is itself emissive
This is part of why I like to minimax my understanding
A lot can be done with math using a minimal understanding
I just write notes
Thereās not all that many games that actually do that though
also Iāve never actually seen cyberpunk
Oh shoot
I just discovered something neat about discord mobile
The Ascent is a small indie cyberpunk game that has cool lighting
You can tap on the top of the screen to jump to the top of the forums posts
So I can just immediately jump to #1248864886772072591 message
Thatās neat
Yea itās also cool if you design your game around it I guess
Actually
A neat mechanic Iāve only seen once or twice
Having stuff react to light
Like
In gameplay
You shine a light on an object and it acts as a trigger
Not just a visual thing
That is cool
Thereās a game with a combat system essentially built around that 
Metro games do that
I have never heard of metro
Some of the creatures hide from light and avoid coming near you
One I was thinking of is alan wake
Metro (Russian: ŠŠµŃŃŠ¾), (Ukrainian: ŠŠµŃŃŠ¾) is a post-apocalyptic fiction franchise consisting primarily of novels and video games that began with the 2005 release of Russian writer Dmitry Glukhovsky's novel Metro 2033. It was followed by his sequels Metro 2034 and Metro 2035, as well as by many other books by different authors, including Tullio ...
I only played 2035 it was great
For alan wake
Enemies can have these, essentially shields
Which much be removed by shining a flash light on them
The one from 2021
Iirc the flashlight can also act as a weapon on its own
The Ascent
seems to be some sort of transistor clone but without pixelart bs?
not transistor, the other game with H
Hades?
yes!
i want something like that for my scifi shit too, instead of the dude, have my ship hover in ze hangar while you look at things š
The Ascent is real fun
Gameās name: Hades
Deccerās memory: transistor
Can play it fully in half a day I think
They added content
Since I played it
Itās like original the Fallout games
Very story based and character driven
Honestly
I should probably actually do a project where I go through and make a bunch of test scenes for sake of generalizing my engine
https://www.youtube.com/watch?v=LyjnQDYee4o its the same shit
Discover the world of Transistor, a sci-fi-themed action RPG from the creators of Bastion.
http://store.steampowered.com/app/237930/
No BULLSHIT! Just Gameplay Subscribe NOW! http://goo.gl/WmU16n
Enjoyed the video? Like and Subscribe for more
PC Specs:
-Intel Core 4770 @ 3.40 Ghz
-Corsair 16GB Vengeance DDR3 1600Mhz RAM
-MSI GTX 760 OC
- ...
same studio too iirc
Also
Iām trying to do a software raytracer in MC
⦠need to figure out how to build a BVH for anywhere from 0 to⦠I think it was 500k triangles entirely on the GPU
every single reference Iāve found of BVH construction is on a light theme website, for C++, on a single thread, and does not assume a fixed memory layout like GLSL has
I also cannot preallocate large blocks of data, as that makes switching to the shader take a while (iirc, ~15ms or smth; more than I have leeway for)
literally writing the number 4 can cripple performance with this due to that
I saw your ray tracing recently looks impressive
That was hardware raytracing with vulkanite
that could not have been much more simple to write
If I can get this shader to perform well I will probably put it on github as a minimal software rt shader type of thing 
#ifdef FALSE
void main()
#endif
{
int att = 0;
uint oldBits = DATA;
float oldFloat = uintBitsToFloat(oldBits);
do {
uint newBits = floatBitsToUint(OP(oldFloat, VALUE));
uint prevBits = atomicCompSwap(minX, oldBits, newBits);
if (prevBits == oldBits) {
// Swap was successful
DATA = newBits;
break;
} else {
// Swap failed due to concurrent modification, try again
oldBits = prevBits;
oldFloat = uintBitsToFloat(oldBits);
}
att++;
// 500 for safety reasons
// should never hit this point, but maybe
} while (att < 500);
}
```cursed atomics
The function returns the original content of mem regardless of the outcome of the comparison.
I'm not sure if (prevBits == oldBits) is valid
isn't that always true
or that means the previous swap, but not this one worked
idk
this feels terrible
If the content of mem is equal to compare, then the content of data is written into mem, otherwise the content of mem is unmodifed. The function returns the original content of mem regardless of the outcome of the comparison.
I see
prevBits == oldBits means it wrote newBits
well
basically
I'm trying to make sure it's written to and also wasn't overwritten by another thread
now the thing is
I feel that should be checking prevBits == newBits
you can't know that
at the time of comparison it may get overwritten
idk
don't you have to get the context each thread
well
it sure seems to be working 
ok it is an atomic compare
this is GLSL
yes
oh I am dumb
if (prevBits == oldBits) {
// Swap was successful
DATA = newBits;
this though
this can be wrong without a lock or something?
because now you're comparing without atomic
yes
seems to reliably converge after 2 iterations, so 500 should be more than good as a safety 
why 500?
arbitrary value
computing the bounds of a box that encloses the entire scene
why do you have to compute the bounds of your scene? is it generated?
you're doing this for light sources from outside the view frustum?
I'm doing this because I'm going to get approximately -1000 fps if I don't have a bvh, and I need to know the size of the root node in order to be able to start subdividing the BVH
idk what I'm saying tbh
can't you just create an arbitrary box and see how it behaves
I could
or I could use 16 threads to essentially instantly compute the bounds that perfectly enclose all of the triangles in the scene; no more no less
I don't know anything about bvh or ray tracing
I know minimal, lol
are you using stb_include
whatever iris does
glsl hates that
I can see that my code is doing stuff based upon the values
can't tell if it's actually right or not but
also why is it flickering sometimes
maybe my triangle bin is full?
can't tell
ok setting it to 1 thread tells me that either these cursed atomics do not work, or my loop is wrong
:P
After this current chapter in GAE I'm going to read a chapter about parallelism and concurrency, maybe after I can say things that are helpful, although this is all GLSL and not application side
That chapter is fire
This my current stack of books, doesnāt include game math obviously since itās digital
That's a fortune in my country
I have Game Programming Patterns & Mathmetaic for 3D Game ... in my library as well
I did also just order The Modern Vulkan Cookbook also
I had some of these books, just sitting around for a couple of years
Lovely collection, drooling just looking at it š
well I have to read them
I mean
to me it's a bunch of pending work
or work in progress
Is it fun?
I was gonna reply with "then all the more reason to do it" to cheer you up, provided you responded with "yes" lol
"Sometimes" works as well though
It's kind of like a roller coaster
it's like exercising, I just do it because it helps me reach my goals
Motivation does not grow on trees
I don't have motivation, I have goals
motivation is temporary, a routine is daily
šÆ % true
That's why I'm still not where I wanted to be perhaps
But I'm getting there
where are you from?
if you don't mind me asking, just curious since you brought it up
Turkey
I personally don't like Ankara that much tbh, worst drivers on the planet for some unknown reason, and the weather is too dry for my crumbling retina (I have severe eye dryness)
I have no control over application side for what I'm doing
everything has to be done in GLSL 
time to let go of minecraft?
no
you need an intervention
I'm using a premade mod to implement this into
how are the trains?
Because Iām sorta trying to challenge myself
I just visited relatives from time to time so I'm not sure
The one going from/to İstanbul is good though, the "speed train"
People have already made raytraced shaders with this
The Lengyel book is so great, it's basically all the math
that you need
it's just not really explained conceptually
but you would know when you need it
what it is for
it's like the ideal math reference I think
what's the math for this problem? it will have an answer
float ov = x
if ov < v break
float nv = min(ov, v)
pv = atomicCompSwap(x, ov, nv)
if x<=nv break```
I think this is probably what I want
Funny story: that Lengyel math book is printed reverse. It is perfectly usable, provided you flip it 180 degrees on your x axis (direction to your right).
I asked Amazon to take this back and send me a new copy, they countered with "keep the book & we'll refund your money". So it is free š
your real time rendering is digital?
How did that occur 
Yeah it is thorough I think, I read a small portion of it yeeears ago. But I remember it being good.
gamemath.com is more intuitive in my opinion. More beginner friendly.
No idea š Additional photos incoming wait
I don't like digital books
It is surreal
but I have to with gamemath
As in I don't have it yet
oh I see
The WORST part is that there IS a glsl extension that does exactly what I need but I canāt use it 
only good about digital is you can search them
I was like that too but I don't know reading from a tablet, laying down on a couch is good too
true
For example I'm reading a digital copy of GAE on the tablet
also lighter to carry around
even though I have a physical copy
I just don't like reading on a screen
decided to abandon the cursed atomics and just do two shaders 
Not 100% convinced itās working though, turning down the invocation count causes it to break
what is it
These colors represent the bounds I need for my BVHās root node
⦠not sure if theyāre actually correct, gonna have to validate that tomorrow
hey
I kinda assumed it from this, lol
also from turkey š
@delicate delta andrew left discord and the zig server behind? do you know why?
#785499283368706060 message
he's still active until end of september
I also dislike the quests
but like
I'm not going to start using IRC
I haven't used IRC in like 10 years
all the clients are unmaintained and it is not great for sharing media and such
idk I don't really talk to him much anyway
I don't go into the dev channels, they are serious in there
like you say the wrong thing while they're trying to get work done it's a ban
its quite funny
i am thinking of leaving discord too
and find a new place where you just hang with your friends
no kids homework solving bs like we have in #opengl or #questions all day
just bikeshedding your frog's projects
We need the elite gp inner circle private element chat or something
where it's mostly just project threads
general discussion can still take place here
yeah
but basically a new server
where those peasant channels dont exist which keep teasing you to take a look
yep something selfhosted perhapsly
I just wish there were some better solution for user uploaded data
yea
There needs to be an "upload manager" system like old forums used to have, where when you upload files it goes into a little personal cloud storage drive with a fixed size
Then it's up to the user to manage their data
If they are running out of space they can delete old files or reduce the resolution of old images
then it puts the data management in the hands of each user and makes the storage scaling on the server vastly more predictable
Also gives an easy way to look back at your pictures so I don't have to search from:the_Demongod has:file every damn time
and click through their slow pages
a background job could replace all the images by low quality ones for posts which are older than 90d or so
and if you click on it to enlarge and the user still has it in their store you get the original pic or something
small thumbnails could be stored globally somewhere, so that you dont lose pics from old messages
Yeah
yeah. I don't get purpose of it. imho, it just creates burden for anyone that wants to occasionally chat/follow up
like, discord search for example, I use it extensively to figure lots of random stuff. and sometimes I stumbled upon zig std channels, read some random interesting stuff
yeah I learn a lot from being on the servers
have been sitting on the zig irc channel on libre via the web client, it's super dead
yeah kids these days dont want irc anymore, i dont blame them
idk if andrew can really stay off of discord
I have never used an IRC client
ohh
he did leave discord today
he didn't wait a month
and he's not on irc he's on zulip
yeah
that platform which uses "leadership" in every other word on their website š
ok I'll try zulip I guess
oh just work channels
doesn't seem like a community chat
I know rust compiler and stuff related uses it successfully
wish it was possible to move existing zig discord conversations to that without hassle, that would be awesome
Having lurked on Zulip for a day, I think itās pretty great actually
i sink i have to ackchually check this out too
yeah
GAE's third chapter has the best explainer for alignment I've ever read
it's super, it's like two pages and just fully explains it in clear and simple terms whereas everything else seems to have struggled
i find GEA quite bad in general
its how one would write engines 15 or 20 years ago
not sure why so many praise that book so much
can't speak to that but the parts I've read so far have been very good, I'm still in the first section of the book
perhaps im biased somehow
because its heavily OGRE influenced, and ogre was shit back then
honestly it kind of comes across as a how to pass a technical interview at a game studio more kinda book
yeah
you wouldnt waste your time reading it
it helps to understand concepts in general and thats more important than knowing what assembly you have to use to implement SSAO for a specific gaming platform or soemthing like that
This shows yeah
I treat GAE as a general-knowledge kind of book
I think maybe the more recent edition might have reduced ogre, I see some of it
Showing the big picture that is a game engine
Lots of better books on specific topics of course but as a general surface-level book I think GAE is not bad
I think it's more like a great intro for junior engineers at game studios or something more than a how to build your own
Yeah
or as I said for how to prepare for an interview
right GEA :P
everyone on the server keeps saying GAE š
I'm only saying it because Bjorn said it first
why do you think gea can be bad?
its only a high level overview but its a pretty decent book to get started with
i dont remember any sort of ogre influence on it š¤
OGRE was truly awful even at its time
and i think first edition of GEA is older than ogre
I think maybe older versions of the book had more about OGRE
it has appeared a little bit so far, but I'm only chapter 3
that's the math chapter yeah
that's the parallelism chapter in my issue


)