2022-02-11 09:07:11 +11:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
* Copyright 2005 Blender Foundation. All rights reserved. */
|
2015-12-06 21:20:19 +01:00
|
|
|
|
2019-02-18 08:08:12 +11:00
|
|
|
/** \file
|
|
|
|
* \ingroup gpu
|
2018-08-30 01:56:08 +10:00
|
|
|
*/
|
|
|
|
|
2020-03-19 09:33:03 +01:00
|
|
|
#include "BLI_utildefines.h"
|
2015-12-06 21:20:19 +01:00
|
|
|
|
|
|
|
#include "GPU_shader.h"
|
|
|
|
|
2017-04-07 13:28:42 -04:00
|
|
|
/* Adjust these constants as needed. */
|
|
|
|
#define MAX_DEFINE_LENGTH 256
|
2020-03-11 17:12:01 +01:00
|
|
|
#define MAX_EXT_DEFINE_LENGTH 512
|
2015-12-06 21:20:19 +01:00
|
|
|
|
|
|
|
/* Non-generated shaders */
|
2016-09-13 02:51:38 -04:00
|
|
|
extern char datatoc_gpu_shader_depth_only_frag_glsl[];
|
2016-08-16 14:58:53 -04:00
|
|
|
extern char datatoc_gpu_shader_uniform_color_frag_glsl[];
|
2017-02-07 13:04:08 +01:00
|
|
|
extern char datatoc_gpu_shader_checker_frag_glsl[];
|
2017-02-16 21:49:20 -02:00
|
|
|
extern char datatoc_gpu_shader_diag_stripes_frag_glsl[];
|
2017-02-07 13:04:08 +01:00
|
|
|
extern char datatoc_gpu_shader_simple_lighting_frag_glsl[];
|
2016-08-16 14:58:53 -04:00
|
|
|
extern char datatoc_gpu_shader_flat_color_frag_glsl[];
|
2016-10-26 03:57:14 -04:00
|
|
|
extern char datatoc_gpu_shader_flat_color_alpha_test_0_frag_glsl[];
|
2018-04-17 13:00:09 +02:00
|
|
|
extern char datatoc_gpu_shader_flat_id_frag_glsl[];
|
2018-08-23 22:29:29 +02:00
|
|
|
extern char datatoc_gpu_shader_2D_area_borders_vert_glsl[];
|
2018-12-01 19:49:31 +01:00
|
|
|
extern char datatoc_gpu_shader_2D_area_borders_frag_glsl[];
|
2016-10-15 02:30:59 -04:00
|
|
|
extern char datatoc_gpu_shader_2D_vert_glsl[];
|
2018-04-20 15:15:10 +02:00
|
|
|
extern char datatoc_gpu_shader_2D_smooth_color_uniform_alpha_vert_glsl[];
|
2016-11-18 16:04:25 +01:00
|
|
|
extern char datatoc_gpu_shader_2D_image_vert_glsl[];
|
2018-03-27 23:57:29 +02:00
|
|
|
extern char datatoc_gpu_shader_2D_image_rect_vert_glsl[];
|
2018-03-31 19:32:28 +02:00
|
|
|
extern char datatoc_gpu_shader_2D_image_multi_rect_vert_glsl[];
|
2018-03-29 03:06:33 +02:00
|
|
|
extern char datatoc_gpu_shader_2D_widget_base_vert_glsl[];
|
2018-04-06 23:54:24 +02:00
|
|
|
extern char datatoc_gpu_shader_2D_widget_base_frag_glsl[];
|
2018-04-06 10:09:23 +02:00
|
|
|
extern char datatoc_gpu_shader_2D_widget_shadow_vert_glsl[];
|
|
|
|
extern char datatoc_gpu_shader_2D_widget_shadow_frag_glsl[];
|
2018-04-05 15:27:53 +02:00
|
|
|
extern char datatoc_gpu_shader_2D_nodelink_frag_glsl[];
|
|
|
|
extern char datatoc_gpu_shader_2D_nodelink_vert_glsl[];
|
2016-11-18 16:04:25 +01:00
|
|
|
|
2016-10-18 00:08:34 -04:00
|
|
|
extern char datatoc_gpu_shader_3D_image_vert_glsl[];
|
2018-02-13 18:09:58 +01:00
|
|
|
extern char datatoc_gpu_shader_image_frag_glsl[];
|
2020-02-11 15:18:55 +01:00
|
|
|
extern char datatoc_gpu_shader_image_overlays_merge_frag_glsl[];
|
2020-03-19 08:06:49 +01:00
|
|
|
extern char datatoc_gpu_shader_image_overlays_stereo_merge_frag_glsl[];
|
2016-11-18 16:04:25 +01:00
|
|
|
extern char datatoc_gpu_shader_image_color_frag_glsl[];
|
2018-04-26 15:42:08 +02:00
|
|
|
extern char datatoc_gpu_shader_image_desaturate_frag_glsl[];
|
2021-11-05 14:51:55 +01:00
|
|
|
extern char datatoc_gpu_shader_image_modulate_alpha_frag_glsl[];
|
2018-03-31 19:32:28 +02:00
|
|
|
extern char datatoc_gpu_shader_image_varying_color_frag_glsl[];
|
2017-02-24 01:07:40 +01:00
|
|
|
extern char datatoc_gpu_shader_image_shuffle_color_frag_glsl[];
|
2016-10-15 02:30:59 -04:00
|
|
|
extern char datatoc_gpu_shader_3D_vert_glsl[];
|
2017-04-16 15:04:07 -04:00
|
|
|
extern char datatoc_gpu_shader_3D_normal_vert_glsl[];
|
2016-08-16 14:58:53 -04:00
|
|
|
extern char datatoc_gpu_shader_3D_flat_color_vert_glsl[];
|
2020-04-23 23:05:39 +02:00
|
|
|
extern char datatoc_gpu_shader_3D_polyline_frag_glsl[];
|
|
|
|
extern char datatoc_gpu_shader_3D_polyline_geom_glsl[];
|
|
|
|
extern char datatoc_gpu_shader_3D_polyline_vert_glsl[];
|
2016-08-16 14:58:53 -04:00
|
|
|
extern char datatoc_gpu_shader_3D_smooth_color_vert_glsl[];
|
|
|
|
extern char datatoc_gpu_shader_3D_smooth_color_frag_glsl[];
|
2017-02-11 21:15:46 +01:00
|
|
|
extern char datatoc_gpu_shader_3D_passthrough_vert_glsl[];
|
2017-04-05 01:28:48 +02:00
|
|
|
extern char datatoc_gpu_shader_3D_clipped_uniform_color_vert_glsl[];
|
2016-08-04 15:59:38 -04:00
|
|
|
|
2017-02-09 20:55:31 +01:00
|
|
|
extern char datatoc_gpu_shader_instance_variying_size_variying_color_vert_glsl[];
|
2017-02-07 11:20:15 +01:00
|
|
|
|
2017-02-28 02:18:52 -05:00
|
|
|
extern char datatoc_gpu_shader_point_uniform_color_aa_frag_glsl[];
|
|
|
|
extern char datatoc_gpu_shader_point_uniform_color_outline_aa_frag_glsl[];
|
2018-09-29 19:42:09 +02:00
|
|
|
extern char datatoc_gpu_shader_point_varying_color_varying_outline_aa_frag_glsl[];
|
2016-09-30 20:44:22 -04:00
|
|
|
extern char datatoc_gpu_shader_point_varying_color_frag_glsl[];
|
|
|
|
extern char datatoc_gpu_shader_3D_point_fixed_size_varying_color_vert_glsl[];
|
2016-10-01 17:32:29 -04:00
|
|
|
extern char datatoc_gpu_shader_3D_point_varying_size_varying_color_vert_glsl[];
|
2017-02-28 02:18:52 -05:00
|
|
|
extern char datatoc_gpu_shader_3D_point_uniform_size_aa_vert_glsl[];
|
|
|
|
extern char datatoc_gpu_shader_2D_point_uniform_size_aa_vert_glsl[];
|
|
|
|
extern char datatoc_gpu_shader_2D_point_uniform_size_outline_aa_vert_glsl[];
|
2016-09-30 20:44:22 -04:00
|
|
|
|
2017-07-13 16:44:02 +02:00
|
|
|
extern char datatoc_gpu_shader_2D_line_dashed_uniform_color_vert_glsl[];
|
2017-02-24 15:33:09 -05:00
|
|
|
extern char datatoc_gpu_shader_2D_line_dashed_frag_glsl[];
|
2017-07-13 16:44:02 +02:00
|
|
|
extern char datatoc_gpu_shader_3D_line_dashed_uniform_color_vert_glsl[];
|
2017-02-24 15:33:09 -05:00
|
|
|
|
2016-09-17 13:33:02 +02:00
|
|
|
extern char datatoc_gpu_shader_text_vert_glsl[];
|
|
|
|
extern char datatoc_gpu_shader_text_frag_glsl[];
|
2021-09-23 15:53:38 +02:00
|
|
|
extern char datatoc_gpu_shader_keyframe_shape_vert_glsl[];
|
|
|
|
extern char datatoc_gpu_shader_keyframe_shape_frag_glsl[];
|
2016-09-17 13:33:02 +02:00
|
|
|
|
2018-07-31 10:22:19 +02:00
|
|
|
extern char datatoc_gpu_shader_gpencil_stroke_vert_glsl[];
|
|
|
|
extern char datatoc_gpu_shader_gpencil_stroke_frag_glsl[];
|
|
|
|
extern char datatoc_gpu_shader_gpencil_stroke_geom_glsl[];
|
|
|
|
|
2019-02-06 09:15:16 +11:00
|
|
|
extern char datatoc_gpu_shader_cfg_world_clip_lib_glsl[];
|
2018-07-31 10:22:19 +02:00
|
|
|
|
2020-04-14 20:44:45 +02:00
|
|
|
extern char datatoc_gpu_shader_colorspace_lib_glsl[];
|
|
|
|
|
2019-02-10 11:06:22 +11:00
|
|
|
const struct GPUShaderConfigData GPU_shader_cfg_data[GPU_SHADER_CFG_LEN] = {
|
|
|
|
[GPU_SHADER_CFG_DEFAULT] =
|
|
|
|
{
|
|
|
|
.lib = "",
|
2020-04-14 20:44:45 +02:00
|
|
|
.def = "#define blender_srgb_to_framebuffer_space(a) a\n",
|
2019-02-10 11:06:22 +11:00
|
|
|
},
|
|
|
|
[GPU_SHADER_CFG_CLIPPED] =
|
|
|
|
{
|
|
|
|
.lib = datatoc_gpu_shader_cfg_world_clip_lib_glsl,
|
2020-04-14 20:44:45 +02:00
|
|
|
.def = "#define USE_WORLD_CLIP_PLANES\n"
|
|
|
|
"#define blender_srgb_to_framebuffer_space(a) a\n",
|
2019-02-10 11:06:22 +11:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2016-11-08 22:53:59 -06:00
|
|
|
/* cache of built-in shaders (each is created on first use) */
|
2019-03-16 19:48:28 +01:00
|
|
|
static GPUShader *builtin_shaders[GPU_SHADER_CFG_LEN][GPU_SHADER_BUILTIN_LEN] = {{NULL}};
|
2015-12-06 21:20:19 +01:00
|
|
|
|
2016-11-08 22:53:59 -06:00
|
|
|
typedef struct {
|
2020-09-16 01:40:04 +02:00
|
|
|
const char *name;
|
2016-11-08 22:53:59 -06:00
|
|
|
const char *vert;
|
2019-01-26 09:46:29 +11:00
|
|
|
/** Optional. */
|
|
|
|
const char *geom;
|
2016-11-08 22:53:59 -06:00
|
|
|
const char *frag;
|
2019-01-26 10:04:10 +11:00
|
|
|
/** Optional. */
|
|
|
|
const char *defs;
|
2022-01-17 14:45:22 +01:00
|
|
|
|
|
|
|
const char *create_info;
|
|
|
|
const char *clipped_create_info;
|
2016-11-08 22:53:59 -06:00
|
|
|
} GPUShaderStages;
|
2015-12-06 21:20:19 +01:00
|
|
|
|
2019-02-06 09:15:16 +11:00
|
|
|
static const GPUShaderStages builtin_shader_stages[GPU_SHADER_BUILTIN_LEN] = {
|
2019-01-26 09:46:29 +11:00
|
|
|
[GPU_SHADER_TEXT] =
|
|
|
|
{
|
2020-09-16 01:40:04 +02:00
|
|
|
.name = "GPU_SHADER_TEXT",
|
2022-01-17 14:45:22 +01:00
|
|
|
.create_info = "gpu_shader_text",
|
2019-01-26 09:46:29 +11:00
|
|
|
},
|
2021-09-23 15:53:38 +02:00
|
|
|
[GPU_SHADER_KEYFRAME_SHAPE] =
|
2019-01-26 09:46:29 +11:00
|
|
|
{
|
2021-09-23 15:53:38 +02:00
|
|
|
.name = "GPU_SHADER_KEYFRAME_SHAPE",
|
2022-01-17 14:45:22 +01:00
|
|
|
.create_info = "gpu_shader_keyframe_shape",
|
2019-01-26 09:46:29 +11:00
|
|
|
},
|
|
|
|
[GPU_SHADER_SIMPLE_LIGHTING] =
|
|
|
|
{
|
2020-09-16 01:40:04 +02:00
|
|
|
.name = "GPU_SHADER_SIMPLE_LIGHTING",
|
2022-01-17 14:45:22 +01:00
|
|
|
.create_info = "gpu_shader_simple_lighting",
|
2019-01-26 09:46:29 +11:00
|
|
|
},
|
EEVEE & Viewport: Add a built-in shader called 3D_IMAGE, and expose to the python API
Adds an example python script to the documentation for the 3D_IMAGE shader.
The **use-case** is to draw textures with 3D vertex positions, in XR views as well as non-XR views (in a simpler manner).
**Testing**: I've tested that this compiles and works on my Macbook (with the example python script included in this change). I don't have access to a Windows or Linux machine right now, but this change doesn't look platform-specific and no new glsl shaders have been added or edited by this change. I'll try to get access to a Windows machine, but if someone does have one, I'd be really grateful if they could try this change. Thanks!
**Problem addressed**: The existing 2D_IMAGE shader (exposed in the python API) gets near-clipped when drawn in the
XR view, regardless of the near-clip settings. Additionally, the 2D_IMAGE shader only accepts 2D
positions for the image vertices, which means drawing textures in 3D requires providing
2D coordinates and then pushing a transform-rotate-scale matrix to the GPU, even for
non-XR (i.e. WINDOW) views. The 3D_IMAGE shader is simpler: it accepts 3D vertex positions, and doesn't require
any additional work by the scripter.
**Workaround**: The current workaround is to use custom shaders in the python script.
**Non-intrusive change**: No new glsl shaders were added. This change just bundles two existing shaders: the vertex shader used
by the 3D_IMAGE_MODULATE_ALPHA shader, and the fragment shader used by the 2D_IMAGE shader.
Reviewed By: #eevee_viewport, jbakker
Differential Revision: https://developer.blender.org/D14832
2022-05-09 08:07:28 +02:00
|
|
|
[GPU_SHADER_3D_IMAGE] =
|
|
|
|
{
|
|
|
|
.name = "GPU_SHADER_3D_IMAGE",
|
|
|
|
.create_info = "gpu_shader_3D_image",
|
|
|
|
},
|
2022-09-05 17:34:10 -03:00
|
|
|
[GPU_SHADER_3D_IMAGE_COLOR] =
|
|
|
|
{
|
|
|
|
.name = "GPU_SHADER_3D_IMAGE_COLOR",
|
|
|
|
.create_info = "gpu_shader_3D_image_color",
|
|
|
|
},
|
2019-01-26 09:46:29 +11:00
|
|
|
[GPU_SHADER_2D_CHECKER] =
|
|
|
|
{
|
2020-09-16 01:40:04 +02:00
|
|
|
.name = "GPU_SHADER_2D_CHECKER",
|
2022-01-17 14:45:22 +01:00
|
|
|
.create_info = "gpu_shader_2D_checker",
|
2019-01-26 09:46:29 +11:00
|
|
|
},
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-01-26 09:46:29 +11:00
|
|
|
[GPU_SHADER_2D_DIAG_STRIPES] =
|
|
|
|
{
|
2020-09-16 01:40:04 +02:00
|
|
|
.name = "GPU_SHADER_2D_DIAG_STRIPES",
|
2022-01-17 14:45:22 +01:00
|
|
|
.create_info = "gpu_shader_2D_diag_stripes",
|
2019-01-26 09:46:29 +11:00
|
|
|
},
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-10-20 16:37:07 +02:00
|
|
|
[GPU_SHADER_ICON] =
|
|
|
|
{
|
|
|
|
.name = "GPU_SHADER_ICON",
|
|
|
|
.create_info = "gpu_shader_icon",
|
|
|
|
},
|
2022-01-21 14:24:30 +01:00
|
|
|
[GPU_SHADER_2D_IMAGE_OVERLAYS_MERGE] =
|
|
|
|
{
|
|
|
|
.name = "GPU_SHADER_2D_IMAGE_OVERLAYS_MERGE",
|
|
|
|
.create_info = "gpu_shader_2D_image_overlays_merge",
|
|
|
|
},
|
2020-03-19 08:06:49 +01:00
|
|
|
[GPU_SHADER_2D_IMAGE_OVERLAYS_STEREO_MERGE] =
|
2022-05-02 01:05:35 +02:00
|
|
|
{
|
|
|
|
.name = "GPU_SHADER_2D_IMAGE_OVERLAYS_STEREO_MERGE",
|
|
|
|
.create_info = "gpu_shader_2D_image_overlays_stereo_merge",
|
|
|
|
},
|
|
|
|
[GPU_SHADER_2D_IMAGE_DESATURATE_COLOR] =
|
|
|
|
{
|
|
|
|
.name = "GPU_SHADER_2D_IMAGE_DESATURATE_COLOR",
|
|
|
|
.create_info = "gpu_shader_2D_image_desaturate_color",
|
|
|
|
},
|
2019-01-26 09:46:29 +11:00
|
|
|
[GPU_SHADER_2D_IMAGE_SHUFFLE_COLOR] =
|
|
|
|
{
|
2020-09-16 01:40:04 +02:00
|
|
|
.name = "GPU_SHADER_2D_IMAGE_SHUFFLE_COLOR",
|
2022-01-17 14:45:22 +01:00
|
|
|
.create_info = "gpu_shader_2D_image_shuffle_color",
|
2019-01-26 09:46:29 +11:00
|
|
|
},
|
2022-05-02 01:05:35 +02:00
|
|
|
[GPU_SHADER_2D_IMAGE_RECT_COLOR] =
|
|
|
|
{
|
|
|
|
.name = "GPU_SHADER_2D_IMAGE_RECT_COLOR",
|
|
|
|
.create_info = "gpu_shader_2D_image_rect_color",
|
|
|
|
},
|
|
|
|
[GPU_SHADER_2D_IMAGE_MULTI_RECT_COLOR] =
|
|
|
|
{
|
|
|
|
.name = "GPU_SHADER_2D_IMAGE_MULTI_RECT_COLOR",
|
|
|
|
.create_info = "gpu_shader_2D_image_multi_rect_color",
|
|
|
|
},
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-01-26 09:46:29 +11:00
|
|
|
[GPU_SHADER_3D_UNIFORM_COLOR] =
|
|
|
|
{
|
2020-09-16 01:40:04 +02:00
|
|
|
.name = "GPU_SHADER_3D_UNIFORM_COLOR",
|
2022-01-17 14:45:22 +01:00
|
|
|
.create_info = "gpu_shader_3D_uniform_color",
|
|
|
|
.clipped_create_info = "gpu_shader_3D_uniform_color_clipped",
|
|
|
|
},
|
2022-05-02 01:05:35 +02:00
|
|
|
[GPU_SHADER_3D_FLAT_COLOR] =
|
|
|
|
{
|
|
|
|
.name = "GPU_SHADER_3D_FLAT_COLOR",
|
|
|
|
.create_info = "gpu_shader_3D_flat_color",
|
|
|
|
.clipped_create_info = "gpu_shader_3D_flat_color_clipped",
|
|
|
|
},
|
|
|
|
[GPU_SHADER_3D_SMOOTH_COLOR] =
|
|
|
|
{
|
|
|
|
.name = "GPU_SHADER_3D_SMOOTH_COLOR",
|
|
|
|
.create_info = "gpu_shader_3D_smooth_color",
|
|
|
|
.clipped_create_info = "gpu_shader_3D_smooth_color_clipped",
|
|
|
|
},
|
|
|
|
[GPU_SHADER_3D_DEPTH_ONLY] =
|
|
|
|
{
|
|
|
|
.name = "GPU_SHADER_3D_DEPTH_ONLY",
|
|
|
|
.create_info = "gpu_shader_3D_depth_only",
|
|
|
|
.clipped_create_info = "gpu_shader_3D_depth_only_clipped",
|
|
|
|
},
|
2019-01-26 09:46:29 +11:00
|
|
|
[GPU_SHADER_3D_CLIPPED_UNIFORM_COLOR] =
|
|
|
|
{
|
2020-09-16 01:40:04 +02:00
|
|
|
.name = "GPU_SHADER_3D_CLIPPED_UNIFORM_COLOR",
|
2022-05-02 00:44:58 +02:00
|
|
|
.create_info = "gpu_shader_3D_clipped_uniform_color",
|
2019-01-26 09:46:29 +11:00
|
|
|
},
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-05-02 01:05:35 +02:00
|
|
|
[GPU_SHADER_3D_POLYLINE_UNIFORM_COLOR] =
|
|
|
|
{
|
|
|
|
.name = "GPU_SHADER_3D_POLYLINE_UNIFORM_COLOR",
|
|
|
|
.create_info = "gpu_shader_3D_polyline_uniform_color",
|
|
|
|
},
|
2020-04-23 23:05:39 +02:00
|
|
|
[GPU_SHADER_3D_POLYLINE_CLIPPED_UNIFORM_COLOR] =
|
2022-05-02 01:05:35 +02:00
|
|
|
{
|
|
|
|
.name = "GPU_SHADER_3D_POLYLINE_CLIPPED_UNIFORM_COLOR",
|
|
|
|
.create_info = "gpu_shader_3D_polyline_uniform_color_clipped",
|
|
|
|
},
|
|
|
|
[GPU_SHADER_3D_POLYLINE_FLAT_COLOR] =
|
|
|
|
{
|
|
|
|
.name = "GPU_SHADER_3D_POLYLINE_FLAT_COLOR",
|
|
|
|
.create_info = "gpu_shader_3D_polyline_flat_color",
|
|
|
|
},
|
|
|
|
[GPU_SHADER_3D_POLYLINE_SMOOTH_COLOR] =
|
|
|
|
{
|
|
|
|
.name = "GPU_SHADER_3D_POLYLINE_SMOOTH_COLOR",
|
|
|
|
.create_info = "gpu_shader_3D_polyline_smooth_color",
|
|
|
|
},
|
|
|
|
|
2019-01-26 09:46:29 +11:00
|
|
|
[GPU_SHADER_3D_LINE_DASHED_UNIFORM_COLOR] =
|
2022-05-02 01:05:35 +02:00
|
|
|
{
|
|
|
|
.name = "GPU_SHADER_3D_LINE_DASHED_UNIFORM_COLOR",
|
|
|
|
.create_info = "gpu_shader_3D_line_dashed_uniform_color",
|
|
|
|
.clipped_create_info = "gpu_shader_3D_line_dashed_uniform_color_clipped",
|
|
|
|
},
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-01-26 09:46:29 +11:00
|
|
|
[GPU_SHADER_2D_POINT_UNIFORM_SIZE_UNIFORM_COLOR_AA] =
|
|
|
|
{
|
2020-09-16 01:40:04 +02:00
|
|
|
.name = "GPU_SHADER_2D_POINT_UNIFORM_SIZE_UNIFORM_COLOR_AA",
|
2022-01-17 14:45:22 +01:00
|
|
|
.create_info = "gpu_shader_2D_point_uniform_size_uniform_color_aa",
|
2019-01-26 09:46:29 +11:00
|
|
|
},
|
|
|
|
[GPU_SHADER_2D_POINT_UNIFORM_SIZE_UNIFORM_COLOR_OUTLINE_AA] =
|
|
|
|
{
|
2020-09-16 01:40:04 +02:00
|
|
|
.name = "GPU_SHADER_2D_POINT_UNIFORM_SIZE_UNIFORM_COLOR_OUTLINE_AA",
|
2022-01-17 14:45:22 +01:00
|
|
|
.create_info = "gpu_shader_2D_point_uniform_size_uniform_color_outline_aa",
|
2019-01-26 09:46:29 +11:00
|
|
|
},
|
|
|
|
[GPU_SHADER_3D_POINT_FIXED_SIZE_VARYING_COLOR] =
|
2022-05-02 01:05:35 +02:00
|
|
|
{
|
|
|
|
.name = "GPU_SHADER_3D_POINT_FIXED_SIZE_VARYING_COLOR",
|
|
|
|
.create_info = "gpu_shader_3D_point_fixed_size_varying_color",
|
|
|
|
},
|
2019-01-26 09:46:29 +11:00
|
|
|
[GPU_SHADER_3D_POINT_VARYING_SIZE_VARYING_COLOR] =
|
2022-05-02 01:05:35 +02:00
|
|
|
{
|
|
|
|
.name = "GPU_SHADER_3D_POINT_VARYING_SIZE_VARYING_COLOR",
|
|
|
|
.create_info = "gpu_shader_3D_point_varying_size_varying_color",
|
|
|
|
},
|
2019-01-26 09:46:29 +11:00
|
|
|
[GPU_SHADER_3D_POINT_UNIFORM_SIZE_UNIFORM_COLOR_AA] =
|
2022-05-02 01:05:35 +02:00
|
|
|
{
|
|
|
|
.name = "GPU_SHADER_3D_POINT_UNIFORM_SIZE_UNIFORM_COLOR_AA",
|
|
|
|
.create_info = "gpu_shader_3D_point_uniform_size_uniform_color_aa",
|
|
|
|
.clipped_create_info = "gpu_shader_3D_point_uniform_size_uniform_color_aa_clipped",
|
|
|
|
},
|
|
|
|
|
|
|
|
[GPU_SHADER_2D_AREA_BORDERS] =
|
|
|
|
{
|
|
|
|
.name = "GPU_SHADER_2D_AREA_BORDERS",
|
|
|
|
.create_info = "gpu_shader_2D_area_borders",
|
|
|
|
},
|
|
|
|
[GPU_SHADER_2D_WIDGET_BASE] =
|
|
|
|
{
|
|
|
|
.name = "GPU_SHADER_2D_WIDGET_BASE",
|
|
|
|
.create_info = "gpu_shader_2D_widget_base",
|
|
|
|
},
|
|
|
|
[GPU_SHADER_2D_WIDGET_BASE_INST] =
|
|
|
|
{
|
|
|
|
.name = "GPU_SHADER_2D_WIDGET_BASE_INST",
|
|
|
|
.defs = "#define USE_INSTANCE\n",
|
|
|
|
.create_info = "gpu_shader_2D_widget_base_inst",
|
|
|
|
},
|
|
|
|
[GPU_SHADER_2D_WIDGET_SHADOW] =
|
|
|
|
{
|
|
|
|
.name = "GPU_SHADER_2D_WIDGET_SHADOW",
|
|
|
|
.create_info = "gpu_shader_2D_widget_shadow",
|
|
|
|
},
|
|
|
|
[GPU_SHADER_2D_NODELINK] =
|
|
|
|
{
|
|
|
|
.name = "GPU_SHADER_2D_NODELINK",
|
|
|
|
.create_info = "gpu_shader_2D_nodelink",
|
|
|
|
},
|
|
|
|
|
|
|
|
[GPU_SHADER_2D_NODELINK_INST] =
|
|
|
|
{
|
|
|
|
.name = "GPU_SHADER_2D_NODELINK_INST",
|
|
|
|
.create_info = "gpu_shader_2D_nodelink_inst",
|
|
|
|
},
|
|
|
|
|
|
|
|
[GPU_SHADER_GPENCIL_STROKE] =
|
|
|
|
{
|
|
|
|
.name = "GPU_SHADER_GPENCIL_STROKE",
|
|
|
|
.create_info = "gpu_shader_gpencil_stroke",
|
|
|
|
},
|
2018-09-14 09:32:19 -03:00
|
|
|
};
|
|
|
|
|
2019-02-06 09:15:16 +11:00
|
|
|
GPUShader *GPU_shader_get_builtin_shader_with_config(eGPUBuiltinShader shader,
|
2019-02-10 11:02:06 +11:00
|
|
|
eGPUShaderConfig sh_cfg)
|
2015-12-06 21:20:19 +01:00
|
|
|
{
|
2019-02-06 09:15:16 +11:00
|
|
|
BLI_assert(shader < GPU_SHADER_BUILTIN_LEN);
|
2019-02-10 11:02:06 +11:00
|
|
|
BLI_assert(sh_cfg < GPU_SHADER_CFG_LEN);
|
|
|
|
GPUShader **sh_p = &builtin_shaders[sh_cfg][shader];
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-02-06 09:15:16 +11:00
|
|
|
if (*sh_p == NULL) {
|
2019-01-26 10:04:10 +11:00
|
|
|
const GPUShaderStages *stages = &builtin_shader_stages[shader];
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-11-08 22:53:59 -06:00
|
|
|
/* common case */
|
2019-02-10 11:02:06 +11:00
|
|
|
if (sh_cfg == GPU_SHADER_CFG_DEFAULT) {
|
2022-01-17 14:45:22 +01:00
|
|
|
if (stages->create_info != NULL) {
|
2022-01-25 14:22:44 +01:00
|
|
|
*sh_p = GPU_shader_create_from_info_name(stages->create_info);
|
2022-05-06 10:59:47 -03:00
|
|
|
if (ELEM(shader,
|
|
|
|
GPU_SHADER_3D_POLYLINE_CLIPPED_UNIFORM_COLOR,
|
|
|
|
GPU_SHADER_3D_POLYLINE_UNIFORM_COLOR,
|
|
|
|
GPU_SHADER_3D_POLYLINE_FLAT_COLOR,
|
|
|
|
GPU_SHADER_3D_POLYLINE_SMOOTH_COLOR)) {
|
|
|
|
/* Set a default value for `lineSmooth`.
|
|
|
|
* Ideally this value should be set by the caller. */
|
|
|
|
GPU_shader_bind(*sh_p);
|
|
|
|
GPU_shader_uniform_1i(*sh_p, "lineSmooth", 1);
|
|
|
|
}
|
2022-01-17 14:45:22 +01:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
*sh_p = GPU_shader_create_from_arrays_named(
|
|
|
|
stages->name,
|
|
|
|
{
|
|
|
|
.vert = (const char *[]){stages->vert, NULL},
|
|
|
|
.geom = (const char *[]){stages->geom, NULL},
|
|
|
|
.frag =
|
|
|
|
(const char *[]){datatoc_gpu_shader_colorspace_lib_glsl, stages->frag, NULL},
|
|
|
|
.defs = (const char *[]){stages->defs, NULL},
|
|
|
|
});
|
|
|
|
}
|
2019-02-06 09:15:16 +11:00
|
|
|
}
|
2019-02-10 11:02:06 +11:00
|
|
|
else if (sh_cfg == GPU_SHADER_CFG_CLIPPED) {
|
2019-02-06 09:15:16 +11:00
|
|
|
/* Remove eventually, for now ensure support for each shader has been added. */
|
|
|
|
BLI_assert(ELEM(shader,
|
|
|
|
GPU_SHADER_3D_UNIFORM_COLOR,
|
|
|
|
GPU_SHADER_3D_SMOOTH_COLOR,
|
|
|
|
GPU_SHADER_3D_DEPTH_ONLY,
|
|
|
|
GPU_SHADER_3D_POINT_UNIFORM_SIZE_UNIFORM_COLOR_AA,
|
2019-05-30 20:02:05 +10:00
|
|
|
GPU_SHADER_3D_FLAT_COLOR,
|
2019-12-02 01:40:58 +01:00
|
|
|
GPU_SHADER_3D_LINE_DASHED_UNIFORM_COLOR));
|
2019-02-06 09:15:16 +11:00
|
|
|
/* In rare cases geometry shaders calculate clipping themselves. */
|
2022-01-17 14:45:22 +01:00
|
|
|
if (stages->clipped_create_info != NULL) {
|
2022-01-25 14:22:44 +01:00
|
|
|
*sh_p = GPU_shader_create_from_info_name(stages->clipped_create_info);
|
2022-01-17 14:45:22 +01:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
const char *world_clip_lib = datatoc_gpu_shader_cfg_world_clip_lib_glsl;
|
|
|
|
const char *world_clip_def = "#define USE_WORLD_CLIP_PLANES\n";
|
|
|
|
*sh_p = GPU_shader_create_from_arrays_named(
|
|
|
|
stages->name,
|
|
|
|
{
|
|
|
|
.vert = (const char *[]){world_clip_lib, stages->vert, NULL},
|
|
|
|
.geom = (const char *[]){stages->geom ? world_clip_lib : NULL, stages->geom, NULL},
|
|
|
|
.frag =
|
|
|
|
(const char *[]){datatoc_gpu_shader_colorspace_lib_glsl, stages->frag, NULL},
|
|
|
|
.defs = (const char *[]){world_clip_def, stages->defs, NULL},
|
|
|
|
});
|
|
|
|
}
|
2019-02-06 09:15:16 +11:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
BLI_assert(0);
|
|
|
|
}
|
2016-11-08 22:53:59 -06:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-02-06 09:15:16 +11:00
|
|
|
return *sh_p;
|
|
|
|
}
|
2020-07-28 20:04:15 +02:00
|
|
|
|
2019-02-06 09:15:16 +11:00
|
|
|
GPUShader *GPU_shader_get_builtin_shader(eGPUBuiltinShader shader)
|
|
|
|
{
|
|
|
|
return GPU_shader_get_builtin_shader_with_config(shader, GPU_SHADER_CFG_DEFAULT);
|
2015-12-06 21:20:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void GPU_shader_free_builtin_shaders(void)
|
|
|
|
{
|
2019-02-06 09:15:16 +11:00
|
|
|
for (int i = 0; i < GPU_SHADER_CFG_LEN; i++) {
|
|
|
|
for (int j = 0; j < GPU_SHADER_BUILTIN_LEN; j++) {
|
|
|
|
if (builtin_shaders[i][j]) {
|
|
|
|
GPU_shader_free(builtin_shaders[i][j]);
|
|
|
|
builtin_shaders[i][j] = NULL;
|
|
|
|
}
|
2016-11-08 22:53:59 -06:00
|
|
|
}
|
2016-10-16 18:43:24 -04:00
|
|
|
}
|
2015-12-06 21:20:19 +01:00
|
|
|
}
|