2023-08-16 00:20:26 +10:00
|
|
|
/* SPDX-FileCopyrightText: 2023 Blender Authors
|
2023-05-31 16:19:06 +02:00
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: GPL-2.0-or-later */
|
2023-02-12 17:37:01 +01:00
|
|
|
|
|
|
|
|
/** \file
|
|
|
|
|
* \ingroup gpu
|
|
|
|
|
*
|
|
|
|
|
* Set of shaders used for interface drawing.
|
|
|
|
|
*
|
|
|
|
|
* 2D shaders are not expected to work in 3D.
|
|
|
|
|
* 3D shaders can work with 2D geometry and matrices.
|
|
|
|
|
*
|
|
|
|
|
* `INST` suffix means instance, which means the shader is build to leverage instancing
|
|
|
|
|
* capabilities to reduce the number of draw-calls.
|
|
|
|
|
*
|
2023-03-29 14:16:26 +11:00
|
|
|
* For full list of parameters, search for the associated #ShaderCreateInfo.
|
2023-02-12 17:37:01 +01:00
|
|
|
* Example: `GPU_SHADER_ICON` is defined by `GPU_SHADER_CREATE_INFO(gpu_shader_icon)`
|
|
|
|
|
* Some parameters are builtins and are set automatically (ex: `ModelViewProjectionMatrix`).
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
2025-08-11 09:34:28 +02:00
|
|
|
namespace blender::gpu {
|
|
|
|
|
class Shader;
|
|
|
|
|
} // namespace blender::gpu
|
2023-02-12 17:37:01 +01:00
|
|
|
|
2024-03-23 01:24:18 +01:00
|
|
|
enum eGPUBuiltinShader {
|
2023-02-12 17:37:01 +01:00
|
|
|
/** Glyph drawing shader used by the BLF module. */
|
2024-09-25 20:14:06 +10:00
|
|
|
GPU_SHADER_TEXT = 0,
|
2023-02-12 17:37:01 +01:00
|
|
|
/** Draws keyframe markers. All markers shapes are supported through a single shader. */
|
|
|
|
|
GPU_SHADER_KEYFRAME_SHAPE,
|
|
|
|
|
/** Draw solid mesh with a single distant light using a clamped simple dot product. */
|
|
|
|
|
GPU_SHADER_SIMPLE_LIGHTING,
|
|
|
|
|
/** Draw an icon, leaving a semi-transparent rectangle on top of the icon. */
|
|
|
|
|
GPU_SHADER_ICON,
|
|
|
|
|
/** Draw a texture with a uniform color multiplied. */
|
|
|
|
|
GPU_SHADER_2D_IMAGE_RECT_COLOR,
|
|
|
|
|
/** Draw a texture with a desaturation factor. */
|
|
|
|
|
GPU_SHADER_2D_IMAGE_DESATURATE_COLOR,
|
|
|
|
|
/** Draw a group of texture rectangle with an associated color multiplied. */
|
2023-02-26 13:23:40 +01:00
|
|
|
GPU_SHADER_ICON_MULTI,
|
2023-02-12 17:37:01 +01:00
|
|
|
/** Draw a two color checker based on screen position (not UV coordinates). */
|
|
|
|
|
GPU_SHADER_2D_CHECKER,
|
|
|
|
|
/** Draw diagonal stripes with two alternating colors. */
|
|
|
|
|
GPU_SHADER_2D_DIAG_STRIPES,
|
|
|
|
|
/** Draw dashed lines with custom dash length and uniform color. */
|
|
|
|
|
GPU_SHADER_3D_LINE_DASHED_UNIFORM_COLOR,
|
|
|
|
|
/** Draw triangles / lines / points with only depth output. */
|
|
|
|
|
GPU_SHADER_3D_DEPTH_ONLY,
|
|
|
|
|
/** Merge viewport overlay texture with the render output. */
|
|
|
|
|
GPU_SHADER_2D_IMAGE_OVERLAYS_MERGE,
|
|
|
|
|
GPU_SHADER_2D_IMAGE_OVERLAYS_STEREO_MERGE,
|
|
|
|
|
/** Merge viewport overlay texture with the render output. */
|
|
|
|
|
GPU_SHADER_2D_IMAGE_SHUFFLE_COLOR,
|
|
|
|
|
/** Used for drawing of annotations (former grease pencil). */
|
|
|
|
|
GPU_SHADER_GPENCIL_STROKE,
|
|
|
|
|
/** Draw rounded area borders with silky smooth anti-aliasing without any over-draw. */
|
|
|
|
|
GPU_SHADER_2D_AREA_BORDERS,
|
|
|
|
|
/** Multi usage widget shaders for drawing buttons and other UI elements. */
|
|
|
|
|
GPU_SHADER_2D_WIDGET_BASE,
|
|
|
|
|
GPU_SHADER_2D_WIDGET_BASE_INST,
|
|
|
|
|
GPU_SHADER_2D_WIDGET_SHADOW,
|
2024-11-23 16:42:38 +01:00
|
|
|
/** Draw a node socket given it's bounding rectangle. All socket shapes are supported through
|
|
|
|
|
* a single shader. */
|
|
|
|
|
GPU_SHADER_2D_NODE_SOCKET,
|
|
|
|
|
GPU_SHADER_2D_NODE_SOCKET_INST,
|
2023-02-12 17:37:01 +01:00
|
|
|
/** Draw a node link given an input quadratic Bezier curve. */
|
|
|
|
|
GPU_SHADER_2D_NODELINK,
|
|
|
|
|
|
|
|
|
|
/** Draw round points with per vertex size and color. */
|
|
|
|
|
GPU_SHADER_3D_POINT_VARYING_SIZE_VARYING_COLOR,
|
|
|
|
|
/** Draw round points with a uniform size. Disabling blending will disable AA. */
|
|
|
|
|
GPU_SHADER_2D_POINT_UNIFORM_SIZE_UNIFORM_COLOR_AA,
|
|
|
|
|
GPU_SHADER_3D_POINT_UNIFORM_SIZE_UNIFORM_COLOR_AA,
|
|
|
|
|
/** Draw round points with a uniform size and an outline. Disabling blending will disable AA. */
|
|
|
|
|
GPU_SHADER_2D_POINT_UNIFORM_SIZE_UNIFORM_COLOR_OUTLINE_AA,
|
|
|
|
|
|
|
|
|
|
/** Draw geometry with uniform color. Has an additional clip plane parameter. */
|
|
|
|
|
GPU_SHADER_3D_CLIPPED_UNIFORM_COLOR,
|
|
|
|
|
/** Draw wide lines with uniform color. Has an additional clip plane parameter. */
|
|
|
|
|
GPU_SHADER_3D_POLYLINE_CLIPPED_UNIFORM_COLOR,
|
|
|
|
|
|
2024-06-04 20:05:35 +02:00
|
|
|
/** Draw strip widgets in sequencer timeline. */
|
|
|
|
|
GPU_SHADER_SEQUENCER_STRIPS,
|
VSE: Faster timeline thumbnail drawing
VSE timeline, when many (hundreds/thousands) of thumbnails were visible, was
very slow to redraw. This PR makes them 3-10x faster to redraw, by stopping
doing things that are slow :) Part of #126087 thumbnail improvements task.
- No longer do mute semitransparency or corner rounding on the CPU, do it in
shader instead.
- Stop creating a separate GPU texture for each thumbnail, on every repaint,
and drawing each thumbnail as a separate draw call. Instead, put thumbnails
into a single texture atlas (using a simple shelf packing algorithm), and
draw them in batch, passing data via UBO. The atlas is still re-created every
frame, but that does not seem to be a performance issue. Thumbnails are
cropped horizontally based on how much of their parts are visible (e.g. a
narrow strip on screen), so realistically the atlas size is kinda
proportional to screen size, and ends up being just several megabytes of data
transfer between CPU -> GPU each frame.
On this Sprite Fright edit timeline view (612 visible thumbnails), time taken
to repaint the timeline window:
- Mac (M1 Max, Metal): 68.1ms -> 4.7ms
- Windows (Ryzen 5950X, RTX 3080Ti, OpenGL): 23.7ms -> 6.8ms
This also fixes a visual issue with thumbnails, where when strips are very
tall, the "rounded corners" that were poked right into the thumbnail bitmap
on the CPU were showing up due to actual bitmap being scaled up a lot.
Pull Request: https://projects.blender.org/blender/blender/pulls/126972
2024-09-03 08:25:15 +02:00
|
|
|
/** Draw strip thumbnails in sequencer timeline. */
|
|
|
|
|
GPU_SHADER_SEQUENCER_THUMBS,
|
VSE: Do Scopes on the GPU, improve their look, HDR for waveform/parade
Faster and better looking VSE scopes & "show overexposed". Waveform &
RGB Parade now can also show HDR color intensities. (Note: this is
only about VSE scopes; Image Space scopes are to be improved separately)
- Waveform, RGB Parade, Vectorscope scopes are done on the GPU now, by
drawing points for each input pixel, and placing them according to
scope logic. The point drawing is implemented in a compute shader,
with a fragment shader resolve pass; this is because drawing lots of
points in the same location is very slow on some GPUs (e.g. Apple).
The compute shader rasterizer is several times faster on regular
desktop GPU as well.
- If a non-default color management is needed (e.g. VSE colorspace is
not the same as display colorspace, or a custom look transform is used
etc. etc.), then transform the VSE preview texture into display space
RGBA 16F texture using OCIO GPU machinery, and calculate scopes
from that.
- The "show overexposed" (zebra) preview option is also done on the
GPU now.
- Waveform/Parade scopes unlock zoom X/Y aspect for viewing HDR scope,
similar to how it was done for HDR histograms recently.
- Added SEQ_preview_cache.hh that holds GPU textures of VSE preview,
this is so that when you have a preview and several scopes, each of
them does not have to create/upload their own GPU texture (that would
both waste memory, and be slow).
Screenshots and performance details in the PR.
Pull Request: https://projects.blender.org/blender/blender/pulls/144867
2025-08-26 12:25:43 +02:00
|
|
|
/** Rasterize sequencer scope points into buffers via compute. */
|
|
|
|
|
GPU_SHADER_SEQUENCER_SCOPE_RASTER,
|
|
|
|
|
/** Resolve rasterized scope point buffers to display. */
|
|
|
|
|
GPU_SHADER_SEQUENCER_SCOPE_RESOLVE,
|
|
|
|
|
/** Draw sequencer zebra pattern (overexposed regions). */
|
|
|
|
|
GPU_SHADER_SEQUENCER_ZEBRA,
|
2024-06-04 20:05:35 +02:00
|
|
|
|
2024-02-25 17:22:58 +01:00
|
|
|
/** Compute shaders to generate 2d index buffers (mainly for curve drawing). */
|
|
|
|
|
GPU_SHADER_INDEXBUF_POINTS,
|
|
|
|
|
GPU_SHADER_INDEXBUF_LINES,
|
|
|
|
|
GPU_SHADER_INDEXBUF_TRIS,
|
|
|
|
|
|
2023-02-12 17:37:01 +01:00
|
|
|
/**
|
|
|
|
|
* ----------------------- Shaders exposed through pyGPU module -----------------------
|
|
|
|
|
*
|
|
|
|
|
* Avoid breaking the interface of these shaders as they are used by addons.
|
|
|
|
|
* Polyline versions are used for drawing wide lines (> 1px width).
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Take a 3D position and color for each vertex without color interpolation.
|
|
|
|
|
*
|
|
|
|
|
* \param color: in vec4
|
|
|
|
|
* \param pos: in vec3
|
|
|
|
|
*/
|
|
|
|
|
GPU_SHADER_3D_FLAT_COLOR,
|
|
|
|
|
GPU_SHADER_3D_POLYLINE_FLAT_COLOR,
|
2025-05-29 14:36:32 +02:00
|
|
|
GPU_SHADER_3D_POINT_FLAT_COLOR,
|
|
|
|
|
|
2023-02-12 17:37:01 +01:00
|
|
|
/**
|
|
|
|
|
* Take a 3D position and color for each vertex with perspective correct interpolation.
|
|
|
|
|
*
|
|
|
|
|
* \param color: in vec4
|
|
|
|
|
* \param pos: in vec3
|
|
|
|
|
*/
|
|
|
|
|
GPU_SHADER_3D_SMOOTH_COLOR,
|
|
|
|
|
GPU_SHADER_3D_POLYLINE_SMOOTH_COLOR,
|
2025-05-29 14:36:32 +02:00
|
|
|
|
2023-02-12 17:37:01 +01:00
|
|
|
/**
|
|
|
|
|
* Take a single color for all the vertices and a 3D position for each vertex.
|
|
|
|
|
*
|
|
|
|
|
* \param color: uniform vec4
|
|
|
|
|
* \param pos: in vec3
|
|
|
|
|
*/
|
|
|
|
|
GPU_SHADER_3D_UNIFORM_COLOR,
|
|
|
|
|
GPU_SHADER_3D_POLYLINE_UNIFORM_COLOR,
|
2025-05-29 14:36:32 +02:00
|
|
|
GPU_SHADER_3D_POINT_UNIFORM_COLOR,
|
|
|
|
|
|
2023-02-12 17:37:01 +01:00
|
|
|
/**
|
|
|
|
|
* Draw a texture in 3D. Take a 3D position and a 2D texture coordinate for each vertex.
|
|
|
|
|
*
|
|
|
|
|
* \param image: uniform sampler2D
|
|
|
|
|
* \param texCoord: in vec2
|
|
|
|
|
* \param pos: in vec3
|
|
|
|
|
*/
|
|
|
|
|
GPU_SHADER_3D_IMAGE,
|
|
|
|
|
/**
|
|
|
|
|
* Take a 3D position and color for each vertex with linear interpolation in window space.
|
|
|
|
|
*
|
|
|
|
|
* \param color: uniform vec4
|
|
|
|
|
* \param image: uniform sampler2D
|
|
|
|
|
* \param texCoord: in vec2
|
|
|
|
|
* \param pos: in vec3
|
|
|
|
|
*/
|
|
|
|
|
GPU_SHADER_3D_IMAGE_COLOR,
|
2024-03-23 01:24:18 +01:00
|
|
|
};
|
2023-02-12 17:37:01 +01:00
|
|
|
#define GPU_SHADER_BUILTIN_LEN (GPU_SHADER_3D_IMAGE_COLOR + 1)
|
|
|
|
|
|
|
|
|
|
/** Support multiple configurations. */
|
2024-03-23 01:24:18 +01:00
|
|
|
enum eGPUShaderConfig {
|
2023-02-12 17:37:01 +01:00
|
|
|
GPU_SHADER_CFG_DEFAULT = 0,
|
|
|
|
|
GPU_SHADER_CFG_CLIPPED = 1,
|
2024-03-23 01:24:18 +01:00
|
|
|
};
|
2023-02-12 17:37:01 +01:00
|
|
|
#define GPU_SHADER_CFG_LEN (GPU_SHADER_CFG_CLIPPED + 1)
|
|
|
|
|
|
2025-08-11 09:34:28 +02:00
|
|
|
blender::gpu::Shader *GPU_shader_get_builtin_shader_with_config(eGPUBuiltinShader shader,
|
|
|
|
|
eGPUShaderConfig sh_cfg);
|
|
|
|
|
blender::gpu::Shader *GPU_shader_get_builtin_shader(eGPUBuiltinShader shader);
|
2023-02-12 17:37:01 +01:00
|
|
|
|
2025-06-11 14:08:38 +02:00
|
|
|
void GPU_shader_builtin_warm_up();
|
|
|
|
|
|
2024-03-23 01:24:18 +01:00
|
|
|
void GPU_shader_free_builtin_shaders();
|