Repository: godot
Issue: Shadow to Opacity no longer handles shadows properly
Labels: bug,confirmed,topic:xr,topic:shaders,topic:3d

### Tested versions

- Reproducible in 4.3 dev 6

### System information

Windows 11 - Mobile Renderer

### Issue description

Shadow to Opacity was a shader feature we added in Godot 3 for a specific use case in AR applications. The port to Godot 4 broke the way it worked. We fixed one issue last week making this solution viable again, this secondary issue remains.

As we are superimposing our rendered scene on top of a camera feed (or in the case of certain wearable AR devices, projecting our rendered scene on top of the real world) we have some unique interactions between what we render virtually, and what we see from the real world. 

Without doing anything, virtual objects that should be behind real world object are rendered in front of them. Also virtual objects that are placed on top of real world objects don't cast shadows on those objects.
![image](https://github.com/godotengine/godot/assets/1945449/5bf5dcc3-b8d2-4e4c-99d8-a7a3a29dfc36)

Many AR systems have functionality that scan the room and identify geometry in the real world and make this available to our application. Some systems require this to be done manually. Nitwel has implemented a manual system for this in Godot showcased here: https://www.youtube.com/watch?v=8t66SH6ZbEE

As a test I'm just bringing in geometry for the table in the above image, I've had to mangle it a bit to fit the image so excuse the crooked legs.

Mimicking transparency with a "green screen" just for visual clarity, this is what our rendered scene would look like **without** using our shadow to opacity shader:
![image](https://github.com/godotengine/godot/assets/1945449/cb9b52ae-11de-4fdc-a133-b6ad156a64f6)
We see our table in black now, with the table casting a shadow on the box that is behind it, and the canister on top of the table casting a shadow on the table.

Enabling our shadow to opacity shader we get this result:
![image](https://github.com/godotengine/godot/assets/1945449/b6e83dfc-4866-4b5e-8a75-ea50e3d141f8)

Our table is now no longer visible, but it is properly occluding the box that is behind it. It's also casting a shadow on the  box. We also see our cylinder that is standing on the table, **however the shadow the cylinder casts is gone**.

For final reference, this is the end result with the "real world" added back in:
![image](https://github.com/godotengine/godot/assets/1945449/3d73c93f-64e4-4a54-9327-b9cf46643e23)

So the outstanding bug is that our shadow to opacity material no longer properly shows shadows cast on it, this due to the calculation applied here being incorrect. 

### Steps to reproduce

Run the MRP

### Minimal reproduction project (MRP)

This is the MRP I've created to "fake" the AR functionality and create the above screenshots. It mimics AR by using a still image as a background instead of a video feed (I am aware the image is a render itself, that is besides the point).
This allows anyone to test the functionality without access to fancy hardware: 
[TestShadowToOpaque.zip](https://github.com/godotengine/godot/files/15195885/TestShadowToOpaque.zip)