Extending PointLight uniforms

I have need in my app to add custom uniforms to PointLights.

My app currently uses a fixed amount of PointLights (8 to be exact) that get recycled and reused depending on player position in the scene. I have set my custom shader to ignore these lights if my geometry is lightmapped. The only thing is now i need certain lights to work on my lightmapped geometry.

I have been able to achieve this in my app by adding the bolded line below to the PointLight section of THREEs WebGLLights function.

} else if ( light.isPointLight ) {

var uniforms = cache.get( light );

uniforms.position.setFromMatrixPosition( light.matrixWorld );
uniforms.position.applyMatrix4( viewMatrix );

uniforms.color.copy( light.color ).multiplyScalar( light.intensity );
uniforms.distance = light.distance;
uniforms.decay = light.decay;
uniforms.animated = light.animated;

 uniforms.shadow = light.castShadow;

 if ( light.castShadow ) {

I then use the animated value (0 for off and 1 for on) in my shader code to determine when a light can affect lightmapped geometry.

I’m hoping there is a better way to go about this instead of hacking it into the library source code. My app includes three.js as an npm module and I would like to leave it the way it comes if possible.

Are you sure masking lights by uniforms will save a lot?

Since you are already digging into the source of WebGLLights (:+1: for that!) , would it be an option to extract the relevant code that defines light counts and types and put it in onBeforeCompile on your custom material (but adding only the lights that you want, instead of masking in the shader), and extract the code that sets light-related uniforms and put it in onBeforeRender of the lightmapped objects?