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
|
2015-12-06 21:20:19 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2021-05-26 16:49:17 +02:00
|
|
|
struct GPUIndexBuf;
|
2020-08-14 15:20:35 +02:00
|
|
|
struct GPUVertBuf;
|
2015-12-06 21:20:19 +01:00
|
|
|
|
2022-01-17 14:45:22 +01:00
|
|
|
/** Opaque type hiding #blender::gpu::shader::ShaderCreateInfo */
|
|
|
|
typedef struct GPUShaderCreateInfo GPUShaderCreateInfo;
|
2021-02-05 16:23:34 +11:00
|
|
|
/** Opaque type hiding #blender::gpu::Shader */
|
2020-08-21 13:48:34 +02:00
|
|
|
typedef struct GPUShader GPUShader;
|
2015-12-06 21:20:19 +01:00
|
|
|
|
2019-01-23 14:15:43 +11:00
|
|
|
typedef enum eGPUShaderTFBType {
|
2018-05-16 12:47:15 +02:00
|
|
|
GPU_SHADER_TFB_NONE = 0, /* Transform feedback unsupported. */
|
|
|
|
GPU_SHADER_TFB_POINTS = 1,
|
|
|
|
GPU_SHADER_TFB_LINES = 2,
|
|
|
|
GPU_SHADER_TFB_TRIANGLES = 3,
|
2019-01-23 14:15:43 +11:00
|
|
|
} eGPUShaderTFBType;
|
2018-05-16 12:47:15 +02:00
|
|
|
|
2020-09-04 20:59:13 +02:00
|
|
|
GPUShader *GPU_shader_create(const char *vertcode,
|
2016-01-10 07:12:10 +11:00
|
|
|
const char *fragcode,
|
2020-09-04 20:59:13 +02:00
|
|
|
const char *geomcode,
|
2016-01-10 07:12:10 +11:00
|
|
|
const char *libcode,
|
2018-08-02 18:31:38 +02:00
|
|
|
const char *defines,
|
2020-09-04 20:59:13 +02:00
|
|
|
const char *shname);
|
2021-05-26 16:49:17 +02:00
|
|
|
GPUShader *GPU_shader_create_compute(const char *computecode,
|
|
|
|
const char *libcode,
|
|
|
|
const char *defines,
|
|
|
|
const char *shname);
|
2020-09-04 20:59:13 +02:00
|
|
|
GPUShader *GPU_shader_create_from_python(const char *vertcode,
|
2020-04-14 20:44:45 +02:00
|
|
|
const char *fragcode,
|
2020-09-04 20:59:13 +02:00
|
|
|
const char *geomcode,
|
2020-04-14 20:44:45 +02:00
|
|
|
const char *libcode,
|
2021-09-13 16:12:12 +10:00
|
|
|
const char *defines,
|
|
|
|
const char *name);
|
2020-09-04 20:59:13 +02:00
|
|
|
GPUShader *GPU_shader_create_ex(const char *vertcode,
|
2016-01-10 07:12:10 +11:00
|
|
|
const char *fragcode,
|
2020-09-04 20:59:13 +02:00
|
|
|
const char *geomcode,
|
2021-05-26 16:49:17 +02:00
|
|
|
const char *computecode,
|
2016-01-10 07:12:10 +11:00
|
|
|
const char *libcode,
|
|
|
|
const char *defines,
|
2022-01-07 11:38:08 +11:00
|
|
|
eGPUShaderTFBType tf_type,
|
2018-05-16 12:47:15 +02:00
|
|
|
const char **tf_names,
|
2022-01-07 11:38:08 +11:00
|
|
|
int tf_count,
|
2020-09-04 20:59:13 +02:00
|
|
|
const char *shname);
|
2022-01-17 14:45:22 +01:00
|
|
|
GPUShader *GPU_shader_create_from_info(const GPUShaderCreateInfo *_info);
|
2022-01-25 14:22:44 +01:00
|
|
|
GPUShader *GPU_shader_create_from_info_name(const char *info_name);
|
2020-08-14 15:20:35 +02:00
|
|
|
|
2022-02-01 13:42:00 +01:00
|
|
|
const GPUShaderCreateInfo *GPU_shader_create_info_get(const char *info_name);
|
2022-04-12 18:28:27 -03:00
|
|
|
bool GPU_shader_create_info_check_error(const GPUShaderCreateInfo *_info, char r_error[128]);
|
2022-02-01 13:42:00 +01:00
|
|
|
|
2019-02-06 09:15:16 +11:00
|
|
|
struct GPU_ShaderCreateFromArray_Params {
|
|
|
|
const char **vert, **geom, **frag, **defs;
|
|
|
|
};
|
2021-12-09 20:01:47 +11:00
|
|
|
/**
|
|
|
|
* Use via #GPU_shader_create_from_arrays macro (avoids passing in param).
|
|
|
|
*
|
|
|
|
* Similar to #DRW_shader_create_with_lib with the ability to include libs for each type of shader.
|
|
|
|
*
|
|
|
|
* It has the advantage that each item can be conditionally included
|
|
|
|
* without having to build the string inline, then free it.
|
|
|
|
*
|
|
|
|
* \param params: NULL terminated arrays of strings.
|
|
|
|
*
|
|
|
|
* Example:
|
|
|
|
* \code{.c}
|
|
|
|
* sh = GPU_shader_create_from_arrays({
|
|
|
|
* .vert = (const char *[]){shader_lib_glsl, shader_vert_glsl, NULL},
|
|
|
|
* .geom = (const char *[]){shader_geom_glsl, NULL},
|
|
|
|
* .frag = (const char *[]){shader_frag_glsl, NULL},
|
|
|
|
* .defs = (const char *[]){"#define DEFINE\n", test ? "#define OTHER_DEFINE\n" : "", NULL},
|
|
|
|
* });
|
|
|
|
* \endcode
|
|
|
|
*/
|
2019-02-06 09:15:16 +11:00
|
|
|
struct GPUShader *GPU_shader_create_from_arrays_impl(
|
2020-08-14 19:11:30 +02:00
|
|
|
const struct GPU_ShaderCreateFromArray_Params *params, const char *func, int line);
|
|
|
|
|
2019-02-06 09:15:16 +11:00
|
|
|
#define GPU_shader_create_from_arrays(...) \
|
2020-08-14 19:11:30 +02:00
|
|
|
GPU_shader_create_from_arrays_impl( \
|
|
|
|
&(const struct GPU_ShaderCreateFromArray_Params)__VA_ARGS__, __func__, __LINE__)
|
2019-02-06 09:15:16 +11:00
|
|
|
|
2020-09-16 01:40:04 +02:00
|
|
|
#define GPU_shader_create_from_arrays_named(name, ...) \
|
|
|
|
GPU_shader_create_from_arrays_impl( \
|
|
|
|
&(const struct GPU_ShaderCreateFromArray_Params)__VA_ARGS__, name, 0)
|
|
|
|
|
2015-12-06 21:20:19 +01:00
|
|
|
void GPU_shader_free(GPUShader *shader);
|
|
|
|
|
|
|
|
void GPU_shader_bind(GPUShader *shader);
|
|
|
|
void GPU_shader_unbind(void);
|
|
|
|
|
2021-09-13 16:12:12 +10:00
|
|
|
const char *GPU_shader_get_name(GPUShader *shader);
|
|
|
|
|
2021-12-09 20:01:47 +11:00
|
|
|
/**
|
|
|
|
* Returns true if transform feedback was successfully enabled.
|
|
|
|
*/
|
2020-08-14 15:20:35 +02:00
|
|
|
bool GPU_shader_transform_feedback_enable(GPUShader *shader, struct GPUVertBuf *vertbuf);
|
2018-05-16 12:47:15 +02:00
|
|
|
void GPU_shader_transform_feedback_disable(GPUShader *shader);
|
|
|
|
|
2021-12-09 20:01:47 +11:00
|
|
|
/** DEPRECATED: Kept only because of BGL API. */
|
2017-02-07 11:20:15 +01:00
|
|
|
int GPU_shader_get_program(GPUShader *shader);
|
2017-03-02 21:46:54 -05:00
|
|
|
|
2020-08-20 13:05:22 +02:00
|
|
|
typedef enum {
|
|
|
|
GPU_UNIFORM_MODEL = 0, /* mat4 ModelMatrix */
|
|
|
|
GPU_UNIFORM_VIEW, /* mat4 ViewMatrix */
|
|
|
|
GPU_UNIFORM_MODELVIEW, /* mat4 ModelViewMatrix */
|
|
|
|
GPU_UNIFORM_PROJECTION, /* mat4 ProjectionMatrix */
|
|
|
|
GPU_UNIFORM_VIEWPROJECTION, /* mat4 ViewProjectionMatrix */
|
|
|
|
GPU_UNIFORM_MVP, /* mat4 ModelViewProjectionMatrix */
|
|
|
|
|
|
|
|
GPU_UNIFORM_MODEL_INV, /* mat4 ModelMatrixInverse */
|
|
|
|
GPU_UNIFORM_VIEW_INV, /* mat4 ViewMatrixInverse */
|
|
|
|
GPU_UNIFORM_MODELVIEW_INV, /* mat4 ModelViewMatrixInverse */
|
|
|
|
GPU_UNIFORM_PROJECTION_INV, /* mat4 ProjectionMatrixInverse */
|
|
|
|
GPU_UNIFORM_VIEWPROJECTION_INV, /* mat4 ViewProjectionMatrixInverse */
|
|
|
|
|
|
|
|
GPU_UNIFORM_NORMAL, /* mat3 NormalMatrix */
|
|
|
|
GPU_UNIFORM_ORCO, /* vec4 OrcoTexCoFactors[] */
|
|
|
|
GPU_UNIFORM_CLIPPLANES, /* vec4 WorldClipPlanes[] */
|
|
|
|
|
|
|
|
GPU_UNIFORM_COLOR, /* vec4 color */
|
|
|
|
GPU_UNIFORM_BASE_INSTANCE, /* int baseInstance */
|
|
|
|
GPU_UNIFORM_RESOURCE_CHUNK, /* int resourceChunk */
|
|
|
|
GPU_UNIFORM_RESOURCE_ID, /* int resourceId */
|
|
|
|
GPU_UNIFORM_SRGB_TRANSFORM, /* bool srgbTarget */
|
|
|
|
|
|
|
|
GPU_NUM_UNIFORMS, /* Special value, denotes number of builtin uniforms. */
|
|
|
|
} GPUUniformBuiltin;
|
|
|
|
|
|
|
|
typedef enum {
|
2022-01-26 12:46:37 +01:00
|
|
|
/** Deprecated */
|
2020-08-20 13:05:22 +02:00
|
|
|
GPU_UNIFORM_BLOCK_VIEW = 0, /* viewBlock */
|
|
|
|
GPU_UNIFORM_BLOCK_MODEL, /* modelBlock */
|
|
|
|
GPU_UNIFORM_BLOCK_INFO, /* infoBlock */
|
2022-01-26 12:46:37 +01:00
|
|
|
/** New ones */
|
|
|
|
GPU_UNIFORM_BLOCK_DRW_VIEW,
|
|
|
|
GPU_UNIFORM_BLOCK_DRW_MODEL,
|
|
|
|
GPU_UNIFORM_BLOCK_DRW_INFOS,
|
2020-08-20 13:05:22 +02:00
|
|
|
|
|
|
|
GPU_NUM_UNIFORM_BLOCKS, /* Special value, denotes number of builtin uniforms block. */
|
|
|
|
} GPUUniformBlockBuiltin;
|
|
|
|
|
2022-08-08 19:01:38 +02:00
|
|
|
typedef enum {
|
|
|
|
GPU_STORAGE_BUFFER_DEBUG_VERTS = 0, /* drw_debug_verts_buf */
|
|
|
|
GPU_STORAGE_BUFFER_DEBUG_PRINT, /* drw_debug_print_buf */
|
|
|
|
|
|
|
|
GPU_NUM_STORAGE_BUFFERS, /* Special value, denotes number of builtin buffer blocks. */
|
|
|
|
} GPUStorageBufferBuiltin;
|
|
|
|
|
2020-08-14 15:20:35 +02:00
|
|
|
void GPU_shader_set_srgb_uniform(GPUShader *shader);
|
2020-04-14 20:44:45 +02:00
|
|
|
|
2015-12-06 21:20:19 +01:00
|
|
|
int GPU_shader_get_uniform(GPUShader *shader, const char *name);
|
2017-10-08 15:49:25 +02:00
|
|
|
int GPU_shader_get_builtin_uniform(GPUShader *shader, int builtin);
|
2020-06-04 13:43:28 +02:00
|
|
|
int GPU_shader_get_builtin_block(GPUShader *shader, int builtin);
|
2022-08-08 19:01:38 +02:00
|
|
|
int GPU_shader_get_builtin_ssbo(GPUShader *shader, int builtin);
|
2021-12-09 20:01:47 +11:00
|
|
|
/** DEPRECATED: Kept only because of Python GPU API. */
|
2017-02-07 11:20:15 +01:00
|
|
|
int GPU_shader_get_uniform_block(GPUShader *shader, const char *name);
|
2021-05-26 16:49:17 +02:00
|
|
|
int GPU_shader_get_ssbo(GPUShader *shader, const char *name);
|
2020-06-02 18:14:28 +02:00
|
|
|
|
|
|
|
int GPU_shader_get_uniform_block_binding(GPUShader *shader, const char *name);
|
|
|
|
int GPU_shader_get_texture_binding(GPUShader *shader, const char *name);
|
|
|
|
|
2018-07-18 23:09:31 +10:00
|
|
|
void GPU_shader_uniform_vector(
|
|
|
|
GPUShader *shader, int location, int length, int arraysize, const float *value);
|
|
|
|
void GPU_shader_uniform_vector_int(
|
|
|
|
GPUShader *shader, int location, int length, int arraysize, const int *value);
|
2015-12-06 21:20:19 +01:00
|
|
|
|
2018-09-20 19:51:02 +00:00
|
|
|
void GPU_shader_uniform_float(GPUShader *shader, int location, float value);
|
2015-12-06 21:20:19 +01:00
|
|
|
void GPU_shader_uniform_int(GPUShader *shader, int location, int value);
|
|
|
|
|
2020-08-11 15:59:02 +02:00
|
|
|
void GPU_shader_uniform_1i(GPUShader *sh, const char *name, int value);
|
|
|
|
void GPU_shader_uniform_1b(GPUShader *sh, const char *name, bool value);
|
|
|
|
void GPU_shader_uniform_1f(GPUShader *sh, const char *name, float value);
|
|
|
|
void GPU_shader_uniform_2f(GPUShader *sh, const char *name, float x, float y);
|
|
|
|
void GPU_shader_uniform_3f(GPUShader *sh, const char *name, float x, float y, float z);
|
|
|
|
void GPU_shader_uniform_4f(GPUShader *sh, const char *name, float x, float y, float z, float w);
|
|
|
|
void GPU_shader_uniform_2fv(GPUShader *sh, const char *name, const float data[2]);
|
|
|
|
void GPU_shader_uniform_3fv(GPUShader *sh, const char *name, const float data[3]);
|
|
|
|
void GPU_shader_uniform_4fv(GPUShader *sh, const char *name, const float data[4]);
|
2022-07-29 08:37:57 +02:00
|
|
|
void GPU_shader_uniform_2iv(GPUShader *sh, const char *name, const int data[2]);
|
2020-08-11 15:59:02 +02:00
|
|
|
void GPU_shader_uniform_mat4(GPUShader *sh, const char *name, const float data[4][4]);
|
2022-07-29 08:37:57 +02:00
|
|
|
void GPU_shader_uniform_mat3_as_mat4(GPUShader *sh, const char *name, const float data[3][3]);
|
2020-08-11 15:59:02 +02:00
|
|
|
void GPU_shader_uniform_2fv_array(GPUShader *sh, const char *name, int len, const float (*val)[2]);
|
|
|
|
void GPU_shader_uniform_4fv_array(GPUShader *sh, const char *name, int len, const float (*val)[4]);
|
|
|
|
|
2015-12-06 21:20:19 +01:00
|
|
|
int GPU_shader_get_attribute(GPUShader *shader, const char *name);
|
|
|
|
|
2020-04-14 20:44:45 +02:00
|
|
|
void GPU_shader_set_framebuffer_srgb_target(int use_srgb_to_linear);
|
|
|
|
|
2015-12-06 21:20:19 +01:00
|
|
|
/* Builtin/Non-generated shaders */
|
2019-01-23 14:15:43 +11:00
|
|
|
typedef enum eGPUBuiltinShader {
|
2016-10-25 03:19:10 -04:00
|
|
|
/* specialized drawing */
|
2016-09-17 13:33:02 +02:00
|
|
|
GPU_SHADER_TEXT,
|
2021-09-23 15:53:38 +02:00
|
|
|
GPU_SHADER_KEYFRAME_SHAPE,
|
2017-02-07 13:04:08 +01:00
|
|
|
GPU_SHADER_SIMPLE_LIGHTING,
|
2016-08-16 14:58:53 -04:00
|
|
|
/* for simple 2D drawing */
|
2018-05-23 15:26:59 +02:00
|
|
|
/**
|
|
|
|
* Take a single color for all the vertices and a 2D position for each vertex.
|
|
|
|
*
|
|
|
|
* \param color: uniform vec4
|
|
|
|
* \param pos: in vec2
|
|
|
|
*/
|
2016-08-04 15:59:38 -04:00
|
|
|
GPU_SHADER_2D_UNIFORM_COLOR,
|
2018-05-23 15:26:59 +02:00
|
|
|
/**
|
|
|
|
* Take a 2D position and color for each vertex without color interpolation.
|
|
|
|
*
|
|
|
|
* \param color: in vec4
|
|
|
|
* \param pos: in vec2
|
|
|
|
*/
|
2016-08-08 04:56:02 -04:00
|
|
|
GPU_SHADER_2D_FLAT_COLOR,
|
2018-05-23 15:26:59 +02:00
|
|
|
/**
|
|
|
|
* Take a 2D position and color for each vertex with linear interpolation in window space.
|
|
|
|
*
|
|
|
|
* \param color: in vec4
|
|
|
|
* \param pos: in vec2
|
|
|
|
*/
|
2016-08-04 15:59:38 -04:00
|
|
|
GPU_SHADER_2D_SMOOTH_COLOR,
|
2018-02-13 18:09:58 +01:00
|
|
|
GPU_SHADER_2D_IMAGE,
|
2016-11-18 16:04:25 +01:00
|
|
|
GPU_SHADER_2D_IMAGE_COLOR,
|
2018-04-26 15:42:08 +02:00
|
|
|
GPU_SHADER_2D_IMAGE_DESATURATE_COLOR,
|
2018-03-27 23:57:29 +02:00
|
|
|
GPU_SHADER_2D_IMAGE_RECT_COLOR,
|
2018-03-31 19:32:28 +02:00
|
|
|
GPU_SHADER_2D_IMAGE_MULTI_RECT_COLOR,
|
2017-02-07 13:04:08 +01:00
|
|
|
GPU_SHADER_2D_CHECKER,
|
2017-02-16 21:49:20 -02:00
|
|
|
GPU_SHADER_2D_DIAG_STRIPES,
|
2016-08-16 14:58:53 -04:00
|
|
|
/* for simple 3D drawing */
|
2018-05-23 15:26:59 +02:00
|
|
|
/**
|
|
|
|
* Take a single color for all the vertices and a 3D position for each vertex.
|
|
|
|
*
|
|
|
|
* \param color: uniform vec4
|
|
|
|
* \param pos: in vec3
|
|
|
|
*/
|
2016-08-16 14:58:53 -04:00
|
|
|
GPU_SHADER_3D_UNIFORM_COLOR,
|
2020-04-23 23:05:39 +02:00
|
|
|
GPU_SHADER_3D_CLIPPED_UNIFORM_COLOR,
|
2018-05-23 15:26:59 +02:00
|
|
|
/**
|
|
|
|
* Take a 3D position and color for each vertex without color interpolation.
|
|
|
|
*
|
|
|
|
* \param color: in vec4
|
|
|
|
* \param pos: in vec3
|
|
|
|
*/
|
2016-08-16 14:58:53 -04:00
|
|
|
GPU_SHADER_3D_FLAT_COLOR,
|
2018-05-23 15:26:59 +02:00
|
|
|
/**
|
|
|
|
* Take a 3D position and color for each vertex with perspective correct interpolation.
|
|
|
|
*
|
|
|
|
* \param color: in vec4
|
|
|
|
* \param pos: in vec3
|
|
|
|
*/
|
2016-08-16 14:58:53 -04:00
|
|
|
GPU_SHADER_3D_SMOOTH_COLOR,
|
2020-04-23 23:05:39 +02:00
|
|
|
/**
|
|
|
|
* 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,
|
2018-05-23 15:26:59 +02:00
|
|
|
/**
|
|
|
|
* Take a 3D position for each vertex and output only depth.
|
2020-04-23 23:05:39 +02:00
|
|
|
* Used for drawing wide lines.
|
2018-05-23 15:26:59 +02:00
|
|
|
*
|
|
|
|
* \param pos: in vec3
|
|
|
|
*/
|
2016-09-13 02:51:38 -04:00
|
|
|
GPU_SHADER_3D_DEPTH_ONLY,
|
2016-10-18 00:08:34 -04:00
|
|
|
/* basic image drawing */
|
2020-02-11 15:18:55 +01:00
|
|
|
GPU_SHADER_2D_IMAGE_OVERLAYS_MERGE,
|
2020-03-19 08:06:49 +01:00
|
|
|
GPU_SHADER_2D_IMAGE_OVERLAYS_STEREO_MERGE,
|
2017-02-24 01:07:40 +01:00
|
|
|
GPU_SHADER_2D_IMAGE_SHUFFLE_COLOR,
|
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
|
|
|
/**
|
|
|
|
* Draw a texture in 3D. Take a 3D position and a 2D texture coordinate for each vertex.
|
|
|
|
*
|
2022-05-11 10:03:17 +10:00
|
|
|
* Exposed via Python-API for add-ons.
|
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
|
|
|
*
|
|
|
|
* \param image: uniform sampler2D
|
|
|
|
* \param texCoord: in vec2
|
|
|
|
* \param pos: in vec3
|
|
|
|
*/
|
|
|
|
GPU_SHADER_3D_IMAGE,
|
2021-11-05 14:51:55 +01:00
|
|
|
/**
|
|
|
|
* Draw texture with alpha. Take a 3D position and a 2D texture coordinate for each vertex.
|
|
|
|
*
|
|
|
|
* \param alpha: uniform float
|
|
|
|
* \param image: uniform sampler2D
|
|
|
|
* \param texCoord: in vec2
|
|
|
|
* \param pos: in vec3
|
|
|
|
*/
|
|
|
|
GPU_SHADER_3D_IMAGE_MODULATE_ALPHA,
|
2016-09-30 20:44:22 -04:00
|
|
|
/* points */
|
2018-05-23 15:26:59 +02:00
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*/
|
2017-02-28 02:18:52 -05:00
|
|
|
GPU_SHADER_2D_POINT_UNIFORM_SIZE_UNIFORM_COLOR_AA,
|
2018-05-23 15:26:59 +02:00
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*/
|
2017-02-28 02:18:52 -05:00
|
|
|
GPU_SHADER_2D_POINT_UNIFORM_SIZE_UNIFORM_COLOR_OUTLINE_AA,
|
2018-05-23 15:26:59 +02:00
|
|
|
/**
|
|
|
|
* Draw round points with a hardcoded size.
|
|
|
|
* Take a single color for all the vertices and a 3D position for each vertex.
|
|
|
|
*
|
|
|
|
* \param color: uniform vec4
|
|
|
|
* \param pos: in vec3
|
|
|
|
*/
|
2016-09-30 20:44:22 -04:00
|
|
|
GPU_SHADER_3D_POINT_FIXED_SIZE_VARYING_COLOR,
|
2018-05-23 15:26:59 +02:00
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*/
|
2017-02-28 02:18:52 -05:00
|
|
|
GPU_SHADER_3D_POINT_UNIFORM_SIZE_UNIFORM_COLOR_AA,
|
2018-05-23 15:26:59 +02:00
|
|
|
/**
|
2019-04-22 01:45:43 +10:00
|
|
|
* Draw round points with a constant size and an outline.
|
|
|
|
* Take a 3D position and a color for each vertex.
|
2018-05-23 15:26:59 +02:00
|
|
|
*
|
|
|
|
* \param size: in float
|
|
|
|
* \param color: in vec4
|
|
|
|
* \param pos: in vec3
|
|
|
|
*/
|
2016-10-01 17:32:29 -04:00
|
|
|
GPU_SHADER_3D_POINT_VARYING_SIZE_VARYING_COLOR,
|
2017-02-24 15:33:09 -05:00
|
|
|
/* lines */
|
2017-07-13 16:44:02 +02:00
|
|
|
GPU_SHADER_2D_LINE_DASHED_UNIFORM_COLOR,
|
|
|
|
GPU_SHADER_3D_LINE_DASHED_UNIFORM_COLOR,
|
2018-07-31 10:22:19 +02:00
|
|
|
/* grease pencil drawing */
|
|
|
|
GPU_SHADER_GPENCIL_STROKE,
|
|
|
|
/* specialized for widget drawing */
|
2022-01-10 12:22:06 +01:00
|
|
|
GPU_SHADER_2D_AREA_BORDERS,
|
2018-03-29 03:06:33 +02:00
|
|
|
GPU_SHADER_2D_WIDGET_BASE,
|
2018-04-06 14:22:20 +02:00
|
|
|
GPU_SHADER_2D_WIDGET_BASE_INST,
|
2018-04-06 10:09:23 +02:00
|
|
|
GPU_SHADER_2D_WIDGET_SHADOW,
|
2018-04-05 15:27:53 +02:00
|
|
|
GPU_SHADER_2D_NODELINK,
|
|
|
|
GPU_SHADER_2D_NODELINK_INST,
|
2019-01-23 14:15:43 +11:00
|
|
|
} eGPUBuiltinShader;
|
2022-01-10 12:18:30 +01:00
|
|
|
#define GPU_SHADER_BUILTIN_LEN (GPU_SHADER_2D_NODELINK_INST + 1)
|
2019-02-06 09:15:16 +11:00
|
|
|
|
|
|
|
/** 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)
|
2015-12-06 21:20:19 +01:00
|
|
|
|
2019-02-10 11:06:22 +11:00
|
|
|
typedef struct GPUShaderConfigData {
|
|
|
|
const char *lib;
|
|
|
|
const char *def;
|
|
|
|
} GPUShaderConfigData;
|
2019-02-11 10:51:25 +11:00
|
|
|
/* gpu_shader.c */
|
2022-04-04 13:17:03 +10:00
|
|
|
|
2019-02-10 11:06:22 +11:00
|
|
|
extern const GPUShaderConfigData GPU_shader_cfg_data[GPU_SHADER_CFG_LEN];
|
|
|
|
|
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);
|
2019-02-06 09:15:16 +11:00
|
|
|
GPUShader *GPU_shader_get_builtin_shader(eGPUBuiltinShader shader);
|
2015-12-06 21:20:19 +01:00
|
|
|
|
|
|
|
void GPU_shader_free_builtin_shaders(void);
|
|
|
|
|
|
|
|
/* Vertex attributes for shaders */
|
|
|
|
|
2019-08-14 22:18:47 +02:00
|
|
|
/* Hardware limit is 16. Position attribute is always needed so we reduce to 15.
|
|
|
|
* This makes sure the GPUVertexFormat name buffer does not overflow. */
|
|
|
|
#define GPU_MAX_ATTR 15
|
2015-12-06 21:20:19 +01:00
|
|
|
|
Materials: add custom object properties as uniform attributes.
This patch allows the user to type a property name into the
Attribute node, which will then output the value of the property
for each individual object, allowing to e.g. customize shaders
by object without duplicating the shader.
In order to make supporting this easier for Eevee, it is necessary
to explicitly choose whether the attribute is varying or uniform
via a dropdown option of the Attribute node. The dropdown also
allows choosing whether instancing should be taken into account.
The Cycles design treats all attributes as one common namespace,
so the Blender interface converts the enum to a name prefix that
can't be entered using keyboard.
In Eevee, the attributes are provided to the shader via a UBO indexed
with resource_id, similar to the existing Object Info data. Unlike it,
however, it is necessary to maintain a separate buffer for every
requested combination of attributes.
This is done using a hash table with the attribute set as the key,
as it is expected that technically different but similar materials
may use the same set of attributes. In addition, in order to minimize
wasted memory, a sparse UBO pool is implemented, so that chunks that
don't contain any data don't have to be allocated.
The back-end Cycles code is already refactored and committed by Brecht.
Differential Revision: https://developer.blender.org/D2057
2020-08-05 19:14:40 +03:00
|
|
|
/* Determined by the maximum uniform buffer size divided by chunk size. */
|
|
|
|
#define GPU_MAX_UNIFORM_ATTR 8
|
|
|
|
|
2021-09-23 15:53:38 +02:00
|
|
|
typedef enum eGPUKeyframeShapes {
|
|
|
|
GPU_KEYFRAME_SHAPE_DIAMOND = (1 << 0),
|
|
|
|
GPU_KEYFRAME_SHAPE_CIRCLE = (1 << 1),
|
|
|
|
GPU_KEYFRAME_SHAPE_CLIPPED_VERTICAL = (1 << 2),
|
|
|
|
GPU_KEYFRAME_SHAPE_CLIPPED_HORIZONTAL = (1 << 3),
|
|
|
|
GPU_KEYFRAME_SHAPE_INNER_DOT = (1 << 4),
|
|
|
|
GPU_KEYFRAME_SHAPE_ARROW_END_MAX = (1 << 8),
|
|
|
|
GPU_KEYFRAME_SHAPE_ARROW_END_MIN = (1 << 9),
|
|
|
|
GPU_KEYFRAME_SHAPE_ARROW_END_MIXED = (1 << 10),
|
|
|
|
} eGPUKeyframeShapes;
|
|
|
|
#define GPU_KEYFRAME_SHAPE_SQUARE \
|
|
|
|
(GPU_KEYFRAME_SHAPE_CLIPPED_VERTICAL | GPU_KEYFRAME_SHAPE_CLIPPED_HORIZONTAL)
|
|
|
|
|
2015-12-06 21:20:19 +01:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|