Fix editor raycast
This commit is contained in:
@@ -1398,9 +1398,9 @@ namespace FlaxEditor.Viewport
|
|||||||
Matrix.Multiply(ref v, ref p, out var ivp);
|
Matrix.Multiply(ref v, ref p, out var ivp);
|
||||||
ivp.Invert();
|
ivp.Invert();
|
||||||
|
|
||||||
// Create near and far points
|
// Create near and far points, with device depth of 1 and 0 respectively
|
||||||
var nearPoint = new Vector3(mousePosition, _nearPlane);
|
var nearPoint = new Vector3(mousePosition, 1.0f);
|
||||||
var farPoint = new Vector3(mousePosition, _farPlane);
|
var farPoint = new Vector3(mousePosition, 0.0f);
|
||||||
viewport.Unproject(ref nearPoint, ref ivp, out nearPoint);
|
viewport.Unproject(ref nearPoint, ref ivp, out nearPoint);
|
||||||
viewport.Unproject(ref farPoint, ref ivp, out farPoint);
|
viewport.Unproject(ref farPoint, ref ivp, out farPoint);
|
||||||
|
|
||||||
|
|||||||
@@ -296,15 +296,13 @@ namespace FlaxEngine
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Converts a screen space point into a corresponding point in world space.
|
/// Converts a screen space point into a corresponding point in world space.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="source">The vector to project.</param>
|
/// <param name="source">The vector to project, screen uv and device depth.</param>
|
||||||
/// <param name="projection">The projection matrix.</param>
|
/// <param name="projection">The projection matrix.</param>
|
||||||
/// <param name="view">The view matrix.</param>
|
/// <param name="view">The view matrix.</param>
|
||||||
/// <param name="world">The world matrix.</param>
|
|
||||||
/// <returns>The unprojected Vector.</returns>
|
/// <returns>The unprojected Vector.</returns>
|
||||||
public Vector3 Unproject(Vector3 source, Matrix projection, Matrix view, Matrix world)
|
public Vector3 Unproject(Vector3 source, Matrix projection, Matrix view)
|
||||||
{
|
{
|
||||||
Matrix.Multiply(ref world, ref view, out Matrix matrix);
|
Matrix.Multiply(ref view, ref projection, out Matrix matrix);
|
||||||
Matrix.Multiply(ref matrix, ref projection, out matrix);
|
|
||||||
Matrix.Invert(ref matrix, out matrix);
|
Matrix.Invert(ref matrix, out matrix);
|
||||||
|
|
||||||
Unproject(ref source, ref matrix, out Vector3 vector);
|
Unproject(ref source, ref matrix, out Vector3 vector);
|
||||||
@@ -314,8 +312,8 @@ namespace FlaxEngine
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Converts a screen space point into a corresponding point in world space.
|
/// Converts a screen space point into a corresponding point in world space.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="source">The vector to project.</param>
|
/// <param name="source">The vector to project, screen uv and device depth.</param>
|
||||||
/// <param name="matrix">An inverted combined WorldViewProjection matrix.</param>
|
/// <param name="matrix">An inverted combined ViewProjection matrix.</param>
|
||||||
/// <param name="vector">The unprojected vector.</param>
|
/// <param name="vector">The unprojected vector.</param>
|
||||||
public void Unproject(ref Vector3 source, ref Matrix matrix, out Vector3 vector)
|
public void Unproject(ref Vector3 source, ref Matrix matrix, out Vector3 vector)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ float4 PS(VS2PS input) : SV_Target
|
|||||||
{
|
{
|
||||||
float sceneDepthDeviceZ = SceneDepthTexture.Load(int3(input.Position.xy, 0)).r;
|
float sceneDepthDeviceZ = SceneDepthTexture.Load(int3(input.Position.xy, 0)).r;
|
||||||
float interpolatedDeviceZ = input.Position.z;
|
float interpolatedDeviceZ = input.Position.z;
|
||||||
clip(sceneDepthDeviceZ - interpolatedDeviceZ);
|
clip(interpolatedDeviceZ - sceneDepthDeviceZ);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user