Skip to content

Commit 51953c2

Browse files
nmwsharpxarthurx
andauthored
Fix rendering of ray-casted primitives in orthographic projection mode (#372)
* fix orthogonal issue. * remove unused function * move lazy properties to internal namespace * manage perspective vs orthographic shader raycasts with a rule at build time * add more tests for orthographic rendering * fix unrelated but with ground plane and upDir in ortho view * remove config file * add ini to gitignore --------- Co-authored-by: xTree <[email protected]>
1 parent 24ec7e3 commit 51953c2

28 files changed

+292
-55
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ misc/file2c/file2cpp
55

66
# Editor and OS things
77
imgui.ini
8+
.polyscope.ini
89
.DS_Store
910
.vscode
1011
*.swp

include/polyscope/camera_view.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@ class CameraView : public QuantityStructure<CameraView> {
9797
// Rendering helpers used by quantities
9898
void setCameraViewUniforms(render::ShaderProgram& p);
9999
std::vector<std::string> addCameraViewRules(std::vector<std::string> initRules, bool withCameraView = true);
100-
std::string getShaderNameForRenderMode();
101100

102101
// Get info related to how the frame is drawn (billboard center vector, center-to-top vector, center-to-right vector)
103102
std::tuple<glm::vec3, glm::vec3, glm::vec3> getFrameBillboardGeometry();

include/polyscope/internal.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
#include <cstdint>
66
#include <string>
77

8+
#include "polyscope/scaled_value.h"
9+
#include "polyscope/types.h"
10+
811

912
namespace polyscope {
1013

@@ -36,5 +39,20 @@ extern float lastRightSideFreeY;
3639
extern float leftWindowsWidth;
3740
extern float rightWindowsWidth;
3841

42+
// Cached versions of lazy properties used for updates
43+
namespace lazy {
44+
extern TransparencyMode transparencyMode;
45+
extern ProjectionMode projectionMode;
46+
extern int transparencyRenderPasses;
47+
extern int ssaaFactor;
48+
extern float uiScale;
49+
extern bool groundPlaneEnabled;
50+
extern GroundPlaneMode groundPlaneMode;
51+
extern ScaledValue<float> groundPlaneHeightFactor;
52+
extern int shadowBlurIters;
53+
extern float shadowDarkness;
54+
} // namespace lazy
55+
56+
3957
} // namespace internal
4058
} // namespace polyscope

include/polyscope/render/opengl/shaders/rules.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ extern const ShaderReplacementRule PROJ_AND_INV_PROJ_MAT;
4040
extern const ShaderReplacementRule COMPUTE_SHADE_NORMAL_FROM_POSITION;
4141
extern const ShaderReplacementRule PREMULTIPLY_LIT_COLOR;
4242
extern const ShaderReplacementRule CULL_POS_FROM_VIEW;
43+
extern const ShaderReplacementRule BUILD_RAY_FOR_FRAGMENT_PERSPECTIVE;
44+
extern const ShaderReplacementRule BUILD_RAY_FOR_FRAGMENT_ORTHOGRAPHIC;
4345

4446
ShaderReplacementRule generateSlicePlaneRule(std::string uniquePostfix);
4547
ShaderReplacementRule generateVolumeGridSlicePlaneRule(std::string uniquePostfix);

include/polyscope/vector_quantity.ipp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,8 @@ void VectorQuantity<QuantityT>::drawVectors() {
158158
template <typename QuantityT>
159159
void VectorQuantity<QuantityT>::createProgram() {
160160
161-
std::vector<std::string> rules = this->quantity.parent.addStructureRules({"SHADE_BASECOLOR"});
161+
std::vector<std::string> rules =
162+
this->quantity.parent.addStructureRules({view::getCurrentProjectionModeRaycastRule(), "SHADE_BASECOLOR"});
162163
if (this->quantity.parent.wantsCullPosition()) {
163164
rules.push_back("VECTOR_CULLPOS_FROM_TAIL");
164165
}

include/polyscope/view.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ CameraParameters getCameraParametersForCurrentView(); // contains all of this in
8585
// (these friendly helpers to get the same info as ^^^)
8686
glm::mat4 getCameraViewMatrix();
8787
void setCameraViewMatrix(glm::mat4 newMat);
88+
ProjectionMode getProjectionMode();
89+
void setProjectionMode(ProjectionMode newMode);
8890
glm::mat4 getCameraPerspectiveMatrix();
8991
glm::vec3 getCameraWorldPosition();
9092
void getCameraFrame(glm::vec3& lookDir, glm::vec3& upDir, glm::vec3& rightDir);
@@ -165,6 +167,7 @@ std::tuple<int, int> screenCoordsToBufferInds(glm::vec2 screenCoords);
165167
glm::ivec2 screenCoordsToBufferIndsVec(glm::vec2 screenCoords);
166168
glm::vec2 bufferIndsToScreenCoords(int xPos, int yPos);
167169
glm::vec2 bufferIndsToScreenCoords(glm::ivec2 bufferInds);
170+
std::string getCurrentProjectionModeRaycastRule();
168171

169172
// == Internal helpers. Should probably not be called in user code.
170173

src/camera_view.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,14 +154,16 @@ void CameraView::drawPickDelayed() {
154154
void CameraView::prepare() {
155155

156156
{
157-
std::vector<std::string> rules = addStructureRules({"SHADE_BASECOLOR"});
157+
std::vector<std::string> rules =
158+
addStructureRules({view::getCurrentProjectionModeRaycastRule(), "SHADE_BASECOLOR"});
158159
if (wantsCullPosition()) rules.push_back("SPHERE_CULLPOS_FROM_CENTER");
159160
rules = render::engine->addMaterialRules(material, rules);
160161
nodeProgram = render::engine->requestShader("RAYCAST_SPHERE", rules);
161162
}
162163

163164
{
164-
std::vector<std::string> rules = addStructureRules({"SHADE_BASECOLOR"});
165+
std::vector<std::string> rules =
166+
addStructureRules({view::getCurrentProjectionModeRaycastRule(), "SHADE_BASECOLOR"});
165167
if (wantsCullPosition()) rules.push_back("CYLINDER_CULLPOS_FROM_MID");
166168
rules = render::engine->addMaterialRules(material, rules);
167169
edgeProgram = render::engine->requestShader("RAYCAST_CYLINDER", rules);

src/curve_network.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,8 @@ void CurveNetwork::drawPickDelayed() {
221221
222222
std::vector<std::string> CurveNetwork::addCurveNetworkNodeRules(std::vector<std::string> initRules) {
223223
initRules = addStructureRules(initRules);
224+
225+
initRules.push_back(view::getCurrentProjectionModeRaycastRule());
224226
225227
if (nodeRadiusQuantityName != "" || edgeRadiusQuantityName != "") {
226228
initRules.push_back("SPHERE_VARIABLE_SIZE");
@@ -233,6 +235,8 @@ std::vector<std::string> CurveNetwork::addCurveNetworkNodeRules(std::vector<std:
233235
std::vector<std::string> CurveNetwork::addCurveNetworkEdgeRules(std::vector<std::string> initRules) {
234236
initRules = addStructureRules(initRules);
235237
238+
initRules.push_back(view::getCurrentProjectionModeRaycastRule());
239+
236240
// use node radius to blend cylinder radius
237241
if (nodeRadiusQuantityName != "" || edgeRadiusQuantityName != "") {
238242
initRules.push_back("CYLINDER_VARIABLE_SIZE");
@@ -292,9 +296,10 @@ void CurveNetwork::preparePick() {
292296
size_t pickStart = pick::requestPickBufferRange(this, totalPickElements);
293297
294298
{ // Set up node picking program
295-
nodePickProgram =
296-
render::engine->requestShader("RAYCAST_SPHERE", addCurveNetworkNodeRules({"SPHERE_PROPAGATE_COLOR"}),
297-
render::ShaderReplacementDefaults::Pick);
299+
nodePickProgram = render::engine->requestShader(
300+
"RAYCAST_SPHERE",
301+
addCurveNetworkNodeRules({"SPHERE_PROPAGATE_COLOR"}),
302+
render::ShaderReplacementDefaults::Pick);
298303
299304
// Fill color buffer with packed point indices
300305
std::vector<glm::vec3> pickColors;

src/internal.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,21 @@ float lastRightSideFreeY = 10;
2222
float leftWindowsWidth = -1.;
2323
float rightWindowsWidth = -1.;
2424

25+
26+
namespace lazy {
27+
28+
TransparencyMode transparencyMode = TransparencyMode::None;
29+
ProjectionMode projectionMode = ProjectionMode::Perspective;
30+
int transparencyRenderPasses = 8;
31+
int ssaaFactor = 1;
32+
float uiScale = -1.;
33+
bool groundPlaneEnabled = true;
34+
GroundPlaneMode groundPlaneMode = GroundPlaneMode::TileReflection;
35+
ScaledValue<float> groundPlaneHeightFactor = 0;
36+
int shadowBlurIters = 2;
37+
float shadowDarkness = .4;
38+
39+
} // namespace lazy
40+
2541
} // namespace internal
2642
} // namespace polyscope

src/point_cloud.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,9 @@ PointCloudPickResult PointCloud::interpretPickResult(const PickResult& rawResult
247247
std::vector<std::string> PointCloud::addPointCloudRules(std::vector<std::string> initRules, bool withPointCloud) {
248248
initRules = addStructureRules(initRules);
249249
if (withPointCloud) {
250+
251+
initRules.push_back(view::getCurrentProjectionModeRaycastRule());
252+
250253
if (pointRadiusQuantityName != "") {
251254
initRules.push_back("SPHERE_VARIABLE_SIZE");
252255
}

0 commit comments

Comments
 (0)