36 bool show_axis_z_ =
false;
38 bool is_3d_grid_ =
false;
40 float v3d_clip_end_ = 0.0f;
51 is_3d_grid_ =
state.is_space_v3d();
59 gpu::Texture **depth_tx =
state.xray_enabled ? &res.xray_depth_tx : &res.depth_tx;
60 gpu::Texture **depth_infront_tx =
state.use_in_front ? &res.depth_target_in_front_tx :
67 if (
state.is_space_image()) {
69 auto &sub = grid_ps_.sub(
"grid_background");
70 sub.shader_set(res.shaders->grid_background.get());
72 res.theme.colors.background, res.theme.colors.grid, 0.5);
73 sub.push_constant(
"ucolor", color_back);
74 sub.push_constant(
"tile_scale",
float3(data_.size));
75 sub.bind_texture(
"depth_buffer", depth_tx);
76 sub.draw(res.shapes.quad_solid.get());
79 auto &sub = grid_ps_.sub(
"grid");
80 sub.shader_set(res.shaders->grid.get());
81 sub.bind_ubo(
"grid_buf", &data_);
85 sub.push_constant(
"grid_flag", &zneg_flag_);
86 sub.push_constant(
"plane_axes", &zplane_axes_);
87 sub.draw(res.shapes.grid.get());
90 sub.push_constant(
"grid_flag", &grid_flag_);
91 sub.push_constant(
"plane_axes", &grid_axes_);
92 sub.draw(res.shapes.grid.get());
95 sub.push_constant(
"grid_flag", &zpos_flag_);
96 sub.push_constant(
"plane_axes", &zplane_axes_);
97 sub.draw(res.shapes.grid.get());
100 if (
state.is_space_image()) {
106 auto &sub = grid_ps_.sub(
"wire_border");
107 sub.shader_set(res.shaders->grid_image.get());
108 sub.push_constant(
"ucolor", theme_color);
109 tile_pos_buf_.clear();
112 tile_pos_buf_.append(
float4(
x,
y, 0.0f, 0.0f));
115 tile_pos_buf_.push_update();
116 sub.bind_ssbo(
"tile_pos_buf", &tile_pos_buf_);
117 sub.draw(res.shapes.quad_wire.get(), tile_pos_buf_.size());
131 manager.submit(grid_ps_,
view);
137 data_.line_size =
max_ff(0.0f,
U.pixelsize - 1.0f) * 0.5f;
139 grid_flag_ = zneg_flag_ = zpos_flag_ = 0;
140 show_axis_z_ =
false;
142 return (is_3d_grid_) ? init_3d(
state) : init_2d(
state);
149 data_.steps[
i][0] = grid_steps_x[
i];
150 data_.steps[
i][1] = grid_steps_y[
i];
154 bool init_2d(
const State &
state)
156 if (
state.hide_overlays) {
161 std::array<float, SI_GRID_STEPS_LEN> grid_steps_x = {
162 0.001f, 0.01f, 0.1f, 1.0f, 10.0f, 100.0f, 1000.0f, 10000.0f};
163 std::array<float, SI_GRID_STEPS_LEN> grid_steps_y = {0.0f};
166 const bool is_uv_edit = sima->mode ==
SI_MODE_UV;
168 const bool background_enabled = is_uv_edit ? (!
state.hide_overlays &&
169 (sima->overlay.flag &
172 if (background_enabled) {
180 if (background_enabled && draw_grid) {
189 data_.distance = 1.0f;
190 data_.size =
float4(1.0f);
192 data_.size[0] =
float(sima->tile_grid_shape[0]);
193 data_.size[1] =
float(sima->tile_grid_shape[1]);
198 copy_steps_to_data(grid_steps_x, grid_steps_y);
202 bool init_3d(
const State &
state)
212 const bool show_any = show_axis_x || show_axis_y || show_axis_z || show_floor ||
215 if (
state.hide_overlays || !show_any) {
219 std::array<float, SI_GRID_STEPS_LEN> grid_steps = {
220 0.001f, 0.01f, 0.1f, 1.0f, 10.0f, 100.0f, 1000.0f, 10000.0f};
247 if (show_ortho_grid) {
266 v3d_clip_end_ = ((
Camera *)(camera_object->
data))->clip_end;
279 copy_steps_to_data(grid_steps, grid_steps);
301 zneg_flag_ = zpos_flag_;
305 if ((
view.is_persp() && (position.
z > 0.0f)) || (!
view.is_persp() && (backward.
z < 0.0f))) {
319 data_.size =
float4(v3d_clip_end_);
320 if (!
view.is_persp()) {
324 data_.distance = v3d_clip_end_ / 2.0f;
331 float viewinvscale =
len_v3(
view.viewinv()[0]);
332 data_.distance *= viewinvscale;