You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Expected: Adding lit sprites to containers should use the cumulative/world transform during lighting calculations
Actual Behavior: Lit sprites in rotating containers display fixed lighting
Details: Adding a sprite + normal map and setting the sprite to the light2d pipeline works as expected - when rotating/moving the sprite, the angle to the light determines lighting intensity.
However, if you take the same sprite + normal map and add it as the child of a container, the container's rotation is ignored when light calculation occurs, resulting in fixed lighting.
functioncreate(){// Create ship containership=this.add.container(400,450);// Add ship body to containershipBody=this.add.sprite(0,0,'ship');shipBody.setPipeline('Light2D');ship.add(shipBody);// Create second ship at scene rootship2=this.add.sprite(1200,450,'ship');ship2.setPipeline('Light2D');this.lights.enable().setAmbientColor(0x333333);// Add light at center of scenesun=this.lights.addLight(800,450,2000,0xffAA00);}// Rotate container + ship2vartimer=0;functionupdate(time,delta){timer+=delta;ship.setAngle(timer/20%360);ship2.setAngle(timer/20%360);}
Additional Information
Seems likely that the lighting engine is passing in the object's local rotation to the shader fragment, rather than the full computed transform. I'll try to dig into the internals and get a better theory but I'm new to Phaser so would appreciate any pointers/assistance!
The text was updated successfully, but these errors were encountered:
OK, so the issue as expected is that the lighting pipeline is naively calling LightPipeline.setNormalMapRotation() with the object's parent-relative rotation, rather than its world-space transform rotation.
The quick and dirty solution would be to instead use object.getWorldTransformMatrix().rotation instead, but as there doesn't seem to be any caching of the cumulative transform (e.g. during scene graph update), running that calc on a per-object basis would likely have a negative performance impact. At this point, I'm going to need some guidance from the core team as to how best approach a solution in the Phaser Way.
Thank you for submitting this issue. We have fixed this and the fix has been pushed to the master branch. It will be part of the next release. If you get time to build and test it for yourself we would appreciate that.
Version
Description
Expected: Adding lit sprites to containers should use the cumulative/world transform during lighting calculations
Actual Behavior: Lit sprites in rotating containers display fixed lighting
Details: Adding a sprite + normal map and setting the sprite to the light2d pipeline works as expected - when rotating/moving the sprite, the angle to the light determines lighting intensity.
However, if you take the same sprite + normal map and add it as the child of a container, the container's rotation is ignored when light calculation occurs, resulting in fixed lighting.
Example Test Code
Codepen here: https://codepen.io/zaphnod/pen/OJzGKZB
Relevant setup:
Additional Information
Seems likely that the lighting engine is passing in the object's local rotation to the shader fragment, rather than the full computed transform. I'll try to dig into the internals and get a better theory but I'm new to Phaser so would appreciate any pointers/assistance!
The text was updated successfully, but these errors were encountered: