Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

askthedev.com Logo askthedev.com Logo
Sign InSign Up

askthedev.com

Search
Ask A Question

Mobile menu

Close
Ask A Question
  • Ubuntu
  • Python
  • JavaScript
  • Linux
  • Git
  • Windows
  • HTML
  • SQL
  • AWS
  • Docker
  • Kubernetes
Home/ Questions/Q 39420
In Process

askthedev.com Latest Questions

Asked: April 18, 20252025-04-18T12:14:07+05:30 2025-04-18T12:14:07+05:30

How do I accurately project a 3D Gaussian transformation to a 2D ellipse in Unity, especially with perspective distortion?

anonymous user

I’m looking for some help with projecting a 3D Gaussian transformation to a 2D ellipse in Unity, specifically dealing with perspective distortion – if that’s even possible. I’ve been trying to get my code to work right, but I’m running into issues, especially when the camera gets close to the objects. It seems to work fine at a distance and with orthographic view, but things start to break down when I use perspective projection.

To simplify what I’m doing: I want to take a unit sphere (for the sake of this example) that has its own transformation matrix involving scale, rotation, and translation in world space, and project it down into a 2D ellipse in screen space. I mean, I get that technically speaking, we’re dealing with a Gaussian here. The goal is to render these shapes efficiently within Unity’s mesh and shader limitations.

I’ve already cooked up some code snippets that I thought would help, but I’m still feeling a bit lost. Here’s where I’m at: I set up a 3D covariance matrix, transform it into camera space, and then try to project it. It seems to almost work, but then I hit a wall with the perspective distortion when the camera is close to the object.

My shader’s not the problem; it’s following the UVs correctly and scaling properly based on the transformed coordinates. It’s just that the 3D to 2D projection part feels sketchy, especially the Jacobian calculations. I feel like I’m missing something with the perspective correction.

Has anyone tackled something like this before? I’d love to hear any tips or pointers about the math behind this projection or any specific resources that might help me understand it better. I’m aware that I might be touching on some heavier math concepts, and I’m totally open to figuring it out! Any input would be super appreciated.

  • 0
  • 0
  • 2 2 Answers
  • 0 Followers
  • 0
Share
  • Facebook

    Leave an answer
    Cancel reply

    You must login to add an answer.

    Continue with Google
    or use

    Forgot Password?

    Need An Account, Sign Up Here
    Continue with Google

    2 Answers

    • Voted
    • Oldest
    • Recent
    1. anonymous user
      2025-04-18T12:14:09+05:30Added an answer on April 18, 2025 at 12:14 pm

      Projecting a 3D Gaussian (or equivalently, a transformed sphere) onto the 2D screen in Unity’s perspective projection indeed introduces non-linear effects that don’t appear in orthographic projection. The distortion you’re experiencing, especially at close camera distances, comes from the fact that perspective transformations are non-linear and thus cannot simply be captured by linearly transforming covariance matrices or spheres. Typically, a robust solution involves explicitly dealing with the perspective projection’s Jacobian at the object’s center point on screen, effectively approximating its curvature and applying it to your covariance matrix in a camera-aligned coordinate space before projection. Essentially, you compute the covariance matrix in camera coordinates, then use the perspective projection equations’ partial derivatives (the Jacobian) to propagate the covariance from 3D camera coordinates onto the 2D viewport space, resulting in a stable 2D ellipse.

      To practically approach this within Unity, start by computing your matrix transformation (rotation, scaling, translation) into camera space. At the object’s projected center point, derive the Jacobian matrix of the perspective projection, then use this to transform your covariance matrix into the screen (clip) space. From this projected covariance, you can extract the ellipse parameters (axis lengths and rotation) accurately. Several resources on “projected Gaussian distributions” or “covariance matrix perspective transformations” can provide detailed mathematical backgrounds. Additionally, exploring research papers or tutorials about uncertainty visualization in computer vision or augmented reality applications may offer valuable insights into the mathematics of projecting 3D Gaussian ellipsoids into 2D screen-space ellipses effectively and efficiently.

        • 0
      • Reply
      • Share
        Share
        • Share on Facebook
        • Share on Twitter
        • Share on LinkedIn
        • Share on WhatsApp
    2. anonymous user
      2025-04-18T12:14:09+05:30Added an answer on April 18, 2025 at 12:14 pm

      3D Gaussian Transformation to 2D Ellipse in Unity

      It sounds like an interesting challenge you’re working on! Projecting a 3D Gaussian representation to a 2D ellipse can definitely get tricky, especially with perspective distortion.

      First, it’s great that you’ve got your transformation matrix and you’re able to position the unit sphere with scale, rotation, and translation. When you hit issues with perspective, it’s usually related to how you convert 3D coordinates to 2D screen coordinates.

      One key thing to keep in mind is that with perspective projection, the position of the camera relative to the object heavily influences the final screen position. The closer the camera is, the more exaggerated the projection can become. You mentioned working with a covariance matrix, so make sure you’re accurately handling the perspective transformation as follows:

      1. Transform the 3D points into camera space using the view matrix.
      2. Apply the perspective projection matrix to transform these coordinates into clip space.
      3. When converting clip space to screen space, remember you need to do the homogeneous division (dividing by the w component) to get correct normalized device coordinates.

      As for the Jacobian calculations, they are essential for understanding how changes in your 3D space affect your 2D projection. Make sure you’re deriving it based on the transformations you’re applying. The Jacobian gives you a handle on how to adjust for changes in position, scale, or maybe even camera rotation.

      If you’re still hitting a wall, consider looking into resources on perspective projection in computer graphics or even Unity’s own documentation on camera setups and transformations. Check out Shader programming documentation too since it can provide insights into handling UV mappings correctly.

      Lastly, don’t hesitate to break your problem down: start by testing your transformations step-by-step and logging the outputs. It might help you identify where things go awry!

      Good luck, and keep experimenting! You’re on the right path!

        • 0
      • Reply
      • Share
        Share
        • Share on Facebook
        • Share on Twitter
        • Share on LinkedIn
        • Share on WhatsApp

    Sidebar

    Recent Answers

    1. anonymous user on How do games using Havok manage rollback netcode without corrupting internal state during save/load operations?
    2. anonymous user on How do games using Havok manage rollback netcode without corrupting internal state during save/load operations?
    3. anonymous user on How can I efficiently determine line of sight between points in various 3D grid geometries without surface intersection?
    4. anonymous user on How can I efficiently determine line of sight between points in various 3D grid geometries without surface intersection?
    5. anonymous user on How can I update the server about my hotbar changes in a FabricMC mod?
    • Home
    • Learn Something
    • Ask a Question
    • Answer Unanswered Questions
    • Privacy Policy
    • Terms & Conditions

    © askthedev ❤️ All Rights Reserved

    Explore

    • Ubuntu
    • Python
    • JavaScript
    • Linux
    • Git
    • Windows
    • HTML
    • SQL
    • AWS
    • Docker
    • Kubernetes

    Insert/edit link

    Enter the destination URL

    Or link to existing content

      No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.