#Foundations - Learning Graphics Programming with the Zig Programming language
1 messages · Page 6 of 1
or is there some way you can change the attachments cheaply
I thought changing FB configuration stuff was expensive
yeah afaik you might as well make a new framebuffer and configure that
Ok so you sort of cache all the configurations or something?
in fwog I have a framebuffer cache but I never measured its effectiveness
alright
I would wager that the operation that is actually expensive is changing the render target state
so configuring or reconfiguring a framebuffer is cheap, but the first time you draw with it since it's been bound is probably not
I'm allowed to ponder about perf like this because it's gl
I’m pretty sure it’s actually just binding framebuffers in general that’s slow
Regardless of if it’s the first time it’s been bound or not
the shadowmaps are flipped, but it doesn't matter during sampling, these look correct for the back light perspective and front light perspective
I have two issues to work through still which is the textures aren't being read correctly for bindless I get warnings that don't correspond to with what I see in Nsight, and the fragment shader code is not applying the shadows
I work through those two remaining issues and I should have multilight shadows
I can actually work back from what is working with my dolphin, which works, to figure both of those issues out
oh there we go
just had the rotation wrong
I don't know what I would do without renderdoc
I guess generate textures from shadowmaps manually
oh I should maybe do that anyway
see the shadowmaps in real time
You can draw textures in imgui with Imgui::Image
You can make a walmart RenderDoc with it
nice
Belive it or not there is an alternative to it. It's not as easy as overriding a method though. You have to mess about with phantom references n stuff but it's still possible
and wiz a little swizzle magic you can make the reddish looking depfthsphf map, look as white as in renderdoc, and a bit of TextureView shmooh
Yeah, alpha is a bit of a pain with the default backend
Maybe you could modify the backend to support extra stuff in imgui's image handle
Sorry, getting ahead of myself hehe
Oh yeah if your drawing your fbo attachments in ingui you have to flip the uvs
Also on the topic ealier too. If you depend on destructor order. Then you probably shouldn't store the object as a global
Bjorn is using zig so I don't think it's a problem
That's one of the few cases where I'm fine with a singleton
I've hear good things a out zig. Just havnt given it a look yet.
It seems comfy
I gotta figure out how to do this too
I used zig once and unfortunately I needed to do a bunch of vector math, so the lack of operator overloading didn't feel nice
Everything else seemed cool
aww no operator overloading would probably make me feel like im back in the java days x.x
you can just pass those in the ImGui::Image() call no need to flip anything
I think zig has some built-in vector and matrix types now so if that's some consolation
yeah theres params in the call that have the uvs, by flip i meant those two params
But that's not as good as just letting you overload the dang operators
that stuff is for simd
sounds janky
and like it's probably not worth the effort
its java, its all jank built on top of jank
I never used operator overloading in the past so I don't have a problem with writing more characters of code to do that
zig is overall more verbose than C or C++
I definitely like zig, but I am fine with relying on a very limited set of C dependencies and updating the compiler every day and dealing with any backwards breaking changes and the overall verbosity of having to explicitly cast and various C++ sugar that lets you avoid writing code explicitly
I am also fine with not having very good editor tooling etc
so if you are ok with not being able to depend on libraries, frequently chance of backwards breaking changes, poor editor tooling/tiny niche ecosystem, no C++ features then you may also like zig
most of those issues are shared by all new languages
I honestly kinda actually dislike operator overloading in most scenarios
ESPECIALLY assignment overloading
I sorta rely on keyword patterns to know what’s doing what
Using operator overloads sorta, breaks the keyword patterns I’m used to
And assignment overloads just drive me mad
If I’m gonna use =, I want it to behave exactly how = would
I don’t want to have clamping logic in my = operator or something, and I don’t expect it to write stuff to the disk
vector/matrix/tensor math are like the only things I like operator overloads for
I prefer imperative readable code, without hidden control flow
operator overloading is hidden control flow
it's why it's not supported in zig
it's one of the main goals of zig, so it will never be supported
Well you have the operator right there! it's not hidden
. Maybe I'm just to used to C++ but I always read an operator as a function call
I find Vector and Matrix math very hard to read without operator overloading
Yes it's terrible without
We have a very old codebase at work that started in C, but then they added C++ on top of it, so some files have really messy C matrix math and some files are super nice C++ with operator overloading
you just roll the dice
I just concatenate my matrices one at a time each line, it doesn't really make a difference after it's compiled
I don't think it's hard to read at all
I could create a function that is concatenate and takes a slice of matrices
I don't really feel the need to
actually think that would compile worse
I think banning operator overloading was not a good choice but I understand the rationale
Any feature can be abused
theres no more guarantee that the function add() does what you think it does than the operator + does
idk, I don't have any problems multiplying matrices in GLSL with the math operators and the zig way doesn't bother me either, I did like how the stroustrup book overloaded the << or whatever operator for the book's calculator problem that you built as you worked through the book
I can see why it's useful, but I have had zero foot gun. moments with zig in a year now
it's the same with go, it's a very simple imperative language that doesn't offer enough for you to ever get lost with the question "how do I do this in this language??" for hours
which is the opposite experience I had with Scala for example
you do have the guarantee that the + never does anything you didn't expect though
have to flip the thought around there to understand the hidden control flow, of course functions can have side effects
operators can't
I don’t think zig is aiming for being a replacement for C++ anyway
More of C replacement
Which also doesn’t have operator overloading
I can’t speak for the core devs though or know their intentions and I don’t want to misrepresent them
idk use the language that works for you. 
I sometimes think about how nice it would be to just write C++ with the huge ecosystem, tooling and editor support
If this wasn’t a hobby I would use C++
There’s zero career value for me doing any of this lol
I use ssbos (basically ubos but infinite size and allow writing) for almost everything
I made that argument and people argued against it saying ssbos are slower
My little buffer abstraction makes using ubo or ssbo trivial
ubos go through special memory on nvidia but it's really not that big of a deal
and on amd they are identical to ssbos
if your operator = does something you dont expect from an assignment, then you wrote bad code
maybe it's not your operator
maybe it's the person on the other team
maybe it's from a library
junior developers are a thing
i mean yeah, in most cases you shouldnt need to write your own assignment anyhow
i mean we all write bad code, anyone who claims their code is perfect are wrong
as far as i see it the only reason to have custom assignment in c++ is if you have custom move or copy
I only write good code
afaik zig doesn't have a move, it's always a copy to do assignment
yet no borrow checker smh
idk what move means I guess
in some circumstances it allows you to avoid copying which is good
as I understand it any time I do var foo = bar; whatever is in bar was just copied to foo and changing foo will never change bar
if those are storing pointers then you can change what both are pointing to by writing to their fields
if you have this in cpp then its usually a copy
auto bar;
auto foo = bar;
but the values actually stored by foo and bar are different
assuming you dont do weird reference shenanigans
what is an example of a move I guess? I don't understand
std::string a = "string";
std::string b = a;
so lets say we have these strings
so as expected atm, a gets copied into b
so lets say you know for a fact that a doesnt get used after you copy it to b, this is a situation where you can do a move instead and avoid the copy
so a is now not usable?
in the example its perfectly usable
std::string a = "string";
std::string b = std::move(a);
moving semantically "steals" the data from an object. in this case it means a now holds an empty string and b now contains the pointer to chars that a previously had
here we can tell b to move a instead of copying
why is this useful
optimization
why not just use a
moves are fast, copies are slow
that's not the main reason
moving lets you express certain semantics that don't exist with only copies
some objects are movable but not copyable, for example, because copying them wouldn't make sense
or in the case of many opengl abstractions, where copying the object a lot of the time doesnt make sense
how is this different from just using pointers though
std::unique_ptr enforces single ownership of the pointer it holds by banning copying
so it will only be automatically destroyed in one place
you could do b = a; a = undefined; now b has it
and a goes out of scope or whatever, I don't know, set it to something that doesn't cause UB
I kind of get it, sorry
this is like ownership semantics
yes, exactly
rust features ported to C++
zig doesn't have destructors so it doesn't make as much sense
std::cow when
that and it lets you keep your value types working as youd expect without heap allocating everything
it used to be legal to implement std::string with 🐮 semantics
like if every object you have behaves like a shared_ptr then yeah moves are almost pointless, ahem... java
Move semantics let you describe things that have a unique and uncopyable identity
It's usually not necessary to implement yourself but it's very useful when it is
falls into that category of if you implement a destructor you should implement the copies and moves too
rule of 0 or 5
yeah i see way too much newbie code define destuctors that do nothing and just casually makes their code that much slower
imo a much worse problem is ignoring the rule of 5
Heres some cpp guidelines that cover this very well
The C++ Core Guidelines are a set of tried-and-true guidelines, rules, and best practices about coding in C++
noobs make opengl abstractions with completely broken copy and move semantics
I kind of never transfer ownership of anything unless I'm doing a job on a thread
i legit have this issue come up on the server enough to where if i see opengl code breaking from a mnewbie and i see abstractions, i point em to those rules since thats more often then not whats breaking em
at least I haven't needed to
actually I do some initialization in the beginning of my app and then pass that into another thing and that thing becomes the owner, and some zig std library will allocate memory you then have to free, but you pass in the allocator for that thing so if you use an arena it's all handled
and if you don't, you just know to handle it, the general purpose allocator in dev detects leaks, UB is totally possible though if you get it wrong
I recently went though a code base where the abstractions were so bad.
Some things were default init in the class, some of it happened on the constuctor, some of it happening inside of it, and there was like a cube class which pushed into a vector of a buffer class with broken semantics and was raising exceptions from the driver, its great
Imagine using abstractions
the thing that was blowing my mind is that he had some classes that deleted copies, so they knew they could tell it to not allow copies
but deleted copies on a class that was never in a situation where it would ever be copied to begin with
write everything in a hex editor then, you dont need all these fancy things like assemblers :>
manually connect the wires many billions of times every second
Don't give me that slippery slope bs you know what I mean
im just saying it starts with saying you dont need abstractions, meanwhile ur working on top of so many abstractions
i can think of at least 20 abstractions almost every one of you are building your software on
everytime I want to do something with my engine any stupid abstraction I wrote before I have to undo
I'm going back to copying and pasting code
i usually end up trying stuff and if i hate it i just git stash it lmao
I was like ok I have lighting now let me abstract it so every scene can have lighting without me having to do all this all over
and then oh, I want to have multiple lights and I want those to cast shadows
and then it's like jfc what I have done
this is why I am going to make a game with static geometry and small levels
yeah its hard to make good abstractions when your needs change a lot
every level will just be artisinal shaders and one use everything just for that level
I will do absolutely as little as possible to reuse code across levels
because it just becomes a fucking straight jacket
a lot of my higher level abstractions are tied into the ecs system so its super easy to iterate on it
ecs is cool, but I'm not going to use one
my light struct for example just has a type, a color and attenuation factors
yeah I have a light and material struct
that's a data type
that's not an abstraction imo
idk
thats fair tbh
i just mention it cause a lot of time abstracting tends to lead to having these massive classes and all
ECS is cool and you should use it
would you write Doom 1 with an ECS
sometimes an ecs is overkill, but if youre making something complex enough its absolutely worth using
because that's the kind of game I'm basically going to make
small puzzle escape room levels
if you know what an ecs is, then usually if you're good enough you'll know when its time to use one
Yes I would
i havnt brought ecs into my voxel stuff yet, but i do plan to bring it in eventually
that's fair, I could see using an ECS too
but the main reason that I don't use an ECS is just there's no easy way to port any of the C / C++ ones to zig because they do so much meta programming
i technically already have the ecs library in the codebase, i just dont use the ecs features of it
You can make one out of static arrays
but that's kind of overkill for a small game
Abstraction is good in like
1-5% of scenarios in my experience
And I’m a java person 
I can just not use an ECS and be fine
yeah good luck porting the weird c++ template stuff into another lang
entt specifically is pretty heavy on templates, im not sure if any ports of that exist
ECS can be overkill but that doesn't mean it's bad
I said ECS was cool though, I never said it was bad :P
nobody here was calling it bad tho?
Well you said you wouldn't use it for something like doom 1
What is ECS
entity component system
oh like what unity has?
yeah probably

high level you have entities and they have components and you query components in systems that have side effects/behavior
ECS is just splitting your game into pure state and pure logic and creating game objects by composing types of state
implementation detail is it's a bunch of arrays of arrays
ECS is great for any problem where objects are combinations of smaller things rather than fitting into completely separate categories
oh
the performance implications of that offend me
No the performance is amazing
ECS are fast af
thinmatrix has a decent older video about the general idea of it, gives a decent enough visuals
small amounts of collocated data queried sequentially goes brr
Yea
while not really talks about ecs, it goes over why giant class heiarchies are just next to impossible to manage over an ecs
I’m the sorta person who will get annoyed about something taking nanoseconds too long 
implement an ecs correctly, they will easily outperform, dare i say nearly all other methods (of grouping entities and behaviors)
ECS is basically cache optimized by default
To make it maximally optimized it takes more work but the naive implementation is like 90% of the way there and faster than most anything else you'd come up with using other architecture paradigms
Yea class hierarchies are painful 
yeah in that video his example was like 7 subclasses deep
and i assume it was based on his real code at the time
my class hierarchies usually only go like 2-3 deep
i mean it was a java codebase and when its so easy to make a subclass, i cant exactly blame him for using it
I mean my stuff is also java, so I have the same conveniences as him for that
tbh the only part of java i miss is easily embedding assets
oh and their standard library
The standard library is something I wish I could ditch most of the time 
I don't use classes at all
yeah but compare it to c++'s standard library annddd yeah
Or almost at all
^ c functional purist?
i hope you actually mean classes and not just the class keyword lmao
Yes I don't use member functions
I struggle to find something that is suitably verbose, with a suitably large collection of libraries made by users of the language, that won’t explode because I looked at it too hard
i suppose, i was always able to just throw the files into the classpath and java just sorta knew about them
and majority of the time it will happily load those with inputstreams
Java’s dependency management environment and ecosystem is pretty nice
Need something? Someone’s made a library for it
One of the highest compression ratio png encoders I’ve seen is a java library
i never got crazy involved in the tooling but what i have used is very nice admittedly
If not actually the highest compression ratio png encoder I’ve seen
Gradle is a dumpster fire but compared to some other tool systems it’s great
the only "proper" tooling ive used for java is gradle (which i hated) and maven
meanwhile theres no c++ tooling out there that i enjoy or know of
Those are about the only ones that are still used nowadays as far as I know 
i still maintain some java stuff and it uses maven and i dont have much to complain about there
I… don’t like how maven is xml based
I also don’t know if it supports actually scripting your builds
eh i could care less if its xml or yaml
just please we gotta get away from using json for everything
but json is nice… so long as you don’t need to look at a large file
And yea yaml is a solid choice for human facing data formats
json is NOT NICE, who told you that, have you everrrr tried working with it
oh toml is aight too
I have written jsons manually
Many times
I am getting so good at renderdoc
oh no I didn’t say I enjoyed it, but json is not meant to be hand written truthfully
it's like boom snap, got my data, confirmed it, move on
like I get a capture and see the output in like 2 seconds
no more of this clicking around
love seeing people learning renderdoc, its like ur moving on from grade 1
json is meant to be used by the computer
… or at least that’s how I feel about it
I mean json doesn’t even support comments
offspring of the devil, javascript
gson is also a very convenient thing to use
oh that brings me back, i remember using that, but after writting yaml, im never choosing json for my own projects
Oh wait
anyhow ima clock out of this chat since this is convo is taking away from bjorn's stuff here
https://github.com/GiantLuigi4/Smaller-Units/blob/1.19.2-mutliloader/Common/src/main/java/tfc/smallerunits/utils/selection/UnitShape.java
sanity is not a question when talking to me
ofc its minecraft related smh
I’m the sorta person to casually reverse engineer a system to go implement something more akin to an older version of the system into the newer one for performance reasons 
ok I have found the most optimal positioning of my lights and objects to test my shadow maps in all 360 degrees
that gets me all four sides and up and down

I got ubos, I got a good 360 I can fix all the shadows, get shadows working with texture binding and then figure out my bindless problems
this is a plan
I am making progress
someday this will work
just my up and down are fucked
bam
fixed
So there’s this optimization you can do
Where you only update shadow maps every N frames
Might also be able to do some reprojection for slow moving light sources
I wouldn't bother with such things until your game is bottlenecking
I really think so
though I know for a fact that my game will bottleneck on lights 

then, if that is possible, smooth shadows and I'm done with this scene
hrm I just do it every frame right now, I'm not worried about performance at all with these learning scenes
just getting it working
I bind 12 framebuffers every frame 
but I should totally go pro I got what it takes, obviously
back to it
Hm actually maybe I can avoid that
Makes sense
well a lot of shit is fucked, but it kinda works too
a ridiculously high glPolygonOffset seems to have made the worst of it go away
you should add a floor to make shadowing issues more apparent
btw shadow mapping is a constant battle between too little bias (causing shadow acne) and too much bias (causing disconnected shadows/peter panning)
the worst case is when the incoming light is almost perpendicular to the surface normal, as you observed. you need an infinite amount of receiver bias to deal with it
yes, I searched this server for glPoygonOffset and found where you had discussed it previously
#graphics-techniques message
I found that diagram really helpful, thank you
although in that case they were using PCF and I am not right now
searching this server for stuff is more helpful than asking google or ai btw
what does receiver bias mean?
one technique to alleviate acne is to simply offset the depth of the receiver (the surface being shaded) in the fragment shader
oh yes I tried that
it did nothing
I don't know what values to use for these things
I don't understand the math. I read and I don't really understand it either
maybe because it's late
glPolygonOffset is different from a receiver bias btw
I saw a really nice visualization deccer shared using glPolygonOffset
but the receiver bias might not have worked for you if you didn't have a factor based on the dot product of the normal and the light
oh I see
at grazing angles the receiver bias approaches infinity
I see
my math books go into shadows
I haven't gotten to those chapters yet
so if you do a dot product you are getting the projection of the light onto the surface normal
well we're just using it to get the cosine of the angle
right because they're both normalized vectors
oh I can drag the control point in that visualization
I'm going to smooth out the shadow and fix bindless and I think I'll call it on this, I have more to learn about shadows for sure
nice progress, you're learning really quickly
What exactly is glpolygonoffset for? Or some use cases of it?
Oh nvm. I found a discussion here. Ignore me
I may be wrong but it offsets the depth buffer value to be closer to the camera so that on sampling there’s less chance of a precision error where we sample behind the surface and erroneously draw a shadow
Are you not using one for your cascading shadowmaps? And that works?
I think maybe my high 4K resolution is part of the problem
I'm not using it. Never seen it covered. But as far as ive been reading it's main use cases are shadows and decals
And the function itself can offset polygons based on their normals if I read it right
I literally cannot have decent shadows of any kind without it so no idea how you aren’t using it
I've just manually calculated biases based on normals
But on the recieving end. So same sorta effect but slower id imagine
I think that’s a different issue
Wouldn't the bias issues be improved by offsetting the polygons in the shadow pass?
Only certain parts of it. The shadow stuff isn't public rn
You’re using textProject with a bias based on cosTheta?
No idea what textProject is
How are you sampling?
But the bias is based on the dot product from the light direction so more or less cosine
You are you doing perspective division in your shader code?
Oh your shadows are orthographic
I'm rendering stuff to the shadowmap as is. No offsets. And when it comes time to shade objects I transform the fragment into light space. Sample the shadowmap and bias the depth based on the dot project of thr normal and light direction
And if it's in shadow. I don't do thr lighting calculation.
This skips over the technical detail of cascades and pcf filters etc
Oh you bias the output of the result of sampling bias cosTheta as in sampleResult * cosTheta? + ?
the dot product of light dir and surface normal is cosTheta
It’s used by your light code too I imagine
The bias is basically that yes and it just gets applied to the current depth
That doesn’t do anything for me I tried that
The lights don't use it at all. It's only used by objects recieving shadows
What lightmodel do you use?
A modified Blind phong
blinn phong and phong use cosTheta
I'm not sure if it exactly has a name but it's based on that
Are you doing a dot product in your light code
Does it happen to be dot product of the light direction and the surface normal
All my vectors are unit vectors
I mean that gets calculated but that's not what's used in thr final calculation
Dot product. Remap the range then clamp
Are you using an ortho projection to generate your shadowmaps?
Ambient light is handled a bit differently then blind phone too but it isn't significant
It'd a directional light so yes ortho
Ambient light doesn’t consider light or view direction
But its part of the light model
I'm not seeing how this is relevant to the shadowmap stuff
I think that’s the difference I use a perspective projection for both directional and point light shadowmaps
It results it in perspective foreshortening
That makes a huge difference?
Yeah in ortho that isn't a big issue
Not an issue at all afaik
The challenge with getting ortho looking nice is biases and very carefully calculating shadow boxes
In perspective projection further away objects are smaller and have fewer fp precision
This is a problem with any perspective projection
Yeah in ortho you still perspective divide but it doesn't cause foreshortning
The range of precision in far plane is bad unless an inverse z matrix is used
With point shadows I could see that being a problem
Which requires a flipped depth buffer
This all makes sense now
I use perspective with my directional light
Because that’s what the book did
That's weird
It’s hard
Cause directional lights are considered parallel so a frustum doesn't exactly make sense for it
But apparently you can make it work
Your ortho near plane is how far from your ground?
It moves with your camera frustum so it isn't based on where the ground is at all
But where is the near plane? Just the top plane of your view frustum?
Basically it calculates a box to fit the frustum. We do some extra calculations to fit it in a certain way and we move the z near plane back some distance to make sure shadows are captures from stuff behind the camera
But if you think about the scene from the pov of the light. You're visualizing a near and far plane.
#1286757925863424063 message
I have this lil gif I make that actually previews the shadowbox
Cool thanks for explaining all that 
The problems I'm currently having is bias issues and some temporal stability issues
And pcf issues but i could care less about that rn
I an going to duck these issues with small levels with static geometry lol
But to make shadows look better for the sun. You basically divide the frustum up into sections and fit multiple shadowmaps into it
And you do cascades with it. Which makes a huge improvement for thr same resolution shadowmap
Yes makes sense
If you're light source are static you can get around almost all temporal stability issues
Do you use multiple passes and multiple framebuffers?
It's one fbo. 4 passes
Basically one depth buffer is split into 4 sections. And using glviewport I draw into the 4 sections
Yeah just clever use of the depth buffer
This method was targeting older hardware so there's probably a better way to do it
I need to read the spec on how to use multiple attachments
But it means the only state that changes between shadow passes is the viewport
It's not too hard to do
You’re working with others on your project?
I am using 12 fbos atm 
I am but I'm the main one working on code
I have someone who helps with Linux compatability improvements in code sometimes but besides that the code base is my thing
Yep
Have not heard of it being used in shadow maps but yeah it offsets the poly in the depth buffer
I… think it’s just a flat offset, don’t think it cares about normal vecs
Not their normals, but their slopes. There are 2 parameters the function, one is constant and 1 is slope dependant
This function is also commonly used in modeling applications, let's say you wanted to draw an overlay of edges on top of a solid model
I'm totally unsatisfied with my understanding of glPolygonOffset and light incident bias so instead of rushing this scene to be done I am going to create a scene just to visualize glPolygonOffset and also add some visualizations to my shadows scene to understand the light direction angles on surfaces
I am unsatisfied with pasting some code that fixes problems in a magical way I don't understand, when I can just spend a little bit of time to understand them and learn how they change rendering
reading the spec for glPolygonOffset is just incomprehensible babble because I guess I'm too ignorant
I am confident that the subsequent shadow and lighting related chapters in my math books I haven't yet read cover this
but glPolygonOffset and textProj are like openglisms
Yes, but there are equivalent isms in d3d and vulkan
that makes sense
there's so much I had to learn for this chapter, first time using fbos, first time using more than one rendering pass, first time using depth sampling, first time using attachments
This is the same concept so you may get more insight here
this is actually a really nice explanation
If an application renders a wall first and then a shadow
this is a curious statement though, because the wall's fragments would change the color in the way I'm doing it, I'm not separately rendering shadows
Yeah don't worry about that, depth bias can be used in multiple ways
Decals for example
DepthBias and SlopeScaledDepthBias are such nicer names than gl's "factor" and "units"
Basically yeah, same thing
I could call anything factor or unit, it's like calling things type and item
This is quite an old feature of GL, im not surprised it has jank naming
Even vulkan has better naming https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/vkCmdSetDepthBias.html
yes
reading the spec actually makes more sense now too
I'm going to make a scene to visualize what it does
opengl is a library built on deprecation
we should all be going 4723h54m37s's route and just write assembly renderers
assembly to spirv when
I might die before I finish a hello triangle if I tried that
it would probably be a bit of assembly
The amount of C ABI would be lethal to write
Opengl is a specification built on depreciation? (Aka compatability)
Yall are being a bit extreme
OpenGL is in fact a modern API with a bright future that everyone in the ecosystem is excited to build with and build additional tooling and drive support.
it's the tip of the spear
the best possible choice
Expecting APIs to be in active development is web brainrot imo
GPU drivers will support GL 4.6 for longer than GL has existed for sure
yes
glPolygonOffset
it's just a depth buffer manipulation
so it's useful for decals to render something on top of a surface by adjusting its depth buffer so it doesn't end up partly inside the object
I guess this is how you can build a wallhack type deal outline too
so stencil a mesh to produce an outline, then change its glPolygonOffset so that it appears through other objects
it's interesting how I need a 20k range abouts to see it work
that's I guess related to my clip matrix
I'm not sure
that's the maximum depth slope above
this is fucking with me
I think it's probably more instructive to look at renderdoc than look at the visuals
have interactive stuff usually explains stuff to my brain better
glPolygonOffset is funny when the depth buffer is floating point
and by funny I mean horrifying
I don't use floating point for my depth buffer attachment
I saw someone say not to do that
yeah, just saying
i might be missing something but arent depth buffers always float?
floating point depth is good for your main camera though. it lets you do infinite reverse z
they are either unorm (fixed point) or float
you should use unorm for shadow maps
ohh i didnt realize, DEPTH_COMPONENT24 was a unorm thing
opengl has bad naming for formats
i should have have known this ages ago since i know about the depth float formats
huh good thing i rarely if ever use the floating point depth formats then
it does have a place as I mentioned
ive done infinite z with the unorm format but i probably didnt pay close enough attention to see the problems
is the only thing I see in renderdoc that's different
the data is otherwise all the same
i mean the gl state yeah makes sense, you should have different stuff written into the depth buffer then no?
oh yeah
this reminds me i should be able to make my shadow passes faster with the multi viewport stuff
multiviewport stuff?
no
this is a common misconception
there is nothing faster about multiviewport
the fastest way to draw a shadow map is to draw nothing in fact
fr
(you can cache shadow maps)
VSM at n0
okay assume i have to draw the shadow map, rn i draw everything in the shadow map 4 times, wouldnt i be able to just draw it once instead if i use the multiple viewports?
VSM is too powerful
what are n1,n2 and what is VSM
sure, are you actually saving anything? no
the amount of work on the gpu is the same
you might save cpu overhead though
even then it's just 4 indirect calls vs 1
you only get a measurable CPU speedup if you're doing basic glDrawArrays
n = number
VSM = virtual shadow maps (or variance shadow maps if you're a pleb)
I am a pleb
I'll allow it
was gonna say this is basically what im doing atm, i didnt get into stuff with indirect draws
variance sm is not too difficult to implement
n1 means number of shadow maps what are we counting?
you still don't want to do multiview because eventually you're going to go indirect
it's a ranking
multiview can only save you so much
oh tier list
so basically just do the 4 indirect draw calls and change my viewport between them
yes
fair enough i suppose
or even just have a layered shadow map if you're not doing fancy stuff
I thought this was a graphics jargon thing and it's just a reading comprehension thing
i would use the layered rendering stuff but i dont think theres a way to set the layer in the vertex shader thats in the core spec
and i really dont want to have a geometry shader for that
yeah gl is sad like that
have you heard of our lord and savior 
eh swapping to vulkan for me would slow me down in terms of development time, plus i just simply dont need the performance gains vulkan provides
i really should just a better method to do shadowmaps though
the better method is glMultiDrawElementsIndirect 
erm how do you render to multiple shadow maps
for shadowmap in shadowmaps glMultiDrawElementsIndirect();
wahoo
its basically just fitting multiple shadow boxes to the furstum and its just a couple small things to help looks
its nothing fancy and im not at all vested into using it forever
You could make your transformation matrix and indirect buffers such that it renders the whole shadow map atlas as a single scene 
yeah I'm just drawing in a loop to do my multiple shadowmaps atm
it was just my introduction to getting shadows working and i crave better shadows lmao
not sure if there was a better way
have you heard of our lord and savior VSM
vsm and pcss are two things ive been wanting to get that workin
oh and shadow samplers, i keep seeing them in the spec but never tried them
oh i aint missing out then
would the gpu gems 3 about summed area vsm be a good place to start?
I don't like the bad vsm
light leaking and self shadowing errors are nasty with bad vsm
yea in shrimple scenes it's fine
i mean good luck avoiding artifacts with any shadow map method
but with high depth complexity you just die
uhm
have you heard of our lord and savior VSM (the good one)
sampler2dshadow
i have but nobody suggested a good resource for me to learn about it
it's like a one line change
eventually it'll come out
textProj
and what about completed stuff that i can follow, discord threads are horrid to navigate
go read this https://therealmjp.github.io/posts/shadow-maps/
virtual shadow maps not found, useless article smh 
ill take actual articles about stuff over stuff that isnt documented well
we made VSM with our blood and tears
remember when we were struggling to understand how to go from virtual UVs to physical UVs Jaker? 
hold up I gotta find that conversation
there were many challenges
sounds like niche stuff that is unecessary
I originally proposed rendering each page as a separate bindless texture
oh so the VSM is making one gigantic texture and then using lookups to index into it
this avoids additional passes?
hrm
it's about applying the concept of virtual memory to textures (so you have virtual textures) and then using that to minimize memory consumption
and it will consume basically a constant amount of memory no matter how many shadow cascades you have
xiao hong zhu
lao gan ma
need some lao gan ma on my vsm
memory consumption or memory allocation? how does virtual memory reduce consumption, reducing memory consumption would involve compression? sorry if this is a dense question
it achieves better resolution with less memory overhead
so for example a classic VSM setup is to use 16 shadow maps, all of which are 4k in resolution
in the context of shadow maps, you can analyze the visible scene to see which pages from which shadow maps need to be allocated
if those are D32_SFLOAT shadow maps they would consume 16 * 4096^2 * 4 bytes of memory (1 GiB basically)
being able to allocate individual pages (not whole shadow maps) gives you the granularity to minimize memory usage
yeah I allocate a lot of memory with my 12 4k shadowmaps
yup, in the classic case you allocate only 64MiB to achieve 16 4k shadowmaps
it's complicated
here's a cool presentation about shadows
https://research.activision.com/publications/2021/10/shadows-of-cold-war--a-scalable-approach-to-shadowing
consider these things a curiosity rather than something you need to implement immediately
gotta be cool to have an entire team of graphics programming experts building just the shadow maps for your game's rendering engine
they could've called us smh
they couldn't afford it
so what's cool
in renderdoc is you can hover over the pixels in the texture map
and get the actual values thank god
and see the math
the output from the math
but maybe it's deceiving because it's a float
hrm
I'm trying to understand what I should learn from this glPolygonOffset visualization
the constant I understand
the slope is harder to understand
by changing the factor parameter, the angle of the surface changes its position in the depth buffer
the factor parameter changes the position of a surface in the depth buffer given the surface's slope
so if I increase the factor the angle of of a surface results in the surface being given a greater distance value in the depth buffer
so factor * angle + r * unit = offset
m is the slope of the angle
I get it!
hrm
and this is useful for reducing shadowacne because I can use it move the surface further into the depth buffer so that when I sample the surface as part of the render pass it will appear closer to the light than what's in the depth buffer
and this can cause peter panning because the actual visible surface is now at a non-zero distance from what's in the depth buffer
hrm
so the reason I saw artifacts
was because it was self shadowing
and I have to offset it just enough so that when I sample it the surface that actually is visible to the light doesn't test as being a more distant value than what's in the depth buffer
I'm going to add these sliders to my shadows scene
that seems good
except when there's movement
hrm
ok
that shadowing while movement happens kind of makes sense though
that's also self shawdowing
the geometry is out of sync with the shadowmap for a frame or something
I don't know how to fix that
let me just skip a frame?
that was a terrible idea
so
I fixed it
I now generate all 12 shadow maps twice in a frame
before a draw and after a draw
but only if the light and objects moved
setting the polygon offset and the full depth pass twice a frame when the lights or objects have moved
jfc that looks nice and smooth
Factor: increase depth offset as the angle between the camera and surface normal increases
Constant: constant depth offset
Yes
Spheres are the worst case for shadow artifacts hehe
Try a bigger, more diverse scene
the final boss
yes eventually want to do sponza and all those and the deccer cubes
Is the dolphin a triangle mesh?
yes an obj
I wrote my own very simple obj parser
idk what I'm going to do for gltf yet
my options are cgltf, write a C++ lib to use in my engine that uses fastglft or write my own gltf parser
they're all kind of bad options
I'm telling sean
oh wait fastgltf is c++
yeah cgltf is probably going to be the easiest to use then
yeah, cgltf is kind of bad though
continue using obj 
two-star programmer
imagine using ** for a format that heavily relies on indexing
cgltf_size cgltf_mesh_index(const cgltf_data* data, const cgltf_mesh* object)
{
assert(object && (cgltf_size)(object - data->meshes) < data->meshes_count);
return (cgltf_size)(object - data->meshes);
}
Consider that if you don't pick one of those 3 options gltf then your next best option will likely be to write another parser for some other format
that's true
I should test if those functions work in zig
and if they do just go with cgltf
I used IQM which is basically like binary .obj but supports animation
It does have an example you could copy but it's still probably more work than just writing some abstraction over cgltf
Just standardize on an output format that your engine will store and just have a function that takes a gltf and returns that format
ok well gouraud is not going to get any shadows :/
hrm
maybe I need to remove ambient from the lights in the shadows too
in gouraud
that doesn't make sense
idk, good enough for gouraud
Looks good. I wouldn't worry too much about fixing the tiny artifacts. If you look closely, most games have them too
yeah that's true
hmm the latency between the cursor and imgui is sus, but maybe it's a recording artifact
oh you mean how the cursor is always ahead of the drag handle?
it's really like that
this is all through renderdoc
nah it's like that without renderdoc too
is that not normal?
hmm let me see
literally rendering only 8 vertices in this scene with no lighting or anything
the cursor is still ahead of the handle
even when I go slow
I recorded that on my crappy 60hz monitor
with double buffering I think
anyway it's not a big deal or even a problem
I don't have evidence, but I think the gpu can't power the pixels
L
should’ve used C++
do you search this server for usages of gltf?
I was searching for something else and found that by accident
what was that something else
looking for users with my name
maybe I will get tired of zig and rewrite in C++
I don't think so though
I would definitely use fastgltf if I was writing C++
me too
idk I might use it with this project too idk yet
Reduce your resolution to 1080p through windows settings, see if that helps
nah
it doesn't work
that's what deccer says he does with his, he has a smiliar laptop
it doesn't scale well
idk why th people decided 4k monitors should be more common on laptops than on desktop computers 
the only differences with a 4k monitor on a laptop to me are
- the device runs slower
- the device uses more battery
- text is basically unreadable unless I reduce to resolution to 1080p in windows settings
Which… I’d imagine a lot of people would have those same complaints with 4k monitors for laptops, lol
it's punishment for just looking blindly looking at a spec with a higher number
and pressing the buy button

nah macs have a lot of pixels
and I wanted something mac like
and dell didn't deliver
My laptop’s a gaming laptop and it only has a 2k monitor with a weird aspect ratio
The weird aspect ratio is eh, but the 2k monitor is relatively nice
I use it as ~1080p because I want to be able to read text 
but it performs comparable to my desktop computer
A lot of programs I use don’t acknowledge dpi, and thus don’t scale for 2k or 4k monitors
The text should be more readable on 4k
If it's too small, increase the scaling
the default scaling is readable on my laptop, it's just a performance issue, readability is an issue with imgui apps that haven't applied scaling themselves
the resolution is a performance issue
anyway I suspect it is
I don't actually have any evidence other than a blank glfw window that just calls clear color maxes at 500 fps
when using the full window resolution
and the smaller the resolution the more the fps go up
a max 500 fps for a blank window seems to indicate poor hardware performance yes?
at 4k
it's all spent in swapbuffer
2ms to blit a single framebuffer is not a good sign
right
the laptop is otherwise really good
well there are touch screen issues
I think given I have an nvidia gpu pc my next laptop will just be amd linux
framework 16 or something
my goal is to get through the books I have and then if I make it maybe that will justify the purchase idk they're not cheap
I can't work on a PC and be glued to a desk I am more productive on a laptop
too small
app doesn't support that
bad app
also fonts just look
off to me at 2k res for some reason
Higher resolution text should always look clearer in an app that correctly respects content scaling
I should really go pro
don't look at my shader code though
it has a lot of if statements
float bias = 0.0;
float not_in_shadow = 1.0;
float normal_offset = 0.5;
if (i == 0) {
if (f_can_get_light_from_z_pos_0 < normal_offset) {
not_in_shadow = textureProj(f_shadow_texture0, fo_light_1_z_pos_0, bias);
}
...
super professional
unreal recruiters breaking down my doors rn

hey it works
you have caused me to start going through LearnOpenGL myself
yes I saw you were active in your thread
I gotta lurk all the unread community threads
been super busy all day
I had a bug where I was shadowing the wrong direction
so that's why I added the normal check
it's not perfect but like
it's just a learning scene
I'm good, I did it, we did it, we have shadows
what does that even mean? 
hrm I lost my capture afte nvidia driver reboot
well actually I only fixed for one lighting
I can show you
that's broken
that's fixed
huh
next thing for me is textures 
(I'm like 90% done, just need to install it into my shader)
good job brain
install is not the right word there 
conveys the point but like
nice
I am going to use this picture for this chapter's learnings on my github readme, it doesn't look like much but it was the hardest thing to get right
that's applying the shadow across three axes onto a sphere
sun + two point lights?
no sun here
it's six shadow maps per light
like a cube encasing the light
maybe that was dumb idk
oh like three faces of the shadow cube
I think so
I didn't verify in renderdoc when I took the screenshot
it was a cube there instead of a sphere
hmm you could color each shadow differently to check
so basically it's seamless
it's not actually, there's definitely a problem there at parts of the diagonal
but it's good enough :P
seamless enough
if I wanted to spend more time on it I could make it better
my frag shader is awful
next time you write it, it'll be better
yes
I still think you should load a bigger model
there's still artifacts, but which for a game I will want to get just right
There are some good objs on casual-effects.com
I will, I have tons of progress to make still, I'm not done with shadows yet
it's just learn a little bit about this, move on to the next, come back around learn a little bit more
after my math books I have four books on just rendering, and then a bunch of vulkan cookbooks
wow
I have a pile of books too, but they're collecting dust 😦
you already read them?
I read a little of all of them
nice
I need to read them fully
you know a lot already
Math is my weakness
you work on graphics at AMD?
oh no I'm sorry
das alot of books
It's all good, I was looking for an out anyway
I wish you luck
I'm having fun working on my renderer
I should've used this free time to read those books lol
I should go through math textbooks too but I don't think I have the discipline to teach myself college level math beyond what I already know
my degree is social science, I am anthro major and have a library science masters so not a lot math, I like learning the graphics and physics math though
I'm definitely not interested in math for math's sake
just to get stuff done in a game and that's it
I do like math a lot
Same, but sometimes I want to understand papers better
I just need it to be useful
Yeah having a use for it really makes you keen to pick it up
I didn't like math classes, but then I discovered graphics programming and now I wish I paid better attention
I was able to solve a shadow problem today because I understood what a dot product does, that felt nice
same!
When I was making a software renderer for a college class, I had a eureka moment when I understood how the dot product fit into lighting
that's a great feeling
gaussian elimination and the determinant matrix construction is basically just a black box to me still, I did think about it while reading through it, and it made sense then, but I couldn't explain it to anyone
for me, it takes multiple reads to understand things
same
and from multiple sources
yes, reading through multiple math books was very so helpful for understanding the look at/view matrix and the perspective matrix
they all had a piece of the puzzle
brain works best when you feed it lots of sources
that is very true
I think Blinn Phong looks better than Phong, at least with what I've done so far
it just looks better, I like the specular better
it does
I was looking at the latest FIFA game because it was being advertised on Steam and you know I think all the shadows in that game are simple projective shadows
the characters are all on a flat surface
the shadows are all highly PCF'ed. I bet those shadows are cheap af
they're all directly beneath the players, there are lights from every direction in the stadium
I bet that game uses 0 shadowmaps
I bet 90% of that game's costs is just the FIFA license
it probably is a single shadowmap
actually idk
2 times mastering thing with vulkan book one on each pile
You’re the first person to notice that
I accidentally ordered it twice
: >
No idea what to do with the extra copy
find one who is also interested in giraffics in your area 🙂 or donate it to the library?
Libraries don’t like donations fwiw
burn it for heat during a particularly cold sf summer day
Librarians curate the books at a library
yeah it's like how museums curate their collections and can't just put everything in an exhibit
so you need to plant the thought into their brains that they should cure their curations by acureately adding a new bok to their curation
well that depends on the library
you can just ask them
most libraries do take books in donations
It’s not pauper house for orphaned books to find parents
They do, but, they don’t like it
i mean that depends if you library has stuff like graphics programming books
It’s extra work and they again curate the books
ive donated mine to my school library
Idk what they do with donated books tbh
They’re usually low quality
And old and very used
I think Americans libraries are different from European libraries
Being a librarian requires a lot of education
I forget it’s been awhile
I think saying vulkan in a community thread summons vblanco like saying gltf summons lethargic 😛
My thread is probably pretty basic for you but always appreciate when you pop in
Probably basic for most people
In a year I will have a game I am working on again
And hopefully it will go better this time
Wait what
You can use operators in glsl to multiply matrices tho
Okay I misread
I read the opposite of what Björn said
Nvm
This channel and Björn is too active
I should read it more often
That’s an insult to Björn :p
