Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/demo-app/demo_app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -870,7 +870,7 @@ void callback() {

std::vector<float> plotVals;
for (float t = 0; t < 10.; t += 0.01) {
plotVals.push_back(std::cosf(t + ImGui::GetTime()));
plotVals.push_back(std::cos(t + ImGui::GetTime()));
}

// sample plot
Expand Down
4 changes: 4 additions & 0 deletions include/polyscope/render/engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -698,4 +698,8 @@ inline std::string getRenderEngineBackendName() { return engineBackendName; }


} // namespace render

// === Small free helpers
std::vector<std::string> removeRule(std::vector<std::string> initRules, std::string ruleName);

} // namespace polyscope
11 changes: 6 additions & 5 deletions src/color_render_image_quantity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,17 @@ void ColorRenderImageQuantity::prepare() {

// Create the sourceProgram
// clang-format off
program = render::engine->requestShader("TEXTURE_DRAW_RENDERIMAGE_PLAIN",
render::engine->addMaterialRules(material.get(),

std::vector<std::string> rules = render::engine->addMaterialRules(material.get(),
parent.addStructureRules({
getImageOriginRule(imageOrigin),
hasNormals ? "SHADE_NORMAL_FROM_TEXTURE" : "SHADE_NORMAL_FROM_VIEWPOS_VAR",
"TEXTURE_SHADE_COLOR"
})
),
render::ShaderReplacementDefaults::SceneObjectNoSlice);
// clang-format on
);
rules = removeRule(rules, "GENERATE_VIEW_POS");

program = render::engine->requestShader("TEXTURE_DRAW_RENDERIMAGE_PLAIN", rules);

program->setAttribute("a_position", render::engine->screenTrianglesCoords());
program->setTextureFromBuffer("t_depth", depths.getRenderTextureBuffer().get());
Expand Down
11 changes: 7 additions & 4 deletions src/depth_render_image_quantity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,18 @@ void DepthRenderImageQuantity::prepare() {

// Create the sourceProgram
// clang-format off
program = render::engine->requestShader("TEXTURE_DRAW_RENDERIMAGE_PLAIN",
render::engine->addMaterialRules(material.get(),

std::vector<std::string> rules = render::engine->addMaterialRules(material.get(),
parent.addStructureRules({
getImageOriginRule(imageOrigin),
hasNormals ? "SHADE_NORMAL_FROM_TEXTURE" : "SHADE_NORMAL_FROM_VIEWPOS_VAR",
"SHADE_BASECOLOR",
})
),
render::ShaderReplacementDefaults::SceneObjectNoSlice);
);
rules = removeRule(rules, "GENERATE_VIEW_POS");

program = render::engine->requestShader("TEXTURE_DRAW_RENDERIMAGE_PLAIN", rules);

// clang-format on

program->setAttribute("a_position", render::engine->screenTrianglesCoords());
Expand Down
5 changes: 3 additions & 2 deletions src/polyscope.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "imgui.h"
#include "implot.h"

#include "polyscope/imgui_config.h"
#include "polyscope/options.h"
#include "polyscope/pick.h"
#include "polyscope/render/engine.h"
Expand Down Expand Up @@ -1175,8 +1176,8 @@ void shutdown(bool allowMidFrameShutdown) {
removeAllSlicePlanes();
clearMessages();
state::userCallback = nullptr;
options::configureImGuiStyleCallback = nullptr;
options::prepareImGuiFontsCallback = nullptr;
options::configureImGuiStyleCallback = configureImGuiStyle; // restore defaults
options::prepareImGuiFontsCallback = prepareImGuiFonts;
options::filesDroppedCallback = nullptr;

// Shut down the render engine
Expand Down
15 changes: 10 additions & 5 deletions src/raw_color_alpha_render_image_quantity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,16 @@ void RawColorAlphaRenderImageQuantity::prepare() {
// applied after compositing.

// Create the sourceProgram
program = render::engine->requestShader(
"TEXTURE_DRAW_RAW_RENDERIMAGE_PLAIN",
parent.addStructureRules({getImageOriginRule(imageOrigin), "TEXTURE_SHADE_COLORALPHA", "INVERSE_TONEMAP",
getIsPremultiplied() ? "" : "TEXTURE_PREMULTIPLY_OUT"}),
render::ShaderReplacementDefaults::SceneObjectNoSlice);
// clang-format off
std::vector<std::string> rules = parent.addStructureRules({
getImageOriginRule(imageOrigin),
"TEXTURE_SHADE_COLORALPHA", "INVERSE_TONEMAP",
getIsPremultiplied() ? "" : "TEXTURE_PREMULTIPLY_OUT"
});
rules = removeRule(rules, "GENERATE_VIEW_POS");

program = render::engine->requestShader("TEXTURE_DRAW_RAW_RENDERIMAGE_PLAIN", rules);
// clang-format on

program->setAttribute("a_position", render::engine->screenTrianglesCoords());
program->setTextureFromBuffer("t_depth", depths.getRenderTextureBuffer().get());
Expand Down
14 changes: 9 additions & 5 deletions src/raw_color_render_image_quantity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,15 @@ void RawColorRenderImageQuantity::refresh() {
void RawColorRenderImageQuantity::prepare() {

// Create the sourceProgram
program =
render::engine->requestShader("TEXTURE_DRAW_RAW_RENDERIMAGE_PLAIN",
parent.addStructureRules({getImageOriginRule(imageOrigin), "TEXTURE_SHADE_COLOR",
"INVERSE_TONEMAP", "PREMULTIPLY_LIT_COLOR"}),
render::ShaderReplacementDefaults::SceneObjectNoSlice);
// clang-format off
std::vector<std::string> rules = parent.addStructureRules({
getImageOriginRule(imageOrigin),
"TEXTURE_SHADE_COLOR", "INVERSE_TONEMAP", "PREMULTIPLY_LIT_COLOR"}
);
rules = removeRule(rules, "GENERATE_VIEW_POS");

program = render::engine->requestShader("TEXTURE_DRAW_RAW_RENDERIMAGE_PLAIN", rules);
// clang-format on

program->setAttribute("a_position", render::engine->screenTrianglesCoords());
program->setTextureFromBuffer("t_depth", depths.getRenderTextureBuffer().get());
Expand Down
9 changes: 9 additions & 0 deletions src/render/engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1200,5 +1200,14 @@ void Engine::preserveResourceUntilImguiFrameCompletes(std::shared_ptr<TextureBuf

void Engine::clearResourcesPreservedForImguiFrame() { resourcesPreservedForImGuiFrame.clear(); }


} // namespace render

// === Small free helpers

std::vector<std::string> removeRule(std::vector<std::string> initRules, std::string ruleName) {
initRules.erase(std::remove(initRules.begin(), initRules.end(), ruleName), initRules.end());
return initRules;
}

} // namespace polyscope
11 changes: 5 additions & 6 deletions src/render/opengl/shaders/texture_draw_shaders.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,14 +167,10 @@ R"(

// Fetch values from texture
float depth = texture(t_depth, tCoord).r;

${ GLOBAL_FRAGMENT_FILTER_PREP }$
${ GLOBAL_FRAGMENT_FILTER }$

if(depth > LARGE_FLOAT()) {
discard;
}

// Set the depth of the fragment from the stored texture data
// TODO: this a wasteful way to convert ray depth to gl_FragDepth, I am sure it can be done with much less arithmetic... figure it out
// WARNING this code is duplicated in other shaders
Expand All @@ -185,6 +181,8 @@ R"(
float fragdepth = fragDepthFromView(u_projMatrix, depthRange, viewPos);
gl_FragDepth = fragdepth;

${ GLOBAL_FRAGMENT_FILTER_PREP }$
${ GLOBAL_FRAGMENT_FILTER }$

// Shading
vec3 shadeNormal = vec3(0.f, 0.f, 0.f);
Expand Down Expand Up @@ -252,7 +250,6 @@ R"(

// Fetch values from texture
float depth = texture(t_depth, tCoord).r;

if(depth > LARGE_FLOAT()) {
discard;
}
Expand All @@ -267,6 +264,8 @@ R"(
float fragdepth = fragDepthFromView(u_projMatrix, depthRange, viewPos);
gl_FragDepth = fragdepth;

${ GLOBAL_FRAGMENT_FILTER_PREP }$
${ GLOBAL_FRAGMENT_FILTER }$

// Shading
${ GENERATE_SHADE_VALUE }$
Expand Down
10 changes: 7 additions & 3 deletions src/render_image_quantity_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ void RenderImageQuantityBase::drawPickDelayed() {
if (!pickProgram) preparePick();

// set uniforms
parent.setStructureUniforms(*pickProgram);
glm::mat4 P = view::getCameraPerspectiveMatrix();
glm::mat4 Pinv = glm::inverse(P);

Expand All @@ -111,11 +112,14 @@ void RenderImageQuantityBase::preparePick() {

// Create the sourceProgram
// clang-format off
pickProgram = render::engine->requestShader("TEXTURE_DRAW_RENDERIMAGE_PLAIN",
parent.addStructureRules({
std::vector<std::string> rules = parent.addStructureRules({
getImageOriginRule(imageOrigin),
"SHADECOLOR_FROM_UNIFORM",
}),
});
rules = removeRule(rules, "GENERATE_VIEW_POS");

pickProgram = render::engine->requestShader("TEXTURE_DRAW_RENDERIMAGE_PLAIN",
rules,
render::ShaderReplacementDefaults::Pick
);
// clang-format on
Expand Down
9 changes: 5 additions & 4 deletions src/scalar_render_image_quantity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,17 +72,18 @@ void ScalarRenderImageQuantity::prepare() {

// Create the sourceProgram
// clang-format off
program = render::engine->requestShader("TEXTURE_DRAW_RENDERIMAGE_PLAIN",
render::engine->addMaterialRules(material.get(),
std::vector<std::string> rules = render::engine->addMaterialRules(material.get(),
addScalarRules(
parent.addStructureRules({
getImageOriginRule(imageOrigin),
hasNormals ? "SHADE_NORMAL_FROM_TEXTURE" : "SHADE_NORMAL_FROM_VIEWPOS_VAR",
"TEXTURE_PROPAGATE_VALUE",
})
)
),
render::ShaderReplacementDefaults::SceneObjectNoSlice);
);
rules = removeRule(rules, "GENERATE_VIEW_POS");

program = render::engine->requestShader("TEXTURE_DRAW_RENDERIMAGE_PLAIN", rules);
// clang-format on

program->setAttribute("a_position", render::engine->screenTrianglesCoords());
Expand Down
70 changes: 63 additions & 7 deletions test/src/floating_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,12 @@ TEST_F(PolyscopeTest, FloatingRenderImageTest) {
im->setEnabled(true);
polyscope::show(3);
polyscope::pickAtScreenCoords(glm::vec2(0.3, 0.8));

// add a slice plane
polyscope::addSceneSlicePlane();
polyscope::show(3);
polyscope::pickAtScreenCoords(glm::vec2(0.3, 0.8));
polyscope::removeLastSceneSlicePlane();
}
{ // with no normals
polyscope::DepthRenderImageQuantity* im = polyscope::addDepthRenderImageQuantity(
Expand All @@ -112,6 +118,12 @@ TEST_F(PolyscopeTest, FloatingRenderImageTest) {
im->setEnabled(true);
polyscope::show(3);
polyscope::pickAtScreenCoords(glm::vec2(0.3, 0.8));

// add a slice plane
polyscope::addSceneSlicePlane();
polyscope::show(3);
polyscope::pickAtScreenCoords(glm::vec2(0.3, 0.8));
polyscope::removeLastSceneSlicePlane();
}

{ // ColorImageQuantity
Expand All @@ -121,6 +133,12 @@ TEST_F(PolyscopeTest, FloatingRenderImageTest) {
im->setEnabled(true);
polyscope::show(3);
polyscope::pickAtScreenCoords(glm::vec2(0.3, 0.8));

// add a slice plane
polyscope::addSceneSlicePlane();
polyscope::show(3);
polyscope::pickAtScreenCoords(glm::vec2(0.3, 0.8));
polyscope::removeLastSceneSlicePlane();
}
{ // with no normals
polyscope::ColorRenderImageQuantity* im = polyscope::addColorRenderImageQuantity(
Expand All @@ -129,6 +147,12 @@ TEST_F(PolyscopeTest, FloatingRenderImageTest) {
im->setEnabled(true);
polyscope::show(3);
polyscope::pickAtScreenCoords(glm::vec2(0.3, 0.8));

// add a slice plane
polyscope::addSceneSlicePlane();
polyscope::show(3);
polyscope::pickAtScreenCoords(glm::vec2(0.3, 0.8));
polyscope::removeLastSceneSlicePlane();
}

{ // ScalarRenderImageQuantity
Expand All @@ -138,6 +162,12 @@ TEST_F(PolyscopeTest, FloatingRenderImageTest) {
im->setEnabled(true);
polyscope::show(3);
polyscope::pickAtScreenCoords(glm::vec2(0.3, 0.8));

// add a slice plane
polyscope::addSceneSlicePlane();
polyscope::show(3);
polyscope::pickAtScreenCoords(glm::vec2(0.3, 0.8));
polyscope::removeLastSceneSlicePlane();
}
{ // with no normals
polyscope::ScalarRenderImageQuantity* im = polyscope::addScalarRenderImageQuantity(
Expand All @@ -146,7 +176,14 @@ TEST_F(PolyscopeTest, FloatingRenderImageTest) {
im->setEnabled(true);
polyscope::show(3);
polyscope::pickAtScreenCoords(glm::vec2(0.3, 0.8));

// add a slice plane
polyscope::addSceneSlicePlane();
polyscope::show(3);
polyscope::pickAtScreenCoords(glm::vec2(0.3, 0.8));
polyscope::removeLastSceneSlicePlane();
}

{ // categorical
polyscope::ScalarRenderImageQuantity* im =
polyscope::addScalarRenderImageQuantity("render im scalar", dimX, dimY, depthVals, normalVals, scalarVals,
Expand All @@ -155,6 +192,12 @@ TEST_F(PolyscopeTest, FloatingRenderImageTest) {
im->setEnabled(true);
polyscope::show(3);
polyscope::pickAtScreenCoords(glm::vec2(0.3, 0.8));

// add a slice plane
polyscope::addSceneSlicePlane();
polyscope::show(3);
polyscope::pickAtScreenCoords(glm::vec2(0.3, 0.8));
polyscope::removeLastSceneSlicePlane();
}

{ // RawColorImageQuantity
Expand All @@ -164,6 +207,12 @@ TEST_F(PolyscopeTest, FloatingRenderImageTest) {
im->setEnabled(true);
polyscope::show(3);
polyscope::pickAtScreenCoords(glm::vec2(0.3, 0.8));

// add a slice plane
polyscope::addSceneSlicePlane();
polyscope::show(3);
polyscope::pickAtScreenCoords(glm::vec2(0.3, 0.8));
polyscope::removeLastSceneSlicePlane();
}

{ // RawColorAlphaImageQuantity
Expand All @@ -175,16 +224,23 @@ TEST_F(PolyscopeTest, FloatingRenderImageTest) {
im->setIsPremultiplied(true);
polyscope::show(3);
polyscope::pickAtScreenCoords(glm::vec2(0.3, 0.8));
}

// make sure it doesn't blow up with transparancy
polyscope::options::transparencyMode = polyscope::TransparencyMode::Simple;
polyscope::show(3);
// add a slice plane
polyscope::addSceneSlicePlane();
polyscope::show(3);
polyscope::pickAtScreenCoords(glm::vec2(0.3, 0.8));

polyscope::options::transparencyMode = polyscope::TransparencyMode::Pretty;
polyscope::show(3);
// make sure it doesn't blow up with transparancy
polyscope::options::transparencyMode = polyscope::TransparencyMode::Simple;
polyscope::show(3);

polyscope::options::transparencyMode = polyscope::TransparencyMode::None;
polyscope::options::transparencyMode = polyscope::TransparencyMode::Pretty;
polyscope::show(3);

polyscope::options::transparencyMode = polyscope::TransparencyMode::None;

polyscope::removeLastSceneSlicePlane();
}

// make sure removing works
polyscope::removeFloatingQuantity("render im depth", true);
Expand Down