3 ms·
Shadows are computationally expensive to generate. First the object has to be rendered to a buffer, and then the buffer blurred, and then the blurred buffer,
by londons_explore 5y ago
Shadows are computationally expensive to generate. First the object has to be rendered to a buffer, and then the buffer blurred, and then the blurred buffer, object and background composited together.
Having many shadows on an object makes this path much longer. I can imagine adding this to a page could easily run out of GPU RAM and end up having to discard buffers which later need to be re-rendered.
End result:. Hot slow phone.
I'd like to at least see a benchmark of this effect before suggesting multiple box shadows.
- jonwinstanley 5y agoI agree that a benchmark on CPU/GPU would be helpful for this effect. However, I doubt you'd end up running out of ram through using this technique unless it was added to a large number of elements.
- MrLeap 5y agoMakes me wish the css filter feature hadn't fizzled. Would be much more performant to do this in a single pass by giving a gradient to a box distance formula in a shader!
- user-the-name 5y agoThat will not generate a visually pleasing shadow, though.
- extropy 5y agoBecause? You could specify any formula you want. Including lookup tables. If you can describe it, the shader can render it.
- user-the-name 5y agoBecause a visually pleasing shadow does not follow a box distance function at all.
- tobr 5y agoThat’s not how CSS box shadows are generated. They only need to take into account the dimensions of the rectangle and the corner radius, which opens up for a lot of optimization.
- londons_explore 5y agoTake a look at the layer tree in the overflow menu in the chrome devtools. You can see which shadows had to be rendered to a buffer and which did not. I suspect the complexity is that some objects can be transparent, and then their shadows get complex.
- tobr 5y agoIf you have an example of how transparency makes the shadow more complex, please give it. I’m fairly confident there are no cases like that. Transparency in the background image or border doesn’t change the shape of the box the shadow applies to, and things like opacity affects the shadow too. The example you had in your first comment is also wrong, as shadows don’t apply to other shadows. There might still be cases where a particular optimization doesn’t work and the browser falls back to a buffer.