2017-03-08 20:00:09 +01:00
|
|
|
/*
|
2019-01-23 11:29:18 +11:00
|
|
|
* ***** BEGIN GPL LICENSE BLOCK *****
|
2017-03-08 20:00:09 +01:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
2019-01-23 11:29:18 +11:00
|
|
|
* Copyright 2016, Blender Foundation.
|
2017-03-08 20:00:09 +01:00
|
|
|
* Contributor(s): Blender Institute
|
|
|
|
*
|
2019-01-23 11:29:18 +11:00
|
|
|
* ***** END GPL LICENSE BLOCK *****
|
|
|
|
*
|
2017-03-08 20:00:09 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
/** \file blender/draw/intern/draw_common.c
|
|
|
|
* \ingroup draw
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "DRW_render.h"
|
|
|
|
|
|
|
|
#include "GPU_shader.h"
|
2017-05-23 16:56:53 +02:00
|
|
|
#include "GPU_texture.h"
|
2017-03-08 20:00:09 +01:00
|
|
|
|
|
|
|
#include "UI_resources.h"
|
|
|
|
|
2018-09-14 18:30:26 +02:00
|
|
|
#include "BKE_object.h"
|
2017-03-08 20:00:09 +01:00
|
|
|
#include "BKE_global.h"
|
2017-12-07 23:53:03 +11:00
|
|
|
#include "BKE_colorband.h"
|
2017-03-08 20:00:09 +01:00
|
|
|
|
|
|
|
#include "draw_common.h"
|
2019-01-25 07:13:02 +11:00
|
|
|
#include "draw_builtin_shader.h"
|
2017-03-08 20:00:09 +01:00
|
|
|
|
2017-04-11 14:05:39 +10:00
|
|
|
#if 0
|
|
|
|
#define UI_COLOR_RGB_FROM_U8(r, g, b, v4) \
|
|
|
|
ARRAY_SET_ITEMS(v4, (float)r / 255.0f, (float)g / 255.0f, (float)b / 255.0f, 1.0)
|
|
|
|
#endif
|
|
|
|
#define UI_COLOR_RGBA_FROM_U8(r, g, b, a, v4) \
|
|
|
|
ARRAY_SET_ITEMS(v4, (float)r / 255.0f, (float)g / 255.0f, (float)b / 255.0f, (float)a / 255.0f)
|
|
|
|
|
2017-03-08 20:00:09 +01:00
|
|
|
/* Colors & Constant */
|
2019-01-22 12:09:27 +11:00
|
|
|
struct DRW_Global G_draw = {0};
|
2018-09-25 19:19:59 +03:00
|
|
|
|
|
|
|
static bool weight_ramp_custom = false;
|
|
|
|
static ColorBand weight_ramp_copy;
|
|
|
|
|
2018-10-01 08:42:26 +10:00
|
|
|
static struct GPUTexture *DRW_create_weight_colorramp_texture(void);
|
2017-03-08 20:00:09 +01:00
|
|
|
|
|
|
|
void DRW_globals_update(void)
|
|
|
|
{
|
2019-01-22 12:09:27 +11:00
|
|
|
GlobalsUboStorage *gb = &G_draw.block;
|
|
|
|
|
|
|
|
UI_GetThemeColor4fv(TH_WIRE, gb->colorWire);
|
|
|
|
UI_GetThemeColor4fv(TH_WIRE_EDIT, gb->colorWireEdit);
|
|
|
|
UI_GetThemeColor4fv(TH_ACTIVE, gb->colorActive);
|
|
|
|
UI_GetThemeColor4fv(TH_SELECT, gb->colorSelect);
|
|
|
|
UI_COLOR_RGBA_FROM_U8(0x88, 0xFF, 0xFF, 155, gb->colorLibrarySelect);
|
|
|
|
UI_COLOR_RGBA_FROM_U8(0x55, 0xCC, 0xCC, 155, gb->colorLibrary);
|
|
|
|
UI_GetThemeColor4fv(TH_TRANSFORM, gb->colorTransform);
|
|
|
|
UI_GetThemeColor4fv(TH_LAMP, gb->colorLamp);
|
|
|
|
UI_GetThemeColor4fv(TH_SPEAKER, gb->colorSpeaker);
|
|
|
|
UI_GetThemeColor4fv(TH_CAMERA, gb->colorCamera);
|
|
|
|
UI_GetThemeColor4fv(TH_EMPTY, gb->colorEmpty);
|
|
|
|
UI_GetThemeColor4fv(TH_VERTEX, gb->colorVertex);
|
|
|
|
UI_GetThemeColor4fv(TH_VERTEX_SELECT, gb->colorVertexSelect);
|
|
|
|
UI_GetThemeColor4fv(TH_VERTEX_UNREFERENCED, gb->colorVertexUnreferenced);
|
|
|
|
UI_COLOR_RGBA_FROM_U8(0xB0, 0x00, 0xB0, 0xFF, gb->colorVertexMissingData);
|
|
|
|
UI_GetThemeColor4fv(TH_EDITMESH_ACTIVE, gb->colorEditMeshActive);
|
|
|
|
UI_GetThemeColor4fv(TH_EDGE_SELECT, gb->colorEdgeSelect);
|
|
|
|
|
|
|
|
UI_GetThemeColor4fv(TH_EDGE_SEAM, gb->colorEdgeSeam);
|
|
|
|
UI_GetThemeColor4fv(TH_EDGE_SHARP, gb->colorEdgeSharp);
|
|
|
|
UI_GetThemeColor4fv(TH_EDGE_CREASE, gb->colorEdgeCrease);
|
|
|
|
UI_GetThemeColor4fv(TH_EDGE_BEVEL, gb->colorEdgeBWeight);
|
|
|
|
UI_GetThemeColor4fv(TH_EDGE_FACESEL, gb->colorEdgeFaceSelect);
|
|
|
|
UI_GetThemeColor4fv(TH_FACE, gb->colorFace);
|
|
|
|
UI_GetThemeColor4fv(TH_FACE_SELECT, gb->colorFaceSelect);
|
|
|
|
UI_GetThemeColor4fv(TH_NORMAL, gb->colorNormal);
|
|
|
|
UI_GetThemeColor4fv(TH_VNORMAL, gb->colorVNormal);
|
|
|
|
UI_GetThemeColor4fv(TH_LNORMAL, gb->colorLNormal);
|
|
|
|
UI_GetThemeColor4fv(TH_FACE_DOT, gb->colorFaceDot);
|
|
|
|
UI_GetThemeColor4fv(TH_BACK, gb->colorBackground);
|
2017-03-22 21:28:59 +01:00
|
|
|
|
2018-12-10 18:30:37 +01:00
|
|
|
/* Custom median color to slightly affect the edit mesh colors. */
|
2019-01-22 12:09:27 +11:00
|
|
|
interp_v4_v4v4(gb->colorEditMeshMiddle, gb->colorVertexSelect, gb->colorWireEdit, 0.35f);
|
|
|
|
copy_v3_fl(gb->colorEditMeshMiddle, dot_v3v3(gb->colorEditMeshMiddle, (float[3]){0.3333f, 0.3333f, 0.3333f})); /* Desaturate */
|
2018-12-10 18:30:37 +01:00
|
|
|
|
2019-01-22 12:09:27 +11:00
|
|
|
interp_v4_v4v4(gb->colorDupliSelect, gb->colorBackground, gb->colorSelect, 0.5f);
|
2019-01-11 14:26:30 +11:00
|
|
|
/* Was 50% in 2.7x since the background was lighter making it easier to tell the color from black,
|
|
|
|
* with a darker background we need a more faded color. */
|
2019-01-22 12:09:27 +11:00
|
|
|
interp_v4_v4v4(gb->colorDupli, gb->colorBackground, gb->colorWire, 0.3f);
|
2019-01-11 13:27:49 +11:00
|
|
|
|
2018-09-05 15:42:32 +02:00
|
|
|
#ifdef WITH_FREESTYLE
|
2019-01-22 12:09:27 +11:00
|
|
|
UI_GetThemeColor4fv(TH_FREESTYLE_EDGE_MARK, gb->colorEdgeFreestyle);
|
|
|
|
UI_GetThemeColor4fv(TH_FREESTYLE_FACE_MARK, gb->colorFaceFreestyle);
|
2018-09-05 15:42:32 +02:00
|
|
|
#else
|
2019-01-22 12:09:27 +11:00
|
|
|
zero_v4(gb->colorEdgeFreestyle);
|
|
|
|
zero_v4(gb->colorFaceFreestyle);
|
2018-09-05 15:42:32 +02:00
|
|
|
#endif
|
|
|
|
|
2018-01-09 13:29:16 +11:00
|
|
|
/* Curve */
|
2019-01-22 12:09:27 +11:00
|
|
|
UI_GetThemeColor4fv(TH_HANDLE_FREE, gb->colorHandleFree);
|
|
|
|
UI_GetThemeColor4fv(TH_HANDLE_AUTO, gb->colorHandleAuto);
|
|
|
|
UI_GetThemeColor4fv(TH_HANDLE_VECT, gb->colorHandleVect);
|
|
|
|
UI_GetThemeColor4fv(TH_HANDLE_ALIGN, gb->colorHandleAlign);
|
|
|
|
UI_GetThemeColor4fv(TH_HANDLE_AUTOCLAMP, gb->colorHandleAutoclamp);
|
|
|
|
UI_GetThemeColor4fv(TH_HANDLE_SEL_FREE, gb->colorHandleSelFree);
|
|
|
|
UI_GetThemeColor4fv(TH_HANDLE_SEL_AUTO, gb->colorHandleSelAuto);
|
|
|
|
UI_GetThemeColor4fv(TH_HANDLE_SEL_VECT, gb->colorHandleSelVect);
|
|
|
|
UI_GetThemeColor4fv(TH_HANDLE_SEL_ALIGN, gb->colorHandleSelAlign);
|
|
|
|
UI_GetThemeColor4fv(TH_HANDLE_SEL_AUTOCLAMP, gb->colorHandleSelAutoclamp);
|
|
|
|
UI_GetThemeColor4fv(TH_NURB_ULINE, gb->colorNurbUline);
|
|
|
|
UI_GetThemeColor4fv(TH_NURB_VLINE, gb->colorNurbVline);
|
|
|
|
UI_GetThemeColor4fv(TH_NURB_SEL_ULINE, gb->colorNurbSelUline);
|
|
|
|
UI_GetThemeColor4fv(TH_NURB_SEL_VLINE, gb->colorNurbSelVline);
|
|
|
|
UI_GetThemeColor4fv(TH_ACTIVE_SPLINE, gb->colorActiveSpline);
|
|
|
|
|
|
|
|
UI_GetThemeColor4fv(TH_BONE_POSE, gb->colorBonePose);
|
|
|
|
|
|
|
|
UI_GetThemeColor4fv(TH_CFRAME, gb->colorCurrentFrame);
|
2018-06-01 16:38:21 +02:00
|
|
|
|
2017-03-22 21:28:59 +01:00
|
|
|
/* Grid */
|
2019-01-22 12:09:27 +11:00
|
|
|
UI_GetThemeColorShade4fv(TH_GRID, 10, gb->colorGrid);
|
2017-03-22 21:28:59 +01:00
|
|
|
/* emphasise division lines lighter instead of darker, if background is darker than grid */
|
2017-08-01 13:35:26 +10:00
|
|
|
UI_GetThemeColorShade4fv(
|
|
|
|
TH_GRID,
|
2019-01-22 12:09:27 +11:00
|
|
|
(gb->colorGrid[0] + gb->colorGrid[1] + gb->colorGrid[2] + 0.12f >
|
|
|
|
gb->colorBackground[0] + gb->colorBackground[1] + gb->colorBackground[2]) ?
|
|
|
|
20 : -10, gb->colorGridEmphasise);
|
2017-03-22 21:28:59 +01:00
|
|
|
/* Grid Axis */
|
2019-01-22 12:09:27 +11:00
|
|
|
UI_GetThemeColorBlendShade4fv(TH_GRID, TH_AXIS_X, 0.5f, -10, gb->colorGridAxisX);
|
|
|
|
UI_GetThemeColorBlendShade4fv(TH_GRID, TH_AXIS_Y, 0.5f, -10, gb->colorGridAxisY);
|
|
|
|
UI_GetThemeColorBlendShade4fv(TH_GRID, TH_AXIS_Z, 0.5f, -10, gb->colorGridAxisZ);
|
2017-03-08 20:00:09 +01:00
|
|
|
|
2019-01-22 12:09:27 +11:00
|
|
|
UI_GetThemeColorShadeAlpha4fv(TH_TRANSFORM, 0, -80, gb->colorDeselect);
|
|
|
|
UI_GetThemeColorShadeAlpha4fv(TH_WIRE, 0, -30, gb->colorOutline);
|
|
|
|
UI_GetThemeColorShadeAlpha4fv(TH_LAMP, 0, 255, gb->colorLampNoAlpha);
|
2017-03-08 20:00:09 +01:00
|
|
|
|
2019-01-22 12:09:27 +11:00
|
|
|
gb->sizeLampCenter = (U.obcenter_dia + 1.5f) * U.pixelsize;
|
|
|
|
gb->sizeLampCircle = U.pixelsize * 9.0f;
|
|
|
|
gb->sizeLampCircleShadow = gb->sizeLampCircle + U.pixelsize * 3.0f;
|
2017-03-08 20:00:09 +01:00
|
|
|
|
|
|
|
/* M_SQRT2 to be at least the same size of the old square */
|
2019-01-22 12:09:27 +11:00
|
|
|
gb->sizeVertex = U.pixelsize * (max_ff(1.0f, UI_GetThemeValuef(TH_VERTEX_SIZE) * (float)M_SQRT2 / 2.0f));
|
|
|
|
gb->sizeFaceDot = U.pixelsize * UI_GetThemeValuef(TH_FACEDOT_SIZE);
|
|
|
|
gb->sizeEdge = U.pixelsize * (1.0f / 2.0f); /* TODO Theme */
|
|
|
|
gb->sizeEdgeFix = U.pixelsize * (0.5f + 2.0f * (2.0f * (gb->sizeEdge * (float)M_SQRT1_2)));
|
2018-02-26 21:12:19 +01:00
|
|
|
|
2018-09-11 17:05:07 +02:00
|
|
|
/* Color management. */
|
|
|
|
if (DRW_state_is_image_render()) {
|
2019-01-22 12:09:27 +11:00
|
|
|
float *color = gb->UBO_FIRST_COLOR;
|
2018-09-11 17:05:07 +02:00
|
|
|
do {
|
|
|
|
/* TODO more accurate transform. */
|
|
|
|
srgb_to_linearrgb_v4(color, color);
|
|
|
|
color += 4;
|
2019-01-22 12:09:27 +11:00
|
|
|
} while (color != gb->UBO_LAST_COLOR);
|
2018-09-11 17:05:07 +02:00
|
|
|
}
|
|
|
|
|
2019-01-22 12:09:27 +11:00
|
|
|
if (G_draw.block_ubo == NULL) {
|
|
|
|
G_draw.block_ubo = DRW_uniformbuffer_create(sizeof(GlobalsUboStorage), gb);
|
2017-03-08 20:00:09 +01:00
|
|
|
}
|
|
|
|
|
2019-01-22 12:09:27 +11:00
|
|
|
DRW_uniformbuffer_update(G_draw.block_ubo, gb);
|
2017-05-23 16:56:53 +02:00
|
|
|
|
2019-01-22 12:09:27 +11:00
|
|
|
if (!G_draw.ramp) {
|
2018-12-11 21:25:17 +01:00
|
|
|
ColorBand ramp = {0};
|
|
|
|
float *colors;
|
|
|
|
int col_size;
|
|
|
|
|
|
|
|
ramp.tot = 3;
|
|
|
|
ramp.data[0].a = 1.0f;
|
|
|
|
ramp.data[0].b = 1.0f;
|
|
|
|
ramp.data[0].pos = 0.0f;
|
|
|
|
ramp.data[1].a = 1.0f;
|
|
|
|
ramp.data[1].g = 1.0f;
|
|
|
|
ramp.data[1].pos = 0.5f;
|
|
|
|
ramp.data[2].a = 1.0f;
|
|
|
|
ramp.data[2].r = 1.0f;
|
|
|
|
ramp.data[2].pos = 1.0f;
|
|
|
|
|
|
|
|
BKE_colorband_evaluate_table_rgba(&ramp, &colors, &col_size);
|
|
|
|
|
2019-01-22 12:09:27 +11:00
|
|
|
G_draw.ramp = GPU_texture_create_1D(col_size, GPU_RGBA8, colors, NULL);
|
2018-12-11 21:25:17 +01:00
|
|
|
|
|
|
|
MEM_freeN(colors);
|
2017-05-24 13:26:06 +10:00
|
|
|
}
|
2018-09-25 19:19:59 +03:00
|
|
|
|
|
|
|
/* Weight Painting color ramp texture */
|
|
|
|
bool user_weight_ramp = (U.flag & USER_CUSTOM_RANGE) != 0;
|
|
|
|
|
|
|
|
if (weight_ramp_custom != user_weight_ramp ||
|
2018-10-01 08:42:26 +10:00
|
|
|
(user_weight_ramp && memcmp(&weight_ramp_copy, &U.coba_weight, sizeof(ColorBand)) != 0))
|
|
|
|
{
|
2019-01-22 12:09:27 +11:00
|
|
|
DRW_TEXTURE_FREE_SAFE(G_draw.weight_ramp);
|
2018-09-25 19:19:59 +03:00
|
|
|
}
|
|
|
|
|
2019-01-22 12:09:27 +11:00
|
|
|
if (G_draw.weight_ramp == NULL) {
|
2018-09-25 19:19:59 +03:00
|
|
|
weight_ramp_custom = user_weight_ramp;
|
|
|
|
memcpy(&weight_ramp_copy, &U.coba_weight, sizeof(ColorBand));
|
|
|
|
|
2019-01-22 12:09:27 +11:00
|
|
|
G_draw.weight_ramp = DRW_create_weight_colorramp_texture();
|
2018-09-25 19:19:59 +03:00
|
|
|
}
|
2017-03-08 20:00:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ********************************* SHGROUP ************************************* */
|
|
|
|
|
2018-06-01 16:38:21 +02:00
|
|
|
extern char datatoc_animviz_mpath_lines_vert_glsl[];
|
|
|
|
extern char datatoc_animviz_mpath_lines_geom_glsl[];
|
|
|
|
extern char datatoc_animviz_mpath_points_vert_glsl[];
|
|
|
|
|
2018-07-16 15:01:44 +02:00
|
|
|
extern char datatoc_volume_velocity_vert_glsl[];
|
|
|
|
|
2018-05-06 16:09:25 +02:00
|
|
|
extern char datatoc_armature_axes_vert_glsl[];
|
2018-05-05 20:51:16 +02:00
|
|
|
extern char datatoc_armature_sphere_solid_vert_glsl[];
|
|
|
|
extern char datatoc_armature_sphere_solid_frag_glsl[];
|
2018-04-30 22:47:40 +02:00
|
|
|
extern char datatoc_armature_sphere_outline_vert_glsl[];
|
2018-05-05 20:51:16 +02:00
|
|
|
extern char datatoc_armature_envelope_solid_vert_glsl[];
|
|
|
|
extern char datatoc_armature_envelope_solid_frag_glsl[];
|
2018-04-30 22:47:40 +02:00
|
|
|
extern char datatoc_armature_envelope_outline_vert_glsl[];
|
2018-05-05 20:51:16 +02:00
|
|
|
extern char datatoc_armature_envelope_distance_frag_glsl[];
|
|
|
|
extern char datatoc_armature_shape_solid_vert_glsl[];
|
|
|
|
extern char datatoc_armature_shape_solid_frag_glsl[];
|
2018-04-22 22:49:36 +02:00
|
|
|
extern char datatoc_armature_shape_outline_vert_glsl[];
|
|
|
|
extern char datatoc_armature_shape_outline_geom_glsl[];
|
2018-05-08 12:05:06 +02:00
|
|
|
extern char datatoc_armature_stick_vert_glsl[];
|
|
|
|
extern char datatoc_armature_stick_frag_glsl[];
|
2018-10-03 15:42:05 +02:00
|
|
|
extern char datatoc_armature_dof_vert_glsl[];
|
2018-06-01 16:38:21 +02:00
|
|
|
|
|
|
|
extern char datatoc_common_globals_lib_glsl[];
|
2019-01-26 15:00:03 +11:00
|
|
|
extern char datatoc_common_world_clip_lib_glsl[];
|
2018-06-01 16:38:21 +02:00
|
|
|
|
2018-04-22 22:49:36 +02:00
|
|
|
extern char datatoc_gpu_shader_flat_color_frag_glsl[];
|
2018-06-01 16:38:21 +02:00
|
|
|
extern char datatoc_gpu_shader_3D_smooth_color_frag_glsl[];
|
|
|
|
extern char datatoc_gpu_shader_point_varying_color_frag_glsl[];
|
2018-04-22 22:49:36 +02:00
|
|
|
|
2018-05-03 09:11:02 -03:00
|
|
|
extern char datatoc_object_mball_handles_vert_glsl[];
|
2018-08-17 12:16:50 +02:00
|
|
|
extern char datatoc_object_empty_axes_vert_glsl[];
|
2018-05-03 09:11:02 -03:00
|
|
|
|
2019-01-26 15:00:03 +11:00
|
|
|
typedef struct COMMON_Shaders {
|
2018-04-22 22:49:36 +02:00
|
|
|
struct GPUShader *shape_outline;
|
2018-05-05 20:51:16 +02:00
|
|
|
struct GPUShader *shape_solid;
|
2018-05-06 16:09:25 +02:00
|
|
|
struct GPUShader *bone_axes;
|
2018-04-29 19:39:44 +02:00
|
|
|
struct GPUShader *bone_envelope;
|
2018-05-02 08:58:29 +02:00
|
|
|
struct GPUShader *bone_envelope_distance;
|
2018-04-29 19:39:44 +02:00
|
|
|
struct GPUShader *bone_envelope_outline;
|
2018-04-27 16:27:47 +02:00
|
|
|
struct GPUShader *bone_sphere;
|
|
|
|
struct GPUShader *bone_sphere_outline;
|
2018-05-08 12:05:06 +02:00
|
|
|
struct GPUShader *bone_stick;
|
2018-10-03 15:42:05 +02:00
|
|
|
struct GPUShader *bone_dofs;
|
2018-05-03 09:11:02 -03:00
|
|
|
|
2018-06-01 16:38:21 +02:00
|
|
|
struct GPUShader *mpath_line_sh;
|
|
|
|
struct GPUShader *mpath_points_sh;
|
|
|
|
|
2018-07-16 15:01:44 +02:00
|
|
|
struct GPUShader *volume_velocity_needle_sh;
|
|
|
|
struct GPUShader *volume_velocity_sh;
|
2018-08-17 12:16:50 +02:00
|
|
|
struct GPUShader *empty_axes_sh;
|
2018-07-16 15:01:44 +02:00
|
|
|
|
2018-05-03 09:11:02 -03:00
|
|
|
struct GPUShader *mball_handles;
|
2019-01-26 15:00:03 +11:00
|
|
|
} COMMON_Shaders;
|
|
|
|
|
|
|
|
static COMMON_Shaders g_shaders[DRW_SHADER_SLOT_LEN] = {{NULL}};
|
2018-04-22 22:49:36 +02:00
|
|
|
|
2018-02-14 18:59:15 +01:00
|
|
|
static struct {
|
2018-07-18 00:12:21 +02:00
|
|
|
struct GPUVertFormat *instance_screenspace;
|
|
|
|
struct GPUVertFormat *instance_color;
|
|
|
|
struct GPUVertFormat *instance_screen_aligned;
|
|
|
|
struct GPUVertFormat *instance_scaled;
|
|
|
|
struct GPUVertFormat *instance_sized;
|
|
|
|
struct GPUVertFormat *instance_outline;
|
|
|
|
struct GPUVertFormat *instance;
|
|
|
|
struct GPUVertFormat *instance_camera;
|
|
|
|
struct GPUVertFormat *instance_distance_lines;
|
|
|
|
struct GPUVertFormat *instance_spot;
|
|
|
|
struct GPUVertFormat *instance_bone;
|
2018-10-03 15:42:05 +02:00
|
|
|
struct GPUVertFormat *instance_bone_dof;
|
2018-07-18 00:12:21 +02:00
|
|
|
struct GPUVertFormat *instance_bone_stick;
|
|
|
|
struct GPUVertFormat *instance_bone_outline;
|
|
|
|
struct GPUVertFormat *instance_bone_envelope;
|
|
|
|
struct GPUVertFormat *instance_bone_envelope_distance;
|
|
|
|
struct GPUVertFormat *instance_bone_envelope_outline;
|
|
|
|
struct GPUVertFormat *instance_mball_handles;
|
|
|
|
struct GPUVertFormat *dynlines_color;
|
2018-02-14 18:59:15 +01:00
|
|
|
} g_formats = {NULL};
|
|
|
|
|
|
|
|
void DRW_globals_free(void)
|
|
|
|
{
|
2018-07-18 00:12:21 +02:00
|
|
|
struct GPUVertFormat **format = &g_formats.instance_screenspace;
|
2018-02-15 18:03:55 +11:00
|
|
|
for (int i = 0; i < sizeof(g_formats) / sizeof(void *); ++i, ++format) {
|
2018-02-14 18:59:15 +01:00
|
|
|
MEM_SAFE_FREE(*format);
|
|
|
|
}
|
2018-04-22 22:49:36 +02:00
|
|
|
|
2019-01-26 15:00:03 +11:00
|
|
|
for (int j = 0; j < DRW_SHADER_SLOT_LEN; j++) {
|
|
|
|
struct GPUShader **shader = &g_shaders[j].shape_outline;
|
|
|
|
for (int i = 0; i < sizeof(g_shaders[j]) / sizeof(void *); ++i, ++shader) {
|
|
|
|
DRW_SHADER_FREE_SAFE(*shader);
|
|
|
|
}
|
2018-04-22 22:49:36 +02:00
|
|
|
}
|
2018-02-14 18:59:15 +01:00
|
|
|
}
|
|
|
|
|
2019-01-21 19:08:42 +11:00
|
|
|
void DRW_shgroup_world_clip_planes_from_rv3d(DRWShadingGroup *shgrp, const RegionView3D *rv3d)
|
|
|
|
{
|
|
|
|
int world_clip_planes_len = (rv3d->viewlock & RV3D_BOXCLIP) ? 4 : 6;
|
|
|
|
DRW_shgroup_uniform_vec4(shgrp, "WorldClipPlanes", rv3d->clip[0], world_clip_planes_len);
|
|
|
|
DRW_shgroup_state_enable(shgrp, DRW_STATE_CLIP_PLANES);
|
|
|
|
}
|
|
|
|
|
2018-05-16 18:01:32 +02:00
|
|
|
DRWShadingGroup *shgroup_dynlines_flat_color(DRWPass *pass)
|
|
|
|
{
|
|
|
|
GPUShader *sh = GPU_shader_get_builtin_shader(GPU_SHADER_3D_FLAT_COLOR);
|
|
|
|
|
|
|
|
DRW_shgroup_instance_format(g_formats.dynlines_color, {
|
2019-01-29 07:46:25 +11:00
|
|
|
{"pos", DRW_ATTR_FLOAT, 3},
|
|
|
|
{"color", DRW_ATTR_FLOAT, 4}
|
2018-05-16 18:01:32 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
DRWShadingGroup *grp = DRW_shgroup_line_batch_create_with_format(sh, pass, g_formats.dynlines_color);
|
|
|
|
|
|
|
|
return grp;
|
|
|
|
}
|
|
|
|
|
2019-01-22 12:08:33 +11:00
|
|
|
DRWShadingGroup *shgroup_dynlines_dashed_uniform_color(DRWPass *pass, const float color[4])
|
2017-03-08 20:00:09 +01:00
|
|
|
{
|
2018-05-07 00:22:03 +02:00
|
|
|
GPUShader *sh = GPU_shader_get_builtin_shader(GPU_SHADER_3D_LINE_DASHED_UNIFORM_COLOR);
|
2017-03-08 20:00:09 +01:00
|
|
|
|
2018-07-01 08:34:04 +02:00
|
|
|
static float dash_width = 6.0f;
|
2018-05-07 00:22:03 +02:00
|
|
|
static float dash_factor = 0.5f;
|
2017-03-08 20:00:09 +01:00
|
|
|
DRWShadingGroup *grp = DRW_shgroup_line_batch_create(sh, pass);
|
|
|
|
DRW_shgroup_uniform_vec4(grp, "color", color, 1);
|
2018-05-07 00:22:03 +02:00
|
|
|
DRW_shgroup_uniform_vec2(grp, "viewport_size", DRW_viewport_size_get(), 1);
|
|
|
|
DRW_shgroup_uniform_float(grp, "dash_width", &dash_width, 1);
|
|
|
|
DRW_shgroup_uniform_float(grp, "dash_factor", &dash_factor, 1);
|
2018-07-01 08:42:16 +02:00
|
|
|
DRW_shgroup_uniform_int_copy(grp, "colors_len", 0); /* "simple" mode */
|
2017-03-08 20:00:09 +01:00
|
|
|
|
|
|
|
return grp;
|
|
|
|
}
|
|
|
|
|
2019-01-29 00:13:42 +11:00
|
|
|
DRWShadingGroup *shgroup_dynpoints_uniform_color(
|
|
|
|
DRWPass *pass, const float color[4], const float *size, eDRW_ShaderSlot shader_slot)
|
2017-03-08 20:00:09 +01:00
|
|
|
{
|
2019-01-29 00:13:42 +11:00
|
|
|
GPUShader *sh = DRW_shader_get_builtin_shader(GPU_SHADER_3D_POINT_UNIFORM_SIZE_UNIFORM_COLOR_AA, shader_slot);
|
2017-03-08 20:00:09 +01:00
|
|
|
|
|
|
|
DRWShadingGroup *grp = DRW_shgroup_point_batch_create(sh, pass);
|
|
|
|
DRW_shgroup_uniform_vec4(grp, "color", color, 1);
|
|
|
|
DRW_shgroup_uniform_float(grp, "size", size, 1);
|
2017-05-03 08:20:11 +10:00
|
|
|
DRW_shgroup_state_enable(grp, DRW_STATE_POINT);
|
2019-01-29 00:13:42 +11:00
|
|
|
if (shader_slot == DRW_SHADER_SLOT_CLIPPED) {
|
|
|
|
DRW_shgroup_world_clip_planes_from_rv3d(grp, DRW_context_state_get()->rv3d);
|
|
|
|
}
|
2017-03-08 20:00:09 +01:00
|
|
|
return grp;
|
|
|
|
}
|
|
|
|
|
2019-01-22 12:08:33 +11:00
|
|
|
DRWShadingGroup *shgroup_groundlines_uniform_color(DRWPass *pass, const float color[4])
|
2017-03-08 20:00:09 +01:00
|
|
|
{
|
|
|
|
GPUShader *sh = GPU_shader_get_builtin_shader(GPU_SHADER_3D_GROUNDLINE);
|
|
|
|
|
|
|
|
DRWShadingGroup *grp = DRW_shgroup_point_batch_create(sh, pass);
|
|
|
|
DRW_shgroup_uniform_vec4(grp, "color", color, 1);
|
|
|
|
|
|
|
|
return grp;
|
|
|
|
}
|
|
|
|
|
2019-01-22 12:08:33 +11:00
|
|
|
DRWShadingGroup *shgroup_groundpoints_uniform_color(DRWPass *pass, const float color[4])
|
2017-03-08 20:00:09 +01:00
|
|
|
{
|
|
|
|
GPUShader *sh = GPU_shader_get_builtin_shader(GPU_SHADER_3D_GROUNDPOINT);
|
|
|
|
|
|
|
|
DRWShadingGroup *grp = DRW_shgroup_point_batch_create(sh, pass);
|
|
|
|
DRW_shgroup_uniform_vec4(grp, "color", color, 1);
|
2017-05-03 08:20:11 +10:00
|
|
|
DRW_shgroup_state_enable(grp, DRW_STATE_POINT);
|
2017-03-08 20:00:09 +01:00
|
|
|
|
|
|
|
return grp;
|
|
|
|
}
|
|
|
|
|
2019-01-29 00:13:42 +11:00
|
|
|
DRWShadingGroup *shgroup_instance_screenspace(
|
|
|
|
DRWPass *pass, struct GPUBatch *geom, const float *size, eDRW_ShaderSlot shader_slot)
|
2017-03-08 20:00:09 +01:00
|
|
|
{
|
2019-01-29 00:13:42 +11:00
|
|
|
GPUShader *sh = DRW_shader_get_builtin_shader(GPU_SHADER_3D_SCREENSPACE_VARIYING_COLOR, shader_slot);
|
2017-03-08 20:00:09 +01:00
|
|
|
|
2018-02-14 18:59:15 +01:00
|
|
|
DRW_shgroup_instance_format(g_formats.instance_screenspace, {
|
2019-01-29 07:46:25 +11:00
|
|
|
{"world_pos", DRW_ATTR_FLOAT, 3},
|
|
|
|
{"color", DRW_ATTR_FLOAT, 3}
|
2018-02-14 18:59:15 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
DRWShadingGroup *grp = DRW_shgroup_instance_create(sh, pass, geom, g_formats.instance_screenspace);
|
2017-03-08 20:00:09 +01:00
|
|
|
DRW_shgroup_uniform_float(grp, "size", size, 1);
|
|
|
|
DRW_shgroup_uniform_float(grp, "pixel_size", DRW_viewport_pixelsize_get(), 1);
|
2017-04-18 19:12:28 +02:00
|
|
|
DRW_shgroup_uniform_vec3(grp, "screen_vecs[0]", DRW_viewport_screenvecs_get(), 2);
|
2019-01-29 00:13:42 +11:00
|
|
|
if (shader_slot == DRW_SHADER_SLOT_CLIPPED) {
|
|
|
|
DRW_shgroup_world_clip_planes_from_rv3d(grp, DRW_context_state_get()->rv3d);
|
|
|
|
}
|
2017-03-08 20:00:09 +01:00
|
|
|
return grp;
|
|
|
|
}
|
|
|
|
|
2018-07-18 00:12:21 +02:00
|
|
|
DRWShadingGroup *shgroup_instance_solid(DRWPass *pass, struct GPUBatch *geom)
|
2017-03-08 20:00:09 +01:00
|
|
|
{
|
|
|
|
static float light[3] = {0.0f, 0.0f, 1.0f};
|
|
|
|
GPUShader *sh = GPU_shader_get_builtin_shader(GPU_SHADER_3D_OBJECTSPACE_SIMPLE_LIGHTING_VARIYING_COLOR);
|
|
|
|
|
2018-02-14 18:59:15 +01:00
|
|
|
DRW_shgroup_instance_format(g_formats.instance_color, {
|
2019-01-29 07:46:25 +11:00
|
|
|
{"InstanceModelMatrix", DRW_ATTR_FLOAT, 16},
|
|
|
|
{"color", DRW_ATTR_FLOAT, 4}
|
2018-02-14 18:59:15 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
DRWShadingGroup *grp = DRW_shgroup_instance_create(sh, pass, geom, g_formats.instance_color);
|
2017-03-08 20:00:09 +01:00
|
|
|
DRW_shgroup_uniform_vec3(grp, "light", light, 1);
|
|
|
|
|
|
|
|
return grp;
|
|
|
|
}
|
|
|
|
|
2018-07-18 00:12:21 +02:00
|
|
|
DRWShadingGroup *shgroup_instance_wire(DRWPass *pass, struct GPUBatch *geom)
|
2017-03-08 20:00:09 +01:00
|
|
|
{
|
|
|
|
GPUShader *sh = GPU_shader_get_builtin_shader(GPU_SHADER_3D_OBJECTSPACE_VARIYING_COLOR);
|
|
|
|
|
2018-02-14 18:59:15 +01:00
|
|
|
DRW_shgroup_instance_format(g_formats.instance_color, {
|
2019-01-29 07:46:25 +11:00
|
|
|
{"InstanceModelMatrix", DRW_ATTR_FLOAT, 16},
|
|
|
|
{"color", DRW_ATTR_FLOAT, 4}
|
2018-02-14 18:59:15 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
DRWShadingGroup *grp = DRW_shgroup_instance_create(sh, pass, geom, g_formats.instance_color);
|
2017-03-08 20:00:09 +01:00
|
|
|
|
|
|
|
return grp;
|
|
|
|
}
|
|
|
|
|
2019-01-29 00:13:42 +11:00
|
|
|
DRWShadingGroup *shgroup_instance_screen_aligned(
|
|
|
|
DRWPass *pass, struct GPUBatch *geom, eDRW_ShaderSlot shader_slot)
|
2017-04-10 22:22:37 +02:00
|
|
|
{
|
2019-01-29 00:13:42 +11:00
|
|
|
GPUShader *sh = DRW_shader_get_builtin_shader(GPU_SHADER_3D_INSTANCE_SCREEN_ALIGNED, shader_slot);
|
2017-04-10 22:22:37 +02:00
|
|
|
|
2018-02-14 18:59:15 +01:00
|
|
|
DRW_shgroup_instance_format(g_formats.instance_screen_aligned, {
|
2019-01-29 07:46:25 +11:00
|
|
|
{"color", DRW_ATTR_FLOAT, 3},
|
|
|
|
{"size", DRW_ATTR_FLOAT, 1},
|
|
|
|
{"InstanceModelMatrix", DRW_ATTR_FLOAT, 16}
|
2018-02-14 18:59:15 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
DRWShadingGroup *grp = DRW_shgroup_instance_create(sh, pass, geom, g_formats.instance_screen_aligned);
|
2017-04-18 19:12:28 +02:00
|
|
|
DRW_shgroup_uniform_vec3(grp, "screen_vecs[0]", DRW_viewport_screenvecs_get(), 2);
|
2019-01-29 00:13:42 +11:00
|
|
|
if (shader_slot == DRW_SHADER_SLOT_CLIPPED) {
|
|
|
|
DRW_shgroup_world_clip_planes_from_rv3d(grp, DRW_context_state_get()->rv3d);
|
|
|
|
}
|
2017-04-10 22:22:37 +02:00
|
|
|
return grp;
|
|
|
|
}
|
|
|
|
|
2019-01-26 15:00:03 +11:00
|
|
|
DRWShadingGroup *shgroup_instance_scaled(DRWPass *pass, struct GPUBatch *geom, eDRW_ShaderSlot shader_slot)
|
2017-03-08 20:00:09 +01:00
|
|
|
{
|
2019-01-26 15:00:03 +11:00
|
|
|
GPUShader *sh_inst = DRW_shader_get_builtin_shader(GPU_SHADER_INSTANCE_VARIYING_COLOR_VARIYING_SCALE, shader_slot);
|
2017-03-08 20:00:09 +01:00
|
|
|
|
2018-08-17 12:16:50 +02:00
|
|
|
DRW_shgroup_instance_format(g_formats.instance_scaled, {
|
2019-01-29 07:46:25 +11:00
|
|
|
{"color", DRW_ATTR_FLOAT, 3},
|
|
|
|
{"size", DRW_ATTR_FLOAT, 3},
|
|
|
|
{"InstanceModelMatrix", DRW_ATTR_FLOAT, 16}
|
2018-02-14 18:59:15 +01:00
|
|
|
});
|
|
|
|
|
2018-08-17 12:16:50 +02:00
|
|
|
DRWShadingGroup *grp = DRW_shgroup_instance_create(sh_inst, pass, geom, g_formats.instance_scaled);
|
2019-01-26 15:00:03 +11:00
|
|
|
if (shader_slot == DRW_SHADER_SLOT_CLIPPED) {
|
|
|
|
DRW_shgroup_world_clip_planes_from_rv3d(grp, DRW_context_state_get()->rv3d);
|
|
|
|
}
|
2017-03-08 20:00:09 +01:00
|
|
|
return grp;
|
|
|
|
}
|
|
|
|
|
2019-01-26 15:00:03 +11:00
|
|
|
DRWShadingGroup *shgroup_instance(DRWPass *pass, struct GPUBatch *geom, eDRW_ShaderSlot shader_slot)
|
2017-04-10 22:22:37 +02:00
|
|
|
{
|
2019-01-26 15:00:03 +11:00
|
|
|
GPUShader *sh_inst = DRW_shader_get_builtin_shader(GPU_SHADER_INSTANCE_VARIYING_COLOR_VARIYING_SIZE, shader_slot);
|
2017-04-10 22:22:37 +02:00
|
|
|
|
2018-08-17 12:16:50 +02:00
|
|
|
DRW_shgroup_instance_format(g_formats.instance_sized, {
|
2019-01-29 07:46:25 +11:00
|
|
|
{"color", DRW_ATTR_FLOAT, 4},
|
|
|
|
{"size", DRW_ATTR_FLOAT, 1},
|
|
|
|
{"InstanceModelMatrix", DRW_ATTR_FLOAT, 16}
|
2018-02-14 18:59:15 +01:00
|
|
|
});
|
|
|
|
|
2018-08-17 12:16:50 +02:00
|
|
|
DRWShadingGroup *grp = DRW_shgroup_instance_create(sh_inst, pass, geom, g_formats.instance_sized);
|
2019-01-11 17:50:45 -02:00
|
|
|
DRW_shgroup_state_disable(grp, DRW_STATE_BLEND);
|
2019-01-26 15:00:03 +11:00
|
|
|
if (shader_slot == DRW_SHADER_SLOT_CLIPPED) {
|
|
|
|
DRW_shgroup_world_clip_planes_from_rv3d(grp, DRW_context_state_get()->rv3d);
|
|
|
|
}
|
2018-08-22 18:44:24 +02:00
|
|
|
return grp;
|
|
|
|
}
|
|
|
|
|
2019-01-26 15:00:03 +11:00
|
|
|
DRWShadingGroup *shgroup_instance_alpha(DRWPass *pass, struct GPUBatch *geom, eDRW_ShaderSlot shader_slot)
|
2018-08-22 18:44:24 +02:00
|
|
|
{
|
2019-01-26 15:00:03 +11:00
|
|
|
GPUShader *sh_inst = DRW_shader_get_builtin_shader(GPU_SHADER_INSTANCE_VARIYING_COLOR_VARIYING_SIZE, shader_slot);
|
2018-08-22 18:44:24 +02:00
|
|
|
|
|
|
|
DRW_shgroup_instance_format(g_formats.instance_sized, {
|
2019-01-29 07:46:25 +11:00
|
|
|
{"color", DRW_ATTR_FLOAT, 4},
|
|
|
|
{"size", DRW_ATTR_FLOAT, 1},
|
|
|
|
{"InstanceModelMatrix", DRW_ATTR_FLOAT, 16}
|
2018-08-22 18:44:24 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
DRWShadingGroup *grp = DRW_shgroup_instance_create(sh_inst, pass, geom, g_formats.instance_sized);
|
2019-01-26 15:00:03 +11:00
|
|
|
if (shader_slot == DRW_SHADER_SLOT_CLIPPED) {
|
|
|
|
DRW_shgroup_world_clip_planes_from_rv3d(grp, DRW_context_state_get()->rv3d);
|
|
|
|
}
|
2017-04-10 22:22:37 +02:00
|
|
|
return grp;
|
|
|
|
}
|
|
|
|
|
2019-01-26 15:00:03 +11:00
|
|
|
DRWShadingGroup *shgroup_instance_empty_axes(DRWPass *pass, struct GPUBatch *geom, eDRW_ShaderSlot shader_slot)
|
2017-03-08 20:00:09 +01:00
|
|
|
{
|
2019-01-26 15:00:03 +11:00
|
|
|
COMMON_Shaders *sh_data = &g_shaders[shader_slot];
|
|
|
|
const char *world_clip_lib_or_empty = (shader_slot == DRW_SHADER_SLOT_CLIPPED) ? datatoc_common_world_clip_lib_glsl : "";
|
|
|
|
const char *world_clip_def_or_empty = (shader_slot == DRW_SHADER_SLOT_CLIPPED) ? "#define USE_WORLD_CLIP_PLANES\n" : "";
|
|
|
|
if (sh_data->empty_axes_sh == NULL) {
|
|
|
|
sh_data->empty_axes_sh = DRW_shader_create_from_arrays({
|
|
|
|
.vert = (const char *[]){world_clip_lib_or_empty, datatoc_object_empty_axes_vert_glsl, NULL},
|
|
|
|
.frag = (const char *[]){datatoc_gpu_shader_flat_color_frag_glsl, NULL},
|
|
|
|
.defs = (const char *[]){world_clip_def_or_empty, NULL}});
|
2018-08-17 12:16:50 +02:00
|
|
|
}
|
2017-03-08 20:00:09 +01:00
|
|
|
|
2018-02-14 18:59:15 +01:00
|
|
|
DRW_shgroup_instance_format(g_formats.instance_sized, {
|
2019-01-29 07:46:25 +11:00
|
|
|
{"color", DRW_ATTR_FLOAT, 3},
|
|
|
|
{"size", DRW_ATTR_FLOAT, 1},
|
|
|
|
{"InstanceModelMatrix", DRW_ATTR_FLOAT, 16}
|
2018-02-14 18:59:15 +01:00
|
|
|
});
|
|
|
|
|
2019-01-26 15:00:03 +11:00
|
|
|
DRWShadingGroup *grp = DRW_shgroup_instance_create(sh_data->empty_axes_sh, pass, geom, g_formats.instance_sized);
|
2018-08-17 12:16:50 +02:00
|
|
|
DRW_shgroup_uniform_vec3(grp, "screenVecs[0]", DRW_viewport_screenvecs_get(), 2);
|
2019-01-26 15:00:03 +11:00
|
|
|
if (shader_slot == DRW_SHADER_SLOT_CLIPPED) {
|
|
|
|
DRW_shgroup_world_clip_planes_from_rv3d(grp, DRW_context_state_get()->rv3d);
|
|
|
|
}
|
2017-03-08 20:00:09 +01:00
|
|
|
return grp;
|
|
|
|
}
|
2018-04-17 13:01:01 +02:00
|
|
|
|
2018-07-18 00:12:21 +02:00
|
|
|
DRWShadingGroup *shgroup_instance_outline(DRWPass *pass, struct GPUBatch *geom, int *baseid)
|
2018-04-17 13:01:01 +02:00
|
|
|
{
|
|
|
|
GPUShader *sh_inst = GPU_shader_get_builtin_shader(GPU_SHADER_INSTANCE_VARIYING_ID_VARIYING_SIZE);
|
|
|
|
|
2018-04-17 17:00:24 +02:00
|
|
|
DRW_shgroup_instance_format(g_formats.instance_outline, {
|
2019-01-29 07:46:25 +11:00
|
|
|
{"callId", DRW_ATTR_INT, 1},
|
|
|
|
{"size", DRW_ATTR_FLOAT, 1},
|
|
|
|
{"InstanceModelMatrix", DRW_ATTR_FLOAT, 16}
|
2018-04-17 13:01:01 +02:00
|
|
|
});
|
|
|
|
|
2018-04-17 17:00:24 +02:00
|
|
|
DRWShadingGroup *grp = DRW_shgroup_instance_create(sh_inst, pass, geom, g_formats.instance_outline);
|
2018-04-17 13:01:01 +02:00
|
|
|
DRW_shgroup_uniform_int(grp, "baseId", baseid, 1);
|
|
|
|
|
|
|
|
return grp;
|
|
|
|
}
|
2017-03-08 20:00:09 +01:00
|
|
|
|
2019-01-25 07:13:02 +11:00
|
|
|
DRWShadingGroup *shgroup_camera_instance(DRWPass *pass, struct GPUBatch *geom, eDRW_ShaderSlot shader_slot)
|
2017-03-08 20:00:09 +01:00
|
|
|
{
|
2019-01-25 07:13:02 +11:00
|
|
|
GPUShader *sh_inst = DRW_shader_get_builtin_shader(GPU_SHADER_CAMERA, shader_slot);
|
2017-03-08 20:00:09 +01:00
|
|
|
|
2018-02-14 18:59:15 +01:00
|
|
|
DRW_shgroup_instance_format(g_formats.instance_camera, {
|
2019-01-29 07:46:25 +11:00
|
|
|
{"color", DRW_ATTR_FLOAT, 3},
|
|
|
|
{"corners", DRW_ATTR_FLOAT, 8},
|
|
|
|
{"depth", DRW_ATTR_FLOAT, 1},
|
|
|
|
{"tria", DRW_ATTR_FLOAT, 4},
|
|
|
|
{"InstanceModelMatrix", DRW_ATTR_FLOAT, 16}
|
2018-02-14 18:59:15 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
DRWShadingGroup *grp = DRW_shgroup_instance_create(sh_inst, pass, geom, g_formats.instance_camera);
|
2019-01-25 07:13:02 +11:00
|
|
|
if (shader_slot == DRW_SHADER_SLOT_CLIPPED) {
|
|
|
|
DRW_shgroup_world_clip_planes_from_rv3d(grp, DRW_context_state_get()->rv3d);
|
|
|
|
}
|
2017-03-08 20:00:09 +01:00
|
|
|
return grp;
|
|
|
|
}
|
|
|
|
|
2018-07-18 00:12:21 +02:00
|
|
|
DRWShadingGroup *shgroup_distance_lines_instance(DRWPass *pass, struct GPUBatch *geom)
|
2017-03-08 20:00:09 +01:00
|
|
|
{
|
|
|
|
GPUShader *sh_inst = GPU_shader_get_builtin_shader(GPU_SHADER_DISTANCE_LINES);
|
|
|
|
static float point_size = 4.0f;
|
|
|
|
|
2018-02-14 18:59:15 +01:00
|
|
|
DRW_shgroup_instance_format(g_formats.instance_distance_lines, {
|
2019-01-29 07:46:25 +11:00
|
|
|
{"color", DRW_ATTR_FLOAT, 3},
|
|
|
|
{"start", DRW_ATTR_FLOAT, 1},
|
|
|
|
{"end", DRW_ATTR_FLOAT, 1},
|
|
|
|
{"InstanceModelMatrix", DRW_ATTR_FLOAT, 16}
|
2018-02-14 18:59:15 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
DRWShadingGroup *grp = DRW_shgroup_instance_create(sh_inst, pass, geom, g_formats.instance_distance_lines);
|
2017-03-08 20:00:09 +01:00
|
|
|
DRW_shgroup_uniform_float(grp, "size", &point_size, 1);
|
|
|
|
|
|
|
|
return grp;
|
|
|
|
}
|
|
|
|
|
2018-07-18 00:12:21 +02:00
|
|
|
DRWShadingGroup *shgroup_spot_instance(DRWPass *pass, struct GPUBatch *geom)
|
2017-03-08 20:00:09 +01:00
|
|
|
{
|
|
|
|
GPUShader *sh_inst = GPU_shader_get_builtin_shader(GPU_SHADER_INSTANCE_EDGES_VARIYING_COLOR);
|
2018-01-03 20:39:44 +01:00
|
|
|
static const int True = true;
|
|
|
|
static const int False = false;
|
2017-03-08 20:00:09 +01:00
|
|
|
|
2018-02-14 18:59:15 +01:00
|
|
|
DRW_shgroup_instance_format(g_formats.instance_spot, {
|
2019-01-29 07:46:25 +11:00
|
|
|
{"color", DRW_ATTR_FLOAT, 3},
|
|
|
|
{"InstanceModelMatrix", DRW_ATTR_FLOAT, 16}
|
2018-02-14 18:59:15 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
DRWShadingGroup *grp = DRW_shgroup_instance_create(sh_inst, pass, geom, g_formats.instance_spot);
|
2017-03-08 20:00:09 +01:00
|
|
|
DRW_shgroup_uniform_bool(grp, "drawFront", &False, 1);
|
|
|
|
DRW_shgroup_uniform_bool(grp, "drawBack", &False, 1);
|
|
|
|
DRW_shgroup_uniform_bool(grp, "drawSilhouette", &True, 1);
|
|
|
|
|
|
|
|
return grp;
|
|
|
|
}
|
|
|
|
|
2018-05-06 16:09:25 +02:00
|
|
|
DRWShadingGroup *shgroup_instance_bone_axes(DRWPass *pass)
|
|
|
|
{
|
2019-01-26 15:00:03 +11:00
|
|
|
COMMON_Shaders *sh_data = &g_shaders[DRW_SHADER_SLOT_DEFAULT];
|
|
|
|
if (sh_data->bone_axes == NULL) {
|
|
|
|
sh_data->bone_axes = DRW_shader_create(
|
|
|
|
datatoc_armature_axes_vert_glsl, NULL,
|
|
|
|
datatoc_gpu_shader_flat_color_frag_glsl, NULL);
|
2018-05-06 16:09:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
DRW_shgroup_instance_format(g_formats.instance_color, {
|
2019-01-29 07:46:25 +11:00
|
|
|
{"InstanceModelMatrix", DRW_ATTR_FLOAT, 16},
|
|
|
|
{"color", DRW_ATTR_FLOAT, 4}
|
2018-05-06 16:09:25 +02:00
|
|
|
});
|
|
|
|
|
2018-05-26 10:41:25 +02:00
|
|
|
DRWShadingGroup *grp = DRW_shgroup_instance_create(
|
2019-01-26 15:00:03 +11:00
|
|
|
sh_data->bone_axes,
|
2018-05-26 10:41:25 +02:00
|
|
|
pass, DRW_cache_bone_arrows_get(),
|
|
|
|
g_formats.instance_color);
|
2018-05-06 16:09:25 +02:00
|
|
|
DRW_shgroup_uniform_vec3(grp, "screenVecs[0]", DRW_viewport_screenvecs_get(), 2);
|
|
|
|
|
|
|
|
return grp;
|
|
|
|
}
|
|
|
|
|
2018-04-30 22:47:40 +02:00
|
|
|
DRWShadingGroup *shgroup_instance_bone_envelope_outline(DRWPass *pass)
|
2017-05-17 12:34:06 +02:00
|
|
|
{
|
2019-01-26 15:00:03 +11:00
|
|
|
COMMON_Shaders *sh_data = &g_shaders[DRW_SHADER_SLOT_DEFAULT];
|
|
|
|
if (sh_data->bone_envelope_outline == NULL) {
|
|
|
|
sh_data->bone_envelope_outline = DRW_shader_create(
|
|
|
|
datatoc_armature_envelope_outline_vert_glsl, NULL,
|
|
|
|
datatoc_gpu_shader_flat_color_frag_glsl, NULL);
|
2018-04-30 22:47:40 +02:00
|
|
|
}
|
2017-05-17 12:34:06 +02:00
|
|
|
|
2018-05-05 20:27:22 +02:00
|
|
|
DRW_shgroup_instance_format(g_formats.instance_bone_envelope_outline, {
|
2019-01-29 07:46:25 +11:00
|
|
|
{"headSphere", DRW_ATTR_FLOAT, 4},
|
|
|
|
{"tailSphere", DRW_ATTR_FLOAT, 4},
|
|
|
|
{"outlineColorSize", DRW_ATTR_FLOAT, 4},
|
|
|
|
{"xAxis", DRW_ATTR_FLOAT, 3}
|
2018-02-14 18:59:15 +01:00
|
|
|
});
|
|
|
|
|
2018-05-26 10:41:25 +02:00
|
|
|
DRWShadingGroup *grp = DRW_shgroup_instance_create(
|
2019-01-26 15:00:03 +11:00
|
|
|
sh_data->bone_envelope_outline,
|
2018-05-26 10:41:25 +02:00
|
|
|
pass, DRW_cache_bone_envelope_outline_get(),
|
|
|
|
g_formats.instance_bone_envelope_outline);
|
2018-04-30 22:47:40 +02:00
|
|
|
DRW_shgroup_uniform_vec2(grp, "viewportSize", DRW_viewport_size_get(), 1);
|
2017-05-17 12:34:06 +02:00
|
|
|
|
|
|
|
return grp;
|
|
|
|
}
|
|
|
|
|
2018-05-02 08:58:29 +02:00
|
|
|
DRWShadingGroup *shgroup_instance_bone_envelope_distance(DRWPass *pass)
|
|
|
|
{
|
2019-01-26 15:00:03 +11:00
|
|
|
COMMON_Shaders *sh_data = &g_shaders[DRW_SHADER_SLOT_DEFAULT];
|
|
|
|
if (sh_data->bone_envelope_distance == NULL) {
|
|
|
|
sh_data->bone_envelope_distance = DRW_shader_create(
|
|
|
|
datatoc_armature_envelope_solid_vert_glsl, NULL,
|
|
|
|
datatoc_armature_envelope_distance_frag_glsl, NULL);
|
2018-05-02 08:58:29 +02:00
|
|
|
}
|
|
|
|
|
2018-05-05 20:51:16 +02:00
|
|
|
DRW_shgroup_instance_format(g_formats.instance_bone_envelope_distance, {
|
2019-01-29 07:46:25 +11:00
|
|
|
{"headSphere", DRW_ATTR_FLOAT, 4},
|
|
|
|
{"tailSphere", DRW_ATTR_FLOAT, 4},
|
|
|
|
{"xAxis", DRW_ATTR_FLOAT, 3}
|
2018-05-02 08:58:29 +02:00
|
|
|
});
|
|
|
|
|
2018-05-26 10:41:25 +02:00
|
|
|
DRWShadingGroup *grp = DRW_shgroup_instance_create(
|
2019-01-26 15:00:03 +11:00
|
|
|
sh_data->bone_envelope_distance,
|
2018-05-26 10:41:25 +02:00
|
|
|
pass, DRW_cache_bone_envelope_solid_get(),
|
|
|
|
g_formats.instance_bone_envelope_distance);
|
2018-05-02 08:58:29 +02:00
|
|
|
|
|
|
|
return grp;
|
|
|
|
}
|
|
|
|
|
2018-07-30 14:17:53 +02:00
|
|
|
DRWShadingGroup *shgroup_instance_bone_envelope_solid(DRWPass *pass, bool transp)
|
2017-05-18 11:41:59 +02:00
|
|
|
{
|
2019-01-26 15:00:03 +11:00
|
|
|
COMMON_Shaders *sh_data = &g_shaders[DRW_SHADER_SLOT_DEFAULT];
|
|
|
|
if (sh_data->bone_envelope == NULL) {
|
|
|
|
sh_data->bone_envelope = DRW_shader_create(
|
|
|
|
datatoc_armature_envelope_solid_vert_glsl, NULL,
|
|
|
|
datatoc_armature_envelope_solid_frag_glsl, "#define SMOOTH_ENVELOPE\n");
|
2018-04-29 19:39:44 +02:00
|
|
|
}
|
2017-05-18 11:41:59 +02:00
|
|
|
|
2018-04-30 22:47:40 +02:00
|
|
|
DRW_shgroup_instance_format(g_formats.instance_bone_envelope, {
|
2019-01-29 07:46:25 +11:00
|
|
|
{"headSphere", DRW_ATTR_FLOAT, 4},
|
|
|
|
{"tailSphere", DRW_ATTR_FLOAT, 4},
|
|
|
|
{"boneColor", DRW_ATTR_FLOAT, 3},
|
|
|
|
{"stateColor", DRW_ATTR_FLOAT, 3},
|
|
|
|
{"xAxis", DRW_ATTR_FLOAT, 3}
|
2018-02-14 18:59:15 +01:00
|
|
|
});
|
|
|
|
|
2018-05-26 10:41:25 +02:00
|
|
|
DRWShadingGroup *grp = DRW_shgroup_instance_create(
|
2019-01-26 15:00:03 +11:00
|
|
|
sh_data->bone_envelope,
|
2018-05-26 10:41:25 +02:00
|
|
|
pass, DRW_cache_bone_envelope_solid_get(),
|
|
|
|
g_formats.instance_bone_envelope);
|
2018-07-30 14:17:53 +02:00
|
|
|
DRW_shgroup_uniform_float_copy(grp, "alpha", transp ? 0.6f : 1.0f);
|
2017-05-18 11:41:59 +02:00
|
|
|
|
|
|
|
return grp;
|
|
|
|
}
|
|
|
|
|
2018-05-02 21:26:43 -03:00
|
|
|
DRWShadingGroup *shgroup_instance_mball_handles(DRWPass *pass)
|
2017-11-16 15:12:32 -02:00
|
|
|
{
|
2019-01-26 15:00:03 +11:00
|
|
|
COMMON_Shaders *sh_data = &g_shaders[DRW_SHADER_SLOT_DEFAULT];
|
|
|
|
if (sh_data->mball_handles == NULL) {
|
|
|
|
sh_data->mball_handles = DRW_shader_create(
|
|
|
|
datatoc_object_mball_handles_vert_glsl, NULL,
|
|
|
|
datatoc_gpu_shader_flat_color_frag_glsl, NULL);
|
2018-05-03 09:11:02 -03:00
|
|
|
}
|
2017-11-16 15:12:32 -02:00
|
|
|
|
2018-02-16 02:01:09 -02:00
|
|
|
DRW_shgroup_instance_format(g_formats.instance_mball_handles, {
|
2019-01-29 07:46:25 +11:00
|
|
|
{"ScaleTranslationMatrix", DRW_ATTR_FLOAT, 12},
|
|
|
|
{"radius", DRW_ATTR_FLOAT, 1},
|
|
|
|
{"color", DRW_ATTR_FLOAT, 3}
|
2018-02-14 18:59:15 +01:00
|
|
|
});
|
|
|
|
|
2018-05-26 10:41:25 +02:00
|
|
|
DRWShadingGroup *grp = DRW_shgroup_instance_create(
|
2019-01-26 15:00:03 +11:00
|
|
|
sh_data->mball_handles, pass,
|
2018-05-26 10:41:25 +02:00
|
|
|
DRW_cache_screenspace_circle_get(),
|
|
|
|
g_formats.instance_mball_handles);
|
2017-11-16 15:12:32 -02:00
|
|
|
DRW_shgroup_uniform_vec3(grp, "screen_vecs[0]", DRW_viewport_screenvecs_get(), 2);
|
|
|
|
|
|
|
|
return grp;
|
|
|
|
}
|
|
|
|
|
2018-04-22 22:49:36 +02:00
|
|
|
/* Only works with batches with adjacency infos. */
|
2018-07-18 00:12:21 +02:00
|
|
|
DRWShadingGroup *shgroup_instance_bone_shape_outline(DRWPass *pass, struct GPUBatch *geom)
|
2018-04-22 22:49:36 +02:00
|
|
|
{
|
2019-01-26 15:00:03 +11:00
|
|
|
COMMON_Shaders *sh_data = &g_shaders[DRW_SHADER_SLOT_DEFAULT];
|
|
|
|
if (sh_data->shape_outline == NULL) {
|
|
|
|
sh_data->shape_outline = DRW_shader_create(
|
|
|
|
datatoc_armature_shape_outline_vert_glsl,
|
|
|
|
datatoc_armature_shape_outline_geom_glsl,
|
|
|
|
datatoc_gpu_shader_flat_color_frag_glsl,
|
|
|
|
NULL);
|
2018-04-22 22:49:36 +02:00
|
|
|
}
|
|
|
|
|
2018-05-05 20:27:22 +02:00
|
|
|
DRW_shgroup_instance_format(g_formats.instance_bone_outline, {
|
2019-01-29 07:46:25 +11:00
|
|
|
{"InstanceModelMatrix", DRW_ATTR_FLOAT, 16},
|
|
|
|
{"outlineColorSize", DRW_ATTR_FLOAT, 4}
|
2018-04-22 22:49:36 +02:00
|
|
|
});
|
|
|
|
|
2018-05-26 10:41:25 +02:00
|
|
|
DRWShadingGroup *grp = DRW_shgroup_instance_create(
|
2019-01-26 15:00:03 +11:00
|
|
|
sh_data->shape_outline,
|
2018-05-26 10:41:25 +02:00
|
|
|
pass, geom, g_formats.instance_bone_outline);
|
2018-04-22 22:49:36 +02:00
|
|
|
DRW_shgroup_uniform_vec2(grp, "viewportSize", DRW_viewport_size_get(), 1);
|
|
|
|
|
|
|
|
return grp;
|
|
|
|
}
|
|
|
|
|
2018-07-30 14:17:53 +02:00
|
|
|
DRWShadingGroup *shgroup_instance_bone_shape_solid(DRWPass *pass, struct GPUBatch *geom, bool transp)
|
2018-05-05 20:51:16 +02:00
|
|
|
{
|
2019-01-26 15:00:03 +11:00
|
|
|
COMMON_Shaders *sh_data = &g_shaders[DRW_SHADER_SLOT_DEFAULT];
|
|
|
|
if (sh_data->shape_solid == NULL) {
|
|
|
|
sh_data->shape_solid = DRW_shader_create(
|
|
|
|
datatoc_armature_shape_solid_vert_glsl, NULL,
|
|
|
|
datatoc_armature_shape_solid_frag_glsl, NULL);
|
2018-05-05 20:51:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
DRW_shgroup_instance_format(g_formats.instance_bone, {
|
2019-01-29 07:46:25 +11:00
|
|
|
{"InstanceModelMatrix", DRW_ATTR_FLOAT, 16},
|
|
|
|
{"boneColor", DRW_ATTR_FLOAT, 3},
|
|
|
|
{"stateColor", DRW_ATTR_FLOAT, 3}
|
2018-05-05 20:51:16 +02:00
|
|
|
});
|
|
|
|
|
2018-05-26 10:41:25 +02:00
|
|
|
DRWShadingGroup *grp = DRW_shgroup_instance_create(
|
2019-01-26 15:00:03 +11:00
|
|
|
sh_data->shape_solid,
|
2018-05-26 10:41:25 +02:00
|
|
|
pass, geom, g_formats.instance_bone);
|
2018-07-30 14:17:53 +02:00
|
|
|
DRW_shgroup_uniform_float_copy(grp, "alpha", transp ? 0.6f : 1.0f);
|
2018-05-05 20:51:16 +02:00
|
|
|
|
|
|
|
return grp;
|
|
|
|
}
|
|
|
|
|
2018-07-30 14:17:53 +02:00
|
|
|
DRWShadingGroup *shgroup_instance_bone_sphere_solid(DRWPass *pass, bool transp)
|
2018-04-27 16:27:47 +02:00
|
|
|
{
|
2019-01-26 15:00:03 +11:00
|
|
|
COMMON_Shaders *sh_data = &g_shaders[DRW_SHADER_SLOT_DEFAULT];
|
|
|
|
if (sh_data->bone_sphere == NULL) {
|
|
|
|
sh_data->bone_sphere = DRW_shader_create(
|
|
|
|
datatoc_armature_sphere_solid_vert_glsl, NULL,
|
|
|
|
datatoc_armature_sphere_solid_frag_glsl, NULL);
|
2018-04-27 16:27:47 +02:00
|
|
|
}
|
|
|
|
|
2018-05-05 20:51:16 +02:00
|
|
|
DRW_shgroup_instance_format(g_formats.instance_bone, {
|
2019-01-29 07:46:25 +11:00
|
|
|
{"InstanceModelMatrix", DRW_ATTR_FLOAT, 16},
|
|
|
|
{"boneColor", DRW_ATTR_FLOAT, 3},
|
|
|
|
{"stateColor", DRW_ATTR_FLOAT, 3}
|
2018-04-27 16:27:47 +02:00
|
|
|
});
|
|
|
|
|
2018-05-26 10:41:25 +02:00
|
|
|
DRWShadingGroup *grp = DRW_shgroup_instance_create(
|
2019-01-26 15:00:03 +11:00
|
|
|
sh_data->bone_sphere,
|
2018-05-26 10:41:25 +02:00
|
|
|
pass, DRW_cache_bone_point_get(), g_formats.instance_bone);
|
2018-07-30 14:17:53 +02:00
|
|
|
/* More transparent than the shape to be less distractive. */
|
|
|
|
DRW_shgroup_uniform_float_copy(grp, "alpha", transp ? 0.4f : 1.0f);
|
2018-04-27 16:27:47 +02:00
|
|
|
|
|
|
|
return grp;
|
|
|
|
}
|
|
|
|
|
2018-04-30 22:47:40 +02:00
|
|
|
DRWShadingGroup *shgroup_instance_bone_sphere_outline(DRWPass *pass)
|
2018-04-27 16:27:47 +02:00
|
|
|
{
|
2019-01-26 15:00:03 +11:00
|
|
|
COMMON_Shaders *sh_data = &g_shaders[DRW_SHADER_SLOT_DEFAULT];
|
|
|
|
if (sh_data->bone_sphere_outline == NULL) {
|
|
|
|
sh_data->bone_sphere_outline = DRW_shader_create(
|
|
|
|
datatoc_armature_sphere_outline_vert_glsl, NULL,
|
|
|
|
datatoc_gpu_shader_flat_color_frag_glsl, NULL);
|
2018-04-27 16:27:47 +02:00
|
|
|
}
|
|
|
|
|
2018-05-05 20:27:22 +02:00
|
|
|
DRW_shgroup_instance_format(g_formats.instance_bone_outline, {
|
2019-01-29 07:46:25 +11:00
|
|
|
{"InstanceModelMatrix", DRW_ATTR_FLOAT, 16},
|
|
|
|
{"outlineColorSize", DRW_ATTR_FLOAT, 4}
|
2018-04-27 16:27:47 +02:00
|
|
|
});
|
|
|
|
|
2018-05-26 10:41:25 +02:00
|
|
|
DRWShadingGroup *grp = DRW_shgroup_instance_create(
|
2019-01-26 15:00:03 +11:00
|
|
|
sh_data->bone_sphere_outline,
|
2018-05-26 10:41:25 +02:00
|
|
|
pass, DRW_cache_bone_point_wire_outline_get(),
|
|
|
|
g_formats.instance_bone_outline);
|
2018-04-27 16:27:47 +02:00
|
|
|
DRW_shgroup_uniform_vec2(grp, "viewportSize", DRW_viewport_size_get(), 1);
|
|
|
|
|
|
|
|
return grp;
|
|
|
|
}
|
2018-04-22 22:49:36 +02:00
|
|
|
|
2018-05-08 12:05:06 +02:00
|
|
|
DRWShadingGroup *shgroup_instance_bone_stick(DRWPass *pass)
|
|
|
|
{
|
2019-01-26 15:00:03 +11:00
|
|
|
COMMON_Shaders *sh_data = &g_shaders[DRW_SHADER_SLOT_DEFAULT];
|
|
|
|
if (sh_data->bone_stick == NULL) {
|
|
|
|
sh_data->bone_stick = DRW_shader_create(
|
|
|
|
datatoc_armature_stick_vert_glsl, NULL,
|
|
|
|
datatoc_armature_stick_frag_glsl, NULL);
|
2018-05-08 12:05:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
DRW_shgroup_instance_format(g_formats.instance_bone_stick, {
|
2019-01-29 07:46:25 +11:00
|
|
|
{"boneStart", DRW_ATTR_FLOAT, 3},
|
|
|
|
{"boneEnd", DRW_ATTR_FLOAT, 3},
|
|
|
|
{"wireColor", DRW_ATTR_FLOAT, 4}, /* TODO port theses to uchar color */
|
|
|
|
{"boneColor", DRW_ATTR_FLOAT, 4},
|
|
|
|
{"headColor", DRW_ATTR_FLOAT, 4},
|
|
|
|
{"tailColor", DRW_ATTR_FLOAT, 4}
|
2018-05-08 12:05:06 +02:00
|
|
|
});
|
|
|
|
|
2018-05-26 10:41:25 +02:00
|
|
|
DRWShadingGroup *grp = DRW_shgroup_instance_create(
|
2019-01-26 15:00:03 +11:00
|
|
|
sh_data->bone_stick,
|
2018-05-26 10:41:25 +02:00
|
|
|
pass, DRW_cache_bone_stick_get(),
|
|
|
|
g_formats.instance_bone_stick);
|
2018-05-08 12:05:06 +02:00
|
|
|
DRW_shgroup_uniform_vec2(grp, "viewportSize", DRW_viewport_size_get(), 1);
|
2018-11-02 16:27:21 +01:00
|
|
|
DRW_shgroup_uniform_float_copy(grp, "stickSize", 5.0f * U.pixelsize);
|
2018-05-08 12:05:06 +02:00
|
|
|
|
|
|
|
return grp;
|
|
|
|
}
|
2018-04-22 22:49:36 +02:00
|
|
|
|
2018-10-03 15:42:05 +02:00
|
|
|
struct DRWShadingGroup *shgroup_instance_bone_dof(struct DRWPass *pass, struct GPUBatch *geom)
|
|
|
|
{
|
2019-01-26 15:00:03 +11:00
|
|
|
COMMON_Shaders *sh_data = &g_shaders[DRW_SHADER_SLOT_DEFAULT];
|
|
|
|
if (sh_data->bone_dofs == NULL) {
|
|
|
|
sh_data->bone_dofs = DRW_shader_create(
|
|
|
|
datatoc_armature_dof_vert_glsl, NULL,
|
|
|
|
datatoc_gpu_shader_flat_color_frag_glsl, NULL);
|
2018-10-03 15:42:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
DRW_shgroup_instance_format(g_formats.instance_bone_dof, {
|
2019-01-29 07:46:25 +11:00
|
|
|
{"InstanceModelMatrix", DRW_ATTR_FLOAT, 16},
|
|
|
|
{"color", DRW_ATTR_FLOAT, 4},
|
|
|
|
{"amin", DRW_ATTR_FLOAT, 2},
|
|
|
|
{"amax", DRW_ATTR_FLOAT, 2},
|
2018-10-03 15:42:05 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
DRWShadingGroup *grp = DRW_shgroup_instance_create(
|
2019-01-26 15:00:03 +11:00
|
|
|
sh_data->bone_dofs,
|
2018-10-03 15:42:05 +02:00
|
|
|
pass, geom,
|
|
|
|
g_formats.instance_bone_dof);
|
|
|
|
|
|
|
|
return grp;
|
|
|
|
}
|
|
|
|
|
2018-06-01 16:38:21 +02:00
|
|
|
struct GPUShader *mpath_line_shader_get(void)
|
|
|
|
{
|
2019-01-26 15:00:03 +11:00
|
|
|
COMMON_Shaders *sh_data = &g_shaders[DRW_SHADER_SLOT_DEFAULT];
|
|
|
|
if (sh_data->mpath_line_sh == NULL) {
|
|
|
|
sh_data->mpath_line_sh = DRW_shader_create_with_lib(
|
2018-06-01 16:38:21 +02:00
|
|
|
datatoc_animviz_mpath_lines_vert_glsl,
|
|
|
|
datatoc_animviz_mpath_lines_geom_glsl,
|
|
|
|
datatoc_gpu_shader_3D_smooth_color_frag_glsl,
|
|
|
|
datatoc_common_globals_lib_glsl,
|
|
|
|
NULL);
|
|
|
|
}
|
2019-01-26 15:00:03 +11:00
|
|
|
return sh_data->mpath_line_sh;
|
2018-06-01 16:38:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
struct GPUShader *mpath_points_shader_get(void)
|
|
|
|
{
|
2019-01-26 15:00:03 +11:00
|
|
|
COMMON_Shaders *sh_data = &g_shaders[DRW_SHADER_SLOT_DEFAULT];
|
|
|
|
if (sh_data->mpath_points_sh == NULL) {
|
|
|
|
sh_data->mpath_points_sh = DRW_shader_create_with_lib(
|
2018-06-01 16:38:21 +02:00
|
|
|
datatoc_animviz_mpath_points_vert_glsl,
|
|
|
|
NULL,
|
|
|
|
datatoc_gpu_shader_point_varying_color_frag_glsl,
|
|
|
|
datatoc_common_globals_lib_glsl,
|
|
|
|
NULL);
|
|
|
|
}
|
2019-01-26 15:00:03 +11:00
|
|
|
return sh_data->mpath_points_sh;
|
2018-06-01 16:38:21 +02:00
|
|
|
}
|
|
|
|
|
2018-07-16 15:01:44 +02:00
|
|
|
struct GPUShader *volume_velocity_shader_get(bool use_needle)
|
|
|
|
{
|
2019-01-26 15:00:03 +11:00
|
|
|
COMMON_Shaders *sh_data = &g_shaders[DRW_SHADER_SLOT_DEFAULT];
|
2018-07-16 15:01:44 +02:00
|
|
|
if (use_needle) {
|
2019-01-26 15:00:03 +11:00
|
|
|
if (sh_data->volume_velocity_needle_sh == NULL) {
|
|
|
|
sh_data->volume_velocity_needle_sh = DRW_shader_create(
|
2018-07-16 15:01:44 +02:00
|
|
|
datatoc_volume_velocity_vert_glsl, NULL,
|
|
|
|
datatoc_gpu_shader_flat_color_frag_glsl, "#define USE_NEEDLE");
|
|
|
|
}
|
2019-01-26 15:00:03 +11:00
|
|
|
return sh_data->volume_velocity_needle_sh;
|
2018-07-16 15:01:44 +02:00
|
|
|
}
|
|
|
|
else {
|
2019-01-26 15:00:03 +11:00
|
|
|
if (sh_data->volume_velocity_sh == NULL) {
|
|
|
|
sh_data->volume_velocity_sh = DRW_shader_create(
|
2018-07-16 15:01:44 +02:00
|
|
|
datatoc_volume_velocity_vert_glsl, NULL,
|
|
|
|
datatoc_gpu_shader_flat_color_frag_glsl, NULL);
|
|
|
|
}
|
2019-01-26 15:00:03 +11:00
|
|
|
return sh_data->volume_velocity_sh;
|
2018-07-16 15:01:44 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-10 22:23:33 +02:00
|
|
|
/* ******************************************** COLOR UTILS *********************************************** */
|
2017-03-08 20:00:09 +01:00
|
|
|
|
|
|
|
/* TODO FINISH */
|
2017-04-15 14:07:57 +10:00
|
|
|
/**
|
|
|
|
* Get the wire color theme_id of an object based on it's state
|
|
|
|
* \a r_color is a way to get a pointer to the static color var associated
|
|
|
|
*/
|
2017-11-22 10:52:39 -02:00
|
|
|
int DRW_object_wire_theme_get(Object *ob, ViewLayer *view_layer, float **r_color)
|
2017-03-08 20:00:09 +01:00
|
|
|
{
|
2018-02-06 16:10:03 +11:00
|
|
|
const DRWContextState *draw_ctx = DRW_context_state_get();
|
2018-12-18 21:20:04 +11:00
|
|
|
const bool is_edit = (draw_ctx->object_mode & OB_MODE_EDIT) && (ob->mode & OB_MODE_EDIT);
|
2017-11-22 10:52:39 -02:00
|
|
|
const bool active = (view_layer->basact && view_layer->basact->object == ob);
|
2017-03-08 20:00:09 +01:00
|
|
|
/* confusing logic here, there are 2 methods of setting the color
|
|
|
|
* 'colortab[colindex]' and 'theme_id', colindex overrides theme_id.
|
|
|
|
*
|
|
|
|
* note: no theme yet for 'colindex' */
|
|
|
|
int theme_id = is_edit ? TH_WIRE_EDIT : TH_WIRE;
|
|
|
|
|
2018-12-14 15:20:28 +01:00
|
|
|
if (is_edit) {
|
|
|
|
/* fallback to TH_WIRE */
|
|
|
|
}
|
|
|
|
else if (((G.moving & G_TRANSFORM_OBJ) != 0) &&
|
|
|
|
((ob->base_flag & BASE_SELECTED) != 0))
|
2017-03-08 20:00:09 +01:00
|
|
|
{
|
|
|
|
theme_id = TH_TRANSFORM;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* Sets the 'theme_id' or fallback to wire */
|
2018-05-04 11:36:50 +02:00
|
|
|
if ((ob->base_flag & BASE_SELECTED) != 0) {
|
|
|
|
theme_id = (active) ? TH_ACTIVE : TH_SELECT;
|
2017-03-08 20:00:09 +01:00
|
|
|
}
|
|
|
|
else {
|
2018-05-04 11:36:50 +02:00
|
|
|
if (ob->type == OB_LAMP) theme_id = TH_LAMP;
|
|
|
|
else if (ob->type == OB_SPEAKER) theme_id = TH_SPEAKER;
|
|
|
|
else if (ob->type == OB_CAMERA) theme_id = TH_CAMERA;
|
|
|
|
else if (ob->type == OB_EMPTY) theme_id = TH_EMPTY;
|
|
|
|
else if (ob->type == OB_LIGHTPROBE) theme_id = TH_EMPTY; /* TODO add lightprobe color */
|
|
|
|
/* fallback to TH_WIRE */
|
2017-03-08 20:00:09 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-15 14:07:57 +10:00
|
|
|
if (r_color != NULL) {
|
2019-01-11 14:22:40 +11:00
|
|
|
if (UNLIKELY(ob->base_flag & BASE_FROM_SET)) {
|
2019-01-22 12:09:27 +11:00
|
|
|
*r_color = G_draw.block.colorDupli;
|
2019-01-11 14:22:40 +11:00
|
|
|
}
|
2019-01-15 23:27:54 +11:00
|
|
|
else if (UNLIKELY(ob->base_flag & BASE_FROM_DUPLI)) {
|
2019-01-10 16:51:36 +11:00
|
|
|
switch (theme_id) {
|
|
|
|
case TH_ACTIVE:
|
2019-01-22 12:09:27 +11:00
|
|
|
case TH_SELECT: *r_color = G_draw.block.colorDupliSelect; break;
|
|
|
|
case TH_TRANSFORM: *r_color = G_draw.block.colorTransform; break;
|
|
|
|
default: *r_color = G_draw.block.colorDupli; break;
|
2019-01-10 16:51:36 +11:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
switch (theme_id) {
|
2019-01-22 12:09:27 +11:00
|
|
|
case TH_WIRE_EDIT: *r_color = G_draw.block.colorWireEdit; break;
|
|
|
|
case TH_ACTIVE: *r_color = G_draw.block.colorActive; break;
|
|
|
|
case TH_SELECT: *r_color = G_draw.block.colorSelect; break;
|
|
|
|
case TH_TRANSFORM: *r_color = G_draw.block.colorTransform; break;
|
|
|
|
case TH_SPEAKER: *r_color = G_draw.block.colorSpeaker; break;
|
|
|
|
case TH_CAMERA: *r_color = G_draw.block.colorCamera; break;
|
|
|
|
case TH_EMPTY: *r_color = G_draw.block.colorEmpty; break;
|
|
|
|
case TH_LAMP: *r_color = G_draw.block.colorLamp; break;
|
|
|
|
default: *r_color = G_draw.block.colorWire; break;
|
2019-01-10 16:51:36 +11:00
|
|
|
}
|
2017-03-08 20:00:09 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return theme_id;
|
|
|
|
}
|
2017-04-10 22:22:37 +02:00
|
|
|
|
2018-09-04 18:44:05 +10:00
|
|
|
/* XXX This is very stupid, better find something more general. */
|
2017-04-10 22:22:37 +02:00
|
|
|
float *DRW_color_background_blend_get(int theme_id)
|
|
|
|
{
|
|
|
|
static float colors[11][4];
|
|
|
|
float *ret;
|
|
|
|
|
|
|
|
switch (theme_id) {
|
|
|
|
case TH_WIRE_EDIT: ret = colors[0]; break;
|
|
|
|
case TH_ACTIVE: ret = colors[1]; break;
|
|
|
|
case TH_SELECT: ret = colors[2]; break;
|
|
|
|
case TH_TRANSFORM: ret = colors[5]; break;
|
2018-05-24 12:01:25 +02:00
|
|
|
case TH_SPEAKER: ret = colors[6]; break;
|
|
|
|
case TH_CAMERA: ret = colors[7]; break;
|
|
|
|
case TH_EMPTY: ret = colors[8]; break;
|
|
|
|
case TH_LAMP: ret = colors[9]; break;
|
2017-04-10 22:22:37 +02:00
|
|
|
default: ret = colors[10]; break;
|
|
|
|
}
|
|
|
|
|
2017-04-11 16:13:09 +02:00
|
|
|
UI_GetThemeColorBlendShade4fv(theme_id, TH_BACK, 0.5, 0, ret);
|
2017-04-10 22:22:37 +02:00
|
|
|
|
|
|
|
return ret;
|
2017-05-17 12:34:06 +02:00
|
|
|
}
|
2018-09-14 18:30:26 +02:00
|
|
|
|
|
|
|
|
|
|
|
bool DRW_object_is_flat(Object *ob, int *axis)
|
|
|
|
{
|
|
|
|
float dim[3];
|
|
|
|
|
|
|
|
if (!ELEM(ob->type, OB_MESH, OB_CURVE, OB_SURF, OB_FONT, OB_MBALL)) {
|
|
|
|
/* Non-meshes object cannot be considered as flat. */
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
BKE_object_dimensions_get(ob, dim);
|
|
|
|
if (dim[0] == 0.0f) {
|
|
|
|
*axis = 0;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else if (dim[1] == 0.0f) {
|
|
|
|
*axis = 1;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else if (dim[2] == 0.0f) {
|
|
|
|
*axis = 2;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool DRW_object_axis_orthogonal_to_view(Object *ob, int axis)
|
|
|
|
{
|
|
|
|
float ob_rot[3][3], invviewmat[4][4];
|
|
|
|
DRW_viewport_matrix_get(invviewmat, DRW_MAT_VIEWINV);
|
|
|
|
BKE_object_rot_to_mat3(ob, ob_rot, true);
|
|
|
|
float dot = dot_v3v3(ob_rot[axis], invviewmat[2]);
|
|
|
|
if (fabsf(dot) < 1e-3) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2018-09-25 19:19:59 +03:00
|
|
|
|
2018-10-03 08:10:48 +10:00
|
|
|
static void DRW_evaluate_weight_to_color(const float weight, float result[4])
|
2018-09-25 19:19:59 +03:00
|
|
|
{
|
2018-10-01 08:42:26 +10:00
|
|
|
if (U.flag & USER_CUSTOM_RANGE) {
|
2018-09-25 19:19:59 +03:00
|
|
|
BKE_colorband_evaluate(&U.coba_weight, weight, result);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* Use gamma correction to even out the color bands:
|
|
|
|
* increasing widens yellow/cyan vs red/green/blue.
|
|
|
|
* Gamma 1.0 produces the original 2.79 color ramp. */
|
|
|
|
const float gamma = 1.5f;
|
2018-10-03 08:10:48 +10:00
|
|
|
float hsv[3] = {(2.0f / 3.0f) * (1.0f - weight), 1.0f, pow(0.5f + 0.5f * weight, gamma)};
|
2018-09-25 19:19:59 +03:00
|
|
|
|
|
|
|
hsv_to_rgb_v(hsv, result);
|
|
|
|
|
|
|
|
for (int i = 0; i < 3; i++) {
|
2018-10-01 08:42:26 +10:00
|
|
|
result[i] = pow(result[i], 1.0f / gamma);
|
2018-09-25 19:19:59 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-01 08:42:26 +10:00
|
|
|
static GPUTexture *DRW_create_weight_colorramp_texture(void)
|
2018-09-25 19:19:59 +03:00
|
|
|
{
|
|
|
|
char error[256];
|
2018-10-03 08:10:48 +10:00
|
|
|
float pixels[256][4];
|
2018-09-25 19:19:59 +03:00
|
|
|
for (int i = 0 ; i < 256 ; i ++) {
|
2018-10-03 08:10:48 +10:00
|
|
|
DRW_evaluate_weight_to_color(i / 255.0f, pixels[i]);
|
|
|
|
pixels[i][3] = 1.0f;
|
2018-09-25 19:19:59 +03:00
|
|
|
}
|
|
|
|
|
2018-10-03 08:10:48 +10:00
|
|
|
return GPU_texture_create_1D(256, GPU_RGBA8, pixels[0], error);
|
2018-09-25 19:19:59 +03:00
|
|
|
}
|