me-main #1

Merged
Nate Rupsis merged 123 commits from me-main into main 2023-02-13 18:39:11 +01:00
2 changed files with 149 additions and 173 deletions
Showing only changes of commit d92c28582a - Show all commits

View File

@ -7,6 +7,8 @@
#pragma once #pragma once
#include "GPU_shader_builtin.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
@ -202,179 +204,6 @@ bool GPU_shader_get_attribute_info(const GPUShader *shader,
void GPU_shader_set_framebuffer_srgb_target(int use_srgb_to_linear); void GPU_shader_set_framebuffer_srgb_target(int use_srgb_to_linear);
/* Builtin/Non-generated shaders */
typedef enum eGPUBuiltinShader {
/* specialized drawing */
GPU_SHADER_TEXT,
GPU_SHADER_KEYFRAME_SHAPE,
GPU_SHADER_SIMPLE_LIGHTING,
/**
* Draw an icon, leaving a semi-transparent rectangle on top of the icon.
*/
GPU_SHADER_ICON,
/**
* Take a 2D position and color for each vertex with linear interpolation in window space.
*
* \param color: in vec4
* \param pos: in vec2
*/
GPU_SHADER_2D_IMAGE_DESATURATE_COLOR,
GPU_SHADER_2D_IMAGE_RECT_COLOR,
GPU_SHADER_2D_IMAGE_MULTI_RECT_COLOR,
GPU_SHADER_2D_CHECKER,
GPU_SHADER_2D_DIAG_STRIPES,
/* for simple 3D drawing */
/**
* 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_CLIPPED_UNIFORM_COLOR,
/**
* 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,
/**
* 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,
/**
* Take a single color for all the vertices and a 3D position for each vertex.
* Used for drawing wide lines.
*
* \param color: uniform vec4
* \param pos: in vec3
*/
GPU_SHADER_3D_POLYLINE_UNIFORM_COLOR,
GPU_SHADER_3D_POLYLINE_CLIPPED_UNIFORM_COLOR,
/**
* Take a 3D position and color for each vertex without color interpolation.
* Used for drawing wide lines.
*
* \param color: in vec4
* \param pos: in vec3
*/
GPU_SHADER_3D_POLYLINE_FLAT_COLOR,
/**
* Take a 3D position and color for each vertex with perspective correct interpolation.
* Used for drawing wide lines.
*
* \param color: in vec4
* \param pos: in vec3
*/
GPU_SHADER_3D_POLYLINE_SMOOTH_COLOR,
/**
* Take a 3D position for each vertex and output only depth.
* Used for drawing wide lines.
*
* \param pos: in vec3
*/
GPU_SHADER_3D_DEPTH_ONLY,
/* basic image drawing */
GPU_SHADER_2D_IMAGE_OVERLAYS_MERGE,
GPU_SHADER_2D_IMAGE_OVERLAYS_STEREO_MERGE,
GPU_SHADER_2D_IMAGE_SHUFFLE_COLOR,
/**
* Draw a texture in 3D. Take a 3D position and a 2D texture coordinate for each vertex.
*
* Exposed via Python-API for add-ons.
*
* \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,
/* points */
/**
* Draw round points with a constant size.
* Take a single color for all the vertices and a 2D position for each vertex.
*
* \param size: uniform float
* \param color: uniform vec4
* \param pos: in vec2
*/
GPU_SHADER_2D_POINT_UNIFORM_SIZE_UNIFORM_COLOR_AA,
/**
* Draw round points with a constant size and an outline.
* Take a single color for all the vertices and a 2D position for each vertex.
*
* \param size: uniform float
* \param outlineWidth: uniform float
* \param color: uniform vec4
* \param outlineColor: uniform vec4
* \param pos: in vec2
*/
GPU_SHADER_2D_POINT_UNIFORM_SIZE_UNIFORM_COLOR_OUTLINE_AA,
/**
* Draw round points with a constant size.
* Take a single color for all the vertices and a 3D position for each vertex.
*
* \param size: uniform float
* \param color: uniform vec4
* \param pos: in vec3
*/
GPU_SHADER_3D_POINT_UNIFORM_SIZE_UNIFORM_COLOR_AA,
/**
* Draw round points with a constant size and an outline.
* Take a 3D position and a color for each vertex.
*
* \param size: in float
* \param color: in vec4
* \param pos: in vec3
*/
GPU_SHADER_3D_POINT_VARYING_SIZE_VARYING_COLOR,
/* lines */
GPU_SHADER_3D_LINE_DASHED_UNIFORM_COLOR,
/* grease pencil drawing */
GPU_SHADER_GPENCIL_STROKE,
/* specialized for widget drawing */
GPU_SHADER_2D_AREA_BORDERS,
GPU_SHADER_2D_WIDGET_BASE,
GPU_SHADER_2D_WIDGET_BASE_INST,
GPU_SHADER_2D_WIDGET_SHADOW,
GPU_SHADER_2D_NODELINK,
GPU_SHADER_2D_NODELINK_INST,
} eGPUBuiltinShader;
#define GPU_SHADER_BUILTIN_LEN (GPU_SHADER_2D_NODELINK_INST + 1)
/** Support multiple configurations. */
typedef enum eGPUShaderConfig {
GPU_SHADER_CFG_DEFAULT = 0,
GPU_SHADER_CFG_CLIPPED = 1,
} eGPUShaderConfig;
#define GPU_SHADER_CFG_LEN (GPU_SHADER_CFG_CLIPPED + 1)
typedef struct GPUShaderConfigData {
const char *lib;
const char *def;
} GPUShaderConfigData;
/* gpu_shader.c */
extern const GPUShaderConfigData GPU_shader_cfg_data[GPU_SHADER_CFG_LEN];
GPUShader *GPU_shader_get_builtin_shader_with_config(eGPUBuiltinShader shader,
eGPUShaderConfig sh_cfg);
GPUShader *GPU_shader_get_builtin_shader(eGPUBuiltinShader shader);
void GPU_shader_free_builtin_shaders(void);
/* Vertex attributes for shaders */ /* Vertex attributes for shaders */
/* Hardware limit is 16. Position attribute is always needed so we reduce to 15. /* Hardware limit is 16. Position attribute is always needed so we reduce to 15.

View File

@ -0,0 +1,147 @@
/* SPDX-License-Identifier: GPL-2.0-or-later
* Copyright 2023 Blender Foundation. All rights reserved. */
/** \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.
*
* For full list of parameters, search for the the associated #ShaderCreateInfo.
* 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
#ifdef __cplusplus
extern "C" {
#endif
struct GPUShader;
typedef enum eGPUBuiltinShader {
/** Glyph drawing shader used by the BLF module. */
GPU_SHADER_TEXT,
/** 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. */
GPU_SHADER_2D_IMAGE_MULTI_RECT_COLOR,
/** 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,
/** Draw a node link given an input quadratic Bezier curve. */
GPU_SHADER_2D_NODELINK,
GPU_SHADER_2D_NODELINK_INST,
/** 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,
/**
* ----------------------- 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,
/**
* 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,
/**
* 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,
/**
* 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,
} eGPUBuiltinShader;
#define GPU_SHADER_BUILTIN_LEN (GPU_SHADER_3D_IMAGE_COLOR + 1)
/** Support multiple configurations. */
typedef enum eGPUShaderConfig {
GPU_SHADER_CFG_DEFAULT = 0,
GPU_SHADER_CFG_CLIPPED = 1,
} eGPUShaderConfig;
#define GPU_SHADER_CFG_LEN (GPU_SHADER_CFG_CLIPPED + 1)
struct GPUShader *GPU_shader_get_builtin_shader_with_config(eGPUBuiltinShader shader,
eGPUShaderConfig sh_cfg);
struct GPUShader *GPU_shader_get_builtin_shader(eGPUBuiltinShader shader);
void GPU_shader_free_builtin_shaders(void);
#ifdef __cplusplus
}
#endif