Skip to content

Conversation

@xarthurx
Copy link
Contributor

@xarthurx xarthurx commented Dec 13, 2025

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

image

Copilot AI review requested due to automatic review settings December 13, 2025 14:20
Copy link

Copilot AI left a 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() and buildRayForFragment() 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;
Copy link

Copilot AI Dec 13, 2025

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.

Suggested change
rayDir = viewPos;
rayDir = normalize(viewPos);

Copilot uses AI. Check for mistakes.
Comment on lines +1 to +7
{
"uiScale": 1.0,
"windowHeight": 1352,
"windowPosX": 1283,
"windowPosY": 35,
"windowWidth": 2554
}
Copy link

Copilot AI Dec 13, 2025

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.

Copilot uses AI. Check for mistakes.
@nmwsharp
Copy link
Owner

Thanks for creating a PR for this. I made some changes in #372 to

  • Change the perspective/ortho to use a shader rule rather than a conditional
  • Added some more tests
  • Fixed/changed some other ortho-related bugs that showed up in testing

That one is merged now. Please let me know if anything doesn't seem to be working!

@nmwsharp nmwsharp closed this Dec 14, 2025
@xarthurx
Copy link
Contributor Author

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?

@nmwsharp
Copy link
Owner

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.

@xarthurx
Copy link
Contributor Author

xarthurx commented Dec 15, 2025 via email

@nmwsharp
Copy link
Owner

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!)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants