37 bool enabled_ =
false;
54 auto &sub = grid_ps_.
sub(
"grid_background");
58 sub.push_constant(
"ucolor", color_back);
59 sub.push_constant(
"tile_scale",
float3(data_.size));
60 sub.bind_texture(
"depthBuffer", &res.
depth_tx);
64 auto &sub = grid_ps_.
sub(
"grid");
66 sub.bind_ubo(
"grid_buf", &data_);
68 sub.bind_texture(
"depth_tx", &res.
depth_tx);
70 sub.push_constant(
"grid_flag", zneg_flag_);
71 sub.push_constant(
"plane_axes", zplane_axes_);
72 sub.draw(shapes.
grid.get());
75 sub.push_constant(
"grid_flag", grid_flag_);
76 sub.push_constant(
"plane_axes", grid_axes_);
77 sub.draw(shapes.
grid.get());
80 sub.push_constant(
"grid_flag", zpos_flag_);
81 sub.push_constant(
"plane_axes", zplane_axes_);
82 sub.draw(shapes.
grid.get());
91 auto &sub = grid_ps_.
sub(
"wire_border");
93 sub.push_constant(
"ucolor", theme_color);
94 tile_pos_buf_.
clear();
95 for (
const int x :
IndexRange(data_.size[0])) {
96 for (
const int y :
IndexRange(data_.size[1])) {
101 sub.bind_ssbo(
"tile_pos_buf", &tile_pos_buf_);
113 manager.
submit(grid_ps_, view);
119 data_.line_size =
max_ff(0.0f,
U.pixelsize - 1.0f) * 0.5f;
130 data_.steps[i][0] = grid_steps_x[i];
131 data_.steps[i][1] = grid_steps_y[i];
135 bool init_2d(
const State &
state)
137 if (
state.hide_overlays) {
142 std::array<float, SI_GRID_STEPS_LEN> grid_steps_x = {
143 0.001f, 0.01f, 0.1f, 1.0f, 10.0f, 100.0f, 1000.0f, 10000.0f};
144 std::array<float, SI_GRID_STEPS_LEN> grid_steps_y = {0.0f};
147 const bool is_uv_edit = sima->mode ==
SI_MODE_UV;
149 const bool background_enabled = is_uv_edit ? (!
state.hide_overlays &&
150 (sima->overlay.flag &
153 if (background_enabled) {
161 if (background_enabled && draw_grid) {
170 data_.distance = 1.0f;
171 data_.size =
float4(1.0f);
173 data_.size[0] =
float(sima->tile_grid_shape[0]);
174 data_.size[1] =
float(sima->tile_grid_shape[1]);
179 copy_steps_to_data(grid_steps_x, grid_steps_y);
183 bool init_3d(
const State &
state,
const View &view)
193 const bool show_any = show_axis_x || show_axis_y || show_axis_z || show_floor ||
196 if (
state.hide_overlays || !show_any) {
200 std::array<float, SI_GRID_STEPS_LEN> grid_steps = {
201 0.001f, 0.01f, 0.1f, 1.0f, 10.0f, 100.0f, 1000.0f, 10000.0f};
245 zneg_flag_ = zpos_flag_;
249 if ((view.is_persp() && (campos[2] > 0.0f)) || (!view.is_persp() && (zvec[2] < 0.0f))) {
269 dist = ((
Camera *)(camera_object->
data))->clip_end;
278 if (view.is_persp()) {
279 data_.size =
float4(dist);
282 float viewdist = 1.0f /
min_ff(
fabsf(view.winmat()[0][0]),
fabsf(view.winmat()[1][1]));
283 data_.size =
float4(viewdist * dist);
286 data_.distance = dist / 2.0f;
295 float viewinvscale =
len_v3(view.viewinv()[0]);
296 data_.distance *= viewinvscale;
298 copy_steps_to_data(grid_steps, grid_steps);