Babylon Projection Texture Support

Yo @Evgeni_Popov … Quick question… Does this count against the 4 light max limit ???

Yes, each created light count to the limit. However, you can raise the 4 limit to a higher value (material.maxSimultaneousLights).

Yo @Evgeni_Popov … is there something i have to do to refresh it when i move the spot light projector position… That projected shadow on the ground stays the same spot.

Should i be redrawing something when the spot light moves… My intent was to have the projector above a car racing on a track so the the shadow would be projected on to the track while driving ?

Turns out if you set a new spot light position, that cause the spot light _setPosition override to run which sets _projectionTextureViewLightDirty = true

But if you just update that value, the _setPosition does not run so you gotta manually mark dirty if you manually update the position vector directly. SO that i am only marking it dirty if the that last position is different

        private updateProjectorPosition():void {
            this.m_projectorOffset.set(0, this.projectionHeight, 0);
            UTIL.GetAbsolutePositionToRef(this.transform, this.m_projectorPosition, this.m_projectorOffset);
            if (this.m_lastPosition.x !== this.m_projectorPosition.x || this.m_lastPosition.y !== this.m_projectorPosition.y || this.m_lastPosition.z !== this.m_projectorPosition.z) {
                this.spotLight.position.set(this.m_projectorPosition.x, this.m_projectorPosition.y, this.m_projectorPosition.z);
                (<any>this.spotLight)._projectionTextureViewLightDirty = true;
            }
            this.m_lastPosition.copyFrom(this.m_projectorPosition);
        }

Works great :slight_smile:

Ok @Evgeni_Popov … i got one for you… How would i rotate the spot light and/or its projected texture ?

Can you modify the playground and rotate/spin the projected texture around… since there is no light.rotation.y += 0.1 or something… How would you handle that one ?

Regarding updating the position, instead of:

                (<any>this.spotLight)._projectionTextureViewLightDirty = true;

I would do:

this.spotLight.position = this.spotLight.position;

because _projectionTextureViewLightDirty is a private property and we make no guarantee that this property will exist forever.

You can use the projectionTextureUpDirection property for that, which is used internally to build the view matrix corresponding to the projection matrix:

Yo @Evgeni_Popov … if you back the camera out a bit… there is a bit of Ghosting of the projected shadow. Take a look at this snapshot:

The problem is with mipmapping, which is not full white at the lowest level(s) but grey. You can either create the mipmap chain yourself and make sure the lowest level is a white pixel or simply disable mipmapping for the shadow texture:

https://playground.babylonjs.com/#CQNGRK#512

Thanks so much @Evgeni_Popov … My Spot Light Projector class is working pretty good so far :slight_smile:

Hello, don’t mean to raise a dead thread too much - this is the closest thing I could find searching for how to do a ‘fake’/forced shadow. I want to do something like the original request here, or look at old 8 bit games like Tornado Low Level.

Is there a sort of final / most recent concise explanation or example per chance? I am super new to BabylonJS and modern 3D apis unfortunately.

1 Like

If you want to do the same thing than in TLL, then the easiest way is to simply draw an additional mesh a bit offseted from the main mesh. Else, you can use the latest PG from this thread (https://playground.babylonjs.com/#CQNGRK#512) or even use real shadows.

2 Likes