MouseOver events and Panini Projection

I have a Global volume in my scene that applies a Panini Projection to my camera, to compensate for the distortion of my FOV.
Now the problem is, at certain points in my game I unlock the mouse cursor and then need to highlight items when they’re hovered. Due to the Panini Projection however, the mouse over is offset on the horizontal level, and gets increasingly noticeable the closer to the edge of the screen I get, due to the Panini Projection.

I currently handle this by offsetting colliders, which works in the more static part of the scene, but it won’t work when objects move on the horizontal axis, it won’t work.

I assume I can’t be the only one with this issue, but still, my Google-fu and GPT skills have fallen short in finding a viable solution. GPT has suggested some shader-based solutions, but I’d rather not delve into that territory, as it’s not my forté, and frankly, may end up in overcomplicated shaders, as I already have some custom shaders for some of my geometry.

I have pondered disabling the panini projection in some of these situations, but that will not be satisfactory from a visual point of view.

As a side note, I’m surprised there aren’t any (to my knowledge) built-in ways to handle this, as this is also one of the ‘built-in’ volumes.

Any thoughts, hints, or even solutions, are very welcome.

Thank you for reading, and for your time.

I obtained the following answer using Unity Muse.

you can try adjusting the mouse hover detection according to the Panini Projection’s distortion. To do this, you’ll need to modify the method used to detect mouse hover so that the mouse position is projected into the Panini Projection coordinate space. Here are the general steps to achieve this:

  1. First, study the mathematics behind the Panini Projection to understand how to convert screen space coordinates to Panini Projection coordinates.
  2. In the script that detects mouse hover, convert the mouse screen space position to Panini Projection coordinates.
  3. Perform raycasting and collision detection using the transformed coordinates.
  4. Highlight the object when hover is detected.

This approach might require more mathematical knowledge and understanding of the Panini Projection. Implementing this solution may take some experimentation and tweaking, but it could address the mouse hover issue without turning off the Panini Projection.

I hope this solution helps. If you need more information about the Panini Projection and Unity, please consult the Unity documentation.

I apologize if my previous responses were not helpful. Here’s a basic example of how to adjust mouse hover detection according to the Panini Projection’s distortion. Please note that this example assumes you have a basic understanding of Panini Projection mathematics and its implementation in Unity.

using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.Rendering.Universal;

public class PaniniMouseHover : MonoBehaviour
{
    public Camera mainCamera;
    public LayerMask hitLayers;
    public GlobalVolume globalVolume;

    private PaniniProjection paniniProjection;

    private void Start()
    {
        if (globalVolume.profile.TryGet(out paniniProjection))
        {
            Debug.Log("Panini Projection found.");
        }
        else
        {
            Debug.LogError("Panini Projection not found.");
        }
    }

    private void Update()
    {
        Vector2 mousePosition = Input.mousePosition;
        Vector2 paniniAdjustedPosition = AdjustMousePositionForPanini(mousePosition);
        Ray ray = mainCamera.ScreenPointToRay(paniniAdjustedPosition);

        RaycastHit hit;
        if (Physics.Raycast(ray, out hit, Mathf.Infinity, hitLayers))
        {
            Debug.Log("Hovering over: " + hit.collider.gameObject.name);
            // Highlight the object or perform other actions
        }
    }

    private Vector2 AdjustMousePositionForPanini(Vector2 mousePosition)
    {
        // Implement the Panini Projection mathematics to adjust the mouse position.
        // This example assumes you have the necessary knowledge of Panini Projection math.
        // You should replace this method with your own implementation.

        return mousePosition;
    }
}

In this example, you should replace the AdjustMousePositionForPanini method with your own implementation of the Panini Projection mathematics to convert the mouse position from screen space to Panini Projection coordinates.

Please note that this is just a starting point and may require further adjustments and experimentation based on your specific implementation of the Panini Projection.

I hope these can help you, Or you can try it yourself https://muse.unity.com/

A bit late, but activating Panini projectionCropt to fit could help you.

Give it a try