#Foundations - Learning Graphics Programming with the Zig Programming language

1 messages · Page 4 of 1

delicate delta
#

in mine

#

that's the foundation section of the book

#

resources is in the next section

#

I have the older edition in digital format, I never read it though

maiden gazelle
#

Chapter 7

delicate delta
#

ah yeah you're way ahead

maiden gazelle
#

I have 3rd ed

delicate delta
#

oh same as me then

#

your cover looked different

maiden gazelle
#

No my physical copy is 1st edition

delicate delta
#

oh

maiden gazelle
#

Digital is 3rd ed

#

Skipped chapter 5 as the book is mostly an overview book

delicate delta
#

the 3rd chapter is taking me a bit, I read every section, then come back and reread and write notes

fleet dew
#

all this talk reminds me that I should read real time rendering

delicate delta
#

I don't do any of the problems in the books though, I build scenes that do the things the books go over

#

some of I am not doing as I want to make progress

#

like plane intersection I didn't do

#

I haven't done any lighting yet either, I need to through the opengl book for that as I'm stuck on using opengl honestly, that's next after I get through chapter 3, 4 and 5 of GEA

#

I'm reading all the math review chapters too

#

just because I need it

maiden gazelle
#

So skipping those in GEA makes sense I think

ivory verge
#

thats catppuccin neh?

#

or kamigawa?

delicate delta
#

I don't know

#

I switched to a high contrast light theme everywhere except on that laptop

ivory verge
#

ah

#

that purply color looks like it

ivory verge
#

im trying to install zulip server

#

and i am not impressed at all

delicate delta
#

yeah I looked at it today actually

#

I'm not going to use it

ivory verge
#

it installs EVERYTHING there is on the planet

#

yeah

delicate delta
#

it really doesn't have anything to do with zig?

ivory verge
#

yep 0

delicate delta
#

it's just like Loris's personal project

ivory verge
#

but it might install zig as a dependency

delicate delta
#

I went to the conference in Milan this year and it wasn't really about zig either, only most of the attendees were all zig devs and it was fun to meet them all, andrew mlugg a bunch of them

#

but like one talk out of 3 days of talks were about zig, the workshops were zig

#

the sycl conference which is Loris's

#

I don't know

ivory verge
#

sycl is such a misleading term

delicate delta
#

I just am there for the zig

#

not for any of this other stuff

ivory verge
#

yeah

#

like i am here just to see what other people make and how cool their shit is 🙂

#

i wanted to write a message based chat platform since forever, i might actually write one this year

delicate delta
#

what would you write it in

ivory verge
#

c# most likely

delicate delta
#

nice

#

the stackoverflow tech stack?

ivory verge
#

but it would just be an api and some websocket bs so that anyone could make a client in any language

ivory verge
#

you can aim much lower, and not support 100mio concurrent users, but just 200 or so

#

lets see 🙂

#

or i just go back to irc and click on links to see the image 😄

delicate delta
#

I'm not going back to irc

#

:P

ivory verge
#

: )

#

deccerNet xD

queen hinge
#

Granted I also didn’t have anything being saved to disk

ivory verge
#

yeah it should be somewhat trivial

#

doesnt even have to be 1000% realtime

queen hinge
#

11k was what happened to be the amount it was able to deal with before connections started timing out iirc

#

Like socket time out I think it was, not timeout implemented by me

queen hinge
#

KEKW was a while ago, I don’t remember exactly

delicate delta
#

On just a single server?

queen hinge
#

Just my desktop computer

delicate delta
#

What were those 11k connections doing?

queen hinge
#

Chillin

#

Sending keep alives every now and then I think

#

maybe it was 1.1k

delicate delta
#

Why did a football stadium worth of people join your desktop server?

queen hinge
#

They were all my own desktop KEKW

delicate delta
#

I see

queen hinge
#

Basically, I wrote a program to just spawn a bajillion dummy client connections to see how many I could handle

delicate delta
#

TCP?

queen hinge
#

Whatever java websockets do KEKW

delicate delta
#

Oh web socket

queen hinge
#

Probably TCP behind the scenes somewhere

#

Oh not websocket just socket

#

bleakekw why are those two terms so similar

#

I mean
They are similar things but like

#

One’s general, one’s for websites

#

Websockets aren’t a part of java api

#

robber_fly: swift predatory fly having a strong body like a bee with the proboscis hardened for sucking juices of other insects captured on the wing
robber_fly: swift predatory fly having a strong body like a bee with the proboscis hardened for sucking juices of other insects captured on the wing
tensor(0.0339, device='cuda:0', grad_fn=<NllLossBackward0>)
Also adventures in AI
My AI can recite dictionary definitions

#

Related note
TIL I learned that hugger-mugger is an actual word in dictionaries KEKW

delicate delta
#

Is it verbatim

queen hinge
# delicate delta Is it verbatim

Of those two
Top is dictionary, bottom is AI

It does learn verbatim, because well, that’s kinda how AIs often are, especially if there’s not a lot of variety to the dataset

queen hinge
delicate delta
#

idk what that is

#

even after looking it up I don't know what it means

#

a hugger-mugger presentation of the facts of the case that left everyone confused
a tale of hugger-mugger doings and international espionage

#

the definition of hugger-mugger is a bit of a hugger-mugger

queen hinge
#

its definition is a state of confusion and the word leaves people in a state of confusion

delicate delta
#

if you said it to the wrong person they may challenge you to a duel

queen hinge
#

lol

#

optimizer: refating of near theptputscdchnr georgair bual sfnpor the rig ers of the amsica coronisers(1727-17rndt follraofwo thoserneinpes os ahp aupl thelfbclan anogrti enoliaid analartomethe pndpereoraora tnelthelipandlipatndlphelandlrahd theloeanelopand tndlopasend porlhaa and eartraane tagar andlitnemand iala tarlonasand phu anoloane phepopases and porliaa and cuugras andlianeaoanu ialerthelonasand slupieand ece ialahclopnand phuliaa and eoriraerandliprnelr phd ial andloandrparaoeneand tor ancland porlian and phuedialerand eadiing plrlialeranolacurthepoendand the i
KEKW what happens when my model tries to actually predict a definition

#

OH
My model's only 6.5M parameters currently KEKW
that is smol

queen hinge
#

AI status update...
this is a single entry in my dataset that I'm hand typing

delicate delta
#

:/

delicate delta
#

I didn't expect AI to have emotions

ivory verge
#

each client would connect to the ftp, check the last file date, and if its newer than last time, would pull the txt file, show the content in some textbox, and when i entered a message hit send, it would upload the whole stuff again 😛 with my text appended

delicate delta
#

I wrote an IRC client once and lots of IRC bots. An IRC bot used to be my default first project for a new programming language. I spent a long time on that IRC client it was pretty good.

ivory verge
#

hehe yea, everyone joining irc did and does : )

#

like kids write discord bots these days hehe

delicate delta
#

I also worked on the imgur mobile web site web sockets nodejs backend, so probably most of the people who were on the internet 10 years ago and saw a cat gif connected with code I wrote :P

ivory verge
#

i have never used any mobile website though, but i appreciate it that you did work on it 🙂

#

besides mobile banking

delicate delta
#

You haven’t open a browser on a phone ? 🤔

#

Just your bank?

#

You clicked links in reddit? cutecatNE

#

Well probably for the best

ivory verge
#

i dont do reddit

#

i have an account but i never use it really

#

and pc masterrace, im not a fan of mobile/web/console platforms

delicate delta
#

Nice, me neither, now anyway

#

Use reddit that is

ivory verge
#

yeah

#

i understood it 🙂

delicate delta
#

Reddit is evidence that the internet was a mistake

ivory verge
#

not just reddit

maiden gazelle
#

And I thought I was getting old

#

Listening to you two gave me hope :p

ivory verge
#

hehe

queen hinge
delicate delta
#

btw I haven't updated with any foundation updates because I've just been reading

#

I got about 4 more chapters to go before I'm back to rendering anything

#

I'm about 30 pages into chapter 4 of GEA and it's a 160 page chapter, then I'll read the math chapter and the math chapter in my opengl book and then I'm probably going to be rendering quite a bit, I want to iterate between chapters that I'll build things with and GEA though so I can get through that book as part of my goal for the first set of books that I initially started with

ivory verge
#

looking forward to what comes out of this this time : >

#

the vector/plane visualization🇮🇸🇲🇸 last time were super cool already

delicate delta
#

thanks, even though it doesn't lead to any rendering I've already learned so much from GEA that I'm doing wrong just with my zig code, I haven't thought about alignment at all or cache performance and if I want this to be a good engine I'll have to consider it, so I am glad I'm reading that book

ivory verge
#

: )

queen hinge
#

Lemme just say
Alignment and cache performance are not explicitly required for good performance

#

Just having a good data structure in the first place goes a long way

#

And also skipping over useless calculations

#

I.e. the player’s hitbox already contains some block
There’s no reason to handle that block when checking for collisions for motion, since the player isn’t going to properly collide with that block anyway

delicate delta
#

makes sense

queen hinge
#

Iteration order can also be important
Sometimes it’s objectively better to go xzy instead of xyz
Ex, Minecraft; you can grab the chunk instance on the z of the xzy loop and use that single chunk grab for the entirety of the y loop
Can’t do that with xyz

delicate delta
#

The Graphics Programming With C++ book publisher sent me the companion files froge_love

#

Mode  Size (KB) LastWriteTime       Name
----  --------- -------------       ----
la---      1214 2024-09-07 12:57:08 grid.obj
la---         2 2024-09-07 12:57:08 icosahedron.obj
la---         1 2024-09-07 12:57:08 pyr.obj
la---         0 2024-09-07 12:57:08 pyrSimple.obj

obj files :P

#

all obj

#

cool though

#

neat

ivory verge
#

holy shit

#

havent seen any Corel software in decades

delicate delta
#

yeah I like it

#

pretty good and doesn't cost any where near as much as adobe stuff

#

good enough for me

#

better than gimp by a mile

delicate delta
#

I was looking at other formats besides gltf, like USD and FBX and I think I'll just stick with gltf

#

and I guess obj files since I have some

#

tinyobject-c and fastgltf I think is what I'll go with

#

if I get that to work easy enough with zig which I expect to

#

unless there's something non ABI compliant about the types

ivory verge
#

usd seems like the jpeg2000 of fbx

#

they turned that format into a weird collection of things, nothing straight forward, like gltf where you just look at the spec and find what you need to know

#

instead usd seems to be a collection of 20 things with weird ass names again where each stands for some facet of the universe usd supports

delicate delta
#

the sdk for fbx is kind of intimidating

#

from a zig perspective anyway

#

if I was just writing C++ and using visual studio it wouldn't be a problem

ivory verge
#

hehe

#

there is ufbx

#

from nem0 iirc

delicate delta
#

I think gltf does everything I want for now though

ivory verge
#

yeah i think its more than enough

delicate delta
#

USD doesn't seem like it's intended use is real time rendering

#

although it can be used for that

ivory verge
#

my understanding its more like a transport format for inbetween all sorts of software in the industy

#

something like collada tried to be 20 years ago

delicate delta
#

oh shit, maybe I can't use these assets from the book in my open source project

ivory verge
delicate delta
#

I think maybe I create a branch I don't push to my repo for now

#

for just the assets idk

#

I'm not going to push anything copyrighted to it

delicate delta
#

oh I'll just put them into the application data folder I already have

#

and show an error if that scene is loaded with those files I guess

#

what I should do actually is just create a generic viewer

#

and it can load any of these things based on what's in that folder

#

and just shows an empty list if nothing is in there

#

idk

wild ember
#

they are all extremely high poly

delicate delta
#

these 150+ page chapters are so exhausting

#

even if I am learning

#

I thought this diagram was unintentionally funny

#

if you were looking for a way to get your multi-threaded concurrency to operate as fast as a single thread using a mutex will do it for you

delicate delta
#

based on my current progress I think I'll be rendering again by next weekend

#

if work doesn't end up taking up my evenings

#

#1248864886772072591 message last time I did any rendering was 2 weeks ago, so 3 weeks of reading 😅

#

this should probably be the last time there's so much reading without rendering as I had these GEA big chapters on hold until I got through the basic math through projections, it's like all rendering from here on out, with some physics and animations somewhere along the way, but the big meaty render-free chapters will all be behind me

#

well two of the last three chapters in game math are purely physics and they're big chapters, but that's a while from now

delicate delta
#

Ya‘ll GEA is really transparent about who this book‘s intended audience is and it’s not individual devs building their own engine

#

A hundred or more developers plus a QA team is a minimum requirement for the book to be applicable

wise imp
#

btw that atomic-fence assert thingy is very useful

#

but using volatile in 2024 is absurd

#

use atomic but use relaxed mode which is basically the same as a volatile load

delicate delta
#

yes

#

makes sense

delicate delta
#

but I'll do it

#

I might actually do it in C++ though because you use the bootstrap stuff, or partially in C++

wise imp
#

for multithreading if you are interested just go grab taskflow

delicate delta
wise imp
#

just make absolutely sure you quarantine the fuck out of it into a pimpl or similar with a wrapper

#

taskflow oblierates compile times on anything that includes it directly

delicate delta
#

oh ok

wise imp
#

my wrapper just does this

delicate delta
#

I see

#

does this obstruct?

wise imp
#

what do you mean obstruct

delicate delta
#

does work ever wait to be done

wise imp
#

the parallel for does, the other doesnt

#

see the future.wait() on the parallel for, while the other has nothing

delicate delta
#

oh I see

#

I meant more does it block waiting for work to start

#

as in waiting for other threads to finish

#

I see a count but it's not clear to me how it's used

#

it looks it just returns without doing the work

#

oh you're scheduling multiple workers there

wise imp
#

up to 4 workers

#

its a very simple atomic style parallel for

#

it launches 4 workers, then each worker does atomic add to grab what index they are going to execute

#

taskflow has its own parallel for, but you cant control how many workers it launches

elder kettle
#

FYI bjorn you can multithread GL rendering just fine you just need to use persistently mapped indirect draw buffers and a bit of extra structure to manage what's being recorded

#

It's not like Vulkan where you can write commands to switch pipelines and vertex buffers and stuff but the draw calls themselves (assuming the state setup is handled elsewhere) work fine

#

So it won't be as generic as Vulkan threading but if you have several systems that have a large specialized workload like CPU particle systems or foliage instancing or whatever you can easily fill the data/draw buffers on a thread

#

And then at the final render step you pull up each system, use its internal state to bind whatever input data it needs, and then dispatch your indirect draw buffers

delicate delta
#

Ah I tried something like with blockens but hadn’t gotten to indirect

wise imp
#

i wouldnt recomend it

#

for gl what works great is a custom RHI command system

#

kinda like how unreal works, you have a thread whose sole thing is to do ogl api commands

#

the rest of the threads build a command buffer and throw it into that api thread

#

as a bonus if you have that sort of thing you can also use it with vulkan and others

elder kettle
#

I don't have an RHI at all I use GL directly

wise imp
#

thing is that if you are going full indirect your cpu cost goes so fast you dont even really need to MT it

#

my current block engine is fully ST on the renderer

elder kettle
#

Mine isn't full indirect since there are a lot of things I need to do on the CPU but it's still fairly indirect

#

Like my foliage system still has a lot of CPU labor to fill draw buffers but since it just fills data and indirect buffers (double buffered too) it could trivially be moved to a thread

#

I am running it single threaded too but I'm just extrapolating

#

Or if you're going to just do CPU frustum culling or something

#

But yeah it's true if you rolled your own command system then you could multithread the actual swapping of pipelines and stuff as well

delicate delta
#

I'm a bit of a ways away from this probably being anything I will have to tackle, I think once I get to building a game it will be small levels with low mesh counts to start with, but I am trying to build out a broad foundation of understanding so I recognize problems and understand things people are talking about on this server

delicate delta
#

I finished Chapter 5 of GEA

#

I read straight from Chapter 2 to 5, 350+ pages and took comprehensive notes

#

I am over it lol

#

Chapter 5, a basic game math overview, was very good. I think it's very much worth reading. I really liked reading about the math from someone who is not a mathematician but actually creates games, shipped The Last of Us 2 and Uncharted, and Medal of Honor. I get a sense of what's important. I also found his short explanations and definitions way better than the math heavy explanations from my math books and I liked his description of how he's used some of the math in games.

#

I am basically going to focus on https://athena.ecs.csus.edu/~gordonvs/textC3E.html now and get through OpenGL stuff and actually render. I might switch back to GEA every couple of chapters so I can make a little bit of progress on it a bit at a time and not do another 300+ pages of it

#

I'm going to get back to my math books after C3E, it's all just rendering from here on with physics at the end

delicate delta
#

Actually

#

I realized something today from reading chapter 5, my matrix rotations are incorrect for a left handed coordinate system

#

If I stick my thumb out and curl my left hand, my fingers rotate clockwise

#

my rotations are all righthanded!

#
 pub inline fn rotationY(angle: f32) matrix {
     return mc(.{
-        @cos(angle),  0, @sin(angle), 0,
-        0,            1, 0,           0,
-        -@sin(angle), 0, @cos(angle), 0,
-        0,            0, 0,           1,
+        @cos(angle), 0, -@sin(angle), 0,
+        0,           1, 0,            0,
+        @sin(angle), 0, @cos(angle),  0,
+        0,           0, 0,            1,
     });
 }
#

fixed

#

None of my other books explicitly said it, but GEA did

#

they did point it out when talking about the cross product but my brain never connected it to the rotation matrices when I wrote them

#

like this would still be wrong if I had skipped this chapter or hadn't read this book, this is why I'm reading

ivory verge
delicate delta
#

hrm

ivory verge
#

im not trying to make fun of you

delicate delta
#

but my rotation around the y should be reflected across the diagonal?

#

pub inline fn rotationX(angle: f32) matrix {
    return mc(.{
        1, 0,           0,            0,
        0, @cos(angle), -@sin(angle), 0,
        0, @sin(angle), @cos(angle),  0,
        0, 0,           0,            1,
    });
}

pub inline fn rotationY(angle: f32) matrix {
    return mc(.{
        @cos(angle), 0, -@sin(angle), 0,
        0,           1, 0,            0,
        @sin(angle), 0, @cos(angle),  0,
        0,           0, 0,            1,
    });
}

pub inline fn rotationZ(angle: f32) matrix {
    return mc(.{
        @cos(angle), -@sin(angle), 0, 0,
        @sin(angle), @cos(angle),  0, 0,
        0,           0,            1, 0,
        0,           0,            0, 1,
    });
}
#

is that just for right handed systems?

delicate delta
#

they all rotate clockwise now when looking from positive into negative

#

which, making a hand gesture is correct

ivory verge
#

hmm rotationy looks different

#

i thought the sign is flipped for the two sin()

#
pub inline fn rotationY(angle: f32) matrix {
    return mc(.{
        @cos(angle),  0, @sin(angle), 0,
        0,            1, 0,           0,
        -@sin(angle), 0, @cos(angle), 0,
        0,            0, 0,           1,
    });
}
delicate delta
#

but this is correct given the left hand rule

#

you can see I move the y positive

#

then looking from the positive into my thumb

#

the thing rotates the same direction as my fingers

#

so I think the matrix is correct

#

and that's how all the other axis rotate

#

is the Y supposed to rotate opposite the other axis?

ivory verge
#

what is your world up here +X Up?

delicate delta
#

yes

#

see, x up, rotates clockwise

ivory verge
#

it looks correct though

delicate delta
#

so if this were right handed it would be reflected

#

but because my coordinate system is cursed it's not

#

I want to hire a math professor to evaluate my zig math

ivory verge
#

hmm what if you flip the two sins?

delicate delta
#

it rotates the wrong way

#

Claude says this is correct for a right handed coordinate system

ivory verge
#

i dont trust LLMs

queen hinge
#

Discord is a flawless piece of software with absolutely no bugs or glitches whatsoever

queen hinge
delicate delta
#

hrm

#

this is bullshit

queen hinge
#

What does claude say if you ask it to design an LLM architecture?

delicate delta
#

as I have a left handed coordinate system

ivory verge
queen hinge
#

KEKW that embed

delicate delta
#

ok well everything is rotating around correctly with my matrices that I pasted above

#

so I'm keeping them

#

also, when you flip the coordinate systems you flip one of the axis right

#

so this makes sense I think

#

if my translations are correct and my rotations are correct and I don't have two left hands then this is correct

ivory verge
#

perhaps add some conversion matrices

delicate delta
#

I will once I import from gltf and obj

#

I will have to

ivory verge
#

so that you can easily convert from XUpRH to YUpLH or something

delicate delta
#

so much stuff breaks if I do that though

ivory verge
#

unit tests : >

delicate delta
#

no no the math breaks

#

my projection will break, my frustum extraction breaks

#

actually no my projection is fine

ivory verge
#

so your code breaks, not the maffematics : >

delicate delta
#

because I convert to Y up prior to projecting

#

no

#

the math is different

#

I would have to write both right handed and left handed math

ivory verge
#

you are extracting planes always the same way, no matter how the frustum is oriented

#

that shouldnt break

delicate delta
#

when I extract the planes from the frustum the frustum is Y up

#

but my coordinate system is X up

#

so I have to convert them back

ivory verge
#

as long as all operations happen in the same coordinate space its fine, and then you just convert to/from if needed

delicate delta
#

plane extraction is not happening in the same coordinate system it's in clip space

#

I take the extracted planes and transform it by my full MVP matrix

#

then it works

#

they're antivectors

#

the planes

queen hinge
delicate delta
#

each one of my math books has a completely different coordinate system and the projection matrices they all use are different

ivory verge
#

😄

delicate delta
#

it's a right handed coordinate system

#

it goes counterclockwise when looking in the direction from positive

#

so I'm doing it right

#

so unity is left handed

#

I think something is wrong in my math

delicate delta
#

I'm sorry I wasted time on this but everything is behaving correctly even though my matrices don't look anything like anyone elses

#

☑️ my GL winding order is clockwise
☑️ my matrix rotations rotate clockwise when angle is increased across all 3 axes
☑️ my quaternions rotate clockwise for positive angle changes across their rotation axis
☑️ my positive x translate goes up, my positive y translate goes into the screen, my positive z translate goes right

#

things that are weird:
my coordinate system transform doesn't have a reflection ?
my extracted frustum plane normals require negating the normal to work?
my extracted frustum planes require a transposed perspective matrix to extract?
my y rotation matrix negative sin is not reflected across the diagonal compared to x and z rotation?

elder kettle
#

Tfw you choose an exotic coordinate system and have to suffer the strange consequences of it 😭

delicate delta
elder kettle
#

(just teasing)

#

I honestly couldn't say whether those weird things are expected or not though

#

But I would definitely expect sign changes and flipped columns and stuff

#

the y rotation one seems plausible

delicate delta
#

it works ?

#

I can't worry about it anymore :|

elder kettle
#

haha

delicate delta
#

I'm sure the moment I import a gltf I will have something fucked, if not, then good, if so, I fix whatever happens then

#

but I'll wait until then

elder kettle
#

You should just be able to pass all transformations through a matrix that converts coordinate systems

delicate delta
#

yes

#

@elder kettle your winding order in your RHS coordinate system is counterclockwise and your rotations for increased angles all go counterclockwise?

elder kettle
#

Yeah

delicate delta
#

nice

elder kettle
#

oh right winding order

#

yeah you may need to swap the winding order or reorder the indices

delicate delta
#

no I just did that

#

so they're all clockwise now

#

they were counterclockwise which is incorrect for LHS

#

I was wondering if in your coordinate system they're counterclockwise

#

I sunk some time into this today so a bit of lost day progress wise, but I want to be intentional about my coordinate system and have it all be correct as much as I'm capable of, glad I read that chapter though

elder kettle
#

the right handedness is applied to everything generally

#

I guess you could choose left handed winding in a right handed system but idk why you would

delicate delta
#

don't you have to be intentional about it if you do your own geometry

elder kettle
#

The choice of handedness is arbitrary so you may as well choose them to be the same

#

Yeah you do but it's arbitrary

delicate delta
#

the cross product produces a vector in a direction based on handedness, I would like my surfaces to be visible in the direction the cross product produces a surface normal given the same handed winding order

#

I had to fix that today

elder kettle
#

oh yeah changes the cross product too lmao

#

I hope you try a right handed coordinate system sometime before you get too used to this one because if you ever get a job where you actually need to do math it's going to be unbelievably confusing to be more intuitively familiar with this extremely nonstandard system

delicate delta
#

some game engines are left handed though

#

yeah but I was just doing it differently as a means to learn so I wouldn't just copy and paste matrices, but had to figure this stuff out

#

if I had just gone with a RHS Y up I wouldn't have had to fix all this and wouldn't have learned what I've learned

elder kettle
#

fair enough

delicate delta
#

these math books just declare what coordinate system they use and never explain how that choice changes the math

#

all these books are like that

#

they do go over the cross product though

elder kettle
#

That's pretty common

#

it's annoying

#

especially for rotation math

delicate delta
#

yeah that's what I appreciated about GEA, it actually mentions that explicitly

#

it's not even a math book, it just has a math chapter

#

that actually was the first thing I thought about when I woke up this morning, I finished reading at like 1 am, went to bed and woke up thinking wait are my rotations going in the right direction? lol

#

they weren't

elder kettle
#

Someone leant me this book at work last year when we were working on a particularly nasty rotation problem and it was very unhelpful because it just assumed one specific choice of convention

#

and we were trying to work out the impact of those choices

#

actually that was 2 years ago damn

delicate delta
#

Oh damn, that book looks cool though

elder kettle
#

my enthusiasm for it was rather dampened by its lack of rigor in that regard but it was decent yeah

#

still helped me understand the problem I just had to figure it out myself

delicate delta
#

Yeah that sucks

#

Your team are like the people that get called when Apollo 13 is stranded in space and they need math to rescue the crew

elder kettle
#

lmao

#

we shouldn't be but sometimes that is indeed the case

delicate delta
#

Alright finished the 3D math chapter in the Graphics Programming in OpenGL with C++ book. There's was nothing new in that one. It's just rendering now, with some GEA progress every so often along the way.

maiden gazelle
#

I'm also not pushing models due to both copyright & size

maiden gazelle
# delicate delta these 150+ page chapters are so exhausting

Yeah it was a long read and I think I successfully managed to forget most of it lol. But it's a nice overview. I'd still take a look at this chapter if I wanted to delve deep into multithreading, just to see a big picture view again, before moving on to detailed resources.

maiden gazelle
maiden gazelle
#

You can transform the transformations too

#

For example I use LH coord system where Z points forward (towards the screen), x to the right and y up. glTF uses the same X & Y, but it is right-handed so its Z axis points towards the user.

#

So when importing node transforms from glTF, I construct a change of basis matrix from glTF's to mine, which consists of my x y z cardinal axes, just the z is inverted, as that is the only difference between the two systems.

#

I just have to sandwich the glTF space transformation between this change of basis matrix & the other way around change of basis matrix (from my system to glTF), which happens to be the same matrix if you think about it!

#

The second part of this video is a good touch up on the subject of change of basis for linear transformations

delicate delta
#

Thanks!

maiden gazelle
#

You probably knew these as well but just wanted to hint at it. You can of course create conversion functions between coord systems too but if it is just to interface with different formats, maybe you can "cheat" like this too.

delicate delta
#

I am not sure, but I will find out how much trouble I am in when I add a mesh loader 😅

#

It should be fine I will just always apply the transformation to my coordinate system at the end after all object space transformations and animations

delicate delta
#

chapter 4 CGPOC first program a plain red cube, with zig and my existing scene flavor

delicate delta
#
program: u32,
location: c.GLint,

const Uniform = @This();

pub fn init(prog: u32, name: []const u8) Uniform {
    const loc: c.GLint = c.glGetUniformLocation(@intCast(prog), @ptrCast(name));
    return .{
        .program = prog,
        .location = loc,
    };
}

pub fn setUniformMatrix(self: Uniform, m: math.matrix) void {
    const v = math.matrix.array(m);
    c.glProgramUniformMatrix4fv(@intCast(self.program), self.location, 1, c.GL_FALSE, &v);
}

const c = @import("../c.zig").c;
const math = @import("../math/math.zig");

my little don't look uniforms up by name every frame code :/

#

idk

elder kettle
#

Fortunately I can't make heads or tails of this language so I can't pass judgement on any of your code

delicate delta
#

yeah the casting is a bit noisy

#

because I'm dealing with C types and I am using zig

#

otherwise this would look a lot like C

#

it just builds a struct with a method that I can call setUniformMatrix on every frame with a 4x4 matrix by location

#

const Uniform = @This(); is just a compile time thing to assign the surrounding struct type as variable with a name to use

#

I am going to have to add stb_include to proceed

elder kettle
#

I got away without it for ages tbh

#

what do you need it for

delicate delta
#

the book wants me to add a bunch of matrix math in the shader

#

and I don't want to copy and paste

elder kettle
#

What's the math for

delicate delta
#

it's not really math it's just transformation matrices actually

elder kettle
#

I'm just curious what you're doing that already has so much matrix math, tbh 90% of my vertex shaders are like a 3-liner

#
void main()
{
    gl_Position = viewProj * model * vec4(in_position, 1);
    out_normal = model * in_normal;
    out_uv = in_uv;
}
delicate delta
#

well I'm just following the book, but this example is a bunch of instanced cubes that rotate every frame and it does all the rotations in the shader

elder kettle
#

I'd do the rotation on the CPU tbh

delicate delta
#

it's like 10K cubes

elder kettle
#

I'd do them in compute then

#

doing them in the VS isn't very realistic

delicate delta
#

well it's just a tutorial in the book

elder kettle
#

Alright fair enough

delicate delta
#

I agree though

#

it escalated pretty quickly from red cube to this

elder kettle
#

also 10k isn't that many you could still easily do it on the CPU

delicate delta
#

after this it does a hiearchy mesh with animations, sorry its 100k

#

I agree though

#

it's being silly in an early chapter

elder kettle
#

Generally the scenario will either be CPU transforms put into an SSBO for rendering, or transforms done in compute and then read in the VS

delicate delta
#

it's like teaching instancing

elder kettle
#

because the odds that you only need the transformation matrices once is unlikely

delicate delta
#

I just kind of want to see if I can use stb_include in zig

delicate delta
#

stb_include is uncessary I can just use std.mem.concat and @embedFile

elder kettle
#

I just copy paste personally

delicate delta
#

yeah that works

elder kettle
#

I have 16 vert shaders for my project, they don't get made that often so idrc

#

Most things that are complex enough to warrant reusing aren't generic enough to need to be reused

delicate delta
#

I have a whole bunch, each scene has its own, and they're all the same

#

this is the first time I'm doing anything fancy with a shader in this project

elder kettle
#

Well I only have one scene

#

Mine are all different

#

But they're short enough to not be worth trying to use common code

#

But I did recently start using stb_include for my foliage stuff but that's because it's a relatively complex system with many SSBOs and interpretation steps to generate the actual transform data from the compressed buffer elements

delicate delta
#

for stb_include what do you use for your path?

#

file path

#

is it part of the project root?

#

do you have like a resources or app_folder that you use?

#

I guess it's a visual studio thing

elder kettle
#

I have a resources/shaders folder

#

Eventually I'd have the game exe in root and then access the resources folder from there but for the time being I set a specific working dir in VS

delicate delta
ivory verge
#

looks cool 🙂

#

also cool to see these patterns emerge everytime you do silly stuff like that

queen hinge
delicate delta
#

I am just sending frame time and using instanced id

#

GPUs are cool

queen hinge
delicate delta
#

Oh ok

#

I thought you were referring to something more fancy 😅

queen hinge
#

Nah, not in this case

delicate delta
#

I need a Graphics Programming dictionary to understand the words people use on this server

queen hinge
#

KEKW me too

#

I generally just use terms I see others use or terms I come up with on my own, lol
GPU instancing is one of the ones I saw someone else use

#

I think GPU instancing is just another term for draw instanced but I’m not 100% sure

#

Probably

delicate delta
#

This is a great new addition to my tech
babble speak I use to ask product managers for more time to get something done

#

Just kidding I don’t do that

queen hinge
#

So
Pytorch
Having had rewritten my AI like 7 times so far
… pytorch is great, though I’m still not a fan of python’s lack of explicit typing
… and the lack of curlies
… or even at leastlua if (condition) then logic endlike LUA or TI basic

delicate delta
#

Yeah I don’t like python or ruby or any of these languages where white space is a significant part of the syntax

#

I used to write python as a job, like in 2010

#

But it was a step up from PHP at the time so I was happy

queen hinge
#

I like being encouraged to type things and discouraged from not typing things
Because having that makes it a lot easier to just grab library, go since I can use the type hints to resolve how to use a library far faster than without those

I also like having something equivalent to curlies because copy/pasting and formatting becomes painful without those bleakekw

delicate delta
#

It’s kind of crazy how python is dominating again, I thought for sure python 3 debacle and Go were going to be the end of python

queen hinge
#

Being able to arbitrarily separate a random snippet of code into its own block is… pretty nice as a formatting option
Lets me indent a thing to make it stand out without having a syntax error, and I can just put a comment above the block to state the blocks purpose

delicate delta
#

I frequently use just two curly braces in zig just to create a block to temporary scope and isolate work

queen hinge
#

Yep
I do that sometimes in java too

delicate delta
#

And it makes code more readable

queen hinge
#

And my god do I wish I could do that in python bleakekw
Need it there more than I do in java bleakekw

delicate delta
#

Have to make a bunch of inline functions or use a lambda

#

You can nest functions in python

queen hinge
#

if True:
# code

delicate delta
#

Nah just lambda it

queen hinge
#

funfact; scopes don’t really exist in python!

delicate delta
#

It’s definitely more fluid

queen hinge
#
if cond:
    x = 5
print(x) # error if cond is false, elsewise prints 5```
delicate delta
#

Maybe Mojo is better

#

It’s for GPU stuff

#

It’s pretty python like though

queen hinge
#

usability of python
python’s syntax
ehhhh not sure about that one KEKW

#

struct Matrix[type: DType, rows: Int, cols: Int]:
oh
Struct syntax is closer to records than classes agonyfrog

delicate delta
#

The life of a value in Mojo begins when a variable is initialized and continues up until the value is last used, at which point Mojo destroys it. This page describes how every value in Mojo is created, copied, and moved

#

Mojo seems like an improvement to me

queen hinge
#

obviously the solution is to make the best language model on the market, and then make it only run on my own custom AI framework written in java

#

Or zig

#

I still need to take a closer try at zig KEKW

delicate delta
#

Not quite a good time to try zig imo unless you are cool with rewriting code a bunch of times all the time

#

Just kidding it’s not really that bad, but it’s a new language still under significant development

#

You are signing up for that when you use zig

queen hinge
#

I’d likely just use libtorch behind the scenes tbh

#

Because libtorch is C++

delicate delta
#

the next section of chapter 4 includes a pyramid, so I made my own.

delicate delta
#

cube and pyramid from chapter 4

#

my colors aren't nice as in the book

#

it's like a combination of my x up and my own geometry is a little different, I don't like theirs, but I'm using their colors

elder kettle
delicate delta
#

it's all srgb

#

but yeah in the book they don't use it

#

so yes, that's part of it

#

I can disable it easy enough per object idk

delicate delta
#

an animation hierarchy program from chapter 4

maiden gazelle
#

Not necessary yeah

delicate delta
#

I just was able to use zig’s std library to concatenate shader source I can directly embed using zig built in ‘@embedFile’ so I just didn’t need to deal with run time file loading and C memory management and c null terminated char arrays in zig

#

I will eventually just compile shaders to spirv from straight zig source anyway so all my shader code will get reworked

ivory verge
#

perhaps you can also make the background color not true black, but {0.01f} or so

delicate delta
#

yeah that black background is terrible

#

I keep forgetting to change it when I'm working on the project

#

been meaning to for weeks now

ivory verge
#

: )

delicate delta
#

that and the imgui theme

delicate delta
#

this new coderabbit ai PR review feature is neat

delicate delta
#

using the green theme you shared

#

looks way nicer than black

#

and default imgui theme imo

#

I like that green dear imgui theme

queen hinge
#

wait

#

not an orange theme???

delicate delta
#

it has orange highlights

queen hinge
#

I see no orange

delicate delta
#

you have to hover over something

#

er press down

delicate delta
#

I am going to alternate each chapter of CGPOC with one with GEA so I keep making progress on that giant book

#

so chapter 6 of GEA is next

maiden gazelle
#

It is very cool bateman but that's nothing

delicate delta
#

Damn that’s nice

#

Deccer shared the green theme in this thread a bit ago

maiden gazelle
#

That khaki & orange look really good

#

I'm getting CS 1.5 - 1.6 or MGS vibes

delicate delta
#

Yeah I agree

delicate delta
#

I think my eventual game will be construction zone themed, so bright orange and yellows

#

concrete gray

#

I should start working on the 3D models for that game while I learn about graphics programming

maiden gazelle
#

I have a tower defense project in mind but not sure if I’m gonna follow through on that one

delicate delta
#

I love tower defense games

#

especially if it's not on rails and the creeps have to pathfind and you can build obstacles

maiden gazelle
#

That’s the exact game I had in mind 😄

#

You build the path by placing towers on a grid

delicate delta
#

I really like chapter 6 of GEA, the memory section in particular with per frame memory and all the custom allocators

#

the rest of it was like CS101 and otherwise felt like big studio problems though, like internationalization and configuring a massive engine

#

yeah for sure I'm going to build a web portal for my internationalized strings and engine configuration

#

oh though I did love the scheme -> C++ header section for building configurations for animations, physics parameters, player mechanics and stuff

#

reminded me of Madrigal's tools

delicate delta
#

one GEA chapter at a time is the way to go, way easier to deal with, did one chapter in a single day today, back to rendering tomorrow, CGPOC chapter 5 is about textures frogeexcited

maiden gazelle
maiden gazelle
delicate delta
#

Zig actually ships with an arena allocator

delicate delta
#

I am going to have to build an asset loader to do this chapter, I'm not just calling stb_load_image in the middle of my scene code

#

just going to build the bare minimum to load textures but in a way I can add models and other stuff later

#

not going to get fancy with comptime I just want to make progress and I'll probably change the loader once I get through GEA and learn more about it

#

and after read some of the other engine books I have too

delicate delta
#

still quite a bit of work even so

maiden gazelle
#

I tried to do the bare minimum but it took a lot of time still

delicate delta
#

computers man

#

all these resources I have to manage now

#

files, memory, images

delicate delta
#

ok ok ok ok so close

#

so much work

#

it's like 3 lines of code in the book, it's a massive PR in my engine

delicate delta
#

ok texture is loading

#

now to add texture coordinates

#

much work, but real close now

#

this is my DSA texture object in zig

name: c.GLuint = 0,
texture_unit: c.GLuint = 0,

const Texture = @This();

pub fn init(image: *assets.Image) Texture {
    var t: Texture = .{};
    var name: u32 = undefined;
    c.glCreateTextures(c.GL_TEXTURE_2D, 1, @ptrCast(&name));
    c.glTextureParameteri(name, c.GL_TEXTURE_WRAP_S, c.GL_CLAMP_TO_EDGE);
    c.glTextureParameteri(name, c.GL_TEXTURE_WRAP_T, c.GL_CLAMP_TO_EDGE);
    c.glTextureParameteri(name, c.GL_TEXTURE_MIN_FILTER, c.GL_LINEAR_MIPMAP_LINEAR);
    c.glTextureParameteri(name, c.GL_TEXTURE_MAG_FILTER, c.GL_LINEAR);
    c.glTextureStorage2D(name, 1, c.GL_RGBA8, @intCast(image.width), @intCast(image.height));
    c.glTextureSubImage2D(
        name,
        0,
        0,
        0,
        @intCast(image.width),
        @intCast(image.height),
        c.GL_RGBA,
        c.GL_UNSIGNED_BYTE,
        image.stb_data.ptr,
    );

    c.glGenerateTextureMipmap(name);
    t.name = name;
    return t;
}

pub fn bind(self: Texture) void {
    c.glBindTextureUnit(self.texture_unit, self.name);
}

const c = @import("../c.zig").c;
const assets = @import("../assets/assets.zig");
#

just hard coding all those settings atm

delicate delta
#

success

#

doesn't look like much but I now have a full fledged texture asset loader

#

that caches

#

adding additional textures is super easy

#

and it loads from the windows app data directory so none of these copyrighted files are in my repo

#

unless they are HDR because I skipped that

delicate delta
delicate delta
#

I'm going to fix my 100 shaders

#

all my scenes have their own shaders

#

I'm going to make it so my vertex vao/buffer code owns the vertex attributes part of the vertex shader, my instance buffer code owns the that part of the vertex attributes, and then the scenes can submit a main function, and most of my frag code is pretty much one of three, color, normals as color or, as of today, a texture coordinates sampler

#

it was really painful to add texture coordinates to all those shaders

#

I also want to switch to TQS instead of a 4x4 matrix for my instance matrices

#

I'm not going to do that right now

#

but this change will make that easier

queen hinge
delicate delta
#

still not done

queen hinge
#

mojang has several shaders they don't even use in minecraft

#

the corresponding java code just flat out doesn't exist in the game's jar

#

which-
implies they generated stuff using scripts tbh

#

several of them are just rearranged element orders of others

delicate delta
#

I'm doing that at runtime atm

#

compile time sounds better

#

I'm not there yet

queen hinge
#

they're likely not doing it at runtime nor comptime

delicate delta
#

hrm, right as part of baking a model or something is ok too

#

any kind of automation that's smart and efficient is good

#

mine were just literally copy and pasted

#

so a step up

ivory verge
#

there is a little mistake in it

ivory verge
#

you want to calculate the miplevels, and pass that in, instead of the 1

#

since you are generating mips

delicate delta
#

Oh

ivory verge
#

1 + floor(log2(max(width, height)))

#

might be 1 + ceil(...) i always mix the two

#

but for a 1024 texture you should get 10

delicate delta
#

Because I went the DSA way I didn’t exactly follow the book with that code and I will fix it thank you!

ivory verge
#

1 miplevel textures are the ones you use for fbos most likely

#

like gbuffer attachments

#

for those you dont have to call generatemips either

queen hinge
delicate delta
# ivory verge there is a little mistake in it

so looks like the book didn't cover this at all because it uses SOIL2 to load the images and it does that automatically. I looked at SOIL2's code

            int MIPlevel = 1;
        int MIPwidth = (width+1) / 2;
        int MIPheight = (height+1) / 2;
        unsigned char *resampled = (unsigned char*)malloc( channels*MIPwidth*MIPheight );

        while( ((1<<MIPlevel) <= width) || ((1<<MIPlevel) <= height) )

I am not using SOIL2 I'm using stb_image which doesn't do any of this and anyway I want to learn OpenGL.

Thanks for letting me know, they did discuss mipmap levels in the book but the book is more about concepts and not about the OpenGL API specifics and they say to go look it up

#

in this case I didn't follow the book's instructions to look at all the parameters of the functions I was using 😅

ivory verge
#

soil and stb just load the pixel data from disk/memory

delicate delta
#

and their documentation

#

nah

#

this is SOIL2

ivory verge
#

they might have opengl helper functions to also create a texture

delicate delta
#

it creates texture objects directly

ivory verge
#

ah

#

here is the magic sauce

delicate delta
#

you just get your GLuid and you're good to go, you do have to specify sampling

ivory verge
#
++MIPlevel;
#

they upload every mip manually

#

i was about to mention earlier that you can do that as well

#

but you still need to allocate those maps in the storage, when using glTextureStorage

delicate delta
#

would prefer to just call the glTextureStorage2D unless that's not performant or something

#

I don't know I guess it depends on the outcome

ivory verge
#

just cater for mips if you need them, otherwise miplevels 1 is fine

delicate delta
#

if there's some issue with how I'm doing it and I get artifacts or it looks wrong or is slow I can revisit but I will fix that 1 level I have right now

#

cater for mips? what does that mean?

ivory verge
#

make space for them, when calling glTextureStorage, by telling it how many mip levels there are

delicate delta
#

I'm going to go read the spec I guess

ivory verge
#

glTexImage2D != glTextureStorage

delicate delta
#

glTextureStorage2D is what I am referring to

#

it has all those characters + 2D

ivory verge
#

yes

#

thats what i am talking about

#

i omitted the 2d because there is a 3d variant too

#

i thought that was obvious 🙂

delicate delta
#

my reading of this in the spec is that by supplying a levels will result in the storage for the arrays required for when I call glGenerateMipmap

#

oh that's what you said

#

ok ok I think I understand thank you!

#

looking at the SOIL2 code makes sense now

#

I changed it to


    const w: f32 = @floatFromInt(image.width);
    const h: f32 = @floatFromInt(image.height);
    const mip_map_levels: c.GLsizei = @intFromFloat(@ceil(@log2(@max(w, h))));
    c.glTextureStorage2D(name, mip_map_levels, c.GL_RGBA8, @intCast(image.width), @intCast(image.height));
#

just your regular zig casting mayhem

#

I am going to add this to my notes

#

these are my mipmapping notes

  • Mipmapping
    • MIP stands for Multum In Parvo, Latin for "much in a small space"
    • stores a series of successively lower-resolution copies of a texture imagee
      and then repeating the process in the remaining one-quater of the image
      space for the same image at one-quarter of the previous level or the
      original resolution if at the beginning, and then subdividing further until
      the remaining quadrant is too small to contain any useful image data.
    • will require storage that is 1/3rd larger than the original image
    • in older systems it might possibly do this in separate R, G, and B
      components
    • used for preventing artifacts caused by image resolution issues when
      texturing mapping objects during rendering.
    • can be used with linear filtering, bilinear filtering and trilinear
      filtering using one or two mipmaps at nearest resolution and use one more
      texels to interpolate a color
    • levels to mimpap to depend on context, but given width w and height h for an
      image ceil(log2(max(w, h)) will produce the max possible levels
ivory verge
#

if you have no mips, but have enabled generating mipmaps. you will get a fancy effect going which looks like "fog"

#

because when it samples into nothing ness (because you have mipmap filtering going) it will returnnothing and that will most likely black, but since its interpolated you see something like fog

delicate delta
#

oh neat hrmmm

#

so it's sampling the texture and undefined values and interpolating them?

#

asking the old gods for what the color should be at the pixel location

ivory verge
#

yeah

delicate delta
#

my notes btw

$ .\Count-Lines.ps1
Current markdown line count: 12861
#

who needs functional memory when you can just write it all down

ivory verge
#

: )

delicate delta
#

finished chapter 7 of GEA, pretty cool stuff about asset conditioning pipeline and resource management and file system stuff

#

time for loading 3D models I guess

delicate delta
#

switched my sphere to use the one from the book, it's better, mine was over complicated, and it had texture coordinates

#

I did the single point at the ends thing with mine, I also had way too many vertices

#

the one in the book you can set a precision on it

elder kettle
#

So it begins

#

Give it a lil 1/300 flattening

delicate delta
#

too spherical? :O

elder kettle
#

Just trying to tempt you down the nightmare of physical geodesy

delicate delta
#

this is bindless btw

#

🎉

delicate delta
#
    // Generate bindless handle
    t.handle = c.glGetTextureHandleARB(t.name);
    if (t.handle == 0) {
        return TextureError.BindlessHandleCreationFailed;
    }

    // Make the texture resident
    c.glMakeTextureHandleResidentARB(t.handle);

    t.uniform = Uniform.init(program, uniform_name);
#
pub fn setUniformHandleui64ARB(self: Uniform, handle: c.GLuint64) void {
    c.glProgramUniformHandleui64ARB(@intCast(self.program), self.location, handle);
}
#
#version 460 core
#extension GL_ARB_bindless_texture : require

out vec4 fo_frag_color;
in vec2 f_tc;

layout(bindless_sampler) uniform sampler2D f_samp;

void main()
{
   fo_frag_color = texture(f_samp, f_tc);
} 
delicate delta
#

idk why people need to use radian conversion when dealing with 360 or 180, that's just 2 * pi and pi

#

actually zig has std.math.tau mindblown

delicate delta
#

this book is creating the same matrix in a loop over and over again

    // rotate the first ring about Y to get the other rings
    for (int ring = 1; ring < prec + 1; ring++) {
        for (int i = 0; i < prec + 1; i++) {
            float amt = (float)toRadians((float)ring * 360.0f / (prec));

            glm::mat4 rMat = glm::rotate(glm::mat4(1.0f), amt, glm::vec3(0.0f, 1.0f, 0.0f));
            vertices[ring*(prec + 1) + i] = glm::vec3(rMat * glm::vec4(vertices[i], 1.0f));

            texCoords[ring*(prec + 1) + i] = glm::vec2((float)ring*2.0f / (float)prec, texCoords[i].t);

            rMat = glm::rotate(glm::mat4(1.0f), amt, glm::vec3(0.0f, 1.0f, 0.0f));
            sTangents[ring*(prec + 1) + i] = glm::vec3(rMat * glm::vec4(sTangents[i], 1.0f));

            rMat = glm::rotate(glm::mat4(1.0f), amt, glm::vec3(0.0f, 1.0f, 0.0f));
            tTangents[ring*(prec + 1) + i] = glm::vec3(rMat * glm::vec4(tTangents[i], 1.0f));

            rMat = glm::rotate(glm::mat4(1.0f), amt, glm::vec3(0.0f, 1.0f, 0.0f));
            normals[ring*(prec + 1) + i] = glm::vec3(rMat * glm::vec4(normals[i], 1.0f));
        }
    }
#

they could just create rMat once in the outer loop?

#

something I don't get about C++?

#
 glm::mat4 rMat = glm::rotate(glm::mat4(1.0f), amt, glm::vec3(0.0f, 1.0f, 0.0f))
 rMat = glm::rotate(glm::mat4(1.0f), amt, glm::vec3(0.0f, 1.0f, 0.0f));
 rMat = glm::rotate(glm::mat4(1.0f), amt, glm::vec3(0.0f, 1.0f, 0.0f));
delicate delta
delicate delta
delicate delta
#

the state of wavefront obj loaders in C and zig is not great

#

I will have to write my own

#

tinyobjloader_c loads from files

#

that was my problem with stb_include as well

#

I don't want to use C to read files

#

stb_image lets me give it the bits

#

every time I want to use a dependency, some other library, and I see the state of zig I just feel despair man

#

people just cannot keep their shit up to date

#

if you aren't along for the ride don't write a library in zig you know

#

you're just creating litter, it's littering, it should be an arrestable offense, straight to jail

#

I have never written a zig library and I never will

#

I'll probably end up writing my own gltf parser too

#

and eventually replace all my dependencies with just my own zig code

delicate delta
#

this looks weird though

#

I don't think that's in the texture

#

I had to

  1. self.texture_coordinates[t_index] = .{ s, 1 - t };
  2. exchange the first face with the third face for all f 1/1/1 2/2/2 3/3/3 (so had to switch 1 and 3)
  3. I had to add a reflection matrix in my shader that reflected along one of the axis
  4. turn off SRGB
#

cuz LH x up mayhem never ends

#

oh and also write my own obj parser

queen hinge
#

when doing lights
PLEASE add options for falloff modes KEKW

#

inverse square is annoying to work with if you want a specific light length KEKW

delicate delta
#

I don't make these things, they came with the book

#

:\

#

that's good to know though

#

is that a material thing

#

like I am just going to write my own lights?

queen hinge
#

uh
whenever doing lights, you're going to have do some kinda shader
somewhere in that shader will be a falloff mechanism
the physically accurate one is inverse square falloff, which tends to result in lights either not going far enough or being way too freaking bright KEKW
in my case, it's ending up with the light not falling off fast enough, since I'm not going for stylistic lighting rather than realistic lighting

delicate delta
#

ok what's the light GUI thing you're showing

#

is that a godot thing

#

are you doing things in blender? do you import that somehow? I'm just not following

queen hinge
#

this is blender

delicate delta
#

I'm familiar with fall off

#

I just don't know why you're showing me light settings in blender :P

queen hinge
#

because it seems the fall off setting was removed from blender and it's bothering me KEKW

delicate delta
#

hrm

queen hinge
#

basically
inverse square falloff is a lot harder to tune in, but it's physically accurate
linear falloff is really easy to tune, but is not physically accurate

#

I assume

#

ngl I kinda feel like linear is the more accurate one

#

solution for my problem: use a negative brightness sun KEKW
why? yes KEKW

delicate delta
queen hinge
queen hinge
delicate delta
#

it was fun yeah, but my weird coordinate system always ruins all the fun

#

everything I do is always broken at first

#

and broken in just the weirdest way

queen hinge
delicate delta
#

and what incantation of flipped signs, subtract from one, reflection, switch around vertices will I have to do perform to fix whatever thing is always a mystery

queen hinge
#

Obj uvs tend to be upsidedown for some reason KEKW

delicate delta
#

maybe grassman algebra avoids all this maybe I should get serious about it

#

I just have to think in 4 dimensions across hyper geometry

queen hinge
delicate delta
#

it's how we will ascend

queen hinge
delicate delta
#

:P

queen hinge
#

I should put that emote in my about me whenever I next get nitro

#

which, quite literally, might happen if I go on hiatus for a week KEKW

#

pretty sure there have been like 3 instances of discord just giving me nitro because I was offline on vacation for a week KEKW

delicate delta
#

nitro is your drawing app? you have like 10 projects

queen hinge
#

discord nitro

delicate delta
#

oh

queen hinge
delicate delta
#

you have to have nitro to put an image in your bio?

queen hinge
#

Yes

#

I’m like
99% sure

#

I’m pretty sure I only have an animated emoji in my bio because discord is funky and didn’t automatically remove it KEKW

#

I’m not sure, and I don’t want to test, because if I’m right, I can’t undo my test KEKW

queen hinge
#

(Most of these are on indefinite hiatus)

#

There’s also a few not included in that count frOK

queen hinge
delicate delta
#

ok ok ok, I finished the 3D models 6th chapter of CGPOC, I finished writing my notes. Next is a relatively short chapter in GEA, chapter 8, which is about the game loop and real time simulation, and then next in chapter CGPOC is lighting, which will be the first time I ever do lighting that isn't the fake minecraft lighting I did in Blockens

#

yeah chapter 8 of GEA is like 34 pages, which is probably the shortest chapter in that book

#

I have to read like 3 or 4 pages in GEA for every page in CGPOC

#

This is a new book I got

queen hinge
delicate delta
#

:P

#

man Anthropic hates me

queen hinge
#

At least it’s not 6 days KEKW

delicate delta
#

I'm going to exercise and go to bed, good luck with your drawings in Krita

queen hinge
#

Oh I’m not on pc

#

Nor do I have the model (it’s a minecraft model and I need to deblockify it before I can draw it because perspective and shapes are not things I’m great at)

#

I’m about to go to bed too KEKW

queen hinge
# delicate delta

But something tells me you have a healthier sleep schedule than me KEKW

delicate delta
#

gotta get rest!

queen hinge
# queen hinge basically inverse square falloff is a lot harder to tune in, but it's physically...

As I understand it
With inverse square, the brightness falls off with distance automatically based on the brightness
So if you have a stupidly large room, you need the power of the entire sun to light it up, even if all your objects are also scaled up to match
Can’t really tell it hey go further without telling it hey be as bright as the freaking sun afaik
With linear this is not a problem
You specify brightness, and distance
It linearly fades off based on vector length between the source and the fragment from brightness to 0

maiden gazelle
#

You are zooming through the books!

#

Godspeed

#

I should take notes as well …

ivory verge
#

oh it didnt scroll

delicate delta
#

Next week I have to go to Salt Lake City for work and drag two work computers with me so I probably will not make much progress then. I may just read the Vulkan spec or something

#

Completely unnecessary trip tbh

#

The Mastering Vulkan book would fit in a plane seat.

wise imp
#

mastering vulkan book is amazing

#

its deeply under-rated

#

the thing actually walks you in detail into implementing quite a few fancy modern techniques

#

the volumetrics i have on my engine are copied from there, it was a huge help

delicate delta
#

yes it looks really good

maiden gazelle
#

Hmmm good to know

queen hinge
#

Advice: don’t accidentally offset a model by 0.00001 pixels
Someone may notice it KEKW
(One of my online friends accidentally offsetted a model by a very small value a long time ago, and well… I was the one who noticed KEKW)

delicate delta
#

pixels?

queen hinge
#

units

#

I’m just defaulting to pixels

delicate delta
#

that's a value approaching a number lower than ULP

#

say ULP is v 1 + less then v doesn't change anything

#

unit in last place or whatever

queen hinge
#

I don’t remember exactly what the value was
But it was small enough that it was like maybe a pixel’s difference from less than a unit away iirc

delicate delta
#

hrm

delicate delta
#

sorry I was referring to machine epislon

delicate delta
#

I finished chapter 8 of GEA, pretty short chapter about render loop and time delta and a job system. I read chapter 7 of CGPOC which is all lighting and so I'll be starting on some lighting work today, I also noticed the chapters have exercises for extra things to do and I like them and I think I will do some of them. Really excited

#

I also realized I can still work with renderdoc, my texture abstraction is pretty great, I'm going to add a command line arg the texture object is aware of and switch between bindless and texture binding based on it so I can just pass in a command line arg in renderdoc and it will use the old style of texture binding

#

I'm also going to add a default magenta 1 px texture whenever a texture doesn't load instead of it just appearing black

#

I have a lot of work to do the rest of this week just on lighting, then on to shadows probably after next week, I won't be able to do much due to work travel but the weekend I should be productive again

delicate delta
#

I'm going to read it a few times

queen hinge
delicate delta
#

ya

#

congrats?

queen hinge
#

yea they just randomly decided to give me a full month for free

delicate delta
#

why

queen hinge
#

KEKW no idea

delicate delta
ivory verge
#

i just cancelled mine, after 5 years

queen hinge
delicate delta
#

hrm

queen hinge
#

discord was like
nitro (one month free)
KEKW

delicate delta
#

there's no viable alternative to discord

#

so I'm not making any changes personally

#

but I respect these choices, discord has many flaws

queen hinge
#

yeah discord just give me nitro randomly
🤷 idk why

#

sanity_warning takes up 37 characters in my about me KEKW

delicate delta
#

it didn't notify you in some way with a message?

#

I think you just paid for it and are lying KEKW

queen hinge
delicate delta
#

ok I am sorry I doubted you and accused you of telling untruths

queen hinge
#

pretty sure I've gotten like 3 trials of nitro at this point KEKW

maiden gazelle
#

I also re-read it a couple of times and aside from the beginning parts, the rest flowed more naturally imo

delicate delta
#

yes

#

the intro lead in was presenting a problem I guess

ivory verge
#

the handmade club also likes to sound a little elite

delicate delta
#

hey, zig nightly now has labeled switches!

    const val = s: switch (six) {
        0...4 => break :s false,
        5 => break :s false,
        6...7 => break :s true,
        else => break :s false,
    };

froge_love this is amaze

#

assign to variable directly from a switch

delicate delta
#

so I made a command line arg to use texture binding

and now I have a working renderdoc again

#

also added a 1 texel sized debug texture for when loading a texture fails

queen hinge
#

There’s a lot of those

delicate delta
#

yeah it's really nice

delicate delta
#

Really basic Gouraud Shading, all in the vertex shader. First time I've ever done any lighting. My torus normals are mirrored so I need to fix that.

I had to fix so much shit. I had to separate out my matrices in camera, I had to add SSBO buffers. I had to add materials and lights. I had to idk, this took all afternoon and evening.

ivory verge
queen hinge
#

You needed SSBOs for this?

ivory verge
#

no

delicate delta
#

No you can just spam uniforms

#

I can stick all my lights and materials in the ssbbos I made

ivory verge
#

can be an ubo too

delicate delta
#

True

delicate delta
#

ok on to phong shading

delicate delta
#

a torus is an interesting shape to test lighting with

#

trying blinn-phong next

wild ember
queen hinge
#

makes sense

delicate delta
#

they're just nice to have though, why use UBO if I can use an SSBO

wild ember
#

UBOs are potentially faster but it depends on the implementation

#

SSBOs are often implemented as a texture lookup

#

And you may or may not have any texture bandwidth to spare

delicate delta
#

you're saying it uses texture unit hardware?

wild ember
#

This is what I've heard, but it's also possible to implement differently

delicate delta
#

interesting

wild ember
#

For small buffers you should generally prefer UBOs

delicate delta
#

good to know, thank you!

queen hinge
#

a lot of gpu stuff is implementation dependent

#

you actually aren't even guaranteed to even have support for GL_NEAREST

delicate delta
#

I mean, I'm only targeting my own GPU :/

#

and any brave soul that wants to pull my repo

#

I do want to make a game eventually though

#

x up lh is not for the faint of heart though

wild ember
#

Oh wait I might need to install a zig compiler

delicate delta
#

yes, and I stay up to date with zig nightly, I literally update my compiler every day

wild ember
#

Damn

delicate delta
#

I use zigup if you're interested, but there's zigvm too

#

yeah, zig is...a lifestyle choice you know

wild ember
#

Hehe yeah

#

Is there not a zig standard?

delicate delta
#

there is a zig grammar

#

it's still being developed

wild ember
#

Ah I see

delicate delta
#

I don't know if there will be a standard

wild ember
#

They drop new C++ like every 3 years

delicate delta
#

I like C++ I wish I had good editor tools and nice dependencies

#

the community uses ZLS which is a language server, and it is frequently behind or broken

#

well it's not that bad

#

but it can be bad sometimes

delicate delta
#

huh

#

I think the blinn-phong in the book is incorrect

#

it calculates the halfway vector in the vertex shader

#

and then uses the interpolated value in the fragment shader

#

it loses all specular

#

if I do it in the fragment shader and use the L and V and H from there it looks correct

#

I have their C++ code but I don't want to build it

#
void main()
{
    Material f_m = f_materials[0];
    Light f_l = f_lights[0];

    vec3 f_L = normalize(fo_lightdir);
    vec3 f_V = normalize(-v_matrix[3].xyz - fo_vert);
    vec3 f_N = normalize(fo_normals);
    vec3 f_H = normalize(f_L + f_V).xyz;

    float cosTheta = dot(f_L, f_N);
    float cosPhi = dot(f_H, f_N);

    vec4 f_global_ambient = vec4(0.7, 0.7, 0.7, 1.0);
    vec3 f_ambient = ((f_global_ambient * f_m.ambient) + (f_l.ambient * f_m.ambient)).xyz;
    vec3 f_diffuse = f_l.diffuse.xyz * f_m.diffuse.xyz * max(cosTheta, 0.0);
    vec3 f_specular = f_m.specular.xyz * f_l.specular.xyz * pow(max(cosPhi, 0.0), f_m.shininess);

    fo_frag_color = vec4((f_ambient + f_diffuse + f_specular), 1.0);
}
#

this works for me

#

made it a bit shinier with a f_m.shininess * 4.0

#

cool cool

#

lighting, we did it

queen hinge
#

vec3 f_ambient = (fma(f_global_ambient, f_m.ambient, (f_l.ambient * f_m.ambient))).xyz;
should be equivalent I think

delicate delta
#

what's fma

queen hinge
#

fused multiply add

delicate delta
#

I've never heard of that, I am getting a refund for all these books

queen hinge
#

I believe it's a little faster than (a*b)+c

delicate delta
#

I learn more from this server than from this tower of books fml

queen hinge
#

but I'm not actually sure if it is meaningfully faster KEKW

#

it's also cleaner in some scenarios

elder kettle
#

Fma isn't just a GPU thing either x64 has it

elder kettle
#

Texture logic is still specialized, and UBOs are ostensibly similar in perf because they may be put into special memory closer to the core

#

But SSBOs and image load/store are basically both just standard main VRAM read/write

#

I'm guessing texture lookup is quite a bit faster than SSBOs and image load/store still

queen hinge
delicate delta
#

I'm still in the shallow end of the pool

delicate delta
#

Ok I changed what kind of game I want to make. I have a good idea for a simple game with a simple concept and small levels

#

An escape game, each level is a puzzle while your being chased kind of like RE2 but without any zombies or combat

#

The character you play is a little old obsolete robot scheduled for reclamation and you’re trying to avoid being caught

#

Not a new idea of course but would be fun to make and simple

#

No giant open world maps, easy occlusion, immutable terrain, hand made levels

#

Just like every small level has its set geometry and models and lights etc

#

And each level is its own small achievable goal to make and measure progress on

#

The fun will be in making cool looking levels and thinking of puzzles

#

Going to keep going on these books for now though

delicate delta
#

also I think my approach to making a game will be to make it playable, and then make it look good, and then iterate on making them each better in turn, but before I do anything at all fancy just have a bare bones thing that is playable instead of working on rendering first

#

like if it's just a couple of pixels moving around and that's a playable game that works as a start

#

like for the first level

delicate delta
#

If I didn't have a no combat rule I think I would just make a Doom clone, but I'm making this instead, which I think will be very similar and fun

wild ember
# elder kettle I think what you're thinking of is image load/store

This is where I first heard it at 38:20 https://www.youtube.com/watch?v=-bCeNzgiJ8I

Although this talk is 10 years old now bleaker_kekw so maybe things are different

In this session, Cass Everitt and John McDonald from NVIDIA will talk about some newer extensions to OpenGL and how they can reduce (or even eliminate) driver overhead. We'll discuss where performance goes, how to effectively profile GL, as well as specific extensions such as bindless rendering and MultiDraw commands.

Speakers: Cass Everitt (NV...

▶ Play video
ivory verge
#

ah the OG azdo vijeo

delicate delta
queen hinge
#

just wait till you learn about shadows

delicate delta
#

that's the next chapter

queen hinge
#

meanwhile I just accidentally setup a while true loop to create windows

#

for some reason
ctrl+alt+delete temporarily paused the window creation
which like, not gonna question it, considering that was my saving grace there KEKW

delicate delta
#

you made an AOL punter

queen hinge
#

reason is because I'm making an ANTLR parser, and wanted to get a list of every statement in a sequence of statements
but I didn't know what to make my stop condition and accidentally ran with run instead of debug bleaker_kekw

#

the freaking one time where it is extremely important for me to use debug is the one time I accidentally use run bleaker_kekw

queen hinge
queen hinge
delicate delta
elder kettle
#

Nice imgui theme haha

delicate delta
#

:P

#

is that yours?