#Platinum — Path Tracing in Metal
3481 messages · Page 4 of 4 (latest)
#ray-tracing a while back
got it
Nothing at all 🙁
With sampling on emissives allowed
Same without MIS
ye, i clearly have some issue
i gotta fix the sampling on emissives as well
Woah these are the same sample counts?
you don't happen to have gmon on?
I get just a few fireflies... I wonder if I also have a problem
No GMoN
how many SPPs?
maybe some slight numerical instabilities somewhere
dang
that pop from time to time
also, do you use agx?
no I use some scuffed reinhart stuff
exposure + gamma
don't even remember what impl that is exactly
ahh okay, they looked similar enough so the fact it's not identical got me worried haha
I'll get around GT7 when I decide it's worth the time : D
😳
does gt7 actually refer to gran turismo 7?
sure if you can do both in a week
yes
it's the tonemap they made specifically for gt7
ain't happening x)
^

but
surely I can just poke my hand in the rabbit hole, grab GT7 and run away right?
god that gif has horrible quality
have an actually good one
this is me
actual masterpiece that gif
Hey mate @winged veldt I will have an m4 Mac mini tomorrow (however can’t unbox or use it until next week, long story) but it’ll get delivered to my auntie who lives near us along with a cheap wireless keyboard and mouse with no need for a usb dongle
So I will be testing your project with hw rt support finally
Very excited to be on the m4 hype train hah
ooh very cool
m4 is neat yeah
m4 pro is like 30% berf uplift over my m3 pro lol (probably good bit of that is it being 8p/4e vs 5p/6e)
lmk if you find the firefly causing bugs 
i haven't had time to look into it more so far 
Yeah, and well I’m still surprised the m4 isn’t faster than M1 Pro in my MacBook (except it has hw rt so your app will run better hehe) also it supports 64 bit atomic so I can finally run unreal engine 5 with nanite on mac :3
M4 pro however is
Do you like Mac OS? I love it tbh, it’s like the perfect middle between windows which is clunky and Linux which is somewhat obscure and a bit tricky to know where to find stuff
yeah macos is like
most of the good stuff from linux (you have a posix aka real os) but with a gui that works 
windows is just ugh
every version gets worse and since 10 it's actively hostile to the user
my only real complaint with mac is developing for it can be kind of a pain at times
apple really wants you to use xcode
but xcode is ass
Yeah Xcode sucks
But yeah like, windows 11 update bricked my ssd
I'm sorry that happened, that's crazy 
really?
like windows 10 to 11 bricked your SSD?
do you know why?
what is better for you on mac for dev?
I worked on mac years ago but now I use win 10 and dont want to use 11 or more. I use vscodium and console compile
same
clangd is great
slow as shit to index though
no issues on platinum guess it's not that big of a codebase
ime clangd is way faster with neovim as a client than clion
for some reason with clion it would sometimes eat 30gb of ram and shit itself 
never did that with nvim
No a specific windows 11 update, Microsoft deny it but plenty of people have said about it so I guess that’s what happened to mine
Thankfully not my windows install ssd
thankfully? i'd rather bindows delete itself than my data 
Haha yeah I mean the data hasn’t been corrupted I don’t think cos after the drive was inaccessible it came back fully working showing in crystal disk as fine
The Mac mini has landed at my aunties
Btw the “long story” short, we have rats in our home so we are living for a week in a hotel while they’re poisoned
Landlord paid for us to stay at the hotel nearby for a week heh
yeah I'm talking about using it on UE 
for my dingus shit I use crab
r-a is ass
nah it's good ime
for meme projects sure
but it lacks the cargo check diagnostics
anything serious it just shits itself
and cargo check is quite slow
I've had the thing import something with a longer name than use the thing already in scope
yeah it's fast for meme projects
indexing ofc
gopls just consumes GB of memory
go pls
ok 
no not like that 
tbf there's a big gap between meme projects and ue 
well yeah true
I've finally figured out where my fireflies came from... added a check to terminate paths that generate directions sampled from brdfs that were not in the same hemisphere as the geometric normal and they're gone
not sure what the best way to deal with that is, but I'll leave it like this for now since it did not visibly darken the image
hm how did you get those paths?
that feels like it shouldn't be happening but ima check later
i think it's both the microfacet normal and the shading normal deviating from the geometric normal that can cause new rays to skip the surface and go inside/past the object
inside the brdf sample function i only check that wi and wo are in the same hemisphere
which doesn't do anything torwards that problem i think
@winged veldt what's the status on your firefly problem
no updates, haven't had any time to work on it 
wanted to see if i can try some stuff later tonight actually
i'll be posting any updates here for sure
in the scenes that show up with firefiles, do you think you have any materials that have significant contributions from bsdfs involving microfacets
I noticed that pbrt does something in its microfacet distribution thing to avoid numerical problems when roughness is very anisotropic
hm, i haven't added aniso roughness to platinum yet actually
i do technically use anisotropic ggx but the x/y roughness is always the same
it should be really shrimple to implement, but i wanted a cleaner way to do anisotropic rotation than what i used in yart cause that was stinky
but also i have at least some firefly issues outside the bsdf cause the first test i did was to make everything lambertian and some fireflies show up with mis still
here
so i'm gonna look into fixing that first then enable bits of the bsdf one by one and make sure they're firefly free
Btw @winged veldt you tried Liquid Glass yet in your project 
hm yes imgui liquid glass 
Ohhhh sorry I forget you’re using imgui not native uikit
Aw well you could try make Liquid Ass with imgui user callbacks ha
I wanna do callbacks to do 3D imgui
Btw I’ve decided to use pure metal api to make my v2 engine
If my OpenGL engine was a car it’d be a lada from 1976 Soviet Union
Metal engine will be a Bugatti
Gee I hope you do fix your fireflies
It’s an annoying issue
Similarly I have NANs from my ray-cone/sphere based volumetric raymarching but not on metal translation of gl
Only on windows heh
It also happens if you have a light exactly attached to the camera origin heh
Again, not on Mac OS
Guess metal has more protection from nasty black squares
yee i just have little to no time to work on it but i'm trying to make some progress even if super slow
what language will you be working with?
if you're doing c/cipipi i'd recomment avoiding metal_cpp and just writing the metal bits in objc, it's kinda clunky
metal being an objc api is kinda ass for interop tbh
oh didn't know that was a thing, interesting
@winged veldt I wonder have you considered doing some unification of things that use microfacet models (metals, the smooth part of the dielectrics, coat, etc)? I found the way cycles organizes its code is kinda interesting, it has a "microfacet bsdf" that's used for everything involving microfacet models, and it's just fresnel models that are different
like metals use something called f82 tint (if it's part of principled bsdf, standalone metallic bsdf also has an option to use "physical conductor" in which things are specified differently), dielectrics use something else, etc
so things end up imo neatly separated
you mean like, evaluating ggx once and reusing it a bunch of times? i haven't done that yet, it's an optimization
i do intend to at some point, though
no
just moving code around
basically factoring out differences between conductors and dielectrics into types with a smol interface (fresnel models)
oh not sure what you mean then? i already have a ggx class for the microfacet distribution
ah right, i see
and then plugging that into microfacet bsdf which glues that + microfact distribution
that could be interesting yea
i should look at how cycles does it
but also last time i went looking at cycles code it took me days to make any progress, it's not exactly easy to parse
for now i just want to fix the fireflies 
🔥 🪰
fix the fireflies!!! look what you could be doing rn 
man so many cool things i could be girafficsing but no time 
mfw i have work, work, school, school societies, applications for next year, my renderer, bevy, and basic necessities to survive on my list of things to do
and do none of them 
yeah. I got burned on material stuff so I'm just working, not even touching grass (excepting weekends) 
well still progressing but very slowly
very cool
volumes is my next thing to implement so ye
is that actually a volume
looks like it ye, shrimple beer's law with rough glass surface
yart does actually support that in a super hacky way
didn't add it to platinum cause i want to do better
some testing: removed direct light hit contributions entirely, the image is wrong (mis is still assuming they're being counted) but the fireflies are gone
@spice frost i'm also rejecting nee samples where the sampled direction is in the opposite hemisphere to the geometric normal
so basically firefly issues are somewhere in the direct hit part
ah i was also doing that too... my problem was with the brdf samples
but you do not seem to have that problem
kinda weird now that i think about it
those planes shouldn't have interpolated normals that are different from geometric normals and the lights are a simple diffuse
maybe the microfacets can generate reflections that go outside of the hemisphere with high enough roughness but dunno
hrm, my problem now is with the brdf samples when the ray hits a light directly
Could it be the brdf pdf giving you the wrong mis weight?
I'm going to bed now but I can look through your code tomorrow if you want an extra pair of eyes
sure, that always helps
nano's comments have been great
i think i'm onto something here, i clamped the cos / pdf term when calculating attenuation to 1 and the fireflies are gone (still some slightly brighter pixels but nowhere near as bad)
overall brightness now matches naive (right) perfectly as well, was a little too bright
so i think some of my pdfs were too close to zero and the attenuation factor was blowing up (and going > 1)
alright, clamp cos/pdf and also clamping rr termination probability to 99.9% seems to have done the trick
this one is way oversampled (10k) but it shows any bright pixels that are left do go away as the image converges, so they're officially not fireflies™
oh it also destroys indirect lighting 
at least i now know it's small pdfs causing the fireflies
hm, rejecting bsdf samples at extreme grazing angles works well for the veach scene but does nothing for the dragons scene
if you use surface form (judging by that emissive polygon in the cornell box) check denominator
also remember having a two sided light being that close to the ceiling while still having a gap increases variance in my experience
oh? wdym
yea my emission lobe is kinda jank
i usually only ever have emission on diffuse materials with roughness 1 so i didn't bother yet
I done cancer
struct composedBxDF {
// TODO: would be nice if we could put it behind a pointer tbh
Registers regs;
uint8_t bxdfids[5]; // TODO: should be a global ptr
uint8_t regoffs[5]; // same as above, probs interleave the two
uint8_t n;
// uint8_t contribregs;
BSDFFlags Flags() {
uint32_t result = 0;
for (uint8_t i = 0; i < n; i++) {
int regoff = regoffs[i];
switch ((bxdfid)bxdfids[i]) {
case bxdfid::diffuseBsdf:
result |= (uint32_t)diffuseFromRegisters(regs, regoff).Flags();
break;
default:
/* abort(); */
break;
}
}
return (BSDFFlags)result;
}
BSDFEvaluatedResult Eval(float3 wo, float3 wi) {
BSDFEvaluatedResult result = {};
for (uint8_t i = 0; i < n; i++) {
int regoff = regoffs[i];
float contrib = 1.0 / n;
BSDFEvaluatedResult tmp = {};
switch ((bxdfid)bxdfids[i]) {
case bxdfid::diffuseBsdf:
tmp = diffuseFromRegisters(regs, regoff).Eval(wo, wi);
break;
default:
/* abort(); */
break;
}
result = result.Add(tmp.Scale(contrib));
}
return result;
}
BSDFSample Sample(float3 wo, float uc, float2 u) {
uint8_t i = min(uc * (float)n, n-1); // TODO: this is horrid, actually
int regoff = regoffs[i];
switch ((bxdfid)bxdfids[i]) {
case bxdfid::diffuseBsdf:
return diffuseFromRegisters(regs, regoff).Sample(wo, uc, u);
default:
/* abort(); */
return {};
}
}
};
I can now almost have weird bxdf compositions fed by the interpreter.
you need this too
contrib should be read from a register and sampling should consider contribs
wot's this
atm I implement programmable materials with interpreter only
Registers is interpreter state beside the instruction pointer
hey bluescreen I'm ready to try it, what were the steps to get it to run again?
so the program runs and when it termiantes, registers contain values that are inputs to weighted bxdfs
so like e.g.
this funny chungus would make it so the interpreter fills in the values that are inputs to the "shader" nodes here
and the contribution of each "shader" node
which is 0.5 for both in this case
and then the composedBxDF thing would implement bxdf interface in terms of the values in these registers
it's remotely comparable to how cycles' svm (its material interpreter) outputs a sequence of closures, except without unnecessary copies
and I guess also somewhat less elegant idk
tbc I'll also cook up a strategy for using api shaders for materials but interpreter is a much less complex way to approach it imo and also you don't get the issue of waiting for api shaders to compile
still not entirely sure where to fit edfs but I probs just need to thonk a lil
oh hey
so uhh i redid the build a bit cause i'm no longer using clion
so assuming you have the xcode cli tools for the metal compiler and stuff you should be able to just clone the repo and make
oh might have to make configure first
idk what i called the cmake config target
ah right
is that at runtime? or does it compile a specialized shader
it's at runtime
see
bad
next question
I mean it's usable
on steam deck
but it's bad
interpreter takes up a significant chunk of time of an an rt dispatch
you can literally feel each interpreter instruction
but I mean
oh right you're doing realtime too


omg ios provisioning is a nightmare :c
rider keeps saying the provisioning profile isn't valid :C
shrimple, don't develop for ios 
:’(
You know if it wasn’t for the Mac keychain having a billion places to drop your cert files it wouldn’t be hard to do
how badly? 
got it building again, just a cmake cache issue + some include paths changed for mysterious reasons
macos tahoe has enbiggified my traffic lights, now they're no longer centered in the menu bar 
what's the goofy ahh weird outline there
in the corner? just my terminal window behind platinum
some apps still using the old style sadge
fixed 😌
now back to fixing ze fireflies
glhf
@spice frost think you might be right, with the light further from the ceiling i'm not getting any fireflies
overall variance is higher tho
probably because of the additional indirect paths
with more samples it cleans up nicely and no fireflies
that's good, means it's a scene issue
honestly i think ima just make all lights one sided for the time being, i literally don't have a single scene where i want two sided lights
why fireflies on the veach scene though?
try this one 
they're gone 
but yeah those images of the dragon scene after your fix just look like regular variance and not fireflies
given the fix was rejecting extreme grazing samples, probably numerical instability with a very low pdf
or wi.z near zero
so rejecting when cos_theta of the sampled direction is near zero?
i also clamped rr termination probability to 99.9%
to avoid dividing throughput by a tiny number and blowing it up
yea
like 1e-4
but you didn't have the fireflies with a brute force path tracer no? (which also included the grazing angle samples)
no, i think it caused issues in the calculation of mis weights, so they blew up
yea i'm being conservative
makes zero difference in the results
since those samples have near zero contribution anyway
1024spp with one sided light, looking clean
volumes are next? 
nah this is diffuse only, now i have to fix the bsdf fireflies 
then volumes
but hey, progress
small steps
still having major issues with the full bsdf 
can you check in the veach scene what it looks like for varying roughness conductors? i think my fireflies came only from high roughness causing rays to skip the surfaces
still have some fireflies
none with diffuse, though
i'll have to test bsdf lobes one at a time, probably gonna start with conductors as that's the simplest one and will let me make sure the ggx stuff itself doesn't have any issues
I'm a bit suspicious of that tbh
Is it not all a MIS issue somehow?
There are still some mild fireflies even with the rejecting grazing samples
You'd have to reject even harder at like 1.0e-3 if you want them gone and this doesn't sound like numerical instabilities anymore imo
those aren't fireflies, they do go away with more samples
but yea there's still issues
don't think it's mis tho
i've checked that code about a billion times and just do not see what i could be doing different
it's for sure not the nee path cause they go away entirely if i disable light hit contribution
might be a mis issue there, but the weight calculation is correct and there's nothing that could cause it to blow up
so it's BSDF sampling or BSDF MIS then?
yea but honestly idk anymore
this is the light hit path:
if (sample.flags & bsdf::Sample_Emitted) {
if (bounce == 0 || lastSample.flags & bsdf::Sample_Specular) {
L += attenuation * sample.Le;
} else {
// Calculate light PDF, BSDF weight and do MIS.
// Sampling pdf is 1 / area, light sample pdf is power / totalPower
// Because power = Le * pi * area, the areas cancel each other out
// and we can simplify
float lightPdf = (dot(sample.Le, float3(0, 1, 0)) * M_PI_F /
args.constants.totalLightPower) *
length_squared(lastHit.pos - hit.pos) /
abs(dot(ray.direction, hit.geometricNormal));
float bsdfWeight = lastSample.pdf / (lastSample.pdf + lightPdf);
L += attenuation * bsdfWeight * sample.Le;
}
}
the bsdf weight can't go too high unless both pdfs are near zero
and sample.Le is literally just material emission
luma from temu
that's not the issue 
it matches what's used for calculating light power elsewhere
and the * M_PI_F?
i also did end up looking at your mis code and didn't find anything that stood out
light power is le * pi * area
i honestly don't recall why the pi is there
iirc some change of variable but as far as the weight is concerned
it's a constant on both sides, i could remove it from the power calculation entirely and the result would be the same
only thing that could make the light pdf near zero is the distance being very close (distance squared term)
but that would have to combine with a near-zero bsdf pdf, otherwise you just get a bsdf weight close to 1
actually save for some weird numerical instability the bsdf weight literally cannot be >1
so yeah it's gotta be the attenuation
the weird thing is that bit is the exact same as the naive integrator which doesn't have firefly issues
or maybe it does, the veach scene is so noisy i can't really tell for sure
i might just leave like a 200k sample render and go make lunch 
I'm kind of getting these guys too with MIS so maybe it's instabilities yeah
but I don't have any kind of clamping though
at 20k i think it's clean enough to say there aren't any fireflies
that small pink light is oof without NEE
looks like debugging-pink-NaNs everywhere
they are pretty obvious with mis+nee
though, they do seem to get converged away eventually...
interesting is that they're mosty green
how many bounces?
anyway that's pretty much all i have time for atm i should like do stuff 
50 max
and with 0 bounce? which disables bsdf mis right
should be way more than the scene needs
yeah, but i know disabling that works
what's a lunch 
where is cornell_dragons.glb or cornell_dragons1.glb? 
i've been trying out zed as an editor, it's very nice
might pry me away from neovim, even
(this was largely triggered by nvim inexplicably spiking my cpu to 100% when i scroll after an update, and me not having time to debug my editor)
use a nvim distro ?
nih'd config using lazy.nvim is what i've been using
anyway zed vim bindings are top notch
and ironically being a gui editor it can actually make better use of the keyboard
I'll have to try it out
looks like the scrolling issue isn't even neovim, just a massive macos 26 bug 
zed is still a very cool editor tho, i like it so far
apparently there's a funi macos tahoe bug where some new feature causes scrolling performance to degrade over time and eat up all the cpu
the workaround is to restart the app
which is just great for my average uptime of just over two months 
@dense jacinth you've been on the tahoe beta for a while right? did you notice any impact on battery life?
i'm pretty sure it's significantly worse than it was on sequoia
they look the same on my Mac 
or am I blind
we have the same macbook so that should work
uh I had tahoe beta on since the start..... i don't think there was any noticeable degration
fuck seeing this I want to do graphics again
but now I need to do PCBs and build a fucking car 💀
left is more saturated for me, it's rather subtle tho
maybe your display is sest to srgb?
huh
i swear my battery is draining quicker since i updated
doubt it
i need to do uni and random jobs 
still trying to fix the damn fireflies
this is uni but requires 100% of my time
I only did uni at the side so I barely wrote the exams I should've
but that's me being dumb and doing more than a normal semester's worth
did 2 out of 5 I think
got a job in automotive?
i hear it's 
it's not even a fucking job
what was the horrible auto embedded thing everyone uses
intern?
hope they're paying you at least 
nope and nope

ah so it's self inflicted
yes
oh nice
will be going to lund tho
well it is a really good uni
that looks fun tho
well yes but it's also an insane amount of work
basically doing electronics and software for them for that
and i have the slight pressure on me that the last car was the fastest car ever built in this category 
ok i'm pretty sure macos tahoe is actually destroying battery life
like what the fuck is this
seriously considering going back to sequoia even if it involves wiping the thing

can we please return to basic iOS 7 UI
and destroy every piece of React that exists
and only have native applications
our energy usage will thank us 🙏
no more liquid ass for me, i rolled back to sequoia
eat the liquid ass.
not me actually googling liquid ass
How do you rollback a MacOS OS update?
wipe the mac 
oh well, a fresh os install every year or two does help keep things clean
(if you have a time machine backup pre-update you can just use that and it's a one click rollback afaik, but i didn't have one)
Do you still get security updates?
Idk about this rollback thing
I think this also means you aren’t getting driver updates? Like new Metal features?
yeah
apple supports two os versions behind latest
so sonoma and sequoia are still supported
support meaning you get security updates but also new safari, xcode tools etc, so yea i should have the new metal stuff as well for another two years
ie until macos 28 releases
i can only hope they'll have fixed the issues with tahoe by then 
honestly battery issues aside (battery life seems back to normal now, drained ~30% in just under three hours with an external display connected) sequoia ui looks so much better, the redesign is not good
i think the whole liquid glass thing was clearly designed for ios first cause it actually looks and works great on my ipad
tbf the fancy glass effects are not the issue, it's the layout changes to macos that i don't like (mostly making random things bigger for no reason)
it doesn't autoupdate, never has for major os versions
you can check by going to system update in settings
or about this mac
if you haven't updated don't, tahoe needs some time in the oven
or, like, make a time machine backup if you do 
nah that's my work laptop, I'm not going to update and hose my ability to get work done, thanks for taking one for the team
I'm gonna wait a few months or something lol
tbf it's not broken, everything still works mostly the same
I need docker to work
only real issue i had was battery life being significantly worse
ye, docker works fine
I'm going to wait a bit and maybe a coworker or two update and then I find out if it's safe
let them be the first ones
I'm already in enough trouble
but there's also no reason to update because it doesn't even introduce any new features
well, you get a windows vista looking UI
idk it all looks the same to me
back to normal, tahoe is truly ass
liquid ass very optimized
@winged veldt maaaate wtf is happening :C
my specular is static
the world pos is correct, the camera pos changes when I move the camera
but this happens
holy shit this is annoying
not sure what i'm looking at here?
