Advertisement

Making my own micro facet BRDF

Started by September 04, 2024 12:06 PM
30 comments, last by MagnusWootton 2 months, 2 weeks ago

So. heres 2 micro bounces, and it doesnt look too bad, but my computer is going so slow i have to stop doing it and get on with other things my computer handles a bit better, besides all this is already done, theres nothing new here, all good game developers know where to get the best shaders from, and this is pretty much just repeating what I saw others do, so its no dif, its fun tho! u get a clay mation type effect from it, or it looks like the surface of the moon, or the floor of the jungle with all the dead leaves, its really nice, very very real! very enjoyable.

so im not sure how to handle all the off legs from the ray tree, so i decided to get all those stub transmissions and dotted them with the normal and got this. (but the reflections stay properly reflected before they dot.)

Advertisement

ok. so theres something wrong with how im doing the light scattering, im getting a really good effect here, Ill take a screen shot of the best frame, but it seems to be phasing in and out of the appealing view, so somethings up - havent got this right yet.

Heres a screen shot of the “good frame”

https://i.imgur.com/nZhDDsV.png

Heres the video of me buzzin' around the “good bit”

So it seems to be changing material properties as I change angles, I guess this could happen in real life as well, but not to this extent, so I've got some calculation wrong there. But its running heaps better than before, So I guess it takes a while to do this, you can't get it on your first day, to make the brill lighting from scratch. or only by getting fresnel and snell done for you, and the rest up to you is a little tricky still.

sorta starts off lovely, soft and fluffy what i want, then it goes hard and reflective, what i kinda dont want.

ok so it looks real now, but its only from 1 angle of 1 little bit of the map… so I wonder what I've got wrong.

Ok. Ive got a result. something funny happened, and I only activated pure reflection then all of a sudden the light went black where it was supposed to be shining on the surface!

I thought I had vectors inverted, but eventually I worked out that all the directions were fine and it literally is purely transmittive for the actual reflection of the light, there is no reflection. only prob is you get absolutely 0 result in this direction except a few glinty pixels here and there, but the cool thing, is toward the light is seems to collect correctly on the edges facing the light, like these bits are easier to scatter and take less computation than the far darker side.

But it could just be bugs, I'm not sure what its going to be, but I can definitely say now it is PURE reflection. this result is good enough for me to be satisfied about that.

Just more bugs to get out, and this is alot harder than I thought to make a cook torrance brdf!!!

GOLD! 🙂

yes it was right! the transmission is dim in this cause its very hard to make it bright enough!! this is 350 rays over 20 marches, only top scatter, so its all parallel with no depth, the ray growth is short and sharp and exponential!! so the shadows arent that good. (it generates lots and lots of little shadows all over it as it goes.)

Advertisement

increased the fresnel ray march distance, and got a velvety surface out of it, this is really slow AND on the RTX3080, so Ive pretty much hit the performance barrier now, but who knows what will happen. the big prob is I havent got much side scatter, If I use a really large dot product light it manages to reflect poorly on the sides, if I use a sun sized light (at dot product 0.7 to 1) it barely reports anything at all. I think I just need more performance to render this thing, it goes really slowly, ive got some ideas tho.

(tighter ray step distance)

You could add an environment map. Currently most of your rays hit a black sky. This way it's pretty hard to work on some brdf, as there is no visual feedback.

JoeJ said:

You could add an environment map. Currently most of your rays hit a black sky. This way it's pretty hard to work on some brdf, as there is no visual feedback.

Yeh, about that… if I make the light too small none of the rays hit it! I'm finding doing perpendicular scattering is where I'm getting the least rays funnily enough, the majority of the scatter seems to be back and forth from the light only.

I could add a sky to it, but I'm digging the dead black at the moment, and its helping me debug the scattering only having a basic sun type light I can vary the radius of.

I'm having trouble with the distribution of the scatter rays over the sphere, I'm trying different depths and how many rays at once, and If I change it, it changes the way it looks. It seems getting 90 degree scatter isn't happening! so I'm trying all sorts of stuff but I'm just out of computation power, Even getting a new video card wont even help that much.

This vid is the coolest one I did. it looks like an ivory type marble on the transmission side, I'll be looking more into this one looks delish.

MagnusWootton said:
Yeh, about that… if I make the light too small none of the rays hit it!

Usually you handle this with a ‘shadow ray’ or ‘next event estimation’ in path tracing, iirc.
Can be as simple as: Pick one (or N) random light (you only have one), trace a ray from the shading point to the light, and if visible calculate it's reflection.
In path tracing you usually do this at every vertex of the path. Even it doubles the ray count, it's much faster in the end because we need less samples to get the same estimate.

MagnusWootton said:
I could add a sky to it, but I'm digging the dead black at the moment, and its helping me debug the scattering only having a basic sun type light I can vary the radius of.

For that you can always turn the sky off. But currently you can't turn it on, so your impressions about the materials reflections are a very shallow view.

MagnusWootton said:
I'm having trouble with the distribution of the scatter rays over the sphere, I'm trying different depths and how many rays at once, and If I change it, it changes the way it looks.

I wonder you mention ray length and sample counts.
What actually matters to model some brdf is the distribution of ray directions.
E.g., for a Lambert diffuse material, the distribution is spread out over the hemisphere, with a higher density on the normal direction and a lower density on the normal plane, as given by the cosine to the normal:


The blue rays would be a proper distribution of rays. So if we sum them all up, we get a good estimate.
For the diffuse material it does not matter where the eye is, which changes for a mirror material, but i make it a little bit rough so it shows blurry reflections like a cooking pot:

Now they are pretty focused, all close to the eye reflection vector.
Again, summing those rays up will give us a good estimate.

So the hard part of modeling some brdf is to calculate such good distribution of rays.
Real world materials are complicated, and you can imagine how the fresnel effect goes from one of those two extremes to the other.

So maybe there is an easier way?
Yes. We can use a uniform distribution of rays, and then caclulate a weight depending on how well the current ray alignes to the dsitribution defined by the brdf. This is much easier.

But the problem is: If we look at my drawn examples, those ‘good’ rays all have a weight of one, so they are perfect samples. (it's ‘importance sampling'’)
But if we use a uniform distribution of rays to model the mirror material, almost all our rays will have a weight of zero, so it was a waste to trace them.

What people do in practice is usually a mix of the two. They choose a function which can generate random sample directions analytically easily, and this function should be pretty similar to the brdf.

Sorry if you knew all this already. Otherwise - that's how you get the most out of a limited number of rays.

MagnusWootton said:
so Ive pretty much hit the performance barrier now

You do not care about performance while you learn how ray tracing works. Or at least you shouldn't.
The primary problem is uncertainty. You're never sure if your stuff is correct.
So it helps a lot if you turn realtime off, and instead accumulate a whopping 4000 samples per pixel. This gives you a noise free image, good enough to draw some conclusions from it, good enough to compare with reference images.
And you also set up soem environment so you can see some relections at all. (You're litterally tapping in the dark.)
Then you can learn all this raytracing stuff. Personally i've used a Cornell Box scene to learn about path tracing. After that i tried the PBR standard material, which looks right but i'm not sure. Still it was fun and interesting, but not realtime. (Did it all on CPU)

Performance is the next step, including topics like:
Accepting samples from nearby pixels and past frames for an orders of magnitudes speedup. (Denoising)
Being smarter about which ‘random’ light to choose. (ReSTIR)
Integrate some upscaler. Quadruples your performance! \:O/ (But also, reduces your sample count by a factor of 4 - just don't tell anybody…)
Put some little crutches below your GPU to carry the heavy weight.
Jensen will love you for spreading the vision. But then he'll replace you with an AI bot.

That's really a lot of topics.
I'm almost happy about DXR being totally useless, since it can't handle LOD, so i don't have to learn all this. Sigh.

hehehe… well, probably you'll get used to my raytracing rant… ; )

This topic is closed to new replies.

Advertisement