Spotlight Projection issue

Hey,

So I think I’ve found a bug, but it’s pretty obscure so I’m posting it here first.

I have a NodeMaterial and I’m trying to project onto it. In my project I’m getting a result I’m not expecting most of the time. In the playground example I’ve put together it’s happening less often than in my project, so I’m worried it’s not exactly the same issue.

Playground

If I keep pressing play, eventually I get a single color projected over the entire surface of the mesh. I’ve uploaded screenshots of what’s happening for me. This is happening in my actual project too.


Before using a NodeMaterial I was using a StandardMaterial and doing the same thing and not experiencing this issue.

By the way, if you remove the setTimeout it seems to be consistent and work correctly, but I’m creating projectors when they’re needed, which isn’t on scene load.

Thanks,
Chris

When you set a projection texture to a spot light, you need to rebuild the node material because it impacts the generated shader code. When using a standard material it is done automatically by the system for you but not when using a node material:

https://playground.babylonjs.com/#MIK09A#14

See line 44.

2 Likes

Oh I see. That’s really good news for my project.

I see that it does work, but if I do it immediately after activating a spotlight it doesn’t always fix the problem. It seems like if I wait for at least 3 frames and then rebuild the materials then it’s correct.

Thanks very much for the help!
Chris

Rebuilding just after creating the spotlight should work, maybe there is something else getting in the way…