Daniela
Daniela

Reputation: 179

OpenGL, are unused shadow maps in the shader bad?

Is it a bad idea to have something like this in your shader code?

uniform sampler2DShadow shadowMaps[8];
uniform int numShadowMaps;

With this one could have an universal shader that works for all cases from 0 to 8 shadow maps. Or is it better for performance to have 8 different shaders with hardcoded shadowmap numbers?

Upvotes: 0

Views: 179

Answers (1)

Nicol Bolas
Nicol Bolas

Reputation: 473946

The issue isn't really one of performance so much as taking up so many binding points. Many implementations only allow 16 texture binding points (per shader stage), so you'd be using up half of them just for shadows. Even if they go unused, they're still taking up those resources.

It would be better to use a 2D array texture shadow map sampler (sampler2DArrayShadow). You would still have a uniform to tell you how many array layers are populated with useful data.

Plus, this way you are not hard-coding a limit into your shader. So if you decide that the upper limit of shadow maps is only 6 or should be expanded to 10, you don't have to change your shader code.

The downside of course is that all layers of an array texture must be the same size. So if you need some of your shadow maps to be smaller, you can't do that.

Upvotes: 1

Related Questions