Changeset View
Changeset View
Standalone View
Standalone View
source/blender/draw/modes/object_mode.c
| Show First 20 Lines • Show All 326 Lines • ▼ Show 20 Lines | |||||
| static struct { | static struct { | ||||
| /* Instance Data format */ | /* Instance Data format */ | ||||
| struct GPUVertFormat *empty_image_format; | struct GPUVertFormat *empty_image_format; | ||||
| struct GPUVertFormat *empty_image_wire_format; | struct GPUVertFormat *empty_image_wire_format; | ||||
| OBJECT_Shaders sh_data[GPU_SHADER_CFG_LEN]; | OBJECT_Shaders sh_data[GPU_SHADER_CFG_LEN]; | ||||
| float grid_settings[5]; | float grid_distance; | ||||
| float grid_mesh_size; | float grid_mesh_size; | ||||
| int grid_flag; | int grid_flag; | ||||
| float grid_axes[3]; | float grid_axes[3]; | ||||
| int zpos_flag; | int zpos_flag; | ||||
| int zneg_flag; | int zneg_flag; | ||||
| float zplane_axes[3]; | float zplane_axes[3]; | ||||
| float inv_viewport_size[2]; | float inv_viewport_size[2]; | ||||
| float grid_steps[8]; | |||||
| bool draw_grid; | bool draw_grid; | ||||
| /* Temp buffer textures */ | /* Temp buffer textures */ | ||||
| struct GPUTexture *outlines_depth_tx; | struct GPUTexture *outlines_depth_tx; | ||||
| struct GPUTexture *outlines_id_tx; | struct GPUTexture *outlines_id_tx; | ||||
| struct GPUTexture *outlines_color_tx; | struct GPUTexture *outlines_color_tx; | ||||
| struct GPUTexture *outlines_blur_tx; | struct GPUTexture *outlines_blur_tx; | ||||
| ListBase smoke_domains; | ListBase smoke_domains; | ||||
| ▲ Show 20 Lines • Show All 203 Lines • ▼ Show 20 Lines | static void OBJECT_engine_init(void *vedata) | ||||
| { | { | ||||
| /* Grid precompute */ | /* Grid precompute */ | ||||
| float viewinv[4][4], wininv[4][4]; | float viewinv[4][4], wininv[4][4]; | ||||
| float viewmat[4][4], winmat[4][4]; | float viewmat[4][4], winmat[4][4]; | ||||
| View3D *v3d = draw_ctx->v3d; | View3D *v3d = draw_ctx->v3d; | ||||
| Scene *scene = draw_ctx->scene; | Scene *scene = draw_ctx->scene; | ||||
| RegionView3D *rv3d = draw_ctx->rv3d; | RegionView3D *rv3d = draw_ctx->rv3d; | ||||
| float grid_scale = ED_view3d_grid_scale(scene, v3d, NULL); | |||||
| float grid_res; | |||||
| const bool show_axis_x = (v3d->gridflag & V3D_SHOW_X) != 0; | const bool show_axis_x = (v3d->gridflag & V3D_SHOW_X) != 0; | ||||
| const bool show_axis_y = (v3d->gridflag & V3D_SHOW_Y) != 0; | const bool show_axis_y = (v3d->gridflag & V3D_SHOW_Y) != 0; | ||||
| const bool show_axis_z = (v3d->gridflag & V3D_SHOW_Z) != 0; | const bool show_axis_z = (v3d->gridflag & V3D_SHOW_Z) != 0; | ||||
| const bool show_floor = (v3d->gridflag & V3D_SHOW_FLOOR) != 0; | const bool show_floor = (v3d->gridflag & V3D_SHOW_FLOOR) != 0; | ||||
| const bool show_ortho_grid = (v3d->gridflag & V3D_SHOW_ORTHO_GRID) != 0; | const bool show_ortho_grid = (v3d->gridflag & V3D_SHOW_ORTHO_GRID) != 0; | ||||
| e_data.draw_grid = show_axis_x || show_axis_y || show_axis_z || show_floor; | e_data.draw_grid = show_axis_x || show_axis_y || show_axis_z || show_floor; | ||||
| Show All 12 Lines | if (winmat[3][3] == 0.0f) { | ||||
| /* convert the view vectors to view space */ | /* convert the view vectors to view space */ | ||||
| for (int i = 0; i < 2; i++) { | for (int i = 0; i < 2; i++) { | ||||
| mul_m4_v4(wininv, viewvecs[i]); | mul_m4_v4(wininv, viewvecs[i]); | ||||
| mul_v3_fl(viewvecs[i], 1.0f / viewvecs[i][2]); /* perspective divide */ | mul_v3_fl(viewvecs[i], 1.0f / viewvecs[i][2]); /* perspective divide */ | ||||
| } | } | ||||
| fov = angle_v3v3(viewvecs[0], viewvecs[1]) / 2.0f; | fov = angle_v3v3(viewvecs[0], viewvecs[1]) / 2.0f; | ||||
| grid_res = fabsf(tanf(fov)) / grid_scale; | |||||
| e_data.grid_flag = (1 << 4); /* XY plane */ | e_data.grid_flag = (1 << 4); /* XY plane */ | ||||
| if (show_axis_x) { | if (show_axis_x) { | ||||
| e_data.grid_flag |= SHOW_AXIS_X; | e_data.grid_flag |= SHOW_AXIS_X; | ||||
| } | } | ||||
| if (show_axis_y) { | if (show_axis_y) { | ||||
| e_data.grid_flag |= SHOW_AXIS_Y; | e_data.grid_flag |= SHOW_AXIS_Y; | ||||
| } | } | ||||
| if (show_floor) { | if (show_floor) { | ||||
| e_data.grid_flag |= SHOW_GRID; | e_data.grid_flag |= SHOW_GRID; | ||||
| } | } | ||||
| } | } | ||||
| else { | else { | ||||
| if (rv3d->view != RV3D_VIEW_USER) { | |||||
| /* Allow 3 more subdivisions. */ | |||||
| grid_scale /= powf(v3d->gridsubdiv, 3); | |||||
| } | |||||
| float viewdist = 1.0f / max_ff(fabsf(winmat[0][0]), fabsf(winmat[1][1])); | |||||
| grid_res = viewdist / grid_scale; | |||||
| if (ELEM(rv3d->view, RV3D_VIEW_RIGHT, RV3D_VIEW_LEFT)) { | if (ELEM(rv3d->view, RV3D_VIEW_RIGHT, RV3D_VIEW_LEFT)) { | ||||
| e_data.draw_grid = show_ortho_grid; | e_data.draw_grid = show_ortho_grid; | ||||
| e_data.grid_flag = PLANE_YZ | SHOW_AXIS_Y | SHOW_AXIS_Z | SHOW_GRID | GRID_BACK; | e_data.grid_flag = PLANE_YZ | SHOW_AXIS_Y | SHOW_AXIS_Z | SHOW_GRID | GRID_BACK; | ||||
| } | } | ||||
| else if (ELEM(rv3d->view, RV3D_VIEW_TOP, RV3D_VIEW_BOTTOM)) { | else if (ELEM(rv3d->view, RV3D_VIEW_TOP, RV3D_VIEW_BOTTOM)) { | ||||
| e_data.draw_grid = show_ortho_grid; | e_data.draw_grid = show_ortho_grid; | ||||
| e_data.grid_flag = PLANE_XY | SHOW_AXIS_X | SHOW_AXIS_Y | SHOW_GRID | GRID_BACK; | e_data.grid_flag = PLANE_XY | SHOW_AXIS_X | SHOW_AXIS_Y | SHOW_GRID | GRID_BACK; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 61 Lines • ▼ Show 20 Lines | if (!sh_data->outline_resolve) { | ||||
| if (rv3d->persp == RV3D_CAMOB && v3d->camera && v3d->camera->type == OB_CAMERA) { | if (rv3d->persp == RV3D_CAMOB && v3d->camera && v3d->camera->type == OB_CAMERA) { | ||||
| Object *camera_object = DEG_get_evaluated_object(draw_ctx->depsgraph, v3d->camera); | Object *camera_object = DEG_get_evaluated_object(draw_ctx->depsgraph, v3d->camera); | ||||
| dist = ((Camera *)(camera_object->data))->clip_end; | dist = ((Camera *)(camera_object->data))->clip_end; | ||||
| } | } | ||||
| else { | else { | ||||
| dist = v3d->clip_end; | dist = v3d->clip_end; | ||||
| } | } | ||||
| e_data.grid_settings[0] = dist / 2.0f; /* gridDistance */ | e_data.grid_distance = dist / 2.0f; /* gridDistance */ | ||||
| e_data.grid_settings[1] = grid_res; /* gridResolution */ | |||||
| e_data.grid_settings[2] = grid_scale; /* gridScale */ | |||||
| e_data.grid_settings[3] = v3d->gridsubdiv; /* gridSubdiv */ | |||||
| e_data.grid_settings[4] = (v3d->gridsubdiv > 1) ? 1.0f / logf(v3d->gridsubdiv) : | |||||
| 0.0f; /* 1/log(gridSubdiv) */ | |||||
| if (winmat[3][3] == 0.0f) { | if (winmat[3][3] == 0.0f) { | ||||
| e_data.grid_mesh_size = dist; | e_data.grid_mesh_size = dist; | ||||
| } | } | ||||
| else { | else { | ||||
| float viewdist = 1.0f / min_ff(fabsf(winmat[0][0]), fabsf(winmat[1][1])); | float viewdist = 1.0f / min_ff(fabsf(winmat[0][0]), fabsf(winmat[1][1])); | ||||
| e_data.grid_mesh_size = viewdist * dist; | e_data.grid_mesh_size = viewdist * dist; | ||||
| } | } | ||||
| ED_view3d_grid_steps(scene, v3d, rv3d, e_data.grid_steps); | |||||
| } | } | ||||
| copy_v2_v2(e_data.inv_viewport_size, DRW_viewport_size_get()); | copy_v2_v2(e_data.inv_viewport_size, DRW_viewport_size_get()); | ||||
| invert_v2(e_data.inv_viewport_size); | invert_v2(e_data.inv_viewport_size); | ||||
| } | } | ||||
| static void OBJECT_engine_free(void) | static void OBJECT_engine_free(void) | ||||
| { | { | ||||
| ▲ Show 20 Lines • Show All 794 Lines • ▼ Show 20 Lines | g_data->custom_shapes = BLI_ghash_ptr_new(__func__); | ||||
| struct GPUBatch *geom = DRW_cache_grid_get(); | struct GPUBatch *geom = DRW_cache_grid_get(); | ||||
| float grid_line_size = max_ff(0.0f, U.pixelsize - 1.0f) * 0.5f; | float grid_line_size = max_ff(0.0f, U.pixelsize - 1.0f) * 0.5f; | ||||
| /* Create 3 quads to render ordered transparency Z axis */ | /* Create 3 quads to render ordered transparency Z axis */ | ||||
| DRWShadingGroup *grp = DRW_shgroup_create(sh_data->grid, psl->grid); | DRWShadingGroup *grp = DRW_shgroup_create(sh_data->grid, psl->grid); | ||||
| DRW_shgroup_uniform_int(grp, "gridFlag", &e_data.zneg_flag, 1); | DRW_shgroup_uniform_int(grp, "gridFlag", &e_data.zneg_flag, 1); | ||||
| DRW_shgroup_uniform_vec3(grp, "planeAxes", e_data.zplane_axes, 1); | DRW_shgroup_uniform_vec3(grp, "planeAxes", e_data.zplane_axes, 1); | ||||
| DRW_shgroup_uniform_vec4(grp, "gridSettings", e_data.grid_settings, 1); | DRW_shgroup_uniform_vec3(grp, "screen_vecs[0]", DRW_viewport_screenvecs_get(), 2); | ||||
| DRW_shgroup_uniform_float(grp, "gridDistance", &e_data.grid_distance, 1); | |||||
| DRW_shgroup_uniform_float_copy(grp, "lineKernel", grid_line_size); | DRW_shgroup_uniform_float_copy(grp, "lineKernel", grid_line_size); | ||||
| DRW_shgroup_uniform_float_copy(grp, "meshSize", e_data.grid_mesh_size); | DRW_shgroup_uniform_float_copy(grp, "meshSize", e_data.grid_mesh_size); | ||||
| DRW_shgroup_uniform_float(grp, "gridOneOverLogSubdiv", &e_data.grid_settings[4], 1); | |||||
| DRW_shgroup_uniform_block(grp, "globalsBlock", G_draw.block_ubo); | DRW_shgroup_uniform_block(grp, "globalsBlock", G_draw.block_ubo); | ||||
| DRW_shgroup_uniform_texture_ref(grp, "depthBuffer", &dtxl->depth); | DRW_shgroup_uniform_texture_ref(grp, "depthBuffer", &dtxl->depth); | ||||
| DRW_shgroup_call(grp, geom, NULL); | DRW_shgroup_call(grp, geom, NULL); | ||||
| grp = DRW_shgroup_create(sh_data->grid, psl->grid); | grp = DRW_shgroup_create(sh_data->grid, psl->grid); | ||||
| DRW_shgroup_uniform_int(grp, "gridFlag", &e_data.grid_flag, 1); | DRW_shgroup_uniform_int(grp, "gridFlag", &e_data.grid_flag, 1); | ||||
| DRW_shgroup_uniform_vec3(grp, "planeAxes", e_data.grid_axes, 1); | DRW_shgroup_uniform_vec3(grp, "planeAxes", e_data.grid_axes, 1); | ||||
| DRW_shgroup_uniform_block(grp, "globalsBlock", G_draw.block_ubo); | DRW_shgroup_uniform_block(grp, "globalsBlock", G_draw.block_ubo); | ||||
| DRW_shgroup_uniform_texture_ref(grp, "depthBuffer", &dtxl->depth); | DRW_shgroup_uniform_texture_ref(grp, "depthBuffer", &dtxl->depth); | ||||
| DRW_shgroup_uniform_float(grp, "grid_steps", e_data.grid_steps, ARRAY_SIZE(e_data.grid_steps)); | |||||
| DRW_shgroup_call(grp, geom, NULL); | DRW_shgroup_call(grp, geom, NULL); | ||||
| grp = DRW_shgroup_create(sh_data->grid, psl->grid); | grp = DRW_shgroup_create(sh_data->grid, psl->grid); | ||||
| DRW_shgroup_uniform_int(grp, "gridFlag", &e_data.zpos_flag, 1); | DRW_shgroup_uniform_int(grp, "gridFlag", &e_data.zpos_flag, 1); | ||||
| DRW_shgroup_uniform_vec3(grp, "planeAxes", e_data.zplane_axes, 1); | DRW_shgroup_uniform_vec3(grp, "planeAxes", e_data.zplane_axes, 1); | ||||
| DRW_shgroup_uniform_block(grp, "globalsBlock", G_draw.block_ubo); | DRW_shgroup_uniform_block(grp, "globalsBlock", G_draw.block_ubo); | ||||
| DRW_shgroup_uniform_texture_ref(grp, "depthBuffer", &dtxl->depth); | DRW_shgroup_uniform_texture_ref(grp, "depthBuffer", &dtxl->depth); | ||||
| DRW_shgroup_call(grp, geom, NULL); | DRW_shgroup_call(grp, geom, NULL); | ||||
| ▲ Show 20 Lines • Show All 2,409 Lines • Show Last 20 Lines | |||||