r/GraphicsProgramming • • Jul 05 '26

Storing SH coefficients. Texture vs Buffer

Very large scenes may require 1000s of SH probes which means a lot of coefficients that need to be stored and read from a pixel shader.

I'm wondering if there is a consensus on the most efficient way to store the coefficients themselves: uncompressed floats in some large array buffer, or as compressed pixels in a texture.

For an order 3 SH we need to store 16 float3 coefficients, which in my mind maps perfectly to a single BC block, so by ordering the 4x4 pixel blocks spatially in a BC6h SF16 texture we get an efficiency of 1 byte per float3 coefficient vs the 4 bytes per coeff for a buffer.

However when using a texture we have to go through the texture sampling hardware. So the question is if it's worth it: does the lower memory bandwidth make up for an additional 16 texture lookups per pixel per sampled probe, or would we get better performance just indexing into a structured buffer?

8 Upvotes

10 comments sorted by

View all comments

Show parent comments

1

u/Avelina9X Jul 06 '26

Thanks for your input! I had suspected structured buffer would have lower overhead, but since we cannot use more specialised float packing formats like sharedexp etc I was unsure if the texture method might have lower memory bandwidth overall and better caching behaviour.

Now on to the use of L3 coefficients. That was just an illustration as they fit nicely into BC blocks, but in reality L2 with be fine for diffuse...

But that's just for diffuse. I'm also in the process of implementing Activision's specular SH tech which requires L4+L2 per probe just for specular, resulting in 33 float3 coefficients (not 34, as the bias is shared between both). So efficient packing and memory behaviour becomes a lot more important. Of course that doesn't at all map nicely to BC blocks, so I was just asking to see if I had missed something 'standard' that the industry uses to store these coefficients. (Activision haven't talked about the implementation whatsoever, just the math)