forked from nmwsharp/polyscope
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdepth_render_image_quantity.cpp
112 lines (81 loc) · 3.56 KB
/
depth_render_image_quantity.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
// Copyright 2017-2023, Nicholas Sharp and the Polyscope contributors. https://polyscope.run
#include "polyscope/polyscope.h"
#include "polyscope/depth_render_image_quantity.h"
#include "imgui.h"
namespace polyscope {
DepthRenderImageQuantity::DepthRenderImageQuantity(Structure& parent_, std::string name, size_t dimX, size_t dimY,
const std::vector<float>& depthData,
const std::vector<glm::vec3>& normalData, ImageOrigin imageOrigin_)
: RenderImageQuantityBase(parent_, name, dimX, dimY, depthData, normalData, imageOrigin_),
color(uniquePrefix() + "#color", getNextUniqueColor()) {}
void DepthRenderImageQuantity::draw() {}
void DepthRenderImageQuantity::drawDelayed() {
if (!isEnabled()) return;
if (!program) prepare();
// set uniforms
glm::mat4 P = view::getCameraPerspectiveMatrix();
glm::mat4 Pinv = glm::inverse(P);
program->setUniform("u_projMatrix", glm::value_ptr(P));
program->setUniform("u_invProjMatrix", glm::value_ptr(Pinv));
program->setUniform("u_viewport", render::engine->getCurrentViewport());
program->setUniform("u_baseColor", color.get());
program->setUniform("u_transparency", transparency.get());
render::engine->setMaterialUniforms(*program, material.get());
// draw
program->draw();
}
void DepthRenderImageQuantity::buildCustomUI() {
ImGui::SameLine();
if (ImGui::ColorEdit3("color", &color.get()[0], ImGuiColorEditFlags_NoInputs)) {
setColor(getColor());
}
ImGui::SameLine();
// == Options popup
if (ImGui::Button("Options")) {
ImGui::OpenPopup("OptionsPopup");
}
if (ImGui::BeginPopup("OptionsPopup")) {
RenderImageQuantityBase::addOptionsPopupEntries();
ImGui::EndPopup();
}
}
void DepthRenderImageQuantity::refresh() {
program = nullptr;
RenderImageQuantityBase::refresh();
}
void DepthRenderImageQuantity::prepare() {
// no extra data to push for this one
// Create the sourceProgram
// clang-format off
program = render::engine->requestShader("TEXTURE_DRAW_RENDERIMAGE_PLAIN",
render::engine->addMaterialRules(material.get(),
{
getImageOriginRule(imageOrigin),
hasNormals ? "SHADE_NORMAL_FROM_TEXTURE" : "SHADE_NORMAL_FROM_VIEWPOS_VAR",
"SHADE_BASECOLOR",
}
),
render::ShaderReplacementDefaults::Process);
// clang-format on
program->setAttribute("a_position", render::engine->screenTrianglesCoords());
program->setTextureFromBuffer("t_depth", depths.getRenderTextureBuffer().get());
if (hasNormals) {
program->setTextureFromBuffer("t_normal", normals.getRenderTextureBuffer().get());
}
render::engine->setMaterial(*program, material.get());
}
std::string DepthRenderImageQuantity::niceName() { return name + " (render image)"; }
DepthRenderImageQuantity* DepthRenderImageQuantity::setColor(glm::vec3 newVal) {
color = newVal;
polyscope::requestRedraw();
return this;
}
glm::vec3 DepthRenderImageQuantity::getColor() { return color.get(); }
// Instantiate a construction helper which is used to avoid header dependencies. See forward declaration and note in
// structure.ipp.
DepthRenderImageQuantity* createDepthRenderImage(Structure& parent, std::string name, size_t dimX, size_t dimY,
const std::vector<float>& depthData,
const std::vector<glm::vec3>& normalData, ImageOrigin imageOrigin) {
return new DepthRenderImageQuantity(parent, name, dimX, dimY, depthData, normalData, imageOrigin);
}
} // namespace polyscope