-
Notifications
You must be signed in to change notification settings - Fork 231
Fix rendering of ray-casted primitives in orthographic projection mode #370
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR fixes incorrect rendering of ray-casted primitives (spheres, cylinders, and vectors) when using orthographic projection. The core issue was that the raycasting logic assumed perspective projection with rays originating from the camera origin, but orthographic projection requires parallel rays.
Key Changes:
- Added
isOrthoProjection()andbuildRayForFragment()functions to properly handle both projection modes - Updated geometry shaders to compute camera direction correctly for orthographic projection
- Modified all fragment shaders to use the new ray building function instead of assuming rays from origin
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/render/opengl/shaders/common.cpp | Adds projection detection and unified ray building functions for both orthographic and perspective modes |
| src/render/opengl/shaders/sphere_shaders.cpp | Updates geometry shaders to compute correct camera direction and fragment shaders to use new ray building |
| src/render/opengl/shaders/cylinder_shaders.cpp | Updates fragment shader to use new ray building function for cylinder intersection |
| src/render/opengl/shaders/vector_shaders.cpp | Updates fragment shader to use new ray building function for vector rendering |
| .polyscope.ini | Adds user-specific window configuration (should not be committed) |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| // Perspective: rays from origin through fragment position | ||
| vec3 viewPos = fragmentViewPosition(viewport, depthRange, invProjMat, fragCoord); | ||
| rayStart = vec3(0.0, 0.0, 0.0); | ||
| rayDir = viewPos; |
Copilot
AI
Dec 13, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The ray direction for perspective projection should be normalized. Currently, rayDir is set to viewPos which is not normalized. This could lead to incorrect intersection calculations or unexpected behavior in the ray-casting functions that consume this direction vector, even though raySphereIntersection normalizes it internally. For consistency and correctness, the ray direction should be normalized here.
| rayDir = viewPos; | |
| rayDir = normalize(viewPos); |
| { | ||
| "uiScale": 1.0, | ||
| "windowHeight": 1352, | ||
| "windowPosX": 1283, | ||
| "windowPosY": 35, | ||
| "windowWidth": 2554 | ||
| } |
Copilot
AI
Dec 13, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file appears to contain user-specific window position and size preferences. Configuration files like this that store local user preferences should not be committed to version control, as they vary between users and development environments. Consider adding .polyscope.ini to the .gitignore file to prevent it from being tracked.
|
Thanks for creating a PR for this. I made some changes in #372 to
That one is merged now. Please let me know if anything doesn't seem to be working! |
|
Thanks for the quick response. The only question I have is that I'm using Python for a project where I've realized this issue. I've seen that both the C++ and Python version are quite old. Does this mean that I have to recompile it for Python so that I can use it in my project, or do you think it's possible to release a new version recently? |
|
No problem. I'm hoping to cut and deploy a new python version within the next week or two, currently trying to get as many bugfixes in as possible. If you want to install the Python package from the current This requires the usual C++ buildchain stuff to be available on your system for it to compile the library. Occasionally you might hit issues with stdlib incompatibilities etc with other Python code, but mostly it just works. |
|
Thanks for the quick reply.
If you will be released before the New Year, then I can definitely wait.
…On 15 Dec 2025 at 18:35 +0100, Nicholas Sharp ***@***.***>, wrote:
nmwsharp left a comment (nmwsharp/polyscope#370)
No problem. I'm hoping to cut and deploy a new python version within the next week or two, currently trying to get as many bugfixes in as possible.
If you want to install the Python package from the current master ASAP, you can use
pip install git+https://github.com/nmwsharp/polyscope-py.git#egg=polyscope
This requires the usual C++ buildchain stuff to be available on your system for it to compile the library. Occasionally you might hit issues with stdlib incompatibilities etc with other Python code, but mostly it just works.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you authored the thread.Message ID: ***@***.***>
|
|
Yep, definitely planning on releasing before the new year. (although I can't strictly promise a release date, sometimes this open-source work gets delayed when other aspects of life get unexpectedly busy!) |
Related Issue
#364
Summary
Fixes incorrect rendering of spheres, cylinders, and vectors when using orthographic projection. The issue was that the raycasting logic assumed perspective projection (rays originating from camera origin), but orthographic projection requires parallel rays.
In orthographic mode:
Fragment shaders were casting rays from the camera origin through each fragment, but orthographic rays should be parallel (all pointing in -Z direction)
Geometry shaders for sphere billboards computed camera direction as normalize(-position), which is only correct for perspective projection