2017-02-17 17:29:43 +01:00
|
|
|
/*
|
|
|
|
* Copyright 2016, Blender Foundation.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software Foundation,
|
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*
|
|
|
|
* Contributor(s): Blender Institute
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/** \file blender/draw/modes/object_mode.c
|
|
|
|
* \ingroup draw
|
|
|
|
*/
|
|
|
|
|
2017-02-17 17:53:51 +01:00
|
|
|
#include "DRW_engine.h"
|
2017-02-17 17:29:43 +01:00
|
|
|
#include "DRW_render.h"
|
|
|
|
|
2017-03-08 20:00:09 +01:00
|
|
|
#include "DNA_userdef_types.h"
|
|
|
|
#include "DNA_armature_types.h"
|
|
|
|
#include "DNA_camera_types.h"
|
2017-04-10 22:22:37 +02:00
|
|
|
#include "DNA_curve_types.h"
|
2017-06-01 02:26:24 +10:00
|
|
|
#include "DNA_mesh_types.h"
|
2017-11-16 15:12:32 -02:00
|
|
|
#include "DNA_meta_types.h"
|
2018-02-07 11:18:50 +11:00
|
|
|
#include "DNA_object_force_types.h"
|
2017-06-12 20:59:54 +10:00
|
|
|
#include "DNA_lightprobe_types.h"
|
2017-05-09 16:23:47 +02:00
|
|
|
#include "DNA_particle_types.h"
|
2017-03-08 20:00:09 +01:00
|
|
|
#include "DNA_view3d_types.h"
|
|
|
|
#include "DNA_world_types.h"
|
2017-02-17 17:29:43 +01:00
|
|
|
|
2017-05-20 22:57:47 +10:00
|
|
|
#include "BIF_gl.h"
|
|
|
|
|
2018-04-16 19:38:40 +02:00
|
|
|
#include "BLI_string_utils.h"
|
|
|
|
|
2017-04-10 22:22:37 +02:00
|
|
|
#include "BKE_anim.h"
|
2017-03-08 20:00:09 +01:00
|
|
|
#include "BKE_camera.h"
|
2017-04-10 22:22:37 +02:00
|
|
|
#include "BKE_curve.h"
|
2017-03-08 20:00:09 +01:00
|
|
|
#include "BKE_global.h"
|
2017-11-16 15:12:32 -02:00
|
|
|
#include "BKE_mball.h"
|
2017-09-21 12:55:14 +02:00
|
|
|
#include "BKE_object.h"
|
2017-05-19 18:32:40 +02:00
|
|
|
#include "BKE_particle.h"
|
2017-05-20 22:57:47 +10:00
|
|
|
#include "BKE_image.h"
|
2017-05-23 16:56:53 +02:00
|
|
|
#include "BKE_texture.h"
|
2017-03-08 20:00:09 +01:00
|
|
|
|
2017-03-22 21:28:59 +01:00
|
|
|
#include "ED_view3d.h"
|
|
|
|
|
2017-03-08 20:00:09 +01:00
|
|
|
#include "GPU_shader.h"
|
2017-05-20 22:57:47 +10:00
|
|
|
#include "GPU_texture.h"
|
2017-03-08 20:00:09 +01:00
|
|
|
|
2018-02-14 18:59:15 +01:00
|
|
|
#include "MEM_guardedalloc.h"
|
|
|
|
|
2017-03-08 20:00:09 +01:00
|
|
|
#include "UI_resources.h"
|
|
|
|
|
|
|
|
#include "draw_mode_engines.h"
|
2017-04-28 04:33:58 +10:00
|
|
|
#include "draw_manager_text.h"
|
2017-03-08 20:00:09 +01:00
|
|
|
#include "draw_common.h"
|
2017-02-17 17:29:43 +01:00
|
|
|
|
2018-01-18 15:58:02 +01:00
|
|
|
#include "DEG_depsgraph_query.h"
|
|
|
|
|
2017-03-22 21:28:59 +01:00
|
|
|
extern struct GPUUniformBuffer *globals_ubo; /* draw_common.c */
|
2017-05-23 16:56:53 +02:00
|
|
|
extern struct GPUTexture *globals_ramp; /* draw_common.c */
|
2017-03-18 22:14:53 +01:00
|
|
|
extern GlobalsUboStorage ts;
|
|
|
|
|
2018-04-16 19:38:40 +02:00
|
|
|
extern char datatoc_object_outline_prepass_frag_glsl[];
|
2017-03-20 14:59:27 +01:00
|
|
|
extern char datatoc_object_outline_resolve_frag_glsl[];
|
2017-03-21 19:29:58 +01:00
|
|
|
extern char datatoc_object_outline_detect_frag_glsl[];
|
2017-03-20 14:59:27 +01:00
|
|
|
extern char datatoc_object_outline_expand_frag_glsl[];
|
2017-03-22 21:28:59 +01:00
|
|
|
extern char datatoc_object_grid_frag_glsl[];
|
|
|
|
extern char datatoc_object_grid_vert_glsl[];
|
2017-05-20 22:57:47 +10:00
|
|
|
extern char datatoc_object_empty_image_frag_glsl[];
|
|
|
|
extern char datatoc_object_empty_image_vert_glsl[];
|
2017-09-30 19:34:23 +02:00
|
|
|
extern char datatoc_object_lightprobe_grid_vert_glsl[];
|
2017-05-23 14:13:25 +02:00
|
|
|
extern char datatoc_object_particle_prim_vert_glsl[];
|
2017-05-23 14:25:12 +02:00
|
|
|
extern char datatoc_object_particle_dot_vert_glsl[];
|
|
|
|
extern char datatoc_object_particle_dot_frag_glsl[];
|
2017-03-22 21:28:59 +01:00
|
|
|
extern char datatoc_common_globals_lib_glsl[];
|
2017-09-22 17:30:39 +02:00
|
|
|
extern char datatoc_common_fxaa_lib_glsl[];
|
2018-01-29 15:51:23 -02:00
|
|
|
extern char datatoc_gpu_shader_flat_color_frag_glsl[];
|
2018-04-17 13:01:01 +02:00
|
|
|
extern char datatoc_gpu_shader_flat_id_frag_glsl[];
|
2018-03-22 16:10:54 +01:00
|
|
|
extern char datatoc_common_fullscreen_vert_glsl[];
|
2017-09-30 19:34:23 +02:00
|
|
|
extern char datatoc_gpu_shader_uniform_color_frag_glsl[];
|
2017-03-18 22:14:53 +01:00
|
|
|
|
|
|
|
/* *********** LISTS *********** */
|
2017-02-22 18:52:07 +01:00
|
|
|
typedef struct OBJECT_PassList {
|
2017-03-08 20:00:09 +01:00
|
|
|
struct DRWPass *non_meshes;
|
|
|
|
struct DRWPass *ob_center;
|
2017-03-18 01:55:41 +01:00
|
|
|
struct DRWPass *outlines;
|
2017-03-22 02:14:23 +01:00
|
|
|
struct DRWPass *outlines_search;
|
2017-03-20 14:59:27 +01:00
|
|
|
struct DRWPass *outlines_expand;
|
2017-09-22 17:30:39 +02:00
|
|
|
struct DRWPass *outlines_bleed;
|
2017-03-20 14:59:27 +01:00
|
|
|
struct DRWPass *outlines_resolve;
|
2017-03-22 21:28:59 +01:00
|
|
|
struct DRWPass *grid;
|
2017-03-08 20:00:09 +01:00
|
|
|
struct DRWPass *bone_solid;
|
2018-04-22 22:49:36 +02:00
|
|
|
struct DRWPass *bone_outline;
|
2017-03-08 20:00:09 +01:00
|
|
|
struct DRWPass *bone_wire;
|
2017-05-17 14:33:34 +02:00
|
|
|
struct DRWPass *bone_envelope;
|
2018-05-06 18:36:27 +02:00
|
|
|
struct DRWPass *bone_axes;
|
2017-05-19 18:32:40 +02:00
|
|
|
struct DRWPass *particle;
|
2017-09-30 19:34:23 +02:00
|
|
|
struct DRWPass *lightprobes;
|
2017-05-24 14:28:48 +10:00
|
|
|
/* use for empty/background images */
|
|
|
|
struct DRWPass *reference_image;
|
2017-02-17 17:29:43 +01:00
|
|
|
} OBJECT_PassList;
|
|
|
|
|
2017-03-20 14:59:27 +01:00
|
|
|
typedef struct OBJECT_FramebufferList {
|
2018-03-25 17:46:48 +02:00
|
|
|
struct GPUFrameBuffer *outlines_fb;
|
|
|
|
struct GPUFrameBuffer *blur_fb;
|
|
|
|
struct GPUFrameBuffer *expand_fb;
|
2017-03-20 14:59:27 +01:00
|
|
|
} OBJECT_FramebufferList;
|
|
|
|
|
2017-03-26 20:13:34 +02:00
|
|
|
typedef struct OBJECT_StorageList {
|
2017-04-29 16:52:12 +10:00
|
|
|
struct OBJECT_PrivateData *g_data;
|
2017-03-26 20:13:34 +02:00
|
|
|
} OBJECT_StorageList;
|
|
|
|
|
2017-03-08 20:00:09 +01:00
|
|
|
typedef struct OBJECT_Data {
|
2017-04-03 19:32:05 +02:00
|
|
|
void *engine_type;
|
2017-04-12 19:49:19 +10:00
|
|
|
OBJECT_FramebufferList *fbl;
|
2017-05-16 03:03:58 +02:00
|
|
|
DRWViewportEmptyList *txl;
|
2017-03-08 20:00:09 +01:00
|
|
|
OBJECT_PassList *psl;
|
2017-04-12 19:49:19 +10:00
|
|
|
OBJECT_StorageList *stl;
|
2017-03-08 20:00:09 +01:00
|
|
|
} OBJECT_Data;
|
|
|
|
|
2017-03-18 22:14:53 +01:00
|
|
|
/* *********** STATIC *********** */
|
|
|
|
|
2017-10-07 15:57:14 +11:00
|
|
|
typedef struct OBJECT_PrivateData {
|
2017-03-18 22:14:53 +01:00
|
|
|
/* Empties */
|
|
|
|
DRWShadingGroup *plain_axes;
|
|
|
|
DRWShadingGroup *cube;
|
|
|
|
DRWShadingGroup *circle;
|
|
|
|
DRWShadingGroup *sphere;
|
|
|
|
DRWShadingGroup *cone;
|
|
|
|
DRWShadingGroup *single_arrow;
|
|
|
|
DRWShadingGroup *single_arrow_line;
|
|
|
|
DRWShadingGroup *arrows;
|
|
|
|
DRWShadingGroup *axis_names;
|
2017-05-20 22:57:47 +10:00
|
|
|
/* GPUTexture -> EmptyImageShadingGroupData */
|
|
|
|
GHash *image_plane_map;
|
2017-03-18 22:14:53 +01:00
|
|
|
|
2017-04-10 22:22:37 +02:00
|
|
|
/* Force Field */
|
|
|
|
DRWShadingGroup *field_wind;
|
|
|
|
DRWShadingGroup *field_force;
|
|
|
|
DRWShadingGroup *field_vortex;
|
|
|
|
DRWShadingGroup *field_curve_sta;
|
|
|
|
DRWShadingGroup *field_curve_end;
|
|
|
|
DRWShadingGroup *field_tube_limit;
|
|
|
|
DRWShadingGroup *field_cone_limit;
|
|
|
|
|
2017-03-18 22:14:53 +01:00
|
|
|
/* Speaker */
|
|
|
|
DRWShadingGroup *speaker;
|
|
|
|
|
2017-06-27 14:59:53 +02:00
|
|
|
/* Probe */
|
|
|
|
DRWShadingGroup *probe_cube;
|
|
|
|
DRWShadingGroup *probe_planar;
|
|
|
|
DRWShadingGroup *probe_grid;
|
2017-06-07 16:00:10 +02:00
|
|
|
|
2017-11-16 15:12:32 -02:00
|
|
|
/* MetaBalls */
|
2018-02-16 02:01:09 -02:00
|
|
|
DRWShadingGroup *mball_handle;
|
2017-11-16 15:12:32 -02:00
|
|
|
|
2017-03-18 22:14:53 +01:00
|
|
|
/* Lamps */
|
|
|
|
DRWShadingGroup *lamp_center;
|
|
|
|
DRWShadingGroup *lamp_groundpoint;
|
|
|
|
DRWShadingGroup *lamp_groundline;
|
|
|
|
DRWShadingGroup *lamp_circle;
|
|
|
|
DRWShadingGroup *lamp_circle_shadow;
|
|
|
|
DRWShadingGroup *lamp_sunrays;
|
|
|
|
DRWShadingGroup *lamp_distance;
|
|
|
|
DRWShadingGroup *lamp_buflimit;
|
|
|
|
DRWShadingGroup *lamp_buflimit_points;
|
Cycles/Eevee: Implement disk and ellipse shapes for area lamps
The implementation is pretty straightforward.
In Cycles, sampling the shapes is currently done w.r.t. area instead of solid angle.
There is a paper on solid angle sampling for disks [1], but the described algorithm is based on
simply sampling the enclosing square and rejecting samples outside of the disk, which is not exactly
great for Cycles' RNG (we'd need to setup a LCG for the repeated sampling) and for GPU divergence.
Even worse, the algorithm is only defined for disks. For ellipses, the basic idea still works, but a
way to analytically calculate the solid angle is required. This is technically possible [2], but the
calculation is extremely complex and still requires a lookup table for the Heuman Lambda function.
Therefore, I've decided to not implement that for now, we could still look into it later on.
In Eevee, the code uses the existing ltc_evaluate_disk to implement the lighting calculations.
[1]: "Solid Angle Sampling of Disk and Cylinder Lights"
[2]: "Analytical solution for the solid angle subtended at any point by an ellipse via a point source radiation vector potential"
Reviewers: sergey, brecht, fclem
Differential Revision: https://developer.blender.org/D3171
2018-05-24 03:50:16 +02:00
|
|
|
DRWShadingGroup *lamp_area_square;
|
|
|
|
DRWShadingGroup *lamp_area_disk;
|
2017-03-18 22:14:53 +01:00
|
|
|
DRWShadingGroup *lamp_hemi;
|
|
|
|
DRWShadingGroup *lamp_spot_cone;
|
|
|
|
DRWShadingGroup *lamp_spot_blend;
|
|
|
|
DRWShadingGroup *lamp_spot_pyramid;
|
|
|
|
DRWShadingGroup *lamp_spot_blend_rect;
|
|
|
|
|
|
|
|
/* Helpers */
|
|
|
|
DRWShadingGroup *relationship_lines;
|
|
|
|
|
|
|
|
/* Objects Centers */
|
|
|
|
DRWShadingGroup *center_active;
|
|
|
|
DRWShadingGroup *center_selected;
|
|
|
|
DRWShadingGroup *center_deselected;
|
2017-04-11 14:05:39 +10:00
|
|
|
DRWShadingGroup *center_selected_lib;
|
|
|
|
DRWShadingGroup *center_deselected_lib;
|
2017-03-18 22:14:53 +01:00
|
|
|
|
|
|
|
/* Camera */
|
|
|
|
DRWShadingGroup *camera;
|
2018-01-22 00:14:28 +01:00
|
|
|
DRWShadingGroup *camera_frame;
|
2017-03-18 22:14:53 +01:00
|
|
|
DRWShadingGroup *camera_tria;
|
|
|
|
DRWShadingGroup *camera_focus;
|
|
|
|
DRWShadingGroup *camera_clip;
|
|
|
|
DRWShadingGroup *camera_clip_points;
|
|
|
|
DRWShadingGroup *camera_mist;
|
|
|
|
DRWShadingGroup *camera_mist_points;
|
|
|
|
|
|
|
|
/* Outlines */
|
|
|
|
DRWShadingGroup *outlines_active;
|
|
|
|
DRWShadingGroup *outlines_select;
|
|
|
|
DRWShadingGroup *outlines_transform;
|
|
|
|
|
2017-09-30 19:34:23 +02:00
|
|
|
/* Lightprobes */
|
2018-04-17 13:01:01 +02:00
|
|
|
DRWShadingGroup *lightprobes_cube_select;
|
|
|
|
DRWShadingGroup *lightprobes_cube_active;
|
|
|
|
DRWShadingGroup *lightprobes_cube_transform;
|
|
|
|
|
|
|
|
DRWShadingGroup *lightprobes_planar_select;
|
|
|
|
DRWShadingGroup *lightprobes_planar_active;
|
|
|
|
DRWShadingGroup *lightprobes_planar_transform;
|
2017-09-30 19:34:23 +02:00
|
|
|
|
2017-04-13 22:09:59 +10:00
|
|
|
/* Wire */
|
|
|
|
DRWShadingGroup *wire;
|
|
|
|
DRWShadingGroup *wire_active;
|
|
|
|
DRWShadingGroup *wire_select;
|
|
|
|
DRWShadingGroup *wire_transform;
|
2018-02-24 04:45:13 +01:00
|
|
|
|
|
|
|
/* Points */
|
|
|
|
DRWShadingGroup *points;
|
|
|
|
DRWShadingGroup *points_active;
|
|
|
|
DRWShadingGroup *points_select;
|
|
|
|
DRWShadingGroup *points_transform;
|
2018-04-16 19:38:40 +02:00
|
|
|
|
|
|
|
/* Outlines id offset */
|
|
|
|
int id_ofs_active;
|
|
|
|
int id_ofs_select;
|
|
|
|
int id_ofs_transform;
|
2018-04-17 13:01:01 +02:00
|
|
|
int id_ofs_prb_active;
|
|
|
|
int id_ofs_prb_select;
|
|
|
|
int id_ofs_prb_transform;
|
2017-04-29 16:52:12 +10:00
|
|
|
} OBJECT_PrivateData; /* Transient data */
|
2017-03-18 22:14:53 +01:00
|
|
|
|
|
|
|
static struct {
|
2018-02-14 18:59:15 +01:00
|
|
|
/* Instance Data format */
|
2018-02-20 01:55:19 +01:00
|
|
|
struct Gwn_VertFormat *particle_format;
|
2018-02-14 18:59:15 +01:00
|
|
|
struct Gwn_VertFormat *empty_image_format;
|
|
|
|
struct Gwn_VertFormat *empty_image_wire_format;
|
|
|
|
|
2017-05-20 22:57:47 +10:00
|
|
|
/* fullscreen shaders */
|
2018-04-16 19:38:40 +02:00
|
|
|
GPUShader *outline_prepass_sh;
|
2017-04-21 04:39:51 +10:00
|
|
|
GPUShader *outline_resolve_sh;
|
2017-09-22 17:30:39 +02:00
|
|
|
GPUShader *outline_resolve_aa_sh;
|
2017-04-21 04:39:51 +10:00
|
|
|
GPUShader *outline_detect_sh;
|
|
|
|
GPUShader *outline_fade_sh;
|
2017-05-20 22:57:47 +10:00
|
|
|
|
|
|
|
/* regular shaders */
|
|
|
|
GPUShader *object_empty_image_sh;
|
|
|
|
GPUShader *object_empty_image_wire_sh;
|
2017-04-21 04:39:51 +10:00
|
|
|
GPUShader *grid_sh;
|
2017-05-19 18:32:40 +02:00
|
|
|
GPUShader *part_dot_sh;
|
|
|
|
GPUShader *part_prim_sh;
|
2017-05-23 18:13:41 +02:00
|
|
|
GPUShader *part_axis_sh;
|
2017-09-30 19:34:23 +02:00
|
|
|
GPUShader *lightprobe_grid_sh;
|
2017-03-22 21:28:59 +01:00
|
|
|
float camera_pos[3];
|
2017-05-27 12:48:25 +02:00
|
|
|
float screenvecs[3][4];
|
2017-03-27 14:01:25 +02:00
|
|
|
float grid_settings[5];
|
2017-03-25 02:46:23 +01:00
|
|
|
int grid_flag;
|
2017-05-27 21:35:03 +02:00
|
|
|
float grid_normal[3];
|
|
|
|
float grid_axes[3];
|
2017-03-25 02:46:23 +01:00
|
|
|
int zpos_flag;
|
|
|
|
int zneg_flag;
|
2017-05-27 21:35:03 +02:00
|
|
|
float zplane_normal[3];
|
|
|
|
float zplane_axes[3];
|
2017-09-22 17:30:39 +02:00
|
|
|
float inv_viewport_size[2];
|
2017-05-27 21:28:29 +02:00
|
|
|
bool draw_grid;
|
2017-05-16 03:03:58 +02:00
|
|
|
/* Temp buffer textures */
|
|
|
|
struct GPUTexture *outlines_depth_tx;
|
2018-04-16 19:38:40 +02:00
|
|
|
struct GPUTexture *outlines_id_tx;
|
2017-05-16 03:03:58 +02:00
|
|
|
struct GPUTexture *outlines_color_tx;
|
|
|
|
struct GPUTexture *outlines_blur_tx;
|
2017-03-18 22:14:53 +01:00
|
|
|
} e_data = {NULL}; /* Engine data */
|
|
|
|
|
2017-03-25 02:46:23 +01:00
|
|
|
|
|
|
|
enum {
|
|
|
|
SHOW_AXIS_X = (1 << 0),
|
|
|
|
SHOW_AXIS_Y = (1 << 1),
|
|
|
|
SHOW_AXIS_Z = (1 << 2),
|
|
|
|
SHOW_GRID = (1 << 3),
|
|
|
|
PLANE_XY = (1 << 4),
|
|
|
|
PLANE_XZ = (1 << 5),
|
|
|
|
PLANE_YZ = (1 << 6),
|
|
|
|
CLIP_ZPOS = (1 << 7),
|
|
|
|
CLIP_ZNEG = (1 << 8),
|
|
|
|
};
|
|
|
|
|
2017-03-18 22:14:53 +01:00
|
|
|
/* *********** FUNCTIONS *********** */
|
2017-03-18 01:55:41 +01:00
|
|
|
|
2017-03-26 19:10:53 +02:00
|
|
|
static void OBJECT_engine_init(void *vedata)
|
2017-03-18 01:55:41 +01:00
|
|
|
{
|
2017-03-26 19:10:53 +02:00
|
|
|
OBJECT_FramebufferList *fbl = ((OBJECT_Data *)vedata)->fbl;
|
2017-03-20 14:59:27 +01:00
|
|
|
|
2017-04-12 12:10:01 +10:00
|
|
|
const float *viewport_size = DRW_viewport_size_get();
|
2018-03-25 17:46:48 +02:00
|
|
|
const int size[2] = {(int)viewport_size[0], (int)viewport_size[1]};
|
2017-03-20 14:59:27 +01:00
|
|
|
|
2017-04-27 02:04:56 +10:00
|
|
|
if (DRW_state_is_fbo()) {
|
2018-04-30 16:02:24 +02:00
|
|
|
e_data.outlines_depth_tx = DRW_texture_pool_query_2D(size[0], size[1], GPU_DEPTH_COMPONENT24,
|
2018-03-25 17:46:48 +02:00
|
|
|
&draw_engine_object_type);
|
2018-04-30 16:02:24 +02:00
|
|
|
/* XXX TODO GPU_R16UI can overflow, it would cause no harm
|
2018-04-16 19:38:40 +02:00
|
|
|
* (only bad colored or missing outlines) but we should
|
|
|
|
* use 32bits only if the scene have that many objects */
|
2018-04-30 16:02:24 +02:00
|
|
|
e_data.outlines_id_tx = DRW_texture_pool_query_2D(size[0], size[1], GPU_R16UI,
|
2018-04-16 19:38:40 +02:00
|
|
|
&draw_engine_object_type);
|
2017-05-16 03:03:58 +02:00
|
|
|
|
2018-03-25 17:46:48 +02:00
|
|
|
GPU_framebuffer_ensure_config(&fbl->outlines_fb, {
|
|
|
|
GPU_ATTACHMENT_TEXTURE(e_data.outlines_depth_tx),
|
2018-04-16 19:38:40 +02:00
|
|
|
GPU_ATTACHMENT_TEXTURE(e_data.outlines_id_tx)
|
2018-03-25 17:46:48 +02:00
|
|
|
});
|
2017-04-26 04:39:25 +10:00
|
|
|
|
2018-04-30 16:02:24 +02:00
|
|
|
e_data.outlines_color_tx = DRW_texture_pool_query_2D(size[0], size[1], GPU_RGBA8,
|
2018-04-16 19:38:40 +02:00
|
|
|
&draw_engine_object_type);
|
|
|
|
|
2018-03-25 17:46:48 +02:00
|
|
|
GPU_framebuffer_ensure_config(&fbl->expand_fb, {
|
|
|
|
GPU_ATTACHMENT_NONE,
|
|
|
|
GPU_ATTACHMENT_TEXTURE(e_data.outlines_color_tx)
|
|
|
|
});
|
|
|
|
|
2018-04-30 16:02:24 +02:00
|
|
|
e_data.outlines_blur_tx = DRW_texture_pool_query_2D(size[0], size[1], GPU_RGBA8,
|
2018-03-25 17:46:48 +02:00
|
|
|
&draw_engine_object_type);
|
|
|
|
|
|
|
|
GPU_framebuffer_ensure_config(&fbl->blur_fb, {
|
|
|
|
GPU_ATTACHMENT_NONE,
|
|
|
|
GPU_ATTACHMENT_TEXTURE(e_data.outlines_blur_tx)
|
|
|
|
});
|
2017-04-26 04:39:25 +10:00
|
|
|
}
|
2017-03-20 14:59:27 +01:00
|
|
|
|
2018-04-16 19:38:40 +02:00
|
|
|
/* Shaders */
|
2017-03-20 14:59:27 +01:00
|
|
|
if (!e_data.outline_resolve_sh) {
|
2018-04-16 19:38:40 +02:00
|
|
|
/* Outline */
|
|
|
|
e_data.outline_prepass_sh = DRW_shader_create_3D(datatoc_object_outline_prepass_frag_glsl, NULL);
|
|
|
|
|
2017-03-20 14:59:27 +01:00
|
|
|
e_data.outline_resolve_sh = DRW_shader_create_fullscreen(datatoc_object_outline_resolve_frag_glsl, NULL);
|
|
|
|
|
2017-09-22 17:30:39 +02:00
|
|
|
e_data.outline_resolve_aa_sh = DRW_shader_create_with_lib(
|
2018-03-22 16:10:54 +01:00
|
|
|
datatoc_common_fullscreen_vert_glsl, NULL,
|
2017-09-22 17:30:39 +02:00
|
|
|
datatoc_object_outline_resolve_frag_glsl,
|
2018-01-17 20:35:06 +11:00
|
|
|
datatoc_common_fxaa_lib_glsl,
|
2017-09-22 17:30:39 +02:00
|
|
|
"#define FXAA_ALPHA\n"
|
2018-01-17 20:35:06 +11:00
|
|
|
"#define USE_FXAA\n");
|
2017-09-22 17:30:39 +02:00
|
|
|
|
2018-04-16 19:38:40 +02:00
|
|
|
e_data.outline_detect_sh = DRW_shader_create_with_lib(
|
|
|
|
datatoc_common_fullscreen_vert_glsl, NULL,
|
|
|
|
datatoc_object_outline_detect_frag_glsl,
|
|
|
|
datatoc_common_globals_lib_glsl,
|
2018-04-16 22:53:44 +02:00
|
|
|
"#extension GL_ARB_texture_gather : enable\n");
|
2017-03-20 14:59:27 +01:00
|
|
|
|
|
|
|
e_data.outline_fade_sh = DRW_shader_create_fullscreen(datatoc_object_outline_expand_frag_glsl, NULL);
|
2017-03-22 21:28:59 +01:00
|
|
|
|
2018-04-16 19:38:40 +02:00
|
|
|
/* Empty images */
|
2017-05-20 22:57:47 +10:00
|
|
|
e_data.object_empty_image_sh = DRW_shader_create_with_lib(
|
|
|
|
datatoc_object_empty_image_vert_glsl, NULL,
|
2018-01-17 20:35:06 +11:00
|
|
|
datatoc_object_empty_image_frag_glsl,
|
|
|
|
datatoc_common_globals_lib_glsl, NULL);
|
2017-05-20 22:57:47 +10:00
|
|
|
|
|
|
|
e_data.object_empty_image_wire_sh = DRW_shader_create_with_lib(
|
|
|
|
datatoc_object_empty_image_vert_glsl, NULL,
|
|
|
|
datatoc_object_empty_image_frag_glsl,
|
2018-01-17 20:35:06 +11:00
|
|
|
datatoc_common_globals_lib_glsl,
|
|
|
|
"#define USE_WIRE\n");
|
2017-05-20 22:57:47 +10:00
|
|
|
|
2018-04-16 19:38:40 +02:00
|
|
|
/* Grid */
|
2017-04-21 04:39:51 +10:00
|
|
|
e_data.grid_sh = DRW_shader_create_with_lib(
|
|
|
|
datatoc_object_grid_vert_glsl, NULL,
|
2018-01-17 20:35:06 +11:00
|
|
|
datatoc_object_grid_frag_glsl,
|
|
|
|
datatoc_common_globals_lib_glsl, NULL);
|
2017-03-22 21:28:59 +01:00
|
|
|
|
2018-04-16 19:38:40 +02:00
|
|
|
/* Particles */
|
2017-07-14 16:56:02 +10:00
|
|
|
e_data.part_prim_sh = DRW_shader_create(
|
2018-01-29 15:51:23 -02:00
|
|
|
datatoc_object_particle_prim_vert_glsl, NULL, datatoc_gpu_shader_flat_color_frag_glsl, NULL);
|
2017-05-19 18:32:40 +02:00
|
|
|
|
2017-07-14 16:56:02 +10:00
|
|
|
e_data.part_axis_sh = DRW_shader_create(
|
2018-01-29 15:51:23 -02:00
|
|
|
datatoc_object_particle_prim_vert_glsl, NULL, datatoc_gpu_shader_flat_color_frag_glsl,
|
2017-07-14 16:56:02 +10:00
|
|
|
"#define USE_AXIS\n");
|
2017-05-23 18:13:41 +02:00
|
|
|
|
2017-07-14 16:56:02 +10:00
|
|
|
e_data.part_dot_sh = DRW_shader_create(
|
|
|
|
datatoc_object_particle_dot_vert_glsl, NULL, datatoc_object_particle_dot_frag_glsl, NULL);
|
2017-05-19 18:32:40 +02:00
|
|
|
|
2018-04-16 19:38:40 +02:00
|
|
|
/* Lightprobes */
|
2017-09-30 19:34:23 +02:00
|
|
|
e_data.lightprobe_grid_sh = DRW_shader_create(
|
2018-04-17 13:01:01 +02:00
|
|
|
datatoc_object_lightprobe_grid_vert_glsl, NULL, datatoc_gpu_shader_flat_id_frag_glsl, NULL);
|
2017-09-30 19:34:23 +02:00
|
|
|
}
|
|
|
|
|
2017-03-22 21:28:59 +01:00
|
|
|
{
|
2017-03-25 02:46:23 +01:00
|
|
|
/* Grid precompute */
|
2017-05-27 12:48:25 +02:00
|
|
|
float invviewmat[4][4], invwinmat[4][4];
|
|
|
|
float viewmat[4][4], winmat[4][4];
|
2017-04-26 00:35:08 +10:00
|
|
|
const DRWContextState *draw_ctx = DRW_context_state_get();
|
|
|
|
View3D *v3d = draw_ctx->v3d;
|
|
|
|
Scene *scene = draw_ctx->scene;
|
|
|
|
RegionView3D *rv3d = draw_ctx->rv3d;
|
2017-03-25 02:46:23 +01:00
|
|
|
float grid_scale = ED_view3d_grid_scale(scene, v3d, NULL);
|
2017-10-12 04:03:42 +02:00
|
|
|
float grid_res;
|
2017-03-25 02:46:23 +01:00
|
|
|
|
2017-04-21 18:43:54 +10:00
|
|
|
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_z = (v3d->gridflag & V3D_SHOW_Z) != 0;
|
|
|
|
const bool show_floor = (v3d->gridflag & V3D_SHOW_FLOOR) != 0;
|
2017-05-27 21:28:29 +02:00
|
|
|
e_data.draw_grid = show_axis_x || show_axis_y || show_axis_z || show_floor;
|
2017-03-25 02:46:23 +01:00
|
|
|
|
2017-03-25 19:02:04 +01:00
|
|
|
DRW_viewport_matrix_get(winmat, DRW_MAT_WIN);
|
|
|
|
DRW_viewport_matrix_get(viewmat, DRW_MAT_VIEW);
|
2017-05-27 12:48:25 +02:00
|
|
|
DRW_viewport_matrix_get(invwinmat, DRW_MAT_WININV);
|
|
|
|
DRW_viewport_matrix_get(invviewmat, DRW_MAT_VIEWINV);
|
2017-03-25 19:02:04 +01:00
|
|
|
|
2017-03-22 21:28:59 +01:00
|
|
|
/* Setup camera pos */
|
2017-05-27 12:48:25 +02:00
|
|
|
copy_v3_v3(e_data.camera_pos, invviewmat[3]);
|
2017-03-22 21:28:59 +01:00
|
|
|
|
2017-03-25 02:46:23 +01:00
|
|
|
/* if perps */
|
|
|
|
if (winmat[3][3] == 0.0f) {
|
|
|
|
float fov;
|
|
|
|
float viewvecs[2][4] = {
|
|
|
|
{1.0f, -1.0f, -1.0f, 1.0f},
|
|
|
|
{-1.0f, 1.0f, -1.0f, 1.0f}
|
|
|
|
};
|
|
|
|
|
|
|
|
/* convert the view vectors to view space */
|
|
|
|
for (int i = 0; i < 2; i++) {
|
|
|
|
mul_m4_v4(invwinmat, viewvecs[i]);
|
2017-05-27 12:48:25 +02:00
|
|
|
mul_v3_fl(viewvecs[i], 1.0f / viewvecs[i][2]); /* perspective divide */
|
2017-03-25 02:46:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
fov = angle_v3v3(viewvecs[0], viewvecs[1]) / 2.0f;
|
|
|
|
grid_res = fabsf(tanf(fov)) / grid_scale;
|
|
|
|
|
|
|
|
e_data.grid_flag = (1 << 4); /* XY plane */
|
|
|
|
if (show_axis_x)
|
|
|
|
e_data.grid_flag |= SHOW_AXIS_X;
|
|
|
|
if (show_axis_y)
|
|
|
|
e_data.grid_flag |= SHOW_AXIS_Y;
|
|
|
|
if (show_floor)
|
|
|
|
e_data.grid_flag |= SHOW_GRID;
|
2017-05-27 12:48:25 +02:00
|
|
|
|
2017-03-25 02:46:23 +01:00
|
|
|
}
|
|
|
|
else {
|
2017-03-25 19:02:04 +01:00
|
|
|
float viewdist = 1.0f / max_ff(fabsf(winmat[0][0]), fabsf(winmat[1][1]));
|
2017-03-25 02:46:23 +01:00
|
|
|
grid_res = viewdist / grid_scale;
|
|
|
|
|
|
|
|
if (ELEM(rv3d->view, RV3D_VIEW_RIGHT, RV3D_VIEW_LEFT)) {
|
|
|
|
e_data.grid_flag = PLANE_YZ;
|
|
|
|
e_data.grid_flag |= SHOW_AXIS_Y;
|
|
|
|
e_data.grid_flag |= SHOW_AXIS_Z;
|
|
|
|
e_data.grid_flag |= SHOW_GRID;
|
|
|
|
}
|
|
|
|
else if (ELEM(rv3d->view, RV3D_VIEW_TOP, RV3D_VIEW_BOTTOM)) {
|
|
|
|
e_data.grid_flag = PLANE_XY;
|
|
|
|
e_data.grid_flag |= SHOW_AXIS_X;
|
|
|
|
e_data.grid_flag |= SHOW_AXIS_Y;
|
|
|
|
e_data.grid_flag |= SHOW_GRID;
|
|
|
|
}
|
|
|
|
else if (ELEM(rv3d->view, RV3D_VIEW_FRONT, RV3D_VIEW_BACK)) {
|
|
|
|
e_data.grid_flag = PLANE_XZ;
|
|
|
|
e_data.grid_flag |= SHOW_AXIS_X;
|
|
|
|
e_data.grid_flag |= SHOW_AXIS_Z;
|
|
|
|
e_data.grid_flag |= SHOW_GRID;
|
|
|
|
}
|
|
|
|
else { /* RV3D_VIEW_USER */
|
|
|
|
e_data.grid_flag = PLANE_XY;
|
|
|
|
if (show_axis_x)
|
|
|
|
e_data.grid_flag |= SHOW_AXIS_X;
|
|
|
|
if (show_axis_y)
|
|
|
|
e_data.grid_flag |= SHOW_AXIS_Y;
|
|
|
|
if (show_floor)
|
|
|
|
e_data.grid_flag |= SHOW_GRID;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-27 21:35:03 +02:00
|
|
|
e_data.grid_normal[0] = (float)((e_data.grid_flag & PLANE_YZ) != 0);
|
|
|
|
e_data.grid_normal[1] = (float)((e_data.grid_flag & PLANE_XZ) != 0);
|
|
|
|
e_data.grid_normal[2] = (float)((e_data.grid_flag & PLANE_XY) != 0);
|
|
|
|
|
|
|
|
e_data.grid_axes[0] = (float)((e_data.grid_flag & (PLANE_XZ | PLANE_XY)) != 0);
|
|
|
|
e_data.grid_axes[1] = (float)((e_data.grid_flag & (PLANE_YZ | PLANE_XY)) != 0);
|
|
|
|
e_data.grid_axes[2] = (float)((e_data.grid_flag & (PLANE_YZ | PLANE_XZ)) != 0);
|
|
|
|
|
2017-05-27 12:48:25 +02:00
|
|
|
/* Vectors to recover pixel world position. Fix grid precision issue. */
|
2017-05-27 21:35:03 +02:00
|
|
|
/* Using pixel at z = 0.0f in ndc space : gives average precision between
|
|
|
|
* near and far plane. Note that it might not be the best choice. */
|
2017-05-27 12:48:25 +02:00
|
|
|
copy_v4_fl4(e_data.screenvecs[0], 1.0f, -1.0f, 0.0f, 1.0f);
|
|
|
|
copy_v4_fl4(e_data.screenvecs[1], -1.0f, 1.0f, 0.0f, 1.0f);
|
|
|
|
copy_v4_fl4(e_data.screenvecs[2], -1.0f, -1.0f, 0.0f, 1.0f);
|
|
|
|
|
|
|
|
for (int i = 0; i < 3; i++) {
|
|
|
|
/* Doing 2 steps to recover world position of the corners of the frustum.
|
|
|
|
* Using the inverse perspective matrix is giving very low precision output. */
|
|
|
|
mul_m4_v4(invwinmat, e_data.screenvecs[i]);
|
|
|
|
e_data.screenvecs[i][0] /= e_data.screenvecs[i][3]; /* perspective divide */
|
|
|
|
e_data.screenvecs[i][1] /= e_data.screenvecs[i][3]; /* perspective divide */
|
|
|
|
e_data.screenvecs[i][2] /= e_data.screenvecs[i][3]; /* perspective divide */
|
|
|
|
e_data.screenvecs[i][3] = 1.0f;
|
2017-05-27 21:35:03 +02:00
|
|
|
/* main instability come from this one */
|
|
|
|
/* TODO : to make things even more stable, don't use
|
|
|
|
* invviewmat and derive vectors from camera properties */
|
2017-05-27 12:48:25 +02:00
|
|
|
mul_m4_v4(invviewmat, e_data.screenvecs[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
sub_v3_v3(e_data.screenvecs[0], e_data.screenvecs[2]);
|
|
|
|
sub_v3_v3(e_data.screenvecs[1], e_data.screenvecs[2]);
|
|
|
|
|
2017-03-25 02:46:23 +01:00
|
|
|
/* Z axis if needed */
|
2017-04-03 21:37:40 +02:00
|
|
|
if (((rv3d->view == RV3D_VIEW_USER) || (rv3d->persp != RV3D_ORTHO)) && show_axis_z) {
|
2017-03-25 02:46:23 +01:00
|
|
|
e_data.zpos_flag = SHOW_AXIS_Z;
|
|
|
|
|
|
|
|
float zvec[4] = {0.0f, 0.0f, -1.0f, 0.0f};
|
2017-05-27 12:48:25 +02:00
|
|
|
mul_m4_v4(invviewmat, zvec);
|
2017-03-25 02:46:23 +01:00
|
|
|
|
|
|
|
/* z axis : chose the most facing plane */
|
2017-03-27 14:01:25 +02:00
|
|
|
if (fabsf(zvec[0]) < fabsf(zvec[1])) {
|
2017-04-03 21:37:40 +02:00
|
|
|
e_data.zpos_flag |= PLANE_XZ;
|
2017-03-25 02:46:23 +01:00
|
|
|
}
|
|
|
|
else {
|
2017-04-03 21:37:40 +02:00
|
|
|
e_data.zpos_flag |= PLANE_YZ;
|
2017-03-25 02:46:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
e_data.zneg_flag = e_data.zpos_flag;
|
|
|
|
|
|
|
|
/* Persp : If camera is below floor plane, we switch clipping
|
|
|
|
* Ortho : If eye vector is looking up, we switch clipping */
|
|
|
|
if (((winmat[3][3] == 0.0f) && (e_data.camera_pos[2] > 0.0f)) ||
|
2017-10-07 15:57:14 +11:00
|
|
|
((winmat[3][3] != 0.0f) && (zvec[2] < 0.0f)))
|
|
|
|
{
|
2017-03-25 02:46:23 +01:00
|
|
|
e_data.zpos_flag |= CLIP_ZPOS;
|
|
|
|
e_data.zneg_flag |= CLIP_ZNEG;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
e_data.zpos_flag |= CLIP_ZNEG;
|
|
|
|
e_data.zneg_flag |= CLIP_ZPOS;
|
|
|
|
}
|
2017-05-27 21:35:03 +02:00
|
|
|
|
|
|
|
e_data.zplane_normal[0] = (float)((e_data.zpos_flag & PLANE_YZ) != 0);
|
|
|
|
e_data.zplane_normal[1] = (float)((e_data.zpos_flag & PLANE_XZ) != 0);
|
|
|
|
e_data.zplane_normal[2] = (float)((e_data.zpos_flag & PLANE_XY) != 0);
|
|
|
|
|
|
|
|
e_data.zplane_axes[0] = (float)((e_data.zpos_flag & (PLANE_XZ | PLANE_XY)) != 0);
|
|
|
|
e_data.zplane_axes[1] = (float)((e_data.zpos_flag & (PLANE_YZ | PLANE_XY)) != 0);
|
|
|
|
e_data.zplane_axes[2] = (float)((e_data.zpos_flag & (PLANE_YZ | PLANE_XZ)) != 0);
|
|
|
|
|
2017-03-25 19:02:04 +01:00
|
|
|
}
|
|
|
|
else {
|
2017-03-27 14:01:25 +02:00
|
|
|
e_data.zneg_flag = e_data.zpos_flag = CLIP_ZNEG | CLIP_ZPOS;
|
2017-03-25 19:02:04 +01:00
|
|
|
}
|
|
|
|
|
2018-01-18 15:58:02 +01:00
|
|
|
float dist;
|
|
|
|
if (rv3d->persp == RV3D_CAMOB && v3d->camera) {
|
|
|
|
Object *camera_object = DEG_get_evaluated_object(draw_ctx->depsgraph, v3d->camera);
|
|
|
|
dist = ((Camera *)camera_object)->clipend;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
dist = v3d->far;
|
|
|
|
}
|
2017-05-09 21:50:18 +02:00
|
|
|
|
|
|
|
e_data.grid_settings[0] = dist / 2.0f; /* gridDistance */
|
2017-03-25 02:46:23 +01:00
|
|
|
e_data.grid_settings[1] = grid_res; /* gridResolution */
|
|
|
|
e_data.grid_settings[2] = grid_scale; /* gridScale */
|
|
|
|
e_data.grid_settings[3] = v3d->gridsubdiv; /* gridSubdiv */
|
2017-08-01 13:35:26 +10:00
|
|
|
e_data.grid_settings[4] = (v3d->gridsubdiv > 1) ? 1.0f / logf(v3d->gridsubdiv) : 0.0f; /* 1/log(gridSubdiv) */
|
2017-03-22 21:28:59 +01:00
|
|
|
}
|
2017-09-22 17:30:39 +02:00
|
|
|
|
|
|
|
copy_v2_v2(e_data.inv_viewport_size, DRW_viewport_size_get());
|
|
|
|
invert_v2(e_data.inv_viewport_size);
|
2017-03-18 01:55:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void OBJECT_engine_free(void)
|
|
|
|
{
|
2018-02-20 01:55:19 +01:00
|
|
|
MEM_SAFE_FREE(e_data.particle_format);
|
2018-02-14 18:59:15 +01:00
|
|
|
MEM_SAFE_FREE(e_data.empty_image_format);
|
|
|
|
MEM_SAFE_FREE(e_data.empty_image_wire_format);
|
2018-04-16 19:38:40 +02:00
|
|
|
DRW_SHADER_FREE_SAFE(e_data.outline_prepass_sh);
|
2017-04-13 13:30:53 +10:00
|
|
|
DRW_SHADER_FREE_SAFE(e_data.outline_resolve_sh);
|
2017-09-22 17:30:39 +02:00
|
|
|
DRW_SHADER_FREE_SAFE(e_data.outline_resolve_aa_sh);
|
2017-04-13 13:30:53 +10:00
|
|
|
DRW_SHADER_FREE_SAFE(e_data.outline_detect_sh);
|
|
|
|
DRW_SHADER_FREE_SAFE(e_data.outline_fade_sh);
|
2017-05-20 22:57:47 +10:00
|
|
|
DRW_SHADER_FREE_SAFE(e_data.object_empty_image_sh);
|
|
|
|
DRW_SHADER_FREE_SAFE(e_data.object_empty_image_wire_sh);
|
2017-04-13 13:30:53 +10:00
|
|
|
DRW_SHADER_FREE_SAFE(e_data.grid_sh);
|
2017-05-19 18:32:40 +02:00
|
|
|
DRW_SHADER_FREE_SAFE(e_data.part_prim_sh);
|
2017-05-23 18:13:41 +02:00
|
|
|
DRW_SHADER_FREE_SAFE(e_data.part_axis_sh);
|
2017-05-23 14:25:12 +02:00
|
|
|
DRW_SHADER_FREE_SAFE(e_data.part_dot_sh);
|
2017-09-30 19:34:23 +02:00
|
|
|
DRW_SHADER_FREE_SAFE(e_data.lightprobe_grid_sh);
|
2017-03-18 01:55:41 +01:00
|
|
|
}
|
|
|
|
|
2018-04-16 19:38:40 +02:00
|
|
|
static DRWShadingGroup *shgroup_outline(DRWPass *pass, const int *ofs, GPUShader *sh)
|
2017-03-18 01:55:41 +01:00
|
|
|
{
|
|
|
|
DRWShadingGroup *grp = DRW_shgroup_create(sh, pass);
|
2018-04-16 19:38:40 +02:00
|
|
|
DRW_shgroup_uniform_int(grp, "baseId", ofs, 1);
|
2017-03-18 01:55:41 +01:00
|
|
|
|
|
|
|
return grp;
|
|
|
|
}
|
|
|
|
|
2017-04-13 22:09:59 +10:00
|
|
|
/* currently same as 'shgroup_outline', new function to avoid confustion */
|
2017-04-21 04:39:51 +10:00
|
|
|
static DRWShadingGroup *shgroup_wire(DRWPass *pass, const float col[4], GPUShader *sh)
|
2017-04-13 22:09:59 +10:00
|
|
|
{
|
|
|
|
DRWShadingGroup *grp = DRW_shgroup_create(sh, pass);
|
|
|
|
DRW_shgroup_uniform_vec4(grp, "color", col, 1);
|
|
|
|
|
|
|
|
return grp;
|
|
|
|
}
|
|
|
|
|
2018-02-24 04:45:13 +01:00
|
|
|
/* currently same as 'shgroup_outline', new function to avoid confustion */
|
|
|
|
static DRWShadingGroup *shgroup_points(DRWPass *pass, const float col[4], GPUShader *sh)
|
|
|
|
{
|
|
|
|
DRWShadingGroup *grp = DRW_shgroup_create(sh, pass);
|
|
|
|
DRW_shgroup_uniform_vec4(grp, "color", col, 1);
|
|
|
|
|
|
|
|
return grp;
|
|
|
|
}
|
|
|
|
|
2018-04-17 13:01:01 +02:00
|
|
|
static int *shgroup_theme_id_to_probe_outline_counter(
|
|
|
|
OBJECT_StorageList *stl, int theme_id)
|
|
|
|
{
|
|
|
|
switch (theme_id) {
|
|
|
|
case TH_ACTIVE:
|
|
|
|
return &stl->g_data->id_ofs_prb_active;
|
|
|
|
case TH_SELECT:
|
|
|
|
return &stl->g_data->id_ofs_prb_select;
|
|
|
|
case TH_TRANSFORM:
|
|
|
|
default:
|
|
|
|
return &stl->g_data->id_ofs_prb_transform;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int *shgroup_theme_id_to_outline_counter(
|
|
|
|
OBJECT_StorageList *stl, int theme_id)
|
|
|
|
{
|
|
|
|
switch (theme_id) {
|
|
|
|
case TH_ACTIVE:
|
|
|
|
return &stl->g_data->id_ofs_active;
|
|
|
|
case TH_SELECT:
|
|
|
|
return &stl->g_data->id_ofs_select;
|
|
|
|
case TH_TRANSFORM:
|
|
|
|
default:
|
|
|
|
return &stl->g_data->id_ofs_transform;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static DRWShadingGroup *shgroup_theme_id_to_probe_planar_outline_shgrp(
|
|
|
|
OBJECT_StorageList *stl, int theme_id)
|
|
|
|
{
|
|
|
|
/* does not increment counter */
|
|
|
|
switch (theme_id) {
|
|
|
|
case TH_ACTIVE:
|
|
|
|
return stl->g_data->lightprobes_planar_active;
|
|
|
|
case TH_SELECT:
|
|
|
|
return stl->g_data->lightprobes_planar_select;
|
|
|
|
case TH_TRANSFORM:
|
|
|
|
default:
|
|
|
|
return stl->g_data->lightprobes_planar_transform;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static DRWShadingGroup *shgroup_theme_id_to_probe_cube_outline_shgrp(
|
|
|
|
OBJECT_StorageList *stl, int theme_id)
|
|
|
|
{
|
|
|
|
/* does not increment counter */
|
|
|
|
switch (theme_id) {
|
|
|
|
case TH_ACTIVE:
|
|
|
|
return stl->g_data->lightprobes_cube_active;
|
|
|
|
case TH_SELECT:
|
|
|
|
return stl->g_data->lightprobes_cube_select;
|
|
|
|
case TH_TRANSFORM:
|
|
|
|
default:
|
|
|
|
return stl->g_data->lightprobes_cube_transform;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-21 04:29:33 +10:00
|
|
|
static DRWShadingGroup *shgroup_theme_id_to_outline_or(
|
2017-04-20 00:24:28 +10:00
|
|
|
OBJECT_StorageList *stl, int theme_id, DRWShadingGroup *fallback)
|
|
|
|
{
|
2018-04-17 13:01:01 +02:00
|
|
|
int *counter = shgroup_theme_id_to_outline_counter(stl, theme_id);
|
|
|
|
*counter += 1;
|
|
|
|
|
2017-04-20 00:24:28 +10:00
|
|
|
switch (theme_id) {
|
|
|
|
case TH_ACTIVE:
|
|
|
|
return stl->g_data->outlines_active;
|
|
|
|
case TH_SELECT:
|
|
|
|
return stl->g_data->outlines_select;
|
|
|
|
case TH_TRANSFORM:
|
|
|
|
return stl->g_data->outlines_transform;
|
|
|
|
default:
|
|
|
|
return fallback;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-21 04:29:33 +10:00
|
|
|
static DRWShadingGroup *shgroup_theme_id_to_wire_or(
|
2017-04-20 00:24:28 +10:00
|
|
|
OBJECT_StorageList *stl, int theme_id, DRWShadingGroup *fallback)
|
|
|
|
{
|
|
|
|
switch (theme_id) {
|
|
|
|
case TH_ACTIVE:
|
|
|
|
return stl->g_data->wire_active;
|
|
|
|
case TH_SELECT:
|
|
|
|
return stl->g_data->wire_select;
|
|
|
|
case TH_TRANSFORM:
|
|
|
|
return stl->g_data->wire_transform;
|
|
|
|
default:
|
|
|
|
return fallback;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-24 04:45:13 +01:00
|
|
|
static DRWShadingGroup *shgroup_theme_id_to_point_or(
|
|
|
|
OBJECT_StorageList *stl, int theme_id, DRWShadingGroup *fallback)
|
|
|
|
{
|
|
|
|
switch (theme_id) {
|
|
|
|
case TH_ACTIVE:
|
|
|
|
return stl->g_data->points_active;
|
|
|
|
case TH_SELECT:
|
|
|
|
return stl->g_data->points_select;
|
|
|
|
case TH_TRANSFORM:
|
|
|
|
return stl->g_data->points_transform;
|
|
|
|
default:
|
|
|
|
return fallback;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-20 22:57:47 +10:00
|
|
|
static void image_calc_aspect(Image *ima, ImageUser *iuser, float r_image_aspect[2])
|
|
|
|
{
|
|
|
|
float ima_x, ima_y;
|
|
|
|
if (ima) {
|
|
|
|
int w, h;
|
|
|
|
BKE_image_get_size(ima, iuser, &w, &h);
|
|
|
|
ima_x = w;
|
|
|
|
ima_y = h;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* if no image, make it a 1x1 empty square, honor scale & offset */
|
|
|
|
ima_x = ima_y = 1.0f;
|
|
|
|
}
|
|
|
|
/* Get the image aspect even if the buffer is invalid */
|
|
|
|
float sca_x = 1.0f, sca_y = 1.0f;
|
|
|
|
if (ima) {
|
|
|
|
if (ima->aspx > ima->aspy) {
|
|
|
|
sca_y = ima->aspy / ima->aspx;
|
|
|
|
}
|
|
|
|
else if (ima->aspx < ima->aspy) {
|
|
|
|
sca_x = ima->aspx / ima->aspy;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const float scale_x_inv = ima_x * sca_x;
|
|
|
|
const float scale_y_inv = ima_y * sca_y;
|
|
|
|
if (scale_x_inv > scale_y_inv) {
|
|
|
|
r_image_aspect[0] = 1.0f;
|
|
|
|
r_image_aspect[1] = scale_y_inv / scale_x_inv;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
r_image_aspect[0] = scale_x_inv / scale_y_inv;
|
|
|
|
r_image_aspect[1] = 1.0f;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-22 16:20:54 +10:00
|
|
|
/* per-image shading groups for image-type empty objects */
|
|
|
|
struct EmptyImageShadingGroupData {
|
|
|
|
DRWShadingGroup *shgrp_image;
|
|
|
|
DRWShadingGroup *shgrp_wire;
|
|
|
|
float image_aspect[2];
|
|
|
|
};
|
|
|
|
|
2017-05-20 22:57:47 +10:00
|
|
|
static void DRW_shgroup_empty_image(
|
2017-05-22 16:20:54 +10:00
|
|
|
OBJECT_StorageList *stl, OBJECT_PassList *psl, Object *ob, const float color[3])
|
2017-05-20 22:57:47 +10:00
|
|
|
{
|
|
|
|
/* TODO: 'StereoViews', see draw_empty_image. */
|
|
|
|
|
|
|
|
if (stl->g_data->image_plane_map == NULL) {
|
|
|
|
stl->g_data->image_plane_map = BLI_ghash_ptr_new(__func__);
|
|
|
|
}
|
|
|
|
|
|
|
|
struct EmptyImageShadingGroupData *empty_image_data;
|
|
|
|
|
|
|
|
GPUTexture *tex = ob->data ?
|
|
|
|
GPU_texture_from_blender(ob->data, ob->iuser, GL_TEXTURE_2D, false, false, false) : NULL;
|
|
|
|
void **val_p;
|
|
|
|
|
|
|
|
/* Create on demand, 'tex' may be NULL. */
|
|
|
|
if (BLI_ghash_ensure_p(stl->g_data->image_plane_map, tex, &val_p)) {
|
|
|
|
empty_image_data = *val_p;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
empty_image_data = MEM_mallocN(sizeof(*empty_image_data), __func__);
|
|
|
|
|
|
|
|
image_calc_aspect(ob->data, ob->iuser, empty_image_data->image_aspect);
|
|
|
|
|
|
|
|
if (tex) {
|
2018-02-14 18:59:15 +01:00
|
|
|
DRW_shgroup_instance_format(e_data.empty_image_format, {
|
2018-04-19 07:47:03 +02:00
|
|
|
{"objectColor", DRW_ATTRIB_FLOAT, 4},
|
|
|
|
{"size", DRW_ATTRIB_FLOAT, 1},
|
|
|
|
{"offset", DRW_ATTRIB_FLOAT, 2},
|
|
|
|
{"InstanceModelMatrix", DRW_ATTRIB_FLOAT, 16},
|
2018-02-14 18:59:15 +01:00
|
|
|
});
|
|
|
|
|
2017-06-19 20:18:04 +10:00
|
|
|
struct Gwn_Batch *geom = DRW_cache_image_plane_get();
|
2017-05-20 22:57:47 +10:00
|
|
|
DRWShadingGroup *grp = DRW_shgroup_instance_create(
|
2018-02-14 18:59:15 +01:00
|
|
|
e_data.object_empty_image_sh, psl->non_meshes, geom, e_data.empty_image_format);
|
2017-05-20 22:57:47 +10:00
|
|
|
DRW_shgroup_uniform_texture(grp, "image", tex);
|
|
|
|
DRW_shgroup_uniform_vec2(grp, "aspect", empty_image_data->image_aspect, 1);
|
|
|
|
|
|
|
|
empty_image_data->shgrp_image = grp;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
empty_image_data->shgrp_image = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2018-02-14 18:59:15 +01:00
|
|
|
DRW_shgroup_instance_format(e_data.empty_image_wire_format, {
|
2018-04-19 07:47:03 +02:00
|
|
|
{"objectColor", DRW_ATTRIB_FLOAT, 4},
|
|
|
|
{"size", DRW_ATTRIB_FLOAT, 1},
|
|
|
|
{"offset", DRW_ATTRIB_FLOAT, 2},
|
|
|
|
{"InstanceModelMatrix", DRW_ATTRIB_FLOAT, 16}
|
2018-02-14 18:59:15 +01:00
|
|
|
});
|
|
|
|
|
2017-06-19 20:18:04 +10:00
|
|
|
struct Gwn_Batch *geom = DRW_cache_image_plane_wire_get();
|
2017-05-20 22:57:47 +10:00
|
|
|
DRWShadingGroup *grp = DRW_shgroup_instance_create(
|
2018-02-14 18:59:15 +01:00
|
|
|
e_data.object_empty_image_wire_sh, psl->non_meshes, geom, e_data.empty_image_wire_format);
|
2017-05-20 22:57:47 +10:00
|
|
|
DRW_shgroup_uniform_vec2(grp, "aspect", empty_image_data->image_aspect, 1);
|
|
|
|
|
|
|
|
empty_image_data->shgrp_wire = grp;
|
|
|
|
}
|
|
|
|
|
|
|
|
*val_p = empty_image_data;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (empty_image_data->shgrp_image != NULL) {
|
|
|
|
DRW_shgroup_call_dynamic_add(
|
|
|
|
empty_image_data->shgrp_image,
|
|
|
|
ob->col,
|
|
|
|
&ob->empty_drawsize,
|
|
|
|
ob->ima_ofs,
|
|
|
|
ob->obmat);
|
|
|
|
}
|
|
|
|
|
|
|
|
DRW_shgroup_call_dynamic_add(
|
|
|
|
empty_image_data->shgrp_wire,
|
|
|
|
color,
|
|
|
|
&ob->empty_drawsize,
|
|
|
|
ob->ima_ofs,
|
|
|
|
ob->obmat);
|
|
|
|
}
|
|
|
|
|
2017-03-26 19:10:53 +02:00
|
|
|
static void OBJECT_cache_init(void *vedata)
|
2017-03-08 20:00:09 +01:00
|
|
|
{
|
2017-03-26 19:10:53 +02:00
|
|
|
OBJECT_PassList *psl = ((OBJECT_Data *)vedata)->psl;
|
2017-03-26 20:13:34 +02:00
|
|
|
OBJECT_StorageList *stl = ((OBJECT_Data *)vedata)->stl;
|
2017-03-20 14:59:27 +01:00
|
|
|
DefaultTextureList *dtxl = DRW_viewport_texture_list_get();
|
2018-04-17 13:01:01 +02:00
|
|
|
OBJECT_PrivateData *g_data;
|
2018-04-18 11:34:46 +02:00
|
|
|
/* TODO : use dpi setting for enabling the second pass */
|
|
|
|
const bool do_outline_expand = false;
|
2017-03-08 20:00:09 +01:00
|
|
|
|
2017-03-26 20:13:34 +02:00
|
|
|
if (!stl->g_data) {
|
|
|
|
/* Alloc transient pointers */
|
2017-04-29 16:52:12 +10:00
|
|
|
stl->g_data = MEM_mallocN(sizeof(*stl->g_data), __func__);
|
2017-03-26 20:13:34 +02:00
|
|
|
}
|
|
|
|
|
2018-04-17 13:01:01 +02:00
|
|
|
g_data = stl->g_data;
|
|
|
|
|
2017-03-08 20:00:09 +01:00
|
|
|
{
|
2018-05-20 19:05:13 +02:00
|
|
|
DRWState state = DRW_STATE_WRITE_COLOR | DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS_EQUAL | DRW_STATE_WIRE;
|
2017-08-09 23:51:00 +02:00
|
|
|
psl->outlines = DRW_pass_create("Outlines Depth Pass", state);
|
2017-03-18 01:55:41 +01:00
|
|
|
|
2018-04-16 19:38:40 +02:00
|
|
|
GPUShader *sh = e_data.outline_prepass_sh;
|
2017-03-18 01:55:41 +01:00
|
|
|
|
|
|
|
/* Select */
|
2018-04-17 13:01:01 +02:00
|
|
|
g_data->outlines_select = shgroup_outline(psl->outlines, &g_data->id_ofs_select, sh);
|
2017-03-18 01:55:41 +01:00
|
|
|
|
|
|
|
/* Transform */
|
2018-04-17 13:01:01 +02:00
|
|
|
g_data->outlines_transform = shgroup_outline(psl->outlines, &g_data->id_ofs_transform, sh);
|
2017-03-18 01:55:41 +01:00
|
|
|
|
|
|
|
/* Active */
|
2018-04-17 13:01:01 +02:00
|
|
|
g_data->outlines_active = shgroup_outline(psl->outlines, &g_data->id_ofs_active, sh);
|
2018-04-16 19:38:40 +02:00
|
|
|
|
2018-04-17 13:01:01 +02:00
|
|
|
g_data->id_ofs_select = 0;
|
|
|
|
g_data->id_ofs_active = 0;
|
|
|
|
g_data->id_ofs_transform = 0;
|
2017-03-18 01:55:41 +01:00
|
|
|
}
|
|
|
|
|
2017-09-30 19:34:23 +02:00
|
|
|
{
|
2018-05-20 19:05:13 +02:00
|
|
|
DRWState state = DRW_STATE_WRITE_COLOR | DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS_EQUAL;
|
2018-04-17 13:01:01 +02:00
|
|
|
DRWPass *pass = psl->lightprobes = DRW_pass_create("Object Probe Pass", state);
|
|
|
|
struct Gwn_Batch *sphere = DRW_cache_sphere_get();
|
|
|
|
struct Gwn_Batch *quad = DRW_cache_quad_get();
|
2017-09-30 19:34:23 +02:00
|
|
|
|
|
|
|
/* Cubemap */
|
2018-04-17 13:01:01 +02:00
|
|
|
g_data->lightprobes_cube_select = shgroup_instance_outline(pass, sphere, &g_data->id_ofs_prb_select);
|
|
|
|
g_data->lightprobes_cube_active = shgroup_instance_outline(pass, sphere, &g_data->id_ofs_prb_active);
|
|
|
|
g_data->lightprobes_cube_transform = shgroup_instance_outline(pass, sphere, &g_data->id_ofs_prb_transform);
|
2017-09-30 19:34:23 +02:00
|
|
|
|
|
|
|
/* Planar */
|
2018-04-17 13:01:01 +02:00
|
|
|
g_data->lightprobes_planar_select = shgroup_instance_outline(pass, quad, &g_data->id_ofs_prb_select);
|
|
|
|
g_data->lightprobes_planar_active = shgroup_instance_outline(pass, quad, &g_data->id_ofs_prb_active);
|
|
|
|
g_data->lightprobes_planar_transform = shgroup_instance_outline(pass, quad, &g_data->id_ofs_prb_transform);
|
|
|
|
|
|
|
|
g_data->id_ofs_prb_select = 0;
|
|
|
|
g_data->id_ofs_prb_active = 0;
|
|
|
|
g_data->id_ofs_prb_transform = 0;
|
2017-09-30 19:34:23 +02:00
|
|
|
}
|
|
|
|
|
2017-03-18 01:55:41 +01:00
|
|
|
{
|
2017-03-20 14:59:27 +01:00
|
|
|
DRWState state = DRW_STATE_WRITE_COLOR;
|
2017-06-19 20:18:04 +10:00
|
|
|
struct Gwn_Batch *quad = DRW_cache_fullscreen_quad_get();
|
2017-03-21 19:29:58 +01:00
|
|
|
static float alphaOcclu = 0.35f;
|
2018-01-03 20:39:44 +01:00
|
|
|
/* Reminder : bool uniforms need to be 4 bytes. */
|
|
|
|
static const int bTrue = true;
|
|
|
|
static const int bFalse = false;
|
2017-03-18 01:55:41 +01:00
|
|
|
|
2017-08-09 23:51:00 +02:00
|
|
|
psl->outlines_search = DRW_pass_create("Outlines Detect Pass", state);
|
2017-03-22 02:14:23 +01:00
|
|
|
|
|
|
|
DRWShadingGroup *grp = DRW_shgroup_create(e_data.outline_detect_sh, psl->outlines_search);
|
2018-04-16 19:38:40 +02:00
|
|
|
DRW_shgroup_uniform_texture_ref(grp, "outlineId", &e_data.outlines_id_tx);
|
2018-03-25 19:24:19 +02:00
|
|
|
DRW_shgroup_uniform_texture_ref(grp, "outlineDepth", &e_data.outlines_depth_tx);
|
|
|
|
DRW_shgroup_uniform_texture_ref(grp, "sceneDepth", &dtxl->depth);
|
2018-04-16 19:38:40 +02:00
|
|
|
DRW_shgroup_uniform_block(grp, "globalsBlock", globals_ubo);
|
2017-03-21 19:29:58 +01:00
|
|
|
DRW_shgroup_uniform_float(grp, "alphaOcclu", &alphaOcclu, 1);
|
2018-05-04 11:36:50 +02:00
|
|
|
DRW_shgroup_uniform_int(grp, "idOffsets", &stl->g_data->id_ofs_active, 3);
|
2017-03-20 14:59:27 +01:00
|
|
|
DRW_shgroup_call_add(grp, quad, NULL);
|
2017-03-18 01:55:41 +01:00
|
|
|
|
2017-03-22 02:14:23 +01:00
|
|
|
psl->outlines_expand = DRW_pass_create("Outlines Expand Pass", state);
|
2017-03-20 14:59:27 +01:00
|
|
|
|
2017-03-22 02:14:23 +01:00
|
|
|
grp = DRW_shgroup_create(e_data.outline_fade_sh, psl->outlines_expand);
|
2018-03-25 19:24:19 +02:00
|
|
|
DRW_shgroup_uniform_texture_ref(grp, "outlineColor", &e_data.outlines_blur_tx);
|
2018-04-18 11:34:46 +02:00
|
|
|
DRW_shgroup_uniform_bool(grp, "doExpand", (do_outline_expand) ? &bTrue : &bFalse, 1);
|
2017-03-20 14:59:27 +01:00
|
|
|
DRW_shgroup_call_add(grp, quad, NULL);
|
|
|
|
|
2017-09-22 17:30:39 +02:00
|
|
|
psl->outlines_bleed = DRW_pass_create("Outlines Bleed Pass", state);
|
2017-03-22 02:14:23 +01:00
|
|
|
|
2018-04-18 11:34:46 +02:00
|
|
|
if (do_outline_expand) {
|
|
|
|
grp = DRW_shgroup_create(e_data.outline_fade_sh, psl->outlines_bleed);
|
|
|
|
DRW_shgroup_uniform_texture_ref(grp, "outlineColor", &e_data.outlines_color_tx);
|
|
|
|
DRW_shgroup_uniform_bool(grp, "doExpand", &bFalse, 1);
|
|
|
|
DRW_shgroup_call_add(grp, quad, NULL);
|
|
|
|
}
|
2017-03-20 14:59:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
DRWState state = DRW_STATE_WRITE_COLOR | DRW_STATE_BLEND;
|
|
|
|
psl->outlines_resolve = DRW_pass_create("Outlines Resolve Pass", state);
|
|
|
|
|
2017-06-19 20:18:04 +10:00
|
|
|
struct Gwn_Batch *quad = DRW_cache_fullscreen_quad_get();
|
2018-04-18 11:34:46 +02:00
|
|
|
GPUTexture **outline_tx = (do_outline_expand) ? &e_data.outlines_blur_tx : &e_data.outlines_color_tx;
|
2017-03-20 14:59:27 +01:00
|
|
|
|
2017-09-22 17:30:39 +02:00
|
|
|
DRWShadingGroup *grp = DRW_shgroup_create(e_data.outline_resolve_aa_sh, psl->outlines_resolve);
|
2018-04-18 11:34:46 +02:00
|
|
|
DRW_shgroup_uniform_texture_ref(grp, "outlineBluredColor", outline_tx);
|
2017-09-22 17:30:39 +02:00
|
|
|
DRW_shgroup_uniform_vec2(grp, "rcpDimensions", e_data.inv_viewport_size, 1);
|
2017-03-20 14:59:27 +01:00
|
|
|
DRW_shgroup_call_add(grp, quad, NULL);
|
2017-03-08 20:00:09 +01:00
|
|
|
}
|
|
|
|
|
2017-03-22 21:28:59 +01:00
|
|
|
{
|
|
|
|
/* Grid pass */
|
2017-10-12 04:03:42 +02:00
|
|
|
DRWState state = DRW_STATE_WRITE_COLOR | DRW_STATE_BLEND;
|
2017-03-22 21:28:59 +01:00
|
|
|
psl->grid = DRW_pass_create("Infinite Grid Pass", state);
|
|
|
|
|
2017-06-19 20:18:04 +10:00
|
|
|
struct Gwn_Batch *quad = DRW_cache_fullscreen_quad_get();
|
2017-04-03 21:37:40 +02:00
|
|
|
static float mat[4][4];
|
|
|
|
unit_m4(mat);
|
2017-03-22 21:28:59 +01:00
|
|
|
|
2017-03-25 02:46:23 +01:00
|
|
|
/* Create 3 quads to render ordered transparency Z axis */
|
2017-03-22 21:28:59 +01:00
|
|
|
DRWShadingGroup *grp = DRW_shgroup_create(e_data.grid_sh, psl->grid);
|
2017-03-25 02:46:23 +01:00
|
|
|
DRW_shgroup_uniform_int(grp, "gridFlag", &e_data.zneg_flag, 1);
|
2017-05-27 21:35:03 +02:00
|
|
|
DRW_shgroup_uniform_vec3(grp, "planeNormal", e_data.zplane_normal, 1);
|
|
|
|
DRW_shgroup_uniform_vec3(grp, "planeAxes", e_data.zplane_axes, 1);
|
2017-03-22 21:28:59 +01:00
|
|
|
DRW_shgroup_uniform_vec3(grp, "cameraPos", e_data.camera_pos, 1);
|
2017-05-27 12:48:25 +02:00
|
|
|
DRW_shgroup_uniform_vec4(grp, "screenvecs[0]", e_data.screenvecs[0], 3);
|
2017-03-22 21:28:59 +01:00
|
|
|
DRW_shgroup_uniform_vec4(grp, "gridSettings", e_data.grid_settings, 1);
|
2017-03-27 14:01:25 +02:00
|
|
|
DRW_shgroup_uniform_float(grp, "gridOneOverLogSubdiv", &e_data.grid_settings[4], 1);
|
2017-05-09 23:55:02 +02:00
|
|
|
DRW_shgroup_uniform_block(grp, "globalsBlock", globals_ubo);
|
2017-05-27 12:48:25 +02:00
|
|
|
DRW_shgroup_uniform_vec2(grp, "viewportSize", DRW_viewport_size_get(), 1);
|
2018-03-25 19:24:19 +02:00
|
|
|
DRW_shgroup_uniform_texture_ref(grp, "depthBuffer", &dtxl->depth);
|
2017-04-03 21:37:40 +02:00
|
|
|
DRW_shgroup_call_add(grp, quad, mat);
|
2017-03-25 02:46:23 +01:00
|
|
|
|
|
|
|
grp = DRW_shgroup_create(e_data.grid_sh, psl->grid);
|
|
|
|
DRW_shgroup_uniform_int(grp, "gridFlag", &e_data.grid_flag, 1);
|
2017-05-27 21:35:03 +02:00
|
|
|
DRW_shgroup_uniform_vec3(grp, "planeNormal", e_data.grid_normal, 1);
|
|
|
|
DRW_shgroup_uniform_vec3(grp, "planeAxes", e_data.grid_axes, 1);
|
2017-09-11 23:15:29 +02:00
|
|
|
DRW_shgroup_uniform_block(grp, "globalsBlock", globals_ubo);
|
2018-03-25 19:24:19 +02:00
|
|
|
DRW_shgroup_uniform_texture_ref(grp, "depthBuffer", &dtxl->depth);
|
2017-04-03 21:37:40 +02:00
|
|
|
DRW_shgroup_call_add(grp, quad, mat);
|
2017-03-25 02:46:23 +01:00
|
|
|
|
|
|
|
grp = DRW_shgroup_create(e_data.grid_sh, psl->grid);
|
|
|
|
DRW_shgroup_uniform_int(grp, "gridFlag", &e_data.zpos_flag, 1);
|
2017-05-27 21:35:03 +02:00
|
|
|
DRW_shgroup_uniform_vec3(grp, "planeNormal", e_data.zplane_normal, 1);
|
|
|
|
DRW_shgroup_uniform_vec3(grp, "planeAxes", e_data.zplane_axes, 1);
|
2017-09-11 23:15:29 +02:00
|
|
|
DRW_shgroup_uniform_block(grp, "globalsBlock", globals_ubo);
|
2018-03-25 19:24:19 +02:00
|
|
|
DRW_shgroup_uniform_texture_ref(grp, "depthBuffer", &dtxl->depth);
|
2017-04-03 21:37:40 +02:00
|
|
|
DRW_shgroup_call_add(grp, quad, mat);
|
2017-03-22 21:28:59 +01:00
|
|
|
}
|
|
|
|
|
2017-03-08 20:00:09 +01:00
|
|
|
{
|
|
|
|
/* Solid bones */
|
2018-05-20 19:05:13 +02:00
|
|
|
DRWState state = DRW_STATE_WRITE_COLOR | DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS_EQUAL | DRW_STATE_CULL_BACK;
|
2017-03-08 20:00:09 +01:00
|
|
|
psl->bone_solid = DRW_pass_create("Bone Solid Pass", state);
|
2018-04-22 22:49:36 +02:00
|
|
|
psl->bone_outline = DRW_pass_create("Bone Outline Pass", state);
|
2017-03-08 20:00:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
/* Wire bones */
|
2018-05-20 19:05:13 +02:00
|
|
|
DRWState state = DRW_STATE_WRITE_COLOR | DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS_EQUAL | DRW_STATE_BLEND;
|
2017-03-08 20:00:09 +01:00
|
|
|
psl->bone_wire = DRW_pass_create("Bone Wire Pass", state);
|
|
|
|
}
|
|
|
|
|
2017-05-17 14:33:34 +02:00
|
|
|
{
|
|
|
|
/* distance outline around envelope bones */
|
2018-05-20 19:05:13 +02:00
|
|
|
DRWState state = DRW_STATE_ADDITIVE | DRW_STATE_WRITE_COLOR | DRW_STATE_DEPTH_LESS_EQUAL | DRW_STATE_CULL_FRONT;
|
2017-05-17 14:33:34 +02:00
|
|
|
psl->bone_envelope = DRW_pass_create("Bone Envelope Outline Pass", state);
|
|
|
|
}
|
|
|
|
|
2018-05-06 18:36:27 +02:00
|
|
|
{
|
2018-05-20 19:05:13 +02:00
|
|
|
DRWState state = DRW_STATE_WRITE_COLOR | DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS_EQUAL | DRW_STATE_WIRE;
|
2018-05-06 18:36:27 +02:00
|
|
|
psl->bone_axes = DRW_pass_create("Bone Axes Pass", state);
|
|
|
|
}
|
|
|
|
|
2017-03-08 20:00:09 +01:00
|
|
|
{
|
|
|
|
/* Non Meshes Pass (Camera, empties, lamps ...) */
|
2017-06-19 20:18:04 +10:00
|
|
|
struct Gwn_Batch *geom;
|
2017-03-08 20:00:09 +01:00
|
|
|
|
2017-04-21 04:39:51 +10:00
|
|
|
DRWState state =
|
|
|
|
DRW_STATE_WRITE_COLOR | DRW_STATE_WRITE_DEPTH |
|
2018-05-20 19:05:13 +02:00
|
|
|
DRW_STATE_DEPTH_LESS_EQUAL | DRW_STATE_BLEND | DRW_STATE_POINT;
|
2017-03-08 20:00:09 +01:00
|
|
|
state |= DRW_STATE_WIRE;
|
|
|
|
psl->non_meshes = DRW_pass_create("Non Meshes Pass", state);
|
|
|
|
|
|
|
|
/* Empties */
|
|
|
|
geom = DRW_cache_plain_axes_get();
|
2017-03-26 20:13:34 +02:00
|
|
|
stl->g_data->plain_axes = shgroup_instance(psl->non_meshes, geom);
|
2017-03-08 20:00:09 +01:00
|
|
|
|
|
|
|
geom = DRW_cache_cube_get();
|
2017-03-26 20:13:34 +02:00
|
|
|
stl->g_data->cube = shgroup_instance(psl->non_meshes, geom);
|
2017-03-08 20:00:09 +01:00
|
|
|
|
|
|
|
geom = DRW_cache_circle_get();
|
2017-03-26 20:13:34 +02:00
|
|
|
stl->g_data->circle = shgroup_instance(psl->non_meshes, geom);
|
2017-03-08 20:00:09 +01:00
|
|
|
|
|
|
|
geom = DRW_cache_empty_sphere_get();
|
2017-03-26 20:13:34 +02:00
|
|
|
stl->g_data->sphere = shgroup_instance(psl->non_meshes, geom);
|
2017-03-08 20:00:09 +01:00
|
|
|
|
|
|
|
geom = DRW_cache_empty_cone_get();
|
2017-03-26 20:13:34 +02:00
|
|
|
stl->g_data->cone = shgroup_instance(psl->non_meshes, geom);
|
2017-03-08 20:00:09 +01:00
|
|
|
|
|
|
|
geom = DRW_cache_single_arrow_get();
|
2017-03-26 20:13:34 +02:00
|
|
|
stl->g_data->single_arrow = shgroup_instance(psl->non_meshes, geom);
|
2017-03-08 20:00:09 +01:00
|
|
|
|
|
|
|
geom = DRW_cache_single_line_get();
|
2017-03-26 20:13:34 +02:00
|
|
|
stl->g_data->single_arrow_line = shgroup_instance(psl->non_meshes, geom);
|
2017-03-08 20:00:09 +01:00
|
|
|
|
|
|
|
geom = DRW_cache_arrows_get();
|
2017-03-26 20:13:34 +02:00
|
|
|
stl->g_data->arrows = shgroup_instance(psl->non_meshes, geom);
|
2017-03-08 20:00:09 +01:00
|
|
|
|
|
|
|
geom = DRW_cache_axis_names_get();
|
2017-03-26 20:13:34 +02:00
|
|
|
stl->g_data->axis_names = shgroup_instance_axis_names(psl->non_meshes, geom);
|
2017-03-08 20:00:09 +01:00
|
|
|
|
2017-05-20 22:57:47 +10:00
|
|
|
/* initialize on first use */
|
|
|
|
stl->g_data->image_plane_map = NULL;
|
|
|
|
|
2017-04-10 22:22:37 +02:00
|
|
|
/* Force Field */
|
|
|
|
geom = DRW_cache_field_wind_get();
|
|
|
|
stl->g_data->field_wind = shgroup_instance_scaled(psl->non_meshes, geom);
|
|
|
|
|
|
|
|
geom = DRW_cache_field_force_get();
|
|
|
|
stl->g_data->field_force = shgroup_instance_screen_aligned(psl->non_meshes, geom);
|
|
|
|
|
|
|
|
geom = DRW_cache_field_vortex_get();
|
|
|
|
stl->g_data->field_vortex = shgroup_instance_scaled(psl->non_meshes, geom);
|
|
|
|
|
|
|
|
geom = DRW_cache_screenspace_circle_get();
|
|
|
|
stl->g_data->field_curve_sta = shgroup_instance_screen_aligned(psl->non_meshes, geom);
|
|
|
|
|
2017-03-08 20:00:09 +01:00
|
|
|
/* Speaker */
|
|
|
|
geom = DRW_cache_speaker_get();
|
2017-03-26 20:13:34 +02:00
|
|
|
stl->g_data->speaker = shgroup_instance(psl->non_meshes, geom);
|
2017-03-08 20:00:09 +01:00
|
|
|
|
2017-06-07 16:00:10 +02:00
|
|
|
/* Probe */
|
2017-06-27 14:59:53 +02:00
|
|
|
static float probeSize = 14.0f;
|
|
|
|
geom = DRW_cache_lightprobe_cube_get();
|
|
|
|
stl->g_data->probe_cube = shgroup_instance_screenspace(psl->non_meshes, geom, &probeSize);
|
|
|
|
|
|
|
|
geom = DRW_cache_lightprobe_grid_get();
|
|
|
|
stl->g_data->probe_grid = shgroup_instance_screenspace(psl->non_meshes, geom, &probeSize);
|
|
|
|
|
|
|
|
static float probePlanarSize = 20.0f;
|
|
|
|
geom = DRW_cache_lightprobe_planar_get();
|
|
|
|
stl->g_data->probe_planar = shgroup_instance_screenspace(psl->non_meshes, geom, &probePlanarSize);
|
2017-06-07 16:00:10 +02:00
|
|
|
|
2017-03-08 20:00:09 +01:00
|
|
|
/* Camera */
|
|
|
|
geom = DRW_cache_camera_get();
|
2017-03-26 20:13:34 +02:00
|
|
|
stl->g_data->camera = shgroup_camera_instance(psl->non_meshes, geom);
|
2017-03-08 20:00:09 +01:00
|
|
|
|
2018-01-22 00:14:28 +01:00
|
|
|
geom = DRW_cache_camera_frame_get();
|
|
|
|
stl->g_data->camera_frame = shgroup_camera_instance(psl->non_meshes, geom);
|
|
|
|
|
2017-03-08 20:00:09 +01:00
|
|
|
geom = DRW_cache_camera_tria_get();
|
2017-03-26 20:13:34 +02:00
|
|
|
stl->g_data->camera_tria = shgroup_camera_instance(psl->non_meshes, geom);
|
2017-03-08 20:00:09 +01:00
|
|
|
|
|
|
|
geom = DRW_cache_plain_axes_get();
|
2017-03-26 20:13:34 +02:00
|
|
|
stl->g_data->camera_focus = shgroup_instance(psl->non_meshes, geom);
|
2017-03-08 20:00:09 +01:00
|
|
|
|
|
|
|
geom = DRW_cache_single_line_get();
|
2017-03-26 20:13:34 +02:00
|
|
|
stl->g_data->camera_clip = shgroup_distance_lines_instance(psl->non_meshes, geom);
|
|
|
|
stl->g_data->camera_mist = shgroup_distance_lines_instance(psl->non_meshes, geom);
|
2017-03-08 20:00:09 +01:00
|
|
|
|
|
|
|
geom = DRW_cache_single_line_endpoints_get();
|
2017-03-26 20:13:34 +02:00
|
|
|
stl->g_data->camera_clip_points = shgroup_distance_lines_instance(psl->non_meshes, geom);
|
|
|
|
stl->g_data->camera_mist_points = shgroup_distance_lines_instance(psl->non_meshes, geom);
|
2017-03-08 20:00:09 +01:00
|
|
|
|
2017-04-13 22:09:59 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2017-04-21 04:39:51 +10:00
|
|
|
GPUShader *sh = GPU_shader_get_builtin_shader(GPU_SHADER_3D_UNIFORM_COLOR);
|
2017-04-13 22:09:59 +10:00
|
|
|
|
|
|
|
/* Unselected */
|
|
|
|
stl->g_data->wire = shgroup_wire(psl->non_meshes, ts.colorWire, sh);
|
|
|
|
|
|
|
|
/* Select */
|
|
|
|
stl->g_data->wire_select = shgroup_wire(psl->non_meshes, ts.colorSelect, sh);
|
|
|
|
|
|
|
|
/* Transform */
|
|
|
|
stl->g_data->wire_transform = shgroup_wire(psl->non_meshes, ts.colorTransform, sh);
|
|
|
|
|
|
|
|
/* Active */
|
|
|
|
stl->g_data->wire_active = shgroup_wire(psl->non_meshes, ts.colorActive, sh);
|
|
|
|
}
|
|
|
|
|
2018-02-24 04:45:13 +01:00
|
|
|
|
|
|
|
{
|
|
|
|
GPUShader *sh = GPU_shader_get_builtin_shader(GPU_SHADER_3D_POINT_FIXED_SIZE_UNIFORM_COLOR);
|
|
|
|
|
|
|
|
/* Unselected */
|
|
|
|
stl->g_data->points = shgroup_points(psl->non_meshes, ts.colorWire, sh);
|
|
|
|
|
|
|
|
/* Select */
|
|
|
|
stl->g_data->points_select = shgroup_points(psl->non_meshes, ts.colorSelect, sh);
|
|
|
|
|
|
|
|
/* Transform */
|
|
|
|
stl->g_data->points_transform = shgroup_points(psl->non_meshes, ts.colorTransform, sh);
|
|
|
|
|
|
|
|
/* Active */
|
|
|
|
stl->g_data->points_active = shgroup_points(psl->non_meshes, ts.colorActive, sh);
|
|
|
|
}
|
|
|
|
|
2017-11-16 15:12:32 -02:00
|
|
|
{
|
2018-02-16 02:01:09 -02:00
|
|
|
/* Metaballs Handles */
|
2018-05-02 21:26:43 -03:00
|
|
|
stl->g_data->mball_handle = shgroup_instance_mball_handles(psl->non_meshes);
|
2017-11-16 15:12:32 -02:00
|
|
|
}
|
|
|
|
|
2017-04-13 22:09:59 +10:00
|
|
|
{
|
2017-03-08 20:00:09 +01:00
|
|
|
/* Lamps */
|
|
|
|
/* TODO
|
|
|
|
* for now we create multiple times the same VBO with only lamp center coordinates
|
|
|
|
* but ideally we would only create it once */
|
2017-06-19 20:18:04 +10:00
|
|
|
struct Gwn_Batch *geom;
|
2017-03-08 20:00:09 +01:00
|
|
|
|
|
|
|
/* start with buflimit because we don't want stipples */
|
|
|
|
geom = DRW_cache_single_line_get();
|
2017-03-26 20:13:34 +02:00
|
|
|
stl->g_data->lamp_buflimit = shgroup_distance_lines_instance(psl->non_meshes, geom);
|
2017-03-08 20:00:09 +01:00
|
|
|
|
2017-03-26 20:13:34 +02:00
|
|
|
stl->g_data->lamp_center = shgroup_dynpoints_uniform_color(psl->non_meshes, ts.colorLampNoAlpha, &ts.sizeLampCenter);
|
2017-03-08 20:00:09 +01:00
|
|
|
|
|
|
|
geom = DRW_cache_lamp_get();
|
2017-03-26 20:13:34 +02:00
|
|
|
stl->g_data->lamp_circle = shgroup_instance_screenspace(psl->non_meshes, geom, &ts.sizeLampCircle);
|
2018-01-21 18:32:40 +01:00
|
|
|
geom = DRW_cache_lamp_shadows_get();
|
2017-03-26 20:13:34 +02:00
|
|
|
stl->g_data->lamp_circle_shadow = shgroup_instance_screenspace(psl->non_meshes, geom, &ts.sizeLampCircleShadow);
|
2017-03-08 20:00:09 +01:00
|
|
|
|
|
|
|
geom = DRW_cache_lamp_sunrays_get();
|
2017-03-26 20:13:34 +02:00
|
|
|
stl->g_data->lamp_sunrays = shgroup_instance_screenspace(psl->non_meshes, geom, &ts.sizeLampCircle);
|
2017-03-08 20:00:09 +01:00
|
|
|
|
2017-03-26 20:13:34 +02:00
|
|
|
stl->g_data->lamp_groundline = shgroup_groundlines_uniform_color(psl->non_meshes, ts.colorLamp);
|
|
|
|
stl->g_data->lamp_groundpoint = shgroup_groundpoints_uniform_color(psl->non_meshes, ts.colorLamp);
|
2017-03-08 20:00:09 +01:00
|
|
|
|
Cycles/Eevee: Implement disk and ellipse shapes for area lamps
The implementation is pretty straightforward.
In Cycles, sampling the shapes is currently done w.r.t. area instead of solid angle.
There is a paper on solid angle sampling for disks [1], but the described algorithm is based on
simply sampling the enclosing square and rejecting samples outside of the disk, which is not exactly
great for Cycles' RNG (we'd need to setup a LCG for the repeated sampling) and for GPU divergence.
Even worse, the algorithm is only defined for disks. For ellipses, the basic idea still works, but a
way to analytically calculate the solid angle is required. This is technically possible [2], but the
calculation is extremely complex and still requires a lookup table for the Heuman Lambda function.
Therefore, I've decided to not implement that for now, we could still look into it later on.
In Eevee, the code uses the existing ltc_evaluate_disk to implement the lighting calculations.
[1]: "Solid Angle Sampling of Disk and Cylinder Lights"
[2]: "Analytical solution for the solid angle subtended at any point by an ellipse via a point source radiation vector potential"
Reviewers: sergey, brecht, fclem
Differential Revision: https://developer.blender.org/D3171
2018-05-24 03:50:16 +02:00
|
|
|
geom = DRW_cache_lamp_area_square_get();
|
|
|
|
stl->g_data->lamp_area_square = shgroup_instance(psl->non_meshes, geom);
|
|
|
|
|
|
|
|
geom = DRW_cache_lamp_area_disk_get();
|
|
|
|
stl->g_data->lamp_area_disk = shgroup_instance(psl->non_meshes, geom);
|
2017-03-08 20:00:09 +01:00
|
|
|
|
|
|
|
geom = DRW_cache_lamp_hemi_get();
|
2017-03-26 20:13:34 +02:00
|
|
|
stl->g_data->lamp_hemi = shgroup_instance(psl->non_meshes, geom);
|
2017-03-08 20:00:09 +01:00
|
|
|
|
|
|
|
geom = DRW_cache_single_line_get();
|
2017-03-26 20:13:34 +02:00
|
|
|
stl->g_data->lamp_distance = shgroup_distance_lines_instance(psl->non_meshes, geom);
|
2017-03-08 20:00:09 +01:00
|
|
|
|
|
|
|
geom = DRW_cache_single_line_endpoints_get();
|
2017-03-26 20:13:34 +02:00
|
|
|
stl->g_data->lamp_buflimit_points = shgroup_distance_lines_instance(psl->non_meshes, geom);
|
2017-03-08 20:00:09 +01:00
|
|
|
|
|
|
|
geom = DRW_cache_lamp_spot_get();
|
2017-03-26 20:13:34 +02:00
|
|
|
stl->g_data->lamp_spot_cone = shgroup_spot_instance(psl->non_meshes, geom);
|
2017-03-08 20:00:09 +01:00
|
|
|
|
|
|
|
geom = DRW_cache_circle_get();
|
2017-03-26 20:13:34 +02:00
|
|
|
stl->g_data->lamp_spot_blend = shgroup_instance(psl->non_meshes, geom);
|
2017-03-08 20:00:09 +01:00
|
|
|
|
|
|
|
geom = DRW_cache_lamp_spot_square_get();
|
2017-03-26 20:13:34 +02:00
|
|
|
stl->g_data->lamp_spot_pyramid = shgroup_instance(psl->non_meshes, geom);
|
2017-03-08 20:00:09 +01:00
|
|
|
|
|
|
|
geom = DRW_cache_square_get();
|
2017-03-26 20:13:34 +02:00
|
|
|
stl->g_data->lamp_spot_blend_rect = shgroup_instance(psl->non_meshes, geom);
|
2017-04-13 22:09:59 +10:00
|
|
|
}
|
2017-03-08 20:00:09 +01:00
|
|
|
|
2017-04-13 22:09:59 +10:00
|
|
|
{
|
2017-04-10 22:22:37 +02:00
|
|
|
/* -------- STIPPLES ------- */
|
2017-06-19 20:18:04 +10:00
|
|
|
struct Gwn_Batch *geom;
|
2017-04-10 22:22:37 +02:00
|
|
|
|
2017-03-08 20:00:09 +01:00
|
|
|
/* Relationship Lines */
|
2018-05-07 00:22:03 +02:00
|
|
|
stl->g_data->relationship_lines = shgroup_dynlines_dashed_uniform_color(psl->non_meshes, ts.colorWire);
|
2017-04-10 22:22:37 +02:00
|
|
|
|
|
|
|
/* Force Field Curve Guide End (here because of stipple) */
|
2018-05-07 00:22:03 +02:00
|
|
|
/* TODO port to shader stipple */
|
2017-04-10 22:22:37 +02:00
|
|
|
geom = DRW_cache_screenspace_circle_get();
|
|
|
|
stl->g_data->field_curve_end = shgroup_instance_screen_aligned(psl->non_meshes, geom);
|
|
|
|
|
|
|
|
/* Force Field Limits */
|
2018-05-07 00:22:03 +02:00
|
|
|
/* TODO port to shader stipple */
|
2017-04-10 22:22:37 +02:00
|
|
|
geom = DRW_cache_field_tube_limit_get();
|
|
|
|
stl->g_data->field_tube_limit = shgroup_instance_scaled(psl->non_meshes, geom);
|
|
|
|
|
2018-05-07 00:22:03 +02:00
|
|
|
/* TODO port to shader stipple */
|
2017-04-10 22:22:37 +02:00
|
|
|
geom = DRW_cache_field_cone_limit_get();
|
|
|
|
stl->g_data->field_cone_limit = shgroup_instance_scaled(psl->non_meshes, geom);
|
2017-03-08 20:00:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
/* Object Center pass grouped by State */
|
|
|
|
DRWShadingGroup *grp;
|
|
|
|
static float outlineWidth, size;
|
|
|
|
|
|
|
|
DRWState state = DRW_STATE_WRITE_COLOR | DRW_STATE_BLEND | DRW_STATE_POINT;
|
|
|
|
psl->ob_center = DRW_pass_create("Obj Center Pass", state);
|
|
|
|
|
|
|
|
outlineWidth = 1.0f * U.pixelsize;
|
|
|
|
size = U.obcenter_dia * U.pixelsize + outlineWidth;
|
|
|
|
|
2017-04-21 04:39:51 +10:00
|
|
|
GPUShader *sh = GPU_shader_get_builtin_shader(GPU_SHADER_3D_POINT_UNIFORM_SIZE_UNIFORM_COLOR_OUTLINE_AA);
|
2017-03-08 20:00:09 +01:00
|
|
|
|
|
|
|
/* Active */
|
|
|
|
grp = DRW_shgroup_point_batch_create(sh, psl->ob_center);
|
|
|
|
DRW_shgroup_uniform_float(grp, "size", &size, 1);
|
|
|
|
DRW_shgroup_uniform_float(grp, "outlineWidth", &outlineWidth, 1);
|
|
|
|
DRW_shgroup_uniform_vec4(grp, "color", ts.colorActive, 1);
|
|
|
|
DRW_shgroup_uniform_vec4(grp, "outlineColor", ts.colorOutline, 1);
|
2017-03-26 20:13:34 +02:00
|
|
|
stl->g_data->center_active = grp;
|
2017-03-08 20:00:09 +01:00
|
|
|
|
|
|
|
/* Select */
|
|
|
|
grp = DRW_shgroup_point_batch_create(sh, psl->ob_center);
|
|
|
|
DRW_shgroup_uniform_vec4(grp, "color", ts.colorSelect, 1);
|
2017-03-26 20:13:34 +02:00
|
|
|
stl->g_data->center_selected = grp;
|
2017-03-08 20:00:09 +01:00
|
|
|
|
|
|
|
/* Deselect */
|
|
|
|
grp = DRW_shgroup_point_batch_create(sh, psl->ob_center);
|
|
|
|
DRW_shgroup_uniform_vec4(grp, "color", ts.colorDeselect, 1);
|
2017-03-26 20:13:34 +02:00
|
|
|
stl->g_data->center_deselected = grp;
|
2017-04-11 14:05:39 +10:00
|
|
|
|
|
|
|
/* Select (library) */
|
|
|
|
grp = DRW_shgroup_point_batch_create(sh, psl->ob_center);
|
|
|
|
DRW_shgroup_uniform_vec4(grp, "color", ts.colorLibrarySelect, 1);
|
|
|
|
stl->g_data->center_selected_lib = grp;
|
|
|
|
|
|
|
|
/* Deselect (library) */
|
|
|
|
grp = DRW_shgroup_point_batch_create(sh, psl->ob_center);
|
|
|
|
DRW_shgroup_uniform_vec4(grp, "color", ts.colorLibrary, 1);
|
|
|
|
stl->g_data->center_deselected_lib = grp;
|
2017-03-08 20:00:09 +01:00
|
|
|
}
|
2017-05-19 18:32:40 +02:00
|
|
|
|
|
|
|
{
|
|
|
|
/* Particle Pass */
|
2017-07-14 16:56:02 +10:00
|
|
|
psl->particle = DRW_pass_create(
|
|
|
|
"Particle Pass",
|
2018-05-20 19:05:13 +02:00
|
|
|
DRW_STATE_WRITE_COLOR | DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS_EQUAL |
|
2017-07-14 16:56:02 +10:00
|
|
|
DRW_STATE_POINT | DRW_STATE_BLEND);
|
2017-05-19 18:32:40 +02:00
|
|
|
}
|
2017-05-24 14:28:48 +10:00
|
|
|
|
|
|
|
{
|
|
|
|
/* Empty/Background Image Pass */
|
|
|
|
psl->reference_image = DRW_pass_create(
|
|
|
|
"Refrence Image Pass",
|
2018-05-20 19:05:13 +02:00
|
|
|
DRW_STATE_WRITE_COLOR | DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS_EQUAL | DRW_STATE_BLEND);
|
2017-05-24 14:28:48 +10:00
|
|
|
}
|
2017-03-08 20:00:09 +01:00
|
|
|
}
|
|
|
|
|
2018-02-16 02:01:09 -02:00
|
|
|
static void DRW_shgroup_mball_handles(OBJECT_StorageList *stl, Object *ob, ViewLayer *view_layer)
|
2017-11-16 15:12:32 -02:00
|
|
|
{
|
|
|
|
MetaBall *mb = ob->data;
|
|
|
|
|
|
|
|
float *color;
|
2017-11-22 10:52:39 -02:00
|
|
|
DRW_object_wire_theme_get(ob, view_layer, &color);
|
2017-11-16 15:12:32 -02:00
|
|
|
|
2018-05-02 21:26:43 -03:00
|
|
|
float draw_scale_xform[3][4]; /* Matrix of Scale and Translation */
|
|
|
|
{
|
|
|
|
float scamat[3][3];
|
|
|
|
copy_m3_m4(scamat, ob->obmat);
|
|
|
|
/* Get the normalized inverse matrix to extract only
|
|
|
|
* the scale of Scamat */
|
|
|
|
float iscamat[3][3];
|
|
|
|
invert_m3_m3(iscamat, scamat);
|
|
|
|
normalize_m3(iscamat);
|
|
|
|
mul_m3_m3_post(scamat, iscamat);
|
|
|
|
|
|
|
|
copy_v3_v3(draw_scale_xform[0], scamat[0]);
|
|
|
|
copy_v3_v3(draw_scale_xform[1], scamat[1]);
|
|
|
|
copy_v3_v3(draw_scale_xform[2], scamat[2]);
|
|
|
|
}
|
|
|
|
|
2017-11-16 15:12:32 -02:00
|
|
|
for (MetaElem *ml = mb->elems.first; ml != NULL; ml = ml->next) {
|
|
|
|
/* draw radius */
|
2018-05-02 21:26:43 -03:00
|
|
|
float world_pos[3];
|
|
|
|
mul_v3_m4v3(world_pos, ob->obmat, &ml->x);
|
|
|
|
draw_scale_xform[0][3] = world_pos[0];
|
|
|
|
draw_scale_xform[1][3] = world_pos[1];
|
|
|
|
draw_scale_xform[2][3] = world_pos[2];
|
|
|
|
|
|
|
|
DRW_shgroup_call_dynamic_add(stl->g_data->mball_handle, draw_scale_xform, &ml->rad, color);
|
2017-11-16 15:12:32 -02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-22 10:52:39 -02:00
|
|
|
static void DRW_shgroup_lamp(OBJECT_StorageList *stl, Object *ob, ViewLayer *view_layer)
|
2017-02-17 17:29:43 +01:00
|
|
|
{
|
2017-03-08 20:00:09 +01:00
|
|
|
Lamp *la = ob->data;
|
|
|
|
float *color;
|
2017-11-22 10:52:39 -02:00
|
|
|
int theme_id = DRW_object_wire_theme_get(ob, view_layer, &color);
|
2017-03-08 20:00:09 +01:00
|
|
|
static float zero = 0.0f;
|
|
|
|
|
2018-01-29 16:28:24 +01:00
|
|
|
typedef struct LampEngineData {
|
|
|
|
ObjectEngineData engine_data;
|
|
|
|
float shape_mat[4][4];
|
|
|
|
float spot_blend_mat[4][4];
|
|
|
|
} LampEngineData;
|
|
|
|
|
|
|
|
LampEngineData *lamp_engine_data =
|
|
|
|
(LampEngineData *)DRW_object_engine_data_ensure(
|
|
|
|
ob,
|
|
|
|
&draw_engine_object_type,
|
|
|
|
sizeof(LampEngineData),
|
|
|
|
NULL,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
float (*shapemat)[4] = lamp_engine_data->shape_mat;
|
|
|
|
float (*spotblendmat)[4] = lamp_engine_data->spot_blend_mat;
|
2017-04-03 19:01:10 +02:00
|
|
|
|
2017-03-08 20:00:09 +01:00
|
|
|
/* Don't draw the center if it's selected or active */
|
2018-05-04 11:36:50 +02:00
|
|
|
if (theme_id == TH_LAMP)
|
2017-04-22 15:53:11 +10:00
|
|
|
DRW_shgroup_call_dynamic_add(stl->g_data->lamp_center, ob->obmat[3]);
|
2017-03-08 20:00:09 +01:00
|
|
|
|
|
|
|
/* First circle */
|
2017-04-22 15:53:11 +10:00
|
|
|
DRW_shgroup_call_dynamic_add(stl->g_data->lamp_circle, ob->obmat[3], color);
|
2017-03-08 20:00:09 +01:00
|
|
|
|
Remove Blender Internal and legacy viewport from Blender 2.8.
Brecht authored this commit, but he gave me the honours to actually
do it. Here it goes; Blender Internal. Bye bye, you did great!
* Point density, voxel data, ocean, environment map textures were removed,
as these only worked within BI rendering. Note that the ocean modifier
and the Cycles point density shader node continue to work.
* Dynamic paint using material shading was removed, as this only worked
with BI. If we ever wanted to support this again probably it should go
through the baking API.
* GPU shader export through the Python API was removed. This only worked
for the old BI GLSL shaders, which no longer exists. Doing something
similar for Eevee would be significantly more complicated because it
uses a lot of multiplass rendering and logic outside the shader, it's
probably impractical.
* Collada material import / export code is mostly gone, as it only worked
for BI materials. We need to add Cycles / Eevee material support at some
point.
* The mesh noise operator was removed since it only worked with BI
material texture slots. A displacement modifier can be used instead.
* The delete texture paint slot operator was removed since it only worked
for BI material texture slots. Could be added back with node support.
* Not all legacy viewport features are supported in the new viewport, but
their code was removed. If we need to bring anything back we can look at
older git revisions.
* There is some legacy viewport code that I could not remove yet, and some
that I probably missed.
* Shader node execution code was left mostly intact, even though it is not
used anywhere now. We may eventually use this to replace the texture
nodes with Cycles / Eevee shader nodes.
* The Cycles Bake panel now includes settings for baking multires normal
and displacement maps. The underlying code needs to be merged properly,
and we plan to add back support for multires AO baking and add support
to Cycles baking for features like vertex color, displacement, and other
missing baking features.
* This commit removes DNA and the Python API for BI material, lamp, world
and scene settings. This breaks a lot of addons.
* There is more DNA that can be removed or renamed, where Cycles or Eevee
are reusing some old BI properties but the names are not really correct
anymore.
* Texture slots for materials, lamps and world were removed. They remain
for brushes, particles and freestyle linestyles.
* 'BLENDER_RENDER' remains in the COMPAT_ENGINES of UI panels. Cycles and
other renderers use this to find all panels to show, minus a few panels
that they have their own replacement for.
2018-04-19 17:34:44 +02:00
|
|
|
/* draw dashed outer circle for shadow */
|
2017-03-08 20:00:09 +01:00
|
|
|
if (la->type != LA_HEMI) {
|
Remove Blender Internal and legacy viewport from Blender 2.8.
Brecht authored this commit, but he gave me the honours to actually
do it. Here it goes; Blender Internal. Bye bye, you did great!
* Point density, voxel data, ocean, environment map textures were removed,
as these only worked within BI rendering. Note that the ocean modifier
and the Cycles point density shader node continue to work.
* Dynamic paint using material shading was removed, as this only worked
with BI. If we ever wanted to support this again probably it should go
through the baking API.
* GPU shader export through the Python API was removed. This only worked
for the old BI GLSL shaders, which no longer exists. Doing something
similar for Eevee would be significantly more complicated because it
uses a lot of multiplass rendering and logic outside the shader, it's
probably impractical.
* Collada material import / export code is mostly gone, as it only worked
for BI materials. We need to add Cycles / Eevee material support at some
point.
* The mesh noise operator was removed since it only worked with BI
material texture slots. A displacement modifier can be used instead.
* The delete texture paint slot operator was removed since it only worked
for BI material texture slots. Could be added back with node support.
* Not all legacy viewport features are supported in the new viewport, but
their code was removed. If we need to bring anything back we can look at
older git revisions.
* There is some legacy viewport code that I could not remove yet, and some
that I probably missed.
* Shader node execution code was left mostly intact, even though it is not
used anywhere now. We may eventually use this to replace the texture
nodes with Cycles / Eevee shader nodes.
* The Cycles Bake panel now includes settings for baking multires normal
and displacement maps. The underlying code needs to be merged properly,
and we plan to add back support for multires AO baking and add support
to Cycles baking for features like vertex color, displacement, and other
missing baking features.
* This commit removes DNA and the Python API for BI material, lamp, world
and scene settings. This breaks a lot of addons.
* There is more DNA that can be removed or renamed, where Cycles or Eevee
are reusing some old BI properties but the names are not really correct
anymore.
* Texture slots for materials, lamps and world were removed. They remain
for brushes, particles and freestyle linestyles.
* 'BLENDER_RENDER' remains in the COMPAT_ENGINES of UI panels. Cycles and
other renderers use this to find all panels to show, minus a few panels
that they have their own replacement for.
2018-04-19 17:34:44 +02:00
|
|
|
DRW_shgroup_call_dynamic_add(stl->g_data->lamp_circle_shadow, ob->obmat[3], color);
|
2017-03-08 20:00:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Distance */
|
|
|
|
if (ELEM(la->type, LA_HEMI, LA_SUN, LA_AREA)) {
|
2017-04-22 15:53:11 +10:00
|
|
|
DRW_shgroup_call_dynamic_add(stl->g_data->lamp_distance, color, &zero, &la->dist, ob->obmat);
|
2017-03-08 20:00:09 +01:00
|
|
|
}
|
|
|
|
|
2017-04-03 19:01:10 +02:00
|
|
|
copy_m4_m4(shapemat, ob->obmat);
|
2017-03-08 20:00:09 +01:00
|
|
|
|
|
|
|
if (la->type == LA_SUN) {
|
2017-04-22 15:53:11 +10:00
|
|
|
DRW_shgroup_call_dynamic_add(stl->g_data->lamp_sunrays, ob->obmat[3], color);
|
2017-03-08 20:00:09 +01:00
|
|
|
}
|
|
|
|
else if (la->type == LA_SPOT) {
|
|
|
|
float size[3], sizemat[4][4];
|
|
|
|
static float one = 1.0f;
|
|
|
|
float blend = 1.0f - pow2f(la->spotblend);
|
|
|
|
|
|
|
|
size[0] = size[1] = sinf(la->spotsize * 0.5f) * la->dist;
|
|
|
|
size[2] = cosf(la->spotsize * 0.5f) * la->dist;
|
|
|
|
|
|
|
|
size_to_mat4(sizemat, size);
|
2017-04-03 19:01:10 +02:00
|
|
|
mul_m4_m4m4(shapemat, ob->obmat, sizemat);
|
2017-03-08 20:00:09 +01:00
|
|
|
|
|
|
|
size[0] = size[1] = blend; size[2] = 1.0f;
|
|
|
|
size_to_mat4(sizemat, size);
|
|
|
|
translate_m4(sizemat, 0.0f, 0.0f, -1.0f);
|
2017-08-01 13:35:26 +10:00
|
|
|
rotate_m4(sizemat, 'X', (float)(M_PI / 2));
|
2017-04-03 19:01:10 +02:00
|
|
|
mul_m4_m4m4(spotblendmat, shapemat, sizemat);
|
2017-03-08 20:00:09 +01:00
|
|
|
|
|
|
|
if (la->mode & LA_SQUARE) {
|
2017-05-03 14:32:16 +02:00
|
|
|
DRW_shgroup_call_dynamic_add(stl->g_data->lamp_spot_pyramid, color, &one, shapemat);
|
2017-03-08 20:00:09 +01:00
|
|
|
|
|
|
|
/* hide line if it is zero size or overlaps with outer border,
|
|
|
|
* previously it adjusted to always to show it but that seems
|
|
|
|
* confusing because it doesn't show the actual blend size */
|
|
|
|
if (blend != 0.0f && blend != 1.0f) {
|
2017-04-22 15:53:11 +10:00
|
|
|
DRW_shgroup_call_dynamic_add(stl->g_data->lamp_spot_blend_rect, color, &one, spotblendmat);
|
2017-03-08 20:00:09 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2017-05-03 14:32:16 +02:00
|
|
|
DRW_shgroup_call_dynamic_add(stl->g_data->lamp_spot_cone, color, shapemat);
|
2017-03-08 20:00:09 +01:00
|
|
|
|
|
|
|
/* hide line if it is zero size or overlaps with outer border,
|
|
|
|
* previously it adjusted to always to show it but that seems
|
|
|
|
* confusing because it doesn't show the actual blend size */
|
|
|
|
if (blend != 0.0f && blend != 1.0f) {
|
2017-04-22 15:53:11 +10:00
|
|
|
DRW_shgroup_call_dynamic_add(stl->g_data->lamp_spot_blend, color, &one, spotblendmat);
|
2017-03-08 20:00:09 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-03 14:32:16 +02:00
|
|
|
DRW_shgroup_call_dynamic_add(stl->g_data->lamp_buflimit, color, &la->clipsta, &la->clipend, ob->obmat);
|
2017-04-22 15:53:11 +10:00
|
|
|
DRW_shgroup_call_dynamic_add(stl->g_data->lamp_buflimit_points, color, &la->clipsta, &la->clipend, ob->obmat);
|
2017-03-08 20:00:09 +01:00
|
|
|
}
|
|
|
|
else if (la->type == LA_HEMI) {
|
|
|
|
static float hemisize = 2.0f;
|
2017-04-22 15:53:11 +10:00
|
|
|
DRW_shgroup_call_dynamic_add(stl->g_data->lamp_hemi, color, &hemisize, shapemat);
|
2017-03-08 20:00:09 +01:00
|
|
|
}
|
|
|
|
else if (la->type == LA_AREA) {
|
|
|
|
float size[3] = {1.0f, 1.0f, 1.0f}, sizemat[4][4];
|
|
|
|
|
Cycles/Eevee: Implement disk and ellipse shapes for area lamps
The implementation is pretty straightforward.
In Cycles, sampling the shapes is currently done w.r.t. area instead of solid angle.
There is a paper on solid angle sampling for disks [1], but the described algorithm is based on
simply sampling the enclosing square and rejecting samples outside of the disk, which is not exactly
great for Cycles' RNG (we'd need to setup a LCG for the repeated sampling) and for GPU divergence.
Even worse, the algorithm is only defined for disks. For ellipses, the basic idea still works, but a
way to analytically calculate the solid angle is required. This is technically possible [2], but the
calculation is extremely complex and still requires a lookup table for the Heuman Lambda function.
Therefore, I've decided to not implement that for now, we could still look into it later on.
In Eevee, the code uses the existing ltc_evaluate_disk to implement the lighting calculations.
[1]: "Solid Angle Sampling of Disk and Cylinder Lights"
[2]: "Analytical solution for the solid angle subtended at any point by an ellipse via a point source radiation vector potential"
Reviewers: sergey, brecht, fclem
Differential Revision: https://developer.blender.org/D3171
2018-05-24 03:50:16 +02:00
|
|
|
if (ELEM(la->area_shape, LA_AREA_RECT, LA_AREA_ELLIPSE)) {
|
2017-03-08 20:00:09 +01:00
|
|
|
size[1] = la->area_sizey / la->area_size;
|
|
|
|
size_to_mat4(sizemat, size);
|
2017-04-03 19:01:10 +02:00
|
|
|
mul_m4_m4m4(shapemat, shapemat, sizemat);
|
2017-03-08 20:00:09 +01:00
|
|
|
}
|
|
|
|
|
Cycles/Eevee: Implement disk and ellipse shapes for area lamps
The implementation is pretty straightforward.
In Cycles, sampling the shapes is currently done w.r.t. area instead of solid angle.
There is a paper on solid angle sampling for disks [1], but the described algorithm is based on
simply sampling the enclosing square and rejecting samples outside of the disk, which is not exactly
great for Cycles' RNG (we'd need to setup a LCG for the repeated sampling) and for GPU divergence.
Even worse, the algorithm is only defined for disks. For ellipses, the basic idea still works, but a
way to analytically calculate the solid angle is required. This is technically possible [2], but the
calculation is extremely complex and still requires a lookup table for the Heuman Lambda function.
Therefore, I've decided to not implement that for now, we could still look into it later on.
In Eevee, the code uses the existing ltc_evaluate_disk to implement the lighting calculations.
[1]: "Solid Angle Sampling of Disk and Cylinder Lights"
[2]: "Analytical solution for the solid angle subtended at any point by an ellipse via a point source radiation vector potential"
Reviewers: sergey, brecht, fclem
Differential Revision: https://developer.blender.org/D3171
2018-05-24 03:50:16 +02:00
|
|
|
if (ELEM(la->area_shape, LA_AREA_DISK, LA_AREA_ELLIPSE)) {
|
|
|
|
DRW_shgroup_call_dynamic_add(stl->g_data->lamp_area_disk, color, &la->area_size, shapemat);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
DRW_shgroup_call_dynamic_add(stl->g_data->lamp_area_square, color, &la->area_size, shapemat);
|
|
|
|
}
|
2017-03-08 20:00:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Line and point going to the ground */
|
2017-04-22 15:53:11 +10:00
|
|
|
DRW_shgroup_call_dynamic_add(stl->g_data->lamp_groundline, ob->obmat[3]);
|
|
|
|
DRW_shgroup_call_dynamic_add(stl->g_data->lamp_groundpoint, ob->obmat[3]);
|
2017-02-17 17:29:43 +01:00
|
|
|
}
|
|
|
|
|
2017-11-22 10:52:39 -02:00
|
|
|
static void DRW_shgroup_camera(OBJECT_StorageList *stl, Object *ob, ViewLayer *view_layer)
|
2017-02-17 17:29:43 +01:00
|
|
|
{
|
2017-04-26 00:35:08 +10:00
|
|
|
const DRWContextState *draw_ctx = DRW_context_state_get();
|
|
|
|
View3D *v3d = draw_ctx->v3d;
|
|
|
|
Scene *scene = draw_ctx->scene;
|
2018-01-22 00:14:28 +01:00
|
|
|
RegionView3D *rv3d = draw_ctx->rv3d;
|
2017-03-08 20:00:09 +01:00
|
|
|
|
|
|
|
Camera *cam = ob->data;
|
2018-03-21 16:29:35 +01:00
|
|
|
const Object *camera_object = DEG_get_evaluated_object(draw_ctx->depsgraph, v3d->camera);
|
|
|
|
const bool is_active = (ob == camera_object);
|
2018-01-22 00:14:28 +01:00
|
|
|
const bool look_through = (is_active && (rv3d->persp == RV3D_CAMOB));
|
2017-03-08 20:00:09 +01:00
|
|
|
float *color;
|
2017-11-22 10:52:39 -02:00
|
|
|
DRW_object_wire_theme_get(ob, view_layer, &color);
|
2017-03-08 20:00:09 +01:00
|
|
|
|
|
|
|
float vec[4][3], asp[2], shift[2], scale[3], drawsize;
|
|
|
|
|
|
|
|
scale[0] = 1.0f / len_v3(ob->obmat[0]);
|
|
|
|
scale[1] = 1.0f / len_v3(ob->obmat[1]);
|
|
|
|
scale[2] = 1.0f / len_v3(ob->obmat[2]);
|
|
|
|
|
|
|
|
BKE_camera_view_frame_ex(scene, cam, cam->drawsize, false, scale,
|
|
|
|
asp, shift, &drawsize, vec);
|
|
|
|
|
2018-01-22 00:14:28 +01:00
|
|
|
/* Frame coords */
|
2017-03-08 20:00:09 +01:00
|
|
|
copy_v2_v2(cam->drwcorners[0], vec[0]);
|
|
|
|
copy_v2_v2(cam->drwcorners[1], vec[1]);
|
|
|
|
copy_v2_v2(cam->drwcorners[2], vec[2]);
|
|
|
|
copy_v2_v2(cam->drwcorners[3], vec[3]);
|
|
|
|
|
|
|
|
/* depth */
|
|
|
|
cam->drwdepth = vec[0][2];
|
|
|
|
|
|
|
|
/* tria */
|
|
|
|
cam->drwtria[0][0] = shift[0] + ((0.7f * drawsize) * scale[0]);
|
|
|
|
cam->drwtria[0][1] = shift[1] + ((drawsize * (asp[1] + 0.1f)) * scale[1]);
|
|
|
|
cam->drwtria[1][0] = shift[0];
|
|
|
|
cam->drwtria[1][1] = shift[1] + ((1.1f * drawsize * (asp[1] + 0.7f)) * scale[1]);
|
|
|
|
|
2018-01-22 00:14:28 +01:00
|
|
|
if (look_through) {
|
|
|
|
/* Only draw the frame. */
|
|
|
|
DRW_shgroup_call_dynamic_add(
|
|
|
|
stl->g_data->camera_frame, color, cam->drwcorners,
|
|
|
|
&cam->drwdepth, cam->drwtria, ob->obmat);
|
|
|
|
}
|
|
|
|
else {
|
2017-04-22 15:53:11 +10:00
|
|
|
DRW_shgroup_call_dynamic_add(
|
2018-01-22 00:14:28 +01:00
|
|
|
stl->g_data->camera, color, cam->drwcorners,
|
|
|
|
&cam->drwdepth, cam->drwtria, ob->obmat);
|
|
|
|
|
|
|
|
/* Active cam */
|
|
|
|
if (is_active) {
|
|
|
|
DRW_shgroup_call_dynamic_add(
|
|
|
|
stl->g_data->camera_tria, color,
|
|
|
|
cam->drwcorners, &cam->drwdepth, cam->drwtria, ob->obmat);
|
|
|
|
}
|
2017-03-08 20:00:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* draw the rest in normalize object space */
|
|
|
|
copy_m4_m4(cam->drwnormalmat, ob->obmat);
|
|
|
|
normalize_m4(cam->drwnormalmat);
|
|
|
|
|
|
|
|
if (cam->flag & CAM_SHOWLIMITS) {
|
|
|
|
static float col[3] = {0.5f, 0.5f, 0.25f}, col_hi[3] = {1.0f, 1.0f, 0.5f};
|
|
|
|
float sizemat[4][4], size[3] = {1.0f, 1.0f, 0.0f};
|
|
|
|
float focusdist = BKE_camera_object_dof_distance(ob);
|
|
|
|
|
|
|
|
copy_m4_m4(cam->drwfocusmat, cam->drwnormalmat);
|
|
|
|
translate_m4(cam->drwfocusmat, 0.0f, 0.0f, -focusdist);
|
|
|
|
size_to_mat4(sizemat, size);
|
|
|
|
mul_m4_m4m4(cam->drwfocusmat, cam->drwfocusmat, sizemat);
|
|
|
|
|
2017-04-22 15:53:11 +10:00
|
|
|
DRW_shgroup_call_dynamic_add(
|
2017-04-21 04:39:51 +10:00
|
|
|
stl->g_data->camera_focus, (is_active ? col_hi : col),
|
|
|
|
&cam->drawsize, cam->drwfocusmat);
|
2017-03-08 20:00:09 +01:00
|
|
|
|
2017-04-22 15:53:11 +10:00
|
|
|
DRW_shgroup_call_dynamic_add(
|
2017-04-21 04:39:51 +10:00
|
|
|
stl->g_data->camera_clip, color,
|
|
|
|
&cam->clipsta, &cam->clipend, cam->drwnormalmat);
|
2017-04-22 15:53:11 +10:00
|
|
|
DRW_shgroup_call_dynamic_add(
|
2017-04-21 04:39:51 +10:00
|
|
|
stl->g_data->camera_clip_points, (is_active ? col_hi : col),
|
|
|
|
&cam->clipsta, &cam->clipend, cam->drwnormalmat);
|
2017-03-08 20:00:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (cam->flag & CAM_SHOWMIST) {
|
|
|
|
World *world = scene->world;
|
|
|
|
|
|
|
|
if (world) {
|
|
|
|
static float col[3] = {0.5f, 0.5f, 0.5f}, col_hi[3] = {1.0f, 1.0f, 1.0f};
|
|
|
|
world->mistend = world->miststa + world->mistdist;
|
2017-04-22 15:53:11 +10:00
|
|
|
DRW_shgroup_call_dynamic_add(
|
2017-04-21 04:39:51 +10:00
|
|
|
stl->g_data->camera_mist, color,
|
|
|
|
&world->miststa, &world->mistend, cam->drwnormalmat);
|
2017-04-22 15:53:11 +10:00
|
|
|
DRW_shgroup_call_dynamic_add(
|
2017-04-21 04:39:51 +10:00
|
|
|
stl->g_data->camera_mist_points, (is_active ? col_hi : col),
|
|
|
|
&world->miststa, &world->mistend, cam->drwnormalmat);
|
2017-03-08 20:00:09 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-22 10:52:39 -02:00
|
|
|
static void DRW_shgroup_empty(OBJECT_StorageList *stl, OBJECT_PassList *psl, Object *ob, ViewLayer *view_layer)
|
2017-03-08 20:00:09 +01:00
|
|
|
{
|
|
|
|
float *color;
|
2017-11-22 10:52:39 -02:00
|
|
|
DRW_object_wire_theme_get(ob, view_layer, &color);
|
2017-03-08 20:00:09 +01:00
|
|
|
|
|
|
|
switch (ob->empty_drawtype) {
|
|
|
|
case OB_PLAINAXES:
|
2017-04-22 15:53:11 +10:00
|
|
|
DRW_shgroup_call_dynamic_add(stl->g_data->plain_axes, color, &ob->empty_drawsize, ob->obmat);
|
2017-03-08 20:00:09 +01:00
|
|
|
break;
|
|
|
|
case OB_SINGLE_ARROW:
|
2017-04-22 15:53:11 +10:00
|
|
|
DRW_shgroup_call_dynamic_add(stl->g_data->single_arrow, color, &ob->empty_drawsize, ob->obmat);
|
|
|
|
DRW_shgroup_call_dynamic_add(stl->g_data->single_arrow_line, color, &ob->empty_drawsize, ob->obmat);
|
2017-03-08 20:00:09 +01:00
|
|
|
break;
|
|
|
|
case OB_CUBE:
|
2017-04-22 15:53:11 +10:00
|
|
|
DRW_shgroup_call_dynamic_add(stl->g_data->cube, color, &ob->empty_drawsize, ob->obmat);
|
2017-03-08 20:00:09 +01:00
|
|
|
break;
|
|
|
|
case OB_CIRCLE:
|
2017-04-22 15:53:11 +10:00
|
|
|
DRW_shgroup_call_dynamic_add(stl->g_data->circle, color, &ob->empty_drawsize, ob->obmat);
|
2017-03-08 20:00:09 +01:00
|
|
|
break;
|
|
|
|
case OB_EMPTY_SPHERE:
|
2017-04-22 15:53:11 +10:00
|
|
|
DRW_shgroup_call_dynamic_add(stl->g_data->sphere, color, &ob->empty_drawsize, ob->obmat);
|
2017-03-08 20:00:09 +01:00
|
|
|
break;
|
|
|
|
case OB_EMPTY_CONE:
|
2017-04-22 15:53:11 +10:00
|
|
|
DRW_shgroup_call_dynamic_add(stl->g_data->cone, color, &ob->empty_drawsize, ob->obmat);
|
2017-03-08 20:00:09 +01:00
|
|
|
break;
|
|
|
|
case OB_ARROWS:
|
2017-04-22 15:53:11 +10:00
|
|
|
DRW_shgroup_call_dynamic_add(stl->g_data->arrows, color, &ob->empty_drawsize, ob->obmat);
|
|
|
|
DRW_shgroup_call_dynamic_add(stl->g_data->axis_names, color, &ob->empty_drawsize, ob->obmat);
|
2017-03-08 20:00:09 +01:00
|
|
|
break;
|
2017-05-20 22:57:47 +10:00
|
|
|
case OB_EMPTY_IMAGE:
|
|
|
|
DRW_shgroup_empty_image(stl, psl, ob, color);
|
|
|
|
break;
|
2017-03-08 20:00:09 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-22 10:52:39 -02:00
|
|
|
static void DRW_shgroup_forcefield(OBJECT_StorageList *stl, Object *ob, ViewLayer *view_layer)
|
2017-04-10 22:22:37 +02:00
|
|
|
{
|
2017-11-22 10:52:39 -02:00
|
|
|
int theme_id = DRW_object_wire_theme_get(ob, view_layer, NULL);
|
2017-04-10 22:22:37 +02:00
|
|
|
float *color = DRW_color_background_blend_get(theme_id);
|
|
|
|
PartDeflect *pd = ob->pd;
|
|
|
|
Curve *cu = (ob->type == OB_CURVE) ? ob->data : NULL;
|
|
|
|
|
|
|
|
/* TODO Move this to depsgraph */
|
|
|
|
float tmp[3];
|
|
|
|
copy_v3_fl(pd->drawvec1, ob->empty_drawsize);
|
|
|
|
|
|
|
|
switch (pd->forcefield) {
|
|
|
|
case PFIELD_WIND:
|
|
|
|
pd->drawvec1[2] = pd->f_strength;
|
|
|
|
break;
|
|
|
|
case PFIELD_VORTEX:
|
|
|
|
if (pd->f_strength < 0.0f) {
|
|
|
|
pd->drawvec1[1] = -pd->drawvec1[1];
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case PFIELD_GUIDE:
|
|
|
|
if (cu && (cu->flag & CU_PATH) && ob->curve_cache->path && ob->curve_cache->path->data) {
|
|
|
|
where_on_path(ob, 0.0f, pd->drawvec1, tmp, NULL, NULL, NULL);
|
|
|
|
where_on_path(ob, 1.0f, pd->drawvec2, tmp, NULL, NULL, NULL);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pd->falloff == PFIELD_FALL_TUBE) {
|
|
|
|
pd->drawvec_falloff_max[0] = pd->drawvec_falloff_max[1] = (pd->flag & PFIELD_USEMAXR) ? pd->maxrad : 1.0f;
|
|
|
|
pd->drawvec_falloff_max[2] = (pd->flag & PFIELD_USEMAX) ? pd->maxdist : 0.0f;
|
|
|
|
|
|
|
|
pd->drawvec_falloff_min[0] = pd->drawvec_falloff_min[1] = (pd->flag & PFIELD_USEMINR) ? pd->minrad : 1.0f;
|
|
|
|
pd->drawvec_falloff_min[2] = (pd->flag & PFIELD_USEMIN) ? pd->mindist : 0.0f;
|
|
|
|
}
|
|
|
|
else if (pd->falloff == PFIELD_FALL_CONE) {
|
|
|
|
float radius, distance;
|
|
|
|
|
|
|
|
radius = DEG2RADF((pd->flag & PFIELD_USEMAXR) ? pd->maxrad : 1.0f);
|
|
|
|
distance = (pd->flag & PFIELD_USEMAX) ? pd->maxdist : 0.0f;
|
|
|
|
pd->drawvec_falloff_max[0] = pd->drawvec_falloff_max[1] = distance * sinf(radius);
|
|
|
|
pd->drawvec_falloff_max[2] = distance * cosf(radius);
|
|
|
|
|
|
|
|
radius = DEG2RADF((pd->flag & PFIELD_USEMINR) ? pd->minrad : 1.0f);
|
|
|
|
distance = (pd->flag & PFIELD_USEMIN) ? pd->mindist : 0.0f;
|
|
|
|
|
|
|
|
pd->drawvec_falloff_min[0] = pd->drawvec_falloff_min[1] = distance * sinf(radius);
|
|
|
|
pd->drawvec_falloff_min[2] = distance * cosf(radius);
|
|
|
|
}
|
|
|
|
/* End of things that should go to depthgraph */
|
|
|
|
|
|
|
|
switch (pd->forcefield) {
|
|
|
|
case PFIELD_WIND:
|
2017-04-22 15:53:11 +10:00
|
|
|
DRW_shgroup_call_dynamic_add(stl->g_data->field_wind, color, &pd->drawvec1, ob->obmat);
|
2017-04-10 22:22:37 +02:00
|
|
|
break;
|
|
|
|
case PFIELD_FORCE:
|
2017-04-22 15:53:11 +10:00
|
|
|
DRW_shgroup_call_dynamic_add(stl->g_data->field_force, color, &pd->drawvec1, ob->obmat);
|
2017-04-10 22:22:37 +02:00
|
|
|
break;
|
|
|
|
case PFIELD_VORTEX:
|
2017-04-22 15:53:11 +10:00
|
|
|
DRW_shgroup_call_dynamic_add(stl->g_data->field_vortex, color, &pd->drawvec1, ob->obmat);
|
2017-04-10 22:22:37 +02:00
|
|
|
break;
|
|
|
|
case PFIELD_GUIDE:
|
|
|
|
if (cu && (cu->flag & CU_PATH) && ob->curve_cache->path && ob->curve_cache->path->data) {
|
2017-04-22 15:53:11 +10:00
|
|
|
DRW_shgroup_call_dynamic_add(stl->g_data->field_curve_sta, color, &pd->f_strength, ob->obmat);
|
|
|
|
DRW_shgroup_call_dynamic_add(stl->g_data->field_curve_end, color, &pd->f_strength, ob->obmat);
|
2017-04-10 22:22:37 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pd->falloff == PFIELD_FALL_SPHERE) {
|
|
|
|
/* as last, guide curve alters it */
|
|
|
|
if ((pd->flag & PFIELD_USEMAX) != 0) {
|
2017-04-22 15:53:11 +10:00
|
|
|
DRW_shgroup_call_dynamic_add(stl->g_data->field_curve_end, color, &pd->maxdist, ob->obmat);
|
2017-04-10 22:22:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if ((pd->flag & PFIELD_USEMIN) != 0) {
|
2017-04-22 15:53:11 +10:00
|
|
|
DRW_shgroup_call_dynamic_add(stl->g_data->field_curve_end, color, &pd->mindist, ob->obmat);
|
2017-04-10 22:22:37 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (pd->falloff == PFIELD_FALL_TUBE) {
|
|
|
|
if (pd->flag & (PFIELD_USEMAX | PFIELD_USEMAXR)) {
|
2017-04-22 15:53:11 +10:00
|
|
|
DRW_shgroup_call_dynamic_add(stl->g_data->field_tube_limit, color, &pd->drawvec_falloff_max, ob->obmat);
|
2017-04-10 22:22:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (pd->flag & (PFIELD_USEMIN | PFIELD_USEMINR)) {
|
2017-04-22 15:53:11 +10:00
|
|
|
DRW_shgroup_call_dynamic_add(stl->g_data->field_tube_limit, color, &pd->drawvec_falloff_min, ob->obmat);
|
2017-04-10 22:22:37 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (pd->falloff == PFIELD_FALL_CONE) {
|
|
|
|
if (pd->flag & (PFIELD_USEMAX | PFIELD_USEMAXR)) {
|
2017-04-22 15:53:11 +10:00
|
|
|
DRW_shgroup_call_dynamic_add(stl->g_data->field_cone_limit, color, &pd->drawvec_falloff_max, ob->obmat);
|
2017-04-10 22:22:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (pd->flag & (PFIELD_USEMIN | PFIELD_USEMINR)) {
|
2017-04-22 15:53:11 +10:00
|
|
|
DRW_shgroup_call_dynamic_add(stl->g_data->field_cone_limit, color, &pd->drawvec_falloff_min, ob->obmat);
|
2017-04-10 22:22:37 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-22 10:52:39 -02:00
|
|
|
static void DRW_shgroup_speaker(OBJECT_StorageList *stl, Object *ob, ViewLayer *view_layer)
|
2017-03-08 20:00:09 +01:00
|
|
|
{
|
|
|
|
float *color;
|
|
|
|
static float one = 1.0f;
|
2017-11-22 10:52:39 -02:00
|
|
|
DRW_object_wire_theme_get(ob, view_layer, &color);
|
2017-03-08 20:00:09 +01:00
|
|
|
|
2017-04-22 15:53:11 +10:00
|
|
|
DRW_shgroup_call_dynamic_add(stl->g_data->speaker, color, &one, ob->obmat);
|
2017-03-08 20:00:09 +01:00
|
|
|
}
|
|
|
|
|
2017-09-30 19:34:23 +02:00
|
|
|
typedef struct OBJECT_LightProbeEngineData {
|
2018-01-30 13:36:41 +11:00
|
|
|
ObjectEngineData engine_data;
|
|
|
|
|
2017-09-30 19:34:23 +02:00
|
|
|
float prb_mats[6][4][4];
|
|
|
|
float probe_cube_mat[4][4];
|
|
|
|
float draw_size;
|
|
|
|
float increment_x[3];
|
|
|
|
float increment_y[3];
|
|
|
|
float increment_z[3];
|
|
|
|
float corner[3];
|
2018-05-11 07:48:52 +02:00
|
|
|
uint cell_count;
|
2017-09-30 19:34:23 +02:00
|
|
|
} OBJECT_LightProbeEngineData;
|
|
|
|
|
2017-11-22 10:52:39 -02:00
|
|
|
static void DRW_shgroup_lightprobe(OBJECT_StorageList *stl, OBJECT_PassList *psl, Object *ob, ViewLayer *view_layer)
|
2017-06-07 16:00:10 +02:00
|
|
|
{
|
|
|
|
float *color;
|
2017-06-17 01:55:49 +02:00
|
|
|
static float one = 1.0f;
|
2017-06-12 20:59:54 +10:00
|
|
|
LightProbe *prb = (LightProbe *)ob->data;
|
2017-09-30 19:34:23 +02:00
|
|
|
bool do_outlines = ((ob->base_flag & BASE_SELECTED) != 0);
|
2018-04-17 13:01:01 +02:00
|
|
|
int theme_id = DRW_object_wire_theme_get(ob, view_layer, &color);
|
2017-06-07 16:00:10 +02:00
|
|
|
|
2018-01-29 16:28:24 +01:00
|
|
|
OBJECT_LightProbeEngineData *prb_data =
|
|
|
|
(OBJECT_LightProbeEngineData *)DRW_object_engine_data_ensure(
|
|
|
|
ob,
|
|
|
|
&draw_engine_object_type,
|
|
|
|
sizeof(OBJECT_LightProbeEngineData),
|
|
|
|
NULL,
|
|
|
|
NULL);
|
2017-09-30 19:34:23 +02:00
|
|
|
|
|
|
|
if ((DRW_state_is_select() || do_outlines) && ((prb->flag & LIGHTPROBE_FLAG_SHOW_DATA) != 0)) {
|
2018-04-17 13:01:01 +02:00
|
|
|
int *call_id = shgroup_theme_id_to_probe_outline_counter(stl, theme_id);
|
2017-09-30 19:34:23 +02:00
|
|
|
|
|
|
|
if (prb->type == LIGHTPROBE_TYPE_GRID) {
|
|
|
|
/* Update transforms */
|
|
|
|
float cell_dim[3], half_cell_dim[3];
|
|
|
|
cell_dim[0] = 2.0f / (float)(prb->grid_resolution_x);
|
|
|
|
cell_dim[1] = 2.0f / (float)(prb->grid_resolution_y);
|
|
|
|
cell_dim[2] = 2.0f / (float)(prb->grid_resolution_z);
|
|
|
|
|
|
|
|
mul_v3_v3fl(half_cell_dim, cell_dim, 0.5f);
|
|
|
|
|
|
|
|
/* First cell. */
|
|
|
|
copy_v3_fl(prb_data->corner, -1.0f);
|
|
|
|
add_v3_v3(prb_data->corner, half_cell_dim);
|
|
|
|
mul_m4_v3(ob->obmat, prb_data->corner);
|
|
|
|
|
|
|
|
/* Opposite neighbor cell. */
|
|
|
|
copy_v3_fl3(prb_data->increment_x, cell_dim[0], 0.0f, 0.0f);
|
|
|
|
add_v3_v3(prb_data->increment_x, half_cell_dim);
|
|
|
|
add_v3_fl(prb_data->increment_x, -1.0f);
|
|
|
|
mul_m4_v3(ob->obmat, prb_data->increment_x);
|
|
|
|
sub_v3_v3(prb_data->increment_x, prb_data->corner);
|
|
|
|
|
|
|
|
copy_v3_fl3(prb_data->increment_y, 0.0f, cell_dim[1], 0.0f);
|
|
|
|
add_v3_v3(prb_data->increment_y, half_cell_dim);
|
|
|
|
add_v3_fl(prb_data->increment_y, -1.0f);
|
|
|
|
mul_m4_v3(ob->obmat, prb_data->increment_y);
|
|
|
|
sub_v3_v3(prb_data->increment_y, prb_data->corner);
|
|
|
|
|
|
|
|
copy_v3_fl3(prb_data->increment_z, 0.0f, 0.0f, cell_dim[2]);
|
|
|
|
add_v3_v3(prb_data->increment_z, half_cell_dim);
|
|
|
|
add_v3_fl(prb_data->increment_z, -1.0f);
|
|
|
|
mul_m4_v3(ob->obmat, prb_data->increment_z);
|
|
|
|
sub_v3_v3(prb_data->increment_z, prb_data->corner);
|
|
|
|
|
2018-03-01 19:27:38 +01:00
|
|
|
prb_data->cell_count = prb->grid_resolution_x * prb->grid_resolution_y * prb->grid_resolution_z;
|
|
|
|
DRWShadingGroup *grp = DRW_shgroup_create(e_data.lightprobe_grid_sh, psl->lightprobes);
|
2018-04-17 13:01:01 +02:00
|
|
|
DRW_shgroup_uniform_int_copy(grp, "call_id", *call_id);
|
|
|
|
DRW_shgroup_uniform_int(grp, "baseId", call_id, 1); /* that's correct */
|
2017-09-30 19:34:23 +02:00
|
|
|
DRW_shgroup_uniform_vec3(grp, "corner", prb_data->corner, 1);
|
|
|
|
DRW_shgroup_uniform_vec3(grp, "increment_x", prb_data->increment_x, 1);
|
|
|
|
DRW_shgroup_uniform_vec3(grp, "increment_y", prb_data->increment_y, 1);
|
|
|
|
DRW_shgroup_uniform_vec3(grp, "increment_z", prb_data->increment_z, 1);
|
|
|
|
DRW_shgroup_uniform_ivec3(grp, "grid_resolution", &prb->grid_resolution_x, 1);
|
|
|
|
DRW_shgroup_uniform_float(grp, "sphere_size", &prb->data_draw_size, 1);
|
2018-03-01 19:27:38 +01:00
|
|
|
DRW_shgroup_call_instances_add(grp, DRW_cache_sphere_get(), NULL, &prb_data->cell_count);
|
2017-09-30 19:34:23 +02:00
|
|
|
}
|
|
|
|
else if (prb->type == LIGHTPROBE_TYPE_CUBE) {
|
|
|
|
prb_data->draw_size = prb->data_draw_size * 0.1f;
|
|
|
|
unit_m4(prb_data->probe_cube_mat);
|
|
|
|
copy_v3_v3(prb_data->probe_cube_mat[3], ob->obmat[3]);
|
2018-04-17 13:01:01 +02:00
|
|
|
|
|
|
|
DRWShadingGroup *grp = shgroup_theme_id_to_probe_cube_outline_shgrp(stl, theme_id);
|
|
|
|
DRW_shgroup_call_dynamic_add(grp, call_id, &prb_data->draw_size, prb_data->probe_cube_mat);
|
2017-09-30 19:34:23 +02:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
prb_data->draw_size = 1.0f;
|
2018-04-17 13:01:01 +02:00
|
|
|
|
|
|
|
DRWShadingGroup *grp = shgroup_theme_id_to_probe_planar_outline_shgrp(stl, theme_id);
|
|
|
|
DRW_shgroup_call_dynamic_add(grp, call_id, &prb_data->draw_size, ob->obmat);
|
2017-09-30 19:34:23 +02:00
|
|
|
}
|
2018-04-17 13:01:01 +02:00
|
|
|
|
|
|
|
*call_id += 1;
|
2017-09-30 19:34:23 +02:00
|
|
|
}
|
|
|
|
|
2017-06-27 14:59:53 +02:00
|
|
|
switch (prb->type) {
|
|
|
|
case LIGHTPROBE_TYPE_PLANAR:
|
|
|
|
DRW_shgroup_call_dynamic_add(stl->g_data->probe_planar, ob->obmat[3], color);
|
|
|
|
break;
|
|
|
|
case LIGHTPROBE_TYPE_GRID:
|
|
|
|
DRW_shgroup_call_dynamic_add(stl->g_data->probe_grid, ob->obmat[3], color);
|
|
|
|
break;
|
|
|
|
case LIGHTPROBE_TYPE_CUBE:
|
|
|
|
default:
|
|
|
|
DRW_shgroup_call_dynamic_add(stl->g_data->probe_cube, ob->obmat[3], color);
|
|
|
|
break;
|
|
|
|
}
|
2017-06-09 01:14:39 +02:00
|
|
|
|
2017-09-30 19:34:23 +02:00
|
|
|
|
2017-06-17 01:55:49 +02:00
|
|
|
|
|
|
|
if (prb->type == LIGHTPROBE_TYPE_PLANAR) {
|
|
|
|
float (*mat)[4];
|
2017-09-30 19:34:23 +02:00
|
|
|
mat = (float (*)[4])(prb_data->prb_mats[0]);
|
2017-06-17 01:55:49 +02:00
|
|
|
copy_m4_m4(mat, ob->obmat);
|
|
|
|
normalize_m4(mat);
|
|
|
|
|
|
|
|
DRW_shgroup_call_dynamic_add(stl->g_data->single_arrow, color, &ob->empty_drawsize, mat);
|
|
|
|
DRW_shgroup_call_dynamic_add(stl->g_data->single_arrow_line, color, &ob->empty_drawsize, mat);
|
|
|
|
|
2017-09-30 19:34:23 +02:00
|
|
|
mat = (float (*)[4])(prb_data->prb_mats[1]);
|
2017-06-17 01:55:49 +02:00
|
|
|
copy_m4_m4(mat, ob->obmat);
|
|
|
|
zero_v3(mat[2]);
|
|
|
|
|
|
|
|
DRW_shgroup_call_dynamic_add(stl->g_data->cube, color, &one, mat);
|
|
|
|
}
|
|
|
|
|
2017-06-12 20:59:54 +10:00
|
|
|
if ((prb->flag & LIGHTPROBE_FLAG_SHOW_INFLUENCE) != 0) {
|
2017-06-15 00:23:37 +02:00
|
|
|
|
|
|
|
prb->distfalloff = (1.0f - prb->falloff) * prb->distinf;
|
|
|
|
prb->distgridinf = prb->distinf;
|
|
|
|
|
2017-06-14 13:45:54 +02:00
|
|
|
if (prb->type == LIGHTPROBE_TYPE_GRID) {
|
2017-06-15 00:23:37 +02:00
|
|
|
prb->distfalloff += 1.0f;
|
|
|
|
prb->distgridinf += 1.0f;
|
2017-06-14 13:45:54 +02:00
|
|
|
}
|
2017-06-15 00:23:37 +02:00
|
|
|
|
|
|
|
if (prb->type == LIGHTPROBE_TYPE_GRID ||
|
2017-10-07 15:57:14 +11:00
|
|
|
prb->attenuation_type == LIGHTPROBE_SHAPE_BOX)
|
2017-06-15 00:23:37 +02:00
|
|
|
{
|
|
|
|
DRW_shgroup_call_dynamic_add(stl->g_data->cube, color, &prb->distgridinf, ob->obmat);
|
2017-06-09 23:21:55 +02:00
|
|
|
DRW_shgroup_call_dynamic_add(stl->g_data->cube, color, &prb->distfalloff, ob->obmat);
|
|
|
|
}
|
2017-06-17 01:55:49 +02:00
|
|
|
else if (prb->type == LIGHTPROBE_TYPE_PLANAR) {
|
|
|
|
float (*rangemat)[4];
|
2017-09-30 19:34:23 +02:00
|
|
|
rangemat = (float (*)[4])(prb_data->prb_mats[2]);
|
2017-06-17 01:55:49 +02:00
|
|
|
copy_m4_m4(rangemat, ob->obmat);
|
|
|
|
normalize_v3(rangemat[2]);
|
|
|
|
mul_v3_fl(rangemat[2], prb->distinf);
|
|
|
|
|
|
|
|
DRW_shgroup_call_dynamic_add(stl->g_data->cube, color, &one, rangemat);
|
|
|
|
|
2017-09-30 19:34:23 +02:00
|
|
|
rangemat = (float (*)[4])(prb_data->prb_mats[3]);
|
2017-06-17 01:55:49 +02:00
|
|
|
copy_m4_m4(rangemat, ob->obmat);
|
|
|
|
normalize_v3(rangemat[2]);
|
|
|
|
mul_v3_fl(rangemat[2], prb->distfalloff);
|
|
|
|
|
|
|
|
DRW_shgroup_call_dynamic_add(stl->g_data->cube, color, &one, rangemat);
|
|
|
|
}
|
2017-06-09 23:21:55 +02:00
|
|
|
else {
|
2017-06-15 00:23:37 +02:00
|
|
|
DRW_shgroup_call_dynamic_add(stl->g_data->sphere, color, &prb->distgridinf, ob->obmat);
|
2017-06-09 23:21:55 +02:00
|
|
|
DRW_shgroup_call_dynamic_add(stl->g_data->sphere, color, &prb->distfalloff, ob->obmat);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-12 20:59:54 +10:00
|
|
|
if ((prb->flag & LIGHTPROBE_FLAG_SHOW_PARALLAX) != 0) {
|
2017-06-17 01:55:49 +02:00
|
|
|
if (prb->type != LIGHTPROBE_TYPE_PLANAR) {
|
|
|
|
float (*obmat)[4], *dist;
|
2017-06-10 00:36:33 +02:00
|
|
|
|
2017-06-17 01:55:49 +02:00
|
|
|
if ((prb->flag & LIGHTPROBE_FLAG_CUSTOM_PARALLAX) != 0) {
|
|
|
|
dist = &prb->distpar;
|
|
|
|
/* TODO object parallax */
|
|
|
|
obmat = ob->obmat;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
dist = &prb->distinf;
|
|
|
|
obmat = ob->obmat;
|
|
|
|
}
|
2017-06-09 23:21:55 +02:00
|
|
|
|
2017-06-17 01:55:49 +02:00
|
|
|
if (prb->parallax_type == LIGHTPROBE_SHAPE_BOX) {
|
2017-10-03 16:24:28 +02:00
|
|
|
DRW_shgroup_call_dynamic_add(stl->g_data->cube, color, dist, obmat);
|
2017-06-17 01:55:49 +02:00
|
|
|
}
|
|
|
|
else {
|
2017-10-03 16:24:28 +02:00
|
|
|
DRW_shgroup_call_dynamic_add(stl->g_data->sphere, color, dist, obmat);
|
2017-06-17 01:55:49 +02:00
|
|
|
}
|
2017-06-09 23:21:55 +02:00
|
|
|
}
|
|
|
|
}
|
2017-06-09 01:14:39 +02:00
|
|
|
|
2017-06-12 20:59:54 +10:00
|
|
|
if ((prb->flag & LIGHTPROBE_FLAG_SHOW_CLIP_DIST) != 0) {
|
2017-06-17 01:55:49 +02:00
|
|
|
if (prb->type != LIGHTPROBE_TYPE_PLANAR) {
|
|
|
|
static const float cubefacemat[6][4][4] = {
|
|
|
|
{{0.0, 0.0, -1.0, 0.0}, {0.0, -1.0, 0.0, 0.0}, {-1.0, 0.0, 0.0, 0.0}, {0.0, 0.0, 0.0, 1.0}},
|
|
|
|
{{0.0, 0.0, 1.0, 0.0}, {0.0, -1.0, 0.0, 0.0}, {1.0, 0.0, 0.0, 0.0}, {0.0, 0.0, 0.0, 1.0}},
|
|
|
|
{{1.0, 0.0, 0.0, 0.0}, {0.0, 0.0, -1.0, 0.0}, {0.0, 1.0, 0.0, 0.0}, {0.0, 0.0, 0.0, 1.0}},
|
|
|
|
{{1.0, 0.0, 0.0, 0.0}, {0.0, 0.0, 1.0, 0.0}, {0.0, -1.0, 0.0, 0.0}, {0.0, 0.0, 0.0, 1.0}},
|
|
|
|
{{1.0, 0.0, 0.0, 0.0}, {0.0, -1.0, 0.0, 0.0}, {0.0, 0.0, -1.0, 0.0}, {0.0, 0.0, 0.0, 1.0}},
|
|
|
|
{{-1.0, 0.0, 0.0, 0.0}, {0.0, -1.0, 0.0, 0.0}, {0.0, 0.0, 1.0, 0.0}, {0.0, 0.0, 0.0, 1.0}},
|
|
|
|
};
|
2017-06-14 19:35:31 +02:00
|
|
|
|
2017-06-17 01:55:49 +02:00
|
|
|
for (int i = 0; i < 6; ++i) {
|
|
|
|
float (*clipmat)[4];
|
2017-09-30 19:34:23 +02:00
|
|
|
clipmat = (float (*)[4])(prb_data->prb_mats[i]);
|
2017-06-14 19:35:31 +02:00
|
|
|
|
2017-06-17 01:55:49 +02:00
|
|
|
normalize_m4_m4(clipmat, ob->obmat);
|
|
|
|
mul_m4_m4m4(clipmat, clipmat, cubefacemat[i]);
|
2017-06-10 00:36:33 +02:00
|
|
|
|
2017-06-17 01:55:49 +02:00
|
|
|
DRW_shgroup_call_dynamic_add(stl->g_data->lamp_buflimit, color, &prb->clipsta, &prb->clipend, clipmat);
|
|
|
|
DRW_shgroup_call_dynamic_add(stl->g_data->lamp_buflimit_points, color, &prb->clipsta, &prb->clipend, clipmat);
|
|
|
|
}
|
2017-06-10 00:36:33 +02:00
|
|
|
}
|
|
|
|
}
|
2017-06-09 01:14:39 +02:00
|
|
|
|
|
|
|
/* Line and point going to the ground */
|
2017-06-17 01:55:49 +02:00
|
|
|
if (prb->type == LIGHTPROBE_TYPE_CUBE) {
|
|
|
|
DRW_shgroup_call_dynamic_add(stl->g_data->lamp_groundline, ob->obmat[3]);
|
|
|
|
DRW_shgroup_call_dynamic_add(stl->g_data->lamp_groundpoint, ob->obmat[3]);
|
|
|
|
}
|
2017-06-07 16:00:10 +02:00
|
|
|
}
|
|
|
|
|
2017-03-26 20:13:34 +02:00
|
|
|
static void DRW_shgroup_relationship_lines(OBJECT_StorageList *stl, Object *ob)
|
2017-03-08 20:00:09 +01:00
|
|
|
{
|
2017-12-21 13:29:14 -02:00
|
|
|
if (ob->parent && DRW_check_object_visible_within_active_context(ob->parent)) {
|
2017-04-22 15:53:11 +10:00
|
|
|
DRW_shgroup_call_dynamic_add(stl->g_data->relationship_lines, ob->parent->obmat[3]);
|
2018-05-07 00:22:03 +02:00
|
|
|
DRW_shgroup_call_dynamic_add(stl->g_data->relationship_lines, ob->obmat[3]);
|
2017-03-08 20:00:09 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-22 10:52:39 -02:00
|
|
|
static void DRW_shgroup_object_center(OBJECT_StorageList *stl, Object *ob, ViewLayer *view_layer, View3D *v3d)
|
2017-03-08 20:00:09 +01:00
|
|
|
{
|
2017-11-06 18:02:46 +01:00
|
|
|
const bool is_library = ob->id.us > 1 || ID_IS_LINKED(ob);
|
2017-04-11 14:05:39 +10:00
|
|
|
DRWShadingGroup *shgroup;
|
|
|
|
|
2017-11-22 10:52:39 -02:00
|
|
|
if (ob == OBACT(view_layer)) {
|
2017-06-06 11:45:29 +02:00
|
|
|
shgroup = stl->g_data->center_active;
|
|
|
|
}
|
|
|
|
else if (ob->base_flag & BASE_SELECTED) {
|
2017-04-11 14:05:39 +10:00
|
|
|
if (is_library) {
|
|
|
|
shgroup = stl->g_data->center_selected_lib;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
shgroup = stl->g_data->center_selected;
|
|
|
|
}
|
2017-03-08 20:00:09 +01:00
|
|
|
}
|
2017-06-06 11:45:29 +02:00
|
|
|
else if (v3d->flag & V3D_DRAW_CENTERS) {
|
2017-04-11 14:05:39 +10:00
|
|
|
if (is_library) {
|
|
|
|
shgroup = stl->g_data->center_deselected_lib;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
shgroup = stl->g_data->center_deselected;
|
|
|
|
}
|
2017-03-08 20:00:09 +01:00
|
|
|
}
|
2017-06-06 11:45:29 +02:00
|
|
|
else {
|
|
|
|
return;
|
|
|
|
}
|
2017-04-11 14:05:39 +10:00
|
|
|
|
2017-04-22 15:53:11 +10:00
|
|
|
DRW_shgroup_call_dynamic_add(shgroup, ob->obmat[3]);
|
2017-03-08 20:00:09 +01:00
|
|
|
}
|
|
|
|
|
2017-05-29 15:26:52 +02:00
|
|
|
static void OBJECT_cache_populate_particles(Object *ob,
|
|
|
|
OBJECT_PassList *psl)
|
|
|
|
{
|
|
|
|
for (ParticleSystem *psys = ob->particlesystem.first; psys; psys = psys->next) {
|
2018-05-15 11:35:39 +02:00
|
|
|
if (!psys_check_enabled(ob, psys, false)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (!DRW_check_psys_visible_within_active_context(ob, psys)) {
|
|
|
|
return;
|
|
|
|
}
|
2017-05-29 15:26:52 +02:00
|
|
|
|
2018-05-15 11:35:39 +02:00
|
|
|
ParticleSettings *part = psys->part;
|
|
|
|
int draw_as = (part->draw_as == PART_DRAW_REND) ? part->ren_as : part->draw_as;
|
2017-05-29 15:26:52 +02:00
|
|
|
|
2018-05-15 11:35:39 +02:00
|
|
|
if (draw_as == PART_DRAW_PATH && !psys->pathcache && !psys->childcache) {
|
|
|
|
draw_as = PART_DRAW_DOT;
|
|
|
|
}
|
|
|
|
|
|
|
|
static float mat[4][4];
|
|
|
|
unit_m4(mat);
|
|
|
|
|
|
|
|
if (draw_as != PART_DRAW_PATH) {
|
|
|
|
struct Gwn_Batch *geom = DRW_cache_particles_get_dots(ob, psys);
|
|
|
|
DRWShadingGroup *shgrp = NULL;
|
|
|
|
static int screen_space[2] = {0, 1};
|
|
|
|
static float def_prim_col[3] = {0.5f, 0.5f, 0.5f};
|
|
|
|
static float def_sec_col[3] = {1.0f, 1.0f, 1.0f};
|
|
|
|
|
|
|
|
/* Dummy particle format for instancing to work. */
|
|
|
|
DRW_shgroup_instance_format(e_data.particle_format, {{"dummy", DRW_ATTRIB_FLOAT, 1}});
|
|
|
|
|
|
|
|
Material *ma = give_current_material(ob, part->omat);
|
|
|
|
|
|
|
|
switch (draw_as) {
|
|
|
|
case PART_DRAW_DOT:
|
|
|
|
shgrp = DRW_shgroup_create(e_data.part_dot_sh, psl->particle);
|
|
|
|
DRW_shgroup_uniform_vec3(shgrp, "color", ma ? &ma->r : def_prim_col, 1);
|
|
|
|
DRW_shgroup_uniform_vec3(shgrp, "outlineColor", ma ? &ma->specr : def_sec_col, 1);
|
|
|
|
DRW_shgroup_uniform_float(shgrp, "pixel_size", DRW_viewport_pixelsize_get(), 1);
|
|
|
|
DRW_shgroup_uniform_float(shgrp, "size", &part->draw_size, 1);
|
|
|
|
DRW_shgroup_uniform_texture(shgrp, "ramp", globals_ramp);
|
|
|
|
DRW_shgroup_call_add(shgrp, geom, mat);
|
|
|
|
break;
|
|
|
|
case PART_DRAW_CROSS:
|
|
|
|
shgrp = DRW_shgroup_instance_create(
|
|
|
|
e_data.part_prim_sh, psl->particle, DRW_cache_particles_get_prim(PART_DRAW_CROSS),
|
|
|
|
e_data.particle_format);
|
|
|
|
DRW_shgroup_uniform_texture(shgrp, "ramp", globals_ramp);
|
|
|
|
DRW_shgroup_uniform_vec3(shgrp, "color", ma ? &ma->r : def_prim_col, 1);
|
|
|
|
DRW_shgroup_uniform_int(shgrp, "screen_space", &screen_space[0], 1);
|
|
|
|
break;
|
|
|
|
case PART_DRAW_CIRC:
|
|
|
|
shgrp = DRW_shgroup_instance_create(
|
|
|
|
e_data.part_prim_sh, psl->particle, DRW_cache_particles_get_prim(PART_DRAW_CIRC),
|
|
|
|
e_data.particle_format);
|
|
|
|
DRW_shgroup_uniform_texture(shgrp, "ramp", globals_ramp);
|
|
|
|
DRW_shgroup_uniform_vec3(shgrp, "color", ma ? &ma->r : def_prim_col, 1);
|
|
|
|
DRW_shgroup_uniform_int(shgrp, "screen_space", &screen_space[1], 1);
|
|
|
|
break;
|
|
|
|
case PART_DRAW_AXIS:
|
|
|
|
shgrp = DRW_shgroup_instance_create(
|
|
|
|
e_data.part_axis_sh, psl->particle, DRW_cache_particles_get_prim(PART_DRAW_AXIS),
|
|
|
|
e_data.particle_format);
|
|
|
|
DRW_shgroup_uniform_int(shgrp, "screen_space", &screen_space[0], 1);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2017-05-29 15:26:52 +02:00
|
|
|
|
2018-05-15 11:35:39 +02:00
|
|
|
if (shgrp) {
|
|
|
|
if (draw_as != PART_DRAW_DOT) {
|
|
|
|
DRW_shgroup_uniform_float(shgrp, "draw_size", &part->draw_size, 1);
|
|
|
|
DRW_shgroup_instance_batch(shgrp, geom);
|
2017-05-29 15:26:52 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-26 19:10:53 +02:00
|
|
|
static void OBJECT_cache_populate(void *vedata, Object *ob)
|
2017-03-08 20:00:09 +01:00
|
|
|
{
|
2017-04-27 16:57:11 +10:00
|
|
|
OBJECT_PassList *psl = ((OBJECT_Data *)vedata)->psl;
|
2017-03-26 20:13:34 +02:00
|
|
|
OBJECT_StorageList *stl = ((OBJECT_Data *)vedata)->stl;
|
2017-04-26 00:35:08 +10:00
|
|
|
const DRWContextState *draw_ctx = DRW_context_state_get();
|
2017-11-22 10:52:39 -02:00
|
|
|
ViewLayer *view_layer = draw_ctx->view_layer;
|
2017-06-06 11:45:29 +02:00
|
|
|
View3D *v3d = draw_ctx->v3d;
|
2017-04-28 04:33:58 +10:00
|
|
|
int theme_id = TH_UNDEFINED;
|
2017-03-08 20:00:09 +01:00
|
|
|
|
2017-12-21 13:29:14 -02:00
|
|
|
/* Handle particles first in case the emitter itself shouldn't be rendered. */
|
|
|
|
if (ob->type == OB_MESH) {
|
|
|
|
OBJECT_cache_populate_particles(ob, psl);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (DRW_check_object_visible_within_active_context(ob) == false) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-03-18 01:55:41 +01:00
|
|
|
bool do_outlines = ((ob->base_flag & BASE_SELECTED) != 0);
|
2017-02-17 17:29:43 +01:00
|
|
|
|
2017-04-21 02:18:14 +10:00
|
|
|
if (do_outlines) {
|
2018-02-13 18:15:47 +11:00
|
|
|
if ((ob != draw_ctx->object_edit) && !((ob == draw_ctx->obact) && (draw_ctx->object_mode & OB_MODE_ALL_PAINT))) {
|
2017-06-19 20:18:04 +10:00
|
|
|
struct Gwn_Batch *geom = DRW_cache_object_surface_get(ob);
|
2017-04-21 02:18:14 +10:00
|
|
|
if (geom) {
|
2017-11-22 10:52:39 -02:00
|
|
|
theme_id = DRW_object_wire_theme_get(ob, view_layer, NULL);
|
2017-04-21 04:29:33 +10:00
|
|
|
DRWShadingGroup *shgroup = shgroup_theme_id_to_outline_or(stl, theme_id, NULL);
|
2017-04-21 02:18:14 +10:00
|
|
|
if (shgroup != NULL) {
|
2018-03-01 15:30:48 +01:00
|
|
|
DRW_shgroup_call_object_add(shgroup, geom, ob);
|
2017-03-08 20:00:09 +01:00
|
|
|
}
|
|
|
|
}
|
2017-04-13 21:44:24 +10:00
|
|
|
}
|
2017-04-21 02:18:14 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
switch (ob->type) {
|
|
|
|
case OB_MESH:
|
2017-06-01 02:26:24 +10:00
|
|
|
{
|
2018-02-24 04:45:13 +01:00
|
|
|
if (ob != draw_ctx->object_edit) {
|
|
|
|
Mesh *me = ob->data;
|
|
|
|
if (me->totpoly == 0) {
|
|
|
|
if (me->totedge == 0) {
|
|
|
|
struct Gwn_Batch *geom = DRW_cache_mesh_verts_get(ob);
|
|
|
|
if (geom) {
|
|
|
|
if (theme_id == TH_UNDEFINED) {
|
|
|
|
theme_id = DRW_object_wire_theme_get(ob, view_layer, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
DRWShadingGroup *shgroup = shgroup_theme_id_to_point_or(stl, theme_id, stl->g_data->points);
|
2018-03-01 15:30:48 +01:00
|
|
|
DRW_shgroup_call_object_add(shgroup, geom, ob);
|
2018-02-24 04:45:13 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
struct Gwn_Batch *geom = DRW_cache_mesh_edges_get(ob);
|
|
|
|
if (geom) {
|
|
|
|
if (theme_id == TH_UNDEFINED) {
|
|
|
|
theme_id = DRW_object_wire_theme_get(ob, view_layer, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
DRWShadingGroup *shgroup = shgroup_theme_id_to_wire_or(stl, theme_id, stl->g_data->wire);
|
2018-03-01 15:30:48 +01:00
|
|
|
DRW_shgroup_call_object_add(shgroup, geom, ob);
|
2017-06-01 02:26:24 +10:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-05-29 15:26:52 +02:00
|
|
|
break;
|
2017-06-01 02:26:24 +10:00
|
|
|
}
|
2017-04-21 02:18:14 +10:00
|
|
|
case OB_SURF:
|
|
|
|
break;
|
2017-04-13 22:09:59 +10:00
|
|
|
case OB_LATTICE:
|
|
|
|
{
|
2018-02-13 18:15:47 +11:00
|
|
|
if (ob != draw_ctx->object_edit) {
|
2017-06-27 15:59:13 +02:00
|
|
|
struct Gwn_Batch *geom = DRW_cache_lattice_wire_get(ob, false);
|
2017-04-28 04:33:58 +10:00
|
|
|
if (theme_id == TH_UNDEFINED) {
|
2017-11-22 10:52:39 -02:00
|
|
|
theme_id = DRW_object_wire_theme_get(ob, view_layer, NULL);
|
2017-04-28 04:33:58 +10:00
|
|
|
}
|
2017-04-13 22:09:59 +10:00
|
|
|
|
2017-04-21 04:29:33 +10:00
|
|
|
DRWShadingGroup *shgroup = shgroup_theme_id_to_wire_or(stl, theme_id, stl->g_data->wire);
|
2018-03-01 15:30:48 +01:00
|
|
|
DRW_shgroup_call_object_add(shgroup, geom, ob);
|
2017-04-15 16:46:17 +10:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case OB_CURVE:
|
|
|
|
{
|
2018-02-13 18:15:47 +11:00
|
|
|
if (ob != draw_ctx->object_edit) {
|
2017-06-19 20:18:04 +10:00
|
|
|
struct Gwn_Batch *geom = DRW_cache_curve_edge_wire_get(ob);
|
2017-04-28 04:33:58 +10:00
|
|
|
if (theme_id == TH_UNDEFINED) {
|
2017-11-22 10:52:39 -02:00
|
|
|
theme_id = DRW_object_wire_theme_get(ob, view_layer, NULL);
|
2017-04-28 04:33:58 +10:00
|
|
|
}
|
2017-04-21 04:29:33 +10:00
|
|
|
DRWShadingGroup *shgroup = shgroup_theme_id_to_wire_or(stl, theme_id, stl->g_data->wire);
|
2018-03-01 15:30:48 +01:00
|
|
|
DRW_shgroup_call_object_add(shgroup, geom, ob);
|
2017-04-13 22:09:59 +10:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2017-11-16 15:12:32 -02:00
|
|
|
case OB_MBALL:
|
|
|
|
{
|
2018-02-13 18:15:47 +11:00
|
|
|
if (ob != draw_ctx->object_edit) {
|
2018-02-16 02:01:09 -02:00
|
|
|
DRW_shgroup_mball_handles(stl, ob, view_layer);
|
2017-11-16 15:12:32 -02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2017-02-17 17:29:43 +01:00
|
|
|
case OB_LAMP:
|
2017-11-22 10:52:39 -02:00
|
|
|
DRW_shgroup_lamp(stl, ob, view_layer);
|
2017-02-17 17:29:43 +01:00
|
|
|
break;
|
|
|
|
case OB_CAMERA:
|
2017-11-22 10:52:39 -02:00
|
|
|
DRW_shgroup_camera(stl, ob, view_layer);
|
2017-03-04 00:09:22 +01:00
|
|
|
break;
|
2017-02-17 17:29:43 +01:00
|
|
|
case OB_EMPTY:
|
2017-11-22 10:52:39 -02:00
|
|
|
DRW_shgroup_empty(stl, psl, ob, view_layer);
|
2017-02-17 17:29:43 +01:00
|
|
|
break;
|
|
|
|
case OB_SPEAKER:
|
2017-11-22 10:52:39 -02:00
|
|
|
DRW_shgroup_speaker(stl, ob, view_layer);
|
2017-02-17 17:29:43 +01:00
|
|
|
break;
|
2017-06-12 20:59:54 +10:00
|
|
|
case OB_LIGHTPROBE:
|
2017-11-22 10:52:39 -02:00
|
|
|
DRW_shgroup_lightprobe(stl, psl, ob, view_layer);
|
2017-06-07 16:00:10 +02:00
|
|
|
break;
|
2017-02-22 13:00:15 +01:00
|
|
|
case OB_ARMATURE:
|
2017-04-13 21:44:24 +10:00
|
|
|
{
|
|
|
|
bArmature *arm = ob->data;
|
|
|
|
if (arm->edbo == NULL) {
|
2017-05-17 11:03:09 +10:00
|
|
|
if (DRW_state_is_select() || !DRW_pose_mode_armature(ob, draw_ctx->obact)) {
|
2018-05-06 18:28:11 +02:00
|
|
|
DRWArmaturePasses passes = {
|
|
|
|
.bone_solid = psl->bone_solid,
|
|
|
|
.bone_outline = psl->bone_outline,
|
|
|
|
.bone_wire = psl->bone_wire,
|
|
|
|
.bone_envelope = psl->bone_envelope,
|
2018-05-06 18:36:27 +02:00
|
|
|
.bone_axes = psl->bone_axes,
|
2018-05-07 00:24:30 +02:00
|
|
|
.relationship_lines = NULL, /* Don't draw relationship lines */
|
2018-05-06 18:28:11 +02:00
|
|
|
};
|
2018-05-07 00:24:30 +02:00
|
|
|
DRW_shgroup_armature_object(ob, view_layer, passes);
|
2017-04-27 16:57:11 +10:00
|
|
|
}
|
2017-03-08 20:00:09 +01:00
|
|
|
}
|
2017-02-22 13:00:15 +01:00
|
|
|
break;
|
2017-04-13 21:44:24 +10:00
|
|
|
}
|
2017-02-17 17:29:43 +01:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2017-04-10 22:22:37 +02:00
|
|
|
if (ob->pd && ob->pd->forcefield) {
|
2017-11-22 10:52:39 -02:00
|
|
|
DRW_shgroup_forcefield(stl, ob, view_layer);
|
2017-04-10 22:22:37 +02:00
|
|
|
}
|
|
|
|
|
2017-04-28 23:52:02 +10:00
|
|
|
/* don't show object extras in set's */
|
2017-06-03 02:21:10 +10:00
|
|
|
if ((ob->base_flag & (BASE_FROM_SET | BASE_FROMDUPLI)) == 0) {
|
2017-06-06 11:45:29 +02:00
|
|
|
|
2017-11-22 10:52:39 -02:00
|
|
|
DRW_shgroup_object_center(stl, ob, view_layer, v3d);
|
2017-06-06 11:45:29 +02:00
|
|
|
|
2017-04-28 23:52:02 +10:00
|
|
|
DRW_shgroup_relationship_lines(stl, ob);
|
|
|
|
|
|
|
|
if ((ob->dtx & OB_DRAWNAME) && DRW_state_show_text()) {
|
|
|
|
struct DRWTextStore *dt = DRW_text_cache_ensure();
|
|
|
|
if (theme_id == TH_UNDEFINED) {
|
2017-11-22 10:52:39 -02:00
|
|
|
theme_id = DRW_object_wire_theme_get(ob, view_layer, NULL);
|
2017-04-28 23:52:02 +10:00
|
|
|
}
|
2017-04-28 04:33:58 +10:00
|
|
|
|
2017-04-28 23:52:02 +10:00
|
|
|
unsigned char color[4];
|
|
|
|
UI_GetThemeColor4ubv(theme_id, color);
|
2017-04-28 04:33:58 +10:00
|
|
|
|
2017-04-28 23:52:02 +10:00
|
|
|
DRW_text_cache_add(
|
|
|
|
dt, ob->obmat[3],
|
|
|
|
ob->id.name + 2, strlen(ob->id.name + 2),
|
|
|
|
10, DRW_TEXT_CACHE_GLOBALSPACE | DRW_TEXT_CACHE_STRING_PTR, color);
|
|
|
|
}
|
2017-04-28 04:33:58 +10:00
|
|
|
}
|
2017-02-17 17:29:43 +01:00
|
|
|
}
|
|
|
|
|
2017-03-26 19:10:53 +02:00
|
|
|
static void OBJECT_draw_scene(void *vedata)
|
2017-02-17 17:29:43 +01:00
|
|
|
{
|
2017-03-26 19:10:53 +02:00
|
|
|
|
|
|
|
OBJECT_PassList *psl = ((OBJECT_Data *)vedata)->psl;
|
2017-07-10 11:36:16 +02:00
|
|
|
OBJECT_StorageList *stl = ((OBJECT_Data *)vedata)->stl;
|
2017-03-26 19:10:53 +02:00
|
|
|
OBJECT_FramebufferList *fbl = ((OBJECT_Data *)vedata)->fbl;
|
2018-04-16 19:38:40 +02:00
|
|
|
OBJECT_PrivateData *g_data = stl->g_data;
|
2017-03-20 14:59:27 +01:00
|
|
|
DefaultFramebufferList *dfbl = DRW_viewport_framebuffer_list_get();
|
2018-04-23 23:11:29 +02:00
|
|
|
DefaultTextureList *dtxl = DRW_viewport_texture_list_get();
|
2017-10-12 04:03:42 +02:00
|
|
|
|
2018-04-17 13:01:01 +02:00
|
|
|
int id_ct_select = g_data->id_ofs_select;
|
|
|
|
int id_ct_active = g_data->id_ofs_active;
|
|
|
|
int id_ct_transform = g_data->id_ofs_transform;
|
|
|
|
|
|
|
|
int id_ct_prb_select = g_data->id_ofs_prb_select;
|
|
|
|
int id_ct_prb_active = g_data->id_ofs_prb_active;
|
|
|
|
int id_ct_prb_transform = g_data->id_ofs_prb_transform;
|
|
|
|
|
2018-05-04 11:36:50 +02:00
|
|
|
int outline_calls = id_ct_select + id_ct_active + id_ct_transform;
|
|
|
|
outline_calls += id_ct_prb_select + id_ct_prb_active + id_ct_prb_transform;
|
2018-04-16 22:55:02 +02:00
|
|
|
|
2017-03-20 14:59:27 +01:00
|
|
|
float clearcol[4] = {0.0f, 0.0f, 0.0f, 0.0f};
|
2017-02-17 17:29:43 +01:00
|
|
|
|
2018-04-29 19:28:43 +02:00
|
|
|
// DRW_draw_pass(psl->bone_envelope); /* Never drawn in Object mode currently. */
|
|
|
|
|
2018-04-23 23:11:29 +02:00
|
|
|
MULTISAMPLE_SYNC_ENABLE(dfbl, dtxl)
|
2018-04-22 22:56:07 +02:00
|
|
|
|
|
|
|
/* This needs to be drawn after the oultine */
|
|
|
|
DRW_draw_pass(psl->bone_solid);
|
|
|
|
DRW_draw_pass(psl->bone_wire);
|
|
|
|
DRW_draw_pass(psl->bone_outline);
|
|
|
|
DRW_draw_pass(psl->non_meshes);
|
|
|
|
DRW_draw_pass(psl->particle);
|
|
|
|
DRW_draw_pass(psl->reference_image);
|
2018-05-06 18:36:27 +02:00
|
|
|
DRW_draw_pass(psl->bone_axes);
|
2018-04-22 22:56:07 +02:00
|
|
|
|
2018-04-23 23:11:29 +02:00
|
|
|
MULTISAMPLE_SYNC_DISABLE(dfbl, dtxl)
|
2018-04-22 22:56:07 +02:00
|
|
|
|
2018-04-16 22:55:02 +02:00
|
|
|
if (DRW_state_is_fbo() && outline_calls > 0) {
|
2017-07-26 19:58:15 +02:00
|
|
|
DRW_stats_group_start("Outlines");
|
2018-04-16 19:38:40 +02:00
|
|
|
|
|
|
|
g_data->id_ofs_active = 1;
|
2018-05-04 11:36:50 +02:00
|
|
|
g_data->id_ofs_select = g_data->id_ofs_active + id_ct_active + id_ct_prb_active + 1;
|
|
|
|
g_data->id_ofs_transform = g_data->id_ofs_select + id_ct_select + id_ct_prb_select + 1;
|
2018-04-17 13:01:01 +02:00
|
|
|
|
|
|
|
g_data->id_ofs_prb_active = g_data->id_ofs_active + id_ct_active;
|
|
|
|
g_data->id_ofs_prb_select = g_data->id_ofs_select + id_ct_select;
|
|
|
|
g_data->id_ofs_prb_transform = g_data->id_ofs_transform + id_ct_transform;
|
2018-04-16 19:38:40 +02:00
|
|
|
|
2017-04-26 04:39:25 +10:00
|
|
|
/* Render filled polygon on a separate framebuffer */
|
2018-03-25 17:46:48 +02:00
|
|
|
GPU_framebuffer_bind(fbl->outlines_fb);
|
|
|
|
GPU_framebuffer_clear_color_depth(fbl->outlines_fb, clearcol, 1.0f);
|
2017-04-26 04:39:25 +10:00
|
|
|
DRW_draw_pass(psl->outlines);
|
2017-09-30 19:34:23 +02:00
|
|
|
DRW_draw_pass(psl->lightprobes);
|
2017-07-26 19:58:15 +02:00
|
|
|
|
2017-04-26 04:39:25 +10:00
|
|
|
/* Search outline pixels */
|
2018-03-25 17:46:48 +02:00
|
|
|
GPU_framebuffer_bind(fbl->blur_fb);
|
2017-04-26 04:39:25 +10:00
|
|
|
DRW_draw_pass(psl->outlines_search);
|
2017-03-20 14:59:27 +01:00
|
|
|
|
2017-09-22 17:30:39 +02:00
|
|
|
/* Expand outline to form a 3px wide line */
|
2018-03-25 17:46:48 +02:00
|
|
|
GPU_framebuffer_bind(fbl->expand_fb);
|
2017-04-26 04:39:25 +10:00
|
|
|
DRW_draw_pass(psl->outlines_expand);
|
2017-03-22 02:14:23 +01:00
|
|
|
|
2017-09-22 17:30:39 +02:00
|
|
|
/* Bleed color so the AA can do it's stuff */
|
2018-03-25 17:46:48 +02:00
|
|
|
GPU_framebuffer_bind(fbl->blur_fb);
|
2017-09-22 17:30:39 +02:00
|
|
|
DRW_draw_pass(psl->outlines_bleed);
|
2017-03-20 14:59:27 +01:00
|
|
|
|
2017-05-16 03:03:58 +02:00
|
|
|
/* restore main framebuffer */
|
2018-03-25 17:46:48 +02:00
|
|
|
GPU_framebuffer_bind(dfbl->default_fb);
|
2017-07-26 19:58:15 +02:00
|
|
|
DRW_stats_group_end();
|
2017-04-26 04:39:25 +10:00
|
|
|
}
|
2017-09-30 19:34:23 +02:00
|
|
|
else if (DRW_state_is_select()) {
|
|
|
|
/* Render probes spheres/planes so we can select them. */
|
|
|
|
DRW_draw_pass(psl->lightprobes);
|
|
|
|
}
|
2017-03-22 02:14:23 +01:00
|
|
|
|
2017-09-23 20:47:42 +02:00
|
|
|
DRW_draw_pass(psl->ob_center);
|
|
|
|
|
2017-10-12 04:03:42 +02:00
|
|
|
if (DRW_state_is_fbo()) {
|
2017-05-27 21:28:29 +02:00
|
|
|
if (e_data.draw_grid) {
|
2018-03-25 17:46:48 +02:00
|
|
|
GPU_framebuffer_bind(dfbl->color_only_fb);
|
2017-05-27 21:28:29 +02:00
|
|
|
DRW_draw_pass(psl->grid);
|
|
|
|
}
|
2017-04-26 04:39:25 +10:00
|
|
|
|
|
|
|
/* Combine with scene buffer last */
|
2018-04-16 22:55:02 +02:00
|
|
|
if (outline_calls > 0) {
|
|
|
|
DRW_draw_pass(psl->outlines_resolve);
|
|
|
|
}
|
2017-04-26 04:39:25 +10:00
|
|
|
}
|
2017-07-10 11:36:16 +02:00
|
|
|
|
|
|
|
/* This has to be freed only after drawing empties! */
|
|
|
|
if (stl->g_data->image_plane_map) {
|
|
|
|
BLI_ghash_free(stl->g_data->image_plane_map, NULL, MEM_freeN);
|
2018-04-25 19:00:55 +02:00
|
|
|
stl->g_data->image_plane_map = NULL;
|
2017-07-10 11:36:16 +02:00
|
|
|
}
|
2017-02-17 17:53:51 +01:00
|
|
|
}
|
|
|
|
|
2017-04-12 19:49:19 +10:00
|
|
|
static const DrawEngineDataSize OBJECT_data_size = DRW_VIEWPORT_DATA_SIZE(OBJECT_Data);
|
|
|
|
|
2017-03-08 20:00:09 +01:00
|
|
|
DrawEngineType draw_engine_object_type = {
|
|
|
|
NULL, NULL,
|
|
|
|
N_("ObjectMode"),
|
2017-04-12 19:49:19 +10:00
|
|
|
&OBJECT_data_size,
|
2017-03-18 01:55:41 +01:00
|
|
|
&OBJECT_engine_init,
|
|
|
|
&OBJECT_engine_free,
|
2017-03-08 20:00:09 +01:00
|
|
|
&OBJECT_cache_init,
|
|
|
|
&OBJECT_cache_populate,
|
2017-07-10 11:36:16 +02:00
|
|
|
NULL,
|
2017-03-08 20:00:09 +01:00
|
|
|
NULL,
|
2017-09-25 20:07:02 +02:00
|
|
|
&OBJECT_draw_scene,
|
|
|
|
NULL,
|
2018-01-29 14:56:16 +01:00
|
|
|
NULL,
|
2017-03-08 20:00:09 +01:00
|
|
|
};
|