guycalledfrank / bakery-issues

Bug tracker for Bakery
4 stars 0 forks source link

request: one more 3D texture in the volume lighting to only store ambient color #65

Open laurentopia opened 3 years ago

laurentopia commented 3 years ago

This is to use in the case of particle systems and flipbooks where directionality doesn't matter that much but number of sample matter a lot due to coverage.

guycalledfrank commented 3 years ago

If your omni color is baked to both direct & indirect, it should be in the volume.

laurentopia commented 3 years ago

yeah, i meant to say ambient, not omni: 1x 3d texture sample is enough to get that, good for particle work.

guycalledfrank commented 3 years ago

Ahh, you mean single color (not volumetric) ambient? If so, I think you can actually just use the first volume texture, just brighten it up a bit.

All 3 3d textures contain L1 spherical harmonics (xyz + xyz + xyz + www), and the first coefficient is actually the "overall color" of the light, while the next 3 add directional variation.

laurentopia commented 3 years ago

oh, so #2 and #3 are delta of #1? That's great, thank you for this info! Is there a function in BakeryVolume to get just that one? Or I just sample _Volume0 with lpUV and the rgb will be that ambient at world posWorld?

guycalledfrank commented 3 years ago

Kinda. Take a look: https://luger.dev/starry/v0.3.0/_images/ylms.png We basically have these 4 values on the top. Basically to compute SH, what we do is: L0 += light weightL0; L1x += light lightDir.x weightL1; L1y += light lightDir.y weightL1; L1z += light lightDir.z * weightL1;

weightL0 is lower than weightL1 by a clever amount, so adding them all together results in full spherical value representation. But as you can see, ALL light is added to L0 (first coeff), so it can represent "single ambient value".

Oh, and happy new year! :D

laurentopia commented 3 years ago

You too :D

I don't understand that so I copy pastaed your BakeryVolume_float and removed sampling of _Volume1 and 2 void BakeryVolumeAmbient_float(float3 posWorld, float3 normalWorld, out float3 sh) { bool isGlobal = dot(abs(_VolumeInvSize),1) == 0; float3 lpUV = (posWorld - (isGlobal ? _GlobalVolumeMin : _VolumeMin)) * (isGlobal ? _GlobalVolumeInvSize : _VolumeInvSize); float4 tex0; float3 L0; tex0 = _Volume0.Sample(sampler_Volume0, lpUV); sh = tex0.xyz; } let's see what happens

laurentopia commented 3 years ago

oh that's good enough I think, I can add something to modulate saturation until it fits in the scene image

laurentopia commented 3 years ago

and i can even use that for stuff that doesn't need that much of directionality like grass image

guycalledfrank commented 3 years ago

Yeah, seems to work. I guess overall white contribution here is much stronger than red, so it's not that colorful with one averaged color.

laurentopia commented 3 years ago

Now I get it L0 is ambient, L1 are orthogonal axis The red came from the fog, here is with 2 directionals at a L angle image I think you should add that Ambient function for those who want to light their particles on a low end gpu (also for the selfish reason that I won't have to re add it whenever you update BakeryDecodeLightmap.hlsl ;)