phaser icon indicating copy to clipboard operation
phaser copied to clipboard

Normal maps not working with some initial image rotation

Open sroboubi opened this issue 1 year ago • 2 comments

Version

  • Phaser Version: 3.60.0 and 3.70.0
  • Operating system: windows (or any)
  • Browser: chrome/edge (or any)

Description

I don’t know if this is related to Phaser.GameObjects.Light does not consider rotation of Phaser.GameObjects.Image with normal map which I also created a while back.

Anyway, I made a small test application to demonstrate this. You can view the very short code by looking at the page source. Note that you can click the mouse to toggle the light position linking to mouse position.

Using Phaser version 3.70.0 and 3.60.0 you can see the normal map is broken for some initial image rotation:

https://sr-proto.netlify.app/phaserbug4/index.html?version=3.70.0 https://sr-proto.netlify.app/phaserbug4/index.html?version=3.60.0

Using Phaser version 3.55.0 it works as expected:

https://sr-proto.netlify.app/phaserbug4/index.html?version=3.55.0

Example Test Code

view-source:https://sr-proto.netlify.app/phaserbug4/index.html

Additional Information

sroboubi avatar Jan 06 '24 00:01 sroboubi

This issue has been mentioned on Phaser. There might be relevant details there:

https://phaser.discourse.group/t/normal-maps-not-working-with-some-initial-image-rotation/13856/2

photonstorm avatar Jan 06 '24 02:01 photonstorm

Additional test shows that this is probably not related to the rotation itself but the order of adding images

https://sr-proto.netlify.app/phaserbug5/index.html?version=3.70.0&test=many.js

If you open this page and use A/D keys to rotate the images, you can see that every second image loses it's normal map. When you return the rotation back to the initial state then it seems like random things happen.

EDIT: I should point out the source for this is here: https://sr-proto.netlify.app/phaserbug5/many.js

sroboubi avatar Jan 06 '24 03:01 sroboubi

Appears to be broken in a different way with 3.80.0 - didn't have time to look into it but exact same code now throws an error when render is called.

https://sr-proto.netlify.app/phaserbug5/index.html?version=3.80.0&test=many.js

sroboubi avatar Feb 27 '24 02:02 sroboubi

Thanks for letting us know! We've also identified the issue: a default normal map was improperly called. We've already fixed it, and there should be a release very soon.

The original issue is still on my agenda for future fixes, so I'm leaving this open. Thanks for the great demonstrations of the issue.

BenjaminDRichards avatar Feb 27 '24 03:02 BenjaminDRichards

As of Phaser 3.80.1, the render error is fixed.

I've also found the source of the original issue. LightPipeline.setTexture2D was always invoked internally with no gameObject parameter, but it expected one, and would set a default normal map when it couldn't find it. This meant that a render batch - a series of operations using the same textures - would run correctly once, then incorrectly once, then detect that the correct normal map was not loaded, and start a new batch and begin the sequence again. Thus, if two objects with the same normal map texture are rendered in a row, the second one will not have a normal map, and this will alternate back and forth.

If any object with a different texture was rendered between them, it would reset the render batch, and everything would render correctly. It's only when two objects with the same texture are rendered in a row that the problem occurred.

I've removed the problematic code with commit 928ce1a1e7a12c141ed290b9126d3e4da5c50733, and the fix will be in the next release.

BenjaminDRichards avatar Feb 28 '24 08:02 BenjaminDRichards

Great, thanks for the quick fix 👍 I'll test it out in the next release.

sroboubi avatar Mar 08 '24 07:03 sroboubi