Problem with spot light (with cookie)

I try to use a spot light with cookie on every character.

But it seems the game can’t handle this. Some objects suddenly stop rendering while playing and on mobile the whole game crashes and script are no longer loaded. What is going wrong here?

Below the settings that I now use for the spot light.

Does this work on desktop?

No errors on the laptop, but the game no longer plays smoothly. I now have 6 characters in the game that would use the spotlight. As an alternative I have now replaced the spotlight for a plane with texture, but of course this is not nice on sloping surfaces.

I think you had that issue on iOS in the past as well, most likely the resulting shader (from the selected material settings/lighting/scene setup) hits some GLSL limit there.

If you would like, report this on the engine repo.

Yes indeed, but I don’t think I knew it was the spotlight at the time. I can just use the spotlight with cookie on just the character of the player so I think it has more to do with how strong your CPU / GPU is. (Or GLSL limit, but I don’t know what that is).

1 Like

Basically what that means is there is a limit on various values used in any shader program (max number of texture channels, vector uniforms etc). And that number can vary per device, so it may work in one device but may fail in another.

Normally you shouldn’t worry about that unless you are doing shader development yourself, or in your case if you are using a combination of materials/lights/effects that hit that limit.

Hey @albertos - that’s a really nice idea, to use a cookie texture to project the character locator onto the ground. However, using one spot light per character seems a bit excessive to me. That’s going to be quite expensive on mobile. A fragment shader that has to process 6 spot lights per pixel is gonna be quite slow on lower end devices especially.

For this particular problem, I suspect you are running out of texture image units in the fragment shader. For six spotlights with cookie, the fragment shader will need to use 6 texture units for the cookies, leaving just two. So if you’re rendering a mesh with, say, a diffuse map, normal map and gloss map, you’ll exceed 8 and the fragment shader will fail to compile. There’s not a great way around this. But maybe one suggestion would be to just start ignoring cookies after the texture units run out rather than just going ahead and generating a shader than won’t compile.

Feel free to log an issue here:

Maybe call it “Shader chunk system can generate shaders that exceed WebGL device limits”.

That would be very very useful! Instead of throwing an exception, it could just log a warning and leave it to the developer to decide if that’s acceptable behavior or not.

Yeah. Definitely a debug message saying:

WARNING: Number of vertex/fragment texture image units exceeded. This device supports 8. Shader requires 10"

Or:

WARNING: Number of varying vectors exceeded. This device supports 8. Shader requires 10"

Something like that.

1 Like

And you start learning your device limits in an easy and educative manner :wink: