I do a racing game on three .js and I stuck to the following problem ...
I have 2 cars, so we need to make 4 spotlights (minimum) for the rear lights of the car and the front lights of the car for each car ...
We also need lights on the road ...
So, I have this code:
//front car1 light var SpotLight = new THREE.SpotLight( 0xffffff, 5, 300, Math.PI/2, 1 ); SpotLight.position.set( 50, 10, 700 ); SpotLight.target.position.set(50, 0, 800); SpotLight.castShadow = true; SpotLight.shadowCameraVisible = false; SpotLight.shadowDarkness = 0.5; scene.add(SpotLight); //front car2 light var SpotLight = new THREE.SpotLight( 0xffffff, 5, 300, -Math.PI/2, 1 ); SpotLight.position.set( -50, 10, 40 ); SpotLight.target.position.set(-50, 0, 100); SpotLight.castShadow = true; SpotLight.shadowCameraVisible = false; SpotLight.shadowDarkness = 0.5; scene.add(SpotLight); //rear car1 light var SpotLight = new THREE.SpotLight( 0xff0000, 2, 200, Math.PI/2, 2 ); SpotLight.position.set( 50, 20, 660 ); SpotLight.target.position.set(50, 0, 600); SpotLight.castShadow = true; SpotLight.shadowCameraVisible = false; SpotLight.shadowDarkness = 0.5; scene.add(SpotLight); //rear car2 light var SpotLight = new THREE.SpotLight( 0xff0000, 2, 100, Math.PI/2, 1 ); SpotLight.position.set( -50, 20, -35 ); SpotLight.target.position.set(-50, 0, -100); SpotLight.castShadow = true; SpotLight.shadowCameraVisible = false; SpotLight.shadowDarkness = 0.5; scene.add(SpotLight); //some road light var SpotLight = new THREE.SpotLight( 0x404040, 3, 500, Math.PI/2, 2 ); SpotLight.position.set( 0, 300, 0 ); SpotLight.target.position.set(0, 0, 0); SpotLight.castShadow = true; SpotLight.shadowCameraVisible = false; SpotLight.shadowDarkness = 0.5; scene.add(SpotLight);
Nothing special .. but the performance dropped to 20-30 FPS, and this is a bit of a lag: -1: And if I add some lights in the future, the performance will be taken even further ...
Has anyone encountered similar problems? How to deal with it? Or maybe I'm doing something wrong?