Author Topic: [Fixed] X-Frame causes Camera Raycasts to be off.  (Read 850 times)

auhfel

  • Newbie
  • *
  • Posts: 3
    • View Profile
[Fixed] X-Frame causes Camera Raycasts to be off.
« on: March 03, 2018, 02:16:20 AM »
[Edit: Solution is in next post]

Hi. Camera.ScreenPointToRay(Input.MousePosition) is off when using X-Frame.

Extra information : I'm uisng an Orthographic camera , isometric angle of 45 degrees, and in mobile portrait mode (resolution 800x1280).

If I turn off X-Frame the raycasts are accurate and my navmeshagent goes where I expect it to. If X-Frame is on, it is very inaccurate (Could be 5 units off easily);

Any ideas?
« Last Edit: March 03, 2018, 04:32:38 PM by auhfel »

Kronnect

  • Administrator
  • Hero Member
  • *****
  • Posts: 4413
    • View Profile
Re: X-Frame causes Camera Raycasts to be off.
« Reply #1 on: March 03, 2018, 02:55:15 AM »
Hello!

Try this:

Code
float factor = XFrameManager.instance.activeDownsampling;
Ray ray = Camera.ScreenPointToRay(Input.MousePosition * factor);

Let me know if that helps.

auhfel

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: X-Frame causes Camera Raycasts to be off.
« Reply #2 on: March 03, 2018, 04:27:52 PM »
Thanks, it worked beautifully. It might be handy for future users for there to be a Xframe.CameraScreenToRay() in the Xframe api.

I ran into one extra problem that I fixed, I dunno if it's X-Frame though. I had it disabled because it was not working. With no changes in the scene (scene is saved), When I enabled X-Frame to test(switched from disabled to quad downsampling) it didn't register any changes in the scene (aka the scene didn't have the unsaved asterisk showing that there are unsaved changes), so I couldn't save. When I switched back to my launch scene to test from game start, when i loaded the scene with X-Frame in it it was still disabled. Going back to the scene with it in it, I found that when I enabled it wasn't getting detected by the scene and was not actually saving the new state.

I got past this by enabling X-Frame, throwing a cube into the scene, saving the scene, then removing the cube and saving again. It's possible that X-Frame is having an issue, but to be honest I'm on Linux and the Unity Linux Editor has *tons* of bugs, lol. Sometimes float fields don't accept keyboard input =/.

Anyways just heads up in case you have any other linux users. Thanks again!

Kronnect

  • Administrator
  • Hero Member
  • *****
  • Posts: 4413
    • View Profile
Re: X-Frame causes Camera Raycasts to be off. [Fixed]
« Reply #3 on: March 03, 2018, 04:30:49 PM »
Very interesting. Thanks for the feedback! X-Frame will be updated soon with your suggestions.

ashwinFEC

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: X-Frame causes Camera Raycasts to be off.
« Reply #4 on: May 07, 2018, 06:34:09 AM »
Hello!

Try this:

Code
float factor = XFrameManager.instance.activeDownsampling;
Ray ray = Camera.ScreenPointToRay(Input.MousePosition * factor);

Let me know if that helps.

I am using EasyTouch and that code didn't work for me ray positions were always off.
Even when using:
Code
float factor = XFrameManager.instance.appliedDownsampling;

But this did work
Code
 

        var screenPos = gesture.position;

        var xframeTexture = XFrameManager.instance.rt;

        screenPos.x = screenPos.x / Screen.width * xframeTexture.width;
        screenPos.y = screenPos.y / Screen.height * xframeTexture.height;
        Ray ray = Camera.ScreenPointToRay(screenPos);



Kronnect

  • Administrator
  • Hero Member
  • *****
  • Posts: 4413
    • View Profile
Re: [Fixed] X-Frame causes Camera Raycasts to be off.
« Reply #5 on: May 07, 2018, 09:26:23 AM »
That's interesting - looks like your code works just the opposite way: activeDownsampling is basically the size of the active render texture / screen width.
What downsampling method are you using? Quad, adaptative, ...?

ashwinFEC

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: [Fixed] X-Frame causes Camera Raycasts to be off.
« Reply #6 on: May 07, 2018, 12:48:37 PM »
I'm using adaptive. Yeah I can switch the division around to match what's in the API


Code
            
screenPos.x = screenPos.x * ((float)xframeTexture.width / Screen.width );
screenPos.y = screenPos.y * ((float)xframeTexture.height / Screen.height);

and still get a better result than what the X-Frame API is providing. XFrameManager.instance.appliedDownsampling is for some reason always slightly off compared to my calculation, except when the system is using the static quality variable. For example when I set the minimum quality to 0.2 and move the camera around (float)xframeTexture.width/Screen.width gives 0.20041 but appliedDownsampling gives 0.2085 in the same frame.
Here are two screenshots from my console


And XFrameManager.instance.activeDownsampling is only binary either the minimum or the static quality nothing in between when X-Frame is transitioning between resolutions.



« Last Edit: May 07, 2018, 12:50:58 PM by ashwinFEC »

Kronnect

  • Administrator
  • Hero Member
  • *****
  • Posts: 4413
    • View Profile
Re: [Fixed] X-Frame causes Camera Raycasts to be off.
« Reply #7 on: May 07, 2018, 12:52:27 PM »
Thanks for the insights. Quite interesting and useful - X-Frame targets are rounded so that can explain the small difference. Will be fixed in next update. Thanks!

Kronnect

  • Administrator
  • Hero Member
  • *****
  • Posts: 4413
    • View Profile
Re: [Fixed] X-Frame causes Camera Raycasts to be off.
« Reply #8 on: May 11, 2018, 01:20:45 AM »
btw, you should use appliedDownsampling instead of activeDownsampling, which returns the currently applied downsampling factor.