Skip to content

Commit 4c4c042

Browse files
committed
unbreak ground shadows
1 parent f34f403 commit 4c4c042

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

include/polyscope/view.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,11 @@ extern const float defaultNearClipRatio;
7777
extern const float defaultFarClipRatio;
7878
extern const float defaultFov;
7979

80+
// Internal details
81+
extern bool overrideClipPlanes; // used for temporary state changes in render passes, internal use only!
82+
extern float overrideNearClipRelative;
83+
extern float overrideFarClipRelative;
84+
8085
// === View methods
8186

8287
// == Get/Set the current camera view in the user's window

src/render/ground_plane.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,9 @@ void GroundPlane::draw(bool isRedraw) {
364364
projMat[iP][iP] = 0.;
365365
projMat[3][iP] = groundHeight;
366366
view::viewMat = view::viewMat * projMat;
367+
view::overrideClipPlanes = true; // set the clip planes manually
368+
view::overrideNearClipRelative = view::defaultNearClipRatio;
369+
view::overrideFarClipRelative = view::defaultFarClipRatio;
367370

368371
// Draw everything
369372
render::engine->setDepthMode(DepthMode::Less);
@@ -396,6 +399,7 @@ void GroundPlane::draw(bool isRedraw) {
396399

397400
// Restore original view matrix
398401
view::viewMat = origViewMat;
402+
view::overrideClipPlanes = false;
399403
}
400404

401405
render::engine->bindSceneBuffer();

src/view.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,12 @@ const float defaultFov = 45.;
5454
const float minFov = 5.; // for UI
5555
const float maxFov = 160.; // for UI
5656

57+
// Internal details
58+
bool overrideClipPlanes =
59+
false; // used only for temporary state changes in render passes, so we do not track in context
60+
float overrideNearClipRelative = defaultNearClipRatio;
61+
float overrideFarClipRelative = defaultFarClipRatio;
62+
5763
// Small helpers
5864

5965
namespace { // anonymous helpers
@@ -740,7 +746,12 @@ glm::mat4 getCameraPerspectiveMatrix() {
740746

741747
// Set the clip plane
742748
float absNearClip, absFarClip;
743-
std::tie(absNearClip, absFarClip) = computeClipPlanes();
749+
if (overrideClipPlanes) {
750+
absNearClip = overrideNearClipRelative * state::lengthScale;
751+
absFarClip = overrideFarClipRelative * state::lengthScale;
752+
} else {
753+
std::tie(absNearClip, absFarClip) = computeClipPlanes();
754+
}
744755

745756
float fovRad = glm::radians(fov);
746757
float aspectRatio = (float)bufferWidth / bufferHeight;

0 commit comments

Comments
 (0)